소스 검색

Add MorphTarget support to outlineRenderer.ts

Markus Billharz 6 년 전
부모
커밋
e8eed1e175
1개의 변경된 파일22개의 추가작업 그리고 3개의 파일을 삭제
  1. 22 3
      src/Rendering/outlineRenderer.ts

+ 22 - 3
src/Rendering/outlineRenderer.ts

@@ -1,6 +1,6 @@
 import { VertexBuffer } from "../Meshes/buffer";
 import { SubMesh } from "../Meshes/subMesh";
-import { _InstancesBatch } from "../Meshes/mesh";
+import {_InstancesBatch, Mesh} from "../Meshes/mesh";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { Scene } from "../scene";
 import { Engine } from "../Engines/engine";
@@ -188,6 +188,9 @@ export class OutlineRenderer implements ISceneComponent {
             this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
         }
 
+        // Morph targets
+        MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
+
         mesh._bind(subMesh, this._effect, Material.TriangleFillMode);
 
         // Alpha test
@@ -253,6 +256,20 @@ export class OutlineRenderer implements ISceneComponent {
             defines.push("#define NUM_BONE_INFLUENCERS 0");
         }
 
+        // Morph targets
+        const morphTargetManager = (mesh as Mesh).morphTargetManager;
+        let numMorphInfluencers = 0;
+        if (morphTargetManager) {
+            if (morphTargetManager.numInfluencers > 0) {
+                numMorphInfluencers = morphTargetManager.numInfluencers;
+
+                defines.push("#define MORPHTARGETS");
+                defines.push("#define NUM_MORPH_INFLUENCERS " + numMorphInfluencers);
+
+                MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, { "NUM_MORPH_INFLUENCERS": numMorphInfluencers });
+            }
+        }
+
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
@@ -265,8 +282,10 @@ export class OutlineRenderer implements ISceneComponent {
             this._cachedDefines = join;
             this._effect = this.scene.getEngine().createEffect("outline",
                 attribs,
-                ["world", "mBones", "viewProjection", "diffuseMatrix", "offset", "color", "logarithmicDepthConstant"],
-                ["diffuseSampler"], join);
+                ["world", "mBones", "viewProjection", "diffuseMatrix", "offset", "color", "logarithmicDepthConstant", "morphTargetInfluences"],
+                ["diffuseSampler"], join,
+                undefined, undefined, undefined,
+                { maxSimultaneousMorphTargets: numMorphInfluencers });
         }
 
         return this._effect.isReady();