Skip to content

Commit ec2a55c

Browse files
committed
few fixes
Only export DSQ if we have a realmesh to pair with it. When looking for the companion shape use the last '_' to strip instead of the first
1 parent 2895e98 commit ec2a55c

4 files changed

Lines changed: 113 additions & 7 deletions

File tree

Engine/source/gui/editor/guiShapeEdPreview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ bool GuiShapeEdPreview::findCompanionShape(const Torque::Path& dsqPath, Torque::
410410
// AssimpLoader and ColladaLoader exports as "modelname_sequencename.dsq" alongside "modelname.cached.dts"
411411
// so strip everything from the last underscore to find the base name
412412
String fileName = dsqPath.getFileName();
413-
String::SizeType sep = fileName.find('_');
413+
String::SizeType sep = fileName.find('_',0, String::Right);
414414

415415
if (sep != String::NPos)
416416
{

Engine/source/ts/assimp/assimpShapeLoader.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,22 @@ static bool sReadAssimp(const Torque::Path &path, TSShape*& res_shape)
991991
if (tss)
992992
{
993993
TSShapeLoader::updateProgress(TSShapeLoader::Load_Complete, "Import complete");
994-
Con::printf("[ASSIMP] Shape created successfully.");
994+
995+
bool realMesh = false;
996+
for (U32 i = 0; i < tss->meshes.size(); ++i)
997+
{
998+
if (tss->meshes[i] && tss->meshes[i]->getMeshType() != TSMesh::NullMeshType)
999+
{
1000+
realMesh = true;
1001+
break;
1002+
}
1003+
}
1004+
1005+
1006+
if (realMesh)
1007+
Con::printf("[ASSIMP] Shape created successfully.");
1008+
else
1009+
Con::printf("[ASSIMP] Animation created successfully.");
9951010

9961011
Torque::Path cachedPath(path);
9971012
// Cache the model to a DTS file for faster loading next time.
@@ -1004,7 +1019,8 @@ static bool sReadAssimp(const Torque::Path &path, TSShape*& res_shape)
10041019
tss->write(&dtsStream);
10051020
}
10061021

1007-
if (tss->sequences.size() > 0)
1022+
// only save dsq if we have a real mesh to pair with it.
1023+
if (tss->sequences.size() > 0 && realMesh)
10081024
{
10091025
Torque::Path dsqPath(cachedPath);
10101026
dsqPath.setExtension("dsq");

Engine/source/ts/collada/colladaShapeLoader.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,21 @@ static bool sReadCollada(const Torque::Path& path, TSShape*& res_shape)
700700
if (tss)
701701
{
702702
TSShapeLoader::updateProgress(TSShapeLoader::Load_Complete, "Import complete");
703-
Con::printf("[COLLADA] Shape created successfully.");
703+
704+
bool realMesh = false;
705+
for (U32 i = 0; i < tss->meshes.size(); ++i)
706+
{
707+
if (tss->meshes[i] && tss->meshes[i]->getMeshType() != TSMesh::NullMeshType)
708+
{
709+
realMesh = true;
710+
break;
711+
}
712+
}
713+
714+
if(realMesh)
715+
Con::printf("[COLLADA] Shape created successfully.");
716+
else
717+
Con::printf("[COLLADA] Animation created successfully.");
704718

705719
Torque::Path cachedPath(path);
706720
// Cache the model to a DTS file for faster loading next time.
@@ -716,7 +730,7 @@ static bool sReadCollada(const Torque::Path& path, TSShape*& res_shape)
716730
// Add collada materials to materials.tscript
717731
updateMaterialsScript(path, isSketchup);
718732

719-
if (tss->sequences.size() > 0)
733+
if (tss->sequences.size() > 0 && realMesh)
720734
{
721735
Torque::Path dsqPath(cachedPath);
722736
dsqPath.setExtension("dsq");

Engine/source/ts/tsShape.cpp

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ void TSShape::compressionKey(U8* keyOut, U32 keyLen)
204204
}
205205
}
206206

207-
void TSShape::xorBufferAtOffset(void* data, U32 byteCount,
207+
void TSShape::xorBufferAtOffset(void* buffer, U32 byteCount,
208208
U32 startOffset,
209209
const U8* key, U32 keyLen)
210210
{
211-
U8* p = (U8*)data;
211+
U8* p = (U8*)buffer;
212212
for (U32 i = 0; i < byteCount; ++i)
213213
p[i] ^= key[(startOffset + i) % keyLen];
214214
}
@@ -2280,6 +2280,82 @@ template<> void *Resource<TSShape>::create(const Torque::Path &path)
22802280
ret = new TSShape;
22812281
readSuccess = ret->read(&stream);
22822282
}
2283+
else if (extension.equal("dsq", String::NoCase))
2284+
{
2285+
// DSQ is an animation-only file. Try to find a companion shape to load
2286+
// sequences into; if none exists, create a minimal empty shape instead.
2287+
Torque::Path companionPath(path);
2288+
bool foundCompanion = false;
2289+
2290+
// Look for basename.cached.dts or basename.dts alongside the DSQ
2291+
String fileName = path.getFileName();
2292+
String::SizeType sep = fileName.find('_', 0, String::Right);
2293+
if (sep != String::NPos)
2294+
{
2295+
companionPath.setFileName(fileName.substr(0, sep));
2296+
companionPath.setExtension("cached.dts");
2297+
if (Torque::FS::IsFile(companionPath.getFullPath()))
2298+
foundCompanion = true;
2299+
2300+
if (!foundCompanion)
2301+
{
2302+
companionPath.setExtension("dts");
2303+
if (Torque::FS::IsFile(companionPath.getFullPath()))
2304+
foundCompanion = true;
2305+
}
2306+
}
2307+
2308+
if (!foundCompanion)
2309+
{
2310+
companionPath.setFileName(fileName);
2311+
companionPath.setExtension("cached.dts");
2312+
if (Torque::FS::IsFile(companionPath.getFullPath()))
2313+
foundCompanion = true;
2314+
}
2315+
2316+
if (!foundCompanion)
2317+
{
2318+
companionPath.setExtension("dts");
2319+
if (Torque::FS::IsFile(companionPath.getFullPath()))
2320+
foundCompanion = true;
2321+
}
2322+
2323+
if (foundCompanion)
2324+
{
2325+
FileStream shapeStream;
2326+
shapeStream.open(companionPath.getFullPath(), Torque::FS::File::Read);
2327+
if (shapeStream.getStatus() == Stream::Ok)
2328+
{
2329+
ret = new TSShape;
2330+
if (!ret->read(&shapeStream))
2331+
{
2332+
delete ret;
2333+
ret = NULL;
2334+
}
2335+
}
2336+
}
2337+
2338+
if (!ret || !foundCompanion)
2339+
{
2340+
// No companion shape found; build a minimal empty shape so sequences
2341+
// have somewhere to live (matches ShapeAnimationAsset's expectations).
2342+
ret = new TSShape;
2343+
ret->createEmptyShape();
2344+
}
2345+
2346+
FileStream dsqStream;
2347+
dsqStream.open(path.getFullPath(), Torque::FS::File::Read);
2348+
if (dsqStream.getStatus() != Stream::Ok)
2349+
{
2350+
Con::errorf("Resource<TSShape>::create - Could not open DSQ '%s'", path.getFullPath().c_str());
2351+
delete ret;
2352+
return NULL;
2353+
}
2354+
2355+
readSuccess = ret->importSequences(&dsqStream, path);
2356+
if (!readSuccess)
2357+
Con::errorf("Resource<TSShape>::create - Failed to import sequences from '%s'", path.getFullPath().c_str());
2358+
}
22832359
else
22842360
{
22852361
const TSShape::ShapeRegistration* regInfo = TSShape::sFindRegInfo(extension);

0 commit comments

Comments
 (0)