Repository navigation
Expand file tree
/
Copy patharrow.js
More file actions
72 lines (58 loc) · 2.01 KB
/
Copy patharrow.js
File metadata and controls
72 lines (58 loc) · 2.01 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
function Arrow(params, particles= false, lights = true, sprites=false){
this.group = new THREE.Group();
this.group.rotation.copy( params.euler );
this.group.position.copy( params.position );
this.group.scale.copy( params.scale );
//add arrow body to group
if( exists(params.tex) ){
this.texture = new THREE.TextureLoader().load( params.tex );
this.texture.wrapS = THREE.RepeatWrapping;
this.texture.wrapT = THREE.RepeatWrapping;
} else this.texture = undefined;
var geo = geo_arrow(params.rf, params.lf );
var mat = mat_arrow_tex(params.color, this.texture);
this.arrow = new THREE.Mesh( geo, mat );
this.group.add( this.arrow );
}
Arrow.prototype.update = function(frame, updateFrame=100){
if( exists(this.texture)){
this.texture.offset.x += 0.001;
this.texture.offset.y += 0.001;
}
}
Arrow.prototype.getGroup = function(){
return this.group;
}
Arrow.prototype.toggleVis = function(){
this.group.visible = !this.group.visible;
}
function geo_arrow( r_frac = 2, l_frac = 0.3, lod = 1){
// makes a noramlized arrow goemetry
var points = [];
var npts = 100*lod;
points.push(new THREE.Vector2(0,0));
for(var p=0; p<npts*(1-l_frac); p++){
points.push( new THREE.Vector2( 1, p/npts));
}
for(var p=0; p<=npts*l_frac; p++){
points.push( new THREE.Vector2(r_frac*(1-p/(npts*l_frac)), (p+npts*(1-l_frac))/npts ));
}
var arrow = new THREE.LatheGeometry( points, 24*lod );
arrow.translate(0,-0.5,0); //center
arrow.rotateX(Math.PI/2); // orient in z
return arrow;
}
function mat_arrow_tex(color, tex){
var mat = new THREE.MeshPhongMaterial( {
color: color,
// opacity:0.75,
// transparent: true,
emissive: 0x660000,
specular: 0x000000,
shininess: 0,
// side:THREE.DoubleSide,
// depthWrite : false,
map: tex,
});
return mat;
}