initial commit
This commit is contained in:
139
lib/helpers/ArrowHelper.js
Normal file
139
lib/helpers/ArrowHelper.js
Normal file
@ -0,0 +1,139 @@
|
||||
/**
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
* @author zz85 / http://github.com/zz85
|
||||
* @author bhouston / http://clara.io
|
||||
*
|
||||
* Creates an arrow for visualizing directions
|
||||
*
|
||||
* Parameters:
|
||||
* dir - Vector3
|
||||
* origin - Vector3
|
||||
* length - Number
|
||||
* color - color in hex value
|
||||
* headLength - Number
|
||||
* headWidth - Number
|
||||
*/
|
||||
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { CylinderBufferGeometry } from '../geometries/CylinderGeometry.js';
|
||||
import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { Mesh } from '../objects/Mesh.js';
|
||||
import { Line } from '../objects/Line.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
var lineGeometry, coneGeometry;
|
||||
|
||||
function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
|
||||
|
||||
// dir is assumed to be normalized
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
if ( dir === undefined ) dir = new THREE.Vector3( 0, 0, 1 );
|
||||
if ( origin === undefined ) origin = new THREE.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 ) {
|
||||
|
||||
lineGeometry = new BufferGeometry();
|
||||
lineGeometry.addAttribute( '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 );
|
||||
|
||||
}
|
||||
|
||||
this.position.copy( origin );
|
||||
|
||||
this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
|
||||
this.line.matrixAutoUpdate = false;
|
||||
this.add( this.line );
|
||||
|
||||
this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
|
||||
this.cone.matrixAutoUpdate = false;
|
||||
this.add( this.cone );
|
||||
|
||||
this.setDirection( dir );
|
||||
this.setLength( length, headLength, headWidth );
|
||||
|
||||
}
|
||||
|
||||
ArrowHelper.prototype = Object.create( Object3D.prototype );
|
||||
ArrowHelper.prototype.constructor = ArrowHelper;
|
||||
|
||||
ArrowHelper.prototype.setDirection = ( function () {
|
||||
|
||||
var axis = new Vector3();
|
||||
var radians;
|
||||
|
||||
return function setDirection( dir ) {
|
||||
|
||||
// dir is assumed to be normalized
|
||||
|
||||
if ( dir.y > 0.99999 ) {
|
||||
|
||||
this.quaternion.set( 0, 0, 0, 1 );
|
||||
|
||||
} else if ( dir.y < - 0.99999 ) {
|
||||
|
||||
this.quaternion.set( 1, 0, 0, 0 );
|
||||
|
||||
} else {
|
||||
|
||||
axis.set( dir.z, 0, - dir.x ).normalize();
|
||||
|
||||
radians = Math.acos( dir.y );
|
||||
|
||||
this.quaternion.setFromAxisAngle( axis, radians );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}() );
|
||||
|
||||
ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
|
||||
|
||||
if ( headLength === undefined ) headLength = 0.2 * length;
|
||||
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
|
||||
|
||||
this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
|
||||
this.line.updateMatrix();
|
||||
|
||||
this.cone.scale.set( headWidth, headLength, headWidth );
|
||||
this.cone.position.y = length;
|
||||
this.cone.updateMatrix();
|
||||
|
||||
};
|
||||
|
||||
ArrowHelper.prototype.setColor = function ( color ) {
|
||||
|
||||
this.line.material.color.copy( color );
|
||||
this.cone.material.color.copy( color );
|
||||
|
||||
};
|
||||
|
||||
ArrowHelper.prototype.copy = function ( source ) {
|
||||
|
||||
Object3D.prototype.copy.call( this, source, false );
|
||||
|
||||
this.line.copy( source.line );
|
||||
this.cone.copy( source.cone );
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
ArrowHelper.prototype.clone = function () {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
};
|
||||
|
||||
export { ArrowHelper };
|
42
lib/helpers/AxesHelper.js
Normal file
42
lib/helpers/AxesHelper.js
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @author sroucheray / http://sroucheray.org/
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { VertexColors } from '../constants.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
|
||||
function AxesHelper( size ) {
|
||||
|
||||
size = size || 1;
|
||||
|
||||
var vertices = [
|
||||
0, 0, 0, size, 0, 0,
|
||||
0, 0, 0, 0, size, 0,
|
||||
0, 0, 0, 0, 0, size
|
||||
];
|
||||
|
||||
var colors = [
|
||||
1, 0, 0, 1, 0.6, 0,
|
||||
0, 1, 0, 0.6, 1, 0,
|
||||
0, 0, 1, 0, 0.6, 1
|
||||
];
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
var material = new LineBasicMaterial( { vertexColors: VertexColors } );
|
||||
|
||||
LineSegments.call( this, geometry, material );
|
||||
|
||||
}
|
||||
|
||||
AxesHelper.prototype = Object.create( LineSegments.prototype );
|
||||
AxesHelper.prototype.constructor = AxesHelper;
|
||||
|
||||
|
||||
export { AxesHelper };
|
55
lib/helpers/Box3Helper.js
Normal file
55
lib/helpers/Box3Helper.js
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
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, hex ) {
|
||||
|
||||
this.type = 'Box3Helper';
|
||||
|
||||
this.box = box;
|
||||
|
||||
var color = ( hex !== undefined ) ? hex : 0xffff00;
|
||||
|
||||
var 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 ] );
|
||||
|
||||
var 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 ];
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
|
||||
geometry.setIndex( new BufferAttribute( indices, 1 ) );
|
||||
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
|
||||
|
||||
LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
|
||||
|
||||
this.geometry.computeBoundingSphere();
|
||||
|
||||
}
|
||||
|
||||
Box3Helper.prototype = Object.create( LineSegments.prototype );
|
||||
Box3Helper.prototype.constructor = Box3Helper;
|
||||
|
||||
Box3Helper.prototype.updateMatrixWorld = function ( force ) {
|
||||
|
||||
var box = this.box;
|
||||
|
||||
if ( box.isEmpty() ) return;
|
||||
|
||||
box.getCenter( this.position );
|
||||
|
||||
box.getSize( this.scale );
|
||||
|
||||
this.scale.multiplyScalar( 0.5 );
|
||||
|
||||
Object3D.prototype.updateMatrixWorld.call( this, force );
|
||||
|
||||
};
|
||||
|
||||
export { Box3Helper };
|
120
lib/helpers/BoxHelper.js
Normal file
120
lib/helpers/BoxHelper.js
Normal file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author Mugen87 / http://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Box3 } from '../math/Box3.js';
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
|
||||
function BoxHelper( object, color ) {
|
||||
|
||||
this.object = object;
|
||||
|
||||
if ( color === undefined ) color = 0xffff00;
|
||||
|
||||
var 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 ] );
|
||||
var positions = new Float32Array( 8 * 3 );
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.setIndex( new BufferAttribute( indices, 1 ) );
|
||||
geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
|
||||
|
||||
LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
BoxHelper.prototype = Object.create( LineSegments.prototype );
|
||||
BoxHelper.prototype.constructor = BoxHelper;
|
||||
|
||||
BoxHelper.prototype.update = ( function () {
|
||||
|
||||
var box = new Box3();
|
||||
|
||||
return function update( object ) {
|
||||
|
||||
if ( object !== undefined ) {
|
||||
|
||||
console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
|
||||
|
||||
}
|
||||
|
||||
if ( this.object !== undefined ) {
|
||||
|
||||
box.setFromObject( this.object );
|
||||
|
||||
}
|
||||
|
||||
if ( box.isEmpty() ) return;
|
||||
|
||||
var min = box.min;
|
||||
var max = box.max;
|
||||
|
||||
/*
|
||||
5____4
|
||||
1/___0/|
|
||||
| 6__|_7
|
||||
2/___3/
|
||||
|
||||
0: max.x, max.y, max.z
|
||||
1: min.x, max.y, max.z
|
||||
2: min.x, min.y, max.z
|
||||
3: max.x, min.y, max.z
|
||||
4: max.x, max.y, min.z
|
||||
5: min.x, max.y, min.z
|
||||
6: min.x, min.y, min.z
|
||||
7: max.x, min.y, min.z
|
||||
*/
|
||||
|
||||
var position = this.geometry.attributes.position;
|
||||
var array = position.array;
|
||||
|
||||
array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
|
||||
array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
|
||||
array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
|
||||
array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
|
||||
array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
|
||||
array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
|
||||
array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
|
||||
array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
|
||||
|
||||
position.needsUpdate = true;
|
||||
|
||||
this.geometry.computeBoundingSphere();
|
||||
|
||||
};
|
||||
|
||||
} )();
|
||||
|
||||
BoxHelper.prototype.setFromObject = function ( object ) {
|
||||
|
||||
this.object = object;
|
||||
this.update();
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
BoxHelper.prototype.copy = function ( source ) {
|
||||
|
||||
LineSegments.prototype.copy.call( this, source );
|
||||
|
||||
this.object = source.object;
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
BoxHelper.prototype.clone = function () {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
};
|
||||
|
||||
export { BoxHelper };
|
210
lib/helpers/CameraHelper.js
Normal file
210
lib/helpers/CameraHelper.js
Normal file
@ -0,0 +1,210 @@
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*
|
||||
* - shows frustum, line of sight and up of the camera
|
||||
* - suitable for fast updates
|
||||
* - based on frustum visualization in lightgl.js shadowmap example
|
||||
* http://evanw.github.com/lightgl.js/tests/shadowmap.html
|
||||
*/
|
||||
|
||||
import { Camera } from '../cameras/Camera.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { Color } from '../math/Color.js';
|
||||
import { FaceColors } from '../constants.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
|
||||
function CameraHelper( camera ) {
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
|
||||
|
||||
var vertices = [];
|
||||
var colors = [];
|
||||
|
||||
var pointMap = {};
|
||||
|
||||
// colors
|
||||
|
||||
var colorFrustum = new Color( 0xffaa00 );
|
||||
var colorCone = new Color( 0xff0000 );
|
||||
var colorUp = new Color( 0x00aaff );
|
||||
var colorTarget = new Color( 0xffffff );
|
||||
var colorCross = new Color( 0x333333 );
|
||||
|
||||
// near
|
||||
|
||||
addLine( 'n1', 'n2', colorFrustum );
|
||||
addLine( 'n2', 'n4', colorFrustum );
|
||||
addLine( 'n4', 'n3', colorFrustum );
|
||||
addLine( 'n3', 'n1', colorFrustum );
|
||||
|
||||
// far
|
||||
|
||||
addLine( 'f1', 'f2', colorFrustum );
|
||||
addLine( 'f2', 'f4', colorFrustum );
|
||||
addLine( 'f4', 'f3', colorFrustum );
|
||||
addLine( 'f3', 'f1', colorFrustum );
|
||||
|
||||
// sides
|
||||
|
||||
addLine( 'n1', 'f1', colorFrustum );
|
||||
addLine( 'n2', 'f2', colorFrustum );
|
||||
addLine( 'n3', 'f3', colorFrustum );
|
||||
addLine( 'n4', 'f4', colorFrustum );
|
||||
|
||||
// cone
|
||||
|
||||
addLine( 'p', 'n1', colorCone );
|
||||
addLine( 'p', 'n2', colorCone );
|
||||
addLine( 'p', 'n3', colorCone );
|
||||
addLine( 'p', 'n4', colorCone );
|
||||
|
||||
// up
|
||||
|
||||
addLine( 'u1', 'u2', colorUp );
|
||||
addLine( 'u2', 'u3', colorUp );
|
||||
addLine( 'u3', 'u1', colorUp );
|
||||
|
||||
// target
|
||||
|
||||
addLine( 'c', 't', colorTarget );
|
||||
addLine( 'p', 'c', colorCross );
|
||||
|
||||
// cross
|
||||
|
||||
addLine( 'cn1', 'cn2', colorCross );
|
||||
addLine( 'cn3', 'cn4', colorCross );
|
||||
|
||||
addLine( 'cf1', 'cf2', colorCross );
|
||||
addLine( 'cf3', 'cf4', colorCross );
|
||||
|
||||
function addLine( a, b, color ) {
|
||||
|
||||
addPoint( a, color );
|
||||
addPoint( b, color );
|
||||
|
||||
}
|
||||
|
||||
function addPoint( id, color ) {
|
||||
|
||||
vertices.push( 0, 0, 0 );
|
||||
colors.push( color.r, color.g, color.b );
|
||||
|
||||
if ( pointMap[ id ] === undefined ) {
|
||||
|
||||
pointMap[ id ] = [];
|
||||
|
||||
}
|
||||
|
||||
pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
|
||||
|
||||
}
|
||||
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
LineSegments.call( this, geometry, material );
|
||||
|
||||
this.camera = camera;
|
||||
if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
|
||||
|
||||
this.matrix = camera.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.pointMap = pointMap;
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
CameraHelper.prototype = Object.create( LineSegments.prototype );
|
||||
CameraHelper.prototype.constructor = CameraHelper;
|
||||
|
||||
CameraHelper.prototype.update = function () {
|
||||
|
||||
var geometry, pointMap;
|
||||
|
||||
var vector = new Vector3();
|
||||
var camera = new Camera();
|
||||
|
||||
function setPoint( point, x, y, z ) {
|
||||
|
||||
vector.set( x, y, z ).unproject( camera );
|
||||
|
||||
var points = pointMap[ point ];
|
||||
|
||||
if ( points !== undefined ) {
|
||||
|
||||
var position = geometry.getAttribute( 'position' );
|
||||
|
||||
for ( var i = 0, l = points.length; i < l; i ++ ) {
|
||||
|
||||
position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return function update() {
|
||||
|
||||
geometry = this.geometry;
|
||||
pointMap = this.pointMap;
|
||||
|
||||
var w = 1, h = 1;
|
||||
|
||||
// we need just camera projection matrix
|
||||
// world matrix must be identity
|
||||
|
||||
camera.projectionMatrix.copy( this.camera.projectionMatrix );
|
||||
|
||||
// center / target
|
||||
|
||||
setPoint( 'c', 0, 0, - 1 );
|
||||
setPoint( 't', 0, 0, 1 );
|
||||
|
||||
// near
|
||||
|
||||
setPoint( 'n1', - w, - h, - 1 );
|
||||
setPoint( 'n2', w, - h, - 1 );
|
||||
setPoint( 'n3', - w, h, - 1 );
|
||||
setPoint( 'n4', w, h, - 1 );
|
||||
|
||||
// far
|
||||
|
||||
setPoint( 'f1', - w, - h, 1 );
|
||||
setPoint( 'f2', w, - h, 1 );
|
||||
setPoint( 'f3', - w, h, 1 );
|
||||
setPoint( 'f4', w, h, 1 );
|
||||
|
||||
// up
|
||||
|
||||
setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
|
||||
setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
|
||||
setPoint( 'u3', 0, h * 2, - 1 );
|
||||
|
||||
// cross
|
||||
|
||||
setPoint( 'cf1', - w, 0, 1 );
|
||||
setPoint( 'cf2', w, 0, 1 );
|
||||
setPoint( 'cf3', 0, - h, 1 );
|
||||
setPoint( 'cf4', 0, h, 1 );
|
||||
|
||||
setPoint( 'cn1', - w, 0, - 1 );
|
||||
setPoint( 'cn2', w, 0, - 1 );
|
||||
setPoint( 'cn3', 0, - h, - 1 );
|
||||
setPoint( 'cn4', 0, h, - 1 );
|
||||
|
||||
geometry.getAttribute( 'position' ).needsUpdate = true;
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
|
||||
export { CameraHelper };
|
98
lib/helpers/DirectionalLightHelper.js
Normal file
98
lib/helpers/DirectionalLightHelper.js
Normal file
@ -0,0 +1,98 @@
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { Line } from '../objects/Line.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
|
||||
function DirectionalLightHelper( light, size, color ) {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.light = light;
|
||||
this.light.updateMatrixWorld();
|
||||
|
||||
this.matrix = light.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.color = color;
|
||||
|
||||
if ( size === undefined ) size = 1;
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( [
|
||||
- size, size, 0,
|
||||
size, size, 0,
|
||||
size, - size, 0,
|
||||
- size, - size, 0,
|
||||
- size, size, 0
|
||||
], 3 ) );
|
||||
|
||||
var material = new LineBasicMaterial( { fog: false } );
|
||||
|
||||
this.lightPlane = new Line( geometry, material );
|
||||
this.add( this.lightPlane );
|
||||
|
||||
geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
|
||||
|
||||
this.targetLine = new Line( geometry, material );
|
||||
this.add( this.targetLine );
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
|
||||
DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
|
||||
|
||||
DirectionalLightHelper.prototype.dispose = function () {
|
||||
|
||||
this.lightPlane.geometry.dispose();
|
||||
this.lightPlane.material.dispose();
|
||||
this.targetLine.geometry.dispose();
|
||||
this.targetLine.material.dispose();
|
||||
|
||||
};
|
||||
|
||||
DirectionalLightHelper.prototype.update = function () {
|
||||
|
||||
var v1 = new Vector3();
|
||||
var v2 = new Vector3();
|
||||
var v3 = new Vector3();
|
||||
|
||||
return function update() {
|
||||
|
||||
v1.setFromMatrixPosition( this.light.matrixWorld );
|
||||
v2.setFromMatrixPosition( this.light.target.matrixWorld );
|
||||
v3.subVectors( v2, v1 );
|
||||
|
||||
this.lightPlane.lookAt( v3 );
|
||||
|
||||
if ( this.color !== undefined ) {
|
||||
|
||||
this.lightPlane.material.color.set( this.color );
|
||||
this.targetLine.material.color.set( this.color );
|
||||
|
||||
} else {
|
||||
|
||||
this.lightPlane.material.color.copy( this.light.color );
|
||||
this.targetLine.material.color.copy( this.light.color );
|
||||
|
||||
}
|
||||
|
||||
this.targetLine.lookAt( v3 );
|
||||
this.targetLine.scale.z = v3.length();
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
|
||||
export { DirectionalLightHelper };
|
118
lib/helpers/FaceNormalsHelper.js
Normal file
118
lib/helpers/FaceNormalsHelper.js
Normal file
@ -0,0 +1,118 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
import { Matrix3 } from '../math/Matrix3.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
|
||||
function FaceNormalsHelper( object, size, hex, linewidth ) {
|
||||
|
||||
// FaceNormalsHelper only supports THREE.Geometry
|
||||
|
||||
this.object = object;
|
||||
|
||||
this.size = ( size !== undefined ) ? size : 1;
|
||||
|
||||
var color = ( hex !== undefined ) ? hex : 0xffff00;
|
||||
|
||||
var width = ( linewidth !== undefined ) ? linewidth : 1;
|
||||
|
||||
//
|
||||
|
||||
var nNormals = 0;
|
||||
|
||||
var objGeometry = this.object.geometry;
|
||||
|
||||
if ( objGeometry && objGeometry.isGeometry ) {
|
||||
|
||||
nNormals = objGeometry.faces.length;
|
||||
|
||||
} else {
|
||||
|
||||
console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
|
||||
var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
|
||||
|
||||
geometry.addAttribute( 'position', positions );
|
||||
|
||||
LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
|
||||
|
||||
//
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
|
||||
FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
|
||||
|
||||
FaceNormalsHelper.prototype.update = ( function () {
|
||||
|
||||
var v1 = new Vector3();
|
||||
var v2 = new Vector3();
|
||||
var normalMatrix = new Matrix3();
|
||||
|
||||
return function update() {
|
||||
|
||||
this.object.updateMatrixWorld( true );
|
||||
|
||||
normalMatrix.getNormalMatrix( this.object.matrixWorld );
|
||||
|
||||
var matrixWorld = this.object.matrixWorld;
|
||||
|
||||
var position = this.geometry.attributes.position;
|
||||
|
||||
//
|
||||
|
||||
var objGeometry = this.object.geometry;
|
||||
|
||||
var vertices = objGeometry.vertices;
|
||||
|
||||
var faces = objGeometry.faces;
|
||||
|
||||
var idx = 0;
|
||||
|
||||
for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
||||
|
||||
var face = faces[ i ];
|
||||
|
||||
var normal = face.normal;
|
||||
|
||||
v1.copy( vertices[ face.a ] )
|
||||
.add( vertices[ face.b ] )
|
||||
.add( vertices[ face.c ] )
|
||||
.divideScalar( 3 )
|
||||
.applyMatrix4( matrixWorld );
|
||||
|
||||
v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
|
||||
|
||||
position.setXYZ( idx, v1.x, v1.y, v1.z );
|
||||
|
||||
idx = idx + 1;
|
||||
|
||||
position.setXYZ( idx, v2.x, v2.y, v2.z );
|
||||
|
||||
idx = idx + 1;
|
||||
|
||||
}
|
||||
|
||||
position.needsUpdate = true;
|
||||
|
||||
};
|
||||
|
||||
}() );
|
||||
|
||||
|
||||
export { FaceNormalsHelper };
|
52
lib/helpers/GridHelper.js
Normal file
52
lib/helpers/GridHelper.js
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { VertexColors } from '../constants.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Color } from '../math/Color.js';
|
||||
|
||||
function GridHelper( size, divisions, color1, color2 ) {
|
||||
|
||||
size = size || 10;
|
||||
divisions = divisions || 10;
|
||||
color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
|
||||
color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
|
||||
|
||||
var center = divisions / 2;
|
||||
var step = size / divisions;
|
||||
var halfSize = size / 2;
|
||||
|
||||
var vertices = [], colors = [];
|
||||
|
||||
for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
|
||||
|
||||
vertices.push( - halfSize, 0, k, halfSize, 0, k );
|
||||
vertices.push( k, 0, - halfSize, k, 0, halfSize );
|
||||
|
||||
var color = i === center ? color1 : color2;
|
||||
|
||||
color.toArray( colors, j ); j += 3;
|
||||
color.toArray( colors, j ); j += 3;
|
||||
color.toArray( colors, j ); j += 3;
|
||||
color.toArray( colors, j ); j += 3;
|
||||
|
||||
}
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
var material = new LineBasicMaterial( { vertexColors: VertexColors } );
|
||||
|
||||
LineSegments.call( this, geometry, material );
|
||||
|
||||
}
|
||||
|
||||
GridHelper.prototype = Object.create( LineSegments.prototype );
|
||||
GridHelper.prototype.constructor = GridHelper;
|
||||
|
||||
export { GridHelper };
|
96
lib/helpers/HemisphereLightHelper.js
Normal file
96
lib/helpers/HemisphereLightHelper.js
Normal file
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Color } from '../math/Color.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { Mesh } from '../objects/Mesh.js';
|
||||
import { VertexColors } from '../constants.js';
|
||||
import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
|
||||
import { OctahedronBufferGeometry } from '../geometries/OctahedronGeometry.js';
|
||||
import { BufferAttribute } from '../core/BufferAttribute.js';
|
||||
|
||||
function HemisphereLightHelper( light, size, color ) {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.light = light;
|
||||
this.light.updateMatrixWorld();
|
||||
|
||||
this.matrix = light.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.color = color;
|
||||
|
||||
var geometry = new OctahedronBufferGeometry( size );
|
||||
geometry.rotateY( Math.PI * 0.5 );
|
||||
|
||||
this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
|
||||
if ( this.color === undefined ) this.material.vertexColors = VertexColors;
|
||||
|
||||
var position = geometry.getAttribute( 'position' );
|
||||
var colors = new Float32Array( position.count * 3 );
|
||||
|
||||
geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
|
||||
|
||||
this.add( new Mesh( geometry, this.material ) );
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
|
||||
HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
|
||||
|
||||
HemisphereLightHelper.prototype.dispose = function () {
|
||||
|
||||
this.children[ 0 ].geometry.dispose();
|
||||
this.children[ 0 ].material.dispose();
|
||||
|
||||
};
|
||||
|
||||
HemisphereLightHelper.prototype.update = function () {
|
||||
|
||||
var vector = new Vector3();
|
||||
|
||||
var color1 = new Color();
|
||||
var color2 = new Color();
|
||||
|
||||
return function update() {
|
||||
|
||||
var mesh = this.children[ 0 ];
|
||||
|
||||
if ( this.color !== undefined ) {
|
||||
|
||||
this.material.color.set( this.color );
|
||||
|
||||
} else {
|
||||
|
||||
var colors = mesh.geometry.getAttribute( 'color' );
|
||||
|
||||
color1.copy( this.light.color );
|
||||
color2.copy( this.light.groundColor );
|
||||
|
||||
for ( var i = 0, l = colors.count; i < l; i ++ ) {
|
||||
|
||||
var color = ( i < ( l / 2 ) ) ? color1 : color2;
|
||||
|
||||
colors.setXYZ( i, color.r, color.g, color.b );
|
||||
|
||||
}
|
||||
|
||||
colors.needsUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
|
||||
export { HemisphereLightHelper };
|
63
lib/helpers/PlaneHelper.js
Normal file
63
lib/helpers/PlaneHelper.js
Normal file
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
import { Line } from '../objects/Line.js';
|
||||
import { Mesh } from '../objects/Mesh.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { FrontSide, BackSide } from '../constants.js';
|
||||
|
||||
function PlaneHelper( plane, size, hex ) {
|
||||
|
||||
this.type = 'PlaneHelper';
|
||||
|
||||
this.plane = plane;
|
||||
|
||||
this.size = ( size === undefined ) ? 1 : size;
|
||||
|
||||
var color = ( hex !== undefined ) ? hex : 0xffff00;
|
||||
|
||||
var 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, 0, 0, 1, 0, 0, 0 ];
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
|
||||
geometry.computeBoundingSphere();
|
||||
|
||||
Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
|
||||
|
||||
//
|
||||
|
||||
var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
|
||||
|
||||
var geometry2 = new BufferGeometry();
|
||||
geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
|
||||
geometry2.computeBoundingSphere();
|
||||
|
||||
this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
|
||||
|
||||
}
|
||||
|
||||
PlaneHelper.prototype = Object.create( Line.prototype );
|
||||
PlaneHelper.prototype.constructor = PlaneHelper;
|
||||
|
||||
PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
|
||||
|
||||
var scale = - this.plane.constant;
|
||||
|
||||
if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
|
||||
|
||||
this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
|
||||
|
||||
this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
|
||||
|
||||
this.lookAt( this.plane.normal );
|
||||
|
||||
Object3D.prototype.updateMatrixWorld.call( this, force );
|
||||
|
||||
};
|
||||
|
||||
export { PlaneHelper };
|
92
lib/helpers/PointLightHelper.js
Normal file
92
lib/helpers/PointLightHelper.js
Normal file
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
import { Mesh } from '../objects/Mesh.js';
|
||||
import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
|
||||
import { SphereBufferGeometry } from '../geometries/SphereGeometry.js';
|
||||
|
||||
function PointLightHelper( light, sphereSize, color ) {
|
||||
|
||||
this.light = light;
|
||||
this.light.updateMatrixWorld();
|
||||
|
||||
this.color = color;
|
||||
|
||||
var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
|
||||
var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
|
||||
|
||||
Mesh.call( this, geometry, material );
|
||||
|
||||
this.matrix = this.light.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.update();
|
||||
|
||||
|
||||
/*
|
||||
var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
|
||||
var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
|
||||
|
||||
this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
|
||||
this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
|
||||
|
||||
var d = light.distance;
|
||||
|
||||
if ( d === 0.0 ) {
|
||||
|
||||
this.lightDistance.visible = false;
|
||||
|
||||
} else {
|
||||
|
||||
this.lightDistance.scale.set( d, d, d );
|
||||
|
||||
}
|
||||
|
||||
this.add( this.lightDistance );
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
PointLightHelper.prototype = Object.create( Mesh.prototype );
|
||||
PointLightHelper.prototype.constructor = PointLightHelper;
|
||||
|
||||
PointLightHelper.prototype.dispose = function () {
|
||||
|
||||
this.geometry.dispose();
|
||||
this.material.dispose();
|
||||
|
||||
};
|
||||
|
||||
PointLightHelper.prototype.update = function () {
|
||||
|
||||
if ( this.color !== undefined ) {
|
||||
|
||||
this.material.color.set( this.color );
|
||||
|
||||
} else {
|
||||
|
||||
this.material.color.copy( this.light.color );
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
var d = this.light.distance;
|
||||
|
||||
if ( d === 0.0 ) {
|
||||
|
||||
this.lightDistance.visible = false;
|
||||
|
||||
} else {
|
||||
|
||||
this.lightDistance.visible = true;
|
||||
this.lightDistance.scale.set( d, d, d );
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
export { PointLightHelper };
|
95
lib/helpers/PolarGridHelper.js
Normal file
95
lib/helpers/PolarGridHelper.js
Normal file
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author Mugen87 / http://github.com/Mugen87
|
||||
* @author Hectate / http://www.github.com/Hectate
|
||||
*/
|
||||
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { VertexColors } from '../constants.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Color } from '../math/Color.js';
|
||||
|
||||
function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
|
||||
|
||||
radius = radius || 10;
|
||||
radials = radials || 16;
|
||||
circles = circles || 8;
|
||||
divisions = divisions || 64;
|
||||
color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
|
||||
color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
|
||||
|
||||
var vertices = [];
|
||||
var colors = [];
|
||||
|
||||
var x, z;
|
||||
var v, i, j, r, color;
|
||||
|
||||
// create the radials
|
||||
|
||||
for ( i = 0; i <= radials; i ++ ) {
|
||||
|
||||
v = ( i / radials ) * ( Math.PI * 2 );
|
||||
|
||||
x = Math.sin( v ) * radius;
|
||||
z = Math.cos( v ) * radius;
|
||||
|
||||
vertices.push( 0, 0, 0 );
|
||||
vertices.push( x, 0, z );
|
||||
|
||||
color = ( i & 1 ) ? color1 : color2;
|
||||
|
||||
colors.push( color.r, color.g, color.b );
|
||||
colors.push( color.r, color.g, color.b );
|
||||
|
||||
}
|
||||
|
||||
// create the circles
|
||||
|
||||
for ( i = 0; i <= circles; i ++ ) {
|
||||
|
||||
color = ( i & 1 ) ? color1 : color2;
|
||||
|
||||
r = radius - ( radius / circles * i );
|
||||
|
||||
for ( j = 0; j < divisions; j ++ ) {
|
||||
|
||||
// first vertex
|
||||
|
||||
v = ( j / divisions ) * ( Math.PI * 2 );
|
||||
|
||||
x = Math.sin( v ) * r;
|
||||
z = Math.cos( v ) * r;
|
||||
|
||||
vertices.push( x, 0, z );
|
||||
colors.push( color.r, color.g, color.b );
|
||||
|
||||
// second vertex
|
||||
|
||||
v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
|
||||
|
||||
x = Math.sin( v ) * r;
|
||||
z = Math.cos( v ) * r;
|
||||
|
||||
vertices.push( x, 0, z );
|
||||
colors.push( color.r, color.g, color.b );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
var material = new LineBasicMaterial( { vertexColors: VertexColors } );
|
||||
|
||||
LineSegments.call( this, geometry, material );
|
||||
|
||||
}
|
||||
|
||||
PolarGridHelper.prototype = Object.create( LineSegments.prototype );
|
||||
PolarGridHelper.prototype.constructor = PolarGridHelper;
|
||||
|
||||
export { PolarGridHelper };
|
81
lib/helpers/RectAreaLightHelper.js
Normal file
81
lib/helpers/RectAreaLightHelper.js
Normal file
@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @author abelnation / http://github.com/abelnation
|
||||
* @author Mugen87 / http://github.com/Mugen87
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { Line } from '../objects/Line.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { BufferAttribute } from '../core/BufferAttribute.js';
|
||||
|
||||
function RectAreaLightHelper( light, color ) {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.light = light;
|
||||
this.light.updateMatrixWorld();
|
||||
|
||||
this.matrix = light.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.color = color;
|
||||
|
||||
var material = new LineBasicMaterial( { fog: false } );
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
|
||||
geometry.addAttribute( 'position', new BufferAttribute( new Float32Array( 5 * 3 ), 3 ) );
|
||||
|
||||
this.line = new Line( geometry, material );
|
||||
this.add( this.line );
|
||||
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
RectAreaLightHelper.prototype = Object.create( Object3D.prototype );
|
||||
RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
|
||||
|
||||
RectAreaLightHelper.prototype.dispose = function () {
|
||||
|
||||
this.children[ 0 ].geometry.dispose();
|
||||
this.children[ 0 ].material.dispose();
|
||||
|
||||
};
|
||||
|
||||
RectAreaLightHelper.prototype.update = function () {
|
||||
|
||||
// calculate new dimensions of the helper
|
||||
|
||||
var hx = this.light.width * 0.5;
|
||||
var hy = this.light.height * 0.5;
|
||||
|
||||
var position = this.line.geometry.attributes.position;
|
||||
var array = position.array;
|
||||
|
||||
// update vertices
|
||||
|
||||
array[ 0 ] = hx; array[ 1 ] = - hy; array[ 2 ] = 0;
|
||||
array[ 3 ] = hx; array[ 4 ] = hy; array[ 5 ] = 0;
|
||||
array[ 6 ] = - hx; array[ 7 ] = hy; array[ 8 ] = 0;
|
||||
array[ 9 ] = - hx; array[ 10 ] = - hy; array[ 11 ] = 0;
|
||||
array[ 12 ] = hx; array[ 13 ] = - hy; array[ 14 ] = 0;
|
||||
|
||||
position.needsUpdate = true;
|
||||
|
||||
if ( this.color !== undefined ) {
|
||||
|
||||
this.line.material.color.set( this.color );
|
||||
|
||||
} else {
|
||||
|
||||
this.line.material.color.copy( this.light.color );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export { RectAreaLightHelper };
|
128
lib/helpers/SkeletonHelper.js
Normal file
128
lib/helpers/SkeletonHelper.js
Normal file
@ -0,0 +1,128 @@
|
||||
/**
|
||||
* @author Sean Griffin / http://twitter.com/sgrif
|
||||
* @author Michael Guerrero / http://realitymeltdown.com
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author ikerr / http://verold.com
|
||||
* @author Mugen87 / https://github.com/Mugen87
|
||||
*/
|
||||
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { Matrix4 } from '../math/Matrix4.js';
|
||||
import { VertexColors } from '../constants.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { Color } from '../math/Color.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
|
||||
function getBoneList( object ) {
|
||||
|
||||
var boneList = [];
|
||||
|
||||
if ( object && object.isBone ) {
|
||||
|
||||
boneList.push( object );
|
||||
|
||||
}
|
||||
|
||||
for ( var i = 0; i < object.children.length; i ++ ) {
|
||||
|
||||
boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
|
||||
|
||||
}
|
||||
|
||||
return boneList;
|
||||
|
||||
}
|
||||
|
||||
function SkeletonHelper( object ) {
|
||||
|
||||
var bones = getBoneList( object );
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
|
||||
var vertices = [];
|
||||
var colors = [];
|
||||
|
||||
var color1 = new Color( 0, 0, 1 );
|
||||
var color2 = new Color( 0, 1, 0 );
|
||||
|
||||
for ( var i = 0; i < bones.length; i ++ ) {
|
||||
|
||||
var bone = bones[ i ];
|
||||
|
||||
if ( bone.parent && bone.parent.isBone ) {
|
||||
|
||||
vertices.push( 0, 0, 0 );
|
||||
vertices.push( 0, 0, 0 );
|
||||
colors.push( color1.r, color1.g, color1.b );
|
||||
colors.push( color2.r, color2.g, color2.b );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
||||
geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
||||
|
||||
var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
|
||||
|
||||
LineSegments.call( this, geometry, material );
|
||||
|
||||
this.root = object;
|
||||
this.bones = bones;
|
||||
|
||||
this.matrix = object.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
}
|
||||
|
||||
SkeletonHelper.prototype = Object.create( LineSegments.prototype );
|
||||
SkeletonHelper.prototype.constructor = SkeletonHelper;
|
||||
|
||||
SkeletonHelper.prototype.updateMatrixWorld = function () {
|
||||
|
||||
var vector = new Vector3();
|
||||
|
||||
var boneMatrix = new Matrix4();
|
||||
var matrixWorldInv = new Matrix4();
|
||||
|
||||
return function updateMatrixWorld( force ) {
|
||||
|
||||
var bones = this.bones;
|
||||
|
||||
var geometry = this.geometry;
|
||||
var position = geometry.getAttribute( 'position' );
|
||||
|
||||
matrixWorldInv.getInverse( this.root.matrixWorld );
|
||||
|
||||
for ( var i = 0, j = 0; i < bones.length; i ++ ) {
|
||||
|
||||
var bone = bones[ i ];
|
||||
|
||||
if ( bone.parent && bone.parent.isBone ) {
|
||||
|
||||
boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
|
||||
vector.setFromMatrixPosition( boneMatrix );
|
||||
position.setXYZ( j, vector.x, vector.y, vector.z );
|
||||
|
||||
boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
|
||||
vector.setFromMatrixPosition( boneMatrix );
|
||||
position.setXYZ( j + 1, vector.x, vector.y, vector.z );
|
||||
|
||||
j += 2;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
geometry.getAttribute( 'position' ).needsUpdate = true;
|
||||
|
||||
Object3D.prototype.updateMatrixWorld.call( this, force );
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
export { SkeletonHelper };
|
103
lib/helpers/SpotLightHelper.js
Normal file
103
lib/helpers/SpotLightHelper.js
Normal file
@ -0,0 +1,103 @@
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
|
||||
function SpotLightHelper( light, color ) {
|
||||
|
||||
Object3D.call( this );
|
||||
|
||||
this.light = light;
|
||||
this.light.updateMatrixWorld();
|
||||
|
||||
this.matrix = light.matrixWorld;
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.color = color;
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
|
||||
var positions = [
|
||||
0, 0, 0, 0, 0, 1,
|
||||
0, 0, 0, 1, 0, 1,
|
||||
0, 0, 0, - 1, 0, 1,
|
||||
0, 0, 0, 0, 1, 1,
|
||||
0, 0, 0, 0, - 1, 1
|
||||
];
|
||||
|
||||
for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
|
||||
|
||||
var p1 = ( i / l ) * Math.PI * 2;
|
||||
var p2 = ( j / l ) * Math.PI * 2;
|
||||
|
||||
positions.push(
|
||||
Math.cos( p1 ), Math.sin( p1 ), 1,
|
||||
Math.cos( p2 ), Math.sin( p2 ), 1
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
|
||||
|
||||
var material = new LineBasicMaterial( { fog: false } );
|
||||
|
||||
this.cone = new LineSegments( geometry, material );
|
||||
this.add( this.cone );
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
SpotLightHelper.prototype = Object.create( Object3D.prototype );
|
||||
SpotLightHelper.prototype.constructor = SpotLightHelper;
|
||||
|
||||
SpotLightHelper.prototype.dispose = function () {
|
||||
|
||||
this.cone.geometry.dispose();
|
||||
this.cone.material.dispose();
|
||||
|
||||
};
|
||||
|
||||
SpotLightHelper.prototype.update = function () {
|
||||
|
||||
var vector = new Vector3();
|
||||
var vector2 = new Vector3();
|
||||
|
||||
return function update() {
|
||||
|
||||
this.light.updateMatrixWorld();
|
||||
|
||||
var coneLength = this.light.distance ? this.light.distance : 1000;
|
||||
var coneWidth = coneLength * Math.tan( this.light.angle );
|
||||
|
||||
this.cone.scale.set( coneWidth, coneWidth, coneLength );
|
||||
|
||||
vector.setFromMatrixPosition( this.light.matrixWorld );
|
||||
vector2.setFromMatrixPosition( this.light.target.matrixWorld );
|
||||
|
||||
this.cone.lookAt( vector2.sub( vector ) );
|
||||
|
||||
if ( this.color !== undefined ) {
|
||||
|
||||
this.cone.material.color.set( this.color );
|
||||
|
||||
} else {
|
||||
|
||||
this.cone.material.color.copy( this.light.color );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
|
||||
export { SpotLightHelper };
|
153
lib/helpers/VertexNormalsHelper.js
Normal file
153
lib/helpers/VertexNormalsHelper.js
Normal file
@ -0,0 +1,153 @@
|
||||
/**
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
* @author WestLangley / http://github.com/WestLangley
|
||||
*/
|
||||
|
||||
import { Matrix3 } from '../math/Matrix3.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
import { LineSegments } from '../objects/LineSegments.js';
|
||||
import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
||||
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
||||
import { BufferGeometry } from '../core/BufferGeometry.js';
|
||||
|
||||
function VertexNormalsHelper( object, size, hex, linewidth ) {
|
||||
|
||||
this.object = object;
|
||||
|
||||
this.size = ( size !== undefined ) ? size : 1;
|
||||
|
||||
var color = ( hex !== undefined ) ? hex : 0xff0000;
|
||||
|
||||
var width = ( linewidth !== undefined ) ? linewidth : 1;
|
||||
|
||||
//
|
||||
|
||||
var nNormals = 0;
|
||||
|
||||
var objGeometry = this.object.geometry;
|
||||
|
||||
if ( objGeometry && objGeometry.isGeometry ) {
|
||||
|
||||
nNormals = objGeometry.faces.length * 3;
|
||||
|
||||
} else if ( objGeometry && objGeometry.isBufferGeometry ) {
|
||||
|
||||
nNormals = objGeometry.attributes.normal.count;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var geometry = new BufferGeometry();
|
||||
|
||||
var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
|
||||
|
||||
geometry.addAttribute( 'position', positions );
|
||||
|
||||
LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
|
||||
|
||||
//
|
||||
|
||||
this.matrixAutoUpdate = false;
|
||||
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
|
||||
VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
|
||||
|
||||
VertexNormalsHelper.prototype.update = ( function () {
|
||||
|
||||
var v1 = new Vector3();
|
||||
var v2 = new Vector3();
|
||||
var normalMatrix = new Matrix3();
|
||||
|
||||
return function update() {
|
||||
|
||||
var keys = [ 'a', 'b', 'c' ];
|
||||
|
||||
this.object.updateMatrixWorld( true );
|
||||
|
||||
normalMatrix.getNormalMatrix( this.object.matrixWorld );
|
||||
|
||||
var matrixWorld = this.object.matrixWorld;
|
||||
|
||||
var position = this.geometry.attributes.position;
|
||||
|
||||
//
|
||||
|
||||
var objGeometry = this.object.geometry;
|
||||
|
||||
if ( objGeometry && objGeometry.isGeometry ) {
|
||||
|
||||
var vertices = objGeometry.vertices;
|
||||
|
||||
var faces = objGeometry.faces;
|
||||
|
||||
var idx = 0;
|
||||
|
||||
for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
||||
|
||||
var face = faces[ i ];
|
||||
|
||||
for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
|
||||
|
||||
var vertex = vertices[ face[ keys[ j ] ] ];
|
||||
|
||||
var normal = face.vertexNormals[ j ];
|
||||
|
||||
v1.copy( vertex ).applyMatrix4( matrixWorld );
|
||||
|
||||
v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
|
||||
|
||||
position.setXYZ( idx, v1.x, v1.y, v1.z );
|
||||
|
||||
idx = idx + 1;
|
||||
|
||||
position.setXYZ( idx, v2.x, v2.y, v2.z );
|
||||
|
||||
idx = idx + 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else if ( objGeometry && objGeometry.isBufferGeometry ) {
|
||||
|
||||
var objPos = objGeometry.attributes.position;
|
||||
|
||||
var objNorm = objGeometry.attributes.normal;
|
||||
|
||||
var idx = 0;
|
||||
|
||||
// for simplicity, ignore index and drawcalls, and render every normal
|
||||
|
||||
for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
|
||||
|
||||
v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
|
||||
|
||||
v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
|
||||
|
||||
v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
|
||||
|
||||
position.setXYZ( idx, v1.x, v1.y, v1.z );
|
||||
|
||||
idx = idx + 1;
|
||||
|
||||
position.setXYZ( idx, v2.x, v2.y, v2.z );
|
||||
|
||||
idx = idx + 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
position.needsUpdate = true;
|
||||
|
||||
};
|
||||
|
||||
}() );
|
||||
|
||||
|
||||
export { VertexNormalsHelper };
|
Reference in New Issue
Block a user