Skip to content

Commit 92e32aa

Browse files
authored
Merge pull request #1724 from marauder2k9-torque/TSShapeResource-Loaders-Exporters-Assimp
Groundwork for exporters and standardizing tsshape resource loading
2 parents aacb9b7 + d6c32f3 commit 92e32aa

19 files changed

Lines changed: 630 additions & 444 deletions

Engine/lib/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,15 @@ IF(MSVC)
143143
advanced_option( ASSIMP_INSTALL_PDB "Install MSVC debug files." ON )
144144
endif()
145145
advanced_option(ASSIMP_RAPIDJSON_NO_MEMBER_ITERATOR "Suppress rapidjson warning on MSVC (NOTE: breaks android build)" ON )
146-
advanced_option(ASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT "default value of all ASSIMP_BUILD_XXX_IMPORTER values" ON)
147-
advanced_option(ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT "default value of all ASSIMP_BUILD_XXX_EXPORTER values" ON)
146+
advanced_option(ASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT "default value of all ASSIMP_BUILD_XXX_IMPORTER values" OFF)
147+
advanced_option(ASSIMP_BUILD_FBX_IMPORTER "FBX Importer" ON)
148+
advanced_option(ASSIMP_BUILD_GLTF_IMPORTER "GLTF Importer" ON)
149+
advanced_option(ASSIMP_BUILD_OBJ_IMPORTER "OBJ Importer" ON)
150+
advanced_option(ASSIMP_BUILD_BLEND_IMPORTER "BLENDER Importer" ON)
151+
advanced_option(ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT "default value of all ASSIMP_BUILD_XXX_EXPORTER values" OFF)
152+
advanced_option(ASSIMP_BUILD_FBX_EXPORTER "FBX Importer" ON)
153+
advanced_option(ASSIMP_BUILD_GLTF_EXPORTER "GLTF Importer" ON)
154+
advanced_option(ASSIMP_BUILD_OBJ_EXPORTER "OBJ Importer" ON)
148155
mark_as_advanced(ASSIMP_ARCHIVE_OUTPUT_DIRECTORY)
149156
mark_as_advanced(ASSIMP_BIN_INSTALL_DIR)
150157
mark_as_advanced(ASSIMP_LIB_INSTALL_DIR)

Engine/source/T3D/assets/assetImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ void AssetImporter::processShapeAsset(AssetImportObject* assetItem)
20122012
{
20132013
enumColladaForImport(filePath, shapeInfo, false);
20142014
}
2015-
else if ((fileExt.compare("dts") == 0) || (fileExt.compare("dsq") == 0))
2015+
else if ((fileExt.compare("dts") == 0))
20162016
{
20172017
enumDTSForImport(filePath, shapeInfo);
20182018
}

Engine/source/gui/editor/guiShapeEdPreview.cpp

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,53 @@ bool GuiShapeEdPreview::setObjectModel(const char* modelName)
405405
return true;
406406
}
407407

