Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 59 additions & 58 deletions src/helpers/ArrowHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,103 +11,104 @@ import { Vector3 } from '../math/Vector3.js';
const _axis = new Vector3();
let _lineGeometry, _coneGeometry;

function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
class ArrowHelper extends Object3D {

// dir is assumed to be normalized
constructor( dir, origin, length, color, headLength, headWidth ) {

Object3D.call( this );
super();
// dir is assumed to be normalized

this.type = 'ArrowHelper';
this.type = 'ArrowHelper';

if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
if ( length === undefined ) length = 1;
if ( color === undefined ) color = 0xffff00;
if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
if ( length === undefined ) length = 1;
if ( color === undefined ) color = 0xffff00;
if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;

if ( _lineGeometry === undefined ) {
if ( _lineGeometry === undefined ) {

_lineGeometry = new BufferGeometry();
_lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
_lineGeometry = new BufferGeometry();
_lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );

_coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
_coneGeometry.translate( 0, - 0.5, 0 );
_coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
_coneGeometry.translate( 0, - 0.5, 0 );

}
}

this.position.copy( origin );
this.position.copy( origin );

this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
this.line.matrixAutoUpdate = false;
this.add( this.line );
this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
this.line.matrixAutoUpdate = false;
this.add( this.line );

this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
this.cone.matrixAutoUpdate = false;
this.add( this.cone );
this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
this.cone.matrixAutoUpdate = false;
this.add( this.cone );

this.setDirection( dir );
this.setLength( length, headLength, headWidth );
this.setDirection( dir );
this.setLength( length, headLength, headWidth );

}
}

ArrowHelper.prototype = Object.create( Object3D.prototype );
ArrowHelper.prototype.constructor = ArrowHelper;
setDirection( dir ) {

ArrowHelper.prototype.setDirection = function ( dir ) {
// dir is assumed to be normalized

// dir is assumed to be normalized
if ( dir.y > 0.99999 ) {

if ( dir.y > 0.99999 ) {
this.quaternion.set( 0, 0, 0, 1 );

this.quaternion.set( 0, 0, 0, 1 );
} else if ( dir.y < - 0.99999 ) {

} else if ( dir.y < - 0.99999 ) {
this.quaternion.set( 1, 0, 0, 0 );

this.quaternion.set( 1, 0, 0, 0 );
} else {

} else {
_axis.set( dir.z, 0, - dir.x ).normalize();

_axis.set( dir.z, 0, - dir.x ).normalize();
const radians = Math.acos( dir.y );

const radians = Math.acos( dir.y );
this.quaternion.setFromAxisAngle( _axis, radians );

this.quaternion.setFromAxisAngle( _axis, radians );
}

}

};
setLength( length, headLength, headWidth ) {

if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;

ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
this.line.updateMatrix();

if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
this.cone.scale.set( headWidth, headLength, headWidth );
this.cone.position.y = length;
this.cone.updateMatrix();

this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
this.line.updateMatrix();
}

this.cone.scale.set( headWidth, headLength, headWidth );
this.cone.position.y = length;
this.cone.updateMatrix();
setColor( color ) {

};
this.line.material.color.set( color );
this.cone.material.color.set( color );

ArrowHelper.prototype.setColor = function ( color ) {
}

this.line.material.color.set( color );
this.cone.material.color.set( color );
copy( source ) {

};
super.copy( source, false );

ArrowHelper.prototype.copy = function ( source ) {
this.line.copy( source.line );
this.cone.copy( source.cone );

Object3D.prototype.copy.call( this, source, false );
return this;

this.line.copy( source.line );
this.cone.copy( source.cone );
}

return this;
}

};

export { ArrowHelper };
43 changes: 22 additions & 21 deletions src/helpers/AxesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
import { BufferGeometry } from '../core/BufferGeometry.js';

function AxesHelper( size ) {
class AxesHelper extends LineSegments {

size = size || 1;
constructor( size ) {

const vertices = [
0, 0, 0, size, 0, 0,
0, 0, 0, 0, size, 0,
0, 0, 0, 0, 0, size
];
size = size || 1;

const colors = [
1, 0, 0, 1, 0.6, 0,
0, 1, 0, 0.6, 1, 0,
0, 0, 1, 0, 0.6, 1
];
const vertices = [
0, 0, 0, size, 0, 0,
0, 0, 0, 0, size, 0,
0, 0, 0, 0, 0, size
];

const geometry = new BufferGeometry();
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
const colors = [
1, 0, 0, 1, 0.6, 0,
0, 1, 0, 0.6, 1, 0,
0, 0, 1, 0, 0.6, 1
];

const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
const geometry = new BufferGeometry();
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );

LineSegments.call( this, geometry, material );
const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );

this.type = 'AxesHelper';
super( geometry, material );

}
this.type = 'AxesHelper';

}

AxesHelper.prototype = Object.create( LineSegments.prototype );
AxesHelper.prototype.constructor = AxesHelper;
}


export { AxesHelper };
46 changes: 22 additions & 24 deletions src/helpers/Box3Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,49 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
import { BufferAttribute } from '../core/BufferAttribute.js';
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
import { BufferGeometry } from '../core/BufferGeometry.js';
import { Object3D } from '../core/Object3D.js';

function Box3Helper( box, color ) {
class Box3Helper extends LineSegments {

this.type = 'Box3Helper';
constructor( box, color ) {

this.box = box;
if ( color === undefined ) color = 0xffff00;

if ( color === undefined ) color = 0xffff00;
const indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );

const indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
const positions = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 1, - 1, 1, - 1, - 1 ];

const positions = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 1, - 1, 1, - 1, - 1 ];
const geometry = new BufferGeometry();

const geometry = new BufferGeometry();
geometry.setIndex( new BufferAttribute( indices, 1 ) );

geometry.setIndex( new BufferAttribute( indices, 1 ) );
geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );

geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );

LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
this.box = box;

this.type = 'Box3Helper';
this.type = 'Box3Helper';

this.geometry.computeBoundingSphere();
this.geometry.computeBoundingSphere();

}
}

Box3Helper.prototype = Object.create( LineSegments.prototype );
Box3Helper.prototype.constructor = Box3Helper;
updateMatrixWorld( force ) {

Box3Helper.prototype.updateMatrixWorld = function ( force ) {
const box = this.box;

const box = this.box;
if ( box.isEmpty() ) return;

if ( box.isEmpty() ) return;
box.getCenter( this.position );

box.getCenter( this.position );
box.getSize( this.scale );

box.getSize( this.scale );
this.scale.multiplyScalar( 0.5 );

this.scale.multiplyScalar( 0.5 );
super.updateMatrixWorld( force );

Object3D.prototype.updateMatrixWorld.call( this, force );
}

};
}

export { Box3Helper };
Loading