Răsfoiți Sursa

Actually animate nested mesh properties with ".prop1.prop2"

jamesgk 8 ani în urmă
părinte
comite
bfc468a590

+ 3 - 3
src/animation/PropertyBinding.js

@@ -333,20 +333,20 @@ Object.assign( PropertyBinding.prototype, { // prototype, continued
 
 			function setValue_direct( buffer, offset ) {
 
-				this.node[ this.propertyName ] = buffer[ offset ];
+				this.targetObject[ this.propertyName ] = buffer[ offset ];
 
 			},
 
 			function setValue_direct_setNeedsUpdate( buffer, offset ) {
 
-				this.node[ this.propertyName ] = buffer[ offset ];
+				this.targetObject[ this.propertyName ] = buffer[ offset ];
 				this.targetObject.needsUpdate = true;
 
 			},
 
 			function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
 
-				this.node[ this.propertyName ] = buffer[ offset ];
+				this.targetObject[ this.propertyName ] = buffer[ offset ];
 				this.targetObject.matrixWorldNeedsUpdate = true;
 
 			}

+ 37 - 0
test/unit/src/animation/PropertyBinding.js

@@ -220,3 +220,40 @@ QUnit.test( 'sanitizeNodeName' , function( assert ) {
 	);
 
 } );
+
+QUnit.test( 'setValue', function( assert ) {
+
+	var paths = [
+		'.material.opacity',
+		'.material[opacity]'
+	];
+
+	paths.forEach( function ( path, i ) {
+
+		var originalValue = 0;
+		var expectedValue = 1;
+
+		var geometry = new THREE.BoxGeometry();
+		var material = new THREE.MeshBasicMaterial();
+		material.opacity = originalValue;
+		var mesh = new THREE.Mesh( geometry, material );
+
+		var binding = new THREE.PropertyBinding( mesh, path, null );
+		binding.bind();
+
+		assert.equal(
+			material.opacity,
+			originalValue,
+			'Sets property of material with "' + path + '" (pre-setValue)'
+		);
+
+		binding.setValue( [ expectedValue ], 0 );
+		assert.equal(
+			material.opacity,
+			expectedValue,
+			'Sets property of material with "' + path + '" (post-setValue)'
+		);
+
+	} );
+
+} );