提交 8b06b211 编写于 作者: A alteredq

Merge remote-tracking branch 'remotes/mrdoob/dev' into editor-outliner-ui

Conflicts:
	editor/js/ui/Viewport.js
......@@ -65,6 +65,31 @@ This code creates a scene, then creates a camera, adds the camera and cube to th
### Change log ###
2012 10 15 - **r52** (379,442 KB, gzip: 94,126 KB)
* New node.js build system. ([gero3](http://github.com/gero3))
* Proper edge handling in `SubdivisionModifier`. ([zz85](http://github.com/zz85))
* Added `defines` parameter for adding preprocessor definitions to `ShaderMaterial`. ([alteredq](http://github.com/alteredq))
* Split `ShaderExtras` into single files (`BasicShader`, `BlendShader`, `ConvolutionShader`, ... ). ([mrdoob](http://github.com/mrdoob))
* Added `HueSaturationShader` and `BrightnessContrastShader`. ([tapio](http://github.com/tapio))
* Fixed `ColladaLoader` not loading sometimes. ([tapio](http://github.com/tapio))
* Added `material.vertexColors = THREE.FaceColor` support to `CanvasRenderer` and `SVGRenderer`. ([mrdoob](http://github.com/mrdoob))
* Added `Object3D.defaultEulerOrder`. ([mrdoob](http://github.com/mrdoob))
* Replaced `SceneUtils.traverseHierarchy` and `SceneUtils.showHierarchy` with `object.traverse`. ([mrdoob](http://github.com/mrdoob))
* Added `PointerLockControls`. ([mrdoob](http://github.com/mrdoob))
* Completed more [documentation](http://mrdoob.github.com/three.js/docs/) pages. ([sole](http://github.com/sole))
* Split `SceneUtils.cloneObject` into `*.clone()`. ([mrdoob](http://github.com/mrdoob))
* Simplified `AxisHelper`. ([mrdoob](http://github.com/mrdoob))
* Added `GeometryExporter`. ([mrdoob](http://github.com/mrdoob))
* Improved `OrbitControls`. ([WestLangley](http://github.com/WestLangley))
* Added `GeometryLibrary`, `MaterialLibrary`, `TextureLibrary` and `ObjectLibrary` (bear in mind that you can't rely on the GC now. Call `*.deallocate()` for removing). ([mrdoob](http://github.com/mrdoob))
* Moved `*Controls` out of the lib. ([mrdoob](http://github.com/mrdoob))
* Fixed shadows getting animated when skinning / morphing was disabled. ([alteredq](http://github.com/alteredq))
* Added `Manual` section to the [documentation](http://mrdoob.github.com/three.js/docs/) pages. ([oal](http://github.com/oal))
* Added `.angleTo()` to `Vector3`. ([Wilt](http://github.com/Wilt))
* Many improvements to the [editor](http://mrdoob.github.com/three.js/editor/). ([mrdoob](http://github.com/mrdoob) and [alteredq](http://github.com/alteredq))
2012 09 15 - **r51** (405,491 KB, gzip: 99,389 KB)
* Added `STLLoader`. ([aleeper](http://github.com/aleeper) and [mrdoob](http://github.com/mrdoob))
......
......@@ -3,7 +3,7 @@
* @author Larry Battle / http://bateru.com/news
*/
var THREE = THREE || { REVISION: '52dev' };
var THREE = THREE || { REVISION: '53dev' };
self.console = self.console || {
......@@ -886,6 +886,12 @@ THREE.Vector3.prototype = {
},
angleTo: function ( v ) {
return Math.acos( this.dot( v ) / this.length() / v.length() );
},
distanceTo: function ( v ) {
return Math.sqrt( this.distanceToSquared( v ) );
......@@ -29385,7 +29391,7 @@ THREE.CubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
* @author mrdoob / http://mrdoob.com/
*/
THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, segmentsRadius, segmentsHeight, openEnded ) {
THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded ) {
THREE.Geometry.call( this );
......@@ -29394,8 +29400,8 @@ THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, segmentsRad
height = height !== undefined ? height : 100;
var heightHalf = height / 2;
var segmentsX = segmentsRadius || 8;
var segmentsY = segmentsHeight || 1;
var segmentsX = radiusSegments || 8;
var segmentsY = heightSegments || 1;
var x, y, vertices = [], uvs = [];
......@@ -30471,15 +30477,15 @@ THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
* based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
*/
THREE.PlaneGeometry = function ( width, height, segmentsWidth, segmentsheight ) {
THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
THREE.Geometry.call( this );
var ix, iz,
width_half = width / 2,
height_half = height / 2,
gridX = segmentsWidth || 1,
gridZ = segmentsheight || 1,
gridX = widthSegments || 1,
gridZ = heightSegments || 1,
gridX1 = gridX + 1,
gridZ1 = gridZ + 1,
segment_width = width / gridX,
......@@ -30533,7 +30539,7 @@ THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
* @author mrdoob / http://mrdoob.com/
*/
THREE.SphereGeometry = function ( radius, segmentsWidth, segmentsHeight, phiStart, phiLength, thetaStart, thetaLength ) {
THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
THREE.Geometry.call( this );
......@@ -30545,8 +30551,8 @@ THREE.SphereGeometry = function ( radius, segmentsWidth, segmentsHeight, phiStar
thetaStart = thetaStart !== undefined ? thetaStart : 0;
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
var segmentsX = Math.max( 3, Math.floor( segmentsWidth ) || 8 );
var segmentsY = Math.max( 2, Math.floor( segmentsHeight ) || 6 );
var segmentsX = Math.max( 3, Math.floor( widthSegments ) || 8 );
var segmentsY = Math.max( 2, Math.floor( heightSegments ) || 6 );
var x, y, vertices = [], uvs = [];
......@@ -30688,7 +30694,7 @@ THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
* based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
*/
THREE.TorusGeometry = function ( radius, tube, segmentsR, segmentsT, arc ) {
THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
THREE.Geometry.call( this );
......@@ -30696,18 +30702,18 @@ THREE.TorusGeometry = function ( radius, tube, segmentsR, segmentsT, arc ) {
this.radius = radius || 100;
this.tube = tube || 40;
this.segmentsR = segmentsR || 8;
this.segmentsT = segmentsT || 6;
this.radialSegments = radialSegments || 8;
this.tubularSegments = tubularSegments || 6;
this.arc = arc || Math.PI * 2;
var center = new THREE.Vector3(), uvs = [], normals = [];
for ( var j = 0; j <= this.segmentsR; j ++ ) {
for ( var j = 0; j <= this.radialSegments; j ++ ) {
for ( var i = 0; i <= this.segmentsT; i ++ ) {
for ( var i = 0; i <= this.tubularSegments; i ++ ) {
var u = i / this.segmentsT * this.arc;
var v = j / this.segmentsR * Math.PI * 2;
var u = i / this.tubularSegments * this.arc;
var v = j / this.radialSegments * Math.PI * 2;
center.x = this.radius * Math.cos( u );
center.y = this.radius * Math.sin( u );
......@@ -30719,21 +30725,21 @@ THREE.TorusGeometry = function ( radius, tube, segmentsR, segmentsT, arc ) {
this.vertices.push( vertex );
uvs.push( new THREE.UV( i / this.segmentsT, j / this.segmentsR ) );
uvs.push( new THREE.UV( i / this.tubularSegments, j / this.radialSegments ) );
normals.push( vertex.clone().subSelf( center ).normalize() );
}
}
for ( var j = 1; j <= this.segmentsR; j ++ ) {
for ( var j = 1; j <= this.radialSegments; j ++ ) {
for ( var i = 1; i <= this.segmentsT; i ++ ) {
for ( var i = 1; i <= this.tubularSegments; i ++ ) {
var a = ( this.segmentsT + 1 ) * j + i - 1;
var b = ( this.segmentsT + 1 ) * ( j - 1 ) + i - 1;
var c = ( this.segmentsT + 1 ) * ( j - 1 ) + i;
var d = ( this.segmentsT + 1 ) * j + i;
var a = ( this.tubularSegments + 1 ) * j + i - 1;
var b = ( this.tubularSegments + 1 ) * ( j - 1 ) + i - 1;
var c = ( this.tubularSegments + 1 ) * ( j - 1 ) + i;
var d = ( this.tubularSegments + 1 ) * j + i;
var face = new THREE.Face4( a, b, c, d, [ normals[ a ], normals[ b ], normals[ c ], normals[ d ] ] );
face.normal.addSelf( normals[ a ] );
......@@ -30759,7 +30765,7 @@ THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
* based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
*/
THREE.TorusKnotGeometry = function ( radius, tube, segmentsR, segmentsT, p, q, heightScale ) {
THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
THREE.Geometry.call( this );
......@@ -30767,25 +30773,25 @@ THREE.TorusKnotGeometry = function ( radius, tube, segmentsR, segmentsT, p, q, h
this.radius = radius || 200;
this.tube = tube || 40;
this.segmentsR = segmentsR || 64;
this.segmentsT = segmentsT || 8;
this.radialSegments = radialSegments || 64;
this.tubularSegments = tubularSegments || 8;
this.p = p || 2;
this.q = q || 3;
this.heightScale = heightScale || 1;
this.grid = new Array(this.segmentsR);
this.grid = new Array(this.radialSegments);
var tang = new THREE.Vector3();
var n = new THREE.Vector3();
var bitan = new THREE.Vector3();
for ( var i = 0; i < this.segmentsR; ++ i ) {
for ( var i = 0; i < this.radialSegments; ++ i ) {
this.grid[ i ] = new Array( this.segmentsT );
this.grid[ i ] = new Array( this.tubularSegments );
for ( var j = 0; j < this.segmentsT; ++ j ) {
for ( var j = 0; j < this.tubularSegments; ++ j ) {
var u = i / this.segmentsR * 2 * this.p * Math.PI;
var v = j / this.segmentsT * 2 * Math.PI;
var u = i / this.radialSegments * 2 * this.p * Math.PI;
var v = j / this.tubularSegments * 2 * Math.PI;
var p1 = getPos( u, v, this.q, this.p, this.radius, this.heightScale );
var p2 = getPos( u + 0.01, v, this.q, this.p, this.radius, this.heightScale );
var cx, cy;
......@@ -30811,22 +30817,22 @@ THREE.TorusKnotGeometry = function ( radius, tube, segmentsR, segmentsT, p, q, h
}
for ( var i = 0; i < this.segmentsR; ++ i ) {
for ( var i = 0; i < this.radialSegments; ++ i ) {
for ( var j = 0; j < this.segmentsT; ++ j ) {
for ( var j = 0; j < this.tubularSegments; ++ j ) {
var ip = ( i + 1 ) % this.segmentsR;
var jp = ( j + 1 ) % this.segmentsT;
var ip = ( i + 1 ) % this.radialSegments;
var jp = ( j + 1 ) % this.tubularSegments;
var a = this.grid[ i ][ j ];
var b = this.grid[ ip ][ j ];
var c = this.grid[ ip ][ jp ];
var d = this.grid[ i ][ jp ];
var uva = new THREE.UV( i / this.segmentsR, j / this.segmentsT );
var uvb = new THREE.UV( ( i + 1 ) / this.segmentsR, j / this.segmentsT );
var uvc = new THREE.UV( ( i + 1 ) / this.segmentsR, ( j + 1 ) / this.segmentsT );
var uvd = new THREE.UV( i / this.segmentsR, ( j + 1 ) / this.segmentsT );
var uva = new THREE.UV( i / this.radialSegments, j / this.tubularSegments );
var uvb = new THREE.UV( ( i + 1 ) / this.radialSegments, j / this.tubularSegments );
var uvc = new THREE.UV( ( i + 1 ) / this.radialSegments, ( j + 1 ) / this.tubularSegments );
var uvd = new THREE.UV( i / this.radialSegments, ( j + 1 ) / this.tubularSegments );
this.faces.push( new THREE.Face4( a, b, c, d ) );
this.faceVertexUvs[ 0 ].push( [ uva,uvb,uvc, uvd ] );
......@@ -30876,14 +30882,14 @@ THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
* http://www.cs.indiana.edu/pub/techreports/TR425.pdf
*/
THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, debug ) {
THREE.TubeGeometry = function( path, segments, radius, radiusSegments, closed, debug ) {
THREE.Geometry.call( this );
this.path = path;
this.segments = segments || 64;
this.radius = radius || 1;
this.segmentsRadius = segmentsRadius || 8;
this.radiusSegments = radiusSegments || 8;
this.closed = closed || false;
if ( debug ) this.debug = new THREE.Object3D();
......@@ -30948,9 +30954,9 @@ THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, d
}
for ( j = 0; j < this.segmentsRadius; j++ ) {
for ( j = 0; j < this.radiusSegments; j++ ) {
v = j / this.segmentsRadius * 2 * Math.PI;
v = j / this.radiusSegments * 2 * Math.PI;
cx = -this.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
cy = this.radius * Math.sin( v );
......@@ -30970,20 +30976,20 @@ THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, d
for ( i = 0; i < this.segments; i++ ) {
for ( j = 0; j < this.segmentsRadius; j++ ) {
for ( j = 0; j < this.radiusSegments; j++ ) {
ip = ( closed ) ? (i + 1) % this.segments : i + 1;
jp = (j + 1) % this.segmentsRadius;
jp = (j + 1) % this.radiusSegments;
a = this.grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
b = this.grid[ ip ][ j ];
c = this.grid[ ip ][ jp ];
d = this.grid[ i ][ jp ];
uva = new THREE.UV( i / this.segments, j / this.segmentsRadius );
uvb = new THREE.UV( ( i + 1 ) / this.segments, j / this.segmentsRadius );
uvc = new THREE.UV( ( i + 1 ) / this.segments, ( j + 1 ) / this.segmentsRadius );
uvd = new THREE.UV( i / this.segments, ( j + 1 ) / this.segmentsRadius );
uva = new THREE.UV( i / this.segments, j / this.radiusSegments );
uvb = new THREE.UV( ( i + 1 ) / this.segments, j / this.radiusSegments );
uvc = new THREE.UV( ( i + 1 ) / this.segments, ( j + 1 ) / this.radiusSegments );
uvd = new THREE.UV( i / this.segments, ( j + 1 ) / this.radiusSegments );
this.faces.push( new THREE.Face4( a, b, c, d ) );
this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvc, uvd ] );
......@@ -31450,9 +31456,9 @@ THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
* Benchmark:
*
* Platform: CPU: P7350 @2.00GHz Engine: V8
*
*
* Num Vertices Time(ms)
*
*
* 10 1
* 20 3
* 30 19
......@@ -31487,21 +31493,21 @@ THREE.ConvexGeometry = function( vertices ) {
for ( var f = 0; f < faces.length; ) {
var face = faces[ f ];
// for each face, if the vertex can see it,
// then we try to add the face's edges into the hole.
if ( visible( face, vertex ) ) {
for ( var e = 0; e < 3; e++ ) {
var edge = [ face[ e ], face[ ( e + 1 ) % 3 ] ];
var boundary = true;
// remove duplicated edges.
for ( var h = 0; h < hole.length; h++ ) {
if ( equalEdge( hole[ h ], edge ) ) {
hole[ h ] = hole[ hole.length - 1 ];
hole.pop();
boundary = false;
......@@ -31522,9 +31528,9 @@ THREE.ConvexGeometry = function( vertices ) {
// remove faces[ f ]
faces[ f ] = faces[ faces.length - 1 ];
faces.pop();
} else { // not visible
f++;
}
......@@ -31564,7 +31570,7 @@ THREE.ConvexGeometry = function( vertices ) {
* Face normal
*/
function normal( va, vb, vc ) {
var cb = new THREE.Vector3();
var ab = new THREE.Vector3();
......@@ -31573,7 +31579,7 @@ THREE.ConvexGeometry = function( vertices ) {
cb.crossSelf( ab );
if ( !cb.isZero() ) {
cb.normalize();
}
......@@ -31588,7 +31594,7 @@ THREE.ConvexGeometry = function( vertices ) {
* be of the negative direction.
*/
function equalEdge( ea, eb ) {
return ea[ 0 ] === eb[ 1 ] && ea[ 1 ] === eb[ 0 ];
}
......@@ -31620,20 +31626,20 @@ THREE.ConvexGeometry = function( vertices ) {
for ( var i = 0; i < faces.length; i++ ) {
var face = faces[ i ];
for ( var j = 0; j < 3; j++ ) {
if ( newId[ face[ j ] ] === undefined ) {
newId[ face[ j ] ] = id++;
this.vertices.push( vertices[ face[ j ] ] );
}
face[ j ] = newId[ face[ j ] ];
}
}
}
// Convert faces into instances of THREE.Face3
......@@ -31649,7 +31655,7 @@ THREE.ConvexGeometry = function( vertices ) {
// Compute UVs
for ( var i = 0; i < this.faces.length; i++ ) {
var face = this.faces[ i ];
this.faceVertexUvs[ 0 ].push( [
......@@ -31659,7 +31665,7 @@ THREE.ConvexGeometry = function( vertices ) {
] );
}
this.computeCentroids();
this.computeFaceNormals();
......@@ -31995,89 +32001,88 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
/// REFACTORING THIS OUT
function orderedKey( a, b ) {
THREE.GeometryUtils.orderedKey = function ( a, b ) {
return Math.min( a, b ) + "_" + Math.max( a, b );
}
};
var G = {
// Returns a hashmap - of { edge_key: face_index }
THREE.GeometryUtils.computeEdgeFaces = function ( geometry ) {
// Returns a hashmap - of { edge_key: face_index }
computeEdgeFaces: function ( geometry ) {
var i, il, v1, v2, j, k,
face, faceIndices, faceIndex,
edge,
hash,
edgeFaceMap = {};
var i, il, v1, v2, j, k,
face, faceIndices, faceIndex,
edge,
hash,
edgeFaceMap = {};
var orderedKey = THREE.GeometryUtils.orderedKey;
function mapEdgeHash( hash, i ) {
if ( edgeFaceMap[ hash ] === undefined ) {
function mapEdgeHash( hash, i ) {
if ( edgeFaceMap[ hash ] === undefined ) {
edgeFaceMap[ hash ] = [];
}
edgeFaceMap[ hash ] = [];
edgeFaceMap[ hash ].push( i );
}
edgeFaceMap[ hash ].push( i );
}
// construct vertex -> face map
// construct vertex -> face map
for( i = 0, il = geometry.faces.length; i < il; i ++ ) {
for( i = 0, il = geometry.faces.length; i < il; i ++ ) {
face = geometry.faces[ i ];
face = geometry.faces[ i ];
if ( face instanceof THREE.Face3 ) {
if ( face instanceof THREE.Face3 ) {
hash = orderedKey( face.a, face.b );
mapEdgeHash( hash, i );
hash = orderedKey( face.a, face.b );
mapEdgeHash( hash, i );
hash = orderedKey( face.b, face.c );
mapEdgeHash( hash, i );
hash = orderedKey( face.b, face.c );
mapEdgeHash( hash, i );
hash = orderedKey( face.c, face.a );
mapEdgeHash( hash, i );
hash = orderedKey( face.c, face.a );
mapEdgeHash( hash, i );
} else if ( face instanceof THREE.Face4 ) {
} else if ( face instanceof THREE.Face4 ) {
hash = orderedKey( face.a, face.b );
mapEdgeHash( hash, i );
hash = orderedKey( face.a, face.b );
mapEdgeHash( hash, i );
hash = orderedKey( face.b, face.c );
mapEdgeHash( hash, i );
hash = orderedKey( face.b, face.c );
mapEdgeHash( hash, i );
hash = orderedKey( face.c, face.d );
mapEdgeHash( hash, i );
hash = orderedKey( face.d, face.a );
mapEdgeHash( hash, i );
}
hash = orderedKey( face.c, face.d );
mapEdgeHash( hash, i );
hash = orderedKey( face.d, face.a );
mapEdgeHash( hash, i );
}
// extract faces
// var edges = [];
//
// var numOfEdges = 0;
// for (i in edgeFaceMap) {
// numOfEdges++;
//
// edge = edgeFaceMap[i];
// edges.push(edge);
//
// }
//debug('edgeFaceMap', edgeFaceMap, 'geometry.edges',geometry.edges, 'numOfEdges', numOfEdges);
}
return edgeFaceMap;
// extract faces
// var edges = [];
//
// var numOfEdges = 0;
// for (i in edgeFaceMap) {
// numOfEdges++;
//
// edge = edgeFaceMap[i];
// edges.push(edge);
//
// }
//debug('edgeFaceMap', edgeFaceMap, 'geometry.edges',geometry.edges, 'numOfEdges', numOfEdges);
return edgeFaceMap;
}
}
/////////////////////////////
......@@ -32095,6 +32100,8 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
}
var scope = this;
var orderedKey = THREE.GeometryUtils.orderedKey;
var computeEdgeFaces = THREE.GeometryUtils.computeEdgeFaces;
function assert() {
if (scope.debug && console && console.assert) console.assert.apply(console, arguments);
......@@ -32288,7 +32295,7 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
// For each edge, add an edge point.
// Set each edge point to be the average of the two neighbouring face points and its two original endpoints.
var edgeFaceMap = G.computeEdgeFaces ( oldGeometry ); // Edge Hash -> Faces Index eg { edge_key: [face_index, face_index2 ]}
var edgeFaceMap = computeEdgeFaces ( oldGeometry ); // Edge Hash -> Faces Index eg { edge_key: [face_index, face_index2 ]}
var edge, faceIndexA, faceIndexB, avg;
// debug('edgeFaceMap', edgeFaceMap);
......@@ -32429,7 +32436,6 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
// Step 3
// For each face point, add an edge for every edge of the face,
// connecting the face point to each edge point for the face.
debugCoreStuff();
var facePt, currentVerticeIndex;
......@@ -33973,9 +33979,12 @@ THREE.SpritePlugin = function ( ) {
if ( sprite.useScreenCoordinates ) {
_gl.uniform1i( uniforms.useScreenCoordinates, 1 );
_gl.uniform3f( uniforms.screenPosition, ( sprite.position.x - halfViewportWidth ) / halfViewportWidth,
( halfViewportHeight - sprite.position.y ) / halfViewportHeight,
Math.max( 0, Math.min( 1, sprite.position.z ) ) );
_gl.uniform3f(
uniforms.screenPosition,
( sprite.position.x - halfViewportWidth ) / halfViewportWidth,
( halfViewportHeight - sprite.position.y ) / halfViewportHeight,
Math.max( 0, Math.min( 1, sprite.position.z ) )
);
} else {
......@@ -34057,7 +34066,8 @@ THREE.SpritePlugin = function ( ) {
};
};/**
};
/**
* @author alteredq / http://alteredqualia.com/
*/
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="../../../list.js"></script>
<script src="../../../page.js"></script>
<link type="text/css" rel="stylesheet" href="../../../page.css" />
</head>
<body>
<h1>[name]</h1>
<div class="desc">todo</div>
<h2>Constructor</h2>
<h3>[name]()</h3>
<h2>Properties</h2>
<h3>.[page:Vector3 todo]</h3>
<h2>Methods</h2>
<h3>.todo( [page:Vector3 todo] )</h3>
<div>
todo — todo<br />
</div>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</body>
</html>
......@@ -22,6 +22,7 @@
color: #555;
font-family: 'inconsolata';
font-size: 15px;
line-height: 18px;
overflow: hidden;
}
......@@ -43,15 +44,27 @@
}
#panel h1 {
color: #333;
margin-top: 20px;
margin-left: 20px;
font-size: 25px;
font-weight: normal;
}
margin-top: 25px;
margin-left: 20px;
#panel h1 a {
color: #444;
text-decoration: none;
}
#panel h2 {
color: #454545;
font-size: 18px;
font-weight: normal;
margin-top: 20px;
margin-left: 20px;
}
#panel h3 {
color: #666;
font-size: 16px;
font-weight: normal;
......@@ -84,24 +97,34 @@
<script src="list.js"></script>
<script>
var REVISION = '51';
var REVISION = '52';
var panel = document.getElementById( 'panel' );
var viewer = document.getElementById( 'viewer' );
var html = '<h1>three.js<span style="font-size: 50%; vertical-align: super;"> r' + REVISION + '</span></h1>';
var html = '<h1><a href="http://threejs.org">three.js</a><span style="font-size: 50%; vertical-align: super;"> r' + REVISION + '</span></h1>';
for ( var category in list ) {
for ( var section in list ) {
html += '<h2>' + category + '</h2>';
html += '<h2>' + section + '</h2>';
html += '<ul>';
for ( var i = 0; i < list[ category ].length; i ++ ) {
for ( var category in list[ section ] ) {
html += '<h3>' + category + '</h3>';
html += '<ul>';
for ( var i = 0; i < list[ section ][ category ].length; i ++ ) {
var page = list[ section ][ category ][ i ];
html += '<li><a href="javascript:goTo(\'' + section + '\', \'' + category + '\', \'' + page[ 0 ] + '\')">' + page[ 0 ] + '</a></li>';
var page = list[ category ][ i ];
}
html += '<li><a href="javascript:goTo(\'' + page[ 0 ] + '\')">' + page[ 0 ] + '</a></li>';
html += '</ul>';
}
......@@ -113,20 +136,20 @@
// Page loading
function goTo( name ) {
function goTo( section, category, name ) {
var path = pages[ name ];
window.document.title = 'three.js - documentation - ' + section + ' - ' + name;
window.document.title = 'three.js - documentation - ' + name;
window.location.hash = section + '/' + category + '/' + name.replace(/\ /g, '-');
window.location.hash = name;
viewer.src = 'api/' + path + '.html';
viewer.src = pages[ section ][ category ][ name ] + '.html';
}
function goToHash() {
goTo( window.location.hash.substring( 1 ) );
var hash = window.location.hash.substring( 1 ).split('/');
goTo( hash[0], hash[1], hash[2].replace(/\-/g, ' ') );
}
......
var list = {
"Cameras": [
[ "Camera", "cameras/Camera" ],
[ "OrthographicCamera", "cameras/OrthographicCamera" ],
[ "PerspectiveCamera", "cameras/PerspectiveCamera" ]
],
"Core": [
[ "Clock", "core/Clock" ],
[ "Color", "core/Color" ],
[ "Face3", "core/Face3" ],
[ "Face4", "core/Face4" ],
[ "Frustum", "core/Frustum" ],
[ "Geometry", "core/Geometry" ],
[ "Math", "core/Math" ],
[ "Matrix3", "core/Matrix3" ],
[ "Matrix4", "core/Matrix4" ],
[ "Object3D", "core/Object3D" ],
[ "Projector", "core/Projector" ],
[ "Quaternion", "core/Quaternion" ],
[ "Ray", "core/Ray" ],
[ "Rectangle", "core/Rectangle" ],
[ "Spline", "core/Spline" ],
[ "UV", "core/UV" ],
[ "Vector2", "core/Vector2" ],
[ "Vector3", "core/Vector3" ],
[ "Vector4", "core/Vector4" ]
],
"Lights": [
[ "Light", "lights/Light" ],
[ "AmbientLight", "lights/AmbientLight" ],
[ "DirectionalLight", "lights/DirectionalLight" ],
[ "PointLight", "lights/PointLight" ],
[ "SpotLight", "lights/SpotLight" ]
],
"Loaders": [
[ "Loader", "loaders/Loader" ],
[ "BinaryLoader", "loaders/BinaryLoader" ],
[ "GeometryLoader", "loaders/GeometryLoader" ],
[ "ImageLoader", "loaders/ImageLoader" ],
[ "JSONLoader", "loaders/JSONLoader" ],
[ "LoadingMonitor", "loaders/LoadingMonitor" ],
[ "SceneLoader", "loaders/SceneLoader" ],
[ "TextureLoader", "loaders/TextureLoader" ],
],
"Materials": [
[ "Material", "materials/Material" ],
[ "LineBasicMaterial", "materials/LineBasicMaterial" ],
[ "MeshBasicMaterial", "materials/MeshBasicMaterial" ],
[ "MeshDepthMaterial", "materials/MeshDepthMaterial" ],
[ "MeshFaceMaterial", "materials/MeshFaceMaterial" ],
[ "MeshLambertMaterial", "materials/MeshLambertMaterial" ],
[ "MeshNormalMaterial", "materials/MeshNormalMaterial" ],
[ "MeshPhongMaterial", "materials/MeshPhongMaterial" ],
[ "ParticleBasicMaterial", "materials/ParticleBasicMaterial" ],
[ "ParticleCanvasMaterial", "materials/ParticleCanvasMaterial" ],
[ "ParticleDOMMaterial", "materials/ParticleDOMMaterial" ],
[ "ShaderMaterial", "materials/ShaderMaterial" ]
],
"Objects": [
[ "Bone", "objects/Bone" ],
[ "Line", "objects/Line" ],
[ "LOD", "objects/LOD" ],
[ "Mesh", "objects/Mesh" ],
[ "MorphAnimMesh", "objects/MorphAnimMesh" ],
[ "Particle", "objects/Particle" ],
[ "ParticleSystem", "objects/ParticleSystem" ],
[ "Ribbon", "objects/Ribbon" ],
[ "SkinnedMesh", "objects/SkinnedMesh" ],
[ "Sprite", "objects/Sprite" ]
],
"Renderers": [
[ "CanvasRenderer", "renderers/CanvasRenderer" ],
[ "DOMRenderer", "renderers/DOMRenderer" ],
[ "SVGRenderer", "renderers/SVGRenderer" ],
[ "WebGLRenderer", "renderers/WebGLRenderer" ],
[ "WebGLRenderTarget", "renderers/WebGLRenderTarget" ],
[ "WebGLRenderTargetCube", "renderers/WebGLRenderTargetCube" ],
[ "WebGLShaders", "renderers/WebGLShaders" ]
],
"Renderers / Renderables": [
[ "RenderableFace3", "renderers/renderables/RenderableFace3" ],
[ "RenderableFace4", "renderers/renderables/RenderableFace4" ],
[ "RenderableLine", "renderers/renderables/RenderableLine" ],
[ "RenderableObject", "renderers/renderables/RenderableObject" ],
[ "RenderableParticle", "renderers/renderables/RenderableParticle" ],
[ "RenderableVertex", "renderers/renderables/RenderableVertex" ]
],
"Scenes": [
[ "Fog", "scenes/Fog" ],
[ "FogExp2", "scenes/FogExp2" ],
[ "Scene", "scenes/Scene" ]
],
"Textures": [
[ "DataTexture", "textures/DataTexture" ],
[ "Texture", "textures/Texture" ]
],
"Extras": [
[ "ColorUtils", "extras/ColorUtils" ],
[ "GeometryUtils", "extras/GeometryUtils" ],
[ "ImageUtils", "extras/ImageUtils" ],
[ "SceneUtils", "extras/SceneUtils" ],
[ "ShaderUtils", "extras/ShaderUtils" ]
],
"Extras / Animation": [
[ "Animation", "extras/animation/Animation" ],
[ "AnimationHandler", "extras/animation/AnimationHandler" ],
[ "AnimationMorphTarget", "extras/animation/AnimationMorphTarget" ],
[ "KeyFrameAnimation", "extras/animation/KeyFrameAnimation" ]
],
"Extras / Cameras": [
[ "CombinedCamera", "extras/cameras/CombinedCamera" ],
[ "CubeCamera", "extras/cameras/CubeCamera" ]
],
"Extras / Controls": [
[ "FirstPersonControls", "extras/controls/FirstPersonControls" ],
[ "FlyControls", "extras/controls/FlyControls" ],
[ "PathControls", "extras/controls/PathControls" ],
[ "RollControls", "extras/controls/RollControls" ],
[ "TrackballControls", "extras/controls/TrackballControls" ]
],
"Extras / Core": [
[ "BufferGeometry", "extras/core/BufferGeometry" ],
[ "Curve", "extras/core/Curve" ],
[ "CurvePath", "extras/core/CurvePath" ],
[ "EventTarget", "extras/core/EventTarget" ],
[ "Gyroscope", "extras/core/Gyroscope" ],
[ "Path", "extras/core/Path" ],
[ "Shape", "extras/core/Shape" ],
[ "TextPath", "extras/core/TextPath" ]
],
"Extras / Geometries": [
[ "CubeGeometry", "extras/geometries/CubeGeometry" ],
[ "CylinderGeometry", "extras/geometries/CylinderGeometry" ],
[ "ExtrudeGeometry", "extras/geometries/ExtrudeGeometry" ],
[ "IcosahedronGeometry", "extras/geometries/IcosahedronGeometry" ],
[ "LatheGeometry", "extras/geometries/LatheGeometry" ],
[ "OctahedronGeometry", "extras/geometries/OctahedronGeometry" ],
[ "PlaneGeometry", "extras/geometries/PlaneGeometry" ],
[ "PolyhedronGeometry", "extras/geometries/PolyhedronGeometry" ],
[ "SphereGeometry", "extras/geometries/SphereGeometry" ],
[ "TetrahedronGeometry", "extras/geometries/TetrahedronGeometry" ],
[ "TextGeometry", "extras/geometries/TextGeometry" ],
[ "TorusGeometry", "extras/geometries/TorusGeometry" ],
[ "TorusKnotGeometry", "extras/geometries/TorusKnotGeometry" ]
],
"Extras / Helpers": [
[ "AxisHelper", "extras/helpers/AxisHelper" ],
[ "CameraHelper", "extras/helpers/CameraHelper" ]
],
"Extras / Modifiers": [
[ "SubdivisionModifier", "extras/modifiers/SubdivisionModifier" ]
],
"Extras / Objects": [
[ "LensFlare", "extras/objects/LensFlare" ],
[ "MarchingCubes", "extras/objects/MarchingCubes" ]
],
"Extras / Renderers / Effects": [
[ "AnaglyphEffect", "extras/renderers/effects/AnaglyphEffect" ],
[ "CrosseyedEffect", "extras/renderers/effects/CrosseyedEffect" ],
[ "ParallaxBarrierEffect", "extras/renderers/effects/ParallaxBarrierEffect" ],
[ "StereoEffect", "extras/renderers/effects/StereoEffect" ]
],
"Extras / Renderers / Plugins": [
[ "LensFlarePlugin", "extras/renderers/plugins/LensFlarePlugin" ],
[ "ShadowMapPlugin", "extras/renderers/plugins/ShadowMapPlugin" ],
[ "SpritePlugin", "extras/renderers/plugins/SpritePlugin" ]
],
"Extras / Shaders": [
[ "ShaderFlares", "extras/shaders/ShaderFlares" ],
[ "ShaderSprite", "extras/shaders/ShaderSprite" ]
]
"Manual": {
"Introduction": [
[ "Creating a scene", "manual/introduction/Creating-a-scene" ]
]
},
"Reference": {
"Cameras": [
[ "Camera", "api/cameras/Camera" ],
[ "OrthographicCamera", "api/cameras/OrthographicCamera" ],
[ "PerspectiveCamera", "api/cameras/PerspectiveCamera" ]
],
"Core": [
[ "Clock", "api/core/Clock" ],
[ "Color", "api/core/Color" ],
[ "Face3", "api/core/Face3" ],
[ "Face4", "api/core/Face4" ],
[ "Frustum", "api/core/Frustum" ],
[ "Geometry", "api/core/Geometry" ],
[ "Math", "api/core/Math" ],
[ "Matrix3", "api/core/Matrix3" ],
[ "Matrix4", "api/core/Matrix4" ],
[ "Object3D", "api/core/Object3D" ],
[ "Projector", "api/core/Projector" ],
[ "Quaternion", "api/core/Quaternion" ],
[ "Ray", "api/core/Ray" ],
[ "Rectangle", "api/core/Rectangle" ],
[ "Spline", "api/core/Spline" ],
[ "UV", "api/core/UV" ],
[ "Vector2", "api/core/Vector2" ],
[ "Vector3", "api/core/Vector3" ],
[ "Vector4", "api/core/Vector4" ]
],
"Lights": [
[ "Light", "api/lights/Light" ],
[ "AmbientLight", "api/lights/AmbientLight" ],
[ "DirectionalLight", "api/lights/DirectionalLight" ],
[ "PointLight", "api/lights/PointLight" ],
[ "SpotLight", "api/lights/SpotLight" ]
],
"Loaders": [
[ "Loader", "api/loaders/Loader" ],
[ "BinaryLoader", "api/loaders/BinaryLoader" ],
[ "GeometryLoader", "api/loaders/GeometryLoader" ],
[ "ImageLoader", "api/loaders/ImageLoader" ],
[ "JSONLoader", "api/loaders/JSONLoader" ],
[ "LoadingMonitor", "api/loaders/LoadingMonitor" ],
[ "SceneLoader", "api/loaders/SceneLoader" ],
[ "TextureLoader", "api/loaders/TextureLoader" ],
],
"Materials": [
[ "Material", "api/materials/Material" ],
[ "LineBasicMaterial", "api/materials/LineBasicMaterial" ],
[ "MeshBasicMaterial", "api/materials/MeshBasicMaterial" ],
[ "MeshDepthMaterial", "api/materials/MeshDepthMaterial" ],
[ "MeshFaceMaterial", "api/materials/MeshFaceMaterial" ],
[ "MeshLambertMaterial", "api/materials/MeshLambertMaterial" ],
[ "MeshNormalMaterial", "api/materials/MeshNormalMaterial" ],
[ "MeshPhongMaterial", "api/materials/MeshPhongMaterial" ],
[ "ParticleBasicMaterial", "api/materials/ParticleBasicMaterial" ],
[ "ParticleCanvasMaterial", "api/materials/ParticleCanvasMaterial" ],
[ "ParticleDOMMaterial", "api/materials/ParticleDOMMaterial" ],
[ "ShaderMaterial", "api/materials/ShaderMaterial" ]
],
"Objects": [
[ "Bone", "api/objects/Bone" ],
[ "Line", "api/objects/Line" ],
[ "LOD", "api/objects/LOD" ],
[ "Mesh", "api/objects/Mesh" ],
[ "MorphAnimMesh", "api/objects/MorphAnimMesh" ],
[ "Particle", "api/objects/Particle" ],
[ "ParticleSystem", "api/objects/ParticleSystem" ],
[ "Ribbon", "api/objects/Ribbon" ],
[ "SkinnedMesh", "api/objects/SkinnedMesh" ],
[ "Sprite", "api/objects/Sprite" ]
],
"Renderers": [
[ "CanvasRenderer", "api/renderers/CanvasRenderer" ],
[ "DOMRenderer", "api/renderers/DOMRenderer" ],
[ "SVGRenderer", "api/renderers/SVGRenderer" ],
[ "WebGLRenderer", "api/renderers/WebGLRenderer" ],
[ "WebGLRenderTarget", "api/renderers/WebGLRenderTarget" ],
[ "WebGLRenderTargetCube", "api/renderers/WebGLRenderTargetCube" ],
[ "WebGLShaders", "api/renderers/WebGLShaders" ]
],
"Renderers / Renderables": [
[ "RenderableFace3", "api/renderers/renderables/RenderableFace3" ],
[ "RenderableFace4", "api/renderers/renderables/RenderableFace4" ],
[ "RenderableLine", "api/renderers/renderables/RenderableLine" ],
[ "RenderableObject", "api/renderers/renderables/RenderableObject" ],
[ "RenderableParticle", "api/renderers/renderables/RenderableParticle" ],
[ "RenderableVertex", "api/renderers/renderables/RenderableVertex" ]
],
"Scenes": [
[ "Fog", "api/scenes/Fog" ],
[ "FogExp2", "api/scenes/FogExp2" ],
[ "Scene", "api/scenes/Scene" ]
],
"Textures": [
[ "DataTexture", "api/textures/DataTexture" ],
[ "Texture", "api/textures/Texture" ]
],
"Extras": [
[ "ColorUtils", "api/extras/ColorUtils" ],
[ "GeometryUtils", "api/extras/GeometryUtils" ],
[ "ImageUtils", "api/extras/ImageUtils" ],
[ "SceneUtils", "api/extras/SceneUtils" ],
[ "ShaderUtils", "api/extras/ShaderUtils" ]
],
"Extras / Animation": [
[ "Animation", "api/extras/animation/Animation" ],
[ "AnimationHandler", "api/extras/animation/AnimationHandler" ],
[ "AnimationMorphTarget", "api/extras/animation/AnimationMorphTarget" ],
[ "KeyFrameAnimation", "api/extras/animation/KeyFrameAnimation" ]
],
"Extras / Cameras": [
[ "CombinedCamera", "api/extras/cameras/CombinedCamera" ],
[ "CubeCamera", "api/extras/cameras/CubeCamera" ]
],
"Extras / Controls": [
[ "FirstPersonControls", "api/extras/controls/FirstPersonControls" ],
[ "FlyControls", "api/extras/controls/FlyControls" ],
[ "PathControls", "api/extras/controls/PathControls" ],
[ "RollControls", "api/extras/controls/RollControls" ],
[ "TrackballControls", "api/extras/controls/TrackballControls" ]
],
"Extras / Core": [
[ "BufferGeometry", "api/extras/core/BufferGeometry" ],
[ "Curve", "api/extras/core/Curve" ],
[ "CurvePath", "api/extras/core/CurvePath" ],
[ "EventTarget", "api/extras/core/EventTarget" ],
[ "Gyroscope", "api/extras/core/Gyroscope" ],
[ "Path", "api/extras/core/Path" ],
[ "Shape", "api/extras/core/Shape" ],
[ "TextPath", "api/extras/core/TextPath" ]
],
"Extras / Geometries": [
[ "CubeGeometry", "api/extras/geometries/CubeGeometry" ],
[ "CylinderGeometry", "api/extras/geometries/CylinderGeometry" ],
[ "ExtrudeGeometry", "api/extras/geometries/ExtrudeGeometry" ],
[ "IcosahedronGeometry", "api/extras/geometries/IcosahedronGeometry" ],
[ "LatheGeometry", "api/extras/geometries/LatheGeometry" ],
[ "OctahedronGeometry", "api/extras/geometries/OctahedronGeometry" ],
[ "PlaneGeometry", "api/extras/geometries/PlaneGeometry" ],
[ "PolyhedronGeometry", "api/extras/geometries/PolyhedronGeometry" ],
[ "SphereGeometry", "api/extras/geometries/SphereGeometry" ],
[ "TetrahedronGeometry", "api/extras/geometries/TetrahedronGeometry" ],
[ "TextGeometry", "api/extras/geometries/TextGeometry" ],
[ "TorusGeometry", "api/extras/geometries/TorusGeometry" ],
[ "TorusKnotGeometry", "api/extras/geometries/TorusKnotGeometry" ]
],
"Extras / Helpers": [
[ "AxisHelper", "api/extras/helpers/AxisHelper" ],
[ "CameraHelper", "api/extras/helpers/CameraHelper" ]
],
"Extras / Modifiers": [
[ "SubdivisionModifier", "api/extras/modifiers/SubdivisionModifier" ]
],
"Extras / Objects": [
[ "LensFlare", "api/extras/objects/LensFlare" ]
],
"Extras / Renderers / Effects": [
[ "AnaglyphEffect", "api/extras/renderers/effects/AnaglyphEffect" ],
[ "CrosseyedEffect", "api/extras/renderers/effects/CrosseyedEffect" ],
[ "ParallaxBarrierEffect", "api/extras/renderers/effects/ParallaxBarrierEffect" ],
[ "StereoEffect", "api/extras/renderers/effects/StereoEffect" ]
],
"Extras / Renderers / Plugins": [
[ "LensFlarePlugin", "api/extras/renderers/plugins/LensFlarePlugin" ],
[ "ShadowMapPlugin", "api/extras/renderers/plugins/ShadowMapPlugin" ],
[ "SpritePlugin", "api/extras/renderers/plugins/SpritePlugin" ]
],
"Extras / Shaders": [
[ "ShaderFlares", "api/extras/shaders/ShaderFlares" ],
[ "ShaderSprite", "api/extras/shaders/ShaderSprite" ]
]
}
};
var pages = {};
for ( var category in list ) {
for ( var section in list ) {
pages[ section ] = {};
for ( var category in list[ section ] ) {
pages[ section ][ category ] = {};
for ( var i = 0; i < list[ section ][ category ].length; i ++ ) {
for ( var i = 0; i < list[ category ].length; i ++ ) {
var page = list[ section ][ category ][ i ];
pages[ section ][ category ][ page[ 0 ] ] = page[ 1 ];
var page = list[ category ][ i ];
pages[ page[ 0 ] ] = page[ 1 ];
}
}
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="../../list.js"></script>
<script src="../../page.js"></script>
<link type="text/css" rel="stylesheet" href="../../page.css" />
</head>
<body>
<h1>[name]</h1>
<div>The goal of this section is to give a brief introduction to Three.js. We will start by setting up a scene, with a spinning cube. A working example is provided at the bottom of the page, if you get stuck, and need help.</div>
<h2>What is Three.js</h2>
<div>If you're reading this, you probably have some understanding of what Three.js is, and what it helps you with, but let's try to describe it briefly anyway.</div>
<div>Three.js is a a library that makes WebGL - 3D in the browser - very easy. While a simple cube in raw WebGL would turn out hundreds of lines of Javascript and shader code, a Three.js equivalent is only a fraction of that.</div>
<h2>Before we start</h2>
<div>Before you can use Three.js, you need somewhere to display it. Save the following HTML to a file on your computer, and open it in your browser.</div>
<code>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My first Three.js app&lt;/title&gt;
&lt;style&gt;canvas { width: 100%; height: 100% }&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script src="https://raw.github.com/mrdoob/three.js/master/build/three.js"&gt;&lt;/script&gt;
&lt;script&gt;
// Our Javascript will go here.
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code>
<div>That's all. All the code below goes into the empty &lt;script&gt; tag.</div>
<h2>Creating the scene</h2>
<div>To actually be able to display anything with Three.js, we need three things: A scene, a camera, and a renderer so we can render the scene with the camera.</div>
<code>var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
</code>
<div>Let's take a moment to explain what's going on here. We have now set up the scene, our camera and the renderer. There are a few different cameras in Three.js, but we'll go more into that later. For now, let's use a PerspectiveCamera. The first attribute is the <strong>field of view</strong>.</div>
<div>The second one is the <strong>aspect ratio</strong>. You almost always want to use the width of the element divided by the height, or you'll get the same result as when you play old movies on a widescreen TV - the image looks squished.</div>
<div>The next two attributes are the <strong>near</strong> and <strong>far</strong> clipping plane. What that means, is that objects further away from the camera than the value of <strong>far</strong> or closer than <strong>near</strong> won't be rendered. You don't have to worry about this now, but you may want to use other values in your games, to get better performance.</div>
<div>Next up is the renderer. This is where the magic happens. In addition to the WebGLRenderer we use here, Three.js comes with a few others, often used as fallbacks for users with older browsers or for some reason don't have WebGL support.</div>
<div>In addition to creating the renderer instance, we also need to set the size at which we want it to render our app. It's a good idea to use the width and height of the are we want to fill with our game - in this case, the width and height of the browser window. For performance intensive games, you can also give <strong>setSize</strong> smaller values, like <strong>window.innerWidth/2</strong> and <strong>window.innerHeight/2</strong>, for half the resolution. This does not mean that the game will only fill half the window, but rather look a bit blurry and scaled up.</div>
<div>Last but not least, we add the <strong>renderer</strong> element to our HTML document. This is a &lt;canvas&gt; element the renderer uses to display the scene to us.</div>
<div><em>"That's all good, but where's that cube you promised?"</em> Let's add it now.</div>
<code>var geometry = new THREE.CubeGeometry(1,1,1);
var material = new THREE.MeshBasicMaterial({color: 0x00ff00});
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
</code>
<div>To create a cube, we need a <strong>CubeGeometry</strong>. This is an object that contains all the points (<strong>vertices</strong>) and fill (<strong>faces</strong>) of the cube. We'll explore this more in the future.</div>
<div>In addition to the geometry, we need a material to color it. Three.js comes with several materials, but we'll stick to the <strong>MeshBasicMateria</strong> for now. All materials take an object of properties which will be applied to them. To keep things very simple, we only supply a color attribute of <strong>0x00ff00</strong>, which is green. This works the same way that colors work in CSS or Photoshop (<strong>hex colors</strong>).</div>
<div>The third thing we need is a <strong>Mesh</strong>. A mesh is an object that takes a geometry, and applies a material to it, which we then can insert to our scene, and move freely around.</div>
<div>By default, when we call <strong>scene.add()</strong>, the thing we add will be added to the coordinates <strong>(0,0,0)</strong>. This would cause both the camera and the cube to be inside each other. To avoid this, we simply move the camera out a bit.</div>
<h2>Rendering the scene</h2>
<div>If you copied the code from above into the HTML file we created earlier, you wouldn't be able to see anything. This is because we're not actually rendering anything yet. For that, we need what's called a <strong>render loop</strong>.</div>
<code>function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
render();
</code>
<div>This will create a loop that causes the renderer to draw the scene 60 times per second. If you're new to writing games in the browser, you might say "why don't we just create a <strong>setInterval</strong>? The thing is - we could, but <strong>requestAnimationFrame</strong> has a number of advantages. Perhaps the most important one is that it pauses when the user navigates to another browser tab, hence not wasting their precious processing power and battery life.</div>
<h2>Animating the cube</h2>
<div>If you insert all the code above into the file you created before we began, you should see a green box. Let's make it all a little more interesting by rotating it.</div>
<div>Add the following right above the <strong>renderer.render</strong> call in your <strong>render</strong> function:</div>
<code>cube.rotation.x += 0.1;
cube.rotation.y += 0.1;</code>
<div>This will be run every frame (60 times per second), and give the cube a nice rotation animation. Basically anything you want to move or change while the game / app is running, has to go through the render loop. You can of course call other functions from there, so that you don't end up with a <strong>render</strong> function that's hundreds of lines.
</div>
<h2>The result</h2>
<div>Congratulations! You have now completed your first Three.js application. It's simple, you have to start somewhere.</div>
<div>The full code is available below. Play around with it to get a better understanding of how it works.</div>
<code>&lthtml&gt
&lthead&gt
&lttitle&gtMy first Three.js app&lt/title&gt
&ltstyle&gtcanvas { width: 100%; height: 100% }&lt/style&gt
&lt/head&gt
&ltbody&gt
&ltscript src="https://raw.github.com/mrdoob/three.js/master/build/three.js"&gt&lt/script&gt
&ltscript&gt
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var geometry = new THREE.CubeGeometry(1,1,1);
var material = new THREE.MeshBasicMaterial({color: 0x00ff00});
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
function render() {
requestAnimationFrame(render);
cube.rotation.x += 0.1;
cube.rotation.y += 0.1;
renderer.render(scene, camera);
}
render();
&lt/script&gt
&lt/body&gt
&lt/html&gt
</code>
</body>
</html>
......@@ -10,6 +10,7 @@ body {
color: #555;
font-family: 'inconsolata';
font-size: 15px;
line-height: 18px;
overflow: auto;
}
......@@ -42,7 +43,7 @@ h3 {
}
div {
padding-left: 30px;
/* padding-left: 30px; */
margin-bottom: 20px;
}
......
var onDocumentLoad = function ( event ) {
var name = /[A-z0-9]+\.html/.exec( window.location.pathname ).toString().split( '.html' )[ 0 ];
var path = /\/api\/[A-z0-9\/]+/.exec( window.location.pathname ).toString().substr( 5 );
var path;
var section = /\/(manual|api)\//.exec( window.location.pathname )[ 1 ].toString().split( '.html' )[ 0 ];
var name = /[\-A-z0-9]+\.html/.exec( window.location.pathname ).toString().split( '.html' )[ 0 ];
if ( section == 'manual' ) {
name = name.replace(/\-/g, ' ');
path = window.location.pathname.replace( /\ /g, '-' );
path = /\/manual\/[-a-z0-9\/]+/.exec( path ).toString().substr( 8 );
} else {
path = /\/api\/[A-z0-9\/]+/.exec( window.location.pathname ).toString().substr( 5 );
}
var text = document.body.innerHTML;
......@@ -23,7 +37,7 @@ var onDocumentLoad = function ( event ) {
button.addEventListener( 'click', function ( event ) {
window.open( 'https://github.com/mrdoob/three.js/blob/dev/docs/api/' + path + '.html' );
window.open( 'https://github.com/mrdoob/three.js/blob/dev/docs/' + section + '/' + path + '.html' );
}, false );
......
......@@ -218,11 +218,15 @@ UI.Panel = function ( position ) {
UI.Element.call( this );
this.dom = document.createElement( 'div' );
this.dom.style.position = position || 'relative';
this.dom.style.marginBottom = '10px';
var dom = document.createElement( 'div' );
dom.style.position = position || 'relative';
dom.style.marginBottom = '10px';
// this.dom.addEventListener( 'mousedown', function ( event ) { event.preventDefault() }, false );
dom.style.userSelect = 'none';
dom.style.WebkitUserSelect = 'none';
dom.style.MozUserSelect = 'none';
this.dom = dom;
return this;
};
......@@ -248,8 +252,10 @@ UI.Text = function ( position ) {
UI.Element.call( this );
this.dom = document.createElement( 'span' );
this.dom.style.position = position || 'relative';
var dom = document.createElement( 'span' );
dom.style.position = position || 'relative';
this.dom = dom;
return this;
......@@ -274,10 +280,12 @@ UI.Input = function ( position ) {
var scope = this;
this.dom = document.createElement( 'input' );
this.dom.style.position = position || 'relative';
this.dom.style.marginTop = '-2px';
this.dom.style.marginLeft = '-2px';
var dom = document.createElement( 'input' );
dom.style.position = position || 'relative';
dom.style.marginTop = '-2px';
dom.style.marginLeft = '-2px';
this.dom = dom;
this.onChangeCallback = null;
......@@ -324,12 +332,14 @@ UI.Select = function ( position ) {
var scope = this;
this.dom = document.createElement( 'select' );
this.dom.style.position = position || 'relative';
this.dom.style.width = '64px';
this.dom.style.height = '16px';
this.dom.style.border = '0px';
this.dom.style.padding = '0px';
var dom = document.createElement( 'select' );
dom.style.position = position || 'relative';
dom.style.width = '64px';
dom.style.height = '16px';
dom.style.border = '0px';
dom.style.padding = '0px';
this.dom = dom;
this.onChangeCallback = null;
......@@ -518,9 +528,11 @@ UI.Checkbox = function ( position ) {
var scope = this;
this.dom = document.createElement( 'input' );
this.dom.type = 'checkbox';
this.dom.style.position = position || 'relative';
var dom = document.createElement( 'input' );
dom.type = 'checkbox';
dom.style.position = position || 'relative';
this.dom = dom;
this.onChangeCallback = null;
......@@ -567,14 +579,16 @@ UI.Color = function ( position ) {
var scope = this;
this.dom = document.createElement( 'input' );
this.dom.type = 'color';
this.dom.style.position = position || 'relative';
this.dom.style.width = '64px';
this.dom.style.height = '16px';
this.dom.style.border = '0px';
this.dom.style.padding = '0px';
this.dom.style.backgroundColor = 'transparent';
var dom = document.createElement( 'input' );
dom.type = 'color';
dom.style.position = position || 'relative';
dom.style.width = '64px';
dom.style.height = '16px';
dom.style.border = '0px';
dom.style.padding = '0px';
dom.style.backgroundColor = 'transparent';
this.dom = dom;
this.onChangeCallback = null;
......@@ -621,23 +635,18 @@ UI.Number = function ( position ) {
var scope = this;
this.dom = document.createElement( 'span' );
this.dom.style.position = position || 'relative';
var dom = document.createElement( 'input' );
dom.style.position = position || 'relative';
dom.style.color = '#0080f0';
dom.style.fontSize = '12px';
dom.style.cursor = 'col-resize';
dom.style.backgroundColor = 'transparent';
dom.style.borderColor = 'transparent';
dom.style.marginTop = '-2px';
dom.style.marginLegt = '-2px';
dom.value = '0.00';
var display = document.createElement( 'span' );
display.style.color = '#0080f0';
display.style.fontSize = '12px';
display.style.cursor = 'col-resize';
display.textContent = '0.00';
this.dom.appendChild( display );
var input = document.createElement( 'input' );
input.style.display = 'none';
input.style.width = '100%';
input.style.marginTop = '-2px';
input.style.marginLeft = '-2px';
input.style.fontSize = '12px';
this.dom.appendChild( input );
this.dom = dom;
this.min = - Infinity;
this.max = Infinity;
......@@ -653,7 +662,7 @@ UI.Number = function ( position ) {
distance = 0;
onMouseDownValue = parseFloat( display.textContent );
onMouseDownValue = parseFloat( dom.value );
document.addEventListener( 'mousemove', onMouseMove, false );
document.addEventListener( 'mouseup', onMouseUp, false );
......@@ -669,7 +678,7 @@ UI.Number = function ( position ) {
var number = onMouseDownValue + ( distance / ( event.shiftKey ? 10 : 100 ) );
display.textContent = Math.min( scope.max, Math.max( scope.min, number ) ).toFixed( 2 );
dom.value = Math.min( scope.max, Math.max( scope.min, number ) ).toFixed( 2 );
if ( scope.onChangeCallback ) scope.onChangeCallback();
......@@ -680,32 +689,22 @@ UI.Number = function ( position ) {
document.removeEventListener( 'mousemove', onMouseMove, false );
document.removeEventListener( 'mouseup', onMouseUp, false );
if ( Math.abs( distance ) < 1 ) {
if ( Math.abs( distance ) < 2 ) {
display.style.display = 'none';
input.value = display.textContent;
input.addEventListener( 'change', onInputChange, false );
input.addEventListener( 'blur', onInputBlur, false );
input.addEventListener( 'keyup', onInputKeyUp, false );
input.style.display = '';
input.focus();
input.select();
dom.focus();
dom.select();
}
};
var onInputChange = function ( event ) {
var onChange = function ( event ) {
var number = parseFloat( input.value );
var number = parseFloat( dom.value );
if ( isNaN( number ) === false ) {
display.textContent = number.toFixed( 2 );
dom.value = number;
if ( scope.onChangeCallback ) scope.onChangeCallback();
......@@ -713,33 +712,37 @@ UI.Number = function ( position ) {
};
var onInputBlur = function ( event ) {
var onFocus = function ( event ) {
dom.style.backgroundColor = '';
dom.style.borderColor = '';
dom.style.cursor = '';
};
display.style.display = '';
var onBlur = function ( event ) {
input.removeEventListener( 'change', onInputChange );
input.removeEventListener( 'blur', onInputBlur );
input.removeEventListener( 'keyup', onInputKeyUp );
input.style.display = 'none';
dom.style.backgroundColor = 'transparent';
dom.style.borderColor = 'transparent';
dom.style.cursor = 'col-resize';
};
var onInputKeyUp = function ( event ) {
var onKeyUp = function ( event ) {
if ( event.keyCode == 13 ) {
display.style.display = '';
input.removeEventListener( 'change', onInputChange );
input.removeEventListener( 'blur', onInputBlur );
input.removeEventListener( 'keyup', onInputKeyUp );
input.style.display = 'none';
onBlur();
}
};
display.addEventListener( 'mousedown', onMouseDown, false );
dom.addEventListener( 'mousedown', onMouseDown, false );
dom.addEventListener( 'change', onChange, false );
dom.addEventListener( 'focus', onFocus, false );
dom.addEventListener( 'blur', onBlur, false );
dom.addEventListener( 'keyup', onKeyUp, false );
return this;
......@@ -749,13 +752,13 @@ UI.Number.prototype = Object.create( UI.Element.prototype );
UI.Number.prototype.getValue = function () {
return parseFloat( this.dom.children[ 0 ].textContent );
return parseFloat( this.dom.value );
};
UI.Number.prototype.setValue = function ( value ) {
this.dom.children[ 0 ].textContent = value.toFixed( 2 );
this.dom.value = value.toFixed( 2 );
return this;
......@@ -785,7 +788,9 @@ UI.Break = function () {
UI.Element.call( this );
this.dom = document.createElement( 'br' );
var dom = document.createElement( 'br' );
this.dom = dom;
return this;
......@@ -800,8 +805,10 @@ UI.HorizontalRule = function ( position ) {
UI.Element.call( this );
this.dom = document.createElement( 'hr' );
this.dom.style.position = position || 'relative';
var dom = document.createElement( 'hr' );
dom.style.position = position || 'relative';
this.dom = dom;
return this;
......@@ -818,8 +825,10 @@ UI.Button = function ( position ) {
var scope = this;
this.dom = document.createElement( 'button' );
this.dom.style.position = position || 'relative';
var dom = document.createElement( 'button' );
dom.style.position = position || 'relative';
this.dom = dom;
this.onClickCallback = null;
......
......@@ -172,7 +172,7 @@ Sidebar.Properties.Material = function ( signals ) {
var materialEnvMapRow = new UI.Panel();
var materialEnvMapEnabled = new UI.Checkbox( 'absolute' ).setValue( false ).setLeft( '100px' ).onChange( update );
var materialEnvMap = new UI.CubeTexture( 'absolute' ).setLeft( '170px' ).setColor( '#444' ).onChange( update );
var materialReflectivity = new UI.Number( 'absolute' ).setValue( 1 ).setLeft( '130px' ).setWidth( '30px' ).setColor( '#444' ).onChange( update );
var materialReflectivity = new UI.Number( 'absolute' ).setValue( 1 ).setLeft( '130px' ).setWidth( '30px' ).onChange( update );
materialEnvMapRow.add( new UI.Text().setValue( 'Env Map' ).setColor( '#666' ) );
......@@ -651,4 +651,4 @@ Sidebar.Properties.Material = function ( signals ) {
return container;
}
\ No newline at end of file
}
......@@ -52,16 +52,6 @@ var Viewport = function ( signals ) {
camera.lookAt( scene.position );
scene.add( camera );
var controls = new THREE.TrackballControls( camera, container.dom );
controls.rotateSpeed = 1.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
controls.addEventListener( 'change', render );
var light1 = new THREE.DirectionalLight( 0xffffff );
light1.position.set( 1, 0.5, 0 ).normalize();
scene.add( light1 );
......@@ -74,14 +64,11 @@ var Viewport = function ( signals ) {
camera.name = "Camera";
light1.name = "Light #1";
light1.target.name = "Light #1 target";
light2.name = "Light #2";
light2.target.name = "Light #2 target";
//
light1.name = "Light 1";
light1.target.name = "Target for light 1";
light2.name = "Light 2";
light2.target.name = "Target for light 2";
signals.sceneChanged.dispatch( scene );
// object picking
......@@ -95,7 +82,9 @@ var Viewport = function ( signals ) {
var offset = new THREE.Vector3();
var picked = null;
container.dom.addEventListener( 'mousedown', function ( event ) {
// events
var onMouseDown = function ( event ) {
event.preventDefault();
......@@ -115,23 +104,28 @@ var Viewport = function ( signals ) {
controls.enabled = false;
intersectionPlane.position.copy( intersects[ 0 ].object.position );
intersectionPlane.lookAt( camera.position );
picked = intersects[ 0 ].object;
selected = picked;
signals.objectSelected.dispatch( selected );
signals.objectSelected.dispatch( picked );
var intersects = ray.intersectObject( intersectionPlane );
offset.copy( intersects[ 0 ].point ).subSelf( intersectionPlane.position );
document.addEventListener( 'mousemove', onMouseMove, false );
document.addEventListener( 'mouseup', onMouseUp, false );
} else {
controls.enabled = true;
}
}, false );
};
container.dom.addEventListener( 'mousemove', function ( event ) {
var onMouseMove = function ( event ) {
var vector = new THREE.Vector3(
( ( event.clientX - container.dom.offsetLeft ) / container.dom.offsetWidth ) * 2 - 1,
......@@ -143,40 +137,28 @@ var Viewport = function ( signals ) {
ray.set( camera.position, vector.subSelf( camera.position ).normalize() );
if ( picked ) {
var intersects = ray.intersectObject( intersectionPlane );
var intersects = ray.intersectObject( intersectionPlane );
if ( intersects.length > 0 ) {
picked.position.copy( intersects[ 0 ].point.subSelf( offset ) );
if ( intersects.length > 0 ) {
signals.objectChanged.dispatch( picked );
picked.position.copy( intersects[ 0 ].point.subSelf( offset ) );
render();
signals.objectChanged.dispatch( picked );
}
return;
render();
}
var intersects = ray.intersectObjects( objects, true );
if ( intersects.length > 0 ) {
intersectionPlane.position.copy( intersects[ 0 ].object.position );
intersectionPlane.lookAt( camera.position );
}
};
}, false );
var onMouseUp = function ( event ) {
container.dom.addEventListener( 'mouseup', function ( event ) {
document.removeEventListener( 'mousemove', onMouseMove );
document.removeEventListener( 'mouseup', onMouseUp );
picked = false;
};
controls.enabled = true;
var onClick = function ( event ) {
var vector = new THREE.Vector3(
( ( event.clientX - container.dom.offsetLeft ) / container.dom.offsetWidth ) * 2 - 1,
......@@ -191,19 +173,33 @@ var Viewport = function ( signals ) {
if ( intersects.length > 0 ) {
selected = intersects[ 0 ].object;
signals.objectSelected.dispatch( intersects[ 0 ].object );
} else {
selected = null;
signals.objectSelected.dispatch( null );
}
signals.objectSelected.dispatch( selected );
};
}, false );
container.dom.addEventListener( 'mousedown', onMouseDown, false );
container.dom.addEventListener( 'click', onClick, false );
// events
// controls need to be added *after* main logic,
// otherwise controls.enabled doesn't work.
var controls = new THREE.TrackballControls( camera, container.dom );
controls.rotateSpeed = 1.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
controls.addEventListener( 'change', render );
// signals
signals.objectAdded.add( function ( object ) {
......@@ -232,55 +228,6 @@ var Viewport = function ( signals ) {
} );
signals.objectRemoved.add( function ( ) {
if ( !selected ) {
console.warn( "No object selected for delete" );
return;
}
var toRemove = {};
selected.traverse( function ( child ) {
toRemove[ child.id ] = true;
} );
var newObjects = [];
for ( var i = 0; i < objects.length; i ++ ) {
var object = objects[ i ];
if ( ! ( object.id in toRemove ) ) {
newObjects.push( object );
}
}
objects = newObjects;
selectionBox.visible = false;
selectionAxis.visible = false;
scene.traverse( function( node ) {
node.remove( selected );
} );
render();
signals.sceneChanged.dispatch( scene );
signals.objectSelected.dispatch( null );
} );
var selected = null;
signals.objectSelected.add( function ( object ) {
......@@ -342,12 +289,6 @@ var Viewport = function ( signals ) {
}
if ( object !== null ) {
selected = object;
}
render();
} );
......
......@@ -268,7 +268,7 @@ THREE.TrackballControls = function ( object, domElement ) {
function keydown( event ) {
if ( ! _this.enabled ) return;
window.removeEventListener( 'keydown', keydown );
_prevState = _state;
......@@ -290,15 +290,15 @@ THREE.TrackballControls = function ( object, domElement ) {
_state = STATE.PAN;
}
}
function keyup( event ) {
if ( ! _this.enabled ) return;
_state = _prevState;
window.addEventListener( 'keydown', keydown, false );
}
......@@ -311,9 +311,9 @@ THREE.TrackballControls = function ( object, domElement ) {
event.stopPropagation();
if ( _state === STATE.NONE ) {
_state = event.button;
}
if ( _state === STATE.ROTATE && !_this.noRotate ) {
......@@ -363,7 +363,7 @@ THREE.TrackballControls = function ( object, domElement ) {
event.stopPropagation();
_state = STATE.NONE;
document.removeEventListener( 'mousemove', mousemove );
document.removeEventListener( 'mouseup', mouseup );
......
......@@ -3,7 +3,7 @@
* @author Larry Battle / http://bateru.com/news
*/
var THREE = THREE || { REVISION: '52dev' };
var THREE = THREE || { REVISION: '53dev' };
self.console = self.console || {
......
......@@ -249,6 +249,12 @@ THREE.Vector3.prototype = {
},
angleTo: function ( v ) {
return Math.acos( this.dot( v ) / this.length() / v.length() );
},
distanceTo: function ( v ) {
return Math.sqrt( this.distanceToSquared( v ) );
......
......@@ -7,9 +7,9 @@
* Benchmark:
*
* Platform: CPU: P7350 @2.00GHz Engine: V8
*
*
* Num Vertices Time(ms)
*
*
* 10 1
* 20 3
* 30 19
......@@ -44,21 +44,21 @@ THREE.ConvexGeometry = function( vertices ) {
for ( var f = 0; f < faces.length; ) {
var face = faces[ f ];
// for each face, if the vertex can see it,
// then we try to add the face's edges into the hole.
if ( visible( face, vertex ) ) {
for ( var e = 0; e < 3; e++ ) {
var edge = [ face[ e ], face[ ( e + 1 ) % 3 ] ];
var boundary = true;
// remove duplicated edges.
for ( var h = 0; h < hole.length; h++ ) {
if ( equalEdge( hole[ h ], edge ) ) {
hole[ h ] = hole[ hole.length - 1 ];
hole.pop();
boundary = false;
......@@ -79,9 +79,9 @@ THREE.ConvexGeometry = function( vertices ) {
// remove faces[ f ]
faces[ f ] = faces[ faces.length - 1 ];
faces.pop();
} else { // not visible
f++;
}
......@@ -121,7 +121,7 @@ THREE.ConvexGeometry = function( vertices ) {
* Face normal
*/
function normal( va, vb, vc ) {
var cb = new THREE.Vector3();
var ab = new THREE.Vector3();
......@@ -130,7 +130,7 @@ THREE.ConvexGeometry = function( vertices ) {
cb.crossSelf( ab );
if ( !cb.isZero() ) {
cb.normalize();
}
......@@ -145,7 +145,7 @@ THREE.ConvexGeometry = function( vertices ) {
* be of the negative direction.
*/
function equalEdge( ea, eb ) {
return ea[ 0 ] === eb[ 1 ] && ea[ 1 ] === eb[ 0 ];
}
......@@ -177,20 +177,20 @@ THREE.ConvexGeometry = function( vertices ) {
for ( var i = 0; i < faces.length; i++ ) {
var face = faces[ i ];
for ( var j = 0; j < 3; j++ ) {
if ( newId[ face[ j ] ] === undefined ) {
newId[ face[ j ] ] = id++;
this.vertices.push( vertices[ face[ j ] ] );
}
face[ j ] = newId[ face[ j ] ];
}
}
}
// Convert faces into instances of THREE.Face3
......@@ -206,7 +206,7 @@ THREE.ConvexGeometry = function( vertices ) {
// Compute UVs
for ( var i = 0; i < this.faces.length; i++ ) {
var face = this.faces[ i ];
this.faceVertexUvs[ 0 ].push( [
......@@ -216,7 +216,7 @@ THREE.ConvexGeometry = function( vertices ) {
] );
}
this.computeCentroids();
this.computeFaceNormals();
......
......@@ -2,7 +2,7 @@
* @author mrdoob / http://mrdoob.com/
*/
THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, segmentsRadius, segmentsHeight, openEnded ) {
THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded ) {
THREE.Geometry.call( this );
......@@ -11,8 +11,8 @@ THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, segmentsRad
height = height !== undefined ? height : 100;
var heightHalf = height / 2;
var segmentsX = segmentsRadius || 8;
var segmentsY = segmentsHeight || 1;
var segmentsX = radiusSegments || 8;
var segmentsY = heightSegments || 1;
var x, y, vertices = [], uvs = [];
......
......@@ -3,15 +3,15 @@
* based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
*/
THREE.PlaneGeometry = function ( width, height, segmentsWidth, segmentsheight ) {
THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
THREE.Geometry.call( this );
var ix, iz,
width_half = width / 2,
height_half = height / 2,
gridX = segmentsWidth || 1,
gridZ = segmentsheight || 1,
gridX = widthSegments || 1,
gridZ = heightSegments || 1,
gridX1 = gridX + 1,
gridZ1 = gridZ + 1,
segment_width = width / gridX,
......
......@@ -2,7 +2,7 @@
* @author mrdoob / http://mrdoob.com/
*/
THREE.SphereGeometry = function ( radius, segmentsWidth, segmentsHeight, phiStart, phiLength, thetaStart, thetaLength ) {
THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
THREE.Geometry.call( this );
......@@ -14,8 +14,8 @@ THREE.SphereGeometry = function ( radius, segmentsWidth, segmentsHeight, phiStar
thetaStart = thetaStart !== undefined ? thetaStart : 0;
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
var segmentsX = Math.max( 3, Math.floor( segmentsWidth ) || 8 );
var segmentsY = Math.max( 2, Math.floor( segmentsHeight ) || 6 );
var segmentsX = Math.max( 3, Math.floor( widthSegments ) || 8 );
var segmentsY = Math.max( 2, Math.floor( heightSegments ) || 6 );
var x, y, vertices = [], uvs = [];
......
......@@ -4,7 +4,7 @@
* based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
*/
THREE.TorusGeometry = function ( radius, tube, segmentsR, segmentsT, arc ) {
THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
THREE.Geometry.call( this );
......@@ -12,18 +12,18 @@ THREE.TorusGeometry = function ( radius, tube, segmentsR, segmentsT, arc ) {
this.radius = radius || 100;
this.tube = tube || 40;
this.segmentsR = segmentsR || 8;
this.segmentsT = segmentsT || 6;
this.radialSegments = radialSegments || 8;
this.tubularSegments = tubularSegments || 6;
this.arc = arc || Math.PI * 2;
var center = new THREE.Vector3(), uvs = [], normals = [];
for ( var j = 0; j <= this.segmentsR; j ++ ) {
for ( var j = 0; j <= this.radialSegments; j ++ ) {
for ( var i = 0; i <= this.segmentsT; i ++ ) {
for ( var i = 0; i <= this.tubularSegments; i ++ ) {
var u = i / this.segmentsT * this.arc;
var v = j / this.segmentsR * Math.PI * 2;
var u = i / this.tubularSegments * this.arc;
var v = j / this.radialSegments * Math.PI * 2;
center.x = this.radius * Math.cos( u );
center.y = this.radius * Math.sin( u );
......@@ -35,21 +35,21 @@ THREE.TorusGeometry = function ( radius, tube, segmentsR, segmentsT, arc ) {
this.vertices.push( vertex );
uvs.push( new THREE.UV( i / this.segmentsT, j / this.segmentsR ) );
uvs.push( new THREE.UV( i / this.tubularSegments, j / this.radialSegments ) );
normals.push( vertex.clone().subSelf( center ).normalize() );
}
}
for ( var j = 1; j <= this.segmentsR; j ++ ) {
for ( var j = 1; j <= this.radialSegments; j ++ ) {
for ( var i = 1; i <= this.segmentsT; i ++ ) {
for ( var i = 1; i <= this.tubularSegments; i ++ ) {
var a = ( this.segmentsT + 1 ) * j + i - 1;
var b = ( this.segmentsT + 1 ) * ( j - 1 ) + i - 1;
var c = ( this.segmentsT + 1 ) * ( j - 1 ) + i;
var d = ( this.segmentsT + 1 ) * j + i;
var a = ( this.tubularSegments + 1 ) * j + i - 1;
var b = ( this.tubularSegments + 1 ) * ( j - 1 ) + i - 1;
var c = ( this.tubularSegments + 1 ) * ( j - 1 ) + i;
var d = ( this.tubularSegments + 1 ) * j + i;
var face = new THREE.Face4( a, b, c, d, [ normals[ a ], normals[ b ], normals[ c ], normals[ d ] ] );
face.normal.addSelf( normals[ a ] );
......
......@@ -3,7 +3,7 @@
* based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
*/
THREE.TorusKnotGeometry = function ( radius, tube, segmentsR, segmentsT, p, q, heightScale ) {
THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
THREE.Geometry.call( this );
......@@ -11,25 +11,25 @@ THREE.TorusKnotGeometry = function ( radius, tube, segmentsR, segmentsT, p, q, h
this.radius = radius || 200;
this.tube = tube || 40;
this.segmentsR = segmentsR || 64;
this.segmentsT = segmentsT || 8;
this.radialSegments = radialSegments || 64;
this.tubularSegments = tubularSegments || 8;
this.p = p || 2;
this.q = q || 3;
this.heightScale = heightScale || 1;
this.grid = new Array(this.segmentsR);
this.grid = new Array(this.radialSegments);
var tang = new THREE.Vector3();
var n = new THREE.Vector3();
var bitan = new THREE.Vector3();
for ( var i = 0; i < this.segmentsR; ++ i ) {
for ( var i = 0; i < this.radialSegments; ++ i ) {
this.grid[ i ] = new Array( this.segmentsT );
this.grid[ i ] = new Array( this.tubularSegments );
for ( var j = 0; j < this.segmentsT; ++ j ) {
for ( var j = 0; j < this.tubularSegments; ++ j ) {
var u = i / this.segmentsR * 2 * this.p * Math.PI;
var v = j / this.segmentsT * 2 * Math.PI;
var u = i / this.radialSegments * 2 * this.p * Math.PI;
var v = j / this.tubularSegments * 2 * Math.PI;
var p1 = getPos( u, v, this.q, this.p, this.radius, this.heightScale );
var p2 = getPos( u + 0.01, v, this.q, this.p, this.radius, this.heightScale );
var cx, cy;
......@@ -55,22 +55,22 @@ THREE.TorusKnotGeometry = function ( radius, tube, segmentsR, segmentsT, p, q, h
}
for ( var i = 0; i < this.segmentsR; ++ i ) {
for ( var i = 0; i < this.radialSegments; ++ i ) {
for ( var j = 0; j < this.segmentsT; ++ j ) {
for ( var j = 0; j < this.tubularSegments; ++ j ) {
var ip = ( i + 1 ) % this.segmentsR;
var jp = ( j + 1 ) % this.segmentsT;
var ip = ( i + 1 ) % this.radialSegments;
var jp = ( j + 1 ) % this.tubularSegments;
var a = this.grid[ i ][ j ];
var b = this.grid[ ip ][ j ];
var c = this.grid[ ip ][ jp ];
var d = this.grid[ i ][ jp ];
var uva = new THREE.UV( i / this.segmentsR, j / this.segmentsT );
var uvb = new THREE.UV( ( i + 1 ) / this.segmentsR, j / this.segmentsT );
var uvc = new THREE.UV( ( i + 1 ) / this.segmentsR, ( j + 1 ) / this.segmentsT );
var uvd = new THREE.UV( i / this.segmentsR, ( j + 1 ) / this.segmentsT );
var uva = new THREE.UV( i / this.radialSegments, j / this.tubularSegments );
var uvb = new THREE.UV( ( i + 1 ) / this.radialSegments, j / this.tubularSegments );
var uvc = new THREE.UV( ( i + 1 ) / this.radialSegments, ( j + 1 ) / this.tubularSegments );
var uvd = new THREE.UV( i / this.radialSegments, ( j + 1 ) / this.tubularSegments );
this.faces.push( new THREE.Face4( a, b, c, d ) );
this.faceVertexUvs[ 0 ].push( [ uva,uvb,uvc, uvd ] );
......
......@@ -11,14 +11,14 @@
* http://www.cs.indiana.edu/pub/techreports/TR425.pdf
*/
THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, debug ) {
THREE.TubeGeometry = function( path, segments, radius, radiusSegments, closed, debug ) {
THREE.Geometry.call( this );
this.path = path;
this.segments = segments || 64;
this.radius = radius || 1;
this.segmentsRadius = segmentsRadius || 8;
this.radiusSegments = radiusSegments || 8;
this.closed = closed || false;
if ( debug ) this.debug = new THREE.Object3D();
......@@ -83,9 +83,9 @@ THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, d
}
for ( j = 0; j < this.segmentsRadius; j++ ) {
for ( j = 0; j < this.radiusSegments; j++ ) {
v = j / this.segmentsRadius * 2 * Math.PI;
v = j / this.radiusSegments * 2 * Math.PI;
cx = -this.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
cy = this.radius * Math.sin( v );
......@@ -105,20 +105,20 @@ THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, d
for ( i = 0; i < this.segments; i++ ) {
for ( j = 0; j < this.segmentsRadius; j++ ) {
for ( j = 0; j < this.radiusSegments; j++ ) {
ip = ( closed ) ? (i + 1) % this.segments : i + 1;
jp = (j + 1) % this.segmentsRadius;
jp = (j + 1) % this.radiusSegments;
a = this.grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
b = this.grid[ ip ][ j ];
c = this.grid[ ip ][ jp ];
d = this.grid[ i ][ jp ];
uva = new THREE.UV( i / this.segments, j / this.segmentsRadius );
uvb = new THREE.UV( ( i + 1 ) / this.segments, j / this.segmentsRadius );
uvc = new THREE.UV( ( i + 1 ) / this.segments, ( j + 1 ) / this.segmentsRadius );
uvd = new THREE.UV( i / this.segments, ( j + 1 ) / this.segmentsRadius );
uva = new THREE.UV( i / this.segments, j / this.radiusSegments );
uvb = new THREE.UV( ( i + 1 ) / this.segments, j / this.radiusSegments );
uvc = new THREE.UV( ( i + 1 ) / this.segments, ( j + 1 ) / this.radiusSegments );
uvd = new THREE.UV( i / this.segments, ( j + 1 ) / this.radiusSegments );
this.faces.push( new THREE.Face4( a, b, c, d ) );
this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvc, uvd ] );
......
......@@ -51,89 +51,88 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
/// REFACTORING THIS OUT
function orderedKey( a, b ) {
THREE.GeometryUtils.orderedKey = function ( a, b ) {
return Math.min( a, b ) + "_" + Math.max( a, b );
}
};
var G = {
// Returns a hashmap - of { edge_key: face_index }
THREE.GeometryUtils.computeEdgeFaces = function ( geometry ) {
// Returns a hashmap - of { edge_key: face_index }
computeEdgeFaces: function ( geometry ) {
var i, il, v1, v2, j, k,
face, faceIndices, faceIndex,
edge,
hash,
edgeFaceMap = {};
var i, il, v1, v2, j, k,
face, faceIndices, faceIndex,
edge,
hash,
edgeFaceMap = {};
var orderedKey = THREE.GeometryUtils.orderedKey;
function mapEdgeHash( hash, i ) {
if ( edgeFaceMap[ hash ] === undefined ) {
function mapEdgeHash( hash, i ) {
if ( edgeFaceMap[ hash ] === undefined ) {
edgeFaceMap[ hash ] = [];
}
edgeFaceMap[ hash ] = [];
edgeFaceMap[ hash ].push( i );
}
edgeFaceMap[ hash ].push( i );
}
// construct vertex -> face map
// construct vertex -> face map
for( i = 0, il = geometry.faces.length; i < il; i ++ ) {
for( i = 0, il = geometry.faces.length; i < il; i ++ ) {
face = geometry.faces[ i ];
face = geometry.faces[ i ];
if ( face instanceof THREE.Face3 ) {
if ( face instanceof THREE.Face3 ) {
hash = orderedKey( face.a, face.b );
mapEdgeHash( hash, i );
hash = orderedKey( face.a, face.b );
mapEdgeHash( hash, i );
hash = orderedKey( face.b, face.c );
mapEdgeHash( hash, i );
hash = orderedKey( face.b, face.c );
mapEdgeHash( hash, i );
hash = orderedKey( face.c, face.a );
mapEdgeHash( hash, i );
hash = orderedKey( face.c, face.a );
mapEdgeHash( hash, i );
} else if ( face instanceof THREE.Face4 ) {
} else if ( face instanceof THREE.Face4 ) {
hash = orderedKey( face.a, face.b );
mapEdgeHash( hash, i );
hash = orderedKey( face.a, face.b );
mapEdgeHash( hash, i );
hash = orderedKey( face.b, face.c );
mapEdgeHash( hash, i );
hash = orderedKey( face.b, face.c );
mapEdgeHash( hash, i );
hash = orderedKey( face.c, face.d );
mapEdgeHash( hash, i );
hash = orderedKey( face.d, face.a );
mapEdgeHash( hash, i );
}
hash = orderedKey( face.c, face.d );
mapEdgeHash( hash, i );
hash = orderedKey( face.d, face.a );
mapEdgeHash( hash, i );
}
// extract faces
// var edges = [];
//
// var numOfEdges = 0;
// for (i in edgeFaceMap) {
// numOfEdges++;
//
// edge = edgeFaceMap[i];
// edges.push(edge);
//
// }
//debug('edgeFaceMap', edgeFaceMap, 'geometry.edges',geometry.edges, 'numOfEdges', numOfEdges);
}
return edgeFaceMap;
// extract faces
// var edges = [];
//
// var numOfEdges = 0;
// for (i in edgeFaceMap) {
// numOfEdges++;
//
// edge = edgeFaceMap[i];
// edges.push(edge);
//
// }
//debug('edgeFaceMap', edgeFaceMap, 'geometry.edges',geometry.edges, 'numOfEdges', numOfEdges);
return edgeFaceMap;
}
}
/////////////////////////////
......@@ -151,6 +150,8 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
}
var scope = this;
var orderedKey = THREE.GeometryUtils.orderedKey;
var computeEdgeFaces = THREE.GeometryUtils.computeEdgeFaces;
function assert() {
if (scope.debug && console && console.assert) console.assert.apply(console, arguments);
......@@ -344,7 +345,7 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
// For each edge, add an edge point.
// Set each edge point to be the average of the two neighbouring face points and its two original endpoints.
var edgeFaceMap = G.computeEdgeFaces ( oldGeometry ); // Edge Hash -> Faces Index eg { edge_key: [face_index, face_index2 ]}
var edgeFaceMap = computeEdgeFaces ( oldGeometry ); // Edge Hash -> Faces Index eg { edge_key: [face_index, face_index2 ]}
var edge, faceIndexA, faceIndexB, avg;
// debug('edgeFaceMap', edgeFaceMap);
......@@ -485,7 +486,6 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
// Step 3
// For each face point, add an edge for every edge of the face,
// connecting the face point to each edge point for the face.
debugCoreStuff();
var facePt, currentVerticeIndex;
......
......@@ -155,9 +155,12 @@ THREE.SpritePlugin = function ( ) {
if ( sprite.useScreenCoordinates ) {
_gl.uniform1i( uniforms.useScreenCoordinates, 1 );
_gl.uniform3f( uniforms.screenPosition, ( sprite.position.x - halfViewportWidth ) / halfViewportWidth,
( halfViewportHeight - sprite.position.y ) / halfViewportHeight,
Math.max( 0, Math.min( 1, sprite.position.z ) ) );
_gl.uniform3f(
uniforms.screenPosition,
( sprite.position.x - halfViewportWidth ) / halfViewportWidth,
( halfViewportHeight - sprite.position.y ) / halfViewportHeight,
Math.max( 0, Math.min( 1, sprite.position.z ) )
);
} else {
......@@ -239,4 +242,4 @@ THREE.SpritePlugin = function ( ) {
};
};
\ No newline at end of file
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册