-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpointer.js
49 lines (42 loc) · 1.38 KB
/
pointer.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
"use strict";
import * as THREE from 'three' ;
/**
* Draw a "ray" from one 3D location to another in the world
* (used at the pointer).
*/
export class Pointer extends THREE.Mesh {
constructor(color,width) {
super() ;
this._origin = new THREE.Vector3() ;
this._target = new THREE.Vector3() ;
this._zAxis = new THREE.Vector3() ;
this._center = new THREE.Vector3() ;
this.geometry = new THREE.PlaneGeometry(1, 0.01) ;
this.geometry.rotateY(0.5 * Math.PI);
this.material = new THREE.MeshBasicMaterial({
//map: texture,
blending: THREE.AdditiveBlending,
color: color || new THREE.Color('yellow'),
side: THREE.DoubleSide,
depthWrite: false,
transparent: true
})
}
setFromTo(from, to) {
this._origin.copy(from);
this._target.copy(to);
this.reposition();
}
setFromDir(from, dir, distance) {
this._origin.copy(from);
this._target.copy(dir).normalize().multiplyScalar(distance||1.0).add(from);
this.reposition();
}
reposition() {
const distance = this._origin.distanceTo(this._target) ;
this.scale.z = distance;
this._center.copy(this._origin).add(this._target).divideScalar(2.0);
this.position.copy(this._center);
this.lookAt(this._target);
}
}