// Test nsIFile::CopyToNative, verifying that the file did not exist at the new location // before and does afterward, and that it does exist at the old location too static bool TestCopy(nsIFile* aBase, nsIFile* aDestDir, const char* aName, const char* aNewName) { gFunction = "TestCopy"; nsCOMPtr<nsIFile> file = NewFile(aBase); if (!file) return false; nsCString name = FixName(aName); nsresult rv = file->AppendNative(name); if (!VerifyResult(rv, "AppendNative")) return false; bool exists; rv = file->Exists(&exists); if (!VerifyResult(rv, "Exists (before)")) return false; if (!exists) { fail("%s File %s does not exist", gFunction, name.get()); return false; } nsCOMPtr<nsIFile> newFile = NewFile(file); nsCString newName = FixName(aNewName); rv = newFile->CopyToNative(aDestDir, newName); if (!VerifyResult(rv, "MoveToNative")) return false; bool equal; rv = file->Equals(newFile, &equal); if (!VerifyResult(rv, "Equals")) return false; if (!equal) { fail("%s file object updated unexpectedly", gFunction); return false; } rv = file->Exists(&exists); if (!VerifyResult(rv, "Exists (after)")) return false; if (!exists) { fail("%s File %s was removed", gFunction, name.get()); return false; } file = NewFile(aDestDir); if (!file) return false; rv = file->AppendNative(newName); if (!VerifyResult(rv, "AppendNative")) return false; rv = file->Exists(&exists); if (!VerifyResult(rv, "Exists (new after)")) return false; if (!exists) { fail("%s Destination file %s was not created", gFunction, newName.get()); return false; } return true; }
STATIC enum cacheRet maybeCache( const char *fullpath, CENTRYPTR *pc ) /********************************************************************/ { char path[_MAX_PATH]; char name[NAME_MAX + 1]; DHEADPTR dcur; CENTRYPTR centry; enum cacheRet ret; PGROUP pg; char const *ext; assert( fullpath != NULL ); _splitpath2( fullpath, pg.buffer, &pg.drive, &pg.dir, &pg.fname, &pg.ext ); _makepath( path, pg.drive, pg.dir, NULL, NULL ); ext = pg.ext; if( ext[0] == '.' && ext[1] == 0 ) { ext = NULL; } _makepath( name, NULL, NULL, pg.fname, ext ); FixName( path ); FixName( name ); dcur = findDir( path ); if( dcur == NULL ) { /* must cache new directory */ ret = cacheDir( &dcur, path ); if( ret != CACHE_OK ) { return( ret ); } dcur->dh_next = cacheHead; cacheHead = dcur; } /* now dcur points to Cached directory */ assert( dcur != NULL ); centry = findFile( dcur, name ); if( centry == NULL ) { return( CACHE_FILE_NOT_FOUND ); } if( pc != NULL ) { *pc = centry; } return( CACHE_OK ); }
// Test nsIFile::Remove, verifying that the file does not exist and did before static bool TestRemove(nsIFile* aBase, const char* aName, bool aRecursive) { gFunction = "TestDelete"; nsCOMPtr<nsIFile> file = NewFile(aBase); if (!file) return false; nsCString name = FixName(aName); nsresult rv = file->AppendNative(name); if (!VerifyResult(rv, "AppendNative")) return false; bool exists; rv = file->Exists(&exists); if (!VerifyResult(rv, "Exists (before)")) return false; if (!exists) { fail("%s File %s does not exist", gFunction, name.get()); return false; } rv = file->Remove(aRecursive); if (!VerifyResult(rv, "Remove")) return false; rv = file->Exists(&exists); if (!VerifyResult(rv, "Exists (after)")) return false; if (exists) { fail("%s File %s was not removed", gFunction, name.get()); return false; } return true; }
// Test nsIFile::Normalize and native path setting/getting static bool TestNormalizeNativePath(nsIFile* aBase, nsIFile* aStart) { gFunction = "TestNormalizeNativePath"; nsCOMPtr<nsIFile> file = NewFile(aStart); if (!file) return false; nsCAutoString path; nsresult rv = file->GetNativePath(path); VerifyResult(rv, "GetNativePath"); path.Append(FixName("/./..")); rv = file->InitWithNativePath(path); VerifyResult(rv, "InitWithNativePath"); rv = file->Normalize(); VerifyResult(rv, "Normalize"); rv = file->GetNativePath(path); VerifyResult(rv, "GetNativePath (after normalization)"); nsCAutoString basePath; rv = aBase->GetNativePath(basePath); VerifyResult(rv, "GetNativePath (base)"); if (!path.Equals(basePath)) { fail("%s Incorrect normalization"); return false; } return true; }
// Test nsIFile::Create, verifying that the file exists and did not exist before, // and leaving it there for future tests static bool TestCreate(nsIFile* aBase, const char* aName, int32_t aType, int32_t aPerm) { gFunction = "TestCreate"; nsCOMPtr<nsIFile> file = NewFile(aBase); if (!file) return false; nsCString name = FixName(aName); nsresult rv = file->AppendNative(name); if (!VerifyResult(rv, "AppendNative")) return false; bool exists; rv = file->Exists(&exists); if (!VerifyResult(rv, "Exists (before)")) return false; if (exists) { fail("%s File %s already exists", gFunction, name.get()); return false; } rv = file->Create(aType, aPerm); if (!VerifyResult(rv, "Create")) return false; rv = file->Exists(&exists); if (!VerifyResult(rv, "Exists (after)")) return false; if (!exists) { fail("%s File %s was not created", gFunction, name.get()); return false; } return true; }
void ModuleManager::Remove(Module* module) { // Remove module from list std::string name = module->GetName(); FixName(name); moduleList.erase(name); delete module; }
const char *DoWildCard( const char *base ) /***********************************************/ { PGROUP pg; struct dirent *entry; if( base != NULL ) { /* clean up from previous invocation */ DoWildCardClose(); if( strpbrk( base, WILD_METAS ) == NULL ) { return( base ); } // create directory name and pattern path = MallocSafe( _MAX_PATH ); pattern = MallocSafe( _MAX_PATH ); strcpy( path, base ); FixName( path ); _splitpath2( path, pg.buffer, &pg.drive, &pg.dir, &pg.fname, &pg.ext ); _makepath( path, pg.drive, pg.dir, ".", NULL ); // create file name pattern _makepath( pattern, NULL, NULL, pg.fname, pg.ext ); parent = opendir( path ); if( parent == NULL ) { DoWildCardClose(); return( base ); } } if( parent == NULL ) { return( NULL ); } assert( path != NULL && parent != NULL ); while( (entry = readdir( parent )) != NULL ) { #ifndef __UNIX__ if( ( entry->d_attr & IGNORE_MASK ) == 0 ) { #endif if( __fnmatch( pattern, entry->d_name ) ) { break; } #ifndef __UNIX__ } #endif } if( entry == NULL ) { DoWildCardClose(); return( base ); } _splitpath2( path, pg.buffer, &pg.drive, &pg.dir, &pg.fname, &pg.ext ); _makepath( path, pg.drive, pg.dir, entry->d_name, NULL ); return( path ); }
void RenameTarget( TARGET *targ, const char *newname ) /****************************************************/ { (void)RemHashNode( targTab, targ->node.name, CASESENSITIVE ); if( targ->node.name != NULL ) { FreeSafe( targ->node.name ); } targ->node.name = FixName( StrDupSafe( newname ) ); AddHashNode( targTab, (HASHNODE *)targ ); }
STATIC enum cacheRet maybeCache( const char *fullpath, CENTRYPTR *pc ) /********************************************************************/ { char path[_MAX_PATH]; char name[NAME_MAX + 1]; DHEADPTR dcur; CENTRYPTR centry; enum cacheRet ret; assert( fullpath != NULL ); splitFullPath( fullpath, path, name ); FixName( path ); FixName( name ); dcur = findDir( path ); if( dcur == NULL ) { /* must cache new directory */ ret = cacheDir( &dcur, path ); if( ret != CACHE_OK ) { return( ret ); } dcur->dh_next = cacheHead; cacheHead = dcur; } /* now dcur points to Cached directory */ assert( dcur != NULL ); centry = findFile( dcur, name ); if( centry == NULL ) { return( CACHE_FILE_NOT_FOUND ); } if( pc != NULL ) { *pc = centry; } return( CACHE_OK ); }
void MSA::ToPhyInterleavedFile(TextFile &File) const { const unsigned SeqCount = GetSeqCount(); const unsigned ColCount = GetColCount(); File.PutFormat("%d %d\n", SeqCount, ColCount); if (0 == ColCount) return; unsigned Col = 0; for (;;) { const unsigned ColBlockStart = Col; const unsigned MaxCols = (ColBlockStart == 0) ? (BLOCKSIZE - 10) : BLOCKSIZE; for (unsigned Seq = 0; Seq < SeqCount; ++Seq) { if (0 == ColBlockStart) { char Name[11]; const char *ptrName = GetSeqName(Seq); size_t n = strlen(ptrName); if (n > 10) n = 10; memcpy(Name, ptrName, n); Name[n] = 0; FixName(Name); File.PutFormat("%-10.10s", Name); } Col = ColBlockStart; for (unsigned ColsThisBlock = 0; ColsThisBlock < MaxCols; ++ColsThisBlock) { if (Col == ColCount) break; if (ColsThisBlock%10 == 0 && (0 == ColBlockStart || ColsThisBlock > 0)) File.PutChar(' '); char c = GetChar(Seq, Col); if (isalpha(c)) c = toupper(c); File.PutChar(c); ++Col; } File.PutChar('\n'); } if (Col == ColCount) break; File.PutChar('\n'); } }
int main(int argc, char* argv[]) { std::shared_ptr<Process> wow = ProcessTools::Open(_T("Wow.exe"), 20173, true); if (!wow) return 1; std::vector<GameObjectProperty> props = wow->ReadArray<GameObjectProperty>(PROPERTY_DATA - 0x400000, MAX_PROPERTY_INDEX); std::string propertyNames[MAX_PROPERTY_INDEX]; for (std::uint32_t i = 0; i < props.size(); ++i) propertyNames[i] = wow->Read<std::string>(props[i].Name); std::vector<GameObjectPropertyInfo> typeData = wow->ReadArray<GameObjectPropertyInfo>(GO_TYPE_DATA - 0x400000, MAX_GAMEOBJECT_TYPE); InitTypes(); Structure templateUnion; templateUnion.SetName("GameObjectTemplateData"); for (std::uint32_t i = 0; i < typeData.size(); ++i) { Structure typeStructure; typeStructure.SetComment(std::to_string(i) + " " + TCEnumName[i]); typeStructure.SetValueCommentPadding(40); std::uint32_t propCount = std::min<std::uint32_t>(MAX_GAMEOBJECT_DATA, typeData[i].Count); std::vector<std::uint32_t> propIndexes = wow->ReadArray<std::uint32_t>(typeData[i].List, propCount); for (std::size_t j = 0; j < propIndexes.size(); ++j) { std::string name = propertyNames[propIndexes[j]]; GameObjectPropertyTypeInfo* type = wow->Read<GameObjectPropertyTypeInfo*>(typeData[i].TypeInfo + j); typeStructure.AddMember(Structure::Member(j, "uint32", FixName(name), static_cast<std::ostringstream&>(std::ostringstream() << j << " " << name << ", " << FormatType(wow, props[propIndexes[j]].TypeIndex, wow->Read<GameObjectPropertyTypeInfo>(type))).str())); } templateUnion.AddMember(Structure::Member(i, static_cast<std::ostringstream&>(std::ostringstream() << SourceOutput<Structure>(std::make_unique<CppStruct>(true), typeStructure, 4)).str(), FixName(wow->Read<std::string>(typeData[i].TypeName)), "")); } Structure raw; raw.AddMember(Structure::Member(0, "uint32", "data[MAX_GAMEOBJECT_DATA]", "")); templateUnion.AddMember(Structure::Member(MAX_GAMEOBJECT_TYPE, static_cast<std::ostringstream&>(std::ostringstream() << SourceOutput<Structure>(std::make_unique<CppStruct>(true), raw, 4)).str(), "raw", "")); std::ofstream structure("GameObjectTemplate.h"); structure << SourceOutput<Structure>(std::make_unique<CppUnion>(false), templateUnion, 0); return 0; }
// Test nsIFile::AppendNative, verifying that aName is not a valid file name static bool TestInvalidFileName(nsIFile* aBase, const char* aName) { gFunction = "TestInvalidFileName"; nsCOMPtr<nsIFile> file = NewFile(aBase); if (!file) return false; nsCString name = FixName(aName); nsresult rv = file->AppendNative(name); if (NS_SUCCEEDED(rv)) { fail("%s AppendNative with invalid filename %s", gFunction, name.get()); return false; } return true; }
void SMDImporter::RecurseCreateNull ( XSI::X3DObject in_pParent, SMDNode* in_pNode ) { LPWSTR l_wszModelName; DSA2W(&l_wszModelName,FixName ( in_pNode->m_szName ) ); XSI::Null myNull = DoesObjectExist ( in_pParent, XSI::CString(l_wszModelName) ); if ( !myNull.IsValid() ) { in_pParent.AddNull ( l_wszModelName, myNull ); } in_pNode->m_x3d = myNull; XSI::KinematicState l_lLocal = myNull.GetKinematics().GetLocal(); XSI::MATH::CTransformation xfo; if ( in_pNode->m_pKeys.GetUsed() ) { SMDKey* l_pKey = in_pNode->GetKey (0); xfo = l_lLocal.GetTransform(); xfo.SetRotationFromXYZAnglesValues ( l_pKey->m_vRotation.GetX(), l_pKey->m_vRotation.GetY(), l_pKey->m_vRotation.GetZ() ); xfo.SetTranslationFromValues ( l_pKey->m_vPosition.GetX(), l_pKey->m_vPosition.GetY(), l_pKey->m_vPosition.GetZ() ); } if ( in_pNode->m_pParent ==NULL ) { XSI::MATH::CTransformation xfo2; xfo2.SetRotationFromXYZAnglesValues ( -1.570796, 0.0, 0.0 ); xfo.MulInPlace(xfo2); } l_lLocal.PutTransform ( xfo ); for (int c=0;c<in_pNode->m_pChildren.GetUsed();c++) { RecurseCreateNull ( myNull, in_pNode->GetChild(c)); } }
// Test nsIFile::CreateUnique, verifying that the new file exists and if it existed before, // the new file has a different name. // The new file is left in place. static bool TestCreateUnique(nsIFile* aBase, const char* aName, int32_t aType, int32_t aPerm) { gFunction = "TestCreateUnique"; nsCOMPtr<nsIFile> file = NewFile(aBase); if (!file) return false; nsCString name = FixName(aName); nsresult rv = file->AppendNative(name); if (!VerifyResult(rv, "AppendNative")) return false; bool existsBefore; rv = file->Exists(&existsBefore); if (!VerifyResult(rv, "Exists (before)")) return false; rv = file->CreateUnique(aType, aPerm); if (!VerifyResult(rv, "Create")) return false; bool existsAfter; rv = file->Exists(&existsAfter); if (!VerifyResult(rv, "Exists (after)")) return false; if (!existsAfter) { fail("%s File %s was not created", gFunction, name.get()); return false; } if (existsBefore) { nsCAutoString leafName; rv = file->GetNativeLeafName(leafName); if (!VerifyResult(rv, "GetNativeLeafName")) return false; if (leafName.Equals(name)) { fail("%s File %s was not given a new name by CreateUnique", gFunction, name.get()); return false; } } return true; }
// Test nsIFile::OpenNSPRFileDesc with DELETE_ON_CLOSE, verifying that the file exists // and did not exist before, and leaving it there for future tests static bool TestDeleteOnClose(nsIFile* aBase, const char* aName, int32_t aFlags, int32_t aPerm) { gFunction = "TestDeleteOnClose"; nsCOMPtr<nsIFile> file = NewFile(aBase); if (!file) return false; nsCString name = FixName(aName); nsresult rv = file->AppendNative(name); if (!VerifyResult(rv, "AppendNative")) return false; bool exists; rv = file->Exists(&exists); if (!VerifyResult(rv, "Exists (before)")) return false; if (exists) { fail("%s File %s already exists", gFunction, name.get()); return false; } PRFileDesc* fileDesc; rv = file->OpenNSPRFileDesc(aFlags | nsIFile::DELETE_ON_CLOSE, aPerm, &fileDesc); if (!VerifyResult(rv, "OpenNSPRFileDesc")) return false; PRStatus status = PR_Close(fileDesc); if (status != PR_SUCCESS) { fail("%s File %s could not be closed", gFunction, name.get()); return false; } rv = file->Exists(&exists); if (!VerifyResult(rv, "Exists (after)")) return false; if (exists) { fail("%s File %s was not removed on close!", gFunction, name.get()); return false; } return true; }
STATIC SUFFIX *findSuffixNode( const char *name, const char **p ) /**************************************************************** * returns: pointer to SUFFIX named name, or NULL. If p != NULL, then * *p will be the pointer to the first dot not in the first * position of name. ie: * .src.dest returns SUFFIX src, and p = ".dest" * src.dest same * .src or src returns SUFFIX src, and p = NULL */ { char sufname[MAX_SUFFIX]; const char *s; char *d; assert( name != NULL ); if( name[0] == DOT ) { ++name; } d = sufname; s = name; while( *s != NULLCHAR && *s != DOT ) { *d++ = *s++; } *d = NULLCHAR; if( p != NULL ) { if( *s == DOT ) { *p = s; } else { *p = NULL; } } FixName( sufname ); return( (SUFFIX *)FindHashNode( sufTab, sufname, CASESENSITIVE ) ); }
STATIC enum cacheRet cacheDir( DHEADPTR *pdhead, char *path ) /************************************************************ * Given a full pathname or just a path ending in \ cache all the files * in that directory. Assumes that this directory is not already * cached. Does not link into list off cacheHead. */ { CENTRYPTR cnew; /* new cacheEntry struct */ DIR *parent; /* parent directory entry */ DIR *entry; /* current directory entry */ HASH_T h; /* hash value */ size_t len; #ifdef CACHE_STATS UINT32 bytes = 0; /* counter */ UINT32 files = 0; /* counter */ UINT32 hits = 0; /* counter */ if( Glob.cachestat ) { PrtMsg( INF | CACHING_DIRECTORY, path ); } #endif *pdhead = myMalloc( sizeof( **pdhead ) ); if( *pdhead == NULL ) { return( CACHE_NOT_ENUF_MEM ); } #ifdef CACHE_STATS bytes += sizeof( **pdhead ); #endif /* clear the memory */ _fmemset( *pdhead, 0, sizeof( **pdhead ) ); len = strlen( path ); _fmemcpy( (*pdhead)->dh_name, path, len + 1 ); strcpy( &path[len], "*.*" ); parent = opendir( path ); if( parent == NULL ) { #ifdef CACHE_STATS if( Glob.cachestat ) { PrtMsg( INF | NEOL | CACHE_FILES_BYTES, files, bytes, hits ); } #endif return( CACHE_OK ); /* an empty, or nonexistent directory */ } entry = readdir( parent ); while( entry != NULL ) { if( !(entry->d_attr & IGNORE_MASK) ) { /* we tromp on entry, and get hash value */ h = Hash( FixName( entry->d_name ), HASH_PRIME ); cnew = myMalloc( sizeof( *cnew ) ); if( cnew == NULL ) { freeDirectList( *pdhead ); /* roll back, and abort */ *pdhead = NULL; #ifdef CACHE_STATS if( Glob.cachestat ) { if( hits % 8 != 0 ) { PrtMsg( INF | NEWLINE ); } PrtMsg( INF | CACHE_MEM ); } #endif return( CACHE_NOT_ENUF_MEM ); } #ifdef CACHE_STATS bytes += sizeof( *cnew ); ++files; #endif cnew->ce_tt = _DOSStampToTime( entry->d_date, entry->d_time ); ConstMemCpy( cnew->ce_name, entry->d_name, NAME_MAX + 1 ); cnew->ce_next = (*pdhead)->dh_table[h]; (*pdhead)->dh_table[h] = cnew; #ifdef CACHE_STATS if( Glob.cachestat && cnew->ce_next != NULL ) { ++hits; PrtMsg( INF | ((hits % 8 == 0) ? 0 : NEOL) | HIT_ON_HASH, h ); } #endif } entry = readdir( parent ); } closedir( parent ); #ifdef CACHE_STATS if( Glob.cachestat ) { if( hits % 8 != 0 ) { PrtMsg( INF | NEWLINE ); } PrtMsg( INF | CACHE_FILES_BYTES, files, bytes, hits ); } #endif return( CACHE_OK ); }
void SMDImporter::CreateAnimationSource() { XSI::ActionSource actionSource; float animStart = 9999; float animEnd = -9999; XSI::CString animatedObjects; for (int c=0;c<m_pNodes.GetUsed();c++) { SMDNode* node = m_pNodes[c]; if ( node->m_pKeys.GetUsed() > 1 ) { if ( !actionSource.IsValid() ) { LPWSTR l_wszActionName; DSA2W(&l_wszActionName,m_szActionName); actionSource = m_pModel.AddActionSource( l_wszActionName ); } XSI::Parameter x = node->m_x3d.GetParameters().GetItem( L"posx" ); XSI::Parameter y = node->m_x3d.GetParameters().GetItem( L"posy" ); XSI::Parameter z = node->m_x3d.GetParameters().GetItem( L"posz" ); XSI::Parameter rx = node->m_x3d.GetParameters().GetItem( L"rotx" ); XSI::Parameter ry = node->m_x3d.GetParameters().GetItem( L"roty" ); XSI::Parameter rz = node->m_x3d.GetParameters().GetItem( L"rotz" ); node->m_fOldX = x.GetValue(); node->m_fOldY = y.GetValue(); node->m_fOldZ = z.GetValue(); node->m_fOldRX = rx.GetValue(); node->m_fOldRY = ry.GetValue(); node->m_fOldRZ = rz.GetValue(); XSI::FCurve fcrvx; x.AddFCurve( XSI::siStandardFCurve, fcrvx ); XSI::FCurve fcrvy; y.AddFCurve( XSI::siStandardFCurve, fcrvy ); XSI::FCurve fcrvz; z.AddFCurve( XSI::siStandardFCurve, fcrvz ); XSI::FCurve fcrvrx; rx.AddFCurve( XSI::siStandardFCurve, fcrvrx ); XSI::FCurve fcrvry; ry.AddFCurve( XSI::siStandardFCurve, fcrvry ); XSI::FCurve fcrvrz; rz.AddFCurve( XSI::siStandardFCurve, fcrvrz ); XSI::CTimeArray time(node->m_pKeys.GetUsed()); XSI::CValueArray xv(node->m_pKeys.GetUsed()); XSI::CValueArray yv(node->m_pKeys.GetUsed()); XSI::CValueArray zv(node->m_pKeys.GetUsed()); XSI::CValueArray rxv(node->m_pKeys.GetUsed()); XSI::CValueArray ryv(node->m_pKeys.GetUsed()); XSI::CValueArray rzv(node->m_pKeys.GetUsed()); if ( node->m_pParent ==NULL ) { for (int k=0;k<node->m_pKeys.GetUsed();k++) { if ( node->GetKey(k)->m_fTime < animStart ) { animStart = node->GetKey(k)->m_fTime; } if ( node->GetKey(k)->m_fTime > animEnd ) { animEnd = node->GetKey(k)->m_fTime; } XSI::MATH::CTransformation xfo1; XSI::MATH::CTransformation xfo2; xfo1.SetRotationFromXYZAnglesValues ( node->GetKey(k)->m_vRotation.GetX(), node->GetKey(k)->m_vRotation.GetY(), node->GetKey(k)->m_vRotation.GetZ() ); xfo1.SetTranslationFromValues ( node->GetKey(k)->m_vPosition.GetX(), node->GetKey(k)->m_vPosition.GetY(), node->GetKey(k)->m_vPosition.GetZ() ); xfo2.SetRotationFromXYZAnglesValues ( -1.570796, 0.0, 0.0 ); xfo1.MulInPlace(xfo2); double dx,dy,dz; double drx, dry, drz; xfo1.GetTranslationValues ( dx, dy, dz); xfo1.GetRotationFromXYZAnglesValues(drx, dry, drz); time[k] = k; xv[k] = dx; yv[k] = dy; zv[k] = dz; rxv[k] = drx * 57.29577951308232286465; ryv[k] = dry * 57.29577951308232286465; rzv[k] = drz * 57.29577951308232286465; } } else { for (int k=0;k<node->m_pKeys.GetUsed();k++) { if ( node->GetKey(k)->m_fTime < animStart ) { animStart = node->GetKey(k)->m_fTime; } if ( node->GetKey(k)->m_fTime > animEnd ) { animEnd = node->GetKey(k)->m_fTime; } time[k] = k; xv[k] = node->GetKey(k)->m_vPosition.GetX(); yv[k] = node->GetKey(k)->m_vPosition.GetY(); zv[k] = node->GetKey(k)->m_vPosition.GetZ(); rxv[k] = node->GetKey(k)->m_vRotation.GetX() * 57.29577951308232286465; ryv[k] = node->GetKey(k)->m_vRotation.GetY() * 57.29577951308232286465; rzv[k] = node->GetKey(k)->m_vRotation.GetZ() * 57.29577951308232286465; } } fcrvx.SetKeys ( time, xv ); fcrvy.SetKeys ( time, yv ); fcrvz.SetKeys ( time, zv ); fcrvrx.SetKeys ( time, rxv ); fcrvry.SetKeys ( time, ryv ); fcrvrz.SetKeys ( time, rzv ); LPWSTR l_wszModelName; DSA2W(&l_wszModelName,FixName(node->m_szName)); XSI::CString cname = l_wszModelName; actionSource.AddSourceItem ( cname + L".kine.local.posx", fcrvx, true ); actionSource.AddSourceItem ( cname + L".kine.local.posy", fcrvy, true ); actionSource.AddSourceItem ( cname + L".kine.local.posz", fcrvz, true ); actionSource.AddSourceItem ( cname + L".kine.local.rotx", fcrvrx, true ); actionSource.AddSourceItem ( cname + L".kine.local.roty", fcrvry, true ); actionSource.AddSourceItem ( cname + L".kine.local.rotz", fcrvrz, true ); // build up the string list of objects that we want to remove animation from if (animatedObjects.IsEmpty() == false) { animatedObjects += L", "; } animatedObjects += node->m_x3d.GetFullName(); } } if ( actionSource.IsValid() ) { actionSource.PutParameterValue(L"FrameStart", (double)animStart); actionSource.PutParameterValue(L"FrameEnd", (double)animEnd); } // remove animation on all objects that were imported // and animated if (animatedObjects.IsEmpty() == false) { XSI::Application app; XSI::CValue out; XSI::CValueArray args(4); args[0] = animatedObjects; args[1] = XSI::CValue(); args[2] = (long)XSI::siBranch; args[3] = (long)(XSI::siFCurveSource); app.ExecuteCommand(L"RemoveAllAnimation", args, out); } }
void SMDImporter::CreateGeometry() { if ( !m_pTriangles.GetUsed() ) return; long t; XSI::MATH::CTransformation xfo; xfo.SetRotationFromXYZAnglesValues ( -1.570796, 0.0, 0.0 ); for (t=0;t<m_pTriangles.GetUsed();t++) { for (int v=0;v<3;v++) { XSI::MATH::CVector3 vec = XSI::MATH::MapObjectPositionToWorldSpace ( xfo, m_pTriangles[t]->m_pVertex[v].m_vPosition ); long outindex; compress.AddVertex ( vec.GetX(), vec.GetY(), vec.GetZ(), m_pTriangles[t]->m_pVertex[v].m_vUV.GetX(), m_pTriangles[t]->m_pVertex[v].m_vUV.GetY(), &m_pTriangles[t]->m_pVertex[v], &outindex); m_lVertexMap.Extend(1); m_lVertexMap[m_lVertexMap.GetUsed()-1] = outindex; } } XSI::MATH::CVector3Array verts(compress.GetCount()); long vindex = 0; long cnt = compress.GetCount (); for (t=0;t<compress.GetCount ();t++) { uvvec vec; compress.GetVertex (t, &vec); verts[t] = XSI::MATH::CVector3 ( vec.x, vec.y, vec.z ); } XSI::CLongArray indices((m_pTriangles.GetUsed() * 3) + m_pTriangles.GetUsed()); long iindex = 0; char *l_szGlobalTexture = m_pTriangles[0]->m_szTexture; CSIBCArray<TriCluster> ClusterList; for (t=0;t<m_pTriangles.GetUsed();t++) { XSI::MATH::CVector3 vec1 = XSI::MATH::MapObjectPositionToWorldSpace ( xfo, m_pTriangles[t]->m_pVertex[0].m_vPosition ); XSI::MATH::CVector3 vec2 = XSI::MATH::MapObjectPositionToWorldSpace ( xfo, m_pTriangles[t]->m_pVertex[1].m_vPosition ); XSI::MATH::CVector3 vec3 = XSI::MATH::MapObjectPositionToWorldSpace ( xfo, m_pTriangles[t]->m_pVertex[2].m_vPosition ); long i1 = compress.GetIndex ( vec1.GetX(), vec1.GetY(), vec1.GetZ(), m_pTriangles[t]->m_pVertex[0].m_vUV.GetX(), m_pTriangles[t]->m_pVertex[0].m_vUV.GetY()); long i2 = compress.GetIndex ( vec2.GetX(), vec2.GetY(), vec2.GetZ(), m_pTriangles[t]->m_pVertex[1].m_vUV.GetX(), m_pTriangles[t]->m_pVertex[1].m_vUV.GetY()); long i3 = compress.GetIndex ( vec3.GetX(), vec3.GetY(), vec3.GetZ(), m_pTriangles[t]->m_pVertex[2].m_vUV.GetX(), m_pTriangles[t]->m_pVertex[2].m_vUV.GetY()); indices[iindex] = 3; indices[iindex+1] = i1; indices[iindex+2] = i2; indices[iindex+3] = i3; iindex += 4; if ( strcmp ( l_szGlobalTexture, m_pTriangles[t]->m_szTexture )) { // // found a local material // TriCluster* cls = NULL; for (int c=0;c<ClusterList.GetUsed();c++) { if ( !strcmp ( ClusterList[c].m_szName, m_pTriangles[t]->m_szTexture)) { cls = &ClusterList[c]; break; } } if ( cls == NULL ) { ClusterList.Extend(1); strcpy ( ClusterList[ClusterList.GetUsed()-1].m_szName, m_pTriangles[t]->m_szTexture ); cls = &ClusterList[ClusterList.GetUsed()-1]; } cls->m_indices.Add ( t ); } } char mname[1024]; sprintf (mname, "mesh" ); if ( m_pMeshNode ) { sprintf (mname, FixName(m_pMeshNode->m_szName)); } LPWSTR l_wszModelName; DSA2W(&l_wszModelName,mname); m_pModel.AddPolygonMesh ( verts, indices, l_wszModelName, m_pMesh ); XSI::Application app; XSI::CValueArray args(4); XSI::CValue outArg; XSI::CStatus st; args[0] = XSI::CValue( XSI::CString(L"") ); args[1] = XSI::CValue(false); args[0] = XSI::CValue(m_pMesh.GetRef()); args[1] = XSI::CValue((long)XSI::siTxtUV); args[2] = XSI::CValue((long)XSI::siTxtDefaultSpherical); args[3] = XSI::CValue(XSI::CString(L"Texture_Support")); app.ExecuteCommand( L"CreateTextureSupport", args, outArg ); XSI::CValueArray moreargs(1); XSI::CValueArray moreoutargs(3); moreargs[0] = m_pMesh.GetRef(); app.ExecuteCommand(L"FreezeObj",moreargs, outArg); XSI::Material l_matMaterial; st = m_pMesh.AddMaterial(L"Phong", true, L"CubeMat", l_matMaterial); XSI::OGLTexture l_oglTexture(l_matMaterial.GetOGLTexture()); XSI::CString l_szFullNameDefaultOut = l_oglTexture.GetFullName(); int l_nHeightDefaultOut = l_oglTexture.GetHeight(); int l_nWidthDefaultOut = l_oglTexture.GetWidth(); // Now actually add a texture, so we can test it. args[0] = XSI::CValue( XSI::CString(L"Image") ); args[1] = XSI::CValue(m_pMesh.GetRef()); args[2] = XSI::CValue((short)1); args[3] = XSI::CValue(false); st = app.ExecuteCommand( L"BlendInPresets", args, outArg ); // // create the texture and connect // XSI::CValueArray clipargs(3); XSI::ImageClip2 l_pClip; char l_szTextureFullname[1024]; sprintf ( l_szTextureFullname, "%s%s", m_szDirectory, m_pTriangles[0]->m_szTexture); char clipname[1024]; _splitpath ( m_pTriangles[0]->m_szTexture, NULL, NULL, clipname, NULL ); LPWSTR l_wszClipName; DSA2W(&l_wszClipName,l_szTextureFullname); LPWSTR l_wszClipName2; DSA2W(&l_wszClipName2,clipname); clipargs[0] = XSI::CValue( XSI::CString(l_wszClipName) ); clipargs[1] = XSI::CValue( XSI::CString(l_wszClipName2) ); clipargs[2] = XSI::CValue(l_pClip.GetRef()); app.ExecuteCommand( L"SICreateImageClip", clipargs, outArg ); XSI::CString l_szMaterialName = l_matMaterial.GetFullName(); XSI::CString l_szImageNode = l_szMaterialName + L".CubeMat.ambient_blend.Image.tex"; XSI::CString l_szFullclipname = L"Clips." + XSI::CString(l_wszClipName2); XSI::CValueArray clipargs2(2); clipargs2[0] = XSI::CValue( XSI::CString(l_szFullclipname) ); clipargs2[1] = XSI::CValue( XSI::CString(l_szImageNode) ); app.ExecuteCommand( L"SIConnectShaderToCnxPoint", clipargs2, outArg ); // // Create all clusters // XSI::Geometry geom( m_pMesh.GetActivePrimitive().GetGeometry() ); for (int b=0;b<ClusterList.GetUsed();b++) { TriCluster* cls = &ClusterList[b]; sprintf ( l_szTextureFullname, "%s%s", m_szDirectory, cls->m_szName); _splitpath ( cls->m_szName, NULL, NULL, clipname, NULL ); DSA2W(&l_wszClipName,l_szTextureFullname); DSA2W(&l_wszClipName2,clipname); XSI::CLongArray array; XSI::Cluster polyCluster ; geom.AddCluster( XSI::siPolygonCluster, l_wszClipName2, cls->m_indices, polyCluster ) ; st = polyCluster.AddMaterial(L"Phong", true, L"CubeMat", l_matMaterial); XSI::OGLTexture l_oglTexture(l_matMaterial.GetOGLTexture()); // Now actually add a texture, so we can test it. args[0] = XSI::CValue( XSI::CString(L"Image") ); args[1] = XSI::CValue(polyCluster.GetRef()); args[2] = XSI::CValue((short)1); args[3] = XSI::CValue(false); st = app.ExecuteCommand( L"BlendInPresets", args, outArg ); clipargs[0] = XSI::CValue( XSI::CString(l_wszClipName) ); clipargs[1] = XSI::CValue( XSI::CString(l_wszClipName2) ); clipargs[2] = XSI::CValue(l_pClip.GetRef()); app.ExecuteCommand( L"SICreateImageClip", clipargs, outArg ); l_szMaterialName = l_matMaterial.GetFullName(); l_szImageNode = l_szMaterialName + L".CubeMat.ambient_blend.Image.tex"; l_szFullclipname = L"Clips." + XSI::CString(l_wszClipName2); clipargs2[0] = XSI::CValue( XSI::CString(l_szFullclipname) ); clipargs2[1] = XSI::CValue( XSI::CString(l_szImageNode) ); app.ExecuteCommand( L"SIConnectShaderToCnxPoint", clipargs2, outArg ); } if ( m_pMesh.IsValid () ) { XSI::Geometry geom( m_pMesh.GetActivePrimitive().GetGeometry() ); XSI::PolygonMesh mesh(m_pMesh.GetActivePrimitive().GetGeometry()); XSI::CPointRefArray Geompoints = geom.GetPoints(); XSI::CTriangleRefArray triangles(geom.GetTriangles()); XSI::ClusterProperty UVWProp(m_pMesh.GetMaterial().GetCurrentUV()); if ( UVWProp.IsValid() ) { XSI::CClusterPropertyElementArray clusterPropertyElements = UVWProp.GetElements(); XSI::CDoubleArray elementArray = clusterPropertyElements.GetArray(); long totalUvCount = elementArray.GetCount (); int cc=0; int uvc = 0; for (int c=0;c<m_pTriangles.GetUsed();c++) { long l_iNumVertex = indices[cc]; cc++; for (int i=0;i<l_iNumVertex;i++) { long l_iID = indices[cc]; cc++; uvvec vec; compress.GetVertex (l_iID, &vec); elementArray[ uvc * 3 ] = vec.u; elementArray[ (uvc * 3) + 1] = vec.v; elementArray[ (uvc * 3) + 2] = 0.0f; uvc++; } } clusterPropertyElements.PutArray(elementArray); } } }
STATIC RET_T imply( TARGET *targ, const char *drive, const char *dir, const char *fname, const char *ext, bool must ) /******************************************************************** * targ is the target to be implied * drive is the drive of the target * dir is the path of the target * fname is the portion of targ's name without the extension * ext is the extension of targ's name * must must we make this target? * * RET_SUCCESS - performed cmds, * RET_WARN unable to imply, * RET_ERROR - perform failed */ { SUFFIX *srcsuf; CREATOR *cur; SUFFIX *cursuf; TARGET *imptarg = NULL; RET_T ret; bool newtarg; UINT32 startcount; char *buf; SLIST *curslist; SLIST *slist; // Slist chosen for sufsuf SLIST *slistDef; // Slist that has dependent path = "" SLIST *slistEmptyTargDepPath; bool UseDefaultSList; int slistCount; srcsuf = FindSuffix( ext ); if( srcsuf == NULL || srcsuf->creator == NULL ) { PrtMsg( DBG | INF | IMP_ENV_M, targ->node.name, M_HAS_NO_IMPLICIT ); return( RET_WARN ); } PrtMsg( DBG | INF | IMP_ENV_M, targ->node.name, M_CHECKING_IMPLICIT ); startcount = cListCount; for( cur = srcsuf->creator; cur != NULL; cur = cur->next ) { cursuf = cur->suffix; /* allocate a buffer */ buf = MallocSafe( _MAX_PATH ); slist = NULL; slistDef = NULL; slistEmptyTargDepPath = NULL; ret = RET_ERROR; UseDefaultSList = true; /* find path in SLIST */ slistCount = 0; for( curslist = cur->slist; curslist != NULL && ret != RET_SUCCESS; curslist = curslist->next ) { _makepath( buf, drive, dir, NULL, NULL ); FixName( buf ); /* * note the path of the current target must match the * path as specified in the slist */ if( stricmp( buf, curslist->targ_path ) == 0 ) { /* build filename for implied target */ _makepath( buf, NULL, curslist->dep_path, fname, cursuf->node.name ); /* try to find this file on path or in targets */ ret = TrySufPath( buf, buf, &imptarg, false ); if( ret == RET_SUCCESS ) { slist = curslist; /* later on we need to check if implied target does not */ /* exist we need to create it on the first directory we */ /* see on the SLIST since */ /* the first on the list is the one that was defined */ /* last in the makefile */ } else if( slistDef == NULL ) { slistDef = curslist; } } if( *curslist->targ_path == NULLCHAR && *curslist->dep_path == NULLCHAR ) { slistEmptyTargDepPath = curslist; } if( slistCount > 0 && slistEmptyTargDepPath != NULL ) { UseDefaultSList = false; } ++slistCount; } if( UseDefaultSList && slist == NULL && !Glob.compat_nmake ) { _makepath( buf, NULL, NULL, fname, cursuf->node.name ); /* try to find this file on path or in targets */ ret = TrySufPath( buf, buf, &imptarg, false ); switch( ret ) { case RET_WARN: break; case RET_ERROR: if( !Glob.compat_nmake ) { slistDef = slistEmptyTargDepPath; } break; case RET_SUCCESS: slist = slistEmptyTargDepPath; break; } } if( ret == RET_ERROR && slistDef == NULL ) { /* * No Default Slist found so must continue and find * another slist */ FreeSafe( buf ); continue; } if( (ret == RET_SUCCESS && imptarg == NULL) || ret == RET_ERROR ) { /* Either file doesn't exist, or it exists and we don't already * have a target for it. Either way, we create a new target. */ if( ret == RET_ERROR ) { slist = slistDef; /* file doesn't exist, assume in directory */ /* pointed to by the slistDef */ _makepath( buf, NULL, slist->dep_path, fname, cursuf->node.name ); } newtarg = true; imptarg = NewTarget( buf ); FreeSafe( buf ); /* don't need any more */ getStats( imptarg ); imptarg->busy = true; /* protect against recursion */ if( imply( imptarg, NULL, slist->dep_path, fname, cursuf->node.name, false ) == RET_ERROR ) { imptarg->error = true; } if( startcount != cListCount && (Glob.noexec || Glob.query) ) { imptarg->touched = true; imptarg->executed = true; } imptarg->updated = true; imptarg->busy = false; } else { /* We already know about imptarg, so just update it */ assert( imptarg != NULL ); FreeSafe( buf ); /* don't need any more */ newtarg = false; /* this isn't a new target */ Update( imptarg ); } /* We've tried our best to make the imptarg, check if it exists * after our efforts. */ if( targExists( imptarg ) ) { /* it exists - now we perform the implicit cmd list, and return */ ret = implyMaybePerform( targ, imptarg, slist->cretarg, must ); if( newtarg && !Glob.noexec ) { /* destroy the implied target, because the info in the target * structure is nicely stored on disk (unless Glob.noexec) */ KillTarget( imptarg->node.name ); } implyDebugInfo( targ, startcount ); return( ret ); } else if( newtarg ) { /* we created an unsuccessful target - so destroy it */ KillTarget( imptarg->node.name ); } /* We couldn't imply with this suffix... try next one */ } implyDebugInfo( targ, startcount ); return( RET_WARN ); }
void ModuleManager::Add(Module* module) { // Add to list of modules std::string name = module->GetName(); FixName(name); moduleList[name] = module; }