提交 662cbae9 编写于 作者: A alteredq

Editor: started to implement scene export.

Very much work-in-progress. This is going to take a while. Besides export being tedious by itself, I keep finding many things elsewhere in the codebase that need to be changed or fixed for something like this to work at all.
上级 5670f0e8
......@@ -9486,17 +9486,17 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
if ( g.type === "cube" ) {
geometry = new THREE.CubeGeometry( g.width, g.height, g.depth, g.segmentsWidth, g.segmentsHeight, g.segmentsDepth, null, g.flipped, g.sides );
geometry = new THREE.CubeGeometry( g.width, g.height, g.depth, g.widthSegments, g.heightSegments, g.depthSegments, null, g.flipped, g.sides );
result.geometries[ dg ] = geometry;
} else if ( g.type === "plane" ) {
geometry = new THREE.PlaneGeometry( g.width, g.height, g.segmentsWidth, g.segmentsHeight );
geometry = new THREE.PlaneGeometry( g.width, g.height, g.widthSegments, g.heightSegments );
result.geometries[ dg ] = geometry;
} else if ( g.type === "sphere" ) {
geometry = new THREE.SphereGeometry( g.radius, g.segmentsWidth, g.segmentsHeight );
geometry = new THREE.SphereGeometry( g.radius, g.widthSegments, g.heightSegments );
result.geometries[ dg ] = geometry;
} else if ( g.type === "cylinder" ) {
......@@ -29245,14 +29245,23 @@ THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
* based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
*/
THREE.CubeGeometry = function ( width, height, depth, segmentsWidth, segmentsHeight, segmentsDepth, materials, sides ) {
THREE.CubeGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments, materials, sides ) {
THREE.Geometry.call( this );
var scope = this,
width_half = width / 2,
height_half = height / 2,
depth_half = depth / 2;
var scope = this;
this.width = width;
this.height = height;
this.depth = depth;
this.widthSegments = widthSegments || 1;
this.heightSegments = heightSegments || 1;
this.depthSegments = depthSegments || 1;
var width_half = this.width / 2;
var height_half = this.height / 2;
var depth_half = this.depth / 2;
var mpx, mpy, mpz, mnx, mny, mnz;
......@@ -29298,18 +29307,18 @@ THREE.CubeGeometry = function ( width, height, depth, segmentsWidth, segmentsHei
}
this.sides.px && buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, mpx ); // px
this.sides.nx && buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, mnx ); // nx
this.sides.py && buildPlane( 'x', 'z', 1, 1, width, depth, height_half, mpy ); // py
this.sides.ny && buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, mny ); // ny
this.sides.pz && buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, mpz ); // pz
this.sides.nz && buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, mnz ); // nz
this.sides.px && buildPlane( 'z', 'y', - 1, - 1, this.depth, this.height, width_half, mpx ); // px
this.sides.nx && buildPlane( 'z', 'y', 1, - 1, this.depth, this.height, - width_half, mnx ); // nx
this.sides.py && buildPlane( 'x', 'z', 1, 1, this.width, this.depth, height_half, mpy ); // py
this.sides.ny && buildPlane( 'x', 'z', 1, - 1, this.width, this.depth, - height_half, mny ); // ny
this.sides.pz && buildPlane( 'x', 'y', 1, - 1, this.width, this.height, depth_half, mpz ); // pz
this.sides.nz && buildPlane( 'x', 'y', - 1, - 1, this.width, this.height, - depth_half, mnz ); // nz
function buildPlane( u, v, udir, vdir, width, height, depth, material ) {
var w, ix, iy,
gridX = segmentsWidth || 1,
gridY = segmentsHeight || 1,
gridX = scope.widthSegments,
gridY = scope.heightSegments,
width_half = width / 2,
height_half = height / 2,
offset = scope.vertices.length;
......@@ -29321,12 +29330,12 @@ THREE.CubeGeometry = function ( width, height, depth, segmentsWidth, segmentsHei
} else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
w = 'y';
gridY = segmentsDepth || 1;
gridY = scope.depthSegments;
} else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
w = 'x';
gridX = segmentsDepth || 1;
gridX = scope.depthSegments;
}
......@@ -30481,16 +30490,26 @@ THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments )
THREE.Geometry.call( this );
var ix, iz,
width_half = width / 2,
height_half = height / 2,
gridX = widthSegments || 1,
gridZ = heightSegments || 1,
gridX1 = gridX + 1,
gridZ1 = gridZ + 1,
segment_width = width / gridX,
segment_height = height / gridZ,
normal = new THREE.Vector3( 0, 0, 1 );
this.width = width;
this.height = height;
this.widthSegments = widthSegments || 1;
this.heightSegments = heightSegments || 1;
var ix, iz;
var width_half = width / 2;
var height_half = height / 2;
var gridX = this.widthSegments;
var gridZ = this.heightSegments;
var gridX1 = gridX + 1;
var gridZ1 = gridZ + 1;
var segment_width = this.width / gridX;
var segment_height = this.height / gridZ;
var normal = new THREE.Vector3( 0, 0, 1 );
for ( iz = 0; iz < gridZ1; iz ++ ) {
......@@ -30543,7 +30562,10 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
THREE.Geometry.call( this );
radius = radius || 50;
this.radius = radius || 50;
this.widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
this.heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
phiStart = phiStart !== undefined ? phiStart : 0;
phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
......@@ -30551,25 +30573,22 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
thetaStart = thetaStart !== undefined ? thetaStart : 0;
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
var segmentsX = Math.max( 3, Math.floor( widthSegments ) || 8 );
var segmentsY = Math.max( 2, Math.floor( heightSegments ) || 6 );
var x, y, vertices = [], uvs = [];
for ( y = 0; y <= segmentsY; y ++ ) {
for ( y = 0; y <= this.heightSegments; y ++ ) {
var verticesRow = [];
var uvsRow = [];
for ( x = 0; x <= segmentsX; x ++ ) {
for ( x = 0; x <= this.widthSegments; x ++ ) {
var u = x / segmentsX;
var v = y / segmentsY;
var u = x / this.widthSegments;
var v = y / this.heightSegments;
var vertex = new THREE.Vector3();
vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
vertex.x = - this.radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
vertex.y = this.radius * Math.cos( thetaStart + v * thetaLength );
vertex.z = this.radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
this.vertices.push( vertex );
......@@ -30583,9 +30602,9 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
}
for ( y = 0; y < segmentsY; y ++ ) {
for ( y = 0; y < this.heightSegments; y ++ ) {
for ( x = 0; x < segmentsX; x ++ ) {
for ( x = 0; x < this.widthSegments; x ++ ) {
var v1 = vertices[ y ][ x + 1 ];
var v2 = vertices[ y ][ x ];
......@@ -30602,12 +30621,12 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
var uv3 = uvs[ y + 1 ][ x ].clone();
var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
if ( Math.abs( this.vertices[ v1 ].y ) == radius ) {
if ( Math.abs( this.vertices[ v1 ].y ) === this.radius ) {
this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
} else if ( Math.abs( this.vertices[ v3 ].y ) == radius ) {
} else if ( Math.abs( this.vertices[ v3 ].y ) === this.radius ) {
this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
......@@ -30626,7 +30645,7 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
this.computeCentroids();
this.computeFaceNormals();
this.boundingSphere = { radius: radius };
this.boundingSphere = { radius: this.radius };
};
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -48,6 +48,7 @@
<script src="../examples/js/loaders/ctm/ctm.js"></script>
<script src="../examples/js/loaders/ctm/CTMLoader.js"></script>
<script src="../examples/js/exporters/GeometryExporter.js"></script>
<script src="../examples/js/exporters/SceneExporter.js"></script>
<script src="js/libs/signals.min.js"></script>
......
......@@ -17,6 +17,7 @@ Sidebar.Outliner = function ( signals ) {
container.setBorderTop( '1px solid #ccc' );
container.add( new UI.Text().setValue( 'SCENE' ).setColor( '#666' ) );
container.add( new UI.Button( 'absolute' ).setRight( '8px' ).setTop( '5px' ).setLabel( 'Export' ).onClick( exportScene ) );
container.add( new UI.Break(), new UI.Break() );
//var sceneGraph = new UI.Select().setMultiple( true ).setWidth( '100%' ).setHeight('140px').setColor( '#444' ).setFontSize( '12px' ).onChange( update );
......@@ -74,7 +75,7 @@ Sidebar.Outliner = function ( signals ) {
var child = object.children[ key ];
options[ child.id ] = '<div class="option_item">'+pad + '+ ' + child.name + ' <span class="object_type">[' + getObjectType( child ) + ']</span></div>';
options[ child.id ] = '<div class="option_item">' + pad + '+ ' + child.name + ' <span class="object_type">[' + getObjectType( child ) + ']</span></div>';
createList( child, pad + '&nbsp;&nbsp;&nbsp;' );
......@@ -92,6 +93,18 @@ Sidebar.Outliner = function ( signals ) {
} );
function exportScene() {
var output = new THREE.SceneExporter().parse( scene );
var blob = new Blob( [ output ], { type: 'text/json' } );
var objectURL = URL.createObjectURL( blob );
window.open( objectURL, '_blank' );
window.focus();
}
return container;
}
......@@ -28,7 +28,7 @@ Sidebar.Properties.Geometry = function ( signals ) {
container.setPadding( '10px' );
container.add( new UI.Text().setValue( 'GEOMETRY' ).setColor( '#666' ) );
container.add( new UI.Button( 'absolute' ).setRight( '0px' ).setLabel( 'Export' ).onClick( exportGeometry ) );
container.add( new UI.Button( 'absolute' ).setRight( '8px' ).setTop( '5px' ).setLabel( 'Export' ).onClick( exportGeometry ) );
container.add( new UI.Break(), new UI.Break() );
// name
......
......@@ -164,7 +164,8 @@ THREE.GeometryExporter.prototype = {
var output = [
'{',
' "metadata": {',
' "formatVersion" : 3',
' "formatVersion" : 3.1,',
' "generatedBy" : "GeometryExporter"',
' },',
' "vertices": ' + JSON.stringify( vertices ) + ',',
' "normals": ' + JSON.stringify( normals ) + ',',
......
/**
* @author alteredq / http://alteredqualia.com/
*/
THREE.SceneExporter = function () {};
THREE.SceneExporter.prototype = {
constructor: THREE.SceneExporter,
parse: function ( scene ) {
var position = Vector3String( scene.position );
var rotation = Vector3String( scene.rotation );
var scale = Vector3String( scene.scale );
// todo: extract all scene elements
var nobjects = 0;
var ngeometries = 0;
var nmaterials = 0;
var ntextures = 0;
var objectsArray = [];
var geometriesArray = [];
var geometriesMap = {};
// todo: make object creation properly recursive
scene.traverse( function ( node ) {
if ( node instanceof THREE.Mesh ) {
objectsArray.push( ObjectString( node ) );
nobjects += 1;
if ( ! ( node.geometry.id in geometriesMap ) ) {
geometriesMap[ node.geometry.id ] = true;
geometriesArray.push( GeometryString( node.geometry ) );
ngeometries += 1;
}
}
} );
var objects = objectsArray.join( ",\n\t" );
var geometries = geometriesArray.join( ",\n\t" );
var materials = "";
var textures = "";
var cameras = "";
var lights = "";
// todo: get somehow these from Viewport's renderer
var bgcolor = ColorString( new THREE.Color( 0xaaaaaa ) );
var bgalpha = 1.0;
var defcamera = LabelString( "default_camera" );
//
function Vector3String( v ) {
return "[" + v.x + "," + v.y + "," + v.z + "]";
}
function ColorString( c ) {
return "[" + c.r.toFixed( 3 ) + "," + c.g.toFixed( 3 ) + "," + c.b.toFixed( 3 ) + "]";
}
function LabelString( s ) {
return '"' + s + '"';
}
//
function ObjectString( o ) {
var output = [
'\t\t' + LabelString( getObjectName( o ) ) + ' : {',
' "geometry" : ' + LabelString( getGeometryName( o.geometry ) ) + ',',
' "materials": [ ' + LabelString( getMaterialName( o.material ) ) + ' ],',
' "position" : ' + Vector3String( o.position ) + ',',
' "rotation" : ' + Vector3String( o.rotation ) + ',',
' "scale" : ' + Vector3String( o.scale ) + ',',
' "visible" : ' + o.visible,
'}'
].join( '\n\t\t' );
return output;
}
function GeometryString( g ) {
if ( g instanceof THREE.SphereGeometry ) {
var output = [
'\t\t' + LabelString( getGeometryName( g ) ) + ': {',
' "type" : "sphere",',
' "radius" : ' + g.radius + ',',
' "widthSegments" : ' + g.widthSegments + ',',
' "heightSegments" : ' + g.heightSegments + ',',
'}',
].join( '\n\t\t' );
} else if ( g instanceof THREE.CubeGeometry ) {
var output = [
'\t\t' + LabelString( getGeometryName( g ) ) + ': {',
' "type" : "cube",',
' "width" : ' + g.width + ',',
' "height" : ' + g.height + ',',
' "depth" : ' + g.depth + ',',
' "widthSegments" : ' + g.widthSegments + ',',
' "heightSegments" : ' + g.heightSegments + ',',
' "depthSegments" : ' + g.depthSegments + ',',
'}',
].join( '\n\t\t' );
} else if ( g instanceof THREE.PlaneGeometry ) {
var output = [
'\t\t' + LabelString( getGeometryName( g ) ) + ': {',
' "type" : "plane",',
' "width" : ' + g.width + ',',
' "height" : ' + g.height + ',',
' "widthSegments" : ' + g.widthSegments + ',',
' "heightSegments" : ' + g.heightSegments + ',',
'}',
].join( '\n\t\t' );
}
return output;
}
function getObjectName( o ) {
return o.name ? o.name : "Object_" + o.id;
}
function getGeometryName( g ) {
return g.name ? g.name : "Geometry_" + g.id;
}
function getMaterialName( m ) {
return m.name ? m.name : "Material_" + m.id;
}
//
var output = [
'{',
' "metadata": {',
' "formatVersion" : 3.1,',
' "type" : "scene",',
' "generatedBy" : "SceneExporter",',
' "objects" : ' + nobjects + ',',
' "geometries" : ' + ngeometries + ',',
' "materials" : ' + nmaterials + ',',
' "textures" : ' + ntextures,
' },',
'',
' "urlBaseType": "relativeToScene",',
'',
' "objects" :',
' {',
objects,
' },',
'',
' "geometries" :',
' {',
geometries,
' },',
'',
' "materials" :',
' {',
materials,
' },',
'',
' "textures" :',
' {',
textures,
' },',
'',
' "cameras" :',
' {',
cameras,
' },',
'',
' "lights" :',
' {',
lights,
' },',
'',
' "transform" :',
' {',
' "position" : ' + position + ',',
' "rotation" : ' + rotation + ',',
' "scale" : ' + scale + ',',
' },',
'',
' "defaults" :',
' {',
' "bgcolor" : ' + bgcolor + ',',
' "bgalpha" : ' + bgalpha + ',',
' "camera" : ' + defcamera,
' }',
'}'
].join( '\n' );
return output;
}
}
......@@ -249,9 +249,9 @@
"width" : 10,
"height": 10,
"depth" : 10,
"segmentsWidth" : 1,
"segmentsHeight" : 1,
"segmentsDepth" : 1,
"widthSegments" : 1,
"heightSegments" : 1,
"depthSegments" : 1,
"flipped" : false,
"sides" : { "px": true, "nx": true, "py": true, "ny": true, "pz": true, "nz": true }
},
......@@ -261,9 +261,9 @@
"width" : 10,
"height": 10,
"depth" : 10,
"segmentsWidth" : 1,
"segmentsHeight" : 1,
"segmentsDepth" : 1,
"widthSegments" : 1,
"heightSegments" : 1,
"depthSegments" : 1,
"flipped" : false,
"sides" : { "px": true, "nx": true, "py": true, "ny": true, "pz": true, "nz": true }
},
......@@ -273,9 +273,9 @@
"width" : 10,
"height": 10,
"depth" : 10,
"segmentsWidth" : 1,
"segmentsHeight" : 1,
"segmentsDepth" : 1,
"widthSegments" : 1,
"heightSegments" : 1,
"depthSegments" : 1,
"flipped" : false,
"sides" : { "px": true, "nx": true, "py": true, "ny": true, "pz": true, "nz": true }
},
......@@ -284,30 +284,30 @@
"type" : "plane",
"width" : 10,
"height" : 10,
"segmentsWidth" : 50,
"segmentsHeight" : 50
"widthSegments" : 50,
"heightSegments" : 50
},
"quad": {
"type" : "plane",
"width" : 10,
"height" : 10,
"segmentsWidth" : 1,
"segmentsHeight" : 1
"widthSegments" : 1,
"heightSegments" : 1
},
"sphere": {
"type" : "sphere",
"radius" : 5,
"segmentsWidth" : 32,
"segmentsHeight" : 16
"widthSegments" : 32,
"heightSegments" : 16
},
"sphere_uvs": {
"type" : "sphere",
"radius" : 5,
"segmentsWidth" : 32,
"segmentsHeight" : 16
"widthSegments" : 32,
"heightSegments" : 16
},
"icosahedron": {
......
......@@ -3,14 +3,23 @@
* based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
*/
THREE.CubeGeometry = function ( width, height, depth, segmentsWidth, segmentsHeight, segmentsDepth, materials, sides ) {
THREE.CubeGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments, materials, sides ) {
THREE.Geometry.call( this );
var scope = this,
width_half = width / 2,
height_half = height / 2,
depth_half = depth / 2;
var scope = this;
this.width = width;
this.height = height;
this.depth = depth;
this.widthSegments = widthSegments || 1;
this.heightSegments = heightSegments || 1;
this.depthSegments = depthSegments || 1;
var width_half = this.width / 2;
var height_half = this.height / 2;
var depth_half = this.depth / 2;
var mpx, mpy, mpz, mnx, mny, mnz;
......@@ -56,18 +65,18 @@ THREE.CubeGeometry = function ( width, height, depth, segmentsWidth, segmentsHei
}
this.sides.px && buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, mpx ); // px
this.sides.nx && buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, mnx ); // nx
this.sides.py && buildPlane( 'x', 'z', 1, 1, width, depth, height_half, mpy ); // py
this.sides.ny && buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, mny ); // ny
this.sides.pz && buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, mpz ); // pz
this.sides.nz && buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, mnz ); // nz
this.sides.px && buildPlane( 'z', 'y', - 1, - 1, this.depth, this.height, width_half, mpx ); // px
this.sides.nx && buildPlane( 'z', 'y', 1, - 1, this.depth, this.height, - width_half, mnx ); // nx
this.sides.py && buildPlane( 'x', 'z', 1, 1, this.width, this.depth, height_half, mpy ); // py
this.sides.ny && buildPlane( 'x', 'z', 1, - 1, this.width, this.depth, - height_half, mny ); // ny
this.sides.pz && buildPlane( 'x', 'y', 1, - 1, this.width, this.height, depth_half, mpz ); // pz
this.sides.nz && buildPlane( 'x', 'y', - 1, - 1, this.width, this.height, - depth_half, mnz ); // nz
function buildPlane( u, v, udir, vdir, width, height, depth, material ) {
var w, ix, iy,
gridX = segmentsWidth || 1,
gridY = segmentsHeight || 1,
gridX = scope.widthSegments,
gridY = scope.heightSegments,
width_half = width / 2,
height_half = height / 2,
offset = scope.vertices.length;
......@@ -79,12 +88,12 @@ THREE.CubeGeometry = function ( width, height, depth, segmentsWidth, segmentsHei
} else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
w = 'y';
gridY = segmentsDepth || 1;
gridY = scope.depthSegments;
} else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
w = 'x';
gridX = segmentsDepth || 1;
gridX = scope.depthSegments;
}
......
......@@ -7,16 +7,26 @@ THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments )
THREE.Geometry.call( this );
var ix, iz,
width_half = width / 2,
height_half = height / 2,
gridX = widthSegments || 1,
gridZ = heightSegments || 1,
gridX1 = gridX + 1,
gridZ1 = gridZ + 1,
segment_width = width / gridX,
segment_height = height / gridZ,
normal = new THREE.Vector3( 0, 0, 1 );
this.width = width;
this.height = height;
this.widthSegments = widthSegments || 1;
this.heightSegments = heightSegments || 1;
var ix, iz;
var width_half = width / 2;
var height_half = height / 2;
var gridX = this.widthSegments;
var gridZ = this.heightSegments;
var gridX1 = gridX + 1;
var gridZ1 = gridZ + 1;
var segment_width = this.width / gridX;
var segment_height = this.height / gridZ;
var normal = new THREE.Vector3( 0, 0, 1 );
for ( iz = 0; iz < gridZ1; iz ++ ) {
......
......@@ -6,7 +6,10 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
THREE.Geometry.call( this );
radius = radius || 50;
this.radius = radius || 50;
this.widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
this.heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
phiStart = phiStart !== undefined ? phiStart : 0;
phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
......@@ -14,25 +17,22 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
thetaStart = thetaStart !== undefined ? thetaStart : 0;
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
var segmentsX = Math.max( 3, Math.floor( widthSegments ) || 8 );
var segmentsY = Math.max( 2, Math.floor( heightSegments ) || 6 );
var x, y, vertices = [], uvs = [];
for ( y = 0; y <= segmentsY; y ++ ) {
for ( y = 0; y <= this.heightSegments; y ++ ) {
var verticesRow = [];
var uvsRow = [];
for ( x = 0; x <= segmentsX; x ++ ) {
for ( x = 0; x <= this.widthSegments; x ++ ) {
var u = x / segmentsX;
var v = y / segmentsY;
var u = x / this.widthSegments;
var v = y / this.heightSegments;
var vertex = new THREE.Vector3();
vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
vertex.x = - this.radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
vertex.y = this.radius * Math.cos( thetaStart + v * thetaLength );
vertex.z = this.radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
this.vertices.push( vertex );
......@@ -46,9 +46,9 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
}
for ( y = 0; y < segmentsY; y ++ ) {
for ( y = 0; y < this.heightSegments; y ++ ) {
for ( x = 0; x < segmentsX; x ++ ) {
for ( x = 0; x < this.widthSegments; x ++ ) {
var v1 = vertices[ y ][ x + 1 ];
var v2 = vertices[ y ][ x ];
......@@ -65,12 +65,12 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
var uv3 = uvs[ y + 1 ][ x ].clone();
var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
if ( Math.abs( this.vertices[ v1 ].y ) == radius ) {
if ( Math.abs( this.vertices[ v1 ].y ) === this.radius ) {
this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
} else if ( Math.abs( this.vertices[ v3 ].y ) == radius ) {
} else if ( Math.abs( this.vertices[ v3 ].y ) === this.radius ) {
this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
......@@ -89,7 +89,7 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
this.computeCentroids();
this.computeFaceNormals();
this.boundingSphere = { radius: radius };
this.boundingSphere = { radius: this.radius };
};
......
......@@ -565,17 +565,17 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
if ( g.type === "cube" ) {
geometry = new THREE.CubeGeometry( g.width, g.height, g.depth, g.segmentsWidth, g.segmentsHeight, g.segmentsDepth, null, g.flipped, g.sides );
geometry = new THREE.CubeGeometry( g.width, g.height, g.depth, g.widthSegments, g.heightSegments, g.depthSegments, null, g.flipped, g.sides );
result.geometries[ dg ] = geometry;
} else if ( g.type === "plane" ) {
geometry = new THREE.PlaneGeometry( g.width, g.height, g.segmentsWidth, g.segmentsHeight );
geometry = new THREE.PlaneGeometry( g.width, g.height, g.widthSegments, g.heightSegments );
result.geometries[ dg ] = geometry;
} else if ( g.type === "sphere" ) {
geometry = new THREE.SphereGeometry( g.radius, g.segmentsWidth, g.segmentsHeight );
geometry = new THREE.SphereGeometry( g.radius, g.widthSegments, g.heightSegments );
result.geometries[ dg ] = geometry;
} else if ( g.type === "cylinder" ) {
......
......@@ -86,6 +86,7 @@ TEMPLATE_SCENE_ASCII = """\
"metadata" :
{
"formatVersion" : 3.1,
"type" : "scene",
"sourceFile" : "%(fname)s",
"generatedBy" : "Blender 2.64 Exporter",
"objects" : %(nobjects)s,
......@@ -94,7 +95,6 @@ TEMPLATE_SCENE_ASCII = """\
"textures" : %(ntextures)s
},
"type" : "scene",
"urlBaseType" : %(basetype)s,
%(sections)s
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册