Просмотр исходного кода

WebGLRenderer: Removed drawcall.index. See #7003.

Mr.doob 10 лет назад
Родитель
Сommit
c200eaea13

+ 1 - 3
examples/js/loaders/ctm/CTMLoader.js

@@ -246,9 +246,7 @@ THREE.CTMLoader.prototype.createModel = function ( file, callback ) {
 	Model.prototype.constructor = Model;
 
 	var geometry = new Model();
-
-	geometry.computeOffsets();
-
+	
 	// compute vertex normals if not present in the CTM model
 	if ( geometry.attributes.normal === undefined ) {
 		geometry.computeVertexNormals();

+ 1 - 2
examples/js/renderers/Projector.js

@@ -439,11 +439,10 @@ THREE.Projector = function () {
 							for ( var o = 0; o < offsets.length; o ++ ) {
 
 								var offset = offsets[ o ];
-								var index = offset.index;
 
 								for ( var i = offset.start, l = offset.start + offset.count; i < l; i += 3 ) {
 
-									renderList.pushTriangle( indices[ i ] + index, indices[ i + 1 ] + index, indices[ i + 2 ] + index );
+									renderList.pushTriangle( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
 
 								}
 

+ 0 - 28
examples/webgl_buffergeometry.html

@@ -82,21 +82,6 @@
 
 				var geometry = new THREE.BufferGeometry();
 
-				// break geometry into
-				// chunks of 21,845 triangles (3 unique vertices per triangle)
-				// for indices to fit into 16 bit integer number
-				// floor(2^16 / 3) = 21845
-
-				var chunkSize = 21845;
-
-				var indices = new Uint16Array( triangles * 3 );
-
-				for ( var i = 0; i < indices.length; i ++ ) {
-
-					indices[ i ] = i % ( 3 * chunkSize );
-
-				}
-
 				var positions = new Float32Array( triangles * 3 * 3 );
 				var normals = new Float32Array( triangles * 3 * 3 );
 				var colors = new Float32Array( triangles * 3 * 3 );
@@ -195,23 +180,10 @@
 
 				}
 
-				geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
 				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
 				geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
 				geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
 
-				var num_offsets = triangles / chunkSize;
-
-				for ( var i = 0; i < num_offsets; i ++ ) {
-
-					var indexStart = i * chunkSize * 3;
-					var indexCount = Math.min( triangles - ( i * chunkSize ), chunkSize ) * 3;
-					var indexOffset = i * chunkSize * 3;
-
-					geometry.addDrawCall( indexStart, indexCount, indexOffset );
-
-				}
-
 				geometry.computeBoundingSphere();
 
 				var material = new THREE.MeshPhongMaterial( {

+ 33 - 153
src/core/BufferGeometry.js

@@ -64,11 +64,16 @@ THREE.BufferGeometry.prototype = {
 
 	addDrawCall: function ( start, count, indexOffset ) {
 
+		if ( indexOffset !== undefined ) {
+
+			console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
+
+		}
+
 		this.drawcalls.push( {
 
 			start: start,
-			count: count,
-			index: indexOffset !== undefined ? indexOffset : 0
+			count: count
 
 		} );
 
@@ -623,6 +628,7 @@ THREE.BufferGeometry.prototype = {
 	computeVertexNormals: function () {
 
 		var attributes = this.attributes;
+		var drawcalls = this.drawcalls;
 
 		if ( attributes.position ) {
 
@@ -663,23 +669,24 @@ THREE.BufferGeometry.prototype = {
 
 				var indices = attributes.index.array;
 
-				if ( this.drawcalls.length === 0 ) {
+				if ( drawcalls.length === 0 ) {
 
 					this.addDrawCall( 0, indices.length );
 
 				}
 
-				for ( var j = 0, jl = this.drawcalls.length; j < jl; ++ j ) {
+				for ( var j = 0, jl = drawcalls.length; j < jl; ++ j ) {
+
+					var drawcall = drawcalls[ j ];
 
-					var start = this.drawcalls[ j ].start;
-					var count = this.drawcalls[ j ].count;
-					var index = this.drawcalls[ j ].index;
+					var start = drawcall.start;
+					var count = drawcall.count;
 
 					for ( var i = start, il = start + count; i < il; i += 3 ) {
 
-						vA = ( index + indices[ i ] ) * 3;
-						vB = ( index + indices[ i + 1 ] ) * 3;
-						vC = ( index + indices[ i + 2 ] ) * 3;
+						vA = indices[ i + 0 ] * 3;
+						vB = indices[ i + 1 ] * 3;
+						vC = indices[ i + 2 ] * 3;
 
 						pA.fromArray( positions, vA );
 						pB.fromArray( positions, vB );
@@ -858,15 +865,16 @@ THREE.BufferGeometry.prototype = {
 
 		for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
 
-			var start = drawcalls[ j ].start;
-			var count = drawcalls[ j ].count;
-			var index = drawcalls[ j ].index;
+			var drawcall = drawcalls[ j ];
+
+			var start = drawcall.start;
+			var count = drawcall.count;
 
 			for ( i = start, il = start + count; i < il; i += 3 ) {
 
-				iA = index + indices[ i ];
-				iB = index + indices[ i + 1 ];
-				iC = index + indices[ i + 2 ];
+				iA = indices[ i + 0 ];
+				iB = indices[ i + 1 ];
+				iC = indices[ i + 2 ];
 
 				handleTriangle( iA, iB, iC );
 
@@ -905,15 +913,16 @@ THREE.BufferGeometry.prototype = {
 
 		for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
 
-			var start = drawcalls[ j ].start;
-			var count = drawcalls[ j ].count;
-			var index = drawcalls[ j ].index;
+			var drawcall = drawcalls[ j ];
+
+			var start = drawcall.start;
+			var count = drawcall.count;
 
 			for ( i = start, il = start + count; i < il; i += 3 ) {
 
-				iA = index + indices[ i ];
-				iB = index + indices[ i + 1 ];
-				iC = index + indices[ i + 2 ];
+				iA = indices[ i + 0 ];
+				iB = indices[ i + 1 ];
+				iC = indices[ i + 2 ];
 
 				handleVertex( iA );
 				handleVertex( iB );
@@ -925,138 +934,9 @@ THREE.BufferGeometry.prototype = {
 
 	},
 
-	/*
-	Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices.
-	This method will effectively rewrite the index buffer and remap all attributes to match the new indices.
-	WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets.
-	size - Defaults to 65535 or 4294967296 if extension OES_element_index_uint supported, but allows for larger or smaller chunks.
-	*/
 	computeOffsets: function ( size ) {
 
-		if ( size === undefined ) size = THREE.BufferGeometry.MaxIndex;
-
-		var indices = this.attributes.index.array;
-		var vertices = this.attributes.position.array;
-
-		var facesCount = ( indices.length / 3 );
-
-		var UintArray = ( ( vertices.length / 3 ) > 65535 && THREE.BufferGeometry.MaxIndex > 65535 ) ? Uint32Array : Uint16Array;
-
-		/*
-		console.log("Computing buffers in offsets of "+size+" -> indices:"+indices.length+" vertices:"+vertices.length);
-		console.log("Faces to process: "+(indices.length/3));
-		console.log("Reordering "+verticesCount+" vertices.");
-		*/
-
-		var sortedIndices = new UintArray( indices.length );
-
-		var indexPtr = 0;
-		var vertexPtr = 0;
-
-		var tmpOffsets = [ { start: 0, count: 0, index: 0 } ];
-		var offset = tmpOffsets[ 0 ];
-
-		var duplicatedVertices = 0;
-		var newVerticeMaps = 0;
-		var faceVertices = new Int32Array( 6 );
-		var vertexMap = new Int32Array( vertices.length );
-		var revVertexMap = new Int32Array( vertices.length );
-		for ( var j = 0; j < vertices.length; j ++ ) {
-
-			vertexMap[ j ] = - 1; revVertexMap[ j ] = - 1;
-
-		}
-
-		/*
-			Traverse every face and reorder vertices in the proper offsets of 65k.
-			We can have more than 'size' entries in the index buffer per offset, but only reference 'size' values.
-		*/
-		for ( var findex = 0; findex < facesCount; findex ++ ) {
-
-			newVerticeMaps = 0;
-
-			for ( var vo = 0; vo < 3; vo ++ ) {
-
-				var vid = indices[ findex * 3 + vo ];
-				if ( vertexMap[ vid ] === - 1 ) {
-
-					//Unmapped vertex
-					faceVertices[ vo * 2 ] = vid;
-					faceVertices[ vo * 2 + 1 ] = - 1;
-					newVerticeMaps ++;
-
-				} else if ( vertexMap[ vid ] < offset.index ) {
-
-					//Reused vertices from previous block (duplicate)
-					faceVertices[ vo * 2 ] = vid;
-					faceVertices[ vo * 2 + 1 ] = - 1;
-					duplicatedVertices ++;
-
-				} else {
-
-					//Reused vertex in the current block
-					faceVertices[ vo * 2 ] = vid;
-					faceVertices[ vo * 2 + 1 ] = vertexMap[ vid ];
-
-				}
-
-			}
-
-			var faceMax = vertexPtr + newVerticeMaps;
-			if ( faceMax > ( offset.index + size ) ) {
-
-				var new_offset = { start: indexPtr, count: 0, index: vertexPtr };
-				tmpOffsets.push( new_offset );
-				offset = new_offset;
-
-				//Re-evaluate reused vertices in light of new offset.
-				for ( var v = 0; v < 6; v += 2 ) {
-
-					var new_vid = faceVertices[ v + 1 ];
-					if ( new_vid > - 1 && new_vid < offset.index )
-						faceVertices[ v + 1 ] = - 1;
-
-				}
-
-			}
-
-			//Reindex the face.
-			for ( var v = 0; v < 6; v += 2 ) {
-
-				var vid = faceVertices[ v ];
-				var new_vid = faceVertices[ v + 1 ];
-
-				if ( new_vid === - 1 )
-					new_vid = vertexPtr ++;
-
-				vertexMap[ vid ] = new_vid;
-				revVertexMap[ new_vid ] = vid;
-				sortedIndices[ indexPtr ++ ] = new_vid - offset.index; //XXX overflows at 16bit
-				offset.count ++;
-
-			}
-
-		}
-
-		/* Move all attribute values to map to the new computed indices , also expand the vertex stack to match our new vertexPtr. */
-		this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr );
-
-		this.clearDrawCalls();
-
-		for ( var i = 0; i < tmpOffsets.length; i ++ ) {
-
-			var tmpOffset = tmpOffsets[ i ];
-			this.addDrawCall( tmpOffset.start, tmpOffset.count, tmpOffset.index );
-
-		}
-
-		/*
-		var orderTime = Date.now();
-		console.log("Reorder time: "+(orderTime-s)+"ms");
-		console.log("Duplicated "+duplicatedVertices+" vertices.");
-		console.log("Compute Buffers time: "+(Date.now()-s)+"ms");
-		console.log("Draw tmpOffsets: "+tmpOffsets.length);
-		*/
+		console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.')
 
 	},
 
@@ -1258,7 +1138,7 @@ THREE.BufferGeometry.prototype = {
 
 			var offset = source.drawcalls[ i ];
 
-			this.addDrawCall( offset.start, offset.count, offset.index );
+			this.addDrawCall( offset.start, offset.count );
 
 		}
 

+ 1 - 2
src/core/Geometry.js

@@ -309,11 +309,10 @@ THREE.Geometry.prototype = {
 
 					var start = drawcall.start;
 					var count = drawcall.count;
-					var index = drawcall.index;
 
 					for ( var j = start, jl = start + count; j < jl; j += 3 ) {
 
-						addFace( index + indices[ j ], index + indices[ j + 1 ], index + indices[ j + 2 ] );
+						addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
 
 					}
 

+ 5 - 6
src/core/InstancedBufferGeometry.js

@@ -14,13 +14,12 @@ THREE.InstancedBufferGeometry = function () {
 THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
 THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
 
-THREE.InstancedBufferGeometry.prototype.addDrawCall = function ( start, count, indexOffset, instances ) {
+THREE.InstancedBufferGeometry.prototype.addDrawCall = function ( start, count, instances ) {
 
 	this.drawcalls.push( {
 
 		start: start,
 		count: count,
-		index: indexOffset !== undefined ? indexOffset : 0,
 		instances: instances
 
 	} );
@@ -28,7 +27,7 @@ THREE.InstancedBufferGeometry.prototype.addDrawCall = function ( start, count, i
 };
 
 THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
-	
+
 	for ( var attr in source.attributes ) {
 
 		var sourceAttr = source.attributes[ attr ];
@@ -39,12 +38,12 @@ THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
 	for ( var i = 0, il = source.drawcalls.length; i < il; i ++ ) {
 
 		var offset = source.drawcalls[ i ];
-		this.addDrawCall( offset.start, offset.count, offset.index, offset.instances );
+		this.addDrawCall( offset.start, offset.count, offset.instances );
 
 	}
-	
+
 	return this;
-	
+
 };
 
 THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );

+ 7 - 6
src/extras/geometries/WireframeGeometry.js

@@ -81,7 +81,7 @@ THREE.WireframeGeometry = function ( geometry ) {
 
 			if ( drawcalls.length === 0 ) {
 
-				drawcalls = [ { count : indices.length, index : 0, start : 0 } ];
+				geometry.addDrawCall( 0, indices.length );
 
 			}
 
@@ -90,16 +90,17 @@ THREE.WireframeGeometry = function ( geometry ) {
 
 			for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
 
-				var start = drawcalls[ o ].start;
-				var count = drawcalls[ o ].count;
-				var index = drawcalls[ o ].index;
+				var drawcall = drawcalls[ o ];
+
+				var start = drawcall.start;
+				var count = drawcall.count;
 
 				for ( var i = start, il = start + count; i < il; i += 3 ) {
 
 					for ( var j = 0; j < 3; j ++ ) {
 
-						edge[ 0 ] = index + indices[ i + j ];
-						edge[ 1 ] = index + indices[ i + ( j + 1 ) % 3 ];
+						edge[ 0 ] = indices[ i + j ];
+						edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
 						edge.sort( sortFunction );
 
 						var key = edge.toString();

+ 1 - 5
src/loaders/BufferGeometryLoader.js

@@ -54,11 +54,7 @@ THREE.BufferGeometryLoader.prototype = {
 			for ( var i = 0, n = drawcalls.length; i !== n; ++ i ) {
 
 				var drawcall = drawcalls[ i ];
-				var indexStart = drawcall.start;
-				var indexCount = drawcall.count;
-				var indexOffset = drawcall.index;
-
-				geometry.addDrawcall( indexStart, indexCount, indexOffset );
+				geometry.addDrawcall( drawcall.start, drawcall.count );
 
 			}
 

+ 7 - 6
src/objects/Line.js

@@ -69,20 +69,21 @@ THREE.Line.prototype.raycast = ( function () {
 
 				if ( offsets.length === 0 ) {
 
-					offsets = [ { start: 0, count: indices.length, index: 0 } ];
+					geometry.addDrawCall( 0, indices.length );
 
 				}
 
 				for ( var oi = 0; oi < offsets.length; oi ++ ) {
 
-					var start = offsets[ oi ].start;
-					var count = offsets[ oi ].count;
-					var index = offsets[ oi ].index;
+					var offset = offsets[ oi ];
+
+					var start = offset.start;
+					var count = offset.count;
 
 					for ( var i = start; i < start + count - 1; i += step ) {
 
-						var a = index + indices[ i ];
-						var b = index + indices[ i + 1 ];
+						var a = indices[ i ];
+						var b = indices[ i + 1 ];
 
 						vStart.fromArray( positions, a * 3 );
 						vEnd.fromArray( positions, b * 3 );

+ 8 - 7
src/objects/Mesh.js

@@ -119,21 +119,22 @@ THREE.Mesh.prototype.raycast = ( function () {
 
 				if ( offsets.length === 0 ) {
 
-					offsets = [ { start: 0, count: indices.length, index: 0 } ];
+					geometry.addDrawCall( 0, indices.length );
 
 				}
 
 				for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
 
-					var start = offsets[ oi ].start;
-					var count = offsets[ oi ].count;
-					var index = offsets[ oi ].index;
+					var offset = offsets[ oi ];
+
+					var start = offset.start;
+					var count = offset.count;
 
 					for ( var i = start, il = start + count; i < il; i += 3 ) {
 
-						a = index + indices[ i ];
-						b = index + indices[ i + 1 ];
-						c = index + indices[ i + 2 ];
+						a = indices[ i ];
+						b = indices[ i + 1 ];
+						c = indices[ i + 2 ];
 
 						vA.fromArray( positions, a * 3 );
 						vB.fromArray( positions, b * 3 );

+ 2 - 3
src/objects/PointCloud.js

@@ -84,7 +84,7 @@ THREE.PointCloud.prototype.raycast = ( function () {
 
 				if ( offsets.length === 0 ) {
 
-					offsets = [ { start: 0, count: indices.length, index: 0 } ];
+					geometry.addDrawCall( 0, indices.length );
 
 				}
 
@@ -94,11 +94,10 @@ THREE.PointCloud.prototype.raycast = ( function () {
 
 					var start = offset.start;
 					var count = offset.count;
-					var index = offset.index;
 
 					for ( var i = start, il = start + count; i < il; i ++ ) {
 
-						var a = index + indices[ i ];
+						var a = indices[ i ];
 
 						position.fromArray( positions, a * 3 );
 

+ 3 - 1
src/renderers/WebGLRenderer.js

@@ -855,7 +855,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		if ( updateBuffers ) {
 
-			setupVertexAttributes( material, program, geometry, 0 );
+			setupVertexAttributes( material, program, geometry );
 
 			if ( index !== undefined ) {
 
@@ -964,6 +964,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		}
 
+		if ( startIndex === undefined ) startIndex = 0;
+
 		state.initAttributes();
 
 		var geometryAttributes = geometry.attributes;