Sfoglia il codice sorgente

Added dispose() method (#24666)

WestLangley 2 anni fa
parent
commit
1c87c53f01

+ 14 - 11
docs/examples/en/helpers/VertexNormalsHelper.html

@@ -7,12 +7,12 @@
 		<link type="text/css" rel="stylesheet" href="page.css" />
 	</head>
 	<body>
-		[page:Object3D] &rarr; [page:Line] &rarr;
+		[page:Object3D] &rarr; [page:Line] &rarr; [page:LineSegments] &rarr;
 
 		<h1>[name]</h1>
 
 		<p class="desc">
-			Renders [page:ArrowHelper arrows] to visualize an object's vertex normal vectors.
+			Visualizes an object's vertex normals.
 			Requires that normals have been specified in a [page:BufferAttribute custom attribute] or
 			have been calculated using [page:BufferGeometry.computeVertexNormals computeVertexNormals].<br /><br />
 		</p>
@@ -21,12 +21,12 @@
 
 		<code>
 		const geometry = new THREE.BoxGeometry( 10, 10, 10, 2, 2, 2 );
-		const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
-		const box = new THREE.Mesh( geometry, material );
+		const material = new THREE.MeshStandardMaterial();
+		const mesh = new THREE.Mesh( geometry, material );
 
-		const helper = new VertexNormalsHelper( box, 2, 0x00ff00, 1 );
+		const helper = new VertexNormalsHelper( mesh, 1, 0xff0000 );
 
-		scene.add( box );
+		scene.add( mesh );
 		scene.add( helper );
 		</code>
 
@@ -38,12 +38,11 @@
 		<h2>Constructor</h2>
 
 
-		<h3>[name]( [param:Object3D object], [param:Number size], [param:Hex color], [param:Number linewidth] )</h3>
+		<h3>[name]( [param:Object3D object], [param:Number size], [param:Hex color] )</h3>
 		<p>
 			[page:Object3D object] -- object for which to render vertex normals.<br />
-			[page:Number size] -- (optional) length of the arrows. Default is 1.<br />
-			[page:Hex color] -- hex color of the arrows. Default is 0xff0000.<br />
-			[page:Number linewidth] -- (optional) width of the arrow lines. Default is 1.
+			[page:Number size] -- (optional) length of the arrows. Default is *1*.<br />
+			[page:Hex color] -- (optional) hex color of the arrows. Default is *0xff0000*.
 		</p>
 
 
@@ -68,8 +67,12 @@
 
 
 		<h3>[method:undefined update]()</h3>
-		<p>Updates the vertex normal preview based on movement of the object.</p>
+		<p>Updates the vertex tangents preview based on the object's world transform.</p>
 
+		<h3>[method:undefined dispose]()</h3>
+		<p>
+		Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
+		</p>
 
 		<h2>Source</h2>
 

+ 12 - 10
docs/examples/en/helpers/VertexTangentsHelper.html

@@ -12,22 +12,21 @@
 		<h1>[name]</h1>
 
 		<p class="desc">
-			Renders arrows to visualize an object's vertex tangent vectors.
+			Visualizes an object's vertex tangents.
 			Requires that tangents have been specified in a [page:BufferAttribute custom attribute] or
 			have been calculated using [page:BufferGeometry.computeTangents computeTangents].<br /><br />
-
-			This helper supports [page:BufferGeometry] only.
 		</p>
 
 		<h2>Code Example</h2>
+
 		<code>
 		const geometry = new THREE.BoxGeometry( 10, 10, 10, 2, 2, 2 );
-		const material = new THREE.MeshNormalMaterial();
-		const box = new THREE.Mesh( geometry, material );
+		const material = new THREE.MeshStandardMaterial();
+		const mesh = new THREE.Mesh( geometry, material );
 
-		const helper = new VertexTangentsHelper( box, 1, 0x00ffff, 1 );
+		const helper = new VertexTangentsHelper( mesh, 1, 0x00ffff );
 
-		scene.add( box );
+		scene.add( mesh );
 		scene.add( helper );
 		</code>
 
@@ -39,12 +38,11 @@
 		<h2>Constructor</h2>
 
 
-		<h3>[name]( [param:Object3D object], [param:Number size], [param:Hex color], [param:Number linewidth] )</h3>
+		<h3>[name]( [param:Object3D object], [param:Number size], [param:Hex color] )</h3>
 		<p>
 			[page:Object3D object] -- object for which to render vertex tangents.<br />
 			[page:Number size] -- (optional) length of the arrows. Default is *1*.<br />
-			[page:Hex color] -- hex color of the arrows. Default is 0x00ffff.<br />
-			[page:Number linewidth] -- (optional) width of the arrow lines. Default is *1*. (Setting lineWidth is currently not supported.)
+			[page:Hex color] -- (optional) hex color of the arrows. Default is *0x00ffff*.
 		</p>
 
 
@@ -71,6 +69,10 @@
 		<h3>[method:undefined update]()</h3>
 		<p>Updates the vertex tangents preview based on the object's world transform.</p>
 
+		<h3>[method:undefined dispose]()</h3>
+		<p>
+		Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
+		</p>
 
 		<h2>Source</h2>
 

+ 7 - 1
examples/jsm/helpers/VertexNormalsHelper.js

@@ -84,7 +84,13 @@ class VertexNormalsHelper extends LineSegments {
 
 	}
 
-}
+	dispose() {
+
+		this.geometry.dispose();
+		this.material.dispose();
 
+	}
+
+}
 
 export { VertexNormalsHelper };

+ 7 - 0
examples/jsm/helpers/VertexTangentsHelper.js

@@ -76,6 +76,13 @@ class VertexTangentsHelper extends LineSegments {
 
 	}
 
+	dispose() {
+
+		this.geometry.dispose();
+		this.material.dispose();
+
+	}
+
 }
 
 export { VertexTangentsHelper };