소스 검색

SVGRenderer: create special method to flush accumulated path

Such method can be used directly at the end of rendering loop
Sergey Linev 8 년 전
부모
커밋
0daa689405
1개의 변경된 파일18개의 추가작업 그리고 11개의 파일을 삭제
  1. 18 11
      examples/js/renderers/SVGRenderer.js

+ 18 - 11
examples/js/renderers/SVGRenderer.js

@@ -46,7 +46,7 @@ THREE.SVGRenderer = function () {
 
 	_svgPathPool = [],
 	_svgNode, _pathCount = 0, _currPath, _currStyle,
-	_quality = 1, _precision = -1;
+	_quality = 1, _precision = null;
 
 	this.domElement = _svg;
 
@@ -134,7 +134,7 @@ THREE.SVGRenderer = function () {
 
 	function convert ( c ) {
 
-		return _precision < 0 ? c : c.toFixed(_precision);
+		return _precision !== null ? c.toFixed(_precision) : c;
 
 	}
 
@@ -241,7 +241,7 @@ THREE.SVGRenderer = function () {
 
 		}
 
-		addPath ( "!dummy!", ""); // just to flush last svg:path
+		flushPath(); // just to flush last svg:path
 
 		scene.traverseVisible( function ( object ) {
 
@@ -447,14 +447,7 @@ THREE.SVGRenderer = function () {
 
 		} else {
 
-			if ( _currPath ) {
-
-				_svgNode = getPathNode( _pathCount ++ );
-				_svgNode.setAttribute( 'd', _currPath );
-				_svgNode.setAttribute( 'style', _currStyle );
-				_svg.appendChild( _svgNode );
-
-			}
+			flushPath();
 
 			_currStyle = style;
 			_currPath = path;
@@ -463,6 +456,20 @@ THREE.SVGRenderer = function () {
 
 	}
 
+	function flushPath() {
+
+		if ( _currPath ) {
+
+			_svgNode = getPathNode( _pathCount ++ );
+			_svgNode.setAttribute( 'd', _currPath );
+			_svgNode.setAttribute( 'style', _currStyle );
+			_svg.appendChild( _svgNode );
+
+		}
+
+		_currPath = _currStyle = "";
+	}
+
 	function getPathNode( id ) {
 
 		if ( _svgPathPool[ id ] == null ) {