408+
bool GuiShapeEdPreview::findCompanionShape(const Torque::Path& dsqPath, Torque::Path& outShapePath)
409+
{
410+
// AssimpLoader and ColladaLoader exports as "modelname_sequencename.dsq" alongside "modelname.cached.dts"
411+
// so strip everything from the last underscore to find the base name
412+
String fileName = dsqPath.getFileName();
413+
String::SizeType sep = fileName.find('_',0, String::Right);
414+
415+
if (sep != String::NPos)
416+
{
417+
Torque::Path candidate(dsqPath);
418+
candidate.setFileName(fileName.substr(0, sep));
419+
420+
candidate.setExtension("cached.dts");
421+
if (Torque::FS::IsFile(candidate.getFullPath()))
422+
{
423+
outShapePath = candidate;
424+
return true;
425+
}
426+
427+
candidate.setExtension("dts");
428+
if (Torque::FS::IsFile(candidate.getFullPath()))
429+
{
430+
outShapePath = candidate;
431+
return true;
432+
}
433+
}
434+
435+
// fallback: same filename, just swap extension
436+
Torque::Path direct(dsqPath);
437+
438+
direct.setExtension("cached.dts");
439+
if (Torque::FS::IsFile(direct.getFullPath()))
440+
{
441+
outShapePath = direct;
442+
return true;
443+
}
444+
445+
direct.setExtension("dts");
446+
if (Torque::FS::IsFile(direct.getFullPath()))
447+
{
448+
outShapePath = direct;
449+
return true;
450+
}
451+
452+
return false;
453+
}
454+
408455
bool GuiShapeEdPreview::setObjectShapeAsset(const char* assetId)
409456
{
410457
SAFE_DELETE(mModel);
@@ -422,16 +469,74 @@ bool GuiShapeEdPreview::setObjectShapeAsset(const char* assetId)
422469
ShapeAsset* asset = AssetDatabase.acquireAsset<ShapeAsset>(id);
423470
modelName = asset->getShapeFile();
424471
AssetDatabase.releaseAsset(id);
472+
return setObjectModel(modelName);
425473
}
426474
else if (assetType == StringTable->insert("ShapeAnimationAsset"))
427475
{
428476
ShapeAnimationAsset* asset = AssetDatabase.acquireAsset<ShapeAnimationAsset>(id);
429-
modelName = asset->getAnimationPath();
477+
StringTableEntry animPath = asset->getAnimationPath();
430478
AssetDatabase.releaseAsset(id);
479+
Torque::Path dsqPath(animPath);
480+
String fileExt = String::ToLower(dsqPath.getExtension());
481+
482+
if (fileExt != String("dsq"))
483+
{
484+
return setObjectModel(animPath);
485+
}
486+
487+
Torque::Path shapePath;
488+
if (!findCompanionShape(dsqPath, shapePath))
489+
{
490+
Con::warnf("GuiShapeEdPreview::setObjectShapeAsset - "
491+
"No companion shape found for '%s'", animPath);
492+
return false;
493+
}
494+
495+
if (!setObjectModel(shapePath.getFullPath()))
496+
{
497+
Con::warnf("GuiShapeEdPreview::setObjectShapeAsset - "
498+
"Could not load companion shape for '%s'", animPath);
499+
return false;
500+
}
501+
502+
FileStream dsqStream;
503+
if (!dsqStream.open(animPath, Torque::FS::File::Read))
504+
{
505+
Con::warnf("GuiShapeEdPreview::setObjectShapeAsset - "
506+
"Could not open '%s'", animPath);
507+
SAFE_DELETE(mModel);
508+
return false;
509+
}
510+
511+
TSShape* shape = mModel->getShape();
512+
513+
bool ok = shape->importSequences(&dsqStream, String(animPath));
514+
dsqStream.close();
515+
516+
if (!ok)
517+
{
518+
Con::warnf("GuiShapeEdPreview::setObjectShapeAsset - "
519+
"importSequences failed for '%s'", animPath);
520+
SAFE_DELETE(mModel);
521+
return false;
522+
}
523+
524+
setAllMeshesHidden(true);
525+
mRenderNodes = true;
526+
if (shape->sequences.size() > 0)
527+
{
528+
// importSequences appends, so the new one is always last
529+
const String& seqName = shape->getSequenceName(shape->sequences.size() - 1);
530+
addThread();
531+
mActiveThread = 0;
532+
setActiveThreadSequence(seqName.c_str(), 0.0f, 0.0f, true);
533+
}
534+
535+
return true;
431536
}
432537
}
433538

434-
return setObjectModel(modelName);
539+
return false;
435540
}
436541

437542
void GuiShapeEdPreview::_onResourceChanged(const Torque::Path& path)

Engine/source/gui/editor/guiShapeEdPreview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class GuiShapeEdPreview : public EditTSCtrl
199199

200200
void setCurrentDetail(S32 dl);
201201
bool setObjectModel(const char * modelName);
202+
bool findCompanionShape(const Torque::Path& dsqPath, Torque::Path& outShapePath);
202203
bool setObjectShapeAsset(const char* assetId);
203204

204205
void _onResourceChanged(const Torque::Path& path);

Engine/source/ts/assimp/assimpAppMesh.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
bool AssimpAppMesh::fixedSizeEnabled = false;
4646
S32 AssimpAppMesh::fixedSize = 2;
47+
Vector<S32> AssimpAppMesh::sMaterialRemap;
4748

4849
//------------------------------------------------------------------------------
4950

@@ -164,7 +165,8 @@ void AssimpAppMesh::lockMesh(F32 t, const MatrixF& objOffset)
164165
primitives.increment();
165166
TSDrawPrimitive& primitive = primitives.last();
166167
primitive.start = 0;
167-
primitive.matIndex = (TSDrawPrimitive::Triangles | TSDrawPrimitive::Indexed) | (S32)mMeshData->mMaterialIndex;
168+
S32 mappedMat = (mMeshData->mMaterialIndex < (U32)AssimpAppMesh::sMaterialRemap.size()) ? AssimpAppMesh::sMaterialRemap[mMeshData->mMaterialIndex] : TSDrawPrimitive::NoMaterial;
169+
primitive.matIndex = (TSDrawPrimitive::Triangles | TSDrawPrimitive::Indexed) | mappedMat;
168170
primitive.numElements = indicesCount;
169171

170172
for ( U32 n = 0; n < mMeshData->mNumFaces; ++n)

Engine/source/ts/assimp/assimpAppMesh.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class AssimpAppMesh : public AppMesh
119119
/// @return The mesh transform at the specified time
120120
MatrixF getMeshTransform(F32 time) override;
121121
F32 getVisValue(F32 t) override;
122+
123+
static Vector<S32> sMaterialRemap;
122124
};
123125

124126
#endif // _COLLADA_APPMESH_H_

0 commit comments

Comments
 (0)