genMorphGeometry method

dynamic genMorphGeometry(
  1. dynamic parentGeo,
  2. dynamic parentGeoNode,
  3. dynamic morphGeoNode,
  4. dynamic preTransform,
  5. dynamic name,
)

Implementation

genMorphGeometry( parentGeo, parentGeoNode, morphGeoNode, preTransform, name ) {

	var vertexIndices = ( parentGeoNode.PolygonVertexIndex != null ) ? parentGeoNode.PolygonVertexIndex.a : [];

	var morphPositionsSparse = ( morphGeoNode.Vertices != null ) ? morphGeoNode.Vertices.a : [];
	var indices = ( morphGeoNode.Indexes != null ) ? morphGeoNode.Indexes.a : [];

	var length = parentGeo.attributes.position.count * 3;
	var morphPositions = new Float32Array( length );

	for ( var i = 0; i < indices.length; i ++ ) {

		var morphIndex = indices[ i ] * 3;

		morphPositions[ morphIndex ] = morphPositionsSparse[ i * 3 ];
		morphPositions[ morphIndex + 1 ] = morphPositionsSparse[ i * 3 + 1 ];
		morphPositions[ morphIndex + 2 ] = morphPositionsSparse[ i * 3 + 2 ];

	}

	// TODO: add morph normal support
	var morphGeoInfo = {
		"vertexIndices": vertexIndices,
		"vertexPositions": morphPositions,
	};

	var morphBuffers = this.genBuffers( morphGeoInfo );

	var positionAttribute = new Float32BufferAttribute( morphBuffers.vertex, 3 );
	positionAttribute.name = name ?? morphGeoNode.attrName;

	positionAttribute.applyMatrix4( preTransform );

	parentGeo.morphAttributes.position.push( positionAttribute );

}