Three.js提供了各種輔助工具幫助開發
用於可視化方向的3D箭頭ArrowHelper(dir : Vector3, origin : Vector3, length : Number, hex : Number, headLength : Number, headWidth : Number )
const dir = new THREE.Vector3( 1, 2, 0 );
dir.normalize();
const origin = new THREE.Vector3( 0, 0, 0 );
const length = 1;
const hex = 0xffff00;
const arrowHelper = new THREE.ArrowHelper( dir, origin, length, hex );
scene.add( arrowHelper )
可以用來創建可視化三維坐標系,X軸為紅色,Y軸綠色、Z軸藍色,參數為座標軸大小。
let axesHelper = new THREE.AxesHelper(3)
scene.add(axesHelper)
輔助物件圖形化顯示物件包圍盒
const sphere = new THREE.SphereGeometry();
const object = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( 0xff0000 ) );
object.position.set(6,1,1)
const box = new THREE.BoxHelper( object, 0xffff00 );
scene.add( box );
scene.add(object)
可視化相機錐體
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const helper = new THREE.CameraHelper( camera );
scene.add( helper );
定義網格GridHelper( size : number, divisions : Number, colorCenterLine : Color, colorGrid : Color )
const size = 10;
const divisions = 10;
const gridHelper = new THREE.GridHelper( size, divisions,0xff0000,0xffffff);
scene.add( gridHelper );
定義極座標網格
const radius = 10;
const radials = 16;
const circles = 8;
const divisions = 64;
const helper = new THREE.PolarGridHelper( radius, radials, circles, divisions );
scene.add( helper );
https://threejs.org/docs/?q=help#api/en/helpers/ArrowHelper
https://threejs.org/docs/#api/en/helpers/AxesHelper
https://threejs.org/docs/?q=help#api/en/helpers/BoxHelper
https://threejs.org/docs/?q=help#api/en/helpers/CameraHelper
https://threejs.org/docs/?q=help#api/en/helpers/GridHelper
https://threejs.org/docs/?q=help#api/en/helpers/PolarGridHelper