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

SVGRenderer: Reset counters on clear() instead of on render(). Cleaned up code a bit too.

上级 c5cca753
......@@ -19,7 +19,6 @@ THREE.SVGRenderer = function () {
_color = new THREE.Color(),
_diffuseColor = new THREE.Color(),
_emissiveColor = new THREE.Color(),
_ambientLight = new THREE.Color(),
_directionalLights = new THREE.Color(),
_pointLights = new THREE.Color(),
......@@ -80,6 +79,10 @@ THREE.SVGRenderer = function () {
this.clear = function () {
_pathCount = 0;
_circleCount = 0;
_lineCount = 0;
while ( _svg.childNodes.length > 0 ) {
_svg.removeChild( _svg.childNodes[ 0 ] );
......@@ -97,9 +100,7 @@ THREE.SVGRenderer = function () {
}
var e, el, element, material;
this.autoClear && this.clear();
if ( this.autoClear === true ) this.clear();
_this.info.render.vertices = 0;
_this.info.render.faces = 0;
......@@ -108,15 +109,12 @@ THREE.SVGRenderer = function () {
_elements = _renderData.elements;
_lights = _renderData.lights;
_pathCount = 0; _circleCount = 0; _lineCount = 0;
calculateLights( _lights );
for ( e = 0, el = _elements.length; e < el; e ++ ) {
element = _elements[ e ];
for ( var e = 0, el = _elements.length; e < el; e ++ ) {
material = element.material;
var element = _elements[ e ];
var material = element.material;
if ( material === undefined || material.visible === false ) continue;
......@@ -127,7 +125,7 @@ THREE.SVGRenderer = function () {
_v1 = element;
_v1.x *= _svgWidthHalf; _v1.y *= -_svgHeightHalf;
renderParticle( _v1, element, material, scene );
renderParticle( _v1, element, material );
} else if ( element instanceof THREE.RenderableLine ) {
......@@ -140,7 +138,7 @@ THREE.SVGRenderer = function () {
if ( _clipBox.isIntersectionBox( _elemBox ) === true ) {
renderLine( _v1, _v2, element, material, scene );
renderLine( _v1, _v2, element, material );
}
......@@ -158,7 +156,7 @@ THREE.SVGRenderer = function () {
_elemBox.setFromPoints( [ _v1.positionScreen, _v2.positionScreen, _v3.positionScreen ] );
renderFace3( _v1, _v2, _v3, element, material, scene );
renderFace3( _v1, _v2, _v3, element, material );
} else if ( element instanceof THREE.RenderableFace4 ) {
......@@ -176,7 +174,7 @@ THREE.SVGRenderer = function () {
_elemBox.setFromPoints( [ _v1.positionScreen, _v2.positionScreen, _v3.positionScreen, _v4.positionScreen ] );
renderFace4( _v1, _v2, _v3, _v4, element, material, scene );
renderFace4( _v1, _v2, _v3, _v4, element, material );
}
......@@ -186,16 +184,14 @@ THREE.SVGRenderer = function () {
function calculateLights( lights ) {
var l, ll, light, lightColor;
_ambientLight.setRGB( 0, 0, 0 );
_directionalLights.setRGB( 0, 0, 0 );
_pointLights.setRGB( 0, 0, 0 );
for ( l = 0, ll = lights.length; l < ll; l++ ) {
for ( var l = 0, ll = lights.length; l < ll; l++ ) {
light = lights[ l ];
lightColor = light.color;
var light = lights[ l ];
var lightColor = light.color;
if ( light instanceof THREE.AmbientLight ) {
......@@ -266,7 +262,7 @@ THREE.SVGRenderer = function () {
}
function renderParticle( v1, element, material, scene ) {
function renderParticle( v1, element, material ) {
/*
_svgNode = getCircleNode( _circleCount++ );
......@@ -295,7 +291,7 @@ THREE.SVGRenderer = function () {
}
function renderLine ( v1, v2, element, material, scene ) {
function renderLine ( v1, v2, element, material ) {
_svgNode = getLineNode( _lineCount ++ );
......@@ -314,7 +310,7 @@ THREE.SVGRenderer = function () {
}
function renderFace3( v1, v2, v3, element, material, scene ) {
function renderFace3( v1, v2, v3, element, material ) {
_this.info.render.vertices += 3;
_this.info.render.faces ++;
......@@ -332,10 +328,9 @@ THREE.SVGRenderer = function () {
}
} else if ( material instanceof THREE.MeshLambertMaterial ) {
} else if ( material instanceof THREE.MeshLambertMaterial || material instanceof THREE.MeshPhongMaterial ) {
_diffuseColor.copy( material.color );
_emissiveColor.copy( material.emissive );
if ( material.vertexColors === THREE.FaceColors ) {
......@@ -347,7 +342,7 @@ THREE.SVGRenderer = function () {
calculateLight( _lights, element.centroidModel, element.normalModel, _color );
_color.multiply( _diffuseColor ).add( _emissiveColor );
_color.multiply( _diffuseColor ).add( material.emissive );
} else if ( material instanceof THREE.MeshDepthMaterial ) {
......@@ -376,7 +371,7 @@ THREE.SVGRenderer = function () {
}
function renderFace4( v1, v2, v3, v4, element, material, scene ) {
function renderFace4( v1, v2, v3, v4, element, material ) {
_this.info.render.vertices += 4;
_this.info.render.faces ++;
......@@ -394,10 +389,9 @@ THREE.SVGRenderer = function () {
}
} else if ( material instanceof THREE.MeshLambertMaterial ) {
} else if ( material instanceof THREE.MeshLambertMaterial || material instanceof THREE.MeshPhongMaterial ) {
_diffuseColor.copy( material.color );
_emissiveColor.copy( material.emissive );
if ( material.vertexColors === THREE.FaceColors ) {
......@@ -409,7 +403,7 @@ THREE.SVGRenderer = function () {
calculateLight( _lights, element.centroidModel, element.normalModel, _color );
_color.multiply( _diffuseColor ).add( _emissiveColor );
_color.multiply( _diffuseColor ).add( material.emissive );
} else if ( material instanceof THREE.MeshDepthMaterial ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册