-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
230 lines (183 loc) · 6.86 KB
/
Copy pathindex.js
File metadata and controls
230 lines (183 loc) · 6.86 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// Namespace('Labeling').Draw3D = ((() =>
// ({
draw3DLine() {
const canvas = document.getElementById('board');
const setAntialias = false;
const showWireframe = false;
const shapeShadows = false;
const sceneTransparentColor = 0x000000;
const coneRadius = 1;
const coneHeight = 2;
const coneRadialSegments = 6;
const coneHeightSegments = 6;
const coneColor = 0xffffff;
const cylinderRadius = .5;
const cylinderRadialSegments = 4;
const cylinderHeightSegments = 4;
const cylinderColor = 0xffffff;
let numberOfLights = 2
let numberOfArrows = 4
function init() {
var lights = [numberOfLights];
var lightCastShadow = true;
var lightColor = 0xffffff;
var coneAxisX = -2.5;
var coneAxisY = 0;
var coneAxisZ = 0;
var coneRotateX = Math.PI / 2;
var coneRotateY = 0;
var coneRotateZ = Math.PI / 2;
var cylinderLength = 6;
var cylinderAxisX = 0;
var cylinderAxisY = -1;
var cylinderAxisZ = 0;
var cylinderRotateX = 0;
var cylinderRotateY = 0;
var cylinderRotateZ = 0;
var scene = new THREE.Scene();
// Add Light environment
var light = getDirectionalLight(1);
light.name = 'directionalLight';
light.position.set(0, 0, 15);
scene.add(light);
// Call SHAPES to be generated
var cylinder = getCylinder(cylinderRadius, cylinderLength, cylinderRadialSegments, cylinderHeightSegments, cylinderColor);
var cone = getCone(coneRadius, coneHeight, coneRadialSegments, coneHeightSegments, coneColor);
cylinder.add(cone);
cylinder.name = 'arrow';
cylinder.position.set(14, -5, 0);
cone.rotation.y += .3;
// SHAPE POINTING DIRECTION /////////////////////////////////////////////
if (cylinder.position.y >= 0) {
cone.position.y = cylinder.geometry.parameters.height / 1.7;
} else if (cylinder.position.y < 0) {
cone.rotation.z += Math.PI;
cone.position.y = -cylinder.geometry.parameters.height / 1.7; // Positive Y
} else {
cone.position.y = cylinder.geometry.parameters.height / 1.7; // Positive Y
}
var arrow = scene.getObjectByName('arrow');
var arrowList = generateArrows(numberOfArrows, cylinderLength);
console.log(arrowList);
for (var index = 0; index < numberOfArrows; index++) {
scene.add(arrowList[index]);
}
scene.add(cylinder);
// var child = arrow.children[0].geometry.parameters.height;
// printShotgun(child);
var cameraDimensions = 15;
var camera = new THREE.OrthographicCamera(
-cameraDimensions,
cameraDimensions,
cameraDimensions,
-cameraDimensions,
1,
1000
);
camera.position.set(0, 0, 2);
var renderer = new THREE.WebGLRenderer({ antialias: setAntialias, alpha: true });
renderer.setClearColor(0x000000, 0);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.shadowMap.enabled = true;
renderer.setSize(canvas.offsetWidth - 1, canvas.offsetHeight - 1);
canvas.appendChild(renderer.domElement);
animate(renderer, scene, camera, light);
}
function getBox(rectangleWidth, rectangleHeight, rectangleLength, rectangleColor) {
var mesh = new THREE.Mesh(
new THREE.BoxGeometry(rectangleWidth, rectangleHeight, rectangleLength),
new THREE.MeshPhongMaterial({ color: rectangleColor, wireframe: showWireframe, }),
);
mesh.castShadow = true;
return mesh;
}
function getCylinder(cylinderRadius, cylinderLength, cylinderRadialSegments, cylinderHeightSegments, cylinderColor) {
var mesh = new THREE.Mesh(
new THREE.CylinderGeometry(cylinderRadius, cylinderRadius, cylinderLength, cylinderRadialSegments, cylinderHeightSegments),
new THREE.MeshPhongMaterial({ color: cylinderColor, wireframe: showWireframe, }),
);
mesh.castShadow = true;
return mesh;
}
function getCone(coneRadius, coneHeight, coneRadialSegments, coneHeightSegments, coneColor) {
var mesh = new THREE.Mesh(
new THREE.ConeGeometry(coneRadius, coneHeight, coneRadialSegments, coneHeightSegments),
new THREE.MeshPhongMaterial({ color: coneColor, wireframe: showWireframe, }),
);
mesh.castShadow = true;
return mesh;
}
function generateArrows(numberOfArrows, cylinderLength) {
var arrowList = [numberOfArrows];
for (var index = 0; index < numberOfArrows; index++) {
arrowList[index] = getCylinder(cylinderRadius, cylinderLength, cylinderRadialSegments, cylinderHeightSegments, cylinderColor);
var cone = getCone(coneRadius, coneHeight, coneRadialSegments, coneHeightSegments, coneColor);
if (index % 2 == 0) {
arrowList[index].position.x = Math.floor(Math.random() * 10);
arrowList[index].position.y = Math.floor(Math.random() * 10);
} else {
arrowList[index].position.x = -Math.floor(Math.random() * 10);
arrowList[index].position.y = -Math.floor(Math.random() * 10);
}
if (arrowList[index].position.y >= 0) {
cone.position.y = arrowList[index].geometry.parameters.height / 1.7;
}
else if (arrowList[index].position.y < 0) {
cone.rotation.z += Math.PI;
cone.position.y = -arrowList[index].geometry.parameters.height / 1.7; // Positive Y
}
else {
cone.position.y = arrowList[index].geometry.parameters.height / 1.7; // Positive Y
}
cone.rotation.y += .3;
arrowList[index].add(cone);
}
return arrowList;
}
function getAmbientLight(intensity) {
var light = new THREE.AmbientLight(0xffffff, intensity);
return light;
}
function getDirectionalLight(intensity) {
var light = new THREE.DirectionalLight(0xffffff, intensity);
light.castShadow = true;
return light;
}
function getSpotLight(intensity) {
var light = new THREE.SpotLight(0xffffff, intensity);
light.castShadow = true;
// Treat the light.shadow.bias on a case by case bases.
// light.shadow.bias = 0.001;
// shadow.mapSize width and height default value is 1024.
light.shadow.mapSize.width = 256;
light.shadow.mapSize.height = 256;
return light;
}
function dynamicLights(light) {
var time = Date.now() * 0.0005;
light.position.x = Math.sin(time * 0.7) * 20;
light.position.y = Math.cos(time * 0.5) * 25;
}
function stretchArrowBody(arrow) {
return arrow.geometry.parameters.height += 0.1;
// arrow.geometry.verticesNeedUpdate = true;
}
function printShotgun(obj) {
console.log(obj);
}
// Updates the browser to allow for animation.
function animate(renderer, scene, camera, light) {
renderer.render(scene, camera);
// dynamicLights(light);
///////////////////////////////////////////
// stretchArrowBody(arrow);
// printShotgun(arrow);
/////////////////////////////////////////////
requestAnimationFrame(function () {
// arrow.geometry.verticesNeedUpdate = true;
animate(renderer, scene, camera, light);
});
}
var scene = init();
// }
// })));