Ver Fonte

Prevent BufferGeometry custom attributes's array from being deleted by setting geometry.attributes.name.dynamic = true

zz85 há 12 anos atrás
pai
commit
80876074e4

+ 3 - 3
examples/webgl_buffergeometry_custom_attributes_particles.html

@@ -138,7 +138,7 @@
 			var radius = 200;
 
 			geometry = new THREE.BufferGeometry();
-			geometry.dynamic = true;
+			// geometry.dynamic = true;
 			geometry.attributes = {
 
 				position: {
@@ -154,7 +154,8 @@
 				size: {
 					itemSize: 1,
 					array: new Float32Array( particles ),
-					numItems: particles * 1
+					numItems: particles * 1,
+					dynamic: true
 				},
 
 			}
@@ -166,7 +167,6 @@
 
 			sphere = new THREE.ParticleSystem( geometry, shaderMaterial );
 
-			sphere.dynamic = true;
 			//sphere.sortParticles = true;
 
 			var color = new THREE.Color( 0xffaa00 );;

+ 12 - 14
src/renderers/WebGLRenderer.js

@@ -3244,29 +3244,27 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			attributeItem = attributes[ attributeName ];
 
-			if ( ! attributeItem.needsUpdate ) continue;
+			if ( attributeItem.needsUpdate ) {
 
-			if ( attributeName === 'index' ) {
+				if ( attributeName === 'index' ) {
 
-				_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attributeItem.buffer );
-				_gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, attributeItem.array, hint );
+					_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attributeItem.buffer );
+					_gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, attributeItem.array, hint );
 
-			} else {
-
-				_gl.bindBuffer( _gl.ARRAY_BUFFER, attributeItem.buffer );
-				_gl.bufferData( _gl.ARRAY_BUFFER, attributeItem.array, hint );
+				} else {
 
-			}
+					_gl.bindBuffer( _gl.ARRAY_BUFFER, attributeItem.buffer );
+					_gl.bufferData( _gl.ARRAY_BUFFER, attributeItem.array, hint );
 
-			attributeItem.needsUpdate = false;
+				}
 
-		}
+				attributeItem.needsUpdate = false;
 
-		if ( dispose ) {
+			}
 
-			for ( var i in geometry.attributes ) {
+			if ( dispose && ! attributeItem.dynamic ) {
 
-				delete geometry.attributes[ i ].array;
+				delete attributeItem.array;
 
 			}