提交 06b10a01 编写于 作者: I ide user ide_gero3

added the the complete performance improvement

因为 它太大了无法显示 source diff 。你可以改为 查看blob
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -11,11 +11,10 @@ var geometry = new THREE.Geometry()
for ( var i = 0; i < 10000; i ++ ) {
var vertex = new THREE.Vertex();
vertex.position.x = Math.random() * 1000 - 500;
vertex.position.y = Math.random() * 1000 - 500;
vertex.position.z = Math.random() * 1000 - 500;
var vertex = new THREE.Vector3();
vertex.x = Math.random() * 1000 - 500;
vertex.y = Math.random() * 1000 - 500;
vertex.z = Math.random() * 1000 - 500;
geometry.vertices.push( vertex );
}
......@@ -37,7 +36,7 @@ Unique number of this geometry instance
<h3>.[page:Array vertices]</h3>
<div>
Array of [page:Vertex vertices].
Array of [page:Vector3 vertices].
</div>
<h3>.[page:Array colors]</h3>
......@@ -166,4 +165,4 @@ Duplicated vertices are removed and faces' vertices are updated.
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
\ No newline at end of file
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
......@@ -33,37 +33,7 @@ m.multiplySelf( m3 );
<h2>Properties</h2>
<h3>.[page:Float n11]</h3>
<h3>.[page:Float n12]</h3>
<h3>.[page:Float n13]</h3>
<h3>.[page:Float n14]</h3>
<h3>.[page:Float n21]</h3>
<h3>.[page:Float n22]</h3>
<h3>.[page:Float n23]</h3>
<h3>.[page:Float n24]</h3>
<h3>.[page:Float n31]</h3>
<h3>.[page:Float n32]</h3>
<h3>.[page:Float n33]</h3>
<h3>.[page:Float n34]</h3>
<h3>.[page:Float n41]</h3>
<h3>.[page:Float n42]</h3>
<h3>.[page:Float n43]</h3>
<h3>.[page:Float n44]</h3>
<h3>.[page:Float32Array elements]</h3>
<h2>Methods</h2>
......@@ -329,4 +299,4 @@ Creates orthographic projection matrix.
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
\ No newline at end of file
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
<h1>[name]</h1>
<div class="desc"></div>
<h2>Constructor</h2>
<h3>[name]()</h3>
<h2>Properties</h2>
<h3>.[page:Vector3 position]</h3>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
\ No newline at end of file
......@@ -140,8 +140,7 @@
{ name: "UV", path: "core/UV" },
{ name: "Vector2", path: "core/Vector2" },
{ name: "Vector3", path: "core/Vector3" },
{ name: "Vector4", path: "core/Vector4" },
{ name: "Vertex", path: "core/Vertex" }
{ name: "Vector4", path: "core/Vector4" }
],
"Lights": [
......
......@@ -77,7 +77,6 @@
{ material: new THREE.MeshDepthMaterial( { overdraw: true } ), doubleSided: false },
{ material: new THREE.MeshNormalMaterial( { overdraw: true } ), doubleSided: false },
{ material: new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'textures/land_ocean_ice_cloud_2048.jpg' ) } ), doubleSided: false },
{ material: new THREE.MeshLambertMaterial( { map: THREE.ImageUtils.loadTexture( 'textures/land_ocean_ice_cloud_2048.jpg' ) } ), doubleSided: false },
{ material: new THREE.MeshBasicMaterial( { envMap: THREE.ImageUtils.loadTexture( 'textures/envmap.png', new THREE.SphericalReflectionMapping() ) } ), doubleSided: false }
];
......
......@@ -708,7 +708,7 @@ THREE.ShaderExtras = {
"vec2 vin;",
"vec2 uv = vUv;",
"add += color = org = texture2D( tDiffuse, uv );",
"add = color = org = texture2D( tDiffuse, uv );",
"vin = ( uv - vec2( 0.5 ) ) * vec2( 1.4 );",
"sample_dist = dot( vin, vin ) * 2.0;",
......
/*
* @author https://github.com/zz85 | @blurspline
*
* tool for "unwrapping" and debugging three.js
* geometries UV mapping
*
* Sample usage:
* document.body.appendChild(
* THREE.UVsDebug(
* new THREE.SphereGeometry(10,10,10,10));
*
*/
THREE.UVsDebug = function(geometry) {
var verts = geometry.vertices,
faces = geometry.faces,
uvs = geometry.faceVertexUvs[0];
console.log('debugging geometry', geometry);
var canvas = document.createElement('canvas');
var width = 1024;
var height = 1024;
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext('2d');
ctx.lineWidth = 1;
ctx.strokeStyle = 'rgba(0,0,0,0.8)';
// paint background white
ctx.fillStyle = 'rgba(255,255,255, 1.0)';
ctx.fillRect(0, 0, width, height);
var abc = 'abcd';
var uv, u, ax, ay;
var i, il, j, jl;
var a = new THREE.Vector2();
var b = new THREE.Vector2();
for (i = 0, il = uvs.length; i < il; i++) {
uv = uvs[i];
// draw lines
ctx.beginPath();
a.set(0, 0);
for (j = 0, jl = uv.length; j < jl; j++) {
u = uv[j];
a.x += u.u;
a.y += u.v;
if (j == 0) {
ctx.moveTo(u.u * width, u.v * height);
} else {
ctx.lineTo(u.u * width, u.v * height);
}
}
ctx.closePath();
ctx.stroke();
a.divideScalar(jl);
// label the face number
ctx.font = "12pt Arial bold";
ctx.fillStyle = 'rgba(0,0,0,0.8)';
ctx.fillText(i, a.x * width, a.y * height);
ctx.font = "8pt Arial bold";
ctx.fillStyle = 'rgba(30,30,0,0.8)';
// label uv edge orders
for (j = 0, jl = uv.length; j < jl; j++) {
u = uv[j];
b.set(u.u, u.v).subSelf(a).divideScalar(4);
b.x = u.u - b.x;
b.y = u.v - b.y;
ctx.fillText(abc[j]
+ ':' + faces[i][abc[j]], b.x * width, b.y * height);
}
}
return canvas;
}
\ No newline at end of file
......@@ -2360,13 +2360,13 @@ THREE.ColladaLoader = function () {
for ( var pCount = 0; pCount < pList.length; ++pCount ) {
var p = pList[pCount], i = 0;
var p = pList[ pCount ], i = 0;
while ( i < p.length ) {
var vs = [];
var ns = [];
var ts = {};
var ts = null;
var cs = [];
if ( primitive.vcount ) {
......@@ -2407,6 +2407,7 @@ THREE.ColladaLoader = function () {
case 'TEXCOORD':
ts = ts || { };
if ( ts[ input.set ] === undefined ) ts[ input.set ] = [];
// invert the V
ts[ input.set ].push( new THREE.UV( source.data[ idx32 ], 1.0 - source.data[ idx32 + 1 ] ) );
......@@ -2420,6 +2421,7 @@ THREE.ColladaLoader = function () {
break;
default:
break;
}
......@@ -2428,11 +2430,9 @@ THREE.ColladaLoader = function () {
}
var face = null, faces = [], uv, uvArr;
if ( ns.length == 0 ) {
// check the vertices source
// check the vertices inputs
input = this.vertices.input.NORMAL;
if ( input ) {
......@@ -2446,13 +2446,62 @@ THREE.ColladaLoader = function () {
}
}
else {
} else {
geom.calcNormals = true;
}
}
if ( !ts ) {
ts = { };
// check the vertices inputs
input = this.vertices.input.TEXCOORD;
if ( input ) {
texture_sets.push( input.set );
source = sources[ input.source ];
numParams = source.accessor.params.length;
for ( var ndx = 0, len = vs.length; ndx < len; ndx++ ) {
idx32 = vs[ ndx ] * numParams;
if ( ts[ input.set ] === undefined ) ts[ input.set ] = [ ];
// invert the V
ts[ input.set ].push( new THREE.UV( source.data[ idx32 ], 1.0 - source.data[ idx32 + 1 ] ) );
}
}
}
if ( cs.length == 0 ) {
// check the vertices inputs
input = this.vertices.input.COLOR;
if ( input ) {
source = sources[ input.source ];
numParams = source.accessor.params.length;
for ( var ndx = 0, len = vs.length; ndx < len; ndx++ ) {
idx32 = vs[ ndx ] * numParams;
cs.push( new THREE.Color().setRGB( source.data[ idx32 ], source.data[ idx32 + 1 ], source.data[ idx32 + 2 ] ) );
}
}
}
var face = null, faces = [], uv, uvArr;
if ( vcount === 3 ) {
faces.push( new THREE.Face3( vs[0], vs[1], vs[2], ns, cs.length ? cs : new THREE.Color() ) );
......
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.OBJLoader = function () {};
THREE.OBJLoader.prototype = new THREE.Loader();
THREE.OBJLoader.prototype.constructor = THREE.OBJLoader;
THREE.OBJLoader.prototype.load = function ( url, callback ) {
var that = this;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if ( xhr.readyState == 4 ) {
if ( xhr.status == 200 || xhr.status == 0 ) {
callback( that.parse( xhr.responseText ) );
} else {
console.error( 'THREE.OBJLoader: Couldn\'t load ' + url + ' (' + xhr.status + ')' );
}
}
};
xhr.open( "GET", url, true );
xhr.send( null );
};
THREE.OBJLoader.prototype.parse = function ( data ) {
function vector( x, y, z ) {
return new THREE.Vector3( x, y, z );
}
function face3( a, b, c, normals ) {
return new THREE.Face3( a, b, c, normals );
}
function face4( a, b, c, d, normals ) {
return new THREE.Face4( a, b, c, d, normals );
}
var objects = [];
var vertices = [];
var normals = [];
var pattern, result;
// v float float float
pattern = /v( [\d|\.|\+|\-|e]+)( [\d|\.|\+|\-|e]+)( [\d|\.|\+|\-|e]+)/g;
while ( ( result = pattern.exec( data ) ) != null ) {
// ["v 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
vertices.push( vector(
parseFloat( result[ 1 ] ),
parseFloat( result[ 2 ] ),
parseFloat( result[ 3 ] )
) );
}
// vn float float float
pattern = /vn( [\d|\.|\+|\-|e]+)( [\d|\.|\+|\-|e]+)( [\d|\.|\+|\-|e]+)/g;
while ( ( result = pattern.exec( data ) ) != null ) {
// ["v 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
normals.push( vector(
parseFloat( result[ 1 ] ),
parseFloat( result[ 2 ] ),
parseFloat( result[ 3 ] )
) );
}
var data = data.split( '\no ');
for ( var i = 0, l = data.length; i < l; i ++ ) {
var object = data[ i ];
var geometry = new THREE.Geometry();
geometry.vertices = vertices;
// f vertex vertex vertex ...
pattern = /f( [\d]+)( [\d]+)( [\d]+)( [\d]+)?/g;
while ( ( result = pattern.exec( object ) ) != null ) {
// ["f 1 2 3", "1", "2", "3", undefined]
if ( result[ 4 ] === undefined ) {
geometry.faces.push( face3(
parseInt( result[ 1 ] ) - 1,
parseInt( result[ 2 ] ) - 1,
parseInt( result[ 3 ] ) - 1
) );
} else {
geometry.faces.push( face4(
parseInt( result[ 1 ] ) - 1,
parseInt( result[ 2 ] ) - 1,
parseInt( result[ 3 ] ) - 1,
parseInt( result[ 4 ] ) - 1
) );
}
}
// f vertex/uv vertex/uv vertex/uv ...
pattern = /f( ([\d]+)\/([\d]+))( ([\d]+)\/([\d]+))( ([\d]+)\/([\d]+))( ([\d]+)\/([\d]+))?/g;
while ( ( result = pattern.exec( object ) ) != null ) {
// ["f 1/1 2/2 3/3", " 1/1", "1", "1", " 2/2", "2", "2", " 3/3", "3", "3", undefined, undefined, undefined]
if ( result[ 10 ] === undefined ) {
geometry.faces.push( face3(
parseInt( result[ 2 ] ) - 1,
parseInt( result[ 5 ] ) - 1,
parseInt( result[ 8 ] ) - 1
) );
} else {
geometry.faces.push( face4(
parseInt( result[ 2 ] ) - 1,
parseInt( result[ 5 ] ) - 1,
parseInt( result[ 8 ] ) - 1,
parseInt( result[ 11 ] ) - 1
) );
}
}
// f vertex/uv/normal vertex/uv/normal vertex/uv/normal ...
pattern = /f( ([\d]+)\/([\d]+)\/([\d]+))( ([\d]+)\/([\d]+)\/([\d]+))( ([\d]+)\/([\d]+)\/([\d]+))( ([\d]+)\/([\d]+)\/([\d]+))?/g;
while ( ( result = pattern.exec( object ) ) != null ) {
// ["f 1/1/1 2/2/2 3/3/3", " 1/1/1", "1", "1", "1", " 2/2/2", "2", "2", "2", " 3/3/3", "3", "3", "3", undefined, undefined, undefined, undefined]
if ( result[ 13 ] === undefined ) {
geometry.faces.push( face3(
parseInt( result[ 2 ] ) - 1,
parseInt( result[ 6 ] ) - 1,
parseInt( result[ 10 ] ) - 1,
[
normals[ parseInt( result[ 4 ] ) - 1 ],
normals[ parseInt( result[ 8 ] ) - 1 ],
normals[ parseInt( result[ 12 ] ) - 1 ]
]
) );
} else {
geometry.faces.push( face4(
parseInt( result[ 2 ] ) - 1,
parseInt( result[ 6 ] ) - 1,
parseInt( result[ 10 ] ) - 1,
parseInt( result[ 14 ] ) - 1,
[
normals[ parseInt( result[ 4 ] ) - 1 ],
normals[ parseInt( result[ 8 ] ) - 1 ],
normals[ parseInt( result[ 12 ] ) - 1 ],
normals[ parseInt( result[ 16 ] ) - 1 ]
]
) );
}
}
// f vertex//normal vertex//normal vertex//normal ...
pattern = /f( ([\d]+)\/\/([\d]+))( ([\d]+)\/\/([\d]+))( ([\d]+)\/\/([\d]+))( ([\d]+)\/\/([\d]+))?/g;
while ( ( result = pattern.exec( object ) ) != null ) {
// ["f 1//1 2//2 3//3", " 1//1", "1", "1", " 2//2", "2", "2", " 3//3", "3", "3", undefined, undefined, undefined]
if ( result[ 10 ] === undefined ) {
geometry.faces.push( face3(
parseInt( result[ 2 ] ) - 1,
parseInt( result[ 5 ] ) - 1,
parseInt( result[ 8 ] ) - 1,
[
normals[ parseInt( result[ 3 ] ) - 1 ],
normals[ parseInt( result[ 6 ] ) - 1 ],
normals[ parseInt( result[ 9 ] ) - 1 ]
]
) );
} else {
geometry.faces.push( face4(
parseInt( result[ 2 ] ) - 1,
parseInt( result[ 5 ] ) - 1,
parseInt( result[ 8 ] ) - 1,
parseInt( result[ 11 ] ) - 1,
[
normals[ parseInt( result[ 3 ] ) - 1 ],
normals[ parseInt( result[ 6 ] ) - 1 ],
normals[ parseInt( result[ 9 ] ) - 1 ],
normals[ parseInt( result[ 12 ] ) - 1 ]
]
) );
}
}
geometry.computeCentroids();
objects.push( new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) ) );
}
return objects;
}
/**
* @author Sebastien Valette sebastien.valette@creatis.insa-lyon.fr
*/
THREE.VTKLoader = function () {};
THREE.VTKLoader.prototype = new THREE.Loader();
THREE.VTKLoader.prototype.constructor = THREE.VTKLoader;
THREE.VTKLoader.prototype.load = function ( url, callback ) {
var that = this;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if ( xhr.readyState == 4 ) {
if ( xhr.status == 200 || xhr.status == 0 ) {
callback( that.parse( xhr.responseText ) );
} else {
console.error( 'THREE.VTKLoader: Couldn\'t load ' + url + ' (' + xhr.status + ')' );
}
}
};
xhr.open( "GET", url, true );
xhr.send( null );
};
THREE.VTKLoader.prototype.parse = function ( data ) {
var geometry = new THREE.Geometry();
var lines = data.split("\n");
function v( x, y, z ) {
geometry.vertices.push( new THREE.Vector3( x, y, z ) );
}
function f3( a, b, c ) {
geometry.faces.push( new THREE.Face3( a, b, c ) );
}
var lineIndex = 0;
var line = lines[ 0 ].split( ' ' );
var lineLength = line.length;
var columnIndex = -1;
function readNextString() {
while ( 1 ) {
var nextWord = line[ columnIndex ];
columnIndex ++;
if ( columnIndex == lineLength ) {
lineIndex ++;
columnIndex = 0;
if ( lineIndex > lines.length ) {
return '';
}
line = lines[ lineIndex ].split( ' ' );
lineLength = line.length;
}
if ( nextWord != null ) {
if ( nextWord.length > 0 ) {
return nextWord;
}
}
}
}
// read point data
var found = false;
while ( !found ) {
var readString = readNextString();
switch ( readString.toUpperCase() ) {
case 'POINTS':
found = true;
break;
case '':
alert ( 'error while reading ' + url + ' : \n' );
return;
}
}
var newIndex;
var new2old;
var numberOfPoints = parseInt( readNextString() );
if ( numberOfPoints > 5000000 ) {
alert ( 'mesh is too big : ' + numberOfPoints + ' vertices' );
return;
}
var coord = [ 0, 0, 0 ];
var index2 = 0;
var number;
var coordIndex;
for ( var j = 0; j != numberOfPoints; j ++ ) {
for ( coordIndex = 0; coordIndex < 3; coordIndex ++ ) {
do {
number = parseFloat( line[ columnIndex ] );
columnIndex ++;
if ( columnIndex == lineLength ) {
lineIndex ++;
columnIndex = 0;
if ( lineIndex > lines.length ) {
alert ( 'error while reading ' + url + ' : \n' );
return;
}
line = lines[ lineIndex ].split( ' ' );
lineLength = line.length;
}
} while ( isNaN( number ) )
coord[ coordIndex ] = number;
}
v( coord[ 0 ], coord[ 1 ], coord[ 2 ] );
}
found = false;
while ( !found ) {
var readString = readNextString();
switch ( readString ) {
case 'POLYGONS':
found = true;
break;
case '':
alert ( 'error while reading ' + url + ' : \n' );
return;
}
}
var numberOfPolygons = parseInt( readNextString() );
var numberOfpolygonElements = parseInt( readNextString() );
index2 = 0;
var connectivity = [];
for ( var p = 0; p != numberOfpolygonElements; p ++ ) {
do {
number = parseInt( line[ columnIndex ] );
columnIndex ++;
if ( columnIndex == lineLength ) {
lineIndex ++;
columnIndex = 0;
if ( lineIndex > lines.length ) {
alert ( 'error while reading ' + url + ' : \n' );
return;
}
line = lines[ lineIndex ].split( ' ' );
lineLength = line.length;
}
} while ( isNaN( number ) )
connectivity[ index2 ] = number;
index2 ++;
if ( index2 == connectivity[ 0 ] + 1 ) {
var triangle = [ 0, 0, 0 ];
index2 = 0;
var numberOfTrianglesInCell = connectivity[ 0 ] - 2;
var vertex1 = triangle[ 0 ] = connectivity[ 1 ];
for ( var i = 0; i < numberOfTrianglesInCell; i ++ ) {
var vertex2 = connectivity[ i + 2 ];
var vertex3 = triangle[ 2 ] = connectivity[ i + 3 ];
f3( vertex1, vertex2, vertex3 );
}
}
}
geometry.computeCentroids();
geometry.computeFaceNormals();
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.VTKLoader2 = function () {};
THREE.VTKLoader2.prototype = new THREE.Loader();
THREE.VTKLoader2.prototype.constructor = THREE.VTKLoader2;
THREE.VTKLoader2.prototype.load = function ( url, callback ) {
var that = this;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if ( xhr.readyState == 4 ) {
if ( xhr.status == 200 || xhr.status == 0 ) {
callback( that.parse( xhr.responseText ) );
} else {
console.error( 'THREE.VTKLoader: Couldn\'t load ' + url + ' (' + xhr.status + ')' );
}
}
};
xhr.open( "GET", url, true );
xhr.send( null );
};
THREE.VTKLoader2.prototype.parse = function ( data ) {
var geometry = new THREE.Geometry();
function vertex( x, y, z ) {
geometry.vertices.push( new THREE.Vector3( x, y, z ) );
}
function face3( a, b, c ) {
geometry.faces.push( new THREE.Face3( a, b, c ) );
}
var pattern, result;
// float float float
pattern = /([\d|\.|\+|\-|e]+) ([\d|\.|\+|\-|e]+) ([\d|\.|\+|\-|e]+)/g;
while ( ( result = pattern.exec( data ) ) != null ) {
// ["1.0 2.0 3.0", "1.0", "2.0", "3.0"]
vertex( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) );
}
// 3 int int int
pattern = /3 ([\d]+) ([\d]+) ([\d]+) /g;
while ( ( result = pattern.exec( data ) ) != null ) {
// ["3 1 2 3", "1", "2", "3"]
face3( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ) );
}
geometry.computeCentroids();
geometry.computeFaceNormals();
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
......@@ -109,7 +109,7 @@ THREE.CTMLoader.prototype.load = function( url, callback, useWorker, useBuffers,
if ( useWorker ) {
var worker = new Worker( "js/ctm/CTMWorker.js" );
var worker = new Worker( "js/loaders/ctm/CTMWorker.js" );
worker.onmessage = function( event ) {
......
此差异已折叠。
......@@ -9,7 +9,7 @@
font-family: Monospace;
background-color: #000;
margin: 0px;
overflow: hidden;
/*overflow: hidden;*/
}
</style>
</head>
......@@ -19,9 +19,10 @@
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
<script src="../src/core/Geometry.js"></script>
<script src="js/CurveExtras.js"></script>
<script src="js/UVsUtils.js"></script>
<script src="../src/extras/geometries/ParametricGeometry.js"></script>
<script src="../src/extras/geometries/ParametricGeometries.js"></script>
<script>
......@@ -69,11 +70,11 @@
var radius = 150, tube = 10, segmentsR = 50, segmentsT = 20;
var GrannyKnot = new THREE.Curves.GrannyKnot();
var torus = new THREE.TorusKnotGeometry( radius, tube, segmentsR, segmentsT, p , q, heightScale );
// var torus = new THREE.TorusKnotGeometry( radius, tube, segmentsR, segmentsT, p , q, heightScale );
var torus2 = new THREE.TorusKnotGeometry2( radius, tube, segmentsR, segmentsT, p , q, heightScale );
var sphere = new THREE.SphereGeometry( 75, 20, 10 );
// var sphere = new THREE.SphereGeometry( 75, 20, 10 );
var sphere2 = new THREE.SphereGeometry2( 75, 20, 10 );
var tube = new THREE.TubeGeometry(GrannyKnot, 150, 2, 8, true, false);
// var tube = new THREE.TubeGeometry(GrannyKnot, 150, 2, 8, true, false);
var tube2 = new THREE.TubeGeometry2(GrannyKnot, 150, 2, 8, true, false);
......@@ -86,46 +87,68 @@
// scene.add( object );
// }
object = THREE.SceneUtils.createMultiMaterialObject( torus, materials );
console.log(THREE.ParametricGeometries);
var geo;
// Klein Bottle
geo = new THREE.ParametricGeometry(THREE.ParametricGeometries.klein, 20, 20);
object = THREE.SceneUtils.createMultiMaterialObject( geo, materials );
object.children[ 0 ].doubleSided = true;
object.position.set( 0, 0, 0 );
object.scale.multiplyScalar(10);
scene.add( object );
// Mobius Strip
geo = new THREE.ParametricGeometry(THREE.ParametricGeometries.mobius, 20, 20);
object = THREE.SceneUtils.createMultiMaterialObject( geo, materials );
// object.children[ 0 ].doubleSided = true;
object.position.set( 10, 0, 0 );
object.scale.multiplyScalar(100);
scene.add( object );
// var geo = new THREE.ParametricGeometry(THREE.ParametricGeometries.plane(200, 200), 10, 10);
// THREE.UVsDebug( geo );
// document.body.appendChild( THREE.UVsDebug( geo ));
// object = THREE.SceneUtils.createMultiMaterialObject( geo, materials );
// object = THREE.SceneUtils.createMultiMaterialObject( torus, materials );
// object.position.set( 0, 0, 0 );
// scene.add( object );
object = THREE.SceneUtils.createMultiMaterialObject( torus2, materials );
object.position.set( 0, 100, 0 );
scene.add( object );
object.children[ 0 ].doubleSided = true;
object = THREE.SceneUtils.createMultiMaterialObject( sphere, materials );
object.position.set( 500, 0, 0 );
scene.add( object );
// object = THREE.SceneUtils.createMultiMaterialObject( sphere, materials );
// object.position.set( 500, 0, 0 );
// scene.add( object );
object = THREE.SceneUtils.createMultiMaterialObject( sphere2, materials );
object.position.set( 200, 0, 0 );
scene.add( object );
object = THREE.SceneUtils.createMultiMaterialObject( tube, materials );
object.position.set( 0, 0, 0 );
scene.add( object );
// object = THREE.SceneUtils.createMultiMaterialObject( tube, materials );
// object.position.set( 0, 0, 0 );
// scene.add( object );
object = THREE.SceneUtils.createMultiMaterialObject( tube2, materials );
object.position.set( 100, 0, 0 );
scene.add( object );
object = THREE.SceneUtils.createMultiMaterialObject( new THREE.ParametricGeometry(10, 10, klein) , materials );
object.position.set( 100, 0, 0 );
scene.add( object );
object = THREE.SceneUtils.createMultiMaterialObject( new THREE.PlaneGeometry( 400, 400, 4, 4 ), materials );
// object.children[ 0 ].doubleSided = true;
object.position.set( -200, 100, 0 );
scene.add( object );
// object = THREE.SceneUtils.createMultiMaterialObject( new THREE.PlaneGeometry( 400, 400, 4, 4 ), materials );
// // object.children[ 0 ].doubleSided = true;
// object.position.set( -200, 100, 0 );
// scene.add( object );
object = THREE.SceneUtils.createMultiMaterialObject( new THREE.PlaneGeometry2( 400, 400, 4, 4 ), materials );
// object = THREE.SceneUtils.createMultiMaterialObject( new THREE.PlaneGeometry2( 400, 400, 4, 4 ), materials );
// object.children[ 0 ].doubleSided = true;
object.position.set( -200, 100, 0 );
scene.add( object );
// object.position.set( -200, 100, 0 );
// scene.add( object );
object = new THREE.AxisHelper();
object.position.set( 200, 0, -200 );
......
......@@ -150,8 +150,8 @@
//geometry.computeFaceNormals();
//geometry.computeVertexNormals();
mesh.geometry.__dirtyVertices = true;
//mesh.geometry.__dirtyNormals = true;
mesh.geometry.verticesNeedUpdate = true;
//mesh.geometry.normalsNeedUpdate = true;
controls.update( delta );
renderer.render( scene, camera );
......
......@@ -224,13 +224,12 @@
smooth = THREE.GeometryUtils.clone( geometry );
// mergeVertices(); is run in case of duplicated vertices
if (! (geometry instanceof THREE.LatheGeometry) ) {
smooth.mergeVertices();
}
smooth.mergeVertices();
smooth.computeCentroids();
smooth.computeFaceNormals();
smooth.computeVertexNormals();
// smooth.computeCentroids();
// smooth.computeFaceNormals();
// smooth.computeVertexNormals();
modifier.modify( smooth );
updateInfo();
......
......@@ -217,8 +217,6 @@
container.appendChild( renderer.domElement );
mouse = new THREE.Vector3( 0, 0, 1 );
projector = new THREE.Projector();
ray = new THREE.Ray( camera.position );
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
......
......@@ -226,8 +226,6 @@
renderer.gammaOutput = true;
renderer.physicallyBasedShading = true;
renderer.sortObjects = false;
// STATS
stats = new Stats();
......
......@@ -34,6 +34,8 @@
<script src="../build/Three.js"></script>
<script src="js/loaders/ColladaLoader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
......
......@@ -36,8 +36,9 @@
<script src="../build/Three.js"></script>
<script src="js/Detector.js"></script>
<script src="js/loaders/ColladaLoader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
<script>
......
......@@ -37,9 +37,9 @@
<script src="../build/Three.js"></script>
<script src="js/ctm/lzma.js"></script>
<script src="js/ctm/ctm.js"></script>
<script src="js/ctm/CTMLoader.js"></script>
<script src="js/loaders/ctm/lzma.js"></script>
<script src="js/loaders/ctm/ctm.js"></script>
<script src="js/loaders/ctm/CTMLoader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
......
......@@ -39,9 +39,9 @@
<script src="../build/Three.js"></script>
<script src="js/ctm/lzma.js"></script>
<script src="js/ctm/ctm.js"></script>
<script src="js/ctm/CTMLoader.js"></script>
<script src="js/loaders/ctm/lzma.js"></script>
<script src="js/loaders/ctm/ctm.js"></script>
<script src="js/loaders/ctm/CTMLoader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
......
......@@ -34,6 +34,8 @@
<script src="../build/Three.js"></script>
<script src="js/loaders/ColladaLoader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
......
<!doctype html>
<html lang="en">
<head>
<title>three.js webgl - loaders - OBJ loader</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
font-family: Monospace;
background-color: #000;
color: #fff;
margin: 0px;
overflow: hidden;
}
#info {
color: #fff;
position: absolute;
top: 10px;
width: 100%;
text-align: center;
z-index: 100;
display:block;
}
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
</style>
</head>
<body>
<div id="info">
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - OBJLoader test
</div>
<script src="../build/Three.js"></script>
<script src="js/loaders/OBJLoader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
<script>
var container, stats;
var camera, scene, renderer;
var mouseX = 0, mouseY = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.z = 100;
scene.add( camera );
var ambient = new THREE.AmbientLight( 0x101030 );
scene.add( ambient );
var directionalLight = new THREE.DirectionalLight( 0xffeedd );
directionalLight.position.set( 0, 0, 1 ).normalize();
scene.add( directionalLight );
var loader = new THREE.OBJLoader();
loader.load( "obj/male02/male02.obj", function ( objects ) {
for ( var i = 0; i < objects.length; i ++ ) {
var object = objects[ i ];
object.position.y = - 80;
scene.add( object );
}
} );
// RENDERER
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
}
function onDocumentMouseMove( event ) {
mouseX = ( event.clientX - windowHalfX ) / 2;
mouseY = ( event.clientY - windowHalfY ) / 2;
}
//
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
camera.position.x += ( mouseX - camera.position.x ) * .05;
camera.position.y += ( - mouseY - camera.position.y ) * .05;
camera.lookAt( scene.position );
renderer.render( scene, camera );
}
</script>
</body>
</html>
......@@ -33,6 +33,7 @@
</div>
<script src="../build/Three.js"></script>
<script src="js/loaders/UTF8Loader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
......
<!doctype html>
<html lang="en">
<head>
<title>three.js webgl - loaders - vtk loader</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
font-family: Monospace;
background-color: #000;
color: #fff;
margin: 0px;
overflow: hidden;
}
#info {
color: #fff;
position: absolute;
top: 10px;
width: 100%;
text-align: center;
z-index: 100;
display:block;
}
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
</style>
</head>
<body>
<div id="info">
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> -
vtk format loader test -
model from <a href="http://www.cc.gatech.edu/projects/large_models/" target="_blank">The GeorgiaTech Lagre Geometric Model Archive</a>,
</div>
<script src="../build/Three.js"></script>
<script src="js/loaders/VTKLoader.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container, stats;
var camera, controls, scene, renderer;
var cross;
// scene and camera
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10 );
camera.position.z = 0.2;
scene.add( camera );
controls = new THREE.TrackballControls( camera );
controls.rotateSpeed = 5.0;
controls.zoomSpeed = 5;
controls.panSpeed = 2;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
// light
var dirLight = new THREE.DirectionalLight( 0xffffff );
dirLight.position.set( 200, 200, 1000 ).normalize();
camera.add( dirLight );
camera.add( dirLight.target );
// renderer
renderer = new THREE.WebGLRenderer( { antialias: false } );
renderer.setClearColorHex( 0x000000, 1 );
renderer.setSize( window.innerWidth, window.innerHeight );
container = document.createElement( 'div' );
document.body.appendChild( container );
container.appendChild( renderer.domElement );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild( stats.domElement );
var material = new THREE.MeshLambertMaterial( { color:0xffffff} );
var loader=new THREE.VTKLoader();
loader.load ("models/vtk/bunny.vtk", function(geom){
var mesh = new THREE.Mesh(geom, material );
mesh.doubleSided=true;
mesh.position.setY(-0.09);
scene.add( mesh );
animate();
});
function animate() {
requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
stats.update();
}
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<title>three.js webgl - loaders - vtk loader (experimental)</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
font-family: Monospace;
background-color: #000;
color: #fff;
margin: 0px;
overflow: hidden;
}
#info {
color: #fff;
position: absolute;
top: 10px;
width: 100%;
text-align: center;
z-index: 100;
display:block;
}
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
</style>
</head>
<body>
<div id="info">
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> -
vtk format loader test -
model from <a href="http://www.cc.gatech.edu/projects/large_models/" target="_blank">The GeorgiaTech Lagre Geometric Model Archive</a>,
</div>
<script src="../build/Three.js"></script>
<script src="js/loaders/VTKLoader2.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container, stats;
var camera, controls, scene, renderer;
var cross;
// scene and camera
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10 );
camera.position.z = 0.2;
scene.add( camera );
controls = new THREE.TrackballControls( camera );
controls.rotateSpeed = 5.0;
controls.zoomSpeed = 5;
controls.panSpeed = 2;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
// light
var dirLight = new THREE.DirectionalLight( 0xffffff );
dirLight.position.set( 200, 200, 1000 ).normalize();
camera.add( dirLight );
camera.add( dirLight.target );
// renderer
renderer = new THREE.WebGLRenderer( { antialias: false } );
renderer.setClearColorHex( 0x000000, 1 );
renderer.setSize( window.innerWidth, window.innerHeight );
container = document.createElement( 'div' );
document.body.appendChild( container );
container.appendChild( renderer.domElement );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild( stats.domElement );
var material = new THREE.MeshLambertMaterial( { color:0xffffff} );
var loader=new THREE.VTKLoader2();
loader.load ("models/vtk/bunny.vtk", function(geom){
var mesh = new THREE.Mesh(geom, material );
mesh.doubleSided=true;
mesh.position.setY(-0.09);
scene.add( mesh );
animate();
});
function animate() {
requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
stats.update();
}
</script>
</body>
</html>
......@@ -449,7 +449,7 @@
}
mesh.geometry.__dirtyVertices = true;
mesh.geometry.verticesNeedUpdate = true;
}
......
......@@ -629,7 +629,7 @@
delta = speed * clock.getDelta();
particleCloud.geometry.__dirtyVertices = true;
particleCloud.geometry.verticesNeedUpdate = true;
attributes.size.needsUpdate = true;
attributes.pcolor.needsUpdate = true;
......
......@@ -26,7 +26,7 @@
var camera, scene, renderer;
var mesh, zmesh, lightMesh, geometry;
var objects;
var mouseX = 0, mouseY = 0;
......@@ -51,6 +51,8 @@
camera.position.z = 3200;
scene.add( camera );
objects = [];
var material = new THREE.MeshNormalMaterial( { shading: THREE.SmoothShading } );
var loader = new THREE.JSONLoader();
......@@ -62,14 +64,14 @@
var mesh = new THREE.Mesh( geometry, material );
mesh.position.x = Math.random() * 10000 - 5000;
mesh.position.y = Math.random() * 10000 - 5000;
mesh.position.z = Math.random() * 10000 - 5000;
mesh.position.x = Math.random() * 8000 - 4000;
mesh.position.y = Math.random() * 8000 - 4000;
mesh.position.z = Math.random() * 8000 - 4000;
mesh.rotation.x = Math.random() * 360 * ( Math.PI / 180 );
mesh.rotation.y = Math.random() * 360 * ( Math.PI / 180 );
mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
mesh.matrixAutoUpdate = false;
mesh.updateMatrix();
objects.push( mesh );
scene.add( mesh );
......@@ -79,7 +81,6 @@
renderer = new THREE.WebGLRenderer( { clearColor: 0xffffff } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.sortObjects = false;
container.appendChild( renderer.domElement );
stats = new Stats();
......@@ -112,9 +113,16 @@
camera.position.x += ( mouseX - camera.position.x ) * .05;
camera.position.y += ( - mouseY - camera.position.y ) * .05;
camera.lookAt( scene.position );
for ( var i = 0; i < 5000; i ++ ) {
objects[ i ].rotation.x += 0.01;
objects[ i ].rotation.y += 0.02;
}
renderer.render( scene, camera );
}
......
......@@ -116,7 +116,6 @@
renderer = new THREE.WebGLRenderer( { clearColor: 0x050505, clearAlpha: 1, antialias: FANCY } );
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
renderer.sortObjects = false;
renderer.gammaInput = true;
renderer.gammaOutput = true;
......
<!doctype html>
<html lang="en">
<head>
<title>three.js webgl - performance [static]</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
background:#fff;
padding:0;
margin:0;
font-weight: bold;
overflow:hidden;
}
</style>
</head>
<body>
<script src="../build/Three.js"></script>
<script src="js/Stats.js"></script>
<script>
var container, stats;
var camera, scene, renderer;
var mesh, zmesh, lightMesh, geometry;
var mouseX = 0, mouseY = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 3200;
scene = new THREE.Scene();
scene.add( camera );
var material = new THREE.MeshNormalMaterial( { shading: THREE.SmoothShading } );
var loader = new THREE.JSONLoader();
loader.load( 'obj/Suzanne.js', function ( geometry ) {
geometry.computeVertexNormals();
for ( var i = 0; i < 7700; i ++ ) {
var mesh = new THREE.Mesh( geometry, material );
mesh.position.x = Math.random() * 10000 - 5000;
mesh.position.y = Math.random() * 10000 - 5000;
mesh.position.z = Math.random() * 10000 - 5000;
mesh.rotation.x = Math.random() * 360 * ( Math.PI / 180 );
mesh.rotation.y = Math.random() * 360 * ( Math.PI / 180 );
mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
mesh.matrixAutoUpdate = false;
mesh.updateMatrix();
scene.add( mesh );
}
} );
renderer = new THREE.WebGLRenderer( { antialias: false } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.sortObjects = false;
container.appendChild( renderer.domElement );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
}
function onDocumentMouseMove(event) {
mouseX = ( event.clientX - windowHalfX ) * 10;
mouseY = ( event.clientY - windowHalfY ) * 10;
}
//
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
camera.position.x += ( mouseX - camera.position.x ) * .05;
camera.position.y += ( - mouseY - camera.position.y ) * .05;
camera.lookAt( scene.position );
renderer.render( scene, camera );
}
</script>
</body>
</html>
......@@ -275,8 +275,8 @@
}
geometry.__dirtyVertices = true;
geometry2.__dirtyVertices = true;
geometry.verticesNeedUpdate = true;
geometry2.verticesNeedUpdate = true;
for( i = 0; i < nribbons; i++ ) {
......
......@@ -30,10 +30,11 @@ THREE.CubeGeometry = function ( width, height, depth, segmentsWidth, segmentsHei
geometry.gui.parameters.depth,
geometry.gui.parameters.segmentsWidth,
geometry.gui.parameters.segmentsHeight,
geometry.gui.parameters.segmentsDepth,
geometry.gui.parameters.materials,
geometry.gui.parameters.flipped,
geometry.gui.parameters.sides
geometry.gui.parameters.segmentsDepth
// ,
// geometry.gui.parameters.materials,
// geometry.gui.parameters.flipped,
// geometry.gui.parameters.sides
].join( ', ' ) + ' )';
......
......@@ -27,9 +27,6 @@ var Code = function () {
temp.innerHTML = _codegen( true );
temp = temp.firstChild.nodeValue;
temp = temp.replace("js/Three.js", "../build/Three.js");
temp = temp.replace("js/RequestAnimationFrame.js", "../examples/js/RequestAnimationFrame.js");
console.log('test', temp);
var opener = window.open('','myconsole',
'width=800,height=400'
......@@ -70,6 +67,7 @@ var Code = function () {
var _codegen = function (html) {
var string = '';
console.log(_list);
string += [
'var camera, scene, renderer;',
......@@ -119,8 +117,12 @@ var Code = function () {
if ( html ) {
string = '&lt;!doctype html&gt;\n&lt;html&gt;\n\t&lt;body&gt;\n\t\t&lt;script src=\"js/Three.js\"&gt;&lt;/script&gt;\n\t\t&lt;script src=\"js/RequestAnimationFrame.js\"&gt;&lt;/script&gt;\n\t\t&lt;script&gt;\n' + ( '\n' + string ).replace( /\n/gi, '\n\t\t\t' ) + '\n\n\t\t&lt;/script&gt;\n\t&lt;/body&gt;\n&lt;/html&gt;';
string = '&lt;!doctype html&gt;\n&lt;html&gt;\n\t&lt;body&gt;\
\n\t\t&lt;style&gt; body {background-color: #f0f0f0;} &lt;/style&gt;\
\n\t\t&lt;script src=\"js/Three.js\"&gt;&lt;/script&gt;\
\n\t\t&lt;script&gt;\n'
+ ( '\n' + string ).replace( /\n/gi, '\n\t\t\t' ) +
'\n\n\t\t&lt;/script&gt;\n\t&lt;/body&gt;\n&lt;/html&gt;';
}
return string;
......@@ -132,6 +134,16 @@ var Code = function () {
}
var _strfor = function(str) {
for (var i=1; i<arguments.length; i++) {
if (arguments[i].toFixed) {
arguments[i] = arguments[i].toFixed(2);
}
str = str.replace('{'+(i-1)+'}', arguments[i]);
}
return str;
}
// signals
signals.updated.add( function ( scene ) {
......@@ -144,7 +156,16 @@ var Code = function () {
if ( object.geometry == undefined || object.geometry.gui == undefined ) {
_list.push( 'TODO' );
if (object instanceof THREE.Camera) {
var string = '';
string += _strfor( '\n\tcamera.position.set({0},{1},{2});', object.position.x, object.position.y, object.position.z);
string += _strfor( '\n\tcamera.rotation.set({0},{1},{2});', object.rotation.x, object.rotation.y, object.rotation.z);
_list.push( string );
} else {
_list.push( 'TODO' );
}
continue;
}
......
......@@ -41,6 +41,8 @@ UI.Viewport = function () {
var _scene = new THREE.Scene();
_scene.add(_camera);
/*
var light = new THREE.AmbientLight( 0x404040 );
_scene.add( light );
......@@ -53,6 +55,8 @@ UI.Viewport = function () {
var _plane = new THREE.Mesh( new THREE.PlaneGeometry( 2000, 2000, 8, 8 ), new THREE.MeshBasicMaterial( { color: 0x000000, opacity: 0.25, transparent: true, wireframe: true } ) );
_plane.visible = false;
_plane.geometry.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI / 2 ) );
_sceneHelpers.add( _plane );
var _projector = new THREE.Projector();
......
......@@ -574,6 +574,7 @@ THREE.Geometry.prototype = {
var precisionPoints = 4; // number of decimal points, eg. 4 for epsilon of 0.0001
var precision = Math.pow( 10, precisionPoints );
var i,il, face;
var abcd = 'abcd', o, k, j, jl, u;
for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
......@@ -615,13 +616,31 @@ THREE.Geometry.prototype = {
face.c = changes[ face.c ];
face.d = changes[ face.d ];
// check dups in (a, b, c, d) and convert to -> face3
o = [face.a, face.b, face.c, face.d];
for (k=3;k>0;k--) {
if ( o.indexOf(face[abcd[k]]) != k ) {
// console.log('faces', face.a, face.b, face.c, face.d, 'dup at', k);
o.splice(k, 1);
this.faces[ i ] = new THREE.Face3(o[0], o[1], o[2]);
for (j=0,jl=this.faceVertexUvs.length;j<jl;j++) {
u = this.faceVertexUvs[j][i];
if (u) u.splice(k, 1);
}
break;
}
}
}
}
// Use unique set of vertices
var diff = this.vertices.length - unique.length;
this.vertices = unique;
return diff;
}
......
......@@ -12,7 +12,7 @@
THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
this.elements = new Float32Array(16);
this.elements = new Float32Array( 16 );
this.set(
......@@ -30,8 +30,9 @@ THREE.Matrix4.prototype = {
constructor: THREE.Matrix4,
set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
var te = this.elements;
var te = this.elements;
te[0] = n11; te[4] = n12; te[8] = n13; te[12] = n14;
te[1] = n21; te[5] = n22; te[9] = n23; te[13] = n24;
te[2] = n31; te[6] = n32; te[10] = n33; te[14] = n34;
......@@ -57,9 +58,9 @@ THREE.Matrix4.prototype = {
},
copy: function ( m ) {
var me = m.elements;
var me = m.elements;
this.set(
me[0], me[4], me[8], me[12],
......@@ -74,8 +75,9 @@ THREE.Matrix4.prototype = {
},
lookAt: function ( eye, target, up ) {
var te = this.elements;
var te = this.elements;
var x = THREE.Matrix4.__v1;
var y = THREE.Matrix4.__v2;
var z = THREE.Matrix4.__v3;
......@@ -109,10 +111,10 @@ THREE.Matrix4.prototype = {
},
multiply: function ( a, b ) {
var ae = a.elements,
be = b.elements,
te = this.elements;
var ae = a.elements;
var be = b.elements;
var te = this.elements;
var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
......@@ -134,7 +136,7 @@ THREE.Matrix4.prototype = {
te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
......@@ -155,9 +157,9 @@ THREE.Matrix4.prototype = {
},
multiplyToArray: function ( a, b, r ) {
var te = this.elements;
var te = this.elements;
this.multiply( a, b );
r[ 0 ] = te[0]; r[ 1 ] = te[1]; r[ 2 ] = te[2]; r[ 3 ] = te[3];
......@@ -170,9 +172,9 @@ THREE.Matrix4.prototype = {
},
multiplyScalar: function ( s ) {
var te = this.elements;
var te = this.elements;
te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s;
te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s;
te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s;
......@@ -183,8 +185,9 @@ THREE.Matrix4.prototype = {
},
multiplyVector3: function ( v ) {
var te = this.elements;
var te = this.elements;
var vx = v.x, vy = v.y, vz = v.z;
var d = 1 / ( te[3] * vx + te[7] * vy + te[11] * vz + te[15] );
......@@ -197,8 +200,8 @@ THREE.Matrix4.prototype = {
},
multiplyVector4: function ( v ) {
var te = this.elements;
var te = this.elements;
var vx = v.x, vy = v.y, vz = v.z, vw = v.w;
v.x = te[0] * vx + te[4] * vy + te[8] * vz + te[12] * vw;
......@@ -211,8 +214,8 @@ THREE.Matrix4.prototype = {
},
rotateAxis: function ( v ) {
var te = this.elements;
var te = this.elements;
var vx = v.x, vy = v.y, vz = v.z;
v.x = vx * te[0] + vy * te[4] + vz * te[8];
......@@ -226,8 +229,8 @@ THREE.Matrix4.prototype = {
},
crossVector: function ( a ) {
var te = this.elements;
var te = this.elements;
var v = new THREE.Vector4();
v.x = te[0] * a.x + te[4] * a.y + te[8] * a.z + te[12] * a.w;
......@@ -242,8 +245,8 @@ THREE.Matrix4.prototype = {
determinant: function () {
var te = this.elements;
var te = this.elements;
var n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
var n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
var n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
......@@ -287,8 +290,8 @@ THREE.Matrix4.prototype = {
},
transpose: function () {
var te = this.elements;
var te = this.elements;
var tmp;
tmp = te[1]; te[1] = te[4]; te[4] = tmp;
......@@ -305,7 +308,7 @@ THREE.Matrix4.prototype = {
flattenToArray: function ( flat ) {
var te = this.elements;
var te = this.elements;
flat[ 0 ] = te[0]; flat[ 1 ] = te[1]; flat[ 2 ] = te[2]; flat[ 3 ] = te[3];
flat[ 4 ] = te[4]; flat[ 5 ] = te[5]; flat[ 6 ] = te[6]; flat[ 7 ] = te[7];
flat[ 8 ] = te[8]; flat[ 9 ] = te[9]; flat[ 10 ] = te[10]; flat[ 11 ] = te[11];
......@@ -317,7 +320,7 @@ THREE.Matrix4.prototype = {
flattenToArrayOffset: function( flat, offset ) {
var te = this.elements;
var te = this.elements;
flat[ offset ] = te[0];
flat[ offset + 1 ] = te[1];
flat[ offset + 2 ] = te[2];
......@@ -343,14 +346,16 @@ THREE.Matrix4.prototype = {
},
getPosition: function () {
var te = this.elements;
var te = this.elements;
return THREE.Matrix4.__v1.set( te[12], te[13], te[14] );
},
setPosition: function ( v ) {
var te = this.elements;
var te = this.elements;
te[12] = v.x;
te[13] = v.y;
te[14] = v.z;
......@@ -360,19 +365,22 @@ THREE.Matrix4.prototype = {
},
getColumnX: function () {
var te = this.elements;
var te = this.elements;
return THREE.Matrix4.__v1.set( te[0], te[1], te[2] );
},
getColumnY: function () {
var te = this.elements;
var te = this.elements;
return THREE.Matrix4.__v1.set( te[4], te[5], te[6] );
},
getColumnZ: function() {
var te = this.elements;
var te = this.elements;
return THREE.Matrix4.__v1.set( te[8], te[9], te[10] );
},
......@@ -380,9 +388,9 @@ THREE.Matrix4.prototype = {
getInverse: function ( m ) {
// based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
var te = this.elements;
var me = m.elements;
var te = this.elements;
var me = m.elements;
var n11 = me[0], n12 = me[4], n13 = me[8], n14 = me[12];
var n21 = me[1], n22 = me[5], n23 = me[9], n24 = me[13];
var n31 = me[2], n32 = me[6], n33 = me[10], n34 = me[14];
......@@ -411,8 +419,9 @@ THREE.Matrix4.prototype = {
},
setRotationFromEuler: function( v, order ) {
var te = this.elements;
var te = this.elements;
var x = v.x, y = v.y, z = v.z;
var a = Math.cos( x ), b = Math.sin( x );
var c = Math.cos( y ), d = Math.sin( y );
......@@ -530,8 +539,9 @@ THREE.Matrix4.prototype = {
setRotationFromQuaternion: function( q ) {
var te = this.elements;
var te = this.elements;
var x = q.x, y = q.y, z = q.z, w = q.w;
var x2 = x + x, y2 = y + y, z2 = z + z;
var xx = x * x2, xy = x * y2, xz = x * z2;
......@@ -555,7 +565,8 @@ THREE.Matrix4.prototype = {
},
compose: function ( translation, rotation, scale ) {
var te = this.elements;
var te = this.elements;
var mRotation = THREE.Matrix4.__m1;
var mScale = THREE.Matrix4.__m2;
......@@ -576,8 +587,9 @@ THREE.Matrix4.prototype = {
decompose: function ( translation, rotation, scale ) {
var te = this.elements;
// grab the axis vectors
var te = this.elements;
var x = THREE.Matrix4.__v1;
var y = THREE.Matrix4.__v2;
var z = THREE.Matrix4.__v3;
......@@ -623,8 +635,10 @@ THREE.Matrix4.prototype = {
},
extractPosition: function ( m ) {
var te = this.elements;
var me = m.elements;
var te = this.elements;
var me = m.elements;
te[12] = me[12];
te[13] = me[13];
te[14] = me[14];
......@@ -634,9 +648,10 @@ THREE.Matrix4.prototype = {
},
extractRotation: function ( m ) {
var te = this.elements;
var me = m.elements;
var te = this.elements;
var me = m.elements;
var vector = THREE.Matrix4.__v1;
var scaleX = 1 / vector.set( me[0], me[1], me[2] ).length();
......@@ -662,7 +677,8 @@ THREE.Matrix4.prototype = {
//
translate: function ( v ) {
var te = this.elements;
var te = this.elements;
var x = v.x, y = v.y, z = v.z;
te[12] = te[0] * x + te[4] * y + te[8] * z + te[12];
......@@ -675,7 +691,8 @@ THREE.Matrix4.prototype = {
},
rotateX: function ( angle ) {
var te = this.elements;
var te = this.elements;
var m12 = te[4];
var m22 = te[5];
var m32 = te[6];
......@@ -699,10 +716,11 @@ THREE.Matrix4.prototype = {
return this;
},
},
rotateY: function ( angle ) {
var te = this.elements;
var te = this.elements;
var m11 = te[0];
var m21 = te[1];
var m31 = te[2];
......@@ -729,7 +747,8 @@ THREE.Matrix4.prototype = {
},
rotateZ: function ( angle ) {
var te = this.elements;
var te = this.elements;
var m11 = te[0];
var m21 = te[1];
var m31 = te[2];
......@@ -756,7 +775,9 @@ THREE.Matrix4.prototype = {
},
rotateByAxis: function ( axis, angle ) {
var te = this.elements;
var te = this.elements;
// optimize by checking axis
if ( axis.x === 1 && axis.y === 0 && axis.z === 0 ) {
......@@ -931,7 +952,7 @@ THREE.Matrix4.prototype = {
this.set(
tx * x + c, tx * y - s * z, tx * z + s * y, 0,
tx * x + c, tx * y - s * z, tx * z + s * y, 0,
tx * y + s * z, ty * y + c, ty * z - s * x, 0,
tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
0, 0, 0, 1
......@@ -958,7 +979,8 @@ THREE.Matrix4.prototype = {
},
makeFrustum: function ( left, right, bottom, top, near, far ) {
var te = this.elements;
var te = this.elements;
var x = 2 * near / ( right - left );
var y = 2 * near / ( top - bottom );
......@@ -988,7 +1010,8 @@ THREE.Matrix4.prototype = {
},
makeOrthographic: function ( left, right, top, bottom, near, far ) {
var te = this.elements;
var te = this.elements;
var w = right - left;
var h = top - bottom;
var p = far - near;
......@@ -1008,7 +1031,9 @@ THREE.Matrix4.prototype = {
clone: function () {
var te = this.elements;
var te = this.elements;
return new THREE.Matrix4(
te[0], te[4], te[8], te[12],
......
......@@ -17,6 +17,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
this.noFly = false;
this.lookVertical = true;
this.autoForward = false;
// this.invertVertical = false;
this.activeLook = true;
......@@ -211,7 +212,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
}
this.lon += this.mouseX * actualLookSpeed;
if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed;
if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed; // * this.invertVertical?-1:1;
this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
this.phi = ( 90 - this.lat ) * Math.PI / 180;
......
......@@ -3,71 +3,145 @@
*
* Experimenting of primitive geometry creation using Surface Parametric equations
*/
var sin = Math.sin, cos = Math.cos, pi = Math.PI;
THREE.ParametricGeometries = {
klein: function (v, u) {
u *= pi;
v *= 2 * pi;
u = u * 2;
var x, y, z;
if (u < pi) {
x = 3 * cos(u) * (1 + sin(u)) + (2 * (1 - cos(u) / 2)) * cos(u) * cos(v);
z = -8 * sin(u) - 2 * (1 - cos(u) / 2) * sin(u) * cos(v);
} else {
x = 3 * cos(u) * (1 + sin(u)) + (2 * (1 - cos(u) / 2)) * cos(v + pi);
z = -8 * sin(u);
}
y = -2 * (1 - cos(u) / 2) * sin(v);
return new THREE.Vector3(x, y, z);
},
plane: function (width, height) {
return function(u, v) {
var x = u * width;
var y = 0;
var z = v * height;
console.log(x, y, z);
return new THREE.Vector3(x, y, z);
};
},
mobius: function(u, t) {
// flat mobius strip
// http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
u = u - 0.5;
var v = 2 * pi * t;
var x, y, z;
var a = 2;
x = cos(v) * (a + u * cos(v/2));
y = sin(v) * (a + u * cos(v/2));
z = u * sin(v/2);
return new THREE.Vector3(x, y, z);
},
mobius3d: function(u, t) {
// volumetric mobius strip
u *= pi;
t *= 2 * pi;
u = u * 2
var phi = u / 2
var major = 2.25, a = 0.125, b = 0.65;
var x, y, z;
x = a * cos(t) * cos(phi) - b * sin(t) * sin(phi);
z = a * cos(t) * sin(phi) + b * sin(t) * cos(phi);
y = (major + x) * sin(u);
x = (major + x) * cos(u);
return new THREE.Vector3(x, y, z);
}
};
THREE.TubeGeometry2 = function(path, segments, radius, segmentsRadius, closed, debug) {
this.path = path;
this.segments = segments || 64;
this.radius = radius || 1;
this.segmentsRadius = segmentsRadius || 8;
this.closed = closed || false;
if (debug) this.debug = new THREE.Object3D();
this.path = path;
this.segments = segments || 64;
this.radius = radius || 1;
this.segmentsRadius = segmentsRadius || 8;
this.closed = closed || false;
if (debug) this.debug = new THREE.Object3D();
var scope = this,
var scope = this,
tangent, normal, binormal,
tangent, normal, binormal,
numpoints = this.segments + 1,
numpoints = this.segments + 1,
x, y, z, tx, ty, tz, u, v,
x, y, z, tx, ty, tz, u, v,
cx, cy, pos, pos2 = new THREE.Vector3(),
i, j, ip, jp, a, b, c, d, uva, uvb, uvc, uvd;
cx, cy, pos, pos2 = new THREE.Vector3(),
i, j, ip, jp, a, b, c, d, uva, uvb, uvc, uvd;
var frames = new THREE.TubeGeometry.FrenetFrames(path, segments, closed),
tangents = frames.tangents,
normals = frames.normals,
binormals = frames.binormals;
var frames = new THREE.TubeGeometry.FrenetFrames(path, segments, closed),
tangents = frames.tangents,
normals = frames.normals,
binormals = frames.binormals;
// proxy internals
this.tangents = tangents;
this.normals = normals;
this.binormals = binormals;
// proxy internals
this.tangents = tangents;
this.normals = normals;
this.binormals = binormals;
var ParametricTube = function(u, v) {
v *= 2 * pi;
i = u * (numpoints - 1);
i = Math.floor(i);
var ParametricTube = function(u, v) {
v *= 2 * pi;
i = u * (numpoints - 1);
i = Math.floor(i);
pos = path.getPointAt(u);
pos = path.getPointAt(u);
tangent = tangents[i];
normal = normals[i];
binormal = binormals[i];
tangent = tangents[i];
normal = normals[i];
binormal = binormals[i];
if (scope.debug) {
if (scope.debug) {
scope.debug.add(new THREE.ArrowHelper(tangent, pos, radius, 0x0000ff));
scope.debug.add(new THREE.ArrowHelper(normal, pos, radius, 0xff0000));
scope.debug.add(new THREE.ArrowHelper(binormal, pos, radius, 0x00ff00));
scope.debug.add(new THREE.ArrowHelper(tangent, pos, radius, 0x0000ff));
scope.debug.add(new THREE.ArrowHelper(normal, pos, radius, 0xff0000));
scope.debug.add(new THREE.ArrowHelper(binormal, pos, radius, 0x00ff00));
}
cx = -scope.radius * Math.cos(v); // TODO: Hack: Negating it so it faces outside.
cy = scope.radius * Math.sin(v);
}
cx = -scope.radius * Math.cos(v); // TODO: Hack: Negating it so it faces outside.
cy = scope.radius * Math.sin(v);
pos2.copy(pos);
pos2.x += cx * normal.x + cy * binormal.x;
pos2.y += cx * normal.y + cy * binormal.y;
pos2.z += cx * normal.z + cy * binormal.z;
pos2.copy(pos);
pos2.x += cx * normal.x + cy * binormal.x;
pos2.y += cx * normal.y + cy * binormal.y;
pos2.z += cx * normal.z + cy * binormal.z;
return pos2.clone();
};
return pos2.clone();
};
THREE.ParametricGeometry.call(this, segments, segmentsRadius, ParametricTube);
THREE.ParametricGeometry.call(this, ParametricTube, segments, segmentsRadius);
};
......@@ -89,31 +163,31 @@ THREE.TubeGeometry2.prototype.constructor = THREE.TubeGeometry2;
this.heightScale = heightScale || 1;
var TorusKnotCurve = THREE.Curve.create(
var TorusKnotCurve = THREE.Curve.create(
function() {
},
function() {
},
function(t) {
function(t) {
t *= Math.PI * 2;
t *= Math.PI * 2;
var r = 0.5;
var tx = (1 + r * Math.cos(q * t)) * Math.cos(p * t),
ty = (1 + r * Math.cos(q * t)) * Math.sin(p * t),
tz = r * Math.sin(q * t);
var r = 0.5;
var tx = (1 + r * Math.cos(q * t)) * Math.cos(p * t),
ty = (1 + r * Math.cos(q * t)) * Math.sin(p * t),
tz = r * Math.sin(q * t);
return new THREE.Vector3(tx, ty * heightScale, tz).multiplyScalar(radius);
return new THREE.Vector3(tx, ty * heightScale, tz).multiplyScalar(radius);
}
}
);
var segments = segmentsR;
var radiusSegments = segmentsT;
var extrudePath = new TorusKnotCurve();
);
var segments = segmentsR;
var radiusSegments = segmentsT;
var extrudePath = new TorusKnotCurve();
THREE.TubeGeometry2.call( this, extrudePath, segments, tube, radiusSegments, true, false );
THREE.TubeGeometry2.call( this, extrudePath, segments, tube, radiusSegments, true, false );
};
......@@ -122,44 +196,20 @@ THREE.TorusKnotGeometry2.prototype = new THREE.Geometry();
THREE.TorusKnotGeometry2.prototype.constructor = THREE.TorusKnotGeometry2;
var sin = Math.sin, cos = Math.cos, pi = Math.PI;
function klein(u, v) {
u *= pi;
v *= 2 * pi;
u = u * 2;
var x, y, z;
if (u < pi) {
x = 3 * cos(u) * (1 + sin(u)) + (2 * (1 - cos(u) / 2)) * cos(u) * cos(v);
z = -8 * sin(u) - 2 * (1 - cos(u) / 2) * sin(u) * cos(v);
} else {
x = 3 * cos(u) * (1 + sin(u)) + (2 * (1 - cos(u) / 2)) * cos(v + pi);
z = -8 * sin(u);
}
y = -2 * (1 - cos(u) / 2) * sin(v);
return new THREE.Vector3(x, y, z);
}
THREE.SphereGeometry2 = function(size, x, y) {
function sphere(u, v) {
u *= pi;
v *= 2 * pi;
var x = sin(u) * cos(v);
var y = cos(u);
var z = -sin(u) * sin(v);
function sphere(u, v) {
u *= pi;
v *= 2 * pi;
var x = sin(u) * cos(v);
var y = cos(u);
var z = -sin(u) * sin(v);
return new THREE.Vector3(x, y, z).multiplyScalar(size);
}
return new THREE.Vector3(x, y, z).multiplyScalar(size);
}
THREE.ParametricGeometry.call(this, y, x, sphere);
THREE.ParametricGeometry.call(this, sphere, y, x);
};
......@@ -169,17 +219,16 @@ THREE.SphereGeometry2.prototype.constructor = THREE.SphereGeometry2;
THREE.PlaneGeometry2 = function(width, depth, segmentsWidth, segmentsDepth) {
function plane(u, v) {
console.log('u, v', u, v);
var x = u * width;
var y = 0;
var z = v * depth;
function plane(u, v) {
var x = u * width;
var y = 0;
var z = v * depth;
return new THREE.Vector3(x, y, z);
}
return new THREE.Vector3(x, y, z);
}
THREE.ParametricGeometry.call(this, segmentsWidth, segmentsDepth, plane);
THREE.ParametricGeometry.call(this, plane, segmentsWidth, segmentsDepth);
};
......
/*
/**
* @author zz85 / https://github.com/zz85
* Parametric Surfaces Geometry
* based on the brilliant article by @prideout http://prideout.net/blog/?p=44
*
* new THREE.ParametricGeometry( parametricFunction, uSements, ySegements, useTris );
*
*/
THREE.ParametricGeometry = function(slices, stacks, func) {
THREE.ParametricGeometry = function ( func, slices, stacks, useTris ) {
THREE.Geometry.call(this);
THREE.Geometry.call( this );
var verts = this.vertices,
faces = this.faces,
uvs = this.faceVertexUvs[0];
var verts = this.vertices;
var faces = this.faces;
var uvs = this.faceVertexUvs[ 0 ];
var i, il, theta, j, phi, p;
useTris = (useTris === undefined) ? false : useTris;
for (i = 0; i <= slices; i++) {
theta = i / slices;
var i, il, j, p;
var u, v;
for (j = 0; j < stacks; j++) {
phi = j / stacks;
var stackCount = stacks + 1;
var sliceCount = slices + 1;
for ( i = 0; i <= stacks; i ++ ) {
p = func(theta, phi);
verts.push(p);
v = i / stacks;
}
}
for ( j = 0; j <= slices; j ++ ) {
var v = 0,
next;
u = j / slices;
// Some UV / Face orientation work needs to be done here...
for (i = 0; i < slices; i++) {
for (j = 0; j < stacks; j++) {
next = (j + 1) % stacks;
p = func( u, v );
verts.push( p );
faces.push(new THREE.Face3(v + j, v + next, v + j + stacks));
faces.push(new THREE.Face3(v + next, v + next + stacks, v + j + stacks));
}
}
uvs.push([
new THREE.UV(i / slices, j / stacks),
new THREE.UV(i / slices, (j + 1) / stacks),
new THREE.UV((i + 1) / slices, j / stacks)
]);
uvs.push([
new THREE.UV(i / slices, (j + 1) / stacks),
new THREE.UV((i + 1) / slices, (j + 1) / stacks),
new THREE.UV((i + 1) / slices, j / stacks)
]);
}
v += stacks;
}
var a, b, c, d;
var uva, uvb, uvc, uvd;
for ( i = 0; i < stacks; i ++ ) {
for ( j = 0; j < slices; j ++ ) {
this.computeCentroids();
this.computeFaceNormals();
this.computeVertexNormals();
a = i * sliceCount + j;
b = i * sliceCount + j + 1;
c = (i + 1) * sliceCount + j;
d = (i + 1) * sliceCount + j + 1;
uva = new THREE.UV( i / slices, j / stacks );
uvb = new THREE.UV( i / slices, ( j + 1 ) / stacks );
uvc = new THREE.UV( ( i + 1 ) / slices, j / stacks );
uvd = new THREE.UV( ( i + 1 ) / slices, ( j + 1 ) / stacks );
if ( useTris ) {
faces.push( new THREE.Face3( a, b, c ) );
faces.push( new THREE.Face3( b, d, c ) );
uvs.push( [ uva, uvb, uvc ] );
uvs.push( [ uvb, uvd, uvc ] );
} else {
faces.push( new THREE.Face4( a, b, d, c ) );
uvs.push( [ uva, uvb, uvc, uvd ] );
}
}
}
// console.log(this);
// magic bullet
// var diff = this.mergeVertices();
// console.log('removed ', diff, ' vertices by merging');
this.computeCentroids();
this.computeFaceNormals();
this.computeVertexNormals();
};
THREE.ParametricGeometry.prototype = new THREE.Geometry();
THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
\ No newline at end of file
THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
......@@ -173,7 +173,7 @@ THREE.CameraHelper.prototype.update = function () {
}
this.lineGeometry.__dirtyVertices = true;
this.lineGeometry.verticesNeedUpdate = true;
};
......
......@@ -56,7 +56,18 @@ THREE.ShadowMapPlugin = function ( ) {
_gl.clearColor( 1, 1, 1, 1 );
_gl.disable( _gl.BLEND );
if ( _renderer.shadowMapCullFrontFaces ) _gl.cullFace( _gl.FRONT );
_gl.enable( _gl.CULL_FACE );
if ( _renderer.shadowMapCullFrontFaces ) {
_gl.cullFace( _gl.FRONT );
} else {
_gl.cullFace( _gl.BACK );
}
_renderer.setDepthTest( true );
......@@ -222,7 +233,6 @@ THREE.ShadowMapPlugin = function ( ) {
if ( ! ( object instanceof THREE.Mesh ) || ! ( object.frustumCulled ) || _frustum.contains( object ) ) {
//object.matrixWorld.flattenToArray( object._objectMatrixArray );
object._modelViewMatrix.multiply( shadowCamera.matrixWorldInverse, object.matrixWorld);
webglObject.render = true;
......@@ -244,7 +254,10 @@ THREE.ShadowMapPlugin = function ( ) {
object = webglObject.object;
buffer = webglObject.buffer;
_renderer.setObjectFaces( object );
// culling is overriden globally for all objects
// while rendering depth map
//_renderer.setObjectFaces( object );
if ( object.customDepthMaterial ) {
......@@ -285,14 +298,6 @@ THREE.ShadowMapPlugin = function ( ) {
if ( object.visible && object.castShadow ) {
/*
if ( object.matrixAutoUpdate ) {
object.matrixWorld.flattenToArray( object._objectMatrixArray );
}
*/
object._modelViewMatrix.multiply( shadowCamera.matrixWorldInverse, object.matrixWorld);
_renderer.renderImmediateObject( shadowCamera, scene.__lights, fog, _depthMaterial, object );
......@@ -310,7 +315,12 @@ THREE.ShadowMapPlugin = function ( ) {
_gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
_gl.enable( _gl.BLEND );
if ( _renderer.shadowMapCullFrontFaces ) _gl.cullFace( _gl.BACK );
if ( _renderer.shadowMapCullFrontFaces ) {
_gl.cullFace( _gl.BACK );
}
};
......
......@@ -10,7 +10,6 @@ THREE.BinaryLoader = function ( showStatus ) {
THREE.BinaryLoader.prototype = new THREE.Loader();
THREE.BinaryLoader.prototype.constructor = THREE.BinaryLoader;
THREE.BinaryLoader.prototype.supr = THREE.Loader.prototype;
// Load models generated by slim OBJ converter with BINARY option (converter_obj_three_slim.py -t binary)
......
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.ImageLoader = function () {};
THREE.ImageLoader.prototype = new THREE.Loader();
THREE.ImageLoader.prototype.constructor = THREE.ImageLoader;
THREE.ImageLoader.prototype.load = function ( url, callback ) {
var that = this;
var image = new Image();
image.onload = function () {
callback( image );
that.onLoadComplete();
};
image.crossOrigin = this.crossOrigin;
image.src = path;
that.onLoadStart();
};
......@@ -11,7 +11,6 @@ THREE.JSONLoader = function ( showStatus ) {
THREE.JSONLoader.prototype = new THREE.Loader();
THREE.JSONLoader.prototype.constructor = THREE.JSONLoader;
THREE.JSONLoader.prototype.supr = THREE.Loader.prototype;
THREE.JSONLoader.prototype.load = function ( url, callback, texturePath ) {
......
......@@ -8,7 +8,7 @@ THREE.Loader = function ( showStatus ) {
this.statusDomElement = showStatus ? THREE.Loader.prototype.addStatusElement() : null;
this.onLoadStart = function () {};
this.onLoadProgress = function() {};
this.onLoadProgress = function () {};
this.onLoadComplete = function () {};
};
......@@ -166,8 +166,8 @@ THREE.Loader.prototype = {
if ( wrap ) {
var wrapMap = {
"repeat" : THREE.RepeatWrapping,
"mirror" : THREE.MirroredRepeatWrapping
"repeat": THREE.RepeatWrapping,
"mirror": THREE.MirroredRepeatWrapping
}
if ( wrapMap[ wrap[ 0 ] ] !== undefined ) where[ name ].wrapS = wrapMap[ wrap[ 0 ] ];
......
......@@ -31,6 +31,8 @@ THREE.Material = function ( parameters ) {
this.overdraw = parameters.overdraw !== undefined ? parameters.overdraw : false; // Boolean for fixing antialiasing gaps in CanvasRenderer
this.visible = true;
this.needsUpdate = true;
}
......
......@@ -206,7 +206,7 @@ THREE.CanvasRenderer = function ( parameters ) {
material = element.material;
material = material instanceof THREE.MeshFaceMaterial ? element.faceMaterial : material;
if ( material == null || material.opacity == 0 ) continue;
if ( material === undefined || material.visible === false ) continue;
_bboxRect.empty();
......@@ -529,7 +529,7 @@ THREE.CanvasRenderer = function ( parameters ) {
if ( material instanceof THREE.MeshBasicMaterial ) {
if ( material.map/* && !material.wireframe*/ ) {
if ( material.map ) {
if ( material.map.mapping instanceof THREE.UVMapping ) {
......@@ -574,19 +574,6 @@ THREE.CanvasRenderer = function ( parameters ) {
} else if ( material instanceof THREE.MeshLambertMaterial ) {
if ( material.map && !material.wireframe ) {
if ( material.map.mapping instanceof THREE.UVMapping ) {
_uvs = element.uvs[ 0 ];
patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v, material.map );
}
setBlending( THREE.SubtractiveBlending );
}
if ( _enableLighting ) {
if ( !material.wireframe && material.shading == THREE.SmoothShading && element.vertexNormalsWorld.length == 3 ) {
......@@ -1068,12 +1055,6 @@ THREE.CanvasRenderer = function ( parameters ) {
break;
case THREE.SubtractiveBlending:
_context.globalCompositeOperation = 'darker';
break;
}
_contextGlobalCompositeOperation = value;
......
......@@ -111,7 +111,7 @@ THREE.SVGRenderer = function () {
material = element.material;
material = material instanceof THREE.MeshFaceMaterial ? element.faceMaterial : material;
if ( material == null || material.opacity == 0 ) continue;
if ( material === undefined || material.visible === false ) continue;
_bboxRect.empty();
......
此差异已折叠。
......@@ -41,6 +41,10 @@ COMMON_FILES = [
'lights/DirectionalLight.js',
'lights/PointLight.js',
'lights/SpotLight.js',
'loaders/Loader.js',
'loaders/BinaryLoader.js',
'loaders/JSONLoader.js',
'loaders/SceneLoader.js',
'materials/Material.js',
'materials/LineBasicMaterial.js',
'materials/MeshBasicMaterial.js',
......@@ -126,12 +130,6 @@ EXTRAS_FILES = [
'extras/helpers/ArrowHelper.js',
'extras/helpers/CameraHelper.js',
'extras/modifiers/SubdivisionModifier.js',
'extras/loaders/Loader.js',
'extras/loaders/BinaryLoader.js',
'extras/loaders/ColladaLoader.js',
'extras/loaders/JSONLoader.js',
'extras/loaders/SceneLoader.js',
'extras/loaders/UTF8Loader.js',
'extras/objects/ImmediateRenderObject.js',
'extras/objects/LensFlare.js',
'extras/objects/MorphBlendMesh.js',
......@@ -172,6 +170,10 @@ CANVAS_FILES = [
'lights/AmbientLight.js',
'lights/DirectionalLight.js',
'lights/PointLight.js',
'loaders/Loader.js',
'loaders/BinaryLoader.js',
'loaders/JSONLoader.js',
'loaders/SceneLoader.js',
'materials/Material.js',
'materials/LineBasicMaterial.js',
'materials/MeshBasicMaterial.js',
......@@ -222,6 +224,7 @@ DOM_FILES = [
'cameras/OrthographicCamera.js',
'cameras/PerspectiveCamera.js',
'lights/Light.js',
'loaders/Loader.js',
'materials/Material.js',
'materials/LineBasicMaterial.js',
'materials/MeshBasicMaterial.js',
......@@ -272,6 +275,10 @@ SVG_FILES = [
'lights/AmbientLight.js',
'lights/DirectionalLight.js',
'lights/PointLight.js',
'loaders/Loader.js',
'loaders/BinaryLoader.js',
'loaders/JSONLoader.js',
'loaders/SceneLoader.js',
'materials/Material.js',
'materials/LineBasicMaterial.js',
'materials/MeshBasicMaterial.js',
......@@ -327,6 +334,10 @@ WEBGL_FILES = [
'lights/DirectionalLight.js',
'lights/PointLight.js',
'lights/SpotLight.js',
'loaders/Loader.js',
'loaders/BinaryLoader.js',
'loaders/JSONLoader.js',
'loaders/SceneLoader.js',
'materials/Material.js',
'materials/LineBasicMaterial.js',
'materials/MeshBasicMaterial.js',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册