Browse Source

Merge remote-tracking branch 'sole/dev-build-python-less-than-2.7' into dev

Mr.doob 12 years ago
parent
commit
14fbf7e895
2 changed files with 49 additions and 1 deletions
  1. 41 0
      src/renderers/CanvasRenderer.js
  2. 8 1
      utils/build.py

+ 41 - 0
src/renderers/CanvasRenderer.js

@@ -29,6 +29,8 @@ THREE.CanvasRenderer = function ( parameters ) {
 	_contextLineWidth = null,
 	_contextLineCap = null,
 	_contextLineJoin = null,
+	_contextDashSize = null,
+	_contextGapSize = 0,
 
 	_v1, _v2, _v3, _v4,
 	_v5 = new THREE.RenderableVertex(),
@@ -89,6 +91,21 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 	_gradientMapQuality --; // Fix UVs
 
+	// dash+gap fallbacks for Firefox and everything else
+	if( ! _context.setLineDash ) {
+		if( 'mozDash' in _context ) {
+			_context.setLineDash = function( values ) {
+				if( values[0] == null || values[1] == null) {
+					_context.mozDash = null;
+				} else {
+					_context.mozDash = values;
+				}
+			}
+		} else {
+			_context.setLineDash = function( values ) {}
+		}
+	}
+
 	this.domElement = _canvas;
 
 	this.devicePixelRatio = parameters.devicePixelRatio !== undefined
@@ -573,6 +590,18 @@ THREE.CanvasRenderer = function ( parameters ) {
 				setLineCap( material.linecap );
 				setLineJoin( material.linejoin );
 				setStrokeStyle( material.color.getStyle() );
+				setDashAndGap( null, null );
+
+				_context.stroke();
+				_elemBox.expandByScalar( material.linewidth * 2 );
+
+			} else if ( material instanceof THREE.LineDashedMaterial ) {
+
+				setLineWidth( material.linewidth );
+				setLineCap( material.linecap );
+				setLineJoin( material.linejoin );
+				setStrokeStyle( material.color.getStyle() );
+				setDashAndGap( material.dashSize, material.gapSize );
 
 				_context.stroke();
 				_elemBox.expandByScalar( material.linewidth * 2 );
@@ -1260,4 +1289,16 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 	}
 
+	function setDashAndGap( dashSizeValue, gapSizeValue ) {
+
+		if( _contextDashSize !== dashSizeValue || _contextGapSize !== gapSizeValue ) {
+			
+			_context.setLineDash([ dashSizeValue, gapSizeValue ]);
+			_contextDashSize = dashSizeValue;
+			_contextGapSize = gapSizeValue;
+		
+		}
+
+	}
+
 };

+ 8 - 1
utils/build.py

@@ -1,10 +1,17 @@
 #!/usr/bin/env python
 
+import sys
+
+if sys.version_info < (2, 7):
+	print("ERROR: The build script requires Python 2.7 or higher.")
+	print("You can get an updated version here: http://www.python.org/download/releases/")
+	exit()
+
+
 import argparse
 import json
 import os
 import shutil
-import sys
 import tempfile