Skip to content

Commit

Permalink
forbid axes/scale for importing models with skeletal animations; appl…
Browse files Browse the repository at this point in the history
…y axes/scale before removing invalid triangles
  • Loading branch information
malytomas committed Nov 24, 2023
1 parent 8ba5fa6 commit 7eb3056
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
10 changes: 0 additions & 10 deletions schemes/skeleton.scheme
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,3 @@ index = 5
display = bake model
type = bool
default = false

[axes]
display = axes
type = string
default = +x+y+z

[scale]
display = scale
type = real
default = 1
20 changes: 5 additions & 15 deletions sources/asset-processor/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,6 @@ namespace
return result;
}

void transformSkeleton(SkeletonRig *skel, const Mat3 &axesScale_)
{
const Mat4 axesScale = Mat4(axesScale_);
const Mat4 axesScaleInv = inverse(axesScale);
Mat4 gi = skel->globalInverse();
std::vector<Mat4> is(skel->invRests().begin(), skel->invRests().end());
gi = gi * axesScale;
for (Mat4 &t : is)
t = t * axesScaleInv;
skel->skeletonData(gi, skel->parents(), skel->bases(), is);
}

void transformMesh(Mesh *msh, const Mat3 &axes, const Mat3 &axesScale)
{
std::vector<Vec3> p(msh->positions().begin(), msh->positions().end());
Expand All @@ -102,9 +90,9 @@ void meshImportTransform(MeshImportResult &result)
const Mat3 axesScale = axes * toFloat(properties("scale"));
if (axesScale == Mat3())
return;
CAGE_LOG(SeverityEnum::Warning, logComponentName, Stringizer() + "using axes/scale conversion matrix: " + axesScale);
CAGE_LOG(SeverityEnum::Info, logComponentName, Stringizer() + "using axes/scale conversion matrix: " + axesScale);
if (result.skeleton)
transformSkeleton(+result.skeleton, axesScale);
CAGE_THROW_ERROR(Exception, "meshes with skeletal animations cannot have axes/scale transformation");
for (auto &it : result.parts)
{
transformMesh(+it.mesh, axes, axesScale);
Expand Down Expand Up @@ -255,12 +243,14 @@ void processModel()
config.trianglesOnly = toBool(properties("trianglesOnly"));
config.passInvalidVectors = toBool(properties("passInvalidNormals"));
MeshImportResult result = meshImportFiles(inputFileName, config);
meshImportTransform(result);
CAGE_LOG(SeverityEnum::Info, logComponentName, "converting materials to cage format");
meshImportConvertToCageFormats(result);
meshImportTransform(result);
meshImportNotifyUsedFiles(result);
const uint32 partIndex = meshImportSelectIndex(result);
const MeshImportPart &part = result.parts[partIndex];
if (part.mesh->verticesCount() == 0)
CAGE_THROW_ERROR(Exception, "the mesh is empty");

ModelDataFlags flags = ModelDataFlags::None;
setFlags(flags, ModelDataFlags::Uvs2, !part.mesh->uvs().empty() || !part.mesh->uvs3().empty(), "uvs");
Expand Down
2 changes: 0 additions & 2 deletions sources/asset-processor/skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
#include <cage-core/skeletalAnimation.h>

MeshImportConfig meshImportConfig();
void meshImportTransform(MeshImportResult &result);
void meshImportNotifyUsedFiles(const MeshImportResult &result);

void processSkeleton()
{
MeshImportResult result = meshImportFiles(inputFileName, meshImportConfig());
meshImportTransform(result);
meshImportNotifyUsedFiles(result);
if (!result.skeleton)
CAGE_THROW_ERROR(Exception, "loaded no skeleton");
Expand Down

0 comments on commit 7eb3056

Please sign in to comment.