Added ScaleGeometry and added Monkey Head + more geometries to examples

This commit is contained in:
zz85
2011-10-14 01:37:14 +08:00
parent 0c3f1a336e
commit 4e97d195b0
4 changed files with 65 additions and 11 deletions
+35 -10
View File
@@ -25,6 +25,7 @@
<script src="../src/extras/geometries/CylinderGeometry.js"></script>
<script src="../src/extras/geometries/TorusGeometry.js"></script>
<script src="../src/extras/modifiers/SubdivisionModifier.js"></script>
<script src="../src/extras/modifiers/ScaleModifier.js"></script>
<script src="fonts/helvetiker_regular.typeface.js"></script>
@@ -79,9 +80,17 @@
{type: 'CubeGeometry', args: [ 200, 200, 200, 2, 2, 2, materials ] },
{type: 'TorusGeometry', args: [ 100, 60, 4, 8, Math.PI*2 ] },
{type: 'SphereGeometry', args: [ 100, 3, 3 ] },
{type: 'IcosahedronGeometry', args: [ 1 ], scale: 200 },
{type: 'TorusKnotGeometry', args: [ ], scale:0.25, meshScale:4 },
{type: 'SphereGeometry', args: [ 100, 3, 3 ], meshScale:2 },
{type: 'IcosahedronGeometry', args: [ 1 ], scale: 100, meshScale:2 },
{type: 'CylinderGeometry', args: [ 25, 75, 200, 8, 3 ]} ,
{type: 'OctahedronGeometry', args: [200, 0], meshScale:2 },
{type: 'LatheGeometry', args: [ [
new THREE.Vector3(0,0,0),
new THREE.Vector3(0,50,50),
new THREE.Vector3(0,0,100),
new THREE.Vector3(0,50,150),
new THREE.Vector3(0,0,200) ] ]},
{type: 'TextGeometry', args: ['&', {
size: 200,
height: 50,
@@ -91,17 +100,27 @@
}]},
{type: 'PlaneGeometry', args: [ 200, 200, 4, 4 ] }
];
if (location.protocol !== "file:") {
var loader = new THREE.JSONLoader();
loader.load( 'obj/WaltHeadLo.js', function ( geometry ) {
geometriesParams.push({type: 'WaltHead', args: [ ], scale: 6 });
geometriesParams.push({type: 'WaltHead', args: [ ], meshScale: 6 });
THREE.WaltHead = function() {
return geometry;
return THREE.GeometryUtils.clone(geometry);
};
});
var loader2 = new THREE.JSONLoader();
loader2.load( 'obj/Suzanne.js', function ( geometry ) {
geometriesParams.push({type: 'Suzanne', args: [ ], scale: 100, meshScale:2 });
THREE.Suzanne = function() {
return THREE.GeometryUtils.clone(geometry);
};
} );
@@ -155,6 +174,12 @@
var params = geometriesParams[ geometryIndex ];
geometry = createSomething( THREE[ params.type ], params.args );
// Scale Geometry
if (params.scale) {
var scaler = new THREE.ScaleModifier( new THREE.Vector3(params.scale,params.scale,params.scale));
scaler.modify(geometry);
}
// Cloning original geometry for debuging
@@ -274,11 +299,11 @@
cube = new THREE.Mesh( smooth, meshmaterials );
var toscale = params.scale ? params.scale : 1;
cube.scale.x = toscale;
cube.scale.y = toscale;
cube.scale.z = toscale;
var meshScale = params.meshScale ? params.meshScale : 1;
cube.scale.x = meshScale;
cube.scale.y = meshScale;
cube.scale.z = meshScale;
scene.add( cube );
+28
View File
@@ -0,0 +1,28 @@
/*
* @author zz85 / http://twitter.com/blurspline
*
* Scales a geometry by vector
*/
// Scale from 0,0,0 with (x,y,z)
THREE.ScaleModifier = function( scale /*Vector3*/ ) {
this.scale = scale;
};
THREE.ScaleModifier.prototype.constructor = THREE.ScaleModifier;
THREE.ScaleModifier.prototype.modify = function ( geometry ) {
var i,il;
var scale = this.scale, v;
for (i=0,il=geometry.vertices.length;i<il;i++) {
v = geometry.vertices[i].position;
v.multiplySelf(scale);
}
geometry.computeCentroids();
geometry.computeFaceNormals();
geometry.computeVertexNormals();
};
+1 -1
View File
@@ -504,7 +504,7 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
}
if (sharpEdgeCount>2) {
// TODO
}
F.divideScalar(f);
+1
View File
@@ -117,6 +117,7 @@ EXTRAS_FILES = [
'extras/geometries/TorusGeometry.js',
'extras/geometries/TorusKnotGeometry.js',
'extras/modifiers/SubdivisionModifier.js',
'extras/modifiers/ScaleModifier.js',
'extras/loaders/Loader.js',
'extras/loaders/BinaryLoader.js',
'extras/loaders/ColladaLoader.js',