提交 fda0a0a8 编写于 作者: M Mr.doob

Simplified AxisHelper.

上级 15dbd15b
......@@ -716,8 +716,7 @@ q,o]);g.push([q,p,o])}else{e.push(new THREE.Face4(a,f,j,l));g.push([m,q,p,o])}}t
THREE.ConvexGeometry=function(a){function b(a){var b=a.length();return new THREE.UV(a.x/b,a.y/b)}THREE.Geometry.call(this);for(var c=[[0,1,2],[0,2,1]],d=3;d<a.length;d++){var f=d,e=a[f].clone(),g=e.length();e.x=e.x+g*(Math.random()-0.5)*2E-6;e.y=e.y+g*(Math.random()-0.5)*2E-6;e.z=e.z+g*(Math.random()-0.5)*2E-6;for(var g=[],h=0;h<c.length;){var i=c[h],j=e,l=a[i[0]],n;n=l;var m=a[i[1]],q=a[i[2]],o=new THREE.Vector3,p=new THREE.Vector3;o.sub(q,m);p.sub(n,m);o.crossSelf(p);o.isZero()||o.normalize();n=
o;l=n.dot(l);if(n.dot(j)>=l){for(j=0;j<3;j++){l=[i[j],i[(j+1)%3]];n=true;for(m=0;m<g.length;m++)if(g[m][0]===l[1]&&g[m][1]===l[0]){g[m]=g[g.length-1];g.pop();n=false;break}n&&g.push(l)}c[h]=c[c.length-1];c.pop()}else h++}for(m=0;m<g.length;m++)c.push([g[m][0],g[m][1],f])}f=0;e=Array(a.length);for(d=0;d<c.length;d++){g=c[d];for(h=0;h<3;h++){if(e[g[h]]===void 0){e[g[h]]=f++;this.vertices.push(a[g[h]])}g[h]=e[g[h]]}}for(d=0;d<c.length;d++)this.faces.push(new THREE.Face3(c[d][0],c[d][1],c[d][2]));for(d=
0;d<this.faces.length;d++){g=this.faces[d];this.faceVertexUvs[0].push([b(this.vertices[g.a]),b(this.vertices[g.b]),b(this.vertices[g.c])])}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.ConvexGeometry.prototype=Object.create(THREE.Geometry.prototype);
THREE.AxisHelper=function(){THREE.Object3D.call(this);var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3);a.vertices.push(new THREE.Vector3(0,100,0));var b=new THREE.CylinderGeometry(0,5,25,5,1),c;c=new THREE.Line(a,new THREE.LineBasicMaterial({color:16711680}));c.rotation.z=-Math.PI/2;this.add(c);c=new THREE.Mesh(b,new THREE.MeshBasicMaterial({color:16711680}));c.position.x=100;c.rotation.z=-Math.PI/2;this.add(c);c=new THREE.Line(a,new THREE.LineBasicMaterial({color:65280}));this.add(c);
c=new THREE.Mesh(b,new THREE.MeshBasicMaterial({color:65280}));c.position.y=100;this.add(c);c=new THREE.Line(a,new THREE.LineBasicMaterial({color:255}));c.rotation.x=Math.PI/2;this.add(c);c=new THREE.Mesh(b,new THREE.MeshBasicMaterial({color:255}));c.position.z=100;c.rotation.x=Math.PI/2;this.add(c)};THREE.AxisHelper.prototype=Object.create(THREE.Object3D.prototype);
THREE.AxisHelper=function(){var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3,new THREE.Vector3(1,0,0),new THREE.Vector3,new THREE.Vector3(0,1,0),new THREE.Vector3,new THREE.Vector3(0,0,1));a.colors.push(new THREE.Color(16711680),new THREE.Color(16755200),new THREE.Color(65280),new THREE.Color(11206400),new THREE.Color(255),new THREE.Color(43775));var b=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors});THREE.Line.call(this,a,b,THREE.LinePieces)};THREE.AxisHelper.prototype=Object.create(THREE.Line.prototype);
THREE.ArrowHelper=function(a,b,c,d){THREE.Object3D.call(this);d===void 0&&(d=16776960);c===void 0&&(c=20);var f=new THREE.Geometry;f.vertices.push(new THREE.Vector3(0,0,0));f.vertices.push(new THREE.Vector3(0,1,0));this.line=new THREE.Line(f,new THREE.LineBasicMaterial({color:d}));this.add(this.line);f=new THREE.CylinderGeometry(0,0.05,0.25,5,1);this.cone=new THREE.Mesh(f,new THREE.MeshBasicMaterial({color:d}));this.cone.position.set(0,1,0);this.add(this.cone);if(b instanceof THREE.Vector3)this.position=
b;this.setDirection(a);this.setLength(c)};THREE.ArrowHelper.prototype=Object.create(THREE.Object3D.prototype);THREE.ArrowHelper.prototype.setDirection=function(a){var b=(new THREE.Vector3(0,1,0)).crossSelf(a),a=Math.acos((new THREE.Vector3(0,1,0)).dot(a.clone().normalize()));this.matrix=(new THREE.Matrix4).makeRotationAxis(b.normalize(),a);this.rotation.setEulerFromRotationMatrix(this.matrix,this.eulerOrder)};THREE.ArrowHelper.prototype.setLength=function(a){this.scale.set(a,a,a)};
THREE.ArrowHelper.prototype.setColor=function(a){this.line.material.color.setHex(a);this.cone.material.color.setHex(a)};
......
......@@ -37,16 +37,13 @@ var Viewport = function ( signals ) {
sceneHelpers.add( selectionBox );
var selectionAxis = new THREE.AxisHelper();
selectionAxis.geometry.applyMatrix( new THREE.Matrix4().makeScale( 100, 100, 100 ) );
selectionAxis.material.depthTest = false;
selectionAxis.material.transparent = true;
selectionAxis.matrixAutoUpdate = false;
selectionAxis.visible = false;
sceneHelpers.add( selectionAxis );
for ( var i = 0; i < selectionAxis.children.length; i ++ ) {
selectionAxis.children[ i ].material.depthTest = false;
selectionAxis.children[ i ].material.transparent = true;
}
//
var scene = new THREE.Scene();
......@@ -136,7 +133,7 @@ var Viewport = function ( signals ) {
signals.objectSelected.add( function ( object ) {
selectionBox.visible = false;
selectionAxis.traverse( function ( object ) { object.visible = false } );
selectionAxis.visible = false;
if ( object !== null && object.geometry ) {
......@@ -188,7 +185,7 @@ var Viewport = function ( signals ) {
selectionAxis.matrixWorld = object.matrixWorld;
selectionBox.visible = true;
selectionAxis.traverse( function ( object ) { object.visible = true } );
selectionAxis.visible = true;
}
......
......@@ -225,13 +225,7 @@
arrow = new THREE.ArrowHelper( new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 0 ), 50, 0xff0000 );
arrow.position.set( -200, 0, -200 );
//scene.add( arrow );
var axis;
axis = new THREE.AxisHelper();
axis.position.set( 200, 0, -200 );
axis.scale.x = axis.scale.y = axis.scale.z = 0.5;
//scene.add( axis );
// scene.add( arrow );
// ground
......
......@@ -113,7 +113,7 @@
object = new THREE.AxisHelper();
object.position.set( 200, 0, -200 );
object.scale.x = object.scale.y = object.scale.z = 0.5;
object.scale.x = object.scale.y = object.scale.z = 50;
scene.add( object );
object = new THREE.ArrowHelper( new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 0 ), 50 );
......
......@@ -159,7 +159,7 @@
object = new THREE.AxisHelper();
object.position.set( 200, 0, -200 );
object.scale.x = object.scale.y = object.scale.z = 0.5;
object.scale.x = object.scale.y = object.scale.z = 50;
scene.add( object );
object = new THREE.ArrowHelper( new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 0 ), 50 );
......
......@@ -104,7 +104,7 @@
object = new THREE.AxisHelper();
object.position.set( 200, 0, -200 );
object.scale.x = object.scale.y = object.scale.z = 0.5;
object.scale.x = object.scale.y = object.scale.z = 50;
scene.add( object );
object = new THREE.ArrowHelper( new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 0 ), 50 );
......
......@@ -20,6 +20,7 @@ THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, d
this.radius = radius || 1;
this.segmentsRadius = segmentsRadius || 8;
this.closed = closed || false;
if ( debug ) this.debug = new THREE.Object3D();
this.grid = [];
......@@ -31,7 +32,7 @@ THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, d
binormal,
numpoints = this.segments + 1,
x, y, z,
tx, ty, tz,
u, v,
......@@ -53,7 +54,6 @@ THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, d
this.normals = normals;
this.binormals = binormals;
function vert( x, y, z ) {
return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
......@@ -61,8 +61,6 @@ THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, d
}
// consruct the grid
for ( i = 0; i < numpoints; i++ ) {
......@@ -79,9 +77,9 @@ THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, d
if ( this.debug ) {
this.debug.add(new THREE.ArrowHelper(tangent, pos, radius, 0x0000ff));
this.debug.add(new THREE.ArrowHelper(normal, pos, radius, 0xff0000));
this.debug.add(new THREE.ArrowHelper(binormal, pos, radius, 0x00ff00));
this.debug.add( new THREE.ArrowHelper(tangent, pos, radius, 0x0000ff ) );
this.debug.add( new THREE.ArrowHelper(normal, pos, radius, 0xff0000 ) );
this.debug.add( new THREE.ArrowHelper(binormal, pos, radius, 0x00ff00 ) );
}
......@@ -92,12 +90,12 @@ THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, d
cx = -this.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
cy = this.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;
this.grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
this.grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
}
}
......
......@@ -5,47 +5,24 @@
THREE.AxisHelper = function () {
THREE.Object3D.call( this );
var geometry = new THREE.Geometry();
var lineGeometry = new THREE.Geometry();
lineGeometry.vertices.push( new THREE.Vector3() );
lineGeometry.vertices.push( new THREE.Vector3( 0, 100, 0 ) );
geometry.vertices.push(
new THREE.Vector3(), new THREE.Vector3( 1, 0, 0 ),
new THREE.Vector3(), new THREE.Vector3( 0, 1, 0 ),
new THREE.Vector3(), new THREE.Vector3( 0, 0, 1 )
);
var coneGeometry = new THREE.CylinderGeometry( 0, 5, 25, 5, 1 );
geometry.colors.push(
new THREE.Color( 0xff0000 ), new THREE.Color( 0xffaa00 ),
new THREE.Color( 0x00ff00 ), new THREE.Color( 0xaaff00 ),
new THREE.Color( 0x0000ff ), new THREE.Color( 0x00aaff )
);
var line, cone;
var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
// x
line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color : 0xff0000 } ) );
line.rotation.z = - Math.PI / 2;
this.add( line );
cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color : 0xff0000 } ) );
cone.position.x = 100;
cone.rotation.z = - Math.PI / 2;
this.add( cone );
// y
line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color : 0x00ff00 } ) );
this.add( line );
cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color : 0x00ff00 } ) );
cone.position.y = 100;
this.add( cone );
// z
line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color : 0x0000ff } ) );
line.rotation.x = Math.PI / 2;
this.add( line );
cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color : 0x0000ff } ) );
cone.position.z = 100;
cone.rotation.x = Math.PI / 2;
this.add( cone );
THREE.Line.call( this, geometry, material, THREE.LinePieces );
};
THREE.AxisHelper.prototype = Object.create( THREE.Object3D.prototype );
THREE.AxisHelper.prototype = Object.create( THREE.Line.prototype );
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册