瀏覽代碼

Add MeshMorph support to geometryBufferRenderer.ts

Markus Billharz 6 年之前
父節點
當前提交
834ef1430e
共有 1 個文件被更改,包括 20 次插入2 次删除
  1. 20 2
      src/Rendering/geometryBufferRenderer.ts

+ 20 - 2
src/Rendering/geometryBufferRenderer.ts

@@ -227,6 +227,20 @@ export class GeometryBufferRenderer {
             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");
@@ -242,10 +256,10 @@ export class GeometryBufferRenderer {
             this._cachedDefines = join;
             this._effect = this._scene.getEngine().createEffect("geometry",
                 attribs,
-                ["world", "mBones", "viewProjection", "diffuseMatrix", "view", "previousWorld", "previousViewProjection", "mPreviousBones"],
+                ["world", "mBones", "viewProjection", "diffuseMatrix", "view", "previousWorld", "previousViewProjection", "mPreviousBones", "morphTargetInfluences"],
                 ["diffuseSampler"], join,
                 undefined, undefined, undefined,
-                { buffersCount: this._enablePosition ? 3 : 2 });
+                { buffersCount: this._enablePosition ? 3 : 2, maxSimultaneousMorphTargets: numMorphInfluencers});
         }
 
         return this._effect.isReady();
@@ -372,6 +386,10 @@ export class GeometryBufferRenderer {
                     }
                 }
 
+                // Morph targets
+                MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
+
+
                 // Velocity
                 if (this._enableVelocity) {
                     this._effect.setMatrix("previousWorld", this._previousTransformationMatrices[mesh.uniqueId].world);