Bladeren bron

Examples - Adjust Compute Geometry Sample (#30699)

* Adjust compute geometry with more accurate comments and add rotation to demonstrate how to modify basePosition to maintain overall position of mesh yet still keep geometry transformations

* slow down rotation

* remove rotation
Christian Helgeson 10 maanden geleden
bovenliggende
commit
8cae4d830f
1 gewijzigde bestanden met toevoegingen van 10 en 5 verwijderingen
  1. 10 5
      examples/webgpu_compute_geometry.html

+ 10 - 5
examples/webgpu_compute_geometry.html

@@ -40,6 +40,8 @@
 			let raycaster, pointer;
 			let stats;
 
+			let mesh;
+
 			const pointerPosition = uniform( vec4( 0 ) );
 			const elasticity = uniform( .4 ); // elasticity ( how "strong" the spring is )
 			const damping = uniform( .94 ); // damping factor ( energy loss )
@@ -52,7 +54,7 @@
 
 				const count = geometry.attributes.position.count;
 
-				// replace geometry attributes for storage buffer attributes
+				// Create storage buffer attribute for modified position.
 
 				const positionBaseAttribute = geometry.attributes.position;
 				const positionStorageBufferAttribute = new THREE.StorageBufferAttribute( count, 3 );
@@ -60,24 +62,27 @@
 
 				geometry.setAttribute( 'storagePosition', positionStorageBufferAttribute );
 
-				// attributes
+				// Attributes
 
 				const positionAttribute = storage( positionBaseAttribute, 'vec3', count );
 				const positionStorageAttribute = storage( positionStorageBufferAttribute, 'vec3', count );
 
 				const speedAttribute = storage( speedBufferAttribute, 'vec3', count );
 
-				// vectors
+				// Vectors
 
+				// Base vec3 position of the mesh vertices.
 				const basePosition = positionAttribute.element( instanceIndex );
+				// Mesh vertices after compute modification.
 				const currentPosition = positionStorageAttribute.element( instanceIndex );
+				// Speed of each mesh vertex.
 				const currentSpeed = speedAttribute.element( instanceIndex );
 
 				//
 
 				const computeInit = Fn( () => {
 
-					// copy position to storage
+					// Modified storage position starts out the same as the base position.
 
 					currentPosition.assign( basePosition );
 
@@ -154,7 +159,7 @@
 
 					// apply the material to the mesh
 
-					const mesh = gltf.scene.children[ 0 ];
+					mesh = gltf.scene.children[ 0 ];
 					mesh.scale.setScalar( .1 );
 					mesh.material = material;
 					scene.add( mesh );

粤ICP备19079148号