-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
463 lines (370 loc) · 12.5 KB
/
script.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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
window.global ||= window;
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import "./math.js"
var deletables = [];
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.01, 2000 );
const loader = new GLTFLoader();
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.shadowMap.enabled = true
renderer.setSize( window.innerWidth, window.innerHeight );
document.getElementById('output').appendChild( renderer.domElement );
const controls = new OrbitControls(camera, renderer.domElement)
controls.enableDamping = true
const light1 = new THREE.AmbientLight( 0xFFFFFF, 1 ); // soft white light
scene.add( light1 );
const light2 = new THREE.SpotLight()
light2.position.set(10, 20, 50)
scene.add(light2)
const light3 = new THREE.SpotLight()
light3.position.set(-10, -40, -10)
scene.add(light3)
const light4 = new THREE.SpotLight()
light4.position.set(10, 35, -50)
scene.add(light4)
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
const material = new THREE.MeshBasicMaterial( { color: 0xDAA520 } );
const cube = new THREE.Mesh( geometry, material );
//scene.add( cube );
scene.background = new THREE.Color( 0xffffff );
var qty8 = document.getElementById("8qty");
var prio8 = document.getElementById("8qtyPriority");
var prio8out = document.getElementById("prio8out");
prio8out.innerHTML = prio8.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle)
prio8.oninput = function() {
prio8out.innerHTML = this.value;
}
qty8.oninput = function() {
prio8.max = this.value;
prio8.value = 0;
prio8out.innerHTML = prio8.value;
}
var qty12 = document.getElementById("12qty");
var prio12 = document.getElementById("12qtyPriority");
var prio12out = document.getElementById("prio12out");
prio12out.innerHTML = prio12.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle)
prio12.oninput = function() {
prio12out.innerHTML = this.value;
}
qty12.oninput = function() {
prio12.max = this.value;
prio12.value = 0;
prio12out.innerHTML = prio12.value;
}
var qty16 = document.getElementById("16qty");
var prio16 = document.getElementById("16qtyPriority");
var prio16out = document.getElementById("prio16out");
prio16out.innerHTML = prio16.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle)
prio16.oninput = function() {
prio16out.innerHTML = this.value;
}
qty16.oninput = function() {
prio16.max = this.value;
prio16.value = 0;
prio16out.innerHTML = prio16.value;
}
var qty24 = document.getElementById("24qty");
var prio24 = document.getElementById("24qtyPriority");
var prio24out = document.getElementById("prio24out");
prio24out.innerHTML = prio24.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle)
prio24.oninput = function() {
prio24out.innerHTML = this.value;
}
qty24.oninput = function() {
prio24.max = this.value;
prio24.value = 0;
prio24out.innerHTML = prio24.value;
}
// 32
var qty32 = document.getElementById("32qty");
var prio32 = document.getElementById("32qtyPriority");
var prio32out = document.getElementById("prio32out");
prio32out.innerHTML = prio32.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle)
prio32.oninput = function() {
prio32out.innerHTML = this.value;
}
qty32.oninput = function() {
prio32.max = this.value;
prio32.value = 0;
prio32out.innerHTML = prio24.value;
}
// importing the path
import assyPath from './asm.glb'
import slotPath from './slots.glb'
import feeder8Path from './8mm-feeder.glb'
import feeder12Path from './12mm-feeder.glb'
import strip8Path from './8mm-strip-feeder.glb'
import strip12Path from './12mm-strip-feeder.glb'
import strip16Path from './16mm-strip-feeder.glb'
import strip24Path from './24mm-strip-feeder.glb'
import strip32Path from './32mm-strip-feeder.glb'
//load lumen
loader.load( assyPath, function ( gltf )
{
var part = gltf.scene;
//part.scale.set(.1, .1, .1);
part.position.y = 0; //-3
part.position.x = -20; //-20
part.rotation.x = 0;
scene.add( part );
}, undefined, function ( error ) {
console.error( error );
}
);
//load slots
loader.load( slotPath, function ( gltf )
{
var part = gltf.scene;
//part.scale.set(.1, .1, .1);
part.position.y = 0; //-3
part.position.x = -20; //-20
part.rotation.x = -1.5708;
scene.add( part );
}, undefined, function ( error ) {
console.error( error );
}
);
camera.position.z = 50;
window.removeObject = function(object){
scene.remove(object);
// object.geometry.dispose();
// object.material.dispose();
// object = undefined;
}
window.clearScene = function(){
for(let i of deletables){
removeObject(i);
}
deletables = [];
}
window.render8 = function(x, z, rotation){
loader.load( feeder8Path, function ( gltf )
{
var part = gltf.scene;
//part.scale.set(.1, .1, .1);
part.position.y = 0;
part.position.z = z;
part.position.x = x;
//this is to make them upright
part.rotation.x = 0;
//this is to flip them facing the right direction
part.rotation.y = rotation;
scene.add( part );
deletables.push(part);
}, undefined, function ( error ) {
console.error( error );
}
);
}
window.render12 = function(x, z, rotation, rail){
loader.load( feeder12Path, function ( gltf )
{
if(rail == 0){
var part = gltf.scene;
part.scale.set(100, 100, 100);
part.position.y = 9.8;
part.position.z = z+15.2;
part.position.x = x+10.15;
//this is to make them upright
part.rotation.x = 3.14159/2;
//this is to flip them facing the right direction
part.rotation.z = rotation - (3.14159/2);
scene.add( part );
deletables.push(part);
}
else{
var part = gltf.scene;
part.scale.set(100, 100, 100);
part.position.y = 9.9;
part.position.z = z-15.28;
part.position.x = x-10.2;
//this is to make them upright
part.rotation.x = 3.14159/2;
//this is to flip them facing the right direction
part.rotation.z = rotation - (3.14159/2);
scene.add( part );
deletables.push(part);
}
}, undefined, function ( error ) {
console.error( error );
}
);
}
window.renderStrip8 = function(x, z, rotation){
loader.load( strip8Path, function ( gltf )
{
var part = gltf.scene;
part.scale.set(.1, .1, .1);
part.position.y = 4.3;
part.position.z = z;
part.position.x = x;
//this is to make them upright
part.rotation.x = 0;
//this is to flip them facing the right direction
part.rotation.y = rotation;
scene.add( part );
deletables.push(part);
}, undefined, function ( error ) {
console.error( error );
}
);
}
window.renderStrip12 = function(x, z, rotation){
loader.load( strip12Path, function ( gltf )
{
var part = gltf.scene;
part.scale.set(.1, .1, .1);
part.position.y = 4.3;
part.position.z = z;
part.position.x = x;
//this is to make them upright
part.rotation.x = 0;
//this is to flip them facing the right direction
part.rotation.y = rotation;
scene.add( part );
deletables.push(part);
}, undefined, function ( error ) {
console.error( error );
}
);
}
window.renderStrip16 = function(x, z, rotation){
loader.load( strip16Path, function ( gltf )
{
var part = gltf.scene;
part.scale.set(.1, .1, .1);
part.position.y = 4.3;
part.position.z = z;
part.position.x = x;
//this is to make them upright
part.rotation.x = 0;
//this is to flip them facing the right direction
part.rotation.y = rotation;
scene.add( part );
deletables.push(part);
}, undefined, function ( error ) {
console.error( error );
}
);
}
window.renderStrip24 = function(x, z, rotation){
loader.load( strip24Path, function ( gltf )
{
var part = gltf.scene;
part.scale.set(.1, .1, .1);
part.position.y = 4.3;
part.position.z = z;
part.position.x = x;
//this is to make them upright
part.rotation.x = 0;
//this is to flip them facing the right direction
part.rotation.y = rotation;
scene.add( part );
deletables.push(part);
}, undefined, function ( error ) {
console.error( error );
}
);
}
window.renderStrip32 = function(x, z, rotation){
loader.load( strip32Path, function ( gltf )
{
var part = gltf.scene;
part.scale.set(.1, .1, .1);
part.position.y = 4.3;
part.position.z = z;
part.position.x = x;
//this is to make them upright
part.rotation.x = 0;
//this is to flip them facing the right direction
part.rotation.y = rotation;
scene.add( part );
deletables.push(part);
}, undefined, function ( error ) {
console.error( error );
}
);
}
window.addFeeders = function(slotSolve){
//clear scene:
clearScene();
//this is how far over the first slot is mounted, effectively
var startingX = -20;
var rail = 0;
var xPos = startingX;
var zPos = 0;
var feederWidth = 1.5;
var spacing = 0.06;
var rotation = 0;
for(let i = 0; i < slotSolve.length; i++){
if(i == 25){
zPos = -43;
xPos = 1.7;
rotation = 3.14159;
rail = 1;
}
//if an 8mm feeder
if(slotSolve[i] == 0){
render8(xPos, zPos, rotation)
xPos = xPos + feederWidth + spacing;
}
// if a 12mm feeder
else if(slotSolve[i] == 1){
render12(xPos, zPos, rotation, rail)
xPos = xPos + feederWidth + spacing;
}
}
}
window.addStrips = function(uSolve){
if(true){
//this is how far over the first slot is mounted, effectively
var startingX = -7.95;
var xPos = startingX;
var zPos = -19.5;
var feederWidth = 4.45;
var spacing = 0.05;
var rotation = 0;
for(let i = 0; i < uSolve.length; i++){
//if an 8mm feeder
if(uSolve[i] == 0){
renderStrip8(xPos, zPos, rotation)
xPos = xPos + feederWidth + spacing;
}
// if a 12mm feeder
else if(uSolve[i] == 1){
renderStrip12(xPos, zPos, rotation)
xPos = xPos + feederWidth + spacing;
}
// if a 16mm feeder
else if(uSolve[i] == 2){
renderStrip16(xPos, zPos, rotation)
xPos = xPos + feederWidth + spacing;
}
// if a 24mm feeder
else if(uSolve[i] == 3){
renderStrip24(xPos - 0.74, zPos, rotation)
xPos = xPos + feederWidth + spacing;
}
// if a 32mm feeder
else if(uSolve[i] == 4){
renderStrip32(xPos - 0.7, zPos, rotation)
xPos = xPos + feederWidth + spacing;
}
}
}
}
function animate() {
requestAnimationFrame( animate );
// part.rotation.x += 0.01;
// part.rotation.y += 0.01;
controls.update()
renderer.render( scene, camera );
}
animate();