-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyAxis.js
60 lines (52 loc) · 2.28 KB
/
MyAxis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as THREE from 'three';
import { MyApp } from './MyApp.js';
/**
* This class contains a 3D axis representation
*/
class MyAxis extends THREE.Object3D {
/**
*
* @param {MyApp} app the application object
* @param {number} size the size of each axis
* @param {number} baseRadius the base radius of each axis
* @param {number} xxColor the hexadecimal representation of the xx axis color
* @param {number} yyColor the hexadecimal representation of the xx axis color
* @param {number} zzColor the hexadecimal representation of the zz axis color
*/
constructor(app, size, baseRadius, xxColor, yyColor, zzColor) {
super();
this.app = app;
this.type = 'Group';
this.size = size || 2;
this.baseRadius = baseRadius || 0.05;
this.xxColor = xxColor || 0xff0000
this.yyColor = yyColor || 0x00ff00
this.zzColor = zzColor || 0x0000ff
// a cone geometry for the xx axis
const xx = new THREE.ConeGeometry( this.baseRadius, this.size, 32 );
const xxMaterial = new THREE.MeshBasicMaterial( {color: this.xxColor} );
const xxMesh = new THREE.Mesh(xx, xxMaterial );
xxMesh.position.set(this.size/2,0,0);
xxMesh.rotation.z = -Math.PI / 2;
this.add( xxMesh );
// a cone geometry for the yy axis
const yy = new THREE.ConeGeometry( this.baseRadius, this.size, 32 );
const yyMaterial = new THREE.MeshBasicMaterial( {color: this.yyColor} );
const yyMesh = new THREE.Mesh(yy, yyMaterial );
yyMesh.position.set(0, this.size/2,0);
this.add( yyMesh );
// a cone geometry for the zz axis
const zz = new THREE.ConeGeometry( this.baseRadius, this.size, 32 );
const zzMaterial = new THREE.MeshBasicMaterial( {color: this.zzColor} );
const zzMesh = new THREE.Mesh(zz, zzMaterial );
zzMesh.position.set(0,0,this.size/2);
zzMesh.rotation.x = Math.PI / 2;
this.add( zzMesh );
// an axis helper
const axesHelper = new THREE.AxesHelper( 5 );
axesHelper.setColors ( new THREE.Color( this.xxColor ), new THREE.Color( this.yyColor ), new THREE.Color( this.zzColor ))
this.add( axesHelper );
}
}
MyAxis.prototype.isGroup = true;
export { MyAxis };