提交 c7133cac 编写于 作者: Z zz85

Merging alteredq/dev

因为 它太大了无法显示 source diff 。你可以改为 查看blob
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -138,7 +138,7 @@
uniforms[ "uShininess" ].value = 30;
var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
var materialNormalMap = new THREE.MeshShaderMaterial( parameters );
// planet
......
......@@ -62,21 +62,70 @@
scene = new THREE.Scene();
var light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 0, 1 );
light.position.normalize();
scene.addLight( light );
parent = new THREE.Object3D();
parent.position.y = 50;
scene.addChild( parent );
function addGeometry( geometry, color, x, y, z, rx, ry, rz, s ) {
function addGeometry( geometry, points, spacedPoints, color, x, y, z, rx, ry, rz, s ) {
// 3d shape
var mesh = new THREE.Mesh( geometry, [ new THREE.MeshBasicMaterial( { color: color } ), new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true } ) ] );
mesh.position.set( x, y, z );
var mesh = new THREE.Mesh( geometry, [ new THREE.MeshLambertMaterial( { color: color } ), new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true } ) ] );
mesh.position.set( x, y, z - 75 );
mesh.rotation.set( rx, ry, rz );
mesh.scale.set( s, s, s );
parent.addChild( mesh );
// solid line
var line = new THREE.Line( points, new THREE.LineBasicMaterial( { color: color, linewidth: 2 } ) );
line.position.set( x, y, z + 25 );
line.rotation.set( rx, ry, rz );
line.scale.set( s, s, s );
parent.addChild( line );
// transparent line from real points
var line = new THREE.Line( points, new THREE.LineBasicMaterial( { color: color, opacity: 0.5 } ) );
line.position.set( x, y, z + 75 );
line.rotation.set( rx, ry, rz );
line.scale.set( s, s, s );
parent.addChild( line );
// vertices from real points
var pgeo = THREE.GeometryUtils.clone( points );
var particles = new THREE.ParticleSystem( pgeo, new THREE.ParticleBasicMaterial( { color: color, size: 2, opacity: 0.75 } ) );
particles.position.set( x, y, z + 75 );
particles.rotation.set( rx, ry, rz );
particles.scale.set( s, s, s );
parent.addChild( particles );
// transparent line from equidistance sampled points
var line = new THREE.Line( spacedPoints, new THREE.LineBasicMaterial( { color: color, opacity: 0.2 } ) );
line.position.set( x, y, z + 100 );
line.rotation.set( rx, ry, rz );
line.scale.set( s, s, s );
parent.addChild( line );
// equidistance sampled points
var pgeo = THREE.GeometryUtils.clone( spacedPoints );
var particles2 = new THREE.ParticleSystem( pgeo, new THREE.ParticleBasicMaterial( { color: color, size: 2, opacity: 0.5 } ) );
particles2.position.set( x, y, z + 100 );
particles2.rotation.set( rx, ry, rz );
particles2.scale.set( s, s, s );
parent.addChild( particles2 );
}
var extrudeSettings = { amount: 20, bevelEnabled: true, bevelSegments: 2, steps: 2 }; //amount: 40, steps: 2
var extrudeSettings = { amount: 20, bevelEnabled: true, bevelSegments: 2, steps: 2 }; // amount: 40, steps: 2
// California
......@@ -106,7 +155,10 @@
californiaPts.push( new THREE.Vector2 ( 610, 320 ) );
var californiaShape = new THREE.Shape( californiaPts );
var california3d = new THREE.ExtrudeGeometry( californiaShape, { amount: 20 } );
var californiaPoints = californiaShape.createPointsGeometry();
var californiaSpacedPoints = californiaShape.createSpacedPointsGeometry( 100 );
// Triangle
......@@ -117,6 +169,8 @@
triangleShape.lineTo( 80, 20 ); // close path
var triangle3d = triangleShape.extrude( extrudeSettings );
var trianglePoints = triangleShape.createPointsGeometry();
var triangleSpacedPoints = triangleShape.createSpacedPointsGeometry();
// Heart
......@@ -134,6 +188,8 @@
heartShape.bezierCurveTo( x + 35, y, x + 25, y + 25, x + 25, y + 25 );
var heart3d = heartShape.extrude( extrudeSettings );
var heartPoints = heartShape.createPointsGeometry();
var heartSpacedPoints = heartShape.createSpacedPointsGeometry();
//heartShape.debug( document.getElementById("debug") );
......@@ -149,6 +205,8 @@
squareShape.lineTo( 0, 0 );
var square3d = squareShape.extrude( extrudeSettings );
var squarePoints = squareShape.createPointsGeometry();
var squareSpacedPoints = squareShape.createSpacedPointsGeometry();
// Rectangle
......@@ -162,6 +220,8 @@
rectShape.lineTo( 0, 0 );
var rect3d = rectShape.extrude( extrudeSettings );
var rectPoints = rectShape.createPointsGeometry();
var rectSpacedPoints = rectShape.createSpacedPointsGeometry();
// Rounded rectangle
......@@ -169,6 +229,8 @@
roundedRect( roundedRectShape, 0, 0, 50, 50, 20 );
var roundedRect3d = roundedRectShape.extrude( extrudeSettings );
var roundedRectPoints = roundedRectShape.createPointsGeometry();
var roundedRectSpacedPoints = roundedRectShape.createSpacedPointsGeometry();
function roundedRect( ctx, x, y, width, height, radius ){
......@@ -195,6 +257,8 @@
circleShape.quadraticCurveTo( -circleRadius, circleRadius, 0, circleRadius );
var circle3d = circleShape.extrude( extrudeSettings );
var circlePoints = circleShape.createPointsGeometry();
var circleSpacedPoints = circleShape.createSpacedPointsGeometry();
// Fish
......@@ -210,20 +274,25 @@
fishShape.quadraticCurveTo( x + 50, y - 80, x, y );
var fish3d = fishShape.extrude( extrudeSettings );
// Arc Circle
var fishPoints = fishShape.createPointsGeometry();
var fishSpacedPoints = fishShape.createSpacedPointsGeometry();
// Arc circle
var arcShape = new THREE.Shape();
arcShape.moveTo( 0, 0);
arcShape.arc(10,10, 40, 0, Math.PI*2,false);
arcShape.moveTo( 0, 0 );
arcShape.arc( 10, 10, 40, 0, Math.PI*2, false );
var holePath = new THREE.Path();
holePath.moveTo( 0, 0);
holePath.arc(10, 10, 10, 0, Math.PI*2, true);
arcShape.holes.push(holePath);
holePath.moveTo( 0, 0 );
holePath.arc( 10, 10, 10, 0, Math.PI*2, true );
arcShape.holes.push( holePath );
var arc3d = arcShape.extrude( extrudeSettings );
var arcPoints = arcShape.createPointsGeometry();
var arcSpacedPoints = arcShape.createSpacedPointsGeometry();
// Spline shape + Path Extrusion
// Spline shape + path extrusion
var splinepts = [];
splinepts.push( new THREE.Vector2 ( 350, 100 ) );
......@@ -239,7 +308,7 @@
var extrudePath = new THREE.Path();
extrudePath.moveTo(0,0);
extrudePath.moveTo( 0, 0 );
extrudePath.lineTo( 10, 10 );
extrudePath.quadraticCurveTo( 80, 60, 160, 10 );
extrudePath.quadraticCurveTo( 240, -40, 320, 10 );
......@@ -248,18 +317,22 @@
extrudeSettings.bevelEnabled = false;
var splineShape3d = splineShape.extrude( extrudeSettings );
addGeometry( california3d, 0xffaa00, -300, -100, 0, 0, 0, 0, 0.25 );
addGeometry( triangle3d, 0xffee00, -180, 0, 0, 0, 0, 0, 1 );
addGeometry( roundedRect3d, 0x005500, -150, 150, 0, 0, 0, 0, 1 );
addGeometry( square3d, 0x0055ff, 150, 100, 0, 0, 0, 0, 1 );
addGeometry( heart3d, 0xff1100, 0, 100, 0, 3.14, 0, 0, 1 );
addGeometry( circle3d, 0x00ff11, 120, 250, 0, 0, 0, 0, 1 );
addGeometry( fish3d, 0x222222, -50, 200, 0, 0, 0, 0, 1 );
addGeometry( splineShape3d, 0x888888, -50, -100, -50, 0, 0, 0, 0.2 );
addGeometry( arc3d, 0xbb4422, 150, 0, 0, 0, 0, 0, 1 );
renderer = new THREE.CanvasRenderer();
var splinePoints = splineShape.createPointsGeometry( );
var splineSpacedPoints = splineShape.createSpacedPointsGeometry( );
addGeometry( california3d, californiaPoints, californiaSpacedPoints, 0xffaa00, -300, -100, 0, 0, 0, 0, 0.25 );
addGeometry( triangle3d, trianglePoints, triangleSpacedPoints, 0xffee00, -180, 0, 0, 0, 0, 0, 1 );
addGeometry( roundedRect3d, roundedRectPoints, roundedRectSpacedPoints, 0x005500, -150, 150, 0, 0, 0, 0, 1 );
addGeometry( square3d, squarePoints, squareSpacedPoints, 0x0055ff, 150, 100, 0, 0, 0, 0, 1 );
addGeometry( heart3d, heartPoints, heartSpacedPoints, 0xff1100, 0, 100, 0, 3.14, 0, 0, 1 );
addGeometry( circle3d, circlePoints, circleSpacedPoints, 0x00ff11, 120, 250, 0, 0, 0, 0, 1 );
addGeometry( fish3d, fishPoints, fishSpacedPoints, 0x222222, -50, 200, 0, 0, 0, 0, 1 );
addGeometry( splineShape3d, splinePoints, splineSpacedPoints, 0x888888, -50, -100, -50, 0, 0, 0, 0.2 );
addGeometry( arc3d, arcPoints, arcSpacedPoints, 0xbb4422, 150, 0, 0, 0, 0, 0, 1 );
//
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
......
......@@ -26,14 +26,14 @@
<body>
<div id="info">
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - procedural 3D text by <a href="http://www.lab4games.net/zz85/blog" target="_blank">zz85</a> &amp; alteredq
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - procedural 3D text by <a href="http://www.lab4games.net/zz85/blog" target="_blank">zz85</a> &amp; alteredq
(fonts from <a href="http://typeface.neocracy.org/">typeface.js</a> and <a href="http://en.wikipedia.org/wiki/Droid_%28font%29">Droid</a>)
<br/>type to enter new text, drag to spin the text
<br/><span class="button" id="color">change color</span>,
<span class="button" id="font">change font</span>,
<br/><span class="button" id="color">change color</span>,
<span class="button" id="font">change font</span>,
<span class="button" id="weight">change weight</span>,
<span class="button" id="bezel">change bezel</span>,
<span class="button" id="postprocessing">change postprocessing</span>,
<span class="button" id="bevel">change bevel</span>,
<span class="button" id="postprocessing">change postprocessing</span>,
<a id="permalink" href="#">permalink</a>
</div>
......@@ -43,12 +43,12 @@
<script type="text/javascript" src="js/Detector.js"></script>
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
<script type="text/javascript" src="js/Stats.js"></script>
<!-- load the font file from canvas-text -->
<!--
-->
<script type="text/javascript" src="fonts/gentilis_bold.typeface.js"></script>
<script type="text/javascript" src="fonts/gentilis_regular.typeface.js"></script>
......@@ -60,7 +60,7 @@
<script type="text/javascript" src="fonts/droid/droid_sans_bold.typeface.js"></script>
<script type="text/javascript" src="fonts/droid/droid_serif_regular.typeface.js"></script>
<script type="text/javascript" src="fonts/droid/droid_serif_bold.typeface.js"></script>
<script type="text/javascript">
......@@ -82,9 +82,9 @@
curveSegments = 6,
bezelThickness = 2,
bezelSize = 1.5,
bezelEnabled = true,
bevelThickness = 2,
bevelSize = 1.5,
bevelEnabled = true,
font = "optimer", // helvetiker, optimer, gentilis, droid sans, droid serif
weight = "bold", // normal bold
......@@ -134,9 +134,9 @@
}
function decimalToHex( d ) {
var hex = Number( d ).toString( 16 );
hex = "000000".substr( 0, 6 - hex.length ) + hex;
hex = "000000".substr( 0, 6 - hex.length ) + hex;
return hex.toUpperCase();
}
......@@ -180,7 +180,7 @@
var fonthash = hash.substring( 6, 7 );
var weighthash = hash.substring( 7, 8 );
var pphash = hash.substring( 8, 9 );
var bezelhash = hash.substring( 9, 10 );
var bevelhash = hash.substring( 9, 10 );
var texthash = hash.substring( 11 );
hex = colorhash;
......@@ -190,7 +190,7 @@
weight = reverseWeightMap[ parseInt( weighthash ) ];
postprocessing.enabled = parseInt( pphash );
bezelEnabled = parseInt( bezelhash );
bevelEnabled = parseInt( bevelhash );
text = decodeURI( texthash );
......@@ -206,7 +206,7 @@
textGeo = new THREE.TextGeometry( text, {
size: size,
size: size,
height: height,
curveSegments: curveSegments,
......@@ -214,16 +214,16 @@
weight: weight,
style: style,
bezelThickness: bezelThickness,
bezelSize: bezelSize,
bezelEnabled: bezelEnabled
bevelThickness: bevelThickness,
bevelSize: bevelSize,
bevelEnabled: bevelEnabled
});
textMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, wireframe: false } );
parent = new THREE.Object3D();
textMesh1 = new THREE.Mesh( textGeo, textMaterial );
textMesh1.position.x = 0;
......@@ -247,7 +247,7 @@
textMesh2.rotation.y = Math.PI * 2;
parent.addChild( textMesh2 );
}
parent.position.y = 100;
......@@ -260,7 +260,7 @@
renderer = new THREE.WebGLRenderer( { antialias: false } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( scene.fog.color, 1 );
container.appendChild( renderer.domElement );
......@@ -277,91 +277,91 @@
document.addEventListener( 'keydown', onDocumentKeyDown, false );
document.getElementById( "color" ).addEventListener( 'click', function() {
pointLight.color.setHSV( Math.random(), 0.95, 0.85 );
pointLight.color.updateHex();
hex = decimalToHex( pointLight.color.hex );
updatePermalink();
}, false );
document.getElementById( "font" ).addEventListener( 'click', function() {
if ( font == "helvetiker" ) {
font = "optimer";
} else if ( font == "optimer" ) {
font = "gentilis";
} else if ( font == "gentilis" ) {
font = "droid sans";
} else if ( font == "droid sans" ) {
font = "droid serif";
} else {
font = "helvetiker";
}
refreshText();
}, false );
document.getElementById( "weight" ).addEventListener( 'click', function() {
if ( weight == "bold" ) {
weight = "normal";
} else {
weight = "bold";
}
refreshText();
}, false );
document.getElementById( "bezel" ).addEventListener( 'click', function() {
bezelEnabled = !bezelEnabled;
document.getElementById( "bevel" ).addEventListener( 'click', function() {
bevelEnabled = !bevelEnabled;
refreshText();
}, false );
document.getElementById( "postprocessing" ).addEventListener( 'click', function() {
postprocessing.enabled = !postprocessing.enabled;
updatePermalink();
}, false );
initPostprocessing();
renderer.autoClear = false;
}
//
function boolToNum( b ) {
return b ? 1 : 0;
}
function updatePermalink() {
var link = hex + fontMap[ font ] + weightMap[ weight ] + boolToNum( postprocessing.enabled ) + boolToNum( bezelEnabled ) + "#" + encodeURI( text );
var link = hex + fontMap[ font ] + weightMap[ weight ] + boolToNum( postprocessing.enabled ) + boolToNum( bevelEnabled ) + "#" + encodeURI( text );
permalink.href = "#" + link;
window.location.hash = link;
......@@ -370,14 +370,14 @@
function onDocumentKeyDown( event ) {
if ( firstLetter ) {
firstLetter = false;
text = "";
}
var keyCode = event.keyCode;
// backspace
if ( keyCode == 8 ) {
......@@ -388,23 +388,23 @@
refreshText();
return false;
}
}
function onDocumentKeyPress( event ) {
var keyCode = event.which;
// backspace
if ( keyCode == 8 ) {
event.preventDefault();
} else {
var ch = String.fromCharCode( keyCode );
text += ch;
......@@ -413,16 +413,16 @@
}
}
function refreshText() {
updatePermalink();
scene.removeChild( textMesh1 );
textGeo = new THREE.TextGeometry( text, {
size: size,
size: size,
height: height,
curveSegments: curveSegments,
......@@ -430,9 +430,9 @@
weight: weight,
style: style,
bezelThickness: bezelThickness,
bezelSize: bezelSize,
bezelEnabled: bezelEnabled
bevelThickness: bevelThickness,
bevelSize: bevelSize,
bevelEnabled: bevelEnabled
});
......@@ -459,14 +459,14 @@
textMesh2.rotation.x = Math.PI;
textMesh2.rotation.y = Math.PI * 2;
parent.addChild( textMesh2 );
}
}
function onDocumentMouseDown( event ) {
event.preventDefault();
......@@ -531,7 +531,7 @@
}
//
function initPostprocessing() {
postprocessing.scene = new THREE.Scene();
......@@ -621,9 +621,9 @@
time = new Date().getTime();
delta = 0.1 * ( time - oldTime );
oldTime = time;
parent.rotation.y += ( targetRotation - parent.rotation.y ) * 0.05;
if ( postprocessing.enabled ) {
renderer.clear();
......@@ -669,7 +669,7 @@
renderer.clear();
renderer.render( scene, camera );
}
}
}
......
......@@ -518,7 +518,9 @@ THREE.Matrix4.prototype = {
e = Math.cos( z ), f = Math.sin( z );
switch ( order ) {
case 'YXZ':
var ce = c * e, cf = c * f, de = d * e, df = d * f;
this.n11 = ce + df * b;
......@@ -535,6 +537,7 @@ THREE.Matrix4.prototype = {
break;
case 'ZXY':
var ce = c * e, cf = c * f, de = d * e, df = d * f;
this.n11 = ce - df * b;
......@@ -551,6 +554,7 @@ THREE.Matrix4.prototype = {
break;
case 'ZYX':
var ae = a * e, af = a * f, be = b * e, bf = b * f;
this.n11 = c * e;
......@@ -567,6 +571,7 @@ THREE.Matrix4.prototype = {
break;
case 'YZX':
var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
this.n11 = c * e;
......@@ -583,6 +588,7 @@ THREE.Matrix4.prototype = {
break;
case 'XZY':
var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
this.n11 = c * e;
......@@ -599,6 +605,7 @@ THREE.Matrix4.prototype = {
break;
default: // 'XYZ'
var ae = a * e, af = a * f, be = b * e, bf = b * f;
this.n11 = c * e;
......@@ -613,6 +620,7 @@ THREE.Matrix4.prototype = {
this.n32 = be + af * d;
this.n33 = a * c;
break;
}
return this;
......
/**
* @author mrdoob / http://mrdoob.com/
* @author alteredq / http://alteredqualia.com/
*/
THREE.GeometryUtils = {
......@@ -19,6 +20,8 @@ THREE.GeometryUtils = {
isMesh && object2.matrixAutoUpdate && object2.updateMatrix();
// vertices
for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
var vertex = vertices2[ i ];
......@@ -31,6 +34,8 @@ THREE.GeometryUtils = {
}
// faces
for ( i = 0, il = faces2.length; i < il; i ++ ) {
var face = faces2[ i ], faceCopy, normal, color,
......@@ -73,6 +78,8 @@ THREE.GeometryUtils = {
}
// uvs
for ( i = 0, il = uvs2.length; i < il; i ++ ) {
var uv = uvs2[ i ], uvCopy = [];
......@@ -87,6 +94,91 @@ THREE.GeometryUtils = {
}
},
clone: function ( geometry ) {
var cloneGeo = new THREE.Geometry();
var i, il;
var vertices = geometry.vertices,
faces = geometry.faces,
uvs = geometry.faceVertexUvs[ 0 ];
// vertices
for ( i = 0, il = vertices.length; i < il; i ++ ) {
var vertex = vertices[ i ];
var vertexCopy = new THREE.Vertex( vertex.position.clone() );
cloneGeo.vertices.push( vertexCopy );
}
// faces
for ( i = 0, il = faces.length; i < il; i ++ ) {
var face = faces[ i ], faceCopy, normal, color,
faceVertexNormals = face.vertexNormals,
faceVertexColors = face.vertexColors;
if ( face instanceof THREE.Face3 ) {
faceCopy = new THREE.Face3( face.a, face.b, face.c );
} else if ( face instanceof THREE.Face4 ) {
faceCopy = new THREE.Face4( face.a, face.b, face.c, face.d );
}
faceCopy.normal.copy( face.normal );
for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
normal = faceVertexNormals[ j ];
faceCopy.vertexNormals.push( normal.clone() );
}
faceCopy.color.copy( face.color );
for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
color = faceVertexColors[ j ];
faceCopy.vertexColors.push( color.clone() );
}
faceCopy.materials = face.materials.slice();
faceCopy.centroid.copy( face.centroid );
cloneGeo.faces.push( faceCopy );
}
// uvs
for ( i = 0, il = uvs.length; i < il; i ++ ) {
var uv = uvs[ i ], uvCopy = [];
for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
uvCopy.push( new THREE.UV( uv[ j ].u, uv[ j ].v ) );
}
cloneGeo.faceVertexUvs[ 0 ].push( uvCopy );
}
return cloneGeo;
}
};
......@@ -164,6 +164,9 @@ THREE.FirstPersonCamera = function ( parameters ) {
case 39: /*right*/
case 68: /*D*/ this.moveRight = true; break;
case 82: /*R*/ this.moveUp = true; break;
case 70: /*F*/ this.moveDown = true; break;
case 81: this.freeze = !this.freeze; break;
}
......@@ -186,6 +189,9 @@ THREE.FirstPersonCamera = function ( parameters ) {
case 39: /*right*/
case 68: /*D*/ this.moveRight = false; break;
case 82: /*R*/ this.moveUp = false; break;
case 70: /*F*/ this.moveDown = false; break;
}
};
......@@ -195,7 +201,7 @@ THREE.FirstPersonCamera = function ( parameters ) {
var now = new Date().getTime();
this.tdiff = ( now - this.lastUpdate ) / 1000;
this.lastUpdate = now;
if ( !this.freeze ) {
......@@ -216,9 +222,13 @@ THREE.FirstPersonCamera = function ( parameters ) {
if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
if ( this.moveBackward ) this.translateZ( actualMoveSpeed );
if ( this.moveLeft ) this.translateX( - actualMoveSpeed );
if ( this.moveRight ) this.translateX( actualMoveSpeed );
if ( this.moveUp ) this.translateY( actualMoveSpeed );
if ( this.moveDown ) this.translateY( - actualMoveSpeed );
var actualLookSpeed = this.tdiff * this.lookSpeed;
if ( !this.activeLook ) {
......
......@@ -17,7 +17,7 @@
* Abstract Curve base class
**************************************************************/
THREE.Curve = function() {
THREE.Curve = function () {
};
......@@ -88,7 +88,7 @@ THREE.Curve.prototype.getLength = function () {
// Get list of cumulative segment lengths
THREE.Curve.prototype.getLengths = function( divisions ) {
THREE.Curve.prototype.getLengths = function ( divisions ) {
if ( !divisions ) divisions = 200;
......@@ -119,7 +119,7 @@ THREE.Curve.prototype.getLengths = function( divisions ) {
// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equi distance
THREE.Curve.prototype.getUtoTmapping = function( u, distance ) {
THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
var lengths = this.getLengths();
var i = 0, il = lengths.length;
......@@ -317,7 +317,9 @@ THREE.SplineCurve.prototype.getPoint = function ( t ) {
**************************************************************/
THREE.ArcCurve = function ( aX, aY, aRadius,
aStartAngle, aEndAngle, aClockwise ) {
aStartAngle, aEndAngle,
aClockwise ) {
this.aX = aX;
this.aY = aY;
......@@ -490,4 +492,4 @@ THREE.QuadraticBezierCurve3 = THREE.Curve.create(
return new THREE.Vector2( tx, ty, tz );
}
);
\ No newline at end of file
);
......@@ -31,14 +31,17 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness; // 8
var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
// We should set bevel segments to 0 if bevel is not enabled.
if (!bevelEnabled) bevelSegments = 0 ;
if ( !bevelEnabled ) bevelSegments = 0;
var steps = options.steps !== undefined ? options.steps : 1;
var extrudePath = options.path !== undefined ? options.path : null;
var extrudePts, extrudeByPath = false;
......@@ -49,101 +52,105 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
extrudeByPath = true;
}
// TODO, extrude by path's tangents? also via 3d path?
// Variables initalization
var ahole, h, hl; // looping of holes
var scope = this;
var bevelPoints = [];
var shapesOffset = this.vertices.length;
// getPoints
var shapePoints = shape.extractAllPoints(false, 8);
// false for getPoints | true for getSpacedPoints() for points with equal divisions
var vertices = shapePoints.shape;
var holes = shapePoints.holes;
var shapePoints = shape.extractAllPoints(); // use shape.extractAllSpacedPoints() for points with equal divisions
var vertices = shapePoints.shape;
var holes = shapePoints.holes;
var reverse = !THREE.Shape.Utils.isClockWise( vertices ) ;
if (reverse) {
if ( reverse ) {
vertices = vertices.reverse();
// Maybe we should also check if holes are in the opposite direction, just to be safe...
for (h = 0, hl = holes.length; h < hl; h++ ) {
ahole = holes[h];
if (THREE.Shape.Utils.isClockWise(ahole)) {
holes[h] = ahole.reverse();
// Maybe we should also check if holes are in the opposite direction, just to be safe ...
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
ahole = holes[ h ];
if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
holes[ h ] = ahole.reverse();
}
}
reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
}
var faces = THREE.Shape.Utils.triangulateShape(vertices, holes);
//var faces = THREE.Shape.Utils.triangulate2(vertices, holes);
var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
//var faces = THREE.Shape.Utils.triangulate2( vertices, holes );
//console.log(faces);
////
/// Handle Vertices
////
var contour = vertices; // vertices has all points but contour has only points of circumference
for (h = 0, hl = holes.length; h < hl; h++ ) {
ahole = holes[h];
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
vertices = vertices.concat(ahole);
ahole = holes[ h ];
vertices = vertices.concat( ahole );
}
// Find all centroids of shapes and holes
var b;
var i, il;
var sum = new THREE.Vector2();
var contourCentroid, holesCentroids;
for (i=0, il = contour.length; i<il; i++) {
sum.addSelf(contour[i]);
for ( i = 0, il = contour.length; i < il; i ++ ) {
sum.addSelf( contour[ i ] );
}
contourCentroid = sum.divideScalar( contour.length ) ;
holesCentroids = [];
for (h=0, hl = holes.length; h<hl; h++) {
var contourCentroid = sum.divideScalar( contour.length );
var holesCentroids = [];
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
sum = new THREE.Vector2();
ahole = holes[h];
for (i=0, il = ahole.length; i<il; i++) {
sum.addSelf(ahole[i]);
ahole = holes[ h ];
for ( i=0, il = ahole.length; i < il; i ++ ) {
sum.addSelf( ahole[ i ] );
}
holesCentroids[h] = sum.divideScalar( ahole.length ) ;
holesCentroids[ h ] = sum.divideScalar( ahole.length );
}
function scalePt (pt, centroid, size, expandOutwards /* Boolean */ ) {
vectorFromCentroid = pt.clone().subSelf( centroid );
adj = size / vectorFromCentroid.length();
function scalePt ( pt, centroid, size, expandOutwards /* Boolean */ ) {
var vectorFromCentroid = pt.clone().subSelf( centroid );
var adj = size / vectorFromCentroid.length();
if ( expandOutwards ) {
adj += 1;
adj = 1 + adj;
} else {
......@@ -152,7 +159,10 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
}
return vectorFromCentroid.multiplyScalar( adj ).addSelf( centroid );
}
function scalePt2 (pt, vec, size ) {
//return vec.clone().multiplyScalar( size ).addSelf( pt );
......@@ -160,14 +170,11 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
}
var i,
var b, bs, t, z,
vert, vlen = vertices.length,
face, flen = faces.length,
cont, clen = contour.length,
hol, hlen;
cont, clen = contour.length;
var bs;
//------
// Find directions for point movement
......@@ -255,23 +262,28 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
// Loop bevelSegments, 1 for the front, 1 for the back
for (b=bevelSegments; b > 0; b--) {
t = b / bevelSegments;
for ( b = bevelSegments; b > 0; b -- ) {
t = b / bevelSegments;
z = bevelThickness * t;
// Formula could probably be simplified
//bs = bevelSize * (1-Math.sin ((1-t) * Math.PI/2 )) ; //bevelSize * t ;
bs = bevelSize * t ;
bs = bevelSize * (1-Math.sin ((1-t) * Math.PI/2 )) ; //bevelSize * t ;
//bs = bevelSize * t ;
// contract shape
for ( i = 0, il = contour.length; i < il; i++ ) {
vert = scalePt2(contour[i], contourMovements[i], bs);
//vert = scalePt( contour[ i ], contourCentroid, bs, false );
v( vert.x, vert.y, - z);
}
// expand holes
for ( h = 0, hl = holes.length; h < hl; h++ ) {
ahole = holes[h];
......@@ -280,25 +292,24 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
for ( i = 0, il = ahole.length; i < il; i++ ) {
vert = scalePt2(ahole[i], oneHoleMovements[i], bs);
//vert = scalePt( ahole[ i ], holesCentroids[ h ], bs, true );
v( vert.x, vert.y, -z );
}
}
}
// Back facing vertices
for ( i = 0; i < vlen; i++ ) {
for ( i = 0; i < vlen; i ++ ) {
vert = vertices[ i ];
//v( vert.x, vert.y, 0 );
if ( !extrudeByPath ) {
v( vert.x, vert.y, 0 );
......@@ -311,11 +322,12 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
}
// Add steped vertices...
// Add stepped vertices...
// Including front facing vertices
var s = 1;
for ( ; s <= steps; s++ ) {
var s;
for ( s = 1; s <= steps; s ++ ) {
for ( i = 0; i < vlen; i ++ ) {
......@@ -323,7 +335,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
if ( !extrudeByPath ) {
v( vert.x, vert.y, amount/steps * s );
v( vert.x, vert.y, amount / steps * s );
} else {
......@@ -334,76 +346,79 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
}
}
// Add Bevel Segments planes
for (b=1; b <= bevelSegments; b++) {
t = b / bevelSegments;
z = bevelThickness * t;
bs = bevelSize * (1-Math.sin ((1-t) * Math.PI/2 ));
// contract shape
for ( i = 0, il = contour.length; i < il; i++ ) {
vert = scalePt(contour[i], contourCentroid, bs , false);
v( vert.x, vert.y, amount + z);
// Add bevel segments planes
}
for ( b = 1; b <= bevelSegments; b ++ ) {
// expand holes
for ( h = 0, hl = holes.length; h < hl; h++ ) {
t = b / bevelSegments;
z = bevelThickness * t;
bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
ahole = holes[h];
for ( i = 0, il = ahole.length; i < il; i++ ) {
vert = scalePt(ahole[i], holesCentroids[h] , bs , true);
if ( !extrudeByPath ) {
// contract shape
for ( i = 0, il = contour.length; i < il; i++ ) {
vert = scalePt( contour[ i ], contourCentroid, bs, false );
v( vert.x, vert.y, amount + z);
}
// expand holes
for ( h = 0, hl = holes.length; h < hl; h++ ) {
v( vert.x, vert.y, amount + z);
ahole = holes[ h ];
} else {
for ( i = 0, il = ahole.length; i < il; i++ ) {
vert = scalePt( ahole[ i ], holesCentroids[h], bs, true );
if ( !extrudeByPath ) {
v( vert.x, vert.y, amount + z );
} else {
v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x +z);
v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x +z );
}
}
}
}
}
}
////
/// Handle Faces
////
// not used anywhere
// var layers = ( steps + bevelSegments * 2 ) * vlen;
// Bottom faces
if (bevelEnabled ) {
var layer = 0 ; //steps + 1
if ( bevelEnabled ) {
var layer = 0 ; // steps + 1
var offset = vlen * layer;
for ( i = 0; i < flen; i++ ) {
for ( i = 0; i < flen; i ++ ) {
face = faces[ i ];
f3( face[ 2 ]+ offset, face[ 1 ]+ offset, face[ 0 ] + offset);
f3( face[ 2 ]+ offset, face[ 1 ]+ offset, face[ 0 ] + offset );
}
layer = steps + bevelSegments* 2;
layer = steps + bevelSegments * 2;
offset = vlen * layer;
// Top faces
var layers = (steps + bevelSegments * 2) * vlen;
for ( i = 0; i < flen; i++ ) {
for ( i = 0; i < flen; i ++ ) {
face = faces[ i ];
f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
......@@ -420,35 +435,40 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
}
// Top faces
var layers = (steps + bevelSegments * 2) * vlen;
for ( i = 0; i < flen; i++ ) {
for ( i = 0; i < flen; i ++ ) {
face = faces[ i ];
f3( face[ 0 ] + vlen* steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
}
}
var tmpPt;
var j, k, l, m;
var layeroffset = 0;
// Sides faces
sidewalls(contour);
sidewalls( contour );
layeroffset += contour.length;
for (h = 0, hl = holes.length; h < hl; h++ ) {
ahole = holes[h];
sidewalls(ahole);
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
ahole = holes[ h ];
sidewalls( ahole );
//, true
layeroffset += ahole.length;
}
// Create faces for the z-sides of the shape
function sidewalls(contour) {
// Create faces for the z-sides of the shape
function sidewalls( contour ) {
i = contour.length;
while ( --i >= 0 ) {
......@@ -456,7 +476,6 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
tmpPt = contour[ i ];
j = i;
k = i - 1;
if ( k < 0 ) k = contour.length - 1;
......@@ -465,20 +484,19 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
var s = 0;
for ( ; s < (steps + bevelSegments * 2) ; s++ ) {
for ( s = 0; s < ( steps + bevelSegments * 2 ); s ++ ) {
var slen1 = vlen * s;
var slen2 = vlen * ( s + 1 );
f4( layeroffset + j + slen1, layeroffset + k + slen1, layeroffset + k + slen2, layeroffset + j + slen2 );
}
}
}
// UVs to be added
this.computeCentroids();
......@@ -498,6 +516,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
scope.faces.push( new THREE.Face3( a, b, c ) );
}
function f4( a, b, c, d ) {
......
......@@ -33,7 +33,7 @@ THREE.PathActions = {
// Create path using straight lines to connect all points
// - vectors: array of Vector2
THREE.Path.prototype.fromPoints = function( vectors ) {
THREE.Path.prototype.fromPoints = function ( vectors ) {
this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
......@@ -49,14 +49,14 @@ THREE.Path.prototype.fromPoints = function( vectors ) {
// startPath() endPath()?
THREE.Path.prototype.moveTo = function( x, y ) {
THREE.Path.prototype.moveTo = function ( x, y ) {
var args = Array.prototype.slice.call( arguments );
this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
};
THREE.Path.prototype.lineTo = function( x, y ) {
THREE.Path.prototype.lineTo = function ( x, y ) {
var args = Array.prototype.slice.call( arguments );
......@@ -86,8 +86,8 @@ THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args, curve: curve } );
//console.log(curve, curve.getPoints(), curve.getSpacedPoints());
//console.log(curve.getPointAt(0), curve.getPointAt(0),curve.getUtoTmapping(0), curve.getSpacedPoints());
//console.log( curve, curve.getPoints(), curve.getSpacedPoints() );
//console.log( curve.getPointAt(0), curve.getPointAt(0), curve.getUtoTmapping(0), curve.getSpacedPoints() );
};
......@@ -127,21 +127,24 @@ THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args, curve: curve } );
//console.log(curve, curve.getPoints(), curve.getSpacedPoints());
//console.log( curve, curve.getPoints(), curve.getSpacedPoints() );
};
// FUTURE: Change the API or follow canvas API?
// TODO ARC ( x, y, x - radius, y - radius, startAngle, endAngle )
THREE.Path.prototype.arc = function(aX, aY, aRadius,
aStartAngle, aEndAngle, aClockwise ) {
THREE.Path.prototype.arc = function ( aX, aY, aRadius,
aStartAngle, aEndAngle, aClockwise ) {
var args = Array.prototype.slice.call( arguments );
var curve = new THREE.ArcCurve( aX, aY, aRadius,
aStartAngle, aEndAngle, aClockwise );
this.curves.push( curve );
//console.log('arc', args);
// console.log( 'arc', args );
this.actions.push( { action: THREE.PathActions.ARC, args: args } );
};
......@@ -162,27 +165,33 @@ THREE.Path.prototype.arc = function(aX, aY, aRadius,
*/
THREE.Path.prototype.getSpacedPoints = function( divisions ) {
THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
if ( !divisions ) divisions = 40;
var pts = [];
var points = [];
for ( var i = 0; i < divisions; i++ ) {
pts.push( this.getPoint( i / divisions ) );
points.push( this.getPoint( i / divisions ) );
//if( !this.getPoint( i / divisions ) ) throw "DIE";
//if(!this.getPoint(i/divisions)) throw "DIE";
}
if ( closedPath ) {
points.push( points[ 0 ] );
}
//console.log(pts);
return pts;
return points;
};
/* Return an array of vectors based on contour of the path */
THREE.Path.prototype.getPoints = function( divisions ) {
THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
divisions = divisions || 12;
......@@ -204,7 +213,7 @@ THREE.Path.prototype.getPoints = function( divisions ) {
case THREE.PathActions.MOVE_TO:
//points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
// points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
break;
......@@ -365,11 +374,17 @@ THREE.Path.prototype.getPoints = function( divisions ) {
}
if ( closedPath ) {
points.push( points[ 0 ] );
}
return points;
};
THREE.Path.prototype.getMinAndMax = function() {
THREE.Path.prototype.getMinAndMax = function () {
var points = this.getPoints();
......@@ -426,7 +441,7 @@ THREE.Path.prototype.getPoint = function( t ) {
while ( i < curveLengths.length ) {
if ( curveLengths[ i ] >= d) {
if ( curveLengths[ i ] >= d ) {
diff = curveLengths[ i ] - d;
curve = this.curves[ i ];
......@@ -471,35 +486,40 @@ THREE.Path.prototype.getLength = function() {
};
// TODO: rewrite to use single Line object
// createPathGeometry by SolarCoordinates
/// Generate geometry from path points (for Line or ParticleSystem objects)
THREE.Path.prototype.createPointsGeometry = function( divisions ) {
/* Returns Object3D with line segments stored as children */
var pts = this.getPoints( divisions, true );
return this.createGeometry( pts );
THREE.Path.prototype.createPathGeometry = function( divisions, lineMaterial ) {
};
// Generate geometry from equidistance sampling along the path
var pts = this.getPoints( divisions );
THREE.Path.prototype.createSpacedPointsGeometry = function( divisions ) {
var segment, pathGeometry = new THREE.Object3D;
if ( !lineMaterial ) lineMaterial = new THREE.LineBasicMaterial( { color: 0x000000, opacity: 0.7 } );
var pts = this.getSpacedPoints( divisions, true );
return this.createGeometry( pts );
for( var i = 1; i < pts.length; i++ ) {
};
var pathSegment = new THREE.Geometry();
pathSegment.vertices.push( new THREE.Vertex( new THREE.Vector3( pts[i-1].x, pts[i-1].y, 0 ) ) );
pathSegment.vertices.push( new THREE.Vertex( new THREE.Vector3( pts[i].x, pts[i].y, 0) ) );
segment = new THREE.Line( pathSegment , lineMaterial );
pathGeometry.addChild(segment);
THREE.Path.prototype.createGeometry = function( points ) {
var geometry = new THREE.Geometry();
for( var i = 0; i < points.length; i ++ ) {
geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( points[ i ].x, points[ i ].y, 0 ) ) );
}
return pathGeometry;
return geometry;
};
// ALL THINGS BELOW TO BE REFACTORED
// QN: Transform final pts or transform ACTIONS or add transform filters?
......@@ -782,4 +802,4 @@ THREE.Path.prototype.toShapes = function() {
console.log("shape", shapes);
return shapes;
};
\ No newline at end of file
};
......@@ -19,26 +19,26 @@ THREE.Shape = function ( ) {
THREE.Shape.prototype = new THREE.Path();
THREE.Shape.prototype.constructor = THREE.Path;
/* Convenience method to return ExtrudeGeometry */
// Convenience method to return ExtrudeGeometry
THREE.Shape.prototype.extrude = function( options ) {
THREE.Shape.prototype.extrude = function ( options ) {
var extruded = new THREE.ExtrudeGeometry( this, options );
return extruded;
};
/* Return array of holes' getPoints() */
// Get points of holes
THREE.Shape.prototype.getHoles = function( spaced, divisions ) {
var getPoints = spaced ? 'getSpacedPoints' : 'getPoints';
THREE.Shape.prototype.getPointsHoles = function () {
var i, il = this.holes.length, holesPts = [];
for ( i = 0; i < il; i ++ ) {
holesPts[ i ] = this.holes[ i ][ getPoints ]( divisions ); // getSpacedPoints getPoints
holesPts[ i ] = this.holes[ i ].getPoints();
}
......@@ -46,24 +46,48 @@ THREE.Shape.prototype.getHoles = function( spaced, divisions ) {
};
/* Returns points of shape and holes
spaced, when true returns points spaced by regular distances
otherwise return keypoints based on segments paramater
*/
// Get points of holes (spaced by regular distance)
THREE.Shape.prototype.getSpacedPointsHoles = function () {
var i, il = this.holes.length, holesPts = [];
for ( i = 0; i < il; i ++ ) {
holesPts[ i ] = this.holes[ i ].getSpacedPoints();
}
return holesPts;
THREE.Shape.prototype.extractAllPoints = function( spaced, divisions ) {
};
var getPoints = spaced ? 'getSpacedPoints' : 'getPoints';
// Get points of shape and holes (keypoints based on segments parameter)
THREE.Shape.prototype.extractAllPoints = function () {
return {
shape: this[ getPoints ]( divisions ),
holes: this.getHoles( spaced, divisions )
shape: this.getPoints(),
holes: this.getPointsHoles()
};
};
// Get points of shape and holes (spaced by regular distance)
THREE.Shape.prototype.extractAllSpacedPoints = function () {
return {
shape: this.getSpacedPoints(),
holes: this.getSpacedPointsHoles()
};
};
/**************************************************************
* Utils
......@@ -75,7 +99,8 @@ THREE.Shape.Utils = {
contour - array of vector2 for contour
holes - array of array of vector2
*/
removeHoles: function( contour, holes ) {
removeHoles: function ( contour, holes ) {
var shape = contour.concat(); // work on this shape
var allpoints = shape.concat();
......@@ -266,7 +291,7 @@ THREE.Shape.Utils = {
},
triangulateShape: function( contour, holes ) {
triangulateShape: function ( contour, holes ) {
var shapeWithoutHoles = THREE.Shape.Utils.removeHoles( contour, holes );
......
......@@ -15,9 +15,9 @@
* weight: <string>, // font weight (normal, bold)
* style: <string>, // font style (normal, italics)
*
* bezelEnabled: <bool>, // turn on bezel
* bezelThickness: <float>, // how deep into text bezel goes
* bezelSize: <float>, // how far from text outline is bezel
* bevelEnabled: <bool>, // turn on bevel
* bevelThickness: <float>, // how deep into text bevel goes
* bevelSize: <float>, // how far from text outline is bevel
* }
*
* It uses techniques used in:
......@@ -76,9 +76,9 @@ THREE.TextGeometry.prototype.set = function ( text, parameters ) {
var weight = parameters.weight !== undefined ? parameters.weight : "normal";
var style = parameters.style !== undefined ? parameters.style : "normal";
var bezelThickness = parameters.bezelThickness !== undefined ? parameters.bezelThickness : 10;
var bezelSize = parameters.bezelSize !== undefined ? parameters.bezelSize : 8;
var bezelEnabled = parameters.bezelEnabled !== undefined ? parameters.bezelEnabled : false;
var bevelThickness = parameters.bevelThickness !== undefined ? parameters.bevelThickness : 10;
var bevelSize = parameters.bevelSize !== undefined ? parameters.bevelSize : 8;
var bevelEnabled = parameters.bevelEnabled !== undefined ? parameters.bevelEnabled : false;
THREE.FontUtils.size = size;
THREE.FontUtils.divisions = curveSegments;
......@@ -87,11 +87,7 @@ THREE.TextGeometry.prototype.set = function ( text, parameters ) {
THREE.FontUtils.weight = weight;
THREE.FontUtils.style = style;
THREE.FontUtils.bezelSize = bezelSize;
THREE.FontUtils.bevelSize = bevelSize;
};
......@@ -529,6 +525,7 @@ THREE.FontUtils = {
for ( i = 0; i < length; i++ ) {
var path = new THREE.Path();
var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
offset += ret.offset;
characterPts.push( ret.points );
......@@ -536,7 +533,6 @@ THREE.FontUtils = {
fontPaths.push( ret.path );
}
// get the width
......@@ -552,7 +548,7 @@ THREE.FontUtils = {
extract.contour = allPts;
extract.paths = fontPaths;
var bezelPoints = [];
var bevelPoints = [];
var centroids = [], forCentroids = [], expandOutwards = [], sum = new THREE.Vector2(), lastV;
......@@ -597,7 +593,7 @@ THREE.FontUtils = {
centroid = centroids[ p ];
dirV = pt.clone().subSelf( centroid );
adj = this.bezelSize / dirV.length();
adj = this.bevelSize / dirV.length();
if ( expandOutwards[ p ] ) {
......@@ -610,7 +606,7 @@ THREE.FontUtils = {
}
adj = dirV.multiplyScalar( adj ).addSelf( centroid );
bezelPoints.unshift( adj );
bevelPoints.unshift( adj );
if ( !lastV ) {
......@@ -634,12 +630,12 @@ THREE.FontUtils = {
for ( p = 0; p < allPts.length; p++ ) {
pt = allPts[ p ];
bezelPoints.push( new THREE.Vector2( pt.x + this.bezelSize, pt.y + this.bezelSize ) );
bevelPoints.push( new THREE.Vector2( pt.x + this.bevelSize, pt.y + this.bevelSize ) );
}
*/
extract.bezel = bezelPoints;
extract.bevel = bevelPoints;
return extract;
......@@ -715,7 +711,7 @@ THREE.FontUtils = {
extractGlyphPoints : function( c, face, scale, offset, path ) {
var pts = [];
var i, i2,
......@@ -932,10 +928,10 @@ THREE.FontUtils = {
result.push( contour[ b ] );
result.push( contour[ c ] );
*/
result.push( [ contour[ a ],
result.push( [ contour[ a ],
contour[ b ],
contour[ c ] ] );
vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
......
......@@ -27,7 +27,12 @@ THREE.Texture.prototype = {
clone: function () {
return new THREE.Texture( this.image, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter );
var clonedTexture = new THREE.Texture( this.image, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter );
clonedTexture.offset.copy( this.offset );
clonedTexture.repeat.copy( this.repeat );
return clonedTexture;
}
......
......@@ -142,7 +142,7 @@ THREE.CanvasRenderer = function ( parameters ) {
_clearRect.inflate( 1 );
_clearRect.minSelf( _clipRect );
if ( _clearColor.hex == 0x000000 && _clearOpacity == 0 ) {
if ( _clearOpacity == 0 ) {
_context.clearRect( _clearRect.getX(), _clearRect.getY(), _clearRect.getWidth(), _clearRect.getHeight() );
......@@ -151,7 +151,8 @@ THREE.CanvasRenderer = function ( parameters ) {
setBlending( THREE.NormalBlending );
setOpacity( 1 );
_context.fillStyle = 'rgba(' + Math.floor( _clearColor.r * 255 ) + ',' + Math.floor( _clearColor.g * 255 ) + ',' + Math.floor( _clearColor.b * 255 ) + ',' + _clearOpacity + ')';
_contextFillStyle = 'rgba(' + Math.floor( _clearColor.r * 255 ) + ',' + Math.floor( _clearColor.g * 255 ) + ',' + Math.floor( _clearColor.b * 255 ) + ',' + _clearOpacity + ')'
_context.fillStyle = _contextFillStyle;
_context.fillRect( _clearRect.getX(), _clearRect.getY(), _clearRect.getWidth(), _clearRect.getHeight() );
}
......
......@@ -2603,8 +2603,6 @@ THREE.WebGLRenderer = function ( parameters ) {
}
if ( material.morphTargets ) {
material.numSupportedMorphTargets = 0;
......@@ -2812,6 +2810,7 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl.uniform3fv( p_uniforms.directionalLightDirection, dirLight );
_gl.uniformMatrix4fv( p_uniforms.objectMatrix, false, object._objectMatrixArray );
_gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, _viewMatrixArray );
}
......@@ -2844,7 +2843,11 @@ THREE.WebGLRenderer = function ( parameters ) {
} else {
setupMorphTargets( material, geometryGroup, object );
if ( object.morphTargetBase ) {
setupMorphTargets( material, geometryGroup, object );
}
}
......@@ -3063,7 +3066,7 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ order[ m ] ] );
_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
object.__webglMorphTargetInfluences[ m ] = influences[ order[ m ]];
object.__webglMorphTargetInfluences[ m ] = influences[ order[ m ] ];
m ++;
}
......@@ -3765,6 +3768,7 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, _projectionMatrixArray );
_gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, _viewMatrixArray );
_gl.uniform3fv( p_uniforms.directionalLightDirection, dirLight );
}
......@@ -4985,6 +4989,17 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl.uniform4f( location, value.x, value.y, value.z, value.w );
} else if( type == "m4" ) {
if ( ! uniform._array ) {
uniform._array = new Float32Array( 16 );
}
value.flattenToArray( uniform._array );
_gl.uniformMatrix4fv( location, false, uniform._array );
} else if( type == "c" ) {
_gl.uniform3f( location, value.r, value.g, value.b );
......
......@@ -549,11 +549,18 @@ THREE.UniformsUtils = {
parameter_src = uniforms_src[ u ][ p ];
if ( parameter_src instanceof THREE.Color ||
parameter_src instanceof THREE.Vector2 ||
parameter_src instanceof THREE.Vector3 ||
parameter_src instanceof THREE.Vector4 ||
parameter_src instanceof THREE.Matrix4 ||
parameter_src instanceof THREE.Texture ) {
uniforms_dst[ u ][ p ] = parameter_src.clone();
} else if ( parameter_src instanceof Array ) {
uniforms_dst[ u ][ p ] = parameter_src.slice();
} else {
uniforms_dst[ u ][ p ] = parameter_src;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册