Comparing version 0.58.3 to 0.58.4
@@ -5,3 +5,3 @@ { | ||
"version" : "0.58.3", | ||
"version" : "0.58.4", | ||
@@ -8,0 +8,0 @@ "description" : "JavaScript 3D library", |
@@ -53,2 +53,7 @@ /** | ||
addEventListener: THREE.EventDispatcher.prototype.addEventListener, | ||
hasEventListener: THREE.EventDispatcher.prototype.hasEventListener, | ||
removeEventListener: THREE.EventDispatcher.prototype.removeEventListener, | ||
dispatchEvent: THREE.EventDispatcher.prototype.dispatchEvent, | ||
applyMatrix: function () { | ||
@@ -55,0 +60,0 @@ |
@@ -78,99 +78,69 @@ /** | ||
var projectGraph = function ( root, sortObjects ) { | ||
var getObject = function ( object ) { | ||
_objectCount = 0; | ||
_object = getNextObjectInPool(); | ||
_object.object = object; | ||
_renderData.objects.length = 0; | ||
_renderData.sprites.length = 0; | ||
_renderData.lights.length = 0; | ||
if ( object.renderDepth !== null ) { | ||
var projectObject = function ( parent ) { | ||
_object.z = object.renderDepth; | ||
for ( var c = 0, cl = parent.children.length; c < cl; c ++ ) { | ||
} else { | ||
var object = parent.children[ c ]; | ||
_vector3.getPositionFromMatrix( object.matrixWorld ); | ||
_vector3.applyProjection( _viewProjectionMatrix ); | ||
_object.z = _vector3.z; | ||
if ( object.visible === false ) continue; | ||
} | ||
if ( object instanceof THREE.Light ) { | ||
return _object; | ||
_renderData.lights.push( object ); | ||
}; | ||
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line ) { | ||
var projectObject = function ( object ) { | ||
if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) { | ||
if ( object.visible === false ) return; | ||
_object = getNextObjectInPool(); | ||
_object.object = object; | ||
if ( object instanceof THREE.Light ) { | ||
if ( object.renderDepth !== null ) { | ||
_renderData.lights.push( object ); | ||
_object.z = object.renderDepth; | ||
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line ) { | ||
} else { | ||
if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) { | ||
_vector3.getPositionFromMatrix( object.matrixWorld ); | ||
_vector3.applyProjection( _viewProjectionMatrix ); | ||
_object.z = _vector3.z; | ||
_renderData.objects.push( getObject( object ) ); | ||
} | ||
} | ||
_renderData.objects.push( _object ); | ||
} else if ( object instanceof THREE.Sprite || object instanceof THREE.Particle ) { | ||
} | ||
_renderData.sprites.push( getObject( object ) ); | ||
} else if ( object instanceof THREE.Sprite || object instanceof THREE.Particle ) { | ||
} | ||
_object = getNextObjectInPool(); | ||
_object.object = object; | ||
for ( var i = 0, l = object.children.length; i < l; i ++ ) { | ||
// TODO: Find an elegant and performant solution and remove this dupe code. | ||
projectObject( object.children[ i ] ); | ||
if ( object.renderDepth !== null ) { | ||
} | ||
_object.z = object.renderDepth; | ||
}; | ||
} else { | ||
var projectGraph = function ( root, sortObjects ) { | ||
_vector3.getPositionFromMatrix( object.matrixWorld ); | ||
_vector3.applyProjection( _viewProjectionMatrix ); | ||
_object.z = _vector3.z; | ||
_objectCount = 0; | ||
} | ||
_renderData.objects.length = 0; | ||
_renderData.sprites.length = 0; | ||
_renderData.lights.length = 0; | ||
_renderData.sprites.push( _object ); | ||
projectObject( root ); | ||
} else { | ||
if ( sortObjects === true ) { | ||
_object = getNextObjectInPool(); | ||
_object.object = object; | ||
_renderData.objects.sort( painterSort ); | ||
if ( object.renderDepth !== null ) { | ||
} | ||
_object.z = object.renderDepth; | ||
} else { | ||
_vector3.getPositionFromMatrix( object.matrixWorld ); | ||
_vector3.applyProjection( _viewProjectionMatrix ); | ||
_object.z = _vector3.z; | ||
} | ||
_renderData.objects.push( _object ); | ||
} | ||
projectObject( object ); | ||
} | ||
}; | ||
projectObject( root ); | ||
if ( sortObjects === true ) _renderData.objects.sort( painterSort ); | ||
return _renderData; | ||
}; | ||
@@ -202,3 +172,3 @@ | ||
_renderData = projectGraph( scene, sortObjects ); | ||
projectGraph( scene, sortObjects ); | ||
@@ -205,0 +175,0 @@ for ( o = 0, ol = _renderData.objects.length; o < ol; o ++ ) { |
@@ -66,7 +66,2 @@ /** | ||
// Merge vertices | ||
this.mergeVertices(); | ||
// Apply radius | ||
@@ -81,2 +76,13 @@ | ||
// Merge vertices | ||
this.mergeVertices(); | ||
this.computeCentroids(); | ||
this.computeFaceNormals(); | ||
this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius ); | ||
// Project vector onto sphere's surface | ||
@@ -106,3 +112,2 @@ | ||
face.centroid.add( v1 ).add( v2 ).add( v3 ).divideScalar( 3 ); | ||
face.normal.copy( face.centroid ).normalize(); | ||
that.faces.push( face ); | ||
@@ -219,8 +224,5 @@ | ||
this.computeCentroids(); | ||
this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius ); | ||
}; | ||
THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype ); |
@@ -104,2 +104,4 @@ /** | ||
this.update(); | ||
}; | ||
@@ -106,0 +108,0 @@ |
@@ -13,8 +13,7 @@ /** | ||
geometry.vertices.push( new THREE.Vector3( -size, 0, i ) ); | ||
geometry.vertices.push( new THREE.Vector3( size, 0, i ) ); | ||
geometry.vertices.push( | ||
new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ), | ||
new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size ) | ||
); | ||
geometry.vertices.push( new THREE.Vector3( i, 0, -size ) ); | ||
geometry.vertices.push( new THREE.Vector3( i, 0, size ) ); | ||
var color = i === 0 ? color1 : color2; | ||
@@ -21,0 +20,0 @@ |
@@ -125,11 +125,20 @@ /** | ||
if ( position ) | ||
result.scene.position.set( position[ 0 ], position[ 1 ], position [ 2 ] ); | ||
if ( position ) { | ||
if ( rotation ) | ||
result.scene.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation [ 2 ] ); | ||
result.scene.position.fromArray( position ); | ||
if ( scale ) | ||
result.scene.scale.set( scale[ 0 ], scale[ 1 ], scale [ 2 ] ); | ||
} | ||
if ( rotation ) { | ||
result.scene.rotation.fromArray( rotation ); | ||
} | ||
if ( scale ) { | ||
result.scene.scale.fromArray( scale ); | ||
} | ||
if ( position || rotation || scale ) { | ||
@@ -177,8 +186,7 @@ | ||
if ( result.objects[ objID ] === undefined ) { | ||
var object = result.objects[ objID ]; | ||
var objJSON = children[ objID ]; | ||
var objJSON = children[ objID ]; | ||
if ( object === undefined ) { | ||
var object = null; | ||
// meshes | ||
@@ -190,6 +198,8 @@ | ||
var reservedTypes = { "type": 1, "url": 1, "material": 1, | ||
"position": 1, "rotation": 1, "scale" : 1, | ||
"visible": 1, "children": 1, "userData": 1, | ||
"skin": 1, "morph": 1, "mirroredLoop": 1, "duration": 1 }; | ||
var reservedTypes = { | ||
"type": 1, "url": 1, "material": 1, | ||
"position": 1, "rotation": 1, "scale" : 1, | ||
"visible": 1, "children": 1, "userData": 1, | ||
"skin": 1, "morph": 1, "mirroredLoop": 1, "duration": 1 | ||
}; | ||
@@ -337,7 +347,7 @@ var loaderParameters = {}; | ||
object.position.set( pos[0], pos[1], pos[2] ); | ||
object.position.fromArray( pos ); | ||
if ( quat ) { | ||
object.quaternion.set( quat[0], quat[1], quat[2], quat[3] ); | ||
object.quaternion.fromArray( quat ); | ||
object.useQuaternion = true; | ||
@@ -347,7 +357,7 @@ | ||
object.rotation.set( rot[0], rot[1], rot[2] ); | ||
object.rotation.fromArray( rot ); | ||
} | ||
object.scale.set( scl[0], scl[1], scl[2] ); | ||
object.scale.fromArray( scl ); | ||
@@ -378,3 +388,3 @@ } | ||
light = new THREE.DirectionalLight( hex, intensity ); | ||
light.position.set( pos[0], pos[1], pos[2] ); | ||
light.position.fromArray( pos ); | ||
@@ -398,3 +408,3 @@ if ( objJSON.target ) { | ||
light = new THREE.PointLight( hex, intensity, dst ); | ||
light.position.set( pos[0], pos[1], pos[2] ); | ||
light.position.fromArray( pos ); | ||
@@ -432,7 +442,7 @@ } else if ( objJSON.type === "AmbientLight" ) { | ||
camera.name = objID; | ||
camera.position.set( pos[0], pos[1], pos[2] ); | ||
camera.position.fromArray( pos ); | ||
if ( quat !== undefined ) { | ||
camera.quaternion.set( quat[0], quat[1], quat[2], quat[3] ); | ||
camera.quaternion.fromArray( quat ); | ||
camera.useQuaternion = true; | ||
@@ -442,3 +452,3 @@ | ||
camera.rotation.set( rot[0], rot[1], rot[2] ); | ||
camera.rotation.fromArray( rot ); | ||
@@ -463,7 +473,7 @@ } | ||
object.name = objID; | ||
object.position.set( pos[0], pos[1], pos[2] ); | ||
object.position.fromArray( pos ); | ||
if ( quat ) { | ||
object.quaternion.set( quat[0], quat[1], quat[2], quat[3] ); | ||
object.quaternion.fromArray( quat ); | ||
object.useQuaternion = true; | ||
@@ -473,7 +483,7 @@ | ||
object.rotation.set( rot[0], rot[1], rot[2] ); | ||
object.rotation.fromArray( rot ); | ||
} | ||
object.scale.set( scl[0], scl[1], scl[2] ); | ||
object.scale.fromArray( scl ); | ||
object.visible = ( objJSON.visible !== undefined ) ? objJSON.visible : false; | ||
@@ -490,3 +500,3 @@ | ||
if ( objJSON.userData !== undefined ) { | ||
if ( objJSON.userData !== undefined ) { | ||
@@ -520,9 +530,9 @@ for ( var key in objJSON.userData ) { | ||
if ( objJSON.children !== undefined ) { | ||
} | ||
handle_children( object, objJSON.children ); | ||
} | ||
} | ||
if ( object !== undefined && objJSON.children !== undefined ) { | ||
} | ||
handle_children( object, objJSON.children ); | ||
@@ -550,7 +560,7 @@ } | ||
node.position.set( p[0], p[1], p[2] ); | ||
node.position.fromArray( p ); | ||
if ( q ) { | ||
node.quaternion.set( q[0], q[1], q[2], q[3] ); | ||
node.quaternion.fromArray( q ); | ||
node.useQuaternion = true; | ||
@@ -560,7 +570,7 @@ | ||
node.rotation.set( r[0], r[1], r[2] ); | ||
node.rotation.fromArray( r ); | ||
} | ||
node.scale.set( s[0], s[1], s[2] ); | ||
node.scale.fromArray( s ); | ||
@@ -572,3 +582,3 @@ // override children materials | ||
node.traverse( function ( child ) { | ||
node.traverse( function ( child ) { | ||
@@ -586,3 +596,3 @@ child.material = material; | ||
node.traverse( function ( child ) { | ||
node.traverse( function ( child ) { | ||
@@ -749,2 +759,18 @@ child.visible = visible; | ||
function traverse_json_hierarchy( objJSON, callback ) { | ||
callback( objJSON ); | ||
if ( objJSON.children !== undefined ) { | ||
for ( var objChildID in objJSON.children ) { | ||
traverse_json_hierarchy( objJSON.children[ objChildID ], callback ); | ||
} | ||
} | ||
}; | ||
// first go synchronous elements | ||
@@ -801,15 +827,15 @@ | ||
var objID, objJSON; | ||
for ( var objID in data.objects ) { | ||
for ( objID in data.objects ) { | ||
traverse_json_hierarchy( data.objects[ objID ], function ( objJSON ) { | ||
objJSON = data.objects[ objID ]; | ||
if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlerMap ) ) { | ||
if ( objJSON.type && ( objJSON.type in this.hierarchyHandlerMap ) ) { | ||
counter_models += 1; | ||
counter_models += 1; | ||
scope.onLoadStart(); | ||
scope.onLoadStart(); | ||
} | ||
} | ||
}); | ||
@@ -934,3 +960,3 @@ } | ||
if ( textureJSON.mapping !== undefined && THREE[ textureJSON.mapping ] !== undefined ) { | ||
if ( textureJSON.mapping !== undefined && THREE[ textureJSON.mapping ] !== undefined ) { | ||
@@ -1008,4 +1034,4 @@ textureJSON.mapping = new THREE[ textureJSON.mapping ](); | ||
var wrapMap = { | ||
"repeat" : THREE.RepeatWrapping, | ||
"mirror" : THREE.MirroredRepeatWrapping | ||
"repeat": THREE.RepeatWrapping, | ||
"mirror": THREE.MirroredRepeatWrapping | ||
} | ||
@@ -1075,3 +1101,3 @@ | ||
} else if ( matJSON.parameters[ parID ] ) { | ||
} else if ( matJSON.parameters[ parID ] ) { | ||
@@ -1078,0 +1104,0 @@ matJSON.parameters[ parID ] = THREE.VertexColors; |
@@ -37,2 +37,4 @@ /** | ||
_camera, | ||
_v1, _v2, _v3, _v4, | ||
@@ -268,2 +270,3 @@ _v5 = new THREE.RenderableVertex(), | ||
_lights = _renderData.lights; | ||
_camera = camera; | ||
@@ -405,32 +408,32 @@ /* DEBUG | ||
// | ||
}; | ||
function calculateLights() { | ||
// | ||
_ambientLight.setRGB( 0, 0, 0 ); | ||
_directionalLights.setRGB( 0, 0, 0 ); | ||
_pointLights.setRGB( 0, 0, 0 ); | ||
function calculateLights() { | ||
for ( var l = 0, ll = _lights.length; l < ll; l ++ ) { | ||
_ambientLight.setRGB( 0, 0, 0 ); | ||
_directionalLights.setRGB( 0, 0, 0 ); | ||
_pointLights.setRGB( 0, 0, 0 ); | ||
var light = _lights[ l ]; | ||
var lightColor = light.color; | ||
for ( var l = 0, ll = _lights.length; l < ll; l ++ ) { | ||
if ( light instanceof THREE.AmbientLight ) { | ||
var light = _lights[ l ]; | ||
var lightColor = light.color; | ||
_ambientLight.add( lightColor ); | ||
if ( light instanceof THREE.AmbientLight ) { | ||
} else if ( light instanceof THREE.DirectionalLight ) { | ||
_ambientLight.add( lightColor ); | ||
// for particles | ||
} else if ( light instanceof THREE.DirectionalLight ) { | ||
_directionalLights.add( lightColor ); | ||
// for particles | ||
} else if ( light instanceof THREE.PointLight ) { | ||
_directionalLights.add( lightColor ); | ||
// for particles | ||
} else if ( light instanceof THREE.PointLight ) { | ||
_pointLights.add( lightColor ); | ||
// for particles | ||
} | ||
_pointLights.add( lightColor ); | ||
@@ -441,39 +444,39 @@ } | ||
function calculateLight( position, normal, color ) { | ||
} | ||
for ( var l = 0, ll = _lights.length; l < ll; l ++ ) { | ||
function calculateLight( position, normal, color ) { | ||
var light = _lights[ l ]; | ||
for ( var l = 0, ll = _lights.length; l < ll; l ++ ) { | ||
_lightColor.copy( light.color ); | ||
var light = _lights[ l ]; | ||
if ( light instanceof THREE.DirectionalLight ) { | ||
_lightColor.copy( light.color ); | ||
var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ).normalize(); | ||
if ( light instanceof THREE.DirectionalLight ) { | ||
var amount = normal.dot( lightPosition ); | ||
var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ).normalize(); | ||
if ( amount <= 0 ) continue; | ||
var amount = normal.dot( lightPosition ); | ||
amount *= light.intensity; | ||
if ( amount <= 0 ) continue; | ||
color.add( _lightColor.multiplyScalar( amount ) ); | ||
amount *= light.intensity; | ||
} else if ( light instanceof THREE.PointLight ) { | ||
color.add( _lightColor.multiplyScalar( amount ) ); | ||
var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ); | ||
} else if ( light instanceof THREE.PointLight ) { | ||
var amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() ); | ||
var lightPosition = _vector3.getPositionFromMatrix( light.matrixWorld ); | ||
if ( amount <= 0 ) continue; | ||
var amount = normal.dot( _vector3.subVectors( lightPosition, position ).normalize() ); | ||
amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 ); | ||
if ( amount <= 0 ) continue; | ||
if ( amount == 0 ) continue; | ||
amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 ); | ||
amount *= light.intensity; | ||
if ( amount == 0 ) continue; | ||
color.add( _lightColor.multiplyScalar( amount ) ); | ||
amount *= light.intensity; | ||
} | ||
color.add( _lightColor.multiplyScalar( amount ) ); | ||
@@ -484,91 +487,57 @@ } | ||
function renderParticle( v1, element, material ) { | ||
} | ||
setOpacity( material.opacity ); | ||
setBlending( material.blending ); | ||
function renderParticle( v1, element, material ) { | ||
var width, height, scaleX, scaleY, | ||
bitmap, bitmapWidth, bitmapHeight; | ||
setOpacity( material.opacity ); | ||
setBlending( material.blending ); | ||
if ( material instanceof THREE.ParticleBasicMaterial ) { | ||
var width, height, scaleX, scaleY, | ||
bitmap, bitmapWidth, bitmapHeight; | ||
if ( material.map === null ) { | ||
if ( material instanceof THREE.ParticleBasicMaterial ) { | ||
scaleX = element.object.scale.x; | ||
scaleY = element.object.scale.y; | ||
if ( material.map === null ) { | ||
// TODO: Be able to disable this | ||
scaleX = element.object.scale.x; | ||
scaleY = element.object.scale.y; | ||
scaleX *= element.scale.x * _canvasWidthHalf; | ||
scaleY *= element.scale.y * _canvasHeightHalf; | ||
// TODO: Be able to disable this | ||
_elemBox.min.set( v1.x - scaleX, v1.y - scaleY ); | ||
_elemBox.max.set( v1.x + scaleX, v1.y + scaleY ); | ||
scaleX *= element.scale.x * _canvasWidthHalf; | ||
scaleY *= element.scale.y * _canvasHeightHalf; | ||
if ( _clipBox.isIntersectionBox( _elemBox ) === false ) { | ||
_elemBox.min.set( v1.x - scaleX, v1.y - scaleY ); | ||
_elemBox.max.set( v1.x + scaleX, v1.y + scaleY ); | ||
_elemBox.makeEmpty(); | ||
return; | ||
if ( _clipBox.isIntersectionBox( _elemBox ) === false ) { | ||
} | ||
_elemBox.makeEmpty(); | ||
return; | ||
setFillStyle( material.color.getStyle() ); | ||
} | ||
_context.save(); | ||
_context.translate( v1.x, v1.y ); | ||
_context.rotate( - element.rotation ); | ||
_context.scale( scaleX, scaleY ); | ||
_context.fillRect( -1, -1, 2, 2 ); | ||
_context.restore(); | ||
setFillStyle( material.color.getStyle() ); | ||
} else { | ||
_context.save(); | ||
_context.translate( v1.x, v1.y ); | ||
_context.rotate( - element.rotation ); | ||
_context.scale( scaleX, scaleY ); | ||
_context.fillRect( -1, -1, 2, 2 ); | ||
_context.restore(); | ||
bitmap = material.map.image; | ||
bitmapWidth = bitmap.width >> 1; | ||
bitmapHeight = bitmap.height >> 1; | ||
} else { | ||
scaleX = element.scale.x * _canvasWidthHalf; | ||
scaleY = element.scale.y * _canvasHeightHalf; | ||
bitmap = material.map.image; | ||
bitmapWidth = bitmap.width >> 1; | ||
bitmapHeight = bitmap.height >> 1; | ||
width = scaleX * bitmapWidth; | ||
height = scaleY * bitmapHeight; | ||
scaleX = element.scale.x * _canvasWidthHalf; | ||
scaleY = element.scale.y * _canvasHeightHalf; | ||
// TODO: Rotations break this... | ||
width = scaleX * bitmapWidth; | ||
height = scaleY * bitmapHeight; | ||
_elemBox.min.set( v1.x - width, v1.y - height ); | ||
_elemBox.max.set( v1.x + width, v1.y + height ); | ||
// TODO: Rotations break this... | ||
if ( _clipBox.isIntersectionBox( _elemBox ) === false ) { | ||
_elemBox.makeEmpty(); | ||
return; | ||
} | ||
_context.save(); | ||
_context.translate( v1.x, v1.y ); | ||
_context.rotate( - element.rotation ); | ||
_context.scale( scaleX, - scaleY ); | ||
_context.translate( - bitmapWidth, - bitmapHeight ); | ||
_context.drawImage( bitmap, 0, 0 ); | ||
_context.restore(); | ||
} | ||
/* DEBUG | ||
setStrokeStyle( 'rgb(255,255,0)' ); | ||
_context.beginPath(); | ||
_context.moveTo( v1.x - 10, v1.y ); | ||
_context.lineTo( v1.x + 10, v1.y ); | ||
_context.moveTo( v1.x, v1.y - 10 ); | ||
_context.lineTo( v1.x, v1.y + 10 ); | ||
_context.stroke(); | ||
*/ | ||
} else if ( material instanceof THREE.ParticleCanvasMaterial ) { | ||
width = element.scale.x * _canvasWidthHalf; | ||
height = element.scale.y * _canvasHeightHalf; | ||
_elemBox.min.set( v1.x - width, v1.y - height ); | ||
@@ -584,12 +553,9 @@ _elemBox.max.set( v1.x + width, v1.y + height ); | ||
setStrokeStyle( material.color.getStyle() ); | ||
setFillStyle( material.color.getStyle() ); | ||
_context.save(); | ||
_context.translate( v1.x, v1.y ); | ||
_context.rotate( - element.rotation ); | ||
_context.scale( width, height ); | ||
_context.scale( scaleX, - scaleY ); | ||
material.program( _context ); | ||
_context.translate( - bitmapWidth, - bitmapHeight ); | ||
_context.drawImage( bitmap, 0, 0 ); | ||
_context.restore(); | ||
@@ -599,34 +565,75 @@ | ||
/* DEBUG | ||
setStrokeStyle( 'rgb(255,255,0)' ); | ||
_context.beginPath(); | ||
_context.moveTo( v1.x - 10, v1.y ); | ||
_context.lineTo( v1.x + 10, v1.y ); | ||
_context.moveTo( v1.x, v1.y - 10 ); | ||
_context.lineTo( v1.x, v1.y + 10 ); | ||
_context.stroke(); | ||
*/ | ||
} else if ( material instanceof THREE.ParticleCanvasMaterial ) { | ||
width = element.scale.x * _canvasWidthHalf; | ||
height = element.scale.y * _canvasHeightHalf; | ||
_elemBox.min.set( v1.x - width, v1.y - height ); | ||
_elemBox.max.set( v1.x + width, v1.y + height ); | ||
if ( _clipBox.isIntersectionBox( _elemBox ) === false ) { | ||
_elemBox.makeEmpty(); | ||
return; | ||
} | ||
setStrokeStyle( material.color.getStyle() ); | ||
setFillStyle( material.color.getStyle() ); | ||
_context.save(); | ||
_context.translate( v1.x, v1.y ); | ||
_context.rotate( - element.rotation ); | ||
_context.scale( width, height ); | ||
material.program( _context ); | ||
_context.restore(); | ||
} | ||
function renderLine( v1, v2, element, material ) { | ||
} | ||
setOpacity( material.opacity ); | ||
setBlending( material.blending ); | ||
function renderLine( v1, v2, element, material ) { | ||
_context.beginPath(); | ||
_context.moveTo( v1.positionScreen.x, v1.positionScreen.y ); | ||
_context.lineTo( v2.positionScreen.x, v2.positionScreen.y ); | ||
setOpacity( material.opacity ); | ||
setBlending( material.blending ); | ||
if ( material instanceof THREE.LineBasicMaterial ) { | ||
_context.beginPath(); | ||
_context.moveTo( v1.positionScreen.x, v1.positionScreen.y ); | ||
_context.lineTo( v2.positionScreen.x, v2.positionScreen.y ); | ||
setLineWidth( material.linewidth ); | ||
setLineCap( material.linecap ); | ||
setLineJoin( material.linejoin ); | ||
if ( material instanceof THREE.LineBasicMaterial ) { | ||
if ( material.vertexColors !== THREE.VertexColors ) { | ||
setLineWidth( material.linewidth ); | ||
setLineCap( material.linecap ); | ||
setLineJoin( material.linejoin ); | ||
setStrokeStyle( material.color.getStyle() ); | ||
if ( material.vertexColors !== THREE.VertexColors ) { | ||
} else { | ||
setStrokeStyle( material.color.getStyle() ); | ||
var colorStyle1 = element.vertexColors[0].getStyle(); | ||
var colorStyle2 = element.vertexColors[1].getStyle(); | ||
} else { | ||
if ( colorStyle1 === colorStyle2 ) { | ||
var colorStyle1 = element.vertexColors[0].getStyle(); | ||
var colorStyle2 = element.vertexColors[1].getStyle(); | ||
setStrokeStyle( colorStyle1 ); | ||
if ( colorStyle1 === colorStyle2 ) { | ||
} else { | ||
setStrokeStyle( colorStyle1 ); | ||
} else { | ||
try { | ||
var grad = _context.createLinearGradient( | ||
@@ -638,190 +645,194 @@ v1.positionScreen.x, | ||
); | ||
grad.addColorStop( 0, colorStyle1 ); | ||
grad.addColorStop( 1, colorStyle2 ); | ||
setStrokeStyle( grad ); | ||
} catch ( exception ) { | ||
grad = colorStyle1; | ||
} | ||
setStrokeStyle( grad ); | ||
} | ||
_context.stroke(); | ||
_elemBox.expandByScalar( material.linewidth * 2 ); | ||
} | ||
} else if ( material instanceof THREE.LineDashedMaterial ) { | ||
_context.stroke(); | ||
_elemBox.expandByScalar( material.linewidth * 2 ); | ||
setLineWidth( material.linewidth ); | ||
setLineCap( material.linecap ); | ||
setLineJoin( material.linejoin ); | ||
setStrokeStyle( material.color.getStyle() ); | ||
setDashAndGap( material.dashSize, material.gapSize ); | ||
} else if ( material instanceof THREE.LineDashedMaterial ) { | ||
_context.stroke(); | ||
setLineWidth( material.linewidth ); | ||
setLineCap( material.linecap ); | ||
setLineJoin( material.linejoin ); | ||
setStrokeStyle( material.color.getStyle() ); | ||
setDashAndGap( material.dashSize, material.gapSize ); | ||
_elemBox.expandByScalar( material.linewidth * 2 ); | ||
_context.stroke(); | ||
setDashAndGap( null, null ); | ||
_elemBox.expandByScalar( material.linewidth * 2 ); | ||
} | ||
setDashAndGap( null, null ); | ||
} | ||
function renderFace3( v1, v2, v3, uv1, uv2, uv3, element, material ) { | ||
} | ||
_this.info.render.vertices += 3; | ||
_this.info.render.faces ++; | ||
function renderFace3( v1, v2, v3, uv1, uv2, uv3, element, material ) { | ||
setOpacity( material.opacity ); | ||
setBlending( material.blending ); | ||
_this.info.render.vertices += 3; | ||
_this.info.render.faces ++; | ||
_v1x = v1.positionScreen.x; _v1y = v1.positionScreen.y; | ||
_v2x = v2.positionScreen.x; _v2y = v2.positionScreen.y; | ||
_v3x = v3.positionScreen.x; _v3y = v3.positionScreen.y; | ||
setOpacity( material.opacity ); | ||
setBlending( material.blending ); | ||
drawTriangle( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y ); | ||
_v1x = v1.positionScreen.x; _v1y = v1.positionScreen.y; | ||
_v2x = v2.positionScreen.x; _v2y = v2.positionScreen.y; | ||
_v3x = v3.positionScreen.x; _v3y = v3.positionScreen.y; | ||
if ( ( material instanceof THREE.MeshLambertMaterial || material instanceof THREE.MeshPhongMaterial ) && material.map === null ) { | ||
drawTriangle( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y ); | ||
_diffuseColor.copy( material.color ); | ||
_emissiveColor.copy( material.emissive ); | ||
if ( ( material instanceof THREE.MeshLambertMaterial || material instanceof THREE.MeshPhongMaterial ) && material.map === null ) { | ||
if ( material.vertexColors === THREE.FaceColors ) { | ||
_diffuseColor.copy( material.color ); | ||
_emissiveColor.copy( material.emissive ); | ||
_diffuseColor.multiply( element.color ); | ||
if ( material.vertexColors === THREE.FaceColors ) { | ||
} | ||
_diffuseColor.multiply( element.color ); | ||
if ( material.wireframe === false && material.shading == THREE.SmoothShading && element.vertexNormalsLength == 3 ) { | ||
} | ||
_color1.copy( _ambientLight ); | ||
_color2.copy( _ambientLight ); | ||
_color3.copy( _ambientLight ); | ||
if ( material.wireframe === false && material.shading == THREE.SmoothShading && element.vertexNormalsLength == 3 ) { | ||
calculateLight( element.v1.positionWorld, element.vertexNormalsModel[ 0 ], _color1 ); | ||
calculateLight( element.v2.positionWorld, element.vertexNormalsModel[ 1 ], _color2 ); | ||
calculateLight( element.v3.positionWorld, element.vertexNormalsModel[ 2 ], _color3 ); | ||
_color1.copy( _ambientLight ); | ||
_color2.copy( _ambientLight ); | ||
_color3.copy( _ambientLight ); | ||
_color1.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color2.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color3.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color4.addColors( _color2, _color3 ).multiplyScalar( 0.5 ); | ||
calculateLight( element.v1.positionWorld, element.vertexNormalsModel[ 0 ], _color1 ); | ||
calculateLight( element.v2.positionWorld, element.vertexNormalsModel[ 1 ], _color2 ); | ||
calculateLight( element.v3.positionWorld, element.vertexNormalsModel[ 2 ], _color3 ); | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
_color1.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color2.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color3.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color4.addColors( _color2, _color3 ).multiplyScalar( 0.5 ); | ||
clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image ); | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
} else { | ||
clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image ); | ||
_color.copy( _ambientLight ); | ||
} else { | ||
calculateLight( element.centroidModel, element.normalModel, _color ); | ||
_color.copy( _ambientLight ); | ||
_color.multiply( _diffuseColor ).add( _emissiveColor ); | ||
calculateLight( element.centroidModel, element.normalModel, _color ); | ||
material.wireframe === true | ||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) | ||
: fillPath( _color ); | ||
_color.multiply( _diffuseColor ).add( _emissiveColor ); | ||
} | ||
material.wireframe === true | ||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) | ||
: fillPath( _color ); | ||
} else if ( material instanceof THREE.MeshBasicMaterial || material instanceof THREE.MeshLambertMaterial || material instanceof THREE.MeshPhongMaterial ) { | ||
} | ||
if ( material.map !== null ) { | ||
} else if ( material instanceof THREE.MeshBasicMaterial || material instanceof THREE.MeshLambertMaterial || material instanceof THREE.MeshPhongMaterial ) { | ||
if ( material.map.mapping instanceof THREE.UVMapping ) { | ||
if ( material.map !== null ) { | ||
_uvs = element.uvs[ 0 ]; | ||
patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].x, _uvs[ uv1 ].y, _uvs[ uv2 ].x, _uvs[ uv2 ].y, _uvs[ uv3 ].x, _uvs[ uv3 ].y, material.map ); | ||
if ( material.map.mapping instanceof THREE.UVMapping ) { | ||
} | ||
_uvs = element.uvs[ 0 ]; | ||
patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].x, _uvs[ uv1 ].y, _uvs[ uv2 ].x, _uvs[ uv2 ].y, _uvs[ uv3 ].x, _uvs[ uv3 ].y, material.map ); | ||
} | ||
} else if ( material.envMap !== null ) { | ||
if ( material.envMap.mapping instanceof THREE.SphericalReflectionMapping ) { | ||
} else if ( material.envMap !== null ) { | ||
_vector3.copy( element.vertexNormalsModelView[ uv1 ] ); | ||
_uv1x = 0.5 * _vector3.x + 0.5; | ||
_uv1y = 0.5 * _vector3.y + 0.5; | ||
if ( material.envMap.mapping instanceof THREE.SphericalReflectionMapping ) { | ||
_vector3.copy( element.vertexNormalsModelView[ uv2 ] ); | ||
_uv2x = 0.5 * _vector3.x + 0.5; | ||
_uv2y = 0.5 * _vector3.y + 0.5; | ||
_vector3.copy( element.vertexNormalsModelView[ uv1 ] ); | ||
_uv1x = 0.5 * _vector3.x + 0.5; | ||
_uv1y = 0.5 * _vector3.y + 0.5; | ||
_vector3.copy( element.vertexNormalsModelView[ uv3 ] ); | ||
_uv3x = 0.5 * _vector3.x + 0.5; | ||
_uv3y = 0.5 * _vector3.y + 0.5; | ||
_vector3.copy( element.vertexNormalsModelView[ uv2 ] ); | ||
_uv2x = 0.5 * _vector3.x + 0.5; | ||
_uv2y = 0.5 * _vector3.y + 0.5; | ||
patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y, material.envMap ); | ||
_vector3.copy( element.vertexNormalsModelView[ uv3 ] ); | ||
_uv3x = 0.5 * _vector3.x + 0.5; | ||
_uv3y = 0.5 * _vector3.y + 0.5; | ||
}/* else if ( material.envMap.mapping == THREE.SphericalRefractionMapping ) { | ||
patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y, material.envMap ); | ||
}/* else if ( material.envMap.mapping == THREE.SphericalRefractionMapping ) { | ||
}*/ | ||
}*/ | ||
} else { | ||
_color.copy( material.color ); | ||
} else { | ||
if ( material.vertexColors === THREE.FaceColors ) { | ||
_color.copy( material.color ); | ||
_color.multiply( element.color ); | ||
if ( material.vertexColors === THREE.FaceColors ) { | ||
} | ||
_color.multiply( element.color ); | ||
material.wireframe === true | ||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) | ||
: fillPath( _color ); | ||
} | ||
} else if ( material instanceof THREE.MeshDepthMaterial ) { | ||
material.wireframe === true | ||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) | ||
: fillPath( _color ); | ||
_near = camera.near; | ||
_far = camera.far; | ||
} | ||
_color1.r = _color1.g = _color1.b = 1 - smoothstep( v1.positionScreen.z * v1.positionScreen.w, _near, _far ); | ||
_color2.r = _color2.g = _color2.b = 1 - smoothstep( v2.positionScreen.z * v2.positionScreen.w, _near, _far ); | ||
_color3.r = _color3.g = _color3.b = 1 - smoothstep( v3.positionScreen.z * v3.positionScreen.w, _near, _far ); | ||
_color4.addColors( _color2, _color3 ).multiplyScalar( 0.5 ); | ||
} else if ( material instanceof THREE.MeshDepthMaterial ) { | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
_near = _camera.near; | ||
_far = _camera.far; | ||
clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image ); | ||
_color1.r = _color1.g = _color1.b = 1 - smoothstep( v1.positionScreen.z * v1.positionScreen.w, _near, _far ); | ||
_color2.r = _color2.g = _color2.b = 1 - smoothstep( v2.positionScreen.z * v2.positionScreen.w, _near, _far ); | ||
_color3.r = _color3.g = _color3.b = 1 - smoothstep( v3.positionScreen.z * v3.positionScreen.w, _near, _far ); | ||
_color4.addColors( _color2, _color3 ).multiplyScalar( 0.5 ); | ||
} else if ( material instanceof THREE.MeshNormalMaterial ) { | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
var normal; | ||
clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image ); | ||
if ( material.shading == THREE.FlatShading ) { | ||
} else if ( material instanceof THREE.MeshNormalMaterial ) { | ||
normal = element.normalModelView; | ||
var normal; | ||
_color.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
if ( material.shading == THREE.FlatShading ) { | ||
material.wireframe === true | ||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) | ||
: fillPath( _color ); | ||
normal = element.normalModelView; | ||
} else if ( material.shading == THREE.SmoothShading ) { | ||
_color.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
normal = element.vertexNormalsModelView[ uv1 ]; | ||
_color1.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
material.wireframe === true | ||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) | ||
: fillPath( _color ); | ||
normal = element.vertexNormalsModelView[ uv2 ]; | ||
_color2.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
} else if ( material.shading == THREE.SmoothShading ) { | ||
normal = element.vertexNormalsModelView[ uv3 ]; | ||
_color3.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
normal = element.vertexNormalsModelView[ uv1 ]; | ||
_color1.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
_color4.addColors( _color2, _color3 ).multiplyScalar( 0.5 ); | ||
normal = element.vertexNormalsModelView[ uv2 ]; | ||
_color2.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
normal = element.vertexNormalsModelView[ uv3 ]; | ||
_color3.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image ); | ||
_color4.addColors( _color2, _color3 ).multiplyScalar( 0.5 ); | ||
} | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image ); | ||
} | ||
@@ -831,92 +842,76 @@ | ||
function renderFace4( v1, v2, v3, v4, v5, v6, element, material ) { | ||
} | ||
_this.info.render.vertices += 4; | ||
_this.info.render.faces ++; | ||
function renderFace4( v1, v2, v3, v4, v5, v6, element, material ) { | ||
setOpacity( material.opacity ); | ||
setBlending( material.blending ); | ||
_this.info.render.vertices += 4; | ||
_this.info.render.faces ++; | ||
if ( ( material.map !== undefined && material.map !== null ) || ( material.envMap !== undefined && material.envMap !== null ) ) { | ||
setOpacity( material.opacity ); | ||
setBlending( material.blending ); | ||
// Let renderFace3() handle this | ||
if ( ( material.map !== undefined && material.map !== null ) || ( material.envMap !== undefined && material.envMap !== null ) ) { | ||
renderFace3( v1, v2, v4, 0, 1, 3, element, material ); | ||
renderFace3( v5, v3, v6, 1, 2, 3, element, material ); | ||
// Let renderFace3() handle this | ||
return; | ||
renderFace3( v1, v2, v4, 0, 1, 3, element, material ); | ||
renderFace3( v5, v3, v6, 1, 2, 3, element, material ); | ||
} | ||
return; | ||
_v1x = v1.positionScreen.x; _v1y = v1.positionScreen.y; | ||
_v2x = v2.positionScreen.x; _v2y = v2.positionScreen.y; | ||
_v3x = v3.positionScreen.x; _v3y = v3.positionScreen.y; | ||
_v4x = v4.positionScreen.x; _v4y = v4.positionScreen.y; | ||
_v5x = v5.positionScreen.x; _v5y = v5.positionScreen.y; | ||
_v6x = v6.positionScreen.x; _v6y = v6.positionScreen.y; | ||
} | ||
if ( material instanceof THREE.MeshLambertMaterial || material instanceof THREE.MeshPhongMaterial ) { | ||
_v1x = v1.positionScreen.x; _v1y = v1.positionScreen.y; | ||
_v2x = v2.positionScreen.x; _v2y = v2.positionScreen.y; | ||
_v3x = v3.positionScreen.x; _v3y = v3.positionScreen.y; | ||
_v4x = v4.positionScreen.x; _v4y = v4.positionScreen.y; | ||
_v5x = v5.positionScreen.x; _v5y = v5.positionScreen.y; | ||
_v6x = v6.positionScreen.x; _v6y = v6.positionScreen.y; | ||
_diffuseColor.copy( material.color ); | ||
_emissiveColor.copy( material.emissive ); | ||
if ( material instanceof THREE.MeshLambertMaterial || material instanceof THREE.MeshPhongMaterial ) { | ||
if ( material.vertexColors === THREE.FaceColors ) { | ||
_diffuseColor.copy( material.color ); | ||
_emissiveColor.copy( material.emissive ); | ||
_diffuseColor.multiply( element.color ); | ||
if ( material.vertexColors === THREE.FaceColors ) { | ||
} | ||
_diffuseColor.multiply( element.color ); | ||
if ( material.wireframe === false && material.shading == THREE.SmoothShading && element.vertexNormalsLength == 4 ) { | ||
} | ||
_color1.copy( _ambientLight ); | ||
_color2.copy( _ambientLight ); | ||
_color3.copy( _ambientLight ); | ||
_color4.copy( _ambientLight ); | ||
if ( material.wireframe === false && material.shading == THREE.SmoothShading && element.vertexNormalsLength == 4 ) { | ||
calculateLight( element.v1.positionWorld, element.vertexNormalsModel[ 0 ], _color1 ); | ||
calculateLight( element.v2.positionWorld, element.vertexNormalsModel[ 1 ], _color2 ); | ||
calculateLight( element.v4.positionWorld, element.vertexNormalsModel[ 3 ], _color3 ); | ||
calculateLight( element.v3.positionWorld, element.vertexNormalsModel[ 2 ], _color4 ); | ||
_color1.copy( _ambientLight ); | ||
_color2.copy( _ambientLight ); | ||
_color3.copy( _ambientLight ); | ||
_color4.copy( _ambientLight ); | ||
_color1.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color2.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color3.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color4.multiply( _diffuseColor ).add( _emissiveColor ); | ||
calculateLight( element.v1.positionWorld, element.vertexNormalsModel[ 0 ], _color1 ); | ||
calculateLight( element.v2.positionWorld, element.vertexNormalsModel[ 1 ], _color2 ); | ||
calculateLight( element.v4.positionWorld, element.vertexNormalsModel[ 3 ], _color3 ); | ||
calculateLight( element.v3.positionWorld, element.vertexNormalsModel[ 2 ], _color4 ); | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
_color1.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color2.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color3.multiply( _diffuseColor ).add( _emissiveColor ); | ||
_color4.multiply( _diffuseColor ).add( _emissiveColor ); | ||
// TODO: UVs are incorrect, v4->v3? | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y ); | ||
clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image ); | ||
// TODO: UVs are incorrect, v4->v3? | ||
drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y ); | ||
clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image ); | ||
drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y ); | ||
clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image ); | ||
} else { | ||
drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y ); | ||
clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image ); | ||
_color.copy( _ambientLight ); | ||
} else { | ||
calculateLight( element.centroidModel, element.normalModel, _color ); | ||
_color.copy( _ambientLight ); | ||
_color.multiply( _diffuseColor ).add( _emissiveColor ); | ||
calculateLight( element.centroidModel, element.normalModel, _color ); | ||
drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y ); | ||
_color.multiply( _diffuseColor ).add( _emissiveColor ); | ||
material.wireframe === true | ||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) | ||
: fillPath( _color ); | ||
} | ||
} else if ( material instanceof THREE.MeshBasicMaterial ) { | ||
_color.copy( material.color ); | ||
if ( material.vertexColors === THREE.FaceColors ) { | ||
_color.multiply( element.color ); | ||
} | ||
drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y ); | ||
@@ -928,55 +923,51 @@ | ||
} else if ( material instanceof THREE.MeshNormalMaterial ) { | ||
} | ||
var normal; | ||
} else if ( material instanceof THREE.MeshBasicMaterial ) { | ||
if ( material.shading == THREE.FlatShading ) { | ||
_color.copy( material.color ); | ||
normal = element.normalModelView; | ||
_color.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
if ( material.vertexColors === THREE.FaceColors ) { | ||
drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y ); | ||
_color.multiply( element.color ); | ||
material.wireframe === true | ||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) | ||
: fillPath( _color ); | ||
} | ||
} else if ( material.shading == THREE.SmoothShading ) { | ||
drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y ); | ||
normal = element.vertexNormalsModelView[ 0 ]; | ||
_color1.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
material.wireframe === true | ||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) | ||
: fillPath( _color ); | ||
normal = element.vertexNormalsModelView[ 1 ]; | ||
_color2.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
} else if ( material instanceof THREE.MeshNormalMaterial ) { | ||
normal = element.vertexNormalsModelView[ 3 ]; | ||
_color3.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
var normal; | ||
normal = element.vertexNormalsModelView[ 2 ]; | ||
_color4.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
if ( material.shading == THREE.FlatShading ) { | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
normal = element.normalModelView; | ||
_color.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y ); | ||
clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image ); | ||
drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y ); | ||
drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y ); | ||
clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image ); | ||
material.wireframe === true | ||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) | ||
: fillPath( _color ); | ||
} | ||
} else if ( material.shading == THREE.SmoothShading ) { | ||
} else if ( material instanceof THREE.MeshDepthMaterial ) { | ||
normal = element.vertexNormalsModelView[ 0 ]; | ||
_color1.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
_near = camera.near; | ||
_far = camera.far; | ||
normal = element.vertexNormalsModelView[ 1 ]; | ||
_color2.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
_color1.r = _color1.g = _color1.b = 1 - smoothstep( v1.positionScreen.z * v1.positionScreen.w, _near, _far ); | ||
_color2.r = _color2.g = _color2.b = 1 - smoothstep( v2.positionScreen.z * v2.positionScreen.w, _near, _far ); | ||
_color3.r = _color3.g = _color3.b = 1 - smoothstep( v4.positionScreen.z * v4.positionScreen.w, _near, _far ); | ||
_color4.r = _color4.g = _color4.b = 1 - smoothstep( v3.positionScreen.z * v3.positionScreen.w, _near, _far ); | ||
normal = element.vertexNormalsModelView[ 3 ]; | ||
_color3.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
normal = element.vertexNormalsModelView[ 2 ]; | ||
_color4.setRGB( normal.x, normal.y, normal.z ).multiplyScalar( 0.5 ).addScalar( 0.5 ); | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
// TODO: UVs are incorrect, v4->v3? | ||
drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y ); | ||
@@ -990,225 +981,246 @@ clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image ); | ||
} | ||
} else if ( material instanceof THREE.MeshDepthMaterial ) { | ||
// | ||
_near = _camera.near; | ||
_far = _camera.far; | ||
function drawTriangle( x0, y0, x1, y1, x2, y2 ) { | ||
_color1.r = _color1.g = _color1.b = 1 - smoothstep( v1.positionScreen.z * v1.positionScreen.w, _near, _far ); | ||
_color2.r = _color2.g = _color2.b = 1 - smoothstep( v2.positionScreen.z * v2.positionScreen.w, _near, _far ); | ||
_color3.r = _color3.g = _color3.b = 1 - smoothstep( v4.positionScreen.z * v4.positionScreen.w, _near, _far ); | ||
_color4.r = _color4.g = _color4.b = 1 - smoothstep( v3.positionScreen.z * v3.positionScreen.w, _near, _far ); | ||
_context.beginPath(); | ||
_context.moveTo( x0, y0 ); | ||
_context.lineTo( x1, y1 ); | ||
_context.lineTo( x2, y2 ); | ||
_context.closePath(); | ||
_image = getGradientTexture( _color1, _color2, _color3, _color4 ); | ||
} | ||
// TODO: UVs are incorrect, v4->v3? | ||
function drawQuad( x0, y0, x1, y1, x2, y2, x3, y3 ) { | ||
drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y ); | ||
clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image ); | ||
_context.beginPath(); | ||
_context.moveTo( x0, y0 ); | ||
_context.lineTo( x1, y1 ); | ||
_context.lineTo( x2, y2 ); | ||
_context.lineTo( x3, y3 ); | ||
_context.closePath(); | ||
drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y ); | ||
clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image ); | ||
} | ||
function strokePath( color, linewidth, linecap, linejoin ) { | ||
} | ||
setLineWidth( linewidth ); | ||
setLineCap( linecap ); | ||
setLineJoin( linejoin ); | ||
setStrokeStyle( color.getStyle() ); | ||
// | ||
_context.stroke(); | ||
function drawTriangle( x0, y0, x1, y1, x2, y2 ) { | ||
_elemBox.expandByScalar( linewidth * 2 ); | ||
_context.beginPath(); | ||
_context.moveTo( x0, y0 ); | ||
_context.lineTo( x1, y1 ); | ||
_context.lineTo( x2, y2 ); | ||
_context.closePath(); | ||
} | ||
} | ||
function fillPath( color ) { | ||
function drawQuad( x0, y0, x1, y1, x2, y2, x3, y3 ) { | ||
setFillStyle( color.getStyle() ); | ||
_context.fill(); | ||
_context.beginPath(); | ||
_context.moveTo( x0, y0 ); | ||
_context.lineTo( x1, y1 ); | ||
_context.lineTo( x2, y2 ); | ||
_context.lineTo( x3, y3 ); | ||
_context.closePath(); | ||
} | ||
} | ||
function patternPath( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, texture ) { | ||
function strokePath( color, linewidth, linecap, linejoin ) { | ||
if ( texture instanceof THREE.DataTexture || texture.image === undefined || texture.image.width == 0 ) return; | ||
setLineWidth( linewidth ); | ||
setLineCap( linecap ); | ||
setLineJoin( linejoin ); | ||
setStrokeStyle( color.getStyle() ); | ||
if ( texture.needsUpdate === true ) { | ||
_context.stroke(); | ||
var repeatX = texture.wrapS == THREE.RepeatWrapping; | ||
var repeatY = texture.wrapT == THREE.RepeatWrapping; | ||
_elemBox.expandByScalar( linewidth * 2 ); | ||
_patterns[ texture.id ] = _context.createPattern( | ||
texture.image, repeatX === true && repeatY === true | ||
? 'repeat' | ||
: repeatX === true && repeatY === false | ||
? 'repeat-x' | ||
: repeatX === false && repeatY === true | ||
? 'repeat-y' | ||
: 'no-repeat' | ||
); | ||
} | ||
texture.needsUpdate = false; | ||
function fillPath( color ) { | ||
} | ||
setFillStyle( color.getStyle() ); | ||
_context.fill(); | ||
_patterns[ texture.id ] === undefined | ||
? setFillStyle( 'rgba(0,0,0,1)' ) | ||
: setFillStyle( _patterns[ texture.id ] ); | ||
} | ||
// http://extremelysatisfactorytotalitarianism.com/blog/?p=2120 | ||
function patternPath( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, texture ) { | ||
var a, b, c, d, e, f, det, idet, | ||
offsetX = texture.offset.x / texture.repeat.x, | ||
offsetY = texture.offset.y / texture.repeat.y, | ||
width = texture.image.width * texture.repeat.x, | ||
height = texture.image.height * texture.repeat.y; | ||
if ( texture instanceof THREE.DataTexture || texture.image === undefined || texture.image.width == 0 ) return; | ||
u0 = ( u0 + offsetX ) * width; | ||
v0 = ( 1.0 - v0 + offsetY ) * height; | ||
if ( texture.needsUpdate === true ) { | ||
u1 = ( u1 + offsetX ) * width; | ||
v1 = ( 1.0 - v1 + offsetY ) * height; | ||
var repeatX = texture.wrapS == THREE.RepeatWrapping; | ||
var repeatY = texture.wrapT == THREE.RepeatWrapping; | ||
u2 = ( u2 + offsetX ) * width; | ||
v2 = ( 1.0 - v2 + offsetY ) * height; | ||
_patterns[ texture.id ] = _context.createPattern( | ||
texture.image, repeatX === true && repeatY === true | ||
? 'repeat' | ||
: repeatX === true && repeatY === false | ||
? 'repeat-x' | ||
: repeatX === false && repeatY === true | ||
? 'repeat-y' | ||
: 'no-repeat' | ||
); | ||
x1 -= x0; y1 -= y0; | ||
x2 -= x0; y2 -= y0; | ||
texture.needsUpdate = false; | ||
u1 -= u0; v1 -= v0; | ||
u2 -= u0; v2 -= v0; | ||
} | ||
det = u1 * v2 - u2 * v1; | ||
_patterns[ texture.id ] === undefined | ||
? setFillStyle( 'rgba(0,0,0,1)' ) | ||
: setFillStyle( _patterns[ texture.id ] ); | ||
if ( det === 0 ) { | ||
// http://extremelysatisfactorytotalitarianism.com/blog/?p=2120 | ||
if ( _imagedatas[ texture.id ] === undefined ) { | ||
var a, b, c, d, e, f, det, idet, | ||
offsetX = texture.offset.x / texture.repeat.x, | ||
offsetY = texture.offset.y / texture.repeat.y, | ||
width = texture.image.width * texture.repeat.x, | ||
height = texture.image.height * texture.repeat.y; | ||
var canvas = document.createElement( 'canvas' ) | ||
canvas.width = texture.image.width; | ||
canvas.height = texture.image.height; | ||
u0 = ( u0 + offsetX ) * width; | ||
v0 = ( 1.0 - v0 + offsetY ) * height; | ||
var context = canvas.getContext( '2d' ); | ||
context.drawImage( texture.image, 0, 0 ); | ||
u1 = ( u1 + offsetX ) * width; | ||
v1 = ( 1.0 - v1 + offsetY ) * height; | ||
_imagedatas[ texture.id ] = context.getImageData( 0, 0, texture.image.width, texture.image.height ).data; | ||
u2 = ( u2 + offsetX ) * width; | ||
v2 = ( 1.0 - v2 + offsetY ) * height; | ||
} | ||
x1 -= x0; y1 -= y0; | ||
x2 -= x0; y2 -= y0; | ||
var data = _imagedatas[ texture.id ]; | ||
var index = ( Math.floor( u0 ) + Math.floor( v0 ) * texture.image.width ) * 4; | ||
u1 -= u0; v1 -= v0; | ||
u2 -= u0; v2 -= v0; | ||
_color.setRGB( data[ index ] / 255, data[ index + 1 ] / 255, data[ index + 2 ] / 255 ); | ||
fillPath( _color ); | ||
det = u1 * v2 - u2 * v1; | ||
return; | ||
if ( det === 0 ) { | ||
if ( _imagedatas[ texture.id ] === undefined ) { | ||
var canvas = document.createElement( 'canvas' ) | ||
canvas.width = texture.image.width; | ||
canvas.height = texture.image.height; | ||
var context = canvas.getContext( '2d' ); | ||
context.drawImage( texture.image, 0, 0 ); | ||
_imagedatas[ texture.id ] = context.getImageData( 0, 0, texture.image.width, texture.image.height ).data; | ||
} | ||
idet = 1 / det; | ||
var data = _imagedatas[ texture.id ]; | ||
var index = ( Math.floor( u0 ) + Math.floor( v0 ) * texture.image.width ) * 4; | ||
a = ( v2 * x1 - v1 * x2 ) * idet; | ||
b = ( v2 * y1 - v1 * y2 ) * idet; | ||
c = ( u1 * x2 - u2 * x1 ) * idet; | ||
d = ( u1 * y2 - u2 * y1 ) * idet; | ||
_color.setRGB( data[ index ] / 255, data[ index + 1 ] / 255, data[ index + 2 ] / 255 ); | ||
fillPath( _color ); | ||
e = x0 - a * u0 - c * v0; | ||
f = y0 - b * u0 - d * v0; | ||
return; | ||
_context.save(); | ||
_context.transform( a, b, c, d, e, f ); | ||
_context.fill(); | ||
_context.restore(); | ||
} | ||
function clipImage( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, image ) { | ||
idet = 1 / det; | ||
// http://extremelysatisfactorytotalitarianism.com/blog/?p=2120 | ||
a = ( v2 * x1 - v1 * x2 ) * idet; | ||
b = ( v2 * y1 - v1 * y2 ) * idet; | ||
c = ( u1 * x2 - u2 * x1 ) * idet; | ||
d = ( u1 * y2 - u2 * y1 ) * idet; | ||
var a, b, c, d, e, f, det, idet, | ||
width = image.width - 1, | ||
height = image.height - 1; | ||
e = x0 - a * u0 - c * v0; | ||
f = y0 - b * u0 - d * v0; | ||
u0 *= width; v0 *= height; | ||
u1 *= width; v1 *= height; | ||
u2 *= width; v2 *= height; | ||
_context.save(); | ||
_context.transform( a, b, c, d, e, f ); | ||
_context.fill(); | ||
_context.restore(); | ||
x1 -= x0; y1 -= y0; | ||
x2 -= x0; y2 -= y0; | ||
} | ||
u1 -= u0; v1 -= v0; | ||
u2 -= u0; v2 -= v0; | ||
function clipImage( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, image ) { | ||
det = u1 * v2 - u2 * v1; | ||
// http://extremelysatisfactorytotalitarianism.com/blog/?p=2120 | ||
idet = 1 / det; | ||
var a, b, c, d, e, f, det, idet, | ||
width = image.width - 1, | ||
height = image.height - 1; | ||
a = ( v2 * x1 - v1 * x2 ) * idet; | ||
b = ( v2 * y1 - v1 * y2 ) * idet; | ||
c = ( u1 * x2 - u2 * x1 ) * idet; | ||
d = ( u1 * y2 - u2 * y1 ) * idet; | ||
u0 *= width; v0 *= height; | ||
u1 *= width; v1 *= height; | ||
u2 *= width; v2 *= height; | ||
e = x0 - a * u0 - c * v0; | ||
f = y0 - b * u0 - d * v0; | ||
x1 -= x0; y1 -= y0; | ||
x2 -= x0; y2 -= y0; | ||
_context.save(); | ||
_context.transform( a, b, c, d, e, f ); | ||
_context.clip(); | ||
_context.drawImage( image, 0, 0 ); | ||
_context.restore(); | ||
u1 -= u0; v1 -= v0; | ||
u2 -= u0; v2 -= v0; | ||
} | ||
det = u1 * v2 - u2 * v1; | ||
function getGradientTexture( color1, color2, color3, color4 ) { | ||
idet = 1 / det; | ||
// http://mrdoob.com/blog/post/710 | ||
a = ( v2 * x1 - v1 * x2 ) * idet; | ||
b = ( v2 * y1 - v1 * y2 ) * idet; | ||
c = ( u1 * x2 - u2 * x1 ) * idet; | ||
d = ( u1 * y2 - u2 * y1 ) * idet; | ||
_pixelMapData[ 0 ] = ( color1.r * 255 ) | 0; | ||
_pixelMapData[ 1 ] = ( color1.g * 255 ) | 0; | ||
_pixelMapData[ 2 ] = ( color1.b * 255 ) | 0; | ||
e = x0 - a * u0 - c * v0; | ||
f = y0 - b * u0 - d * v0; | ||
_pixelMapData[ 4 ] = ( color2.r * 255 ) | 0; | ||
_pixelMapData[ 5 ] = ( color2.g * 255 ) | 0; | ||
_pixelMapData[ 6 ] = ( color2.b * 255 ) | 0; | ||
_context.save(); | ||
_context.transform( a, b, c, d, e, f ); | ||
_context.clip(); | ||
_context.drawImage( image, 0, 0 ); | ||
_context.restore(); | ||
_pixelMapData[ 8 ] = ( color3.r * 255 ) | 0; | ||
_pixelMapData[ 9 ] = ( color3.g * 255 ) | 0; | ||
_pixelMapData[ 10 ] = ( color3.b * 255 ) | 0; | ||
} | ||
_pixelMapData[ 12 ] = ( color4.r * 255 ) | 0; | ||
_pixelMapData[ 13 ] = ( color4.g * 255 ) | 0; | ||
_pixelMapData[ 14 ] = ( color4.b * 255 ) | 0; | ||
function getGradientTexture( color1, color2, color3, color4 ) { | ||
_pixelMapContext.putImageData( _pixelMapImage, 0, 0 ); | ||
_gradientMapContext.drawImage( _pixelMap, 0, 0 ); | ||
// http://mrdoob.com/blog/post/710 | ||
return _gradientMap; | ||
_pixelMapData[ 0 ] = ( color1.r * 255 ) | 0; | ||
_pixelMapData[ 1 ] = ( color1.g * 255 ) | 0; | ||
_pixelMapData[ 2 ] = ( color1.b * 255 ) | 0; | ||
} | ||
_pixelMapData[ 4 ] = ( color2.r * 255 ) | 0; | ||
_pixelMapData[ 5 ] = ( color2.g * 255 ) | 0; | ||
_pixelMapData[ 6 ] = ( color2.b * 255 ) | 0; | ||
// Hide anti-alias gaps | ||
_pixelMapData[ 8 ] = ( color3.r * 255 ) | 0; | ||
_pixelMapData[ 9 ] = ( color3.g * 255 ) | 0; | ||
_pixelMapData[ 10 ] = ( color3.b * 255 ) | 0; | ||
function expand( v1, v2 ) { | ||
_pixelMapData[ 12 ] = ( color4.r * 255 ) | 0; | ||
_pixelMapData[ 13 ] = ( color4.g * 255 ) | 0; | ||
_pixelMapData[ 14 ] = ( color4.b * 255 ) | 0; | ||
var x = v2.x - v1.x, y = v2.y - v1.y, | ||
det = x * x + y * y, idet; | ||
_pixelMapContext.putImageData( _pixelMapImage, 0, 0 ); | ||
_gradientMapContext.drawImage( _pixelMap, 0, 0 ); | ||
if ( det === 0 ) return; | ||
return _gradientMap; | ||
idet = 1 / Math.sqrt( det ); | ||
} | ||
x *= idet; y *= idet; | ||
// Hide anti-alias gaps | ||
v2.x += x; v2.y += y; | ||
v1.x -= x; v1.y -= y; | ||
function expand( v1, v2 ) { | ||
} | ||
}; | ||
var x = v2.x - v1.x, y = v2.y - v1.y, | ||
det = x * x + y * y, idet; | ||
if ( det === 0 ) return; | ||
idet = 1 / Math.sqrt( det ); | ||
x *= idet; y *= idet; | ||
v2.x += x; v2.y += y; | ||
v1.x -= x; v1.y -= y; | ||
} | ||
// Context cached methods. | ||
@@ -1215,0 +1227,0 @@ |
@@ -6,3 +6,3 @@ /** | ||
var THREE = THREE || { REVISION: '58' }; | ||
var THREE = THREE || { REVISION: '59dev' }; | ||
@@ -9,0 +9,0 @@ self.console = self.console || { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
278
73709
6810547