6969# define new _new
7070#endif
7171
72+ extern bool gTryUseDSQs ;
7273
7374MODULE_BEGIN ( AssimpShapeLoader )
7475 MODULE_INIT_AFTER( ShapeLoader )
@@ -664,13 +665,12 @@ bool AssimpShapeLoader::fillGuiTreeView(const char* sourceShapePath, GuiTreeView
664665 return true ;
665666}
666667
667- // / Check if an up-to-date cached DTS is available for this DAE file
668+ // / Check if an up-to-date cached DTS is available for this file
668669bool AssimpShapeLoader::canLoadCachedDTS (const Torque::Path& path)
669670{
670671 // Generate the cached filename
671672 Torque::Path cachedPath (path);
672- if (String::compare (path.getExtension (), " dsq" ) != 0 )
673- cachedPath.setExtension (" cached.dts" );
673+ cachedPath.setExtension (" cached.dts" );
674674
675675 // Check if a cached DTS newer than this file is available
676676 FileTime cachedModifyTime;
@@ -689,6 +689,30 @@ bool AssimpShapeLoader::canLoadCachedDTS(const Torque::Path& path)
689689 return false ;
690690}
691691
692+ // / Check if an up-to-date cached DSQ is available for this file
693+ bool AssimpShapeLoader::canLoadCachedDSQ (const Torque::Path& path)
694+ {
695+ // Generate the cached filename
696+ Torque::Path cachedPath (path);
697+ cachedPath.setExtension (" dsq" );
698+
699+ // Check if a cached DTS newer than this file is available
700+ FileTime cachedModifyTime;
701+ if (Platform::getFileTimes (cachedPath.getFullPath (), NULL , &cachedModifyTime))
702+ {
703+ bool forceLoad = Con::getBoolVariable (" $assimp::forceLoad" , false );
704+
705+ FileTime daeModifyTime;
706+ if (!Platform::getFileTimes (path.getFullPath (), NULL , &daeModifyTime) ||
707+ (!forceLoad && (Platform::compareFileTimes (cachedModifyTime, daeModifyTime) >= 0 )))
708+ {
709+ // Original file not found, or cached DTS is newer
710+ return true ;
711+ }
712+ }
713+ return false ;
714+ }
715+
692716void AssimpShapeLoader::assimpLogCallback (const char * message, char * user)
693717{
694718 Con::printf (" [Assimp log message] %s" , StringUnit::getUnit (message, 0 , " \n " ));
@@ -973,30 +997,37 @@ TSShape* assimpLoadShape(const Torque::Path &path)
973997 // TODO: add .cached.dts generation.
974998 // Generate the cached filename
975999 Torque::Path cachedPath (path);
976- if ( String::compare (path. getExtension (), " dsq " ) != 0 )
977- cachedPath. setExtension ( " cached.dts " ) ;
1000+ bool canLoadCached = false ;
1001+ bool canLoadDSQ = false ;
9781002
9791003 // Check if an up-to-date cached DTS version of this file exists, and
9801004 // if so, use that instead.
9811005 if (AssimpShapeLoader::canLoadCachedDTS (path))
1006+ {
1007+ cachedPath.setExtension (" cached.dts" );
1008+ canLoadCached = true ;
1009+ }
1010+ else if (gTryUseDSQs && AssimpShapeLoader::canLoadCachedDSQ (path))
1011+ {
1012+ cachedPath.setExtension (" dsq" );
1013+ canLoadDSQ = true ;
1014+ }
1015+ if (canLoadCached || canLoadDSQ)
9821016 {
9831017 FileStream cachedStream;
9841018 cachedStream.open (cachedPath.getFullPath (), Torque::FS::File::Read);
9851019 if (cachedStream.getStatus () == Stream::Ok)
9861020 {
9871021 TSShape *shape = new TSShape;
988- if (String::compare (path.getExtension (), " dsq" ) == 0 )
1022+ bool readSuccess = false ;
1023+ if (canLoadCached)
9891024 {
990- if (!shape->importSequences (&cachedStream, cachedPath.getFullPath ()))
991- {
992- Con::errorf (" assimpLoadShape: Load sequence file '%s' failed" , cachedPath.getFullPath ().c_str ());
993- delete shape;
994- shape = NULL ;
995- }
996- cachedStream.close ();
997- return shape;
1025+ readSuccess = shape->read (&cachedStream);
1026+ }
1027+ else
1028+ {
1029+ readSuccess = shape->importSequences (&cachedStream, cachedPath);
9981030 }
999- bool readSuccess = shape->read (&cachedStream);
10001031 cachedStream.close ();
10011032
10021033 if (readSuccess)
@@ -1007,10 +1038,13 @@ TSShape* assimpLoadShape(const Torque::Path &path)
10071038 return shape;
10081039 }
10091040 else
1041+ {
1042+ #ifdef TORQUE_DEBUG
1043+ Con::errorf (" assimpLoadShape: Load sequence file '%s' failed" , cachedPath.getFullPath ().c_str ());
1044+ #endif
10101045 delete shape;
1046+ }
10111047 }
1012-
1013- Con::warnf (" Failed to load cached shape from %s" , cachedPath.getFullPath ().c_str ());
10141048 }
10151049
10161050 if (!Torque::FS::IsFile (path))
@@ -1041,27 +1075,22 @@ TSShape* assimpLoadShape(const Torque::Path &path)
10411075 realMesh = true ;
10421076 }
10431077
1044- if (!realMesh)
1078+ if (!realMesh && gTryUseDSQs )
10451079 {
10461080 Torque::Path dsqPath (cachedPath);
10471081 dsqPath.setExtension (" dsq" );
10481082 FileStream animOutStream;
1049- for (S32 i = 0 ; i < tss->sequences .size (); i++)
1083+ dsqPath.setFileName (cachedPath.getFileName ());
1084+ if (animOutStream.open (dsqPath.getFullPath (), Torque::FS::File::Write))
10501085 {
1051- const String& seqName = tss->getName (tss->sequences [i].nameIndex );
1052- Con::printf (" Writing DSQ Animation File for sequence '%s'" , seqName.c_str ());
1053-
1054- dsqPath.setFileName (cachedPath.getFileName () + " _" + seqName);
1055- if (animOutStream.open (dsqPath.getFullPath (), Torque::FS::File::Write))
1056- {
1057- tss->exportSequence (&animOutStream, tss->sequences [i], false );
1058- animOutStream.close ();
1059- }
1060-
1086+ Con::printf (" Writing DSQ Animation File for '%s'" , dsqPath.getFileName ().c_str ());
1087+ tss->exportSequences (&animOutStream);
10611088 }
10621089 }
10631090 else
10641091 {
1092+ // Cache the model to a DTS file for faster loading next time.
1093+ cachedPath.setExtension (" cached.dts" );
10651094 // Cache the model to a DTS file for faster loading next time.
10661095 FileStream dtsStream;
10671096 if (dtsStream.open (cachedPath.getFullPath (), Torque::FS::File::Write))
0 commit comments