Browse Source

SkinnedNode: Ensure `previousBoneMatrices` is defined for cloned skeletons. (#32422)

Michael Herzog 2 months ago
parent
commit
6a8392415b
2 changed files with 23 additions and 1 deletions
  1. 14 1
      src/nodes/accessors/SkinningNode.js
  2. 9 0
      src/objects/Skeleton.js

+ 14 - 1
src/nodes/accessors/SkinningNode.js

@@ -282,7 +282,20 @@ class SkinningNode extends Node {
 
 		_frameId.set( skeleton, frame.frameId );
 
-		if ( this.previousBoneMatricesNode !== null ) skeleton.previousBoneMatrices.set( skeleton.boneMatrices );
+		if ( this.previousBoneMatricesNode !== null ) {
+
+			if ( skeleton.previousBoneMatrices === null ) {
+
+				// cloned skeletons miss "previousBoneMatrices" in their first updated
+
+				skeleton.previousBoneMatrices = new Float32Array( skeleton.boneMatrices );
+
+			}
+
+			skeleton.previousBoneMatrices.set( skeleton.boneMatrices );
+
+
+		}
 
 		skeleton.update();
 

+ 9 - 0
src/objects/Skeleton.js

@@ -70,6 +70,15 @@ class Skeleton {
 		 */
 		this.boneMatrices = null;
 
+		/**
+		 * An array buffer holding the bone data of the previous frame.
+		 * Required for computing velocity. Maintained in {@link SkinningNode}.
+		 *
+		 * @type {?Float32Array}
+		 * @default null
+		 */
+		this.previousBoneMatrices = null;
+
 		/**
 		 * A texture holding the bone data for use
 		 * in the vertex shader.

粤ICP备19079148号