소스 검색

InstancedMesh.getMorphAt() + docs (#27704)

* InstancedMesh.getMorphAt() + docs

* influences -> weights

* dummy -> object
Yannis Gravezas 1 년 전
부모
커밋
48666e11b3
2개의 변경된 파일56개의 추가작업 그리고 2개의 파일을 삭제
  1. 36 0
      docs/api/en/objects/InstancedMesh.html
  2. 20 2
      src/objects/InstancedMesh.js

+ 36 - 0
docs/api/en/objects/InstancedMesh.html

@@ -79,6 +79,13 @@
 			instanced data via [page:.setMatrixAt]().
 		</p>
 
+		<h3>[property:DataTexture morphTexture]</h3>
+		<p>
+			Represents the morph target weights of all instances. You have to set its
+			[page:Texture.needsUpdate needsUpdate] flag to true if you modify
+			instanced data via [page:.setMorphAt]().
+		</p>
+
 		<h3>[property:Boolean isInstancedMesh]</h3>
 		<p>Read-only flag to check if a given object is of type [name].</p>
 
@@ -132,6 +139,18 @@
 		</p>
 		<p>Get the local transformation matrix of the defined instance.</p>
 
+		<h3>
+			[method:undefined getMorphAt]( [param:Integer index], [param:Mesh mesh] )
+		</h3>
+		<p>
+			[page:Integer index]: The index of an instance. Values have to be in the
+			range [0, count].
+		</p>
+		<p>
+			[page:Mesh mesh]: The [page:Mesh.morphTargetInfluences .morphTargetInfluences] property of this mesh will be filled with the morph target weights of the defined instance.
+		</p>
+		<p>Get the morph target weights of the defined instance.</p>
+
 		<h3>
 			[method:undefined setColorAt]( [param:Integer index], [param:Color color] )
 		</h3>
@@ -163,6 +182,23 @@
 			to true after updating all the matrices.
 		</p>
 
+		<h3>
+			[method:undefined setMorphAt]( [param:Integer index], [param:Mesh mesh] )
+		</h3>
+		<p>
+			[page:Integer index]: The index of an instance. Values have to be in the
+			range [0, count].
+		</p>
+		<p>
+			[page:Matrix4 matrix]: A mesh with [page:Mesh.morphTargetInfluences .morphTargetInfluences] property containing the morph target weights
+			of a single instance.
+		</p>
+		<p>
+			Sets the morph target weights to the defined instance. Make
+			sure you set [page:.morphTexture][page:Texture.needsUpdate .needsUpdate] 
+			to true after updating all the influences.
+		</p>
+
 		<h2>Source</h2>
 
 		<p>

+ 20 - 2
src/objects/InstancedMesh.js

@@ -132,6 +132,24 @@ class InstancedMesh extends Mesh {
 
 	}
 
+	getMorphAt( index, object ) {
+
+		const objectInfluences = object.morphTargetInfluences;
+
+		const array = this.morphTexture.source.data.data;
+
+		const len = objectInfluences.length + 1; // All influences + the baseInfluenceSum
+
+		const dataIndex = index * len + 1; // Skip the baseInfluenceSum at the beginning
+
+		for ( let i = 0; i < objectInfluences.length; i ++ ) {
+
+			objectInfluences[ i ] = array[ dataIndex + i ];
+
+		}
+
+	}
+
 	raycast( raycaster, intersects ) {
 
 		const matrixWorld = this.matrixWorld;
@@ -202,9 +220,9 @@ class InstancedMesh extends Mesh {
 
 	}
 
-	setMorphAt( index, dummy ) {
+	setMorphAt( index, object ) {
 
-		const objectInfluences = dummy.morphTargetInfluences;
+		const objectInfluences = object.morphTargetInfluences;
 
 		const len = objectInfluences.length + 1; // morphBaseInfluence + all influences