浏览代码

WebGLGeometries: Check for duplicate edges. Currently too slow...

Mr.doob 10 年之前
父节点
当前提交
93534a11ac
共有 1 个文件被更改,包括 19 次插入5 次删除
  1. 19 5
      src/renderers/webgl/WebGLGeometries.js

+ 19 - 5
src/renderers/webgl/WebGLGeometries.js

@@ -50,19 +50,31 @@ THREE.WebGLGeometries = function ( gl, properties, info ) {
 
 	};
 
+	function checkEdge( edges, a, b ) {
+
+		if ( edges[ a + '|' + b ] === true ) return false;
+
+		edges[ a + '|' + b ] = true;
+		edges[ b + '|' + a ] = true;
+
+		return true;
+
+	}
+
 	function createWireframeIndexBuffer( geometry ) {
 
 		var attributes = geometry.attributes;
 
-		// create wireframe indices
-
 		var indices = [];
 
 		var index = attributes.index;
 		var position = attributes.position;
 
+		console.time( 'wireframe' );
+
 		if ( index !== undefined ) {
 
+			var edges = {};
 			var array = index.array;
 
 			for ( var i = 0, j = 0, l = array.length; i < l; i += 3 ) {
@@ -71,9 +83,9 @@ THREE.WebGLGeometries = function ( gl, properties, info ) {
 				var b = array[ i + 1 ];
 				var c = array[ i + 2 ];
 
-				// TODO: Check for duplicates
-
-				indices.push( a, b, b, c, c, a );
+				if ( checkEdge( edges, a, b ) ) indices.push( a, b );
+				if ( checkEdge( edges, b, c ) ) indices.push( b, c );
+				if ( checkEdge( edges, c, a ) ) indices.push( c, a );
 
 			}
 
@@ -93,6 +105,8 @@ THREE.WebGLGeometries = function ( gl, properties, info ) {
 
 		}
 
+		console.timeEnd( 'wireframe' );
+
 		var TypeArray = position.array.length > 65535 ? Uint32Array : Uint16Array;
 
 		return new THREE.BufferAttribute( new TypeArray( indices ), 1 );