kopia lustrzana https://github.com/backface/turtlestitch
three.js update
rodzic
34f09731c5
commit
01cc431369
|
@ -9,7 +9,7 @@ THREE.SpriteCanvasMaterial = function ( parameters ) {
|
||||||
this.type = 'SpriteCanvasMaterial';
|
this.type = 'SpriteCanvasMaterial';
|
||||||
|
|
||||||
this.color = new THREE.Color( 0xffffff );
|
this.color = new THREE.Color( 0xffffff );
|
||||||
this.program = function ( context, color ) {};
|
this.program = function () {};
|
||||||
|
|
||||||
this.setValues( parameters );
|
this.setValues( parameters );
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ THREE.SpriteCanvasMaterial = function ( parameters ) {
|
||||||
|
|
||||||
THREE.SpriteCanvasMaterial.prototype = Object.create( THREE.Material.prototype );
|
THREE.SpriteCanvasMaterial.prototype = Object.create( THREE.Material.prototype );
|
||||||
THREE.SpriteCanvasMaterial.prototype.constructor = THREE.SpriteCanvasMaterial;
|
THREE.SpriteCanvasMaterial.prototype.constructor = THREE.SpriteCanvasMaterial;
|
||||||
|
THREE.SpriteCanvasMaterial.prototype.isSpriteCanvasMaterial = true;
|
||||||
|
|
||||||
THREE.SpriteCanvasMaterial.prototype.clone = function () {
|
THREE.SpriteCanvasMaterial.prototype.clone = function () {
|
||||||
|
|
||||||
|
@ -74,20 +75,11 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
_contextLineJoin = null,
|
_contextLineJoin = null,
|
||||||
_contextLineDash = [],
|
_contextLineDash = [],
|
||||||
|
|
||||||
_camera,
|
_v1, _v2, _v3,
|
||||||
|
|
||||||
_v1, _v2, _v3, _v4,
|
|
||||||
_v5 = new THREE.RenderableVertex(),
|
|
||||||
_v6 = new THREE.RenderableVertex(),
|
|
||||||
|
|
||||||
_v1x, _v1y, _v2x, _v2y, _v3x, _v3y,
|
_v1x, _v1y, _v2x, _v2y, _v3x, _v3y,
|
||||||
_v4x, _v4y, _v5x, _v5y, _v6x, _v6y,
|
|
||||||
|
|
||||||
_color = new THREE.Color(),
|
_color = new THREE.Color(),
|
||||||
_color1 = new THREE.Color(),
|
|
||||||
_color2 = new THREE.Color(),
|
|
||||||
_color3 = new THREE.Color(),
|
|
||||||
_color4 = new THREE.Color(),
|
|
||||||
|
|
||||||
_diffuseColor = new THREE.Color(),
|
_diffuseColor = new THREE.Color(),
|
||||||
_emissiveColor = new THREE.Color(),
|
_emissiveColor = new THREE.Color(),
|
||||||
|
@ -96,7 +88,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
|
|
||||||
_patterns = {},
|
_patterns = {},
|
||||||
|
|
||||||
_image, _uvs,
|
_uvs,
|
||||||
_uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y,
|
_uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y,
|
||||||
|
|
||||||
_clipBox = new THREE.Box2(),
|
_clipBox = new THREE.Box2(),
|
||||||
|
@ -312,7 +304,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
|
|
||||||
this.render = function ( scene, camera ) {
|
this.render = function ( scene, camera ) {
|
||||||
|
|
||||||
if ( camera instanceof THREE.Camera === false ) {
|
if ( camera.isCamera === undefined ) {
|
||||||
|
|
||||||
console.error( 'THREE.CanvasRenderer.render: camera is not an instance of THREE.Camera.' );
|
console.error( 'THREE.CanvasRenderer.render: camera is not an instance of THREE.Camera.' );
|
||||||
return;
|
return;
|
||||||
|
@ -341,7 +333,6 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
_renderData = _projector.projectScene( scene, camera, this.sortObjects, this.sortElements );
|
_renderData = _projector.projectScene( scene, camera, this.sortObjects, this.sortElements );
|
||||||
_elements = _renderData.elements;
|
_elements = _renderData.elements;
|
||||||
_lights = _renderData.lights;
|
_lights = _renderData.lights;
|
||||||
_camera = camera;
|
|
||||||
|
|
||||||
_normalViewMatrix.getNormalMatrix( camera.matrixWorldInverse );
|
_normalViewMatrix.getNormalMatrix( camera.matrixWorldInverse );
|
||||||
|
|
||||||
|
@ -454,17 +445,17 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
var light = _lights[ l ];
|
var light = _lights[ l ];
|
||||||
var lightColor = light.color;
|
var lightColor = light.color;
|
||||||
|
|
||||||
if ( light instanceof THREE.AmbientLight ) {
|
if ( light.isAmbientLight ) {
|
||||||
|
|
||||||
_ambientLight.add( lightColor );
|
_ambientLight.add( lightColor );
|
||||||
|
|
||||||
} else if ( light instanceof THREE.DirectionalLight ) {
|
} else if ( light.isDirectionalLight ) {
|
||||||
|
|
||||||
// for sprites
|
// for sprites
|
||||||
|
|
||||||
_directionalLights.add( lightColor );
|
_directionalLights.add( lightColor );
|
||||||
|
|
||||||
} else if ( light instanceof THREE.PointLight ) {
|
} else if ( light.isPointLight ) {
|
||||||
|
|
||||||
// for sprites
|
// for sprites
|
||||||
|
|
||||||
|
@ -484,7 +475,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
|
|
||||||
_lightColor.copy( light.color );
|
_lightColor.copy( light.color );
|
||||||
|
|
||||||
if ( light instanceof THREE.DirectionalLight ) {
|
if ( light.isDirectionalLight ) {
|
||||||
|
|
||||||
var lightPosition = _vector3.setFromMatrixPosition( light.matrixWorld ).normalize();
|
var lightPosition = _vector3.setFromMatrixPosition( light.matrixWorld ).normalize();
|
||||||
|
|
||||||
|
@ -496,7 +487,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
|
|
||||||
color.add( _lightColor.multiplyScalar( amount ) );
|
color.add( _lightColor.multiplyScalar( amount ) );
|
||||||
|
|
||||||
} else if ( light instanceof THREE.PointLight ) {
|
} else if ( light.isPointLight ) {
|
||||||
|
|
||||||
var lightPosition = _vector3.setFromMatrixPosition( light.matrixWorld );
|
var lightPosition = _vector3.setFromMatrixPosition( light.matrixWorld );
|
||||||
|
|
||||||
|
@ -526,11 +517,11 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
var scaleX = element.scale.x * _canvasWidthHalf;
|
var scaleX = element.scale.x * _canvasWidthHalf;
|
||||||
var scaleY = element.scale.y * _canvasHeightHalf;
|
var scaleY = element.scale.y * _canvasHeightHalf;
|
||||||
|
|
||||||
var dist = 0.5 * Math.sqrt( scaleX * scaleX + scaleY * scaleY ); // allow for rotated sprite
|
var dist = Math.sqrt( scaleX * scaleX + scaleY * scaleY ); // allow for rotated sprite
|
||||||
_elemBox.min.set( v1.x - dist, v1.y - dist );
|
_elemBox.min.set( v1.x - dist, v1.y - dist );
|
||||||
_elemBox.max.set( v1.x + dist, v1.y + dist );
|
_elemBox.max.set( v1.x + dist, v1.y + dist );
|
||||||
|
|
||||||
if ( material instanceof THREE.SpriteMaterial ) {
|
if ( material.isSpriteMaterial ) {
|
||||||
|
|
||||||
var texture = material.map;
|
var texture = material.map;
|
||||||
|
|
||||||
|
@ -586,7 +577,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ( material instanceof THREE.SpriteCanvasMaterial ) {
|
} else if ( material.isSpriteCanvasMaterial ) {
|
||||||
|
|
||||||
setStrokeStyle( material.color.getStyle() );
|
setStrokeStyle( material.color.getStyle() );
|
||||||
setFillStyle( material.color.getStyle() );
|
setFillStyle( material.color.getStyle() );
|
||||||
|
@ -600,6 +591,17 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
|
|
||||||
_context.restore();
|
_context.restore();
|
||||||
|
|
||||||
|
} else if ( material.isPointsMaterial ) {
|
||||||
|
|
||||||
|
setFillStyle( material.color.getStyle() );
|
||||||
|
|
||||||
|
_context.save();
|
||||||
|
_context.translate( v1.x, v1.y );
|
||||||
|
if ( material.rotation !== 0 ) _context.rotate( material.rotation );
|
||||||
|
_context.scale( scaleX * material.size, - scaleY * material.size );
|
||||||
|
_context.fillRect( - 0.5, - 0.5, 1, 1 );
|
||||||
|
_context.restore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DEBUG
|
/* DEBUG
|
||||||
|
@ -623,7 +625,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
_context.moveTo( v1.positionScreen.x, v1.positionScreen.y );
|
_context.moveTo( v1.positionScreen.x, v1.positionScreen.y );
|
||||||
_context.lineTo( v2.positionScreen.x, v2.positionScreen.y );
|
_context.lineTo( v2.positionScreen.x, v2.positionScreen.y );
|
||||||
|
|
||||||
if ( material instanceof THREE.LineBasicMaterial ) {
|
if ( material.isLineBasicMaterial ) {
|
||||||
|
|
||||||
setLineWidth( material.linewidth );
|
setLineWidth( material.linewidth );
|
||||||
setLineCap( material.linecap );
|
setLineCap( material.linecap );
|
||||||
|
@ -670,7 +672,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
_context.stroke();
|
_context.stroke();
|
||||||
_elemBox.expandByScalar( material.linewidth * 2 );
|
_elemBox.expandByScalar( material.linewidth * 2 );
|
||||||
|
|
||||||
} else if ( material instanceof THREE.LineDashedMaterial ) {
|
} else if ( material.isLineDashedMaterial ) {
|
||||||
|
|
||||||
setLineWidth( material.linewidth );
|
setLineWidth( material.linewidth );
|
||||||
setLineCap( material.linecap );
|
setLineCap( material.linecap );
|
||||||
|
@ -702,7 +704,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
|
|
||||||
drawTriangle( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y );
|
drawTriangle( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y );
|
||||||
|
|
||||||
if ( ( material instanceof THREE.MeshLambertMaterial || material instanceof THREE.MeshPhongMaterial ) && material.map === null ) {
|
if ( ( material.isMeshLambertMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial ) && material.map === null ) {
|
||||||
|
|
||||||
_diffuseColor.copy( material.color );
|
_diffuseColor.copy( material.color );
|
||||||
_emissiveColor.copy( material.emissive );
|
_emissiveColor.copy( material.emissive );
|
||||||
|
@ -725,9 +727,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin )
|
? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin )
|
||||||
: fillPath( _color );
|
: fillPath( _color );
|
||||||
|
|
||||||
} else if ( material instanceof THREE.MeshBasicMaterial ||
|
} else if ( material.isMeshBasicMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial ) {
|
||||||
material instanceof THREE.MeshLambertMaterial ||
|
|
||||||
material instanceof THREE.MeshPhongMaterial ) {
|
|
||||||
|
|
||||||
if ( material.map !== null ) {
|
if ( material.map !== null ) {
|
||||||
|
|
||||||
|
@ -776,7 +776,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ( material instanceof THREE.MeshNormalMaterial ) {
|
} else if ( material.isMeshNormalMaterial ) {
|
||||||
|
|
||||||
_normal.copy( element.normalModel ).applyMatrix3( _normalViewMatrix );
|
_normal.copy( element.normalModel ).applyMatrix3( _normalViewMatrix );
|
||||||
|
|
||||||
|
@ -985,6 +985,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
function clipImage( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, image ) {
|
function clipImage( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, image ) {
|
||||||
|
|
||||||
// http://extremelysatisfactorytotalitarianism.com/blog/?p=2120
|
// http://extremelysatisfactorytotalitarianism.com/blog/?p=2120
|
||||||
|
@ -1022,6 +1023,7 @@ THREE.CanvasRenderer = function ( parameters ) {
|
||||||
_context.restore();
|
_context.restore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Hide anti-alias gaps
|
// Hide anti-alias gaps
|
||||||
|
|
||||||
|
|
|
@ -720,8 +720,7 @@ THREE.OBJLoader.prototype = {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var multiMaterial = new THREE.MultiMaterial( createdMaterials );
|
mesh = ( ! isLine ? new THREE.Mesh( buffergeometry, createdMaterials ) : new THREE.LineSegments( buffergeometry, createdMaterials ) );
|
||||||
mesh = ( ! isLine ? new THREE.Mesh( buffergeometry, multiMaterial ) : new THREE.LineSegments( buffergeometry, multiMaterial ) );
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
Plik diff jest za duży
Load Diff
|
@ -112,7 +112,6 @@ THREE.Projector = function () {
|
||||||
_clipBox = new THREE.Box3( new THREE.Vector3( - 1, - 1, - 1 ), new THREE.Vector3( 1, 1, 1 ) ),
|
_clipBox = new THREE.Box3( new THREE.Vector3( - 1, - 1, - 1 ), new THREE.Vector3( 1, 1, 1 ) ),
|
||||||
_boundingBox = new THREE.Box3(),
|
_boundingBox = new THREE.Box3(),
|
||||||
_points3 = new Array( 3 ),
|
_points3 = new Array( 3 ),
|
||||||
_points4 = new Array( 4 ),
|
|
||||||
|
|
||||||
_viewMatrix = new THREE.Matrix4(),
|
_viewMatrix = new THREE.Matrix4(),
|
||||||
_viewProjectionMatrix = new THREE.Matrix4(),
|
_viewProjectionMatrix = new THREE.Matrix4(),
|
||||||
|
@ -143,7 +142,7 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.pickingRay = function ( vector, camera ) {
|
this.pickingRay = function () {
|
||||||
|
|
||||||
console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
|
console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
|
||||||
|
|
||||||
|
@ -154,6 +153,7 @@ THREE.Projector = function () {
|
||||||
var RenderList = function () {
|
var RenderList = function () {
|
||||||
|
|
||||||
var normals = [];
|
var normals = [];
|
||||||
|
var colors = [];
|
||||||
var uvs = [];
|
var uvs = [];
|
||||||
|
|
||||||
var object = null;
|
var object = null;
|
||||||
|
@ -169,6 +169,7 @@ THREE.Projector = function () {
|
||||||
normalMatrix.getNormalMatrix( object.matrixWorld );
|
normalMatrix.getNormalMatrix( object.matrixWorld );
|
||||||
|
|
||||||
normals.length = 0;
|
normals.length = 0;
|
||||||
|
colors.length = 0;
|
||||||
uvs.length = 0;
|
uvs.length = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -209,6 +210,12 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pushColor( r, g, b ) {
|
||||||
|
|
||||||
|
colors.push( r, g, b );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function pushUv( x, y ) {
|
function pushUv( x, y ) {
|
||||||
|
|
||||||
uvs.push( x, y );
|
uvs.push( x, y );
|
||||||
|
@ -241,20 +248,39 @@ THREE.Projector = function () {
|
||||||
var v1 = _vertexPool[ a ];
|
var v1 = _vertexPool[ a ];
|
||||||
var v2 = _vertexPool[ b ];
|
var v2 = _vertexPool[ b ];
|
||||||
|
|
||||||
_line = getNextLineInPool();
|
// Clip
|
||||||
|
|
||||||
|
v1.positionScreen.copy( v1.position ).applyMatrix4( _modelViewProjectionMatrix );
|
||||||
|
v2.positionScreen.copy( v2.position ).applyMatrix4( _modelViewProjectionMatrix );
|
||||||
|
|
||||||
|
if ( clipLine( v1.positionScreen, v2.positionScreen ) === true ) {
|
||||||
|
|
||||||
|
// Perform the perspective divide
|
||||||
|
v1.positionScreen.multiplyScalar( 1 / v1.positionScreen.w );
|
||||||
|
v2.positionScreen.multiplyScalar( 1 / v2.positionScreen.w );
|
||||||
|
|
||||||
|
_line = getNextLineInPool();
|
||||||
_line.id = object.id;
|
_line.id = object.id;
|
||||||
_line.v1.copy( v1 );
|
_line.v1.copy( v1 );
|
||||||
_line.v2.copy( v2 );
|
_line.v2.copy( v2 );
|
||||||
_line.z = ( v1.positionScreen.z + v2.positionScreen.z ) / 2;
|
_line.z = Math.max( v1.positionScreen.z, v2.positionScreen.z );
|
||||||
_line.renderOrder = object.renderOrder;
|
_line.renderOrder = object.renderOrder;
|
||||||
|
|
||||||
_line.material = object.material;
|
_line.material = object.material;
|
||||||
|
|
||||||
|
if ( object.material.vertexColors === THREE.VertexColors ) {
|
||||||
|
|
||||||
|
_line.vertexColors[ 0 ].fromArray( colors, a * 3 );
|
||||||
|
_line.vertexColors[ 1 ].fromArray( colors, b * 3 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
_renderData.elements.push( _line );
|
_renderData.elements.push( _line );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function pushTriangle( a, b, c ) {
|
function pushTriangle( a, b, c ) {
|
||||||
|
|
||||||
var v1 = _vertexPool[ a ];
|
var v1 = _vertexPool[ a ];
|
||||||
|
@ -307,15 +333,65 @@ THREE.Projector = function () {
|
||||||
checkBackfaceCulling: checkBackfaceCulling,
|
checkBackfaceCulling: checkBackfaceCulling,
|
||||||
pushVertex: pushVertex,
|
pushVertex: pushVertex,
|
||||||
pushNormal: pushNormal,
|
pushNormal: pushNormal,
|
||||||
|
pushColor: pushColor,
|
||||||
pushUv: pushUv,
|
pushUv: pushUv,
|
||||||
pushLine: pushLine,
|
pushLine: pushLine,
|
||||||
pushTriangle: pushTriangle
|
pushTriangle: pushTriangle
|
||||||
}
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var renderList = new RenderList();
|
var renderList = new RenderList();
|
||||||
|
|
||||||
|
function projectObject( object ) {
|
||||||
|
|
||||||
|
if ( object.visible === false ) return;
|
||||||
|
|
||||||
|
if ( object instanceof THREE.Light ) {
|
||||||
|
|
||||||
|
_renderData.lights.push( object );
|
||||||
|
|
||||||
|
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
|
||||||
|
|
||||||
|
if ( object.material.visible === false ) return;
|
||||||
|
if ( object.frustumCulled === true && _frustum.intersectsObject( object ) === false ) return;
|
||||||
|
|
||||||
|
addObject( object );
|
||||||
|
|
||||||
|
} else if ( object instanceof THREE.Sprite ) {
|
||||||
|
|
||||||
|
if ( object.material.visible === false ) return;
|
||||||
|
if ( object.frustumCulled === true && _frustum.intersectsSprite( object ) === false ) return;
|
||||||
|
|
||||||
|
addObject( object );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var children = object.children;
|
||||||
|
|
||||||
|
for ( var i = 0, l = children.length; i < l; i ++ ) {
|
||||||
|
|
||||||
|
projectObject( children[ i ] );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function addObject( object ) {
|
||||||
|
|
||||||
|
_object = getNextObjectInPool();
|
||||||
|
_object.id = object.id;
|
||||||
|
_object.object = object;
|
||||||
|
|
||||||
|
_vector3.setFromMatrixPosition( object.matrixWorld );
|
||||||
|
_vector3.applyMatrix4( _viewProjectionMatrix );
|
||||||
|
_object.z = _vector3.z;
|
||||||
|
_object.renderOrder = object.renderOrder;
|
||||||
|
|
||||||
|
_renderData.objects.push( _object );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
this.projectScene = function ( scene, camera, sortObjects, sortElements ) {
|
this.projectScene = function ( scene, camera, sortObjects, sortElements ) {
|
||||||
|
|
||||||
_faceCount = 0;
|
_faceCount = 0;
|
||||||
|
@ -339,44 +415,7 @@ THREE.Projector = function () {
|
||||||
_renderData.objects.length = 0;
|
_renderData.objects.length = 0;
|
||||||
_renderData.lights.length = 0;
|
_renderData.lights.length = 0;
|
||||||
|
|
||||||
function addObject( object ) {
|
projectObject( scene );
|
||||||
|
|
||||||
_object = getNextObjectInPool();
|
|
||||||
_object.id = object.id;
|
|
||||||
_object.object = object;
|
|
||||||
|
|
||||||
_vector3.setFromMatrixPosition( object.matrixWorld );
|
|
||||||
_vector3.applyMatrix4( _viewProjectionMatrix );
|
|
||||||
_object.z = _vector3.z;
|
|
||||||
_object.renderOrder = object.renderOrder;
|
|
||||||
|
|
||||||
_renderData.objects.push( _object );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.traverseVisible( function ( object ) {
|
|
||||||
|
|
||||||
if ( object instanceof THREE.Light ) {
|
|
||||||
|
|
||||||
_renderData.lights.push( object );
|
|
||||||
|
|
||||||
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line ) {
|
|
||||||
|
|
||||||
if ( object.material.visible === false ) return;
|
|
||||||
if ( object.frustumCulled === true && _frustum.intersectsObject( object ) === false ) return;
|
|
||||||
|
|
||||||
addObject( object );
|
|
||||||
|
|
||||||
} else if ( object instanceof THREE.Sprite ) {
|
|
||||||
|
|
||||||
if ( object.material.visible === false ) return;
|
|
||||||
if ( object.frustumCulled === true && _frustum.intersectsSprite( object ) === false ) return;
|
|
||||||
|
|
||||||
addObject( object );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} );
|
|
||||||
|
|
||||||
if ( sortObjects === true ) {
|
if ( sortObjects === true ) {
|
||||||
|
|
||||||
|
@ -386,9 +425,11 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
for ( var o = 0, ol = _renderData.objects.length; o < ol; o ++ ) {
|
var objects = _renderData.objects;
|
||||||
|
|
||||||
var object = _renderData.objects[ o ].object;
|
for ( var o = 0, ol = objects.length; o < ol; o ++ ) {
|
||||||
|
|
||||||
|
var object = objects[ o ].object;
|
||||||
var geometry = object.geometry;
|
var geometry = object.geometry;
|
||||||
|
|
||||||
renderList.setObject( object );
|
renderList.setObject( object );
|
||||||
|
@ -486,8 +527,7 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
var material = object.material;
|
var material = object.material;
|
||||||
|
|
||||||
var isFaceMaterial = material instanceof THREE.MultiMaterial;
|
var isMultiMaterial = Array.isArray( material );
|
||||||
var objectMaterials = isFaceMaterial === true ? object.material : null;
|
|
||||||
|
|
||||||
for ( var v = 0, vl = vertices.length; v < vl; v ++ ) {
|
for ( var v = 0, vl = vertices.length; v < vl; v ++ ) {
|
||||||
|
|
||||||
|
@ -525,8 +565,8 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
var face = faces[ f ];
|
var face = faces[ f ];
|
||||||
|
|
||||||
material = isFaceMaterial === true
|
material = isMultiMaterial === true
|
||||||
? objectMaterials.materials[ face.materialIndex ]
|
? object.material[ face.materialIndex ]
|
||||||
: object.material;
|
: object.material;
|
||||||
|
|
||||||
if ( material === undefined ) continue;
|
if ( material === undefined ) continue;
|
||||||
|
@ -610,6 +650,8 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
} else if ( object instanceof THREE.Line ) {
|
} else if ( object instanceof THREE.Line ) {
|
||||||
|
|
||||||
|
_modelViewProjectionMatrix.multiplyMatrices( _viewProjectionMatrix, _modelMatrix );
|
||||||
|
|
||||||
if ( geometry instanceof THREE.BufferGeometry ) {
|
if ( geometry instanceof THREE.BufferGeometry ) {
|
||||||
|
|
||||||
var attributes = geometry.attributes;
|
var attributes = geometry.attributes;
|
||||||
|
@ -624,6 +666,18 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( attributes.color !== undefined ) {
|
||||||
|
|
||||||
|
var colors = attributes.color.array;
|
||||||
|
|
||||||
|
for ( var i = 0, l = colors.length; i < l; i += 3 ) {
|
||||||
|
|
||||||
|
renderList.pushColor( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if ( geometry.index !== null ) {
|
if ( geometry.index !== null ) {
|
||||||
|
|
||||||
var indices = geometry.index.array;
|
var indices = geometry.index.array;
|
||||||
|
@ -650,8 +704,6 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
} else if ( geometry instanceof THREE.Geometry ) {
|
} else if ( geometry instanceof THREE.Geometry ) {
|
||||||
|
|
||||||
_modelViewProjectionMatrix.multiplyMatrices( _viewProjectionMatrix, _modelMatrix );
|
|
||||||
|
|
||||||
var vertices = object.geometry.vertices;
|
var vertices = object.geometry.vertices;
|
||||||
|
|
||||||
if ( vertices.length === 0 ) continue;
|
if ( vertices.length === 0 ) continue;
|
||||||
|
@ -705,11 +757,50 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if ( object instanceof THREE.Points ) {
|
||||||
|
|
||||||
|
_modelViewProjectionMatrix.multiplyMatrices( _viewProjectionMatrix, _modelMatrix );
|
||||||
|
|
||||||
|
if ( geometry instanceof THREE.Geometry ) {
|
||||||
|
|
||||||
|
var vertices = object.geometry.vertices;
|
||||||
|
|
||||||
|
for ( var v = 0, vl = vertices.length; v < vl; v ++ ) {
|
||||||
|
|
||||||
|
var vertex = vertices[ v ];
|
||||||
|
|
||||||
|
_vector4.set( vertex.x, vertex.y, vertex.z, 1 );
|
||||||
|
_vector4.applyMatrix4( _modelViewProjectionMatrix );
|
||||||
|
|
||||||
|
pushPoint( _vector4, object, camera );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} else if ( object instanceof THREE.Sprite ) {
|
} else if ( object instanceof THREE.Sprite ) {
|
||||||
|
|
||||||
_vector4.set( _modelMatrix.elements[ 12 ], _modelMatrix.elements[ 13 ], _modelMatrix.elements[ 14 ], 1 );
|
_vector4.set( _modelMatrix.elements[ 12 ], _modelMatrix.elements[ 13 ], _modelMatrix.elements[ 14 ], 1 );
|
||||||
_vector4.applyMatrix4( _viewProjectionMatrix );
|
_vector4.applyMatrix4( _viewProjectionMatrix );
|
||||||
|
|
||||||
|
pushPoint( _vector4, object, camera );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( sortElements === true ) {
|
||||||
|
|
||||||
|
_renderData.elements.sort( painterSort );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return _renderData;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
function pushPoint( _vector4, object, camera ) {
|
||||||
|
|
||||||
var invW = 1 / _vector4.w;
|
var invW = 1 / _vector4.w;
|
||||||
|
|
||||||
_vector4.z *= invW;
|
_vector4.z *= invW;
|
||||||
|
@ -737,18 +828,6 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( sortElements === true ) {
|
|
||||||
|
|
||||||
_renderData.elements.sort( painterSort );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return _renderData;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// Pools
|
// Pools
|
||||||
|
|
||||||
function getNextObjectInPool() {
|
function getNextObjectInPool() {
|
||||||
|
@ -862,6 +941,7 @@ THREE.Projector = function () {
|
||||||
|
|
||||||
// Calculate the boundary coordinate of each vertex for the near and far clip planes,
|
// Calculate the boundary coordinate of each vertex for the near and far clip planes,
|
||||||
// Z = -1 and Z = +1, respectively.
|
// Z = -1 and Z = +1, respectively.
|
||||||
|
|
||||||
bc1near = s1.z + s1.w,
|
bc1near = s1.z + s1.w,
|
||||||
bc2near = s2.z + s2.w,
|
bc2near = s2.z + s2.w,
|
||||||
bc1far = - s1.z + s1.w,
|
bc1far = - s1.z + s1.w,
|
||||||
|
|
|
@ -78,7 +78,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
this.supportsVertexTextures = function () {};
|
this.supportsVertexTextures = function () {};
|
||||||
this.setFaceCulling = function () {};
|
this.setFaceCulling = function () {};
|
||||||
|
|
||||||
this.setClearColor = function ( color, alpha ) {
|
this.setClearColor = function ( color ) {
|
||||||
|
|
||||||
clearColor.set( color );
|
clearColor.set( color );
|
||||||
clearColorBuffer( clearColor );
|
clearColorBuffer( clearColor );
|
||||||
|
@ -179,7 +179,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
var material = element.material;
|
var material = element.material;
|
||||||
var shader = getMaterialShader( material );
|
var shader = getMaterialShader( material );
|
||||||
|
|
||||||
if ( !shader ) continue;
|
if ( ! shader ) continue;
|
||||||
|
|
||||||
if ( element instanceof THREE.RenderableFace ) {
|
if ( element instanceof THREE.RenderableFace ) {
|
||||||
|
|
||||||
|
@ -286,8 +286,8 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
drawLine(
|
drawLine(
|
||||||
element.v1.positionScreen,
|
element.v1.positionScreen,
|
||||||
element.v2.positionScreen,
|
element.v2.positionScreen,
|
||||||
element.vertexColors[0],
|
element.vertexColors[ 0 ],
|
||||||
element.vertexColors[1],
|
element.vertexColors[ 1 ],
|
||||||
shader,
|
shader,
|
||||||
material
|
material
|
||||||
);
|
);
|
||||||
|
@ -479,6 +479,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
|
|
||||||
if ( buffer[ colorOffset + 3 ] == 255 ) // Only opaue pixls write to the depth buffer
|
if ( buffer[ colorOffset + 3 ] == 255 ) // Only opaue pixls write to the depth buffer
|
||||||
depthBuf[ offset ] = depth;
|
depthBuf[ offset ] = depth;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -528,16 +529,6 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMaterialUpdate ( event ) {
|
|
||||||
|
|
||||||
var material = event.target;
|
|
||||||
|
|
||||||
material.removeEventListener( 'update', onMaterialUpdate );
|
|
||||||
|
|
||||||
delete shaders[ material.id ];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function getMaterialShader( material ) {
|
function getMaterialShader( material ) {
|
||||||
|
|
||||||
var id = material.id;
|
var id = material.id;
|
||||||
|
@ -545,9 +536,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
|
|
||||||
if ( shader && material.map && !textures[ material.map.id ] ) delete shaders[ id ];
|
if ( shader && material.map && !textures[ material.map.id ] ) delete shaders[ id ];
|
||||||
|
|
||||||
if ( shaders[ id ] === undefined ) {
|
if ( shaders[ id ] === undefined || material.needsUpdate === true ) {
|
||||||
|
|
||||||
material.addEventListener( 'update', onMaterialUpdate );
|
|
||||||
|
|
||||||
if ( material instanceof THREE.MeshBasicMaterial ||
|
if ( material instanceof THREE.MeshBasicMaterial ||
|
||||||
material instanceof THREE.MeshLambertMaterial ||
|
material instanceof THREE.MeshLambertMaterial ||
|
||||||
|
@ -581,7 +570,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
var texture = new THREE.SoftwareRenderer.Texture();
|
var texture = new THREE.SoftwareRenderer.Texture();
|
||||||
texture.fromImage( material.map.image );
|
texture.fromImage( material.map.image );
|
||||||
|
|
||||||
if ( !texture.data ) return;
|
if ( ! texture.data ) return;
|
||||||
|
|
||||||
textures[ material.map.id ] = texture;
|
textures[ material.map.id ] = texture;
|
||||||
|
|
||||||
|
@ -636,7 +625,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
'buffer[ colorOffset + 2 ] = material.color.b * (color1.b+color2.b) * 0.5 * 255;',
|
'buffer[ colorOffset + 2 ] = material.color.b * (color1.b+color2.b) * 0.5 * 255;',
|
||||||
'buffer[ colorOffset + 3 ] = 255;',
|
'buffer[ colorOffset + 3 ] = 255;',
|
||||||
'depthBuf[ offset ] = depth;'
|
'depthBuf[ offset ] = depth;'
|
||||||
].join('\n');
|
].join( '\n' );
|
||||||
|
|
||||||
shader = new Function( 'buffer, depthBuf, offset, depth, color1, color2, material', string );
|
shader = new Function( 'buffer, depthBuf, offset, depth, color1, color2, material', string );
|
||||||
|
|
||||||
|
@ -657,12 +646,15 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
|
|
||||||
shaders[ id ] = shader;
|
shaders[ id ] = shader;
|
||||||
|
|
||||||
|
material.needsUpdate = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return shader;
|
return shader;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
function clearRectangle( x1, y1, x2, y2 ) {
|
function clearRectangle( x1, y1, x2, y2 ) {
|
||||||
|
|
||||||
var xmin = Math.max( Math.min( x1, x2 ), 0 );
|
var xmin = Math.max( Math.min( x1, x2 ), 0 );
|
||||||
|
@ -686,6 +678,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
function drawTriangle( v1, v2, v3, uv1, uv2, uv3, shader, face, material ) {
|
function drawTriangle( v1, v2, v3, uv1, uv2, uv3, shader, face, material ) {
|
||||||
|
|
||||||
|
@ -712,13 +705,12 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
var bHasUV = uv1 && uv2 && uv3;
|
var bHasUV = uv1 && uv2 && uv3;
|
||||||
|
|
||||||
var longestSide = Math.max(
|
var longestSide = Math.max(
|
||||||
Math.sqrt( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) ),
|
Math.sqrt( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ),
|
||||||
Math.sqrt( (x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3) ),
|
Math.sqrt( ( x2 - x3 ) * ( x2 - x3 ) + ( y2 - y3 ) * ( y2 - y3 ) ),
|
||||||
Math.sqrt( (x3 - x1)*(x3 - x1) + (y3 - y1)*(y3 - y1) )
|
Math.sqrt( ( x3 - x1 ) * ( x3 - x1 ) + ( y3 - y1 ) * ( y3 - y1 ) )
|
||||||
);
|
);
|
||||||
|
|
||||||
if( !(face instanceof THREE.RenderableSprite)
|
if ( ! ( face instanceof THREE.RenderableSprite ) && ( longestSide > 100 * fixscale ) ) {
|
||||||
&& (longestSide > 100 * fixscale) ) {
|
|
||||||
|
|
||||||
// 1
|
// 1
|
||||||
// |\
|
// |\
|
||||||
|
@ -728,11 +720,13 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
// |b\|d\
|
// |b\|d\
|
||||||
// |__\__\
|
// |__\__\
|
||||||
// 2 3
|
// 2 3
|
||||||
var tempFace = { vertexNormalsModel : [],
|
var tempFace = { vertexNormalsModel: [], color: face.color };
|
||||||
color : face.color };
|
|
||||||
var mpUV12, mpUV23, mpUV31;
|
var mpUV12, mpUV23, mpUV31;
|
||||||
|
|
||||||
if ( bHasUV ) {
|
if ( bHasUV ) {
|
||||||
|
|
||||||
if ( mpUVPoolCount === mpUVPool.length ) {
|
if ( mpUVPoolCount === mpUVPool.length ) {
|
||||||
|
|
||||||
mpUV12 = new THREE.Vector2();
|
mpUV12 = new THREE.Vector2();
|
||||||
mpUVPool.push( mpUV12 );
|
mpUVPool.push( mpUV12 );
|
||||||
++mpUVPoolCount;
|
++mpUVPoolCount;
|
||||||
|
@ -744,27 +738,37 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
mpUV31 = new THREE.Vector2();
|
mpUV31 = new THREE.Vector2();
|
||||||
mpUVPool.push( mpUV31 );
|
mpUVPool.push( mpUV31 );
|
||||||
++mpUVPoolCount;
|
++mpUVPoolCount;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
mpUV12 = mpUVPool[ mpUVPoolCount ];
|
mpUV12 = mpUVPool[ mpUVPoolCount ];
|
||||||
++mpUVPoolCount;
|
++mpUVPoolCount;
|
||||||
|
|
||||||
mpUV23 = mpUVPool[ mpUVPoolCount ];
|
mpUV23 = mpUVPool[ mpUVPoolCount ];
|
||||||
++mpUVPoolCount;
|
++mpUVPoolCount;
|
||||||
|
|
||||||
mpUV31 = mpUVPool[ mpUVPoolCount ];
|
mpUV31 = mpUVPool[ mpUVPoolCount ];
|
||||||
++mpUVPoolCount;
|
++mpUVPoolCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var weight;
|
var weight;
|
||||||
|
|
||||||
weight = (1 + v2.z) * (v2.w / v1.w) / (1 + v1.z);
|
weight = ( 1 + v2.z ) * ( v2.w / v1.w ) / ( 1 + v1.z );
|
||||||
mpUV12.copy( uv1 ).multiplyScalar( weight ).add( uv2 ).multiplyScalar( 1 / (weight + 1) );
|
mpUV12.copy( uv1 ).multiplyScalar( weight ).add( uv2 ).multiplyScalar( 1 / ( weight + 1 ) );
|
||||||
weight = (1 + v3.z) * (v3.w / v2.w) / (1 + v2.z);
|
|
||||||
mpUV23.copy( uv2 ).multiplyScalar( weight ).add( uv3 ).multiplyScalar( 1 / (weight + 1) );
|
weight = ( 1 + v3.z ) * ( v3.w / v2.w ) / ( 1 + v2.z );
|
||||||
weight = (1 + v1.z) * (v1.w / v3.w) / (1 + v3.z);
|
mpUV23.copy( uv2 ).multiplyScalar( weight ).add( uv3 ).multiplyScalar( 1 / ( weight + 1 ) );
|
||||||
mpUV31.copy( uv3 ).multiplyScalar( weight ).add( uv1 ).multiplyScalar( 1 / (weight + 1) );
|
|
||||||
|
weight = ( 1 + v1.z ) * ( v1.w / v3.w ) / ( 1 + v3.z );
|
||||||
|
mpUV31.copy( uv3 ).multiplyScalar( weight ).add( uv1 ).multiplyScalar( 1 / ( weight + 1 ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var mpV12, mpV23, mpV31;
|
var mpV12, mpV23, mpV31;
|
||||||
|
|
||||||
if ( mpVPoolCount === mpVPool.length ) {
|
if ( mpVPoolCount === mpVPool.length ) {
|
||||||
|
|
||||||
mpV12 = new THREE.Vector4();
|
mpV12 = new THREE.Vector4();
|
||||||
mpVPool.push( mpV12 );
|
mpVPool.push( mpV12 );
|
||||||
++mpVPoolCount;
|
++mpVPoolCount;
|
||||||
|
@ -776,13 +780,18 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
mpV31 = new THREE.Vector4();
|
mpV31 = new THREE.Vector4();
|
||||||
mpVPool.push( mpV31 );
|
mpVPool.push( mpV31 );
|
||||||
++mpVPoolCount;
|
++mpVPoolCount;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
mpV12 = mpVPool[ mpVPoolCount ];
|
mpV12 = mpVPool[ mpVPoolCount ];
|
||||||
++mpVPoolCount;
|
++mpVPoolCount;
|
||||||
|
|
||||||
mpV23 = mpVPool[ mpVPoolCount ];
|
mpV23 = mpVPool[ mpVPoolCount ];
|
||||||
++mpVPoolCount;
|
++mpVPoolCount;
|
||||||
|
|
||||||
mpV31 = mpVPool[ mpVPoolCount ];
|
mpV31 = mpVPool[ mpVPoolCount ];
|
||||||
++mpVPoolCount;
|
++mpVPoolCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mpV12.copy( v1 ).add( v2 ).multiplyScalar( 0.5 );
|
mpV12.copy( v1 ).add( v2 ).multiplyScalar( 0.5 );
|
||||||
|
@ -790,8 +799,11 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
mpV31.copy( v3 ).add( v1 ).multiplyScalar( 0.5 );
|
mpV31.copy( v3 ).add( v1 ).multiplyScalar( 0.5 );
|
||||||
|
|
||||||
var mpN12, mpN23, mpN31;
|
var mpN12, mpN23, mpN31;
|
||||||
if( bHasNormal ) {
|
|
||||||
|
if ( bHasNormal ) {
|
||||||
|
|
||||||
if ( mpNPoolCount === mpNPool.length ) {
|
if ( mpNPoolCount === mpNPool.length ) {
|
||||||
|
|
||||||
mpN12 = new THREE.Vector3();
|
mpN12 = new THREE.Vector3();
|
||||||
mpNPool.push( mpN12 );
|
mpNPool.push( mpN12 );
|
||||||
++mpNPoolCount;
|
++mpNPoolCount;
|
||||||
|
@ -803,53 +815,72 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
mpN31 = new THREE.Vector3();
|
mpN31 = new THREE.Vector3();
|
||||||
mpNPool.push( mpN31 );
|
mpNPool.push( mpN31 );
|
||||||
++mpNPoolCount;
|
++mpNPoolCount;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
mpN12 = mpNPool[ mpNPoolCount ];
|
mpN12 = mpNPool[ mpNPoolCount ];
|
||||||
++mpNPoolCount;
|
++mpNPoolCount;
|
||||||
|
|
||||||
mpN23 = mpNPool[ mpNPoolCount ];
|
mpN23 = mpNPool[ mpNPoolCount ];
|
||||||
++mpNPoolCount;
|
++mpNPoolCount;
|
||||||
|
|
||||||
mpN31 = mpNPool[ mpNPoolCount ];
|
mpN31 = mpNPool[ mpNPoolCount ];
|
||||||
++mpNPoolCount;
|
++mpNPoolCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mpN12.copy( face.vertexNormalsModel[ 0 ] ).add( face.vertexNormalsModel[ 1 ] ).normalize();
|
mpN12.copy( face.vertexNormalsModel[ 0 ] ).add( face.vertexNormalsModel[ 1 ] ).normalize();
|
||||||
mpN23.copy( face.vertexNormalsModel[ 1 ] ).add( face.vertexNormalsModel[ 2 ] ).normalize();
|
mpN23.copy( face.vertexNormalsModel[ 1 ] ).add( face.vertexNormalsModel[ 2 ] ).normalize();
|
||||||
mpN31.copy( face.vertexNormalsModel[ 2 ] ).add( face.vertexNormalsModel[ 0 ] ).normalize();
|
mpN31.copy( face.vertexNormalsModel[ 2 ] ).add( face.vertexNormalsModel[ 0 ] ).normalize();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// a
|
// a
|
||||||
if( bHasNormal ) {
|
if ( bHasNormal ) {
|
||||||
|
|
||||||
tempFace.vertexNormalsModel[ 0 ] = face.vertexNormalsModel[ 0 ];
|
tempFace.vertexNormalsModel[ 0 ] = face.vertexNormalsModel[ 0 ];
|
||||||
tempFace.vertexNormalsModel[ 1 ] = mpN12;
|
tempFace.vertexNormalsModel[ 1 ] = mpN12;
|
||||||
tempFace.vertexNormalsModel[ 2 ] = mpN31;
|
tempFace.vertexNormalsModel[ 2 ] = mpN31;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drawTriangle( v1, mpV12, mpV31, uv1, mpUV12, mpUV31, shader, tempFace, material );
|
drawTriangle( v1, mpV12, mpV31, uv1, mpUV12, mpUV31, shader, tempFace, material );
|
||||||
|
|
||||||
// b
|
// b
|
||||||
if( bHasNormal ) {
|
if ( bHasNormal ) {
|
||||||
|
|
||||||
tempFace.vertexNormalsModel[ 0 ] = face.vertexNormalsModel[ 1 ];
|
tempFace.vertexNormalsModel[ 0 ] = face.vertexNormalsModel[ 1 ];
|
||||||
tempFace.vertexNormalsModel[ 1 ] = mpN23;
|
tempFace.vertexNormalsModel[ 1 ] = mpN23;
|
||||||
tempFace.vertexNormalsModel[ 2 ] = mpN12;
|
tempFace.vertexNormalsModel[ 2 ] = mpN12;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drawTriangle( v2, mpV23, mpV12, uv2, mpUV23, mpUV12, shader, tempFace, material );
|
drawTriangle( v2, mpV23, mpV12, uv2, mpUV23, mpUV12, shader, tempFace, material );
|
||||||
|
|
||||||
// c
|
// c
|
||||||
if( bHasNormal ) {
|
if ( bHasNormal ) {
|
||||||
|
|
||||||
tempFace.vertexNormalsModel[ 0 ] = mpN12;
|
tempFace.vertexNormalsModel[ 0 ] = mpN12;
|
||||||
tempFace.vertexNormalsModel[ 1 ] = mpN23;
|
tempFace.vertexNormalsModel[ 1 ] = mpN23;
|
||||||
tempFace.vertexNormalsModel[ 2 ] = mpN31;
|
tempFace.vertexNormalsModel[ 2 ] = mpN31;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drawTriangle( mpV12, mpV23, mpV31, mpUV12, mpUV23, mpUV31, shader, tempFace, material );
|
drawTriangle( mpV12, mpV23, mpV31, mpUV12, mpUV23, mpUV31, shader, tempFace, material );
|
||||||
|
|
||||||
// d
|
// d
|
||||||
if( bHasNormal ) {
|
if ( bHasNormal ) {
|
||||||
|
|
||||||
tempFace.vertexNormalsModel[ 0 ] = face.vertexNormalsModel[ 2 ];
|
tempFace.vertexNormalsModel[ 0 ] = face.vertexNormalsModel[ 2 ];
|
||||||
tempFace.vertexNormalsModel[ 1 ] = mpN31;
|
tempFace.vertexNormalsModel[ 1 ] = mpN31;
|
||||||
tempFace.vertexNormalsModel[ 2 ] = mpN23;
|
tempFace.vertexNormalsModel[ 2 ] = mpN23;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drawTriangle( v3, mpV31, mpV23, uv3, mpUV31, mpUV23, shader, tempFace, material );
|
drawTriangle( v3, mpV31, mpV23, uv3, mpUV31, mpUV23, shader, tempFace, material );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Z values (.28 fixed-point)
|
// Z values (.28 fixed-point)
|
||||||
|
@ -976,7 +1007,8 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var dnxdx, dnzdy, cbnz;
|
var dnzdy, cbnz;
|
||||||
|
|
||||||
if ( bHasNormal ) {
|
if ( bHasNormal ) {
|
||||||
|
|
||||||
// Normal interpolation setup
|
// Normal interpolation setup
|
||||||
|
@ -1369,16 +1401,18 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
function drawLine( v1, v2, color1, color2, shader, material ) {
|
function drawLine( v1, v2, color1, color2, shader, material ) {
|
||||||
|
|
||||||
// While the line mode is enable, blockSize has to be changed to 0.
|
// While the line mode is enable, blockSize has to be changed to 0.
|
||||||
if ( !lineMode ) {
|
if ( ! lineMode ) {
|
||||||
|
|
||||||
lineMode = true;
|
lineMode = true;
|
||||||
blockShift = 0;
|
blockShift = 0;
|
||||||
blockSize = 1 << blockShift;
|
blockSize = 1 << blockShift;
|
||||||
|
|
||||||
setSize( canvas.width, canvas.height );
|
setSize( canvas.width, canvas.height );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement per-pixel z-clipping
|
// TODO: Implement per-pixel z-clipping
|
||||||
if ( v1.z < -1 || v1.z > 1 || v2.z < -1 || v2.z > 1 ) return;
|
if ( v1.z < - 1 || v1.z > 1 || v2.z < - 1 || v2.z > 1 ) return;
|
||||||
|
|
||||||
var halfLineWidth = Math.floor( ( material.linewidth - 1 ) * 0.5 );
|
var halfLineWidth = Math.floor( ( material.linewidth - 1 ) * 0.5 );
|
||||||
|
|
||||||
|
@ -1422,7 +1456,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
crossVector.cross( lookVector );
|
crossVector.cross( lookVector );
|
||||||
crossVector.normalize();
|
crossVector.normalize();
|
||||||
|
|
||||||
while (length > 0) {
|
while ( length > 0 ) {
|
||||||
|
|
||||||
// Get this pixel.
|
// Get this pixel.
|
||||||
pixelX = x2 + length * unitX;
|
pixelX = x2 + length * unitX;
|
||||||
|
@ -1434,7 +1468,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
pZ = ( pixelZ + subpixelBias ) >> subpixelBits;
|
pZ = ( pixelZ + subpixelBias ) >> subpixelBits;
|
||||||
|
|
||||||
// Draw line with line width
|
// Draw line with line width
|
||||||
for ( var i = -halfLineWidth; i <= halfLineWidth; ++i ) {
|
for ( var i = - halfLineWidth; i <= halfLineWidth; ++ i ) {
|
||||||
|
|
||||||
// Compute the line pixels.
|
// Compute the line pixels.
|
||||||
// Get the pixels on the vector that crosses to the line vector
|
// Get the pixels on the vector that crosses to the line vector
|
||||||
|
@ -1442,8 +1476,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
pY = Math.floor( ( pixelY + crossVector.y * i ) );
|
pY = Math.floor( ( pixelY + crossVector.y * i ) );
|
||||||
|
|
||||||
// if pixel is over the rect. Continue
|
// if pixel is over the rect. Continue
|
||||||
if ( rectx1 >= pX || rectx2 <= pX || recty1 >= pY
|
if ( rectx1 >= pX || rectx2 <= pX || recty1 >= pY || recty2 <= pY )
|
||||||
|| recty2 <= pY )
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Find this pixel at which block
|
// Find this pixel at which block
|
||||||
|
@ -1464,11 +1497,15 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
var offset = pX + pY * canvasWidth;
|
var offset = pX + pY * canvasWidth;
|
||||||
|
|
||||||
if ( pZ < zbuffer[ offset ] ) {
|
if ( pZ < zbuffer[ offset ] ) {
|
||||||
|
|
||||||
shader( data, zbuffer, offset, pZ, color1, color2, material );
|
shader( data, zbuffer, offset, pZ, color1, color2, material );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
--length;
|
--length;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1526,11 +1563,11 @@ THREE.SoftwareRenderer = function ( parameters ) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
THREE.SoftwareRenderer.Texture = function() {
|
THREE.SoftwareRenderer.Texture = function () {
|
||||||
|
|
||||||
var canvas;
|
var canvas;
|
||||||
|
|
||||||
this.fromImage = function( image ) {
|
this.fromImage = function ( image ) {
|
||||||
|
|
||||||
if ( ! image || image.width <= 0 || image.height <= 0 )
|
if ( ! image || image.width <= 0 || image.height <= 0 )
|
||||||
return;
|
return;
|
||||||
|
|
File diff suppressed because one or more lines are too long
Ładowanie…
Reference in New Issue