瀏覽代碼

Merge pull request #21086 from SntsDev/docs/computeMorphedBufferGeometry

Add documentation of computeMorphedBufferGeometry
Mr.doob 4 年之前
父節點
當前提交
832d1ce4da

+ 15 - 0
docs/examples/en/utils/BufferGeometryUtils.html

@@ -74,6 +74,21 @@
 
 		</p>
 
+		<h3>[method:Object computeMorphedAttributes]( [param:Mesh | Line | Points object] )</h3>
+		<p>
+		object -- Instance of [page:Mesh Mesh] | [page:Line Line] | [page:Points Points].<br /><br />
+
+		Returns the current attributes (Position and Normal) of a morphed/skinned [page:Object3D Object3D] whose geometry is a 
+		[page:BufferGeometry BufferGeometry], together with the original ones: An Object with 4 properties: 
+		`positionAttribute`, `normalAttribute`, `morphedPositionAttribute` and `morphedNormalAttribute`.
+
+		Helpful for Raytracing or Decals (i.e. a [page:DecalGeometry DecalGeometry] applied to a morphed Object 
+		with a [page:BufferGeometry BufferGeometry] will use the original BufferGeometry, not the morphed/skinned one, 
+		generating an incorrect result. 
+		Using this function to create a shadow Object3D the DecalGeometry can be correctly generated).
+
+		</p>
+
 		<h2>Source</h2>
 
 		<p>

+ 2 - 16
examples/js/utils/BufferGeometryUtils.js

@@ -623,24 +623,10 @@ THREE.BufferGeometryUtils = {
 	/**
 	 * Calculates the morphed attributes of a morphed/skinned BufferGeometry.
 	 * Helpful for Raytracing or Decals.
-	 * @param {Object3D} object
+	 * @param {Mesh | Line | Points} object An instance of Mesh, Line or Points.
 	 * @return {Object} An Object with original position/normal attributes and morphed ones.
 	 */
-	computeMorphedBufferGeometry: function ( object ) {
-
-		if ( ! object ) {
-
-			console.error( 'Please provide an object' );
-			return null;
-
-		}
-
-		if ( ! object.geometry ) {
-
-			console.error( 'Please provide an object with a geometry' );
-			return null;
-
-		}
+	computeMorphedAttributes: function ( object ) {
 
 		if ( ! object.geometry.isBufferGeometry ) {
 

+ 2 - 2
examples/jsm/utils/BufferGeometryUtils.d.ts

@@ -1,4 +1,4 @@
-import { BufferAttribute, BufferGeometry, InterleavedBufferAttribute, TrianglesDrawModes, Object3D } from '../../../src/Three';
+import { BufferAttribute, BufferGeometry, InterleavedBufferAttribute, TrianglesDrawModes, Mesh, Line, Points } from '../../../src/Three';
 
 export namespace BufferGeometryUtils {
 	export function mergeBufferGeometries( geometries: BufferGeometry[], useGroups?: boolean ): BufferGeometry;
@@ -7,5 +7,5 @@ export namespace BufferGeometryUtils {
 	export function estimateBytesUsed( geometry: BufferGeometry ): number;
 	export function mergeVertices( geometry: BufferGeometry, tolerance?: number ): BufferGeometry;
 	export function toTrianglesDrawMode( geometry: BufferGeometry, drawMode: TrianglesDrawModes ): BufferGeometry;
-	export function computeMorphedBufferGeometry( object: Object3D ): Object;
+	export function computeMorphedAttributes( object: Mesh | Line | Points ): Object;
 }

+ 3 - 17
examples/jsm/utils/BufferGeometryUtils.js

@@ -635,28 +635,14 @@ var BufferGeometryUtils = {
 	/**
 	 * Calculates the morphed attributes of a morphed/skinned BufferGeometry.
 	 * Helpful for Raytracing or Decals.
-	 * @param {Object3D} object
+	 * @param {Mesh | Line | Points} object An instance of Mesh, Line or Points.
 	 * @return {Object} An Object with original position/normal attributes and morphed ones.
 	 */
-	computeMorphedBufferGeometry: function ( object ) {
-
-		if ( ! object ) {
-
-			console.error( 'Please provide an object' );
-			return null;
-
-		}
-
-		if ( ! object.geometry ) {
-
-			console.error( 'Please provide an object with a geometry' );
-			return null;
-
-		}
+	computeMorphedAttributes: function ( object ) {
 
 		if ( ! object.geometry.isBufferGeometry ) {
 
-			console.error( 'Geometry is not a BufferGeometry' );
+			console.warn( 'Geometry is not a BufferGeometry' );
 			return null;
 
 		}