提交 da7e7255 编写于 作者: M Mr.doob

Implemented extend pattern in WebGLRenderer2 objects.

上级 82f90a00
THREE.WebGLRenderer.LineRenderer = function ( lowlevelrenderer, info ) {
THREE.WebGLRenderer.LineRenderer = function(lowlevelrenderer, info){
THREE.WebGLRenderer.Object3DRenderer.call( this, lowlevelrenderer, info ); THREE.WebGLRenderer.Object3DRenderer.call( this, lowlevelrenderer, info );
};
};
THREE.WebGLRenderer.LineRenderer.prototype = Object.create( THREE.WebGLRenderer.Object3DRenderer.prototype ); THREE.WebGLRenderer.LineRenderer.prototype = Object.create( THREE.WebGLRenderer.Object3DRenderer.prototype );
THREE.WebGLRenderer.LineRenderer.prototype.createBuffers = function( geometry ) { THREE.extend( THREE.WebGLRenderer.LineRenderer.prototype, {
var renderer = this.renderer; createBuffers: function ( geometry ) {
geometry.__webglVertexBuffer = renderer.createBuffer();
geometry.__webglColorBuffer = renderer.createBuffer();
geometry.__webglLineDistanceBuffer = renderer.createBuffer();
this.info.memory.geometries ++; var renderer = this.renderer;
}; geometry.__webglVertexBuffer = renderer.createBuffer();
geometry.__webglColorBuffer = renderer.createBuffer();
geometry.__webglLineDistanceBuffer = renderer.createBuffer();
THREE.WebGLRenderer.LineRenderer.prototype.initBuffers = function( geometry, object ) { this.info.memory.geometries ++;
var nvertices = geometry.vertices.length; },
geometry.__vertexArray = new Float32Array( nvertices * 3 ); initBuffers: function ( geometry, object ) {
geometry.__colorArray = new Float32Array( nvertices * 3 );
geometry.__lineDistanceArray = new Float32Array( nvertices * 1 );
geometry.__webglLineCount = nvertices; var nvertices = geometry.vertices.length;
this.initCustomAttributes ( geometry, object ); geometry.__vertexArray = new Float32Array( nvertices * 3 );
}; geometry.__colorArray = new Float32Array( nvertices * 3 );
geometry.__lineDistanceArray = new Float32Array( nvertices * 1 );
geometry.__webglLineCount = nvertices;
this.initCustomAttributes ( geometry, object );
THREE.WebGLRenderer.LineRenderer.prototype.setBuffers = function( geometry, object) { },
var renderer = this.renderer; setBuffers: function ( geometry, object ) {
var v, c, d, vertex, offset, color,
vertices = geometry.vertices, var renderer = this.renderer;
colors = geometry.colors, var v, c, d, vertex, offset, color,
lineDistances = geometry.lineDistances,
vl = vertices.length, vertices = geometry.vertices,
cl = colors.length, colors = geometry.colors,
dl = lineDistances.length, lineDistances = geometry.lineDistances,
vertexArray = geometry.__vertexArray, vl = vertices.length,
colorArray = geometry.__colorArray, cl = colors.length,
lineDistanceArray = geometry.__lineDistanceArray, dl = lineDistances.length,
dirtyVertices = geometry.verticesNeedUpdate, vertexArray = geometry.__vertexArray,
dirtyColors = geometry.colorsNeedUpdate, colorArray = geometry.__colorArray,
dirtyLineDistances = geometry.lineDistancesNeedUpdate, lineDistanceArray = geometry.__lineDistanceArray,
customAttributes = geometry.__webglCustomAttributesList, dirtyVertices = geometry.verticesNeedUpdate,
dirtyColors = geometry.colorsNeedUpdate,
dirtyLineDistances = geometry.lineDistancesNeedUpdate,
i, il, customAttributes = geometry.__webglCustomAttributesList,
a, ca, cal, value,
customAttribute;
if ( dirtyVertices ) { i, il,
a, ca, cal, value,
customAttribute;
for ( v = 0; v < vl; v ++ ) { if ( dirtyVertices ) {
vertex = vertices[ v ]; for ( v = 0; v < vl; v ++ ) {
offset = v * 3; vertex = vertices[ v ];
vertexArray[ offset ] = vertex.x; offset = v * 3;
vertexArray[ offset + 1 ] = vertex.y;
vertexArray[ offset + 2 ] = vertex.z; vertexArray[ offset ] = vertex.x;
vertexArray[ offset + 1 ] = vertex.y;
vertexArray[ offset + 2 ] = vertex.z;
}
renderer.setDynamicArrayBuffer(geometry.__webglVertexBuffer,vertexArray);
} }
renderer.setDynamicArrayBuffer(geometry.__webglVertexBuffer,vertexArray); if ( dirtyColors ) {
} for ( c = 0; c < cl; c ++ ) {
if ( dirtyColors ) { color = colors[ c ];
for ( c = 0; c < cl; c ++ ) { offset = c * 3;
color = colors[ c ]; colorArray[ offset ] = color.r;
colorArray[ offset + 1 ] = color.g;
colorArray[ offset + 2 ] = color.b;
offset = c * 3; }
colorArray[ offset ] = color.r; renderer.setDynamicArrayBuffer(geometry.__webglColorBuffer,colorArray);
colorArray[ offset + 1 ] = color.g;
colorArray[ offset + 2 ] = color.b;
} }
renderer.setDynamicArrayBuffer(geometry.__webglColorBuffer,colorArray); if ( dirtyLineDistances ) {
} for ( d = 0; d < dl; d ++ ) {
if ( dirtyLineDistances ) { lineDistanceArray[ d ] = lineDistances[ d ];
for ( d = 0; d < dl; d ++ ) { }
lineDistanceArray[ d ] = lineDistances[ d ]; renderer.setDynamicArrayBuffer( geometry.__webglLineDistanceBuffer,lineDistanceArray);
} }
renderer.setDynamicArrayBuffer( geometry.__webglLineDistanceBuffer,lineDistanceArray); if ( customAttributes ) {
}
if ( customAttributes ) { for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
for ( i = 0, il = customAttributes.length; i < il; i ++ ) { customAttribute = customAttributes[ i ];
customAttribute = customAttributes[ i ]; if ( customAttribute.needsUpdate &&
( customAttribute.boundTo === undefined ||
customAttribute.boundTo === "vertices" ) ) {
if ( customAttribute.needsUpdate && offset = 0;
( customAttribute.boundTo === undefined ||
customAttribute.boundTo === "vertices" ) ) {
offset = 0; cal = customAttribute.value.length;
cal = customAttribute.value.length; if ( customAttribute.size === 1 ) {
if ( customAttribute.size === 1 ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { customAttribute.array[ ca ] = customAttribute.value[ ca ];
customAttribute.array[ ca ] = customAttribute.value[ ca ]; }
} } else if ( customAttribute.size === 2 ) {
} else if ( customAttribute.size === 2 ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset ] = value.x; offset += 2;
customAttribute.array[ offset + 1 ] = value.y;
offset += 2; }
} } else if ( customAttribute.size === 3 ) {
} else if ( customAttribute.size === 3 ) { if ( customAttribute.type === "c" ) {
if ( customAttribute.type === "c" ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.r;
customAttribute.array[ offset + 1 ] = value.g;
customAttribute.array[ offset + 2 ] = value.b;
customAttribute.array[ offset ] = value.r; offset += 3;
customAttribute.array[ offset + 1 ] = value.g;
customAttribute.array[ offset + 2 ] = value.b;
offset += 3; }
} } else {
} else { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset ] = value.x; offset += 3;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
offset += 3; }
} }
} } else if ( customAttribute.size === 4 ) {
} else if ( customAttribute.size === 4 ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset + 3 ] = value.w;
customAttribute.array[ offset ] = value.x; offset += 4;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset + 3 ] = value.w;
offset += 4; }
} }
} renderer.setDynamicArrayBuffer( customAttribute.buffer,customAttribute.array);
renderer.setDynamicArrayBuffer( customAttribute.buffer,customAttribute.array); }
} }
} }
} }
};
} );
THREE.WebGLRenderer.Object3DRenderer = function ( lowlevelrenderer, info ) {
THREE.WebGLRenderer.Object3DRenderer = function(lowlevelrenderer, info){
this.renderer = lowlevelrenderer; this.renderer = lowlevelrenderer;
this.info = info; this.info = info;
}; };
THREE.WebGLRenderer.Object3DRenderer.prototype.getBufferMaterial = function( object, geometryGroup ) { THREE.extend( THREE.WebGLRenderer.Object3DRenderer.prototype, {
return object.material instanceof THREE.MeshFaceMaterial getBufferMaterial: function ( object, geometryGroup ) {
? object.material.materials[ geometryGroup.materialIndex ]
: object.material;
}; return object.material instanceof THREE.MeshFaceMaterial
? object.material.materials[ geometryGroup.materialIndex ]
: object.material;
THREE.WebGLRenderer.Object3DRenderer.prototype.bufferGuessUVType = function( material ) { },
// material must use some texture to require uvs bufferGuessUVType: function ( material ) {
if ( material.map || material.lightMap || material.bumpMap || material.normalMap || material.specularMap || material instanceof THREE.ShaderMaterial ) { // material must use some texture to require uvs
return true; if ( material.map || material.lightMap || material.bumpMap || material.normalMap || material.specularMap || material instanceof THREE.ShaderMaterial ) {
} return true;
return false; }
}; return false;
THREE.WebGLRenderer.Object3DRenderer.prototype.bufferGuessNormalType = function ( material ) { },
// only MeshBasicMaterial and MeshDepthMaterial don't need normals bufferGuessNormalType: function ( material ) {
if ( ( material instanceof THREE.MeshBasicMaterial && !material.envMap ) || material instanceof THREE.MeshDepthMaterial ) { // only MeshBasicMaterial and MeshDepthMaterial don't need normals
return false; if ( ( material instanceof THREE.MeshBasicMaterial && !material.envMap ) || material instanceof THREE.MeshDepthMaterial ) {
} return false;
if ( this.materialNeedsSmoothNormals( material ) ) { }
return THREE.SmoothShading; if ( this.materialNeedsSmoothNormals( material ) ) {
} else { return THREE.SmoothShading;
return THREE.FlatShading; } else {
} return THREE.FlatShading;
}; }
THREE.WebGLRenderer.Object3DRenderer.prototype.materialNeedsSmoothNormals = function ( material ) { },
return material && material.shading !== undefined && material.shading === THREE.SmoothShading; materialNeedsSmoothNormals: function ( material ) {
}; return material && material.shading !== undefined && material.shading === THREE.SmoothShading;
},
THREE.WebGLRenderer.Object3DRenderer.prototype.bufferGuessVertexColorType = function ( material ) { bufferGuessVertexColorType: function ( material ) {
if ( material.vertexColors ) { if ( material.vertexColors ) {
return material.vertexColors; return material.vertexColors;
} }
return false; return false;
}; },
initCustomAttributes: function ( geometry, object ) {
THREE.WebGLRenderer.Object3DRenderer.prototype.initCustomAttributes = function( geometry, object ) { var nvertices = geometry.vertices.length;
var nvertices = geometry.vertices.length; var material = object.material;
var material = object.material; if ( material.attributes ) {
if ( material.attributes ) { if ( geometry.__webglCustomAttributesList === undefined ) {
if ( geometry.__webglCustomAttributesList === undefined ) { geometry.__webglCustomAttributesList = [];
geometry.__webglCustomAttributesList = []; }
} for ( var a in material.attributes ) {
for ( var a in material.attributes ) { var attribute = material.attributes[ a ];
var attribute = material.attributes[ a ]; if ( !attribute.__webglInitialized || attribute.createUniqueBuffers ) {
if ( !attribute.__webglInitialized || attribute.createUniqueBuffers ) { attribute.__webglInitialized = true;
attribute.__webglInitialized = true; var size = 1; // "f" and "i"
var size = 1; // "f" and "i" if ( attribute.type === "v2" ) size = 2;
else if ( attribute.type === "v3" ) size = 3;
else if ( attribute.type === "v4" ) size = 4;
else if ( attribute.type === "c" ) size = 3;
if ( attribute.type === "v2" ) size = 2; attribute.size = size;
else if ( attribute.type === "v3" ) size = 3;
else if ( attribute.type === "v4" ) size = 4;
else if ( attribute.type === "c" ) size = 3;
attribute.size = size; attribute.array = new Float32Array( nvertices * size );
attribute.array = new Float32Array( nvertices * size ); attribute.buffer = this.renderer.createBuffer();
attribute.buffer.belongsToAttribute = a;
attribute.buffer = this.renderer.createBuffer(); attribute.needsUpdate = true;
attribute.buffer.belongsToAttribute = a;
attribute.needsUpdate = true; }
} geometry.__webglCustomAttributesList.push( attribute );
geometry.__webglCustomAttributesList.push( attribute ); }
} }
} },
}; numericalSort: function ( a, b ) {
THREE.WebGLRenderer.Object3DRenderer.prototype.numericalSort = function( a, b ) { return b[ 0 ] - a[ 0 ];
return b[ 0 ] - a[ 0 ]; }
}; } );
THREE.WebGLRenderer.ParticleRenderer = function ( lowlevelrenderer, info ) {
THREE.WebGLRenderer.ParticleRenderer = function(lowlevelrenderer, info){
THREE.WebGLRenderer.Object3DRenderer.call( this, lowlevelrenderer, info ); THREE.WebGLRenderer.Object3DRenderer.call( this, lowlevelrenderer, info );
}; };
THREE.WebGLRenderer.ParticleRenderer.prototype = Object.create( THREE.WebGLRenderer.Object3DRenderer.prototype ); THREE.WebGLRenderer.ParticleRenderer.prototype = Object.create( THREE.WebGLRenderer.Object3DRenderer.prototype );
THREE.WebGLRenderer.ParticleRenderer.prototype.createBuffers = function( geometry ) { THREE.extend( THREE.WebGLRenderer.ParticleRenderer.prototype, {
var renderer = this.renderer; createBuffers: function ( geometry ) {
geometry.__webglVertexBuffer = renderer.createBuffer();
geometry.__webglColorBuffer = renderer.createBuffer();
this.info.memory.geometries ++; var renderer = this.renderer;
}; geometry.__webglVertexBuffer = renderer.createBuffer();
geometry.__webglColorBuffer = renderer.createBuffer();
THREE.WebGLRenderer.ParticleRenderer.prototype.initBuffers = function( geometry, object ) { this.info.memory.geometries ++;
},
var nvertices = geometry.vertices.length; initBuffers: function ( geometry, object ) {
geometry.__vertexArray = new Float32Array( nvertices * 3 ); var nvertices = geometry.vertices.length;
geometry.__colorArray = new Float32Array( nvertices * 3 );
geometry.__sortArray = []; geometry.__vertexArray = new Float32Array( nvertices * 3 );
geometry.__colorArray = new Float32Array( nvertices * 3 );
geometry.__webglParticleCount = nvertices; geometry.__sortArray = [];
this.initCustomAttributes ( geometry, object ); geometry.__webglParticleCount = nvertices;
}; this.initCustomAttributes ( geometry, object );
},
THREE.WebGLRenderer.ParticleRenderer.prototype.setBuffers = function( geometry, object , projectionScreenMatrix) { setBuffers: function ( geometry, object , projectionScreenMatrix ) {
var renderer = this.renderer; var renderer = this.renderer;
var v, c, vertex, offset, index, color, var v, c, vertex, offset, index, color,
vertices = geometry.vertices, vertices = geometry.vertices,
vl = vertices.length, vl = vertices.length,
colors = geometry.colors, colors = geometry.colors,
cl = colors.length, cl = colors.length,
vertexArray = geometry.__vertexArray, vertexArray = geometry.__vertexArray,
colorArray = geometry.__colorArray, colorArray = geometry.__colorArray,
sortArray = geometry.__sortArray, sortArray = geometry.__sortArray,
dirtyVertices = geometry.verticesNeedUpdate, dirtyVertices = geometry.verticesNeedUpdate,
dirtyElements = geometry.elementsNeedUpdate, dirtyElements = geometry.elementsNeedUpdate,
dirtyColors = geometry.colorsNeedUpdate, dirtyColors = geometry.colorsNeedUpdate,
customAttributes = geometry.__webglCustomAttributesList, customAttributes = geometry.__webglCustomAttributesList,
i, il, i, il,
a, ca, cal, value, a, ca, cal, value,
customAttribute; customAttribute;
var _projScreenMatrixPS = THREE.WebGLRenderer.ParticleRenderer._m1, var _projScreenMatrixPS = THREE.WebGLRenderer.ParticleRenderer._m1,
_vector3 = THREE.WebGLRenderer.ParticleRenderer._v1; _vector3 = THREE.WebGLRenderer.ParticleRenderer._v1;
if ( object.sortParticles ) { if ( object.sortParticles ) {
_projScreenMatrixPS.multiplyMatrices( projectionScreenMatrix, object.matrixWorld ); _projScreenMatrixPS.multiplyMatrices( projectionScreenMatrix, object.matrixWorld );
for ( v = 0; v < vl; v ++ ) { for ( v = 0; v < vl; v ++ ) {
vertex = vertices[ v ]; vertex = vertices[ v ];
_vector3.copy( vertex ); _vector3.copy( vertex );
_vector3.applyProjection(_projScreenMatrixPS); _vector3.applyProjection(_projScreenMatrixPS);
sortArray[ v ] = [ _vector3.z, v ]; sortArray[ v ] = [ _vector3.z, v ];
} }
sortArray.sort( this.numericalSort ); sortArray.sort( this.numericalSort );
for ( v = 0; v < vl; v ++ ) { for ( v = 0; v < vl; v ++ ) {
vertex = vertices[ sortArray[v][1] ]; vertex = vertices[ sortArray[v][1] ];
offset = v * 3; offset = v * 3;
vertexArray[ offset ] = vertex.x; vertexArray[ offset ] = vertex.x;
vertexArray[ offset + 1 ] = vertex.y; vertexArray[ offset + 1 ] = vertex.y;
vertexArray[ offset + 2 ] = vertex.z; vertexArray[ offset + 2 ] = vertex.z;
} }
for ( c = 0; c < cl; c ++ ) { for ( c = 0; c < cl; c ++ ) {
offset = c * 3; offset = c * 3;
color = colors[ sortArray[c][1] ]; color = colors[ sortArray[c][1] ];
colorArray[ offset ] = color.r; colorArray[ offset ] = color.r;
colorArray[ offset + 1 ] = color.g; colorArray[ offset + 1 ] = color.g;
colorArray[ offset + 2 ] = color.b; colorArray[ offset + 2 ] = color.b;
} }
if ( customAttributes ) { if ( customAttributes ) {
for ( i = 0, il = customAttributes.length; i < il; i ++ ) { for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
customAttribute = customAttributes[ i ]; customAttribute = customAttributes[ i ];
if ( ! ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) ) continue; if ( ! ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) ) continue;
offset = 0; offset = 0;
cal = customAttribute.value.length; cal = customAttribute.value.length;
if ( customAttribute.size === 1 ) { if ( customAttribute.size === 1 ) {
for ( ca = 0; ca < cal; ca ++ ) { for ( ca = 0; ca < cal; ca ++ ) {
index = sortArray[ ca ][ 1 ]; index = sortArray[ ca ][ 1 ];
customAttribute.array[ ca ] = customAttribute.value[ index ]; customAttribute.array[ ca ] = customAttribute.value[ index ];
} }
} else if ( customAttribute.size === 2 ) { } else if ( customAttribute.size === 2 ) {
for ( ca = 0; ca < cal; ca ++ ) { for ( ca = 0; ca < cal; ca ++ ) {
index = sortArray[ ca ][ 1 ]; index = sortArray[ ca ][ 1 ];
value = customAttribute.value[ index ]; value = customAttribute.value[ index ];
customAttribute.array[ offset ] = value.x; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y; customAttribute.array[ offset + 1 ] = value.y;
offset += 2; offset += 2;
} }
} else if ( customAttribute.size === 3 ) { } else if ( customAttribute.size === 3 ) {
if ( customAttribute.type === "c" ) { if ( customAttribute.type === "c" ) {
for ( ca = 0; ca < cal; ca ++ ) { for ( ca = 0; ca < cal; ca ++ ) {
index = sortArray[ ca ][ 1 ]; index = sortArray[ ca ][ 1 ];
value = customAttribute.value[ index ]; value = customAttribute.value[ index ];
customAttribute.array[ offset ] = value.r; customAttribute.array[ offset ] = value.r;
customAttribute.array[ offset + 1 ] = value.g; customAttribute.array[ offset + 1 ] = value.g;
customAttribute.array[ offset + 2 ] = value.b; customAttribute.array[ offset + 2 ] = value.b;
offset += 3; offset += 3;
} }
} else { } else {
for ( ca = 0; ca < cal; ca ++ ) { for ( ca = 0; ca < cal; ca ++ ) {
index = sortArray[ ca ][ 1 ]; index = sortArray[ ca ][ 1 ];
value = customAttribute.value[ index ]; value = customAttribute.value[ index ];
customAttribute.array[ offset ] = value.x; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y; customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z; customAttribute.array[ offset + 2 ] = value.z;
offset += 3; offset += 3;
}
} }
} } else if ( customAttribute.size === 4 ) {
} else if ( customAttribute.size === 4 ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { index = sortArray[ ca ][ 1 ];
index = sortArray[ ca ][ 1 ]; value = customAttribute.value[ index ];
value = customAttribute.value[ index ]; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset + 3 ] = value.w;
customAttribute.array[ offset ] = value.x; offset += 4;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset + 3 ] = value.w;
offset += 4; }
} }
...@@ -194,121 +198,121 @@ THREE.WebGLRenderer.ParticleRenderer.prototype.setBuffers = function( geometry, ...@@ -194,121 +198,121 @@ THREE.WebGLRenderer.ParticleRenderer.prototype.setBuffers = function( geometry,
} }
} } else {
} else { if ( dirtyVertices ) {
if ( dirtyVertices ) { for ( v = 0; v < vl; v ++ ) {
for ( v = 0; v < vl; v ++ ) { vertex = vertices[ v ];
vertex = vertices[ v ]; offset = v * 3;
offset = v * 3; vertexArray[ offset ] = vertex.x;
vertexArray[ offset + 1 ] = vertex.y;
vertexArray[ offset + 2 ] = vertex.z;
vertexArray[ offset ] = vertex.x; }
vertexArray[ offset + 1 ] = vertex.y;
vertexArray[ offset + 2 ] = vertex.z;
} }
} if ( dirtyColors ) {
if ( dirtyColors ) { for ( c = 0; c < cl; c ++ ) {
for ( c = 0; c < cl; c ++ ) { color = colors[ c ];
color = colors[ c ]; offset = c * 3;
offset = c * 3; colorArray[ offset ] = color.r;
colorArray[ offset + 1 ] = color.g;
colorArray[ offset + 2 ] = color.b;
colorArray[ offset ] = color.r; }
colorArray[ offset + 1 ] = color.g;
colorArray[ offset + 2 ] = color.b;
} }
} if ( customAttributes ) {
if ( customAttributes ) { for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
for ( i = 0, il = customAttributes.length; i < il; i ++ ) { customAttribute = customAttributes[ i ];
customAttribute = customAttributes[ i ]; if ( customAttribute.needsUpdate &&
( customAttribute.boundTo === undefined ||
customAttribute.boundTo === "vertices") ) {
if ( customAttribute.needsUpdate && cal = customAttribute.value.length;
( customAttribute.boundTo === undefined ||
customAttribute.boundTo === "vertices") ) {
cal = customAttribute.value.length; offset = 0;
offset = 0; if ( customAttribute.size === 1 ) {
if ( customAttribute.size === 1 ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { customAttribute.array[ ca ] = customAttribute.value[ ca ];
customAttribute.array[ ca ] = customAttribute.value[ ca ]; }
} } else if ( customAttribute.size === 2 ) {
} else if ( customAttribute.size === 2 ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset ] = value.x; offset += 2;
customAttribute.array[ offset + 1 ] = value.y;
offset += 2; }
} } else if ( customAttribute.size === 3 ) {
} else if ( customAttribute.size === 3 ) { if ( customAttribute.type === "c" ) {
if ( customAttribute.type === "c" ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.r;
customAttribute.array[ offset + 1 ] = value.g;
customAttribute.array[ offset + 2 ] = value.b;
customAttribute.array[ offset ] = value.r; offset += 3;
customAttribute.array[ offset + 1 ] = value.g;
customAttribute.array[ offset + 2 ] = value.b;
offset += 3; }
} } else {
} else { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset ] = value.x; offset += 3;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
offset += 3; }
} }
} } else if ( customAttribute.size === 4 ) {
} else if ( customAttribute.size === 4 ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset + 3 ] = value.w;
customAttribute.array[ offset ] = value.x; offset += 4;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset + 3 ] = value.w;
offset += 4; }
} }
...@@ -320,29 +324,29 @@ THREE.WebGLRenderer.ParticleRenderer.prototype.setBuffers = function( geometry, ...@@ -320,29 +324,29 @@ THREE.WebGLRenderer.ParticleRenderer.prototype.setBuffers = function( geometry,
} }
} if ( dirtyVertices || object.sortParticles ) {
if ( dirtyVertices || object.sortParticles ) { renderer.setDynamicArrayBuffer(geometry.__webglVertexBuffer,vertexArray);
renderer.setDynamicArrayBuffer(geometry.__webglVertexBuffer,vertexArray); }
} if ( dirtyColors || object.sortParticles ) {
if ( dirtyColors || object.sortParticles ) { renderer.setDynamicArrayBuffer(geometry.__webglColorBuffer,colorArray);
renderer.setDynamicArrayBuffer(geometry.__webglColorBuffer,colorArray); }
} if ( customAttributes ) {
if ( customAttributes ) { for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
for ( i = 0, il = customAttributes.length; i < il; i ++ ) { customAttribute = customAttributes[ i ];
customAttribute = customAttributes[ i ]; if ( customAttribute.needsUpdate || object.sortParticles ) {
if ( customAttribute.needsUpdate || object.sortParticles ) { renderer.setDynamicArrayBuffer(customAttribute.buffer,customAttribute.array);
renderer.setDynamicArrayBuffer(customAttribute.buffer,customAttribute.array); }
} }
...@@ -350,8 +354,7 @@ THREE.WebGLRenderer.ParticleRenderer.prototype.setBuffers = function( geometry, ...@@ -350,8 +354,7 @@ THREE.WebGLRenderer.ParticleRenderer.prototype.setBuffers = function( geometry,
} }
} );
};
THREE.WebGLRenderer.ParticleRenderer._m1 = new THREE.Matrix4(); THREE.WebGLRenderer.ParticleRenderer._m1 = new THREE.Matrix4();
THREE.WebGLRenderer.ParticleRenderer._v1 = new THREE.Vector3(); THREE.WebGLRenderer.ParticleRenderer._v1 = new THREE.Vector3();
THREE.WebGLRenderer.RibbonRenderer = function ( lowlevelrenderer, info ) {
THREE.WebGLRenderer.RibbonRenderer = function(lowlevelrenderer, info){
THREE.WebGLRenderer.Object3DRenderer.call( this, lowlevelrenderer, info ); THREE.WebGLRenderer.Object3DRenderer.call( this, lowlevelrenderer, info );
}; };
THREE.WebGLRenderer.RibbonRenderer.prototype = Object.create( THREE.WebGLRenderer.Object3DRenderer.prototype ); THREE.WebGLRenderer.RibbonRenderer.prototype = Object.create( THREE.WebGLRenderer.Object3DRenderer.prototype );
THREE.WebGLRenderer.RibbonRenderer.prototype.createBuffers = function( geometry ) { THREE.extend( THREE.WebGLRenderer.RibbonRenderer.prototype, {
var renderer = this.renderer; createBuffers: function ( geometry ) {
geometry.__webglVertexBuffer = renderer.createBuffer();
geometry.__webglColorBuffer = renderer.createBuffer();
geometry.__webglNormalBuffer = renderer.createBuffer();
this.info.memory.geometries ++; var renderer = this.renderer;
}; geometry.__webglVertexBuffer = renderer.createBuffer();
geometry.__webglColorBuffer = renderer.createBuffer();
geometry.__webglNormalBuffer = renderer.createBuffer();
THREE.WebGLRenderer.RibbonRenderer.prototype.initBuffers = function( geometry, object ) { this.info.memory.geometries ++;
},
var nvertices = geometry.vertices.length; initBuffers: function ( geometry, object ) {
geometry.__vertexArray = new Float32Array( nvertices * 3 ); var nvertices = geometry.vertices.length;
geometry.__colorArray = new Float32Array( nvertices * 3 );
geometry.__normalArray = new Float32Array( nvertices * 3 );
geometry.__webglVertexCount = nvertices; geometry.__vertexArray = new Float32Array( nvertices * 3 );
geometry.__colorArray = new Float32Array( nvertices * 3 );
geometry.__normalArray = new Float32Array( nvertices * 3 );
this.initCustomAttributes ( geometry, object ); geometry.__webglVertexCount = nvertices;
}; this.initCustomAttributes ( geometry, object );
},
THREE.WebGLRenderer.RibbonRenderer.prototype.setBuffers = function( geometry, object , projectionScreenMatrix) { setBuffers: function ( geometry, object , projectionScreenMatrix ) {
var renderer = this.renderer; var renderer = this.renderer;
var v, c, n, vertex, offset, color, normal, var v, c, n, vertex, offset, color, normal,
i, il, ca, cal, customAttribute, value, i, il, ca, cal, customAttribute, value,
vertices = geometry.vertices, vertices = geometry.vertices,
colors = geometry.colors, colors = geometry.colors,
normals = geometry.normals, normals = geometry.normals,
vl = vertices.length, vl = vertices.length,
cl = colors.length, cl = colors.length,
nl = normals.length, nl = normals.length,
vertexArray = geometry.__vertexArray, vertexArray = geometry.__vertexArray,
colorArray = geometry.__colorArray, colorArray = geometry.__colorArray,
normalArray = geometry.__normalArray, normalArray = geometry.__normalArray,
dirtyVertices = geometry.verticesNeedUpdate, dirtyVertices = geometry.verticesNeedUpdate,
dirtyColors = geometry.colorsNeedUpdate, dirtyColors = geometry.colorsNeedUpdate,
dirtyNormals = geometry.normalsNeedUpdate, dirtyNormals = geometry.normalsNeedUpdate,
customAttributes = geometry.__webglCustomAttributesList; customAttributes = geometry.__webglCustomAttributesList;
if ( dirtyVertices ) { if ( dirtyVertices ) {
for ( v = 0; v < vl; v ++ ) { for ( v = 0; v < vl; v ++ ) {
vertex = vertices[ v ]; vertex = vertices[ v ];
offset = v * 3; offset = v * 3;
vertexArray[ offset ] = vertex.x; vertexArray[ offset ] = vertex.x;
vertexArray[ offset + 1 ] = vertex.y; vertexArray[ offset + 1 ] = vertex.y;
vertexArray[ offset + 2 ] = vertex.z; vertexArray[ offset + 2 ] = vertex.z;
}
renderer.setDynamicArrayBuffer( geometry.__webglVertexBuffer,vertexArray);
} }
renderer.setDynamicArrayBuffer( geometry.__webglVertexBuffer,vertexArray); if ( dirtyColors ) {
} for ( c = 0; c < cl; c ++ ) {
if ( dirtyColors ) { color = colors[ c ];
for ( c = 0; c < cl; c ++ ) { offset = c * 3;
color = colors[ c ]; colorArray[ offset ] = color.r;
colorArray[ offset + 1 ] = color.g;
colorArray[ offset + 2 ] = color.b;
offset = c * 3; }
colorArray[ offset ] = color.r; renderer.setDynamicArrayBuffer( geometry.__webglColorBuffer, colorArray);
colorArray[ offset + 1 ] = color.g;
colorArray[ offset + 2 ] = color.b;
} }
renderer.setDynamicArrayBuffer( geometry.__webglColorBuffer, colorArray); if ( dirtyNormals ) {
} for ( n = 0; n < nl; n ++ ) {
if ( dirtyNormals ) { normal = normals[ n ];
for ( n = 0; n < nl; n ++ ) { offset = n * 3;
normal = normals[ n ]; normalArray[ offset ] = normal.x;
normalArray[ offset + 1 ] = normal.y;
normalArray[ offset + 2 ] = normal.z;
offset = n * 3; }
normalArray[ offset ] = normal.x; renderer.setDynamicArrayBuffer( geometry.__webglNormalBuffer, normalArray);
normalArray[ offset + 1 ] = normal.y;
normalArray[ offset + 2 ] = normal.z;
} }
renderer.setDynamicArrayBuffer( geometry.__webglNormalBuffer, normalArray); if ( customAttributes ) {
} for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
if ( customAttributes ) { customAttribute = customAttributes[ i ];
for ( i = 0, il = customAttributes.length; i < il; i ++ ) { if ( customAttribute.needsUpdate &&
( customAttribute.boundTo === undefined ||
customAttribute.boundTo === "vertices" ) ) {
customAttribute = customAttributes[ i ]; offset = 0;
if ( customAttribute.needsUpdate && cal = customAttribute.value.length;
( customAttribute.boundTo === undefined ||
customAttribute.boundTo === "vertices" ) ) {
offset = 0; if ( customAttribute.size === 1 ) {
cal = customAttribute.value.length; for ( ca = 0; ca < cal; ca ++ ) {
if ( customAttribute.size === 1 ) { customAttribute.array[ ca ] = customAttribute.value[ ca ];
for ( ca = 0; ca < cal; ca ++ ) { }
customAttribute.array[ ca ] = customAttribute.value[ ca ]; } else if ( customAttribute.size === 2 ) {
} for ( ca = 0; ca < cal; ca ++ ) {
} else if ( customAttribute.size === 2 ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset ] = value.x; offset += 2;
customAttribute.array[ offset + 1 ] = value.y;
offset += 2; }
} } else if ( customAttribute.size === 3 ) {
} else if ( customAttribute.size === 3 ) { if ( customAttribute.type === "c" ) {
if ( customAttribute.type === "c" ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.r;
customAttribute.array[ offset + 1 ] = value.g;
customAttribute.array[ offset + 2 ] = value.b;
customAttribute.array[ offset ] = value.r; offset += 3;
customAttribute.array[ offset + 1 ] = value.g;
customAttribute.array[ offset + 2 ] = value.b;
offset += 3; }
} } else {
} else { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset ] = value.x; offset += 3;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
offset += 3; }
} }
} } else if ( customAttribute.size === 4 ) {
} else if ( customAttribute.size === 4 ) { for ( ca = 0; ca < cal; ca ++ ) {
for ( ca = 0; ca < cal; ca ++ ) { value = customAttribute.value[ ca ];
value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset + 3 ] = value.w;
customAttribute.array[ offset ] = value.x; offset += 4;
customAttribute.array[ offset + 1 ] = value.y;
customAttribute.array[ offset + 2 ] = value.z;
customAttribute.array[ offset + 3 ] = value.w;
offset += 4; }
} }
} renderer.setDynamicArrayBuffer( customAttribute.buffer, customAttribute.array);
renderer.setDynamicArrayBuffer( customAttribute.buffer, customAttribute.array); }
} }
...@@ -202,4 +206,4 @@ THREE.WebGLRenderer.RibbonRenderer.prototype.setBuffers = function( geometry, ob ...@@ -202,4 +206,4 @@ THREE.WebGLRenderer.RibbonRenderer.prototype.setBuffers = function( geometry, ob
} }
}; } );
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册