소스 검색

glTF: Implement support for morph target names

While morph target names aren't technically part of glTF spec, there is one de-facto standard for specifying them via mesh.extras, which is also called out in glTF specification as an implementation note. See https://github.com/KhronosGroup/glTF/issues/1036.

This change adds support for using the names if they are present - the default morphTarget0, etc names are generated as a fallback.
Arseny Kapoulkine 5 년 전
부모
커밋
9994183749
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      loaders/src/glTF/2.0/glTFLoader.ts

+ 4 - 1
loaders/src/glTF/2.0/glTFLoader.ts

@@ -866,10 +866,13 @@ export class GLTFLoader implements IGLTFLoader {
             throw new Error(`${context}: Primitives do not have the same number of targets`);
         }
 
+        const targetNames = mesh.extras ? mesh.extras.targetNames : null;
+
         babylonMesh.morphTargetManager = new MorphTargetManager(babylonMesh.getScene());
         for (let index = 0; index < primitive.targets.length; index++) {
             const weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
-            babylonMesh.morphTargetManager.addTarget(new MorphTarget(`morphTarget${index}`, weight, babylonMesh.getScene()));
+            const name = targetNames ? targetNames[index] : `morphTarget${index}`;
+            babylonMesh.morphTargetManager.addTarget(new MorphTarget(name, weight, babylonMesh.getScene()));
             // TODO: tell the target whether it has positions, normals, tangents
         }
     }