浏览代码

Projector: BufferGeometry-based Lines vertex colors support.

Mr.doob 8 年之前
父节点
当前提交
268ba4d2ae
共有 1 个文件被更改,包括 31 次插入3 次删除
  1. 31 3
      examples/js/renderers/Projector.js

+ 31 - 3
examples/js/renderers/Projector.js

@@ -153,6 +153,7 @@ THREE.Projector = function () {
 	var RenderList = function () {
 	var RenderList = function () {
 
 
 		var normals = [];
 		var normals = [];
+		var colors = [];
 		var uvs = [];
 		var uvs = [];
 
 
 		var object = null;
 		var object = null;
@@ -168,6 +169,7 @@ THREE.Projector = function () {
 			normalMatrix.getNormalMatrix( object.matrixWorld );
 			normalMatrix.getNormalMatrix( object.matrixWorld );
 
 
 			normals.length = 0;
 			normals.length = 0;
+			colors.length = 0;
 			uvs.length = 0;
 			uvs.length = 0;
 
 
 		}
 		}
@@ -208,6 +210,12 @@ THREE.Projector = function () {
 
 
 		}
 		}
 
 
+		function pushColor( r, g, b ) {
+
+			colors.push( r, g, b );
+
+		}
+
 		function pushUv( x, y ) {
 		function pushUv( x, y ) {
 
 
 			uvs.push( x, y );
 			uvs.push( x, y );
@@ -235,7 +243,7 @@ THREE.Projector = function () {
 
 
 		}
 		}
 
 
-		function pushLine( a, b, _modelViewProjectionMatrix ) {
+		function pushLine( a, b ) {
 
 
 			var v1 = _vertexPool[ a ];
 			var v1 = _vertexPool[ a ];
 			var v2 = _vertexPool[ b ];
 			var v2 = _vertexPool[ b ];
@@ -260,6 +268,13 @@ THREE.Projector = function () {
 
 
 				_line.material = object.material;
 				_line.material = object.material;
 
 
+				if ( object.material.vertexColors === THREE.VertexColors ) {
+
+					_line.vertexColors[ 0 ].fromArray( colors, a * 3 );
+					_line.vertexColors[ 1 ].fromArray( colors, b * 3 );
+
+				}
+
 				_renderData.elements.push( _line );
 				_renderData.elements.push( _line );
 
 
 			}
 			}
@@ -318,6 +333,7 @@ THREE.Projector = function () {
 			checkBackfaceCulling: checkBackfaceCulling,
 			checkBackfaceCulling: checkBackfaceCulling,
 			pushVertex: pushVertex,
 			pushVertex: pushVertex,
 			pushNormal: pushNormal,
 			pushNormal: pushNormal,
+			pushColor: pushColor,
 			pushUv: pushUv,
 			pushUv: pushUv,
 			pushLine: pushLine,
 			pushLine: pushLine,
 			pushTriangle: pushTriangle
 			pushTriangle: pushTriangle
@@ -636,13 +652,25 @@ THREE.Projector = function () {
 
 
 						}
 						}
 
 
+						if ( attributes.color !== undefined ) {
+
+							var colors = attributes.color.array;
+
+							for ( var i = 0, l = colors.length; i < l; i += 3 ) {
+
+								renderList.pushColor( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] );
+
+							}
+
+						}
+
 						if ( geometry.index !== null ) {
 						if ( geometry.index !== null ) {
 
 
 							var indices = geometry.index.array;
 							var indices = geometry.index.array;
 
 
 							for ( var i = 0, l = indices.length; i < l; i += 2 ) {
 							for ( var i = 0, l = indices.length; i < l; i += 2 ) {
 
 
-								renderList.pushLine( indices[ i ], indices[ i + 1 ], _modelViewProjectionMatrix );
+								renderList.pushLine( indices[ i ], indices[ i + 1 ] );
 
 
 							}
 							}
 
 
@@ -652,7 +680,7 @@ THREE.Projector = function () {
 
 
 							for ( var i = 0, l = ( positions.length / 3 ) - 1; i < l; i += step ) {
 							for ( var i = 0, l = ( positions.length / 3 ) - 1; i < l; i += step ) {
 
 
-								renderList.pushLine( i, i + 1, _modelViewProjectionMatrix );
+								renderList.pushLine( i, i + 1 );
 
 
 							}
 							}