Skip to content

Commit 258cdfd

Browse files
Export tangents in GLTF (assimp#5900)
Previously tangents were not being exported. If they are present, they should also be properly exported. Co-authored-by: Kim Kulling <[email protected]>
1 parent 016be03 commit 258cdfd

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

code/AssetLib/glTF2/glTF2AssetWriter.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ namespace glTF2 {
608608
{
609609
WriteAttrs(w, attrs, p.attributes.position, "POSITION");
610610
WriteAttrs(w, attrs, p.attributes.normal, "NORMAL");
611+
WriteAttrs(w, attrs, p.attributes.tangent, "TANGENT");
611612
WriteAttrs(w, attrs, p.attributes.texcoord, "TEXCOORD", true);
612613
WriteAttrs(w, attrs, p.attributes.color, "COLOR", true);
613614
WriteAttrs(w, attrs, p.attributes.joint, "JOINTS", true);

code/AssetLib/glTF2/glTF2Exporter.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,20 @@ void glTF2Exporter::ExportMeshes() {
12151215
p.attributes.normal.push_back(n);
12161216
}
12171217

1218+
/******************** Tangents ********************/
1219+
if (nullptr != aim->mTangents) {
1220+
for (uint32_t i = 0; i < aim->mNumVertices; ++i) {
1221+
aim->mTangents[i].NormalizeSafe();
1222+
}
1223+
Ref<Accessor> t = ExportData(
1224+
*mAsset, meshId, b, aim->mNumVertices, aim->mTangents, AttribType::VEC3,
1225+
AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER
1226+
);
1227+
if (t) {
1228+
p.attributes.tangent.push_back(t);
1229+
}
1230+
}
1231+
12181232
/************** Texture coordinates **************/
12191233
for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
12201234
if (!aim->HasTextureCoords(i)) {

0 commit comments

Comments
 (0)