Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TinyGltfImporter: Import Weights and JointIds mesh attributes #84

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/MagnumPlugins/TinyGltfImporter/TinyGltfImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,41 @@ Containers::Optional<MeshData> TinyGltfImporter::doMesh(const UnsignedInt id, Un
return Containers::NullOpt;
}

/* Joint attribute ends with _0, _1 ... */
} else if(Utility::String::beginsWith(attribute.first, "JOINTS")) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO for testing: the code relies on the attributes being sorted (so JOINTS_0 before JOINTS_1) and without gaps. I think sorting is ensured implicitly due to how JSON dict data is stored, but the gaps need to be checked.

name = MeshAttribute::JointIds;

if(accessor.type != TINYGLTF_TYPE_VEC4) {
Error{} << "Trade::TinyGltfImporter::mesh(): unexpected JOINTS type" << accessor.type;
return Containers::NullOpt;
}

if(!(accessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE) &&
!(accessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT)) {
Comment on lines +1183 to +1184
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!(accessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE) &&
!(accessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT)) {
if(!(accessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE && !accessor.normalized) &&
!(accessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT && !accessor.normalized)) {

IDs can't be normalized. Also needs a test ;)

Error{} << "Trade::TinyGltfImporter::mesh(): unsupported JOINTS component type"
<< (accessor.normalized ? "normalized" : "unnormalized")
<< accessor.componentType;
return Containers::NullOpt;
}

/* Weights attribute ends with _0, _1 ... */
} else if(Utility::String::beginsWith(attribute.first, "WEIGHTS")) {
name = MeshAttribute::Weights;

if(accessor.type != TINYGLTF_TYPE_VEC4) {
Error{} << "Trade::TinyGltfImporter::mesh(): unexpected WEIGHTS type" << accessor.type;
return Containers::NullOpt;
}

if(!(accessor.componentType == TINYGLTF_COMPONENT_TYPE_FLOAT && !accessor.normalized) &&
!(accessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE && accessor.normalized) &&
!(accessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT && accessor.normalized)) {
Error{} << "Trade::TinyGltfImporter::mesh(): unsupported WEIGHTS component type"
<< (accessor.normalized ? "normalized" : "unnormalized")
<< accessor.componentType;
return Containers::NullOpt;
}

/* Custom or unrecognized attributes, map to an ID */
} else name = _d->meshAttributesForName.at(attribute.first);

Expand Down