forked from nmalex/three.js-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RayysAxisHelper.js
83 lines (70 loc) · 2.32 KB
/
RayysAxisHelper.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class RayysAxisHelper {
create(bias, n) {
if (n === undefined) n = 2;
if (n < 1) n = 2;
var node = new THREE.Object3D();
var biasArr = [
[0, bias, 0],
[0, -bias, 0],
[bias, 0, 0],
[-bias, 0, 0],
[0, 0, bias],
[0, 0, -bias],
[0, bias, bias],
[0, -bias, bias],
[bias, 0, bias],
[-bias, 0, bias],
[0, bias, bias],
[0, bias, -bias],
[0, bias, -bias],
[0, -bias, -bias],
[bias, 0, -bias],
[-bias, 0, -bias],
[0, -bias, bias],
[0, -bias, -bias],
];
var geometryX = new THREE.Geometry();
var geometryY = new THREE.Geometry();
var geometryZ = new THREE.Geometry();
var step = 1 / n;
for (var k = 0; k < biasArr.length; k++) {
// axis X
for (var xi = 0; xi < 1; xi += step) {
for (var xj = 0; xj < 1; xj += step) {
geometryX.vertices.push(new THREE.Vector3(0, 0 + xi * biasArr[k][1], 0 + xj * biasArr[k][2]));
geometryX.vertices.push(new THREE.Vector3(1, 0 + xi * biasArr[k][1], 0 + xj * biasArr[k][2]));
}
}
// axis Y
for (var yi = 0; yi < 1; yi += step) {
for (var yj = 0; yj < 1; yj += step) {
geometryY.vertices.push(new THREE.Vector3(0 + yi * biasArr[k][0], 0, 0 + yj * biasArr[k][2]));
geometryY.vertices.push(new THREE.Vector3(0 + yi * biasArr[k][0], 1, 0 + yj * biasArr[k][2]));
}
}
// axis Z
for (var zi = 0; zi < 1; zi += step) {
for (var zj = 0; zj < 1; zj += step) {
geometryZ.vertices.push(new THREE.Vector3(0 + zi * biasArr[k][1], 0 + zj * biasArr[k][2], 0));
geometryZ.vertices.push(new THREE.Vector3(0 + zi * biasArr[k][1], 0 + zj * biasArr[k][2], 1));
}
}
}
var lineX = new THREE.LineSegments(geometryX, new THREE.LineBasicMaterial({
color: 0xff0000
}));
lineX.name = "lineX";
node.add(lineX);
var lineY = new THREE.LineSegments(geometryY, new THREE.LineBasicMaterial({
color: 0x00ff00
}));
lineX.name = "lineY";
node.add(lineY);
var lineZ = new THREE.LineSegments(geometryZ, new THREE.LineBasicMaterial({
color: 0x0000ff
}));
lineX.name = "lineZ";
node.add(lineZ);
return node;
}
}