Browse Source

Merge branch 'dev' of https://github.com/mrdoob/three.js into dev

Mr.doob 10 years ago
parent
commit
c227b00ef8

+ 1 - 5
examples/js/loaders/AWDLoader.js

@@ -699,11 +699,7 @@
 						attrib = new THREE.BufferAttribute( buffer, 1 );
 						geom.addAttribute( 'index', attrib );
 
-						geom.offsets.push({
-							start: 0,
-							index: 0,
-							count: str_len/2
-						});
+						geom.addDrawCall( 0, str_len / 2 );
 
 						idx = 0;
 

+ 1 - 1
examples/js/loaders/UTF8Loader.js

@@ -99,7 +99,7 @@ THREE.UTF8Loader.BufferGeometryCreator.prototype.create = function ( attribArray
 	geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
 	geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
 
-	geometry.offsets.push( { start: 0, count: indices.length, index: 0 } );
+	geometry.addDrawCall( 0, indices.length );
 
 	geometry.computeBoundingSphere();
 

+ 1 - 1
examples/js/loaders/gltf/glTFLoader.js

@@ -104,7 +104,7 @@ THREE.glTFLoader.prototype.load = function( url, callback ) {
 		var geometry = this.geometry;
 
 		geometry.addAttribute( 'index', new THREE.BufferAttribute( this.indexArray, 1 ) );
-		geometry.addDrawCall( 0, this.indexArray.length, 0 );
+		geometry.addDrawCall( 0, this.indexArray.length );
 
 		geometry.computeBoundingSphere();
 	};

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

@@ -392,7 +392,7 @@ THREE.Projector = function () {
 				if ( geometry instanceof THREE.BufferGeometry ) {
 
 					var attributes = geometry.attributes;
-					var offsets = geometry.offsets;
+					var offsets = geometry.drawcalls;
 
 					if ( attributes.position === undefined ) continue;
 

+ 1 - 1
examples/js/wip/ProxyGeometry.js

@@ -744,7 +744,7 @@ THREE.ProxyGeometry.prototype.clone = function () {
 	var buff = THREE.BufferGeometry.prototype.clone.call(this);
 	var geo = new THREE.ProxyGeometry();
 	geo.attributes = buff.attributes;
-	geo.offsets = buff.offsets;
+	geo.offsets = buff.drawcalls;
 
 	return geo;
 

+ 6 - 8
examples/webgl_buffergeometry.html

@@ -200,17 +200,15 @@
 				geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
 				geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
 
-				var offsets = triangles / chunkSize;
+				var num_offsets = triangles / chunkSize;
 
-				for ( var i = 0; i < offsets; i ++ ) {
+				for ( var i = 0; i < num_offsets; i ++ ) {
 
-					var offset = {
-						start: i * chunkSize * 3,
-						index: i * chunkSize * 3,
-						count: Math.min( triangles - ( i * chunkSize ), chunkSize ) * 3
-					};
+					var indexStart = i * chunkSize * 3;
+					var indexCount = Math.min( triangles - ( i * chunkSize ), chunkSize ) * 3;
+					var indexOffset = i * chunkSize * 3;
 
-					geometry.offsets.push( offset );
+					geometry.addDrawCall( indexStart, indexCount, indexOffset );
 
 				}
 

+ 5 - 13
examples/webgl_buffergeometry_drawcalls.html

@@ -44,10 +44,11 @@
 		<script>
 
 			var group;
-			var container, stats;
+			var container, controls, stats;
 			var particlesData = [];
 			var camera, scene, renderer;
-			var positions,colors;
+			var positions, colors;
+			var particles;
 			var pointCloud;
 			var particlePositions;
 			var linesMesh;
@@ -146,12 +147,7 @@
 
 				}
 
-				particles.drawcalls.push( {
-					start: 0,
-					count: particleCount,
-					index: 0
-				} );
-
+				particles.addDrawCall( 0, particleCount );
 				particles.addAttribute( 'position', new THREE.DynamicBufferAttribute( particlePositions, 3 ) );
 
 				// create the particle system
@@ -165,11 +161,7 @@
 
 				geometry.computeBoundingSphere();
 
-				geometry.drawcalls.push( {
-					start: 0,
-					count: 0,
-					index: 0
-				} );
+				geometry.addDrawCall( 0, 0 );
 
 				var material = new THREE.LineBasicMaterial( {
 					vertexColors: THREE.VertexColors,

+ 4 - 7
examples/webgl_interactive_raycasting_pointcloud.html

@@ -42,7 +42,7 @@
 
 			var renderer, scene, camera, stats;
 			var pointclouds;
-			var raycaster, intersects;
+			var raycaster;
 			var mouse = new THREE.Vector2();
 			var intersection = null;
 			var spheres = [];
@@ -160,9 +160,7 @@
 				}
 
 				geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
-
-				var offset = { start: 0, count: indices.length, index: 0 };
-				geometry.offsets.push( offset );
+				geometry.addDrawCall( 0, indices.length );
 
 				var material = new THREE.PointCloudMaterial( { size: pointSize, vertexColors: THREE.VertexColors } );
 				var pointcloud = new THREE.PointCloud( geometry, material );
@@ -174,7 +172,6 @@
 			function generateRegularPointcloud( color, width, length ) {
 
 				var geometry = new THREE.Geometry();
-				var numPoints = width * length;
 
 				var colors = [];
 
@@ -217,7 +214,7 @@
 
 			function init() {
 
-				container = document.getElementById( 'container' );
+				var container = document.getElementById( 'container' );
 
 				scene = new THREE.Scene();
 
@@ -229,7 +226,7 @@
 
 				//
 
-				pcBuffer = generatePointcloud( new THREE.Color( 1,0,0 ), width, length );
+				var pcBuffer = generatePointcloud( new THREE.Color( 1,0,0 ), width, length );
 				pcBuffer.scale.set( 10,10,10 );
 				pcBuffer.position.set( -5,0,5 );
 				scene.add( pcBuffer );

+ 43 - 34
src/core/BufferGeometry.js

@@ -17,7 +17,6 @@ THREE.BufferGeometry = function () {
 	this.morphAttributes = [];
 
 	this.drawcalls = [];
-	this.offsets = this.drawcalls; // backwards compatibility
 
 	this.boundingBox = null;
 	this.boundingSphere = null;
@@ -50,6 +49,13 @@ THREE.BufferGeometry.prototype = {
 
 	},
 
+	get offsets() {
+
+		console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .drawcalls.' );
+		return this.drawcalls;
+
+	},
+
 	addDrawCall: function ( start, count, indexOffset ) {
 
 		this.drawcalls.push( {
@@ -62,6 +68,12 @@ THREE.BufferGeometry.prototype = {
 
 	},
 
+	clearDrawCalls: function () {
+
+		this.drawcalls = [];
+
+	},
+
 	applyMatrix: function ( matrix ) {
 
 		var position = this.attributes.position;
@@ -100,8 +112,10 @@ THREE.BufferGeometry.prototype = {
 
 	copy: function ( geometry ) {
 
+		// TODO Clear attributes? Clear drawcalls? Copy morphTargets?
+
 		var attributes = geometry.attributes;
-		var offsets = geometry.offsets;
+		var offsets = geometry.drawcalls;
 
 		for ( var name in attributes ) {
 
@@ -114,14 +128,7 @@ THREE.BufferGeometry.prototype = {
 		for ( var i = 0, il = offsets.length; i < il; i ++ ) {
 
 			var offset = offsets[ i ];
-
-			this.offsets.push( {
-
-				start: offset.start,
-				index: offset.index,
-				count: offset.count
-
-			} );
+			this.addDrawCall( offset.start, offset.count, offset.index );
 
 		}
 
@@ -552,13 +559,17 @@ THREE.BufferGeometry.prototype = {
 
 				var indices = attributes.index.array;
 
-				var offsets = ( this.offsets.length > 0 ? this.offsets : [ { start: 0, count: indices.length, index: 0 } ] );
+				if ( this.drawcalls.length === 0 ) {
+
+					this.addDrawCall( 0, indices.length );
+
+				}
 
-				for ( var j = 0, jl = offsets.length; j < jl; ++ j ) {
+				for ( var j = 0, jl = this.drawcalls.length; j < jl; ++ j ) {
 
-					var start = offsets[ j ].start;
-					var count = offsets[ j ].count;
-					var index = offsets[ j ].index;
+					var start = this.drawcalls[ j ].start;
+					var count = this.drawcalls[ j ].count;
+					var index = this.drawcalls[ j ].index;
 
 					for ( var i = start, il = start + count; i < il; i += 3 ) {
 
@@ -735,7 +746,7 @@ THREE.BufferGeometry.prototype = {
 
 		if ( this.drawcalls.length === 0 ) {
 
-			this.addDrawCall( 0, indices.length, 0 );
+			this.addDrawCall( 0, indices.length );
 
 		}
 
@@ -838,8 +849,8 @@ THREE.BufferGeometry.prototype = {
 		var indexPtr = 0;
 		var vertexPtr = 0;
 
-		var offsets = [ { start:0, count:0, index:0 } ];
-		var offset = offsets[ 0 ];
+		var tmpOffsets = [ { start:0, count:0, index:0 } ];
+		var offset = tmpOffsets[ 0 ];
 
 		var duplicatedVertices = 0;
 		var newVerticeMaps = 0;
@@ -877,7 +888,7 @@ THREE.BufferGeometry.prototype = {
 			var faceMax = vertexPtr + newVerticeMaps;
 			if ( faceMax > ( offset.index + size ) ) {
 				var new_offset = { start:indexPtr, count:0, index:vertexPtr };
-				offsets.push( new_offset );
+				tmpOffsets.push( new_offset );
 				offset = new_offset;
 
 				//Re-evaluate reused vertices in light of new offset.
@@ -905,19 +916,23 @@ THREE.BufferGeometry.prototype = {
 
 		/* 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.offsets = offsets; // TODO: Deprecate
-		this.drawcalls = offsets;
+
+		this.clearDrawCalls();
+		for ( var i = 0; i < tmpOffsets.length; i ++ ) {
+
+			var offset = tmpOffsets[ i ];
+			this.addDrawCall( offset.start, offset.count, offset.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 offsets: "+offsets.length);
+		console.log("Draw tmpOffsets: "+tmpOffsets.length);
 		*/
 
-		return offsets;
-
 	},
 
 	merge: function ( geometry, offset ) {
@@ -1054,7 +1069,7 @@ THREE.BufferGeometry.prototype = {
 		data.data = { attributes: {} };
 
 		var attributes = this.attributes;
-		var offsets = this.offsets;
+		var offsets = this.drawcalls;
 		var boundingSphere = this.boundingSphere;
 
 		for ( var key in attributes ) {
@@ -1101,17 +1116,11 @@ THREE.BufferGeometry.prototype = {
 
 		}
 
-		for ( var i = 0, il = this.offsets.length; i < il; i ++ ) {
-
-			var offset = this.offsets[ i ];
-
-			geometry.offsets.push( {
+		for ( var i = 0, il = this.drawcalls.length; i < il; i ++ ) {
 
-				start: offset.start,
-				index: offset.index,
-				count: offset.count
+			var offset = this.drawcalls[ i ];
 
-			} );
+			geometry.addDrawCall( offset.start, offset.count, offset.index );
 
 		}
 

+ 3 - 11
src/core/InstancedBufferGeometry.js

@@ -38,18 +38,10 @@ THREE.InstancedBufferGeometry.prototype.clone = function () {
 
 	}
 
-	for ( var i = 0, il = this.offsets.length; i < il; i++ ) {
+	for ( var i = 0, il = this.drawcalls.length; i < il; i++ ) {
 
-		var offset = this.offsets[i];
-
-		geometry.offsets.push( {
-
-			start: offset.start,
-			index: offset.index,
-			count: offset.count,
-			instances: offset.instances
-
-		} );
+		var offset = this.drawcalls[i];
+		geometry.addDrawCall( offset.start, offset.count, offset.index, offset.instances );
 
 	}
 

+ 12 - 1
src/loaders/BufferGeometryLoader.js

@@ -51,7 +51,18 @@ THREE.BufferGeometryLoader.prototype = {
 
 		if ( offsets !== undefined ) {
 
-			geometry.offsets = JSON.parse( JSON.stringify( offsets ) );
+			var offsetsArray = JSON.parse( JSON.stringify( offsets ) );
+
+			for ( var i = 0; i < offsetsArray.length; i ++ ) {
+
+				var offset = offsetsArray[i];
+				var indexStart = offset.start;
+				var indexCount = offset.count;
+				var indexOffset = offset.index;
+
+				geometry.addDrawcall( indexStart, indexCount, indexOffset );
+
+			}
 
 		}
 

+ 1 - 1
src/objects/Line.js

@@ -65,7 +65,7 @@ THREE.Line.prototype.raycast = ( function () {
 
 				var indices = attributes.index.array;
 				var positions = attributes.position.array;
-				var offsets = geometry.offsets;
+				var offsets = geometry.drawcalls;
 
 				if ( offsets.length === 0 ) {
 

+ 1 - 1
src/objects/Mesh.js

@@ -111,7 +111,7 @@ THREE.Mesh.prototype.raycast = ( function () {
 
 				var indices = attributes.index.array;
 				var positions = attributes.position.array;
-				var offsets = geometry.offsets;
+				var offsets = geometry.drawcalls;
 
 				if ( offsets.length === 0 ) {
 

+ 2 - 6
src/objects/PointCloud.js

@@ -80,15 +80,11 @@ THREE.PointCloud.prototype.raycast = ( function () {
 			if ( attributes.index !== undefined ) {
 
 				var indices = attributes.index.array;
-				var offsets = geometry.offsets;
+				var offsets = geometry.drawcalls;
 
 				if ( offsets.length === 0 ) {
 
-					offsets.push( {
-						start: 0,
-						count: indices.length,
-						index: 0
-					} );
+					offsets = [ { start: 0, count: indices.length, index: 0 } ];
 
 				}
 

+ 6 - 6
src/renderers/WebGLRenderer.js

@@ -1064,7 +1064,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			}
 
-			var offsets = geometry.offsets;
+			var offsets = geometry.drawcalls;
 
 			if ( offsets.length === 0 ) {
 
@@ -1149,7 +1149,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			// non-indexed triangles
 
-			var offsets = geometry.offsets;
+			var offsets = geometry.drawcalls;
 
 			if ( offsets.length === 0 ) {
 
@@ -1270,7 +1270,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			}
 
-			var offsets = geometry.offsets;
+			var offsets = geometry.drawcalls;
 
 			if ( offsets.length === 0 ) {
 
@@ -1327,7 +1327,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 			}
 
 			var position = geometry.attributes.position;
-			var offsets = geometry.offsets;
+			var offsets = geometry.drawcalls;
 
 			if ( offsets.length === 0 ) {
 
@@ -1379,7 +1379,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			}
 
-			var offsets = geometry.offsets;
+			var offsets = geometry.drawcalls;
 
 			if ( offsets.length === 0 ) {
 
@@ -1436,7 +1436,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 			}
 
 			var position = geometry.attributes.position;
-			var offsets = geometry.offsets;
+			var offsets = geometry.drawcalls;
 
 			if ( offsets.length === 0 ) {