Skip to content

Commit

Permalink
Export tangents in GLTF
Browse files Browse the repository at this point in the history
Previously tangents were not being exported. If they are present, they should also be properly
exported.
  • Loading branch information
JulianKnodt committed Nov 27, 2024
1 parent e7a6d33 commit 1a85ebb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions code/AssetLib/glTF2/glTF2AssetWriter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ namespace glTF2 {
{
WriteAttrs(w, attrs, p.attributes.position, "POSITION");
WriteAttrs(w, attrs, p.attributes.normal, "NORMAL");
WriteAttrs(w, attrs, p.attributes.tangent, "TANGENT");
WriteAttrs(w, attrs, p.attributes.texcoord, "TEXCOORD", true);
WriteAttrs(w, attrs, p.attributes.color, "COLOR", true);
WriteAttrs(w, attrs, p.attributes.joint, "JOINTS", true);
Expand Down
14 changes: 14 additions & 0 deletions code/AssetLib/glTF2/glTF2Exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,20 @@ void glTF2Exporter::ExportMeshes() {
p.attributes.normal.push_back(n);
}

/******************** Tangents ********************/
if (nullptr != aim->mTangents) {
for (uint32_t i = 0; i < aim->mNumVertices; ++i) {
aim->mTangents[i].NormalizeSafe();
}
Ref<Accessor> t = ExportData(
*mAsset, meshId, b, aim->mNumVertices, aim->mTangents, AttribType::VEC3,
AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER
);
if (t) {
p.attributes.tangent.push_back(t);
}
}

/************** Texture coordinates **************/
for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
if (!aim->HasTextureCoords(i)) {
Expand Down

0 comments on commit 1a85ebb

Please sign in to comment.