Skip to content
Permalink
Browse files

Fix bug with morph target data in glTF loader

  • Loading branch information...
bghgary committed May 17, 2019
1 parent a5ae810 commit 7fcf5f50029326dcb32323de7eeeb27935d6d003
Showing with 11 additions and 7 deletions.
  1. +11 −7 loaders/src/glTF/2.0/glTFLoader.ts
@@ -896,32 +896,36 @@ export class GLTFLoader implements IGLTFLoader {
};

loadAttribute("POSITION", VertexBuffer.PositionKind, (babylonVertexBuffer, data) => {
const positions = new Float32Array(data.length);
babylonVertexBuffer.forEach(data.length, (value, index) => {
data[index] += value;
positions[index] = data[index] + value;
});

babylonMorphTarget.setPositions(data);
babylonMorphTarget.setPositions(positions);
});

loadAttribute("NORMAL", VertexBuffer.NormalKind, (babylonVertexBuffer, data) => {
babylonVertexBuffer.forEach(data.length, (value, index) => {
data[index] += value;
const normals = new Float32Array(data.length);
babylonVertexBuffer.forEach(normals.length, (value, index) => {
normals[index] = data[index] + value;
});

babylonMorphTarget.setNormals(data);
babylonMorphTarget.setNormals(normals);
});

loadAttribute("TANGENT", VertexBuffer.TangentKind, (babylonVertexBuffer, data) => {
const tangents = new Float32Array(data.length / 3 * 4);
let dataIndex = 0;
babylonVertexBuffer.forEach(data.length / 3 * 4, (value, index) => {
// Tangent data for morph targets is stored as xyz delta.
// The vertexData.tangent is stored as xyzw.
// So we need to skip every fourth vertexData.tangent.
if (((index + 1) % 4) !== 0) {
data[dataIndex++] += value;
tangents[dataIndex] = data[dataIndex] += value;
dataIndex++;
}
});
babylonMorphTarget.setTangents(data);
babylonMorphTarget.setTangents(tangents);
});

return Promise.all(promises).then(() => { });

0 comments on commit 7fcf5f5

Please sign in to comment.
You can’t perform that action at this time.