Просмотр исходного кода

Merge pull request #16110 from looeee/support_morph_targets_in_points

Points: Introduce . updateMorphTargets()
Mr.doob 6 лет назад
Родитель
Сommit
0eedc634f4
1 измененных файлов с 34 добавлено и 1 удалено
  1. 34 1
      src/objects/Points.js

+ 34 - 1
src/objects/Points.js

@@ -19,6 +19,8 @@ function Points( geometry, material ) {
 	this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
 	this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
 
+	this.updateMorphTargets();
+
 }
 
 Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
@@ -136,6 +138,38 @@ Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 	}() ),
 
+	updateMorphTargets: function () {
+
+		var geometry = this.geometry;
+		var m, ml, name;
+
+		var morphAttributes = geometry.morphAttributes;
+		var keys = Object.keys( morphAttributes );
+
+		if ( keys.length > 0 ) {
+
+			var morphAttribute = morphAttributes[ keys[ 0 ] ];
+
+			if ( morphAttribute !== undefined ) {
+
+				this.morphTargetInfluences = [];
+				this.morphTargetDictionary = {};
+
+				for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
+
+					name = morphAttribute[ m ].name || String( m );
+
+					this.morphTargetInfluences.push( 0 );
+					this.morphTargetDictionary[ name ] = m;
+
+				}
+
+			}
+
+		}
+
+	},
+
 	clone: function () {
 
 		return new this.constructor( this.geometry, this.material ).copy( this );
@@ -144,5 +178,4 @@ Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 } );
 
-
 export { Points };