-
Notifications
You must be signed in to change notification settings - Fork 0
/
mscript.js
671 lines (455 loc) · 16.7 KB
/
mscript.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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r127/build/three.module.js'
const loader = new THREE.TextureLoader();
export var Pig = function(){
this.mesh = new THREE.Object3D();
// geometry for the pig's body
//const bodyGeometry = new THREE.BoxBufferGeometry(5, 2, 2.2);
const pigTexture = loader.load('./textures/pig.png');
const bodyGeometry = new THREE.Mesh(
new THREE.BoxGeometry(5, 2, 2.2),
new THREE.MeshPhongMaterial( { map: pigTexture } )
);
const noseGeometry = new THREE.BoxBufferGeometry(0.8, 1, 1.3);
const noseHoleGeometry = new THREE.BoxBufferGeometry(0.2, 0.5, 0.3);
const eyeGeometry = new THREE.BoxBufferGeometry(0.3, 0.3, 0.3);
const tailGeometry = new THREE.CylinderBufferGeometry(0.1, .2, 1.4);
// material for the pink pig's body
const bodyMaterial = new THREE.MeshPhongMaterial({ color: 0xFFC0CB });
const headMaterial = new THREE.MeshPhongMaterial({ color: 0xFFC0F0 });
const eyesMaterial = new THREE.MeshPhongMaterial({ color: 0x000000 });
const noseHoleMaterial = new THREE.MeshPhongMaterial({ color: 0x808080 });
// Mesh for the pig's body
//const = new THREE.Mesh(bodyGeometry, bodyMaterial);
const noseMesh = new THREE.Mesh(noseGeometry, headMaterial);
const noseHolesMesh1 = new THREE.Mesh(noseHoleGeometry,noseHoleMaterial);
const noseHolesMesh2 = new THREE.Mesh(noseHoleGeometry,noseHoleMaterial);
const eyeMesh1 = new THREE.Mesh(eyeGeometry,eyesMaterial);
const eyeMesh2 = new THREE.Mesh(eyeGeometry,eyesMaterial);
const tailMesh = new THREE.Mesh(tailGeometry, bodyMaterial);
noseHolesMesh1.position.set(4.4,1.2,0.3);
noseHolesMesh2.position.set(4.4,1.2,-0.3);
eyeMesh1.position.set(4,2.2,0.4);
eyeMesh2.position.set(4,2.2,-0.4);
// Create a geometry for the pig's head
const headGeometry = new THREE.BoxBufferGeometry(1.7, 2, 2);
// material for the pink pig's head
// mesh for the pig's head
const headMesh = new THREE.Mesh(headGeometry, bodyMaterial);
// Position the pig's head on top of the pig's body
headMesh.position.set(3.2, 1.5, 0);
noseMesh.position.set(4,1.2,0);
//pig's head to the scene
this.mesh.add(headMesh);
// geometry for the pig's legs
const legGeometry = new THREE.BoxBufferGeometry(.8, 2, .8);
// material for the pink pig's legs
const legMaterial = new THREE.MeshPhongMaterial({ color: 0xFFC0D3 });
//meshes for the pig's legs
const leftFrontLegMesh = new THREE.Mesh(legGeometry, legMaterial);
const rightFrontLegMesh = new THREE.Mesh(legGeometry, legMaterial);
const leftBackLegMesh = new THREE.Mesh(legGeometry, legMaterial);
const rightBackLegMesh = new THREE.Mesh(legGeometry, legMaterial);
// pig's legs on the bottom of the pig's body
leftFrontLegMesh.position.set(-1.8, -1.8, -0.7);
rightFrontLegMesh.position.set(-1.8, -1.8, 0.7);
leftBackLegMesh.position.set(1.8, -1.8, 0.7);
rightBackLegMesh.position.set(1.8, -1.8, -0.7);
tailMesh.position.set(-3,.8,0);
tailMesh.rotation.z = 20;
//Grouping pig's limbs
const groupedHeadPig = new THREE.Group();
groupedHeadPig.add(headMesh);
groupedHeadPig.add(eyeMesh1);
groupedHeadPig.add(eyeMesh2);
groupedHeadPig.add(noseMesh);
groupedHeadPig.add(noseHolesMesh1);
groupedHeadPig.add(noseHolesMesh2);
// Add the pig's body to the scene
this.mesh.add(bodyGeometry);
this.mesh.add(groupedHeadPig);
this.mesh.add(tailMesh);
this.mesh.add(rightFrontLegMesh);
this.mesh.add(leftBackLegMesh);
this.mesh.add(leftFrontLegMesh);
this.mesh.add(rightBackLegMesh);
// mesh for the pig's tail
// pig's tail on the back of the pig's body
var tic = 0;
var toc = 0;
var ticMax = 50;
var tocMax = 50;
this.animationUp = function(){
if(tic<ticMax){
toc = 0;
console.log("tic");
groupedHeadPig.rotation.z += 0.55 * 0.005;
rightFrontLegMesh.rotation.z += 1.3 * 0.005;
leftBackLegMesh.rotation.z -= 1.3 * 0.005;
leftFrontLegMesh.rotation.z -=1.3 * 0.005;
rightBackLegMesh.rotation.z +=1.3 * 0.005;
tailMesh.position.x+=1 * 0.006;;
tailMesh.rotation.z += 2 * 0.006;
tic++;
}
else if(toc<tocMax){
console.log("toc");
this.animationDown();
toc++;
}
else{tic=0;}
}
this.animationDown = function(){
groupedHeadPig.rotation.z -= 0.55 * 0.005;
rightFrontLegMesh.rotation.z -= 1.3 * 0.005;
leftBackLegMesh.rotation.z += 1.3 * 0.005;
leftFrontLegMesh.rotation.z +=1.3 * 0.005;
rightBackLegMesh.rotation.z -=1.3 * 0.005;
tailMesh.rotation.z -= 2 * 0.006;
tailMesh.position.x-=1 * 0.006;
}
this.setTicToc = function(t1){
ticMax = t1;
tocMax = t1;
}
}
export var Chicken = function() {
this.mesh = new THREE.Object3D();
//GEOMETRIES
const featherTexture = loader.load('./textures/feather.png');
const bodyGeometry = new THREE.Mesh(
new THREE.BoxGeometry(3, 2, 2.2),
new THREE.MeshPhongMaterial( { map: featherTexture } )
);
const headGeometry = new THREE.BoxGeometry(1, 2, 1.5);
const wingGeometry = new THREE.BoxGeometry(2,1,0.5);
const legGeometry = new THREE.BoxGeometry(0.2,2,0.2);
const footGeometry = new THREE.BoxGeometry(1,0.1,0.4);
const beakGeometry = new THREE.BoxGeometry(1.2,0.5,1.3);
const tongueGeometry = new THREE.BoxGeometry(1.2,.6,0.7); //indeed it's not literally its tongue tho...
const eyesGeometry = new THREE.BoxGeometry(.25, .25, .25);
//MATERIALS
const material = new THREE.MeshPhongMaterial({ color: 0xffffff });
const legMaterial = new THREE.MeshPhongMaterial({color: 0x9b870c })
const headMaterial = new THREE.MeshPhongMaterial({ color: 0xFF000D});
const eyeMaterial = new THREE.MeshPhongMaterial({ color: 0x000000});
//MESHES
// Create a mesh for the chicken's body
//const bodyMesh = new THREE.Mesh(bodyGeometry, material);
// Create a mesh for the chicken's head
const headMesh = new THREE.Mesh(headGeometry, material);
//legs meshes
const rightLegMesh = new THREE.Mesh(legGeometry, legMaterial);
const leftLegMesh = new THREE.Mesh(legGeometry, legMaterial);
//wings meshes
const leftWingMesh = new THREE.Mesh(wingGeometry, material);
const rightWingMesh = new THREE.Mesh(wingGeometry, material);
//feet meshes
const leftFootMesh = new THREE.Mesh(footGeometry, legMaterial);
const rightFootMesh = new THREE.Mesh(footGeometry, legMaterial);
//beak mesh
const beakMesh = new THREE.Mesh(beakGeometry, legMaterial);
//tongue mesh
const tongueMesh = new THREE.Mesh(tongueGeometry, headMaterial);
//eyes meshes
const leftEyeMesh = new THREE.Mesh(eyesGeometry, eyeMaterial);
const rightEyeMesh = new THREE.Mesh(eyesGeometry, eyeMaterial);
//POSITIONS & ROTATIONS
headMesh.position.set(1.5, 1.5, 0);
leftLegMesh.position.set(-0.3,-2,-0.5);
rightLegMesh.position.set(-0.3,-2,0.5);
leftWingMesh.position.set(0.8,0,1.35);
leftWingMesh.rotation.z = 35;
rightWingMesh.rotation.z = 35;
rightWingMesh.position.set(0.8,0,-1.35);
leftFootMesh.position.set(0,-3,-0.5);
rightFootMesh.position.set(0,-3,0.5);
beakMesh.position.set(2.2,1.7,0);
tongueMesh.position.set(2,1.2,0);
leftEyeMesh.position.set(2,2.2,0.5);
rightEyeMesh.position.set(2,2.2,-0.5);
//limbs nesting for the animations
const groupedLeftLeg = new THREE.Group();
groupedLeftLeg.add(leftFootMesh);
groupedLeftLeg.add(leftLegMesh);
const groupedRightLeg = new THREE.Group();
groupedRightLeg.add(rightLegMesh);
groupedRightLeg.add(rightFootMesh);
const groupedHead = new THREE.Group();
groupedHead.add(headMesh);
groupedHead.add(beakMesh);
groupedHead.add(tongueMesh);
groupedHead.add(leftEyeMesh);
groupedHead.add(rightEyeMesh);
// Add the body and head meshes to the `Chicken` object
this.mesh.add(bodyGeometry);
this.mesh.add(groupedHead);
this.mesh.add(leftWingMesh);
this.mesh.add(rightWingMesh);
this.mesh.add(groupedLeftLeg);
this.mesh.add(groupedRightLeg);
var tic = 0;
var toc = 0;
var ticMax = 20;
var tocMax = 20;
this.setTicToc = function(t1){
ticMax = t1;
tocMax = t1;
console.log(this.tocMax);
}
this.animationUp = function(){
if(tic<ticMax){
toc = 0;
this.moveWingsUp();
this.moveHeadUp();
this.moveLegsUp();
tic++;
}
else if(toc<tocMax){
this.animationDown();
toc++;
}
else{tic=0;}
}
this.animationDown = function(){
this.moveWingsDown();
this.moveHeadDown();
this.moveLegsDown();
}
this.moveWingsUp = function(){
leftWingMesh.rotation.x -= 25.5*0.0005;
rightWingMesh.rotation.x += 25.5*0.0005;
}
this.moveWingsDown = function(){
leftWingMesh.rotation.x += 25.5*0.0005;
rightWingMesh.rotation.x -= 25.5*0.0005;
}
this.moveLegsUp= function(){
groupedLeftLeg.rotation.z -= 5 * 0.002;
groupedRightLeg.rotation.z += 5 * 0.002;
}
this.moveLegsDown= function(){
groupedLeftLeg.rotation.z += 5 * 0.002;
groupedRightLeg.rotation.z -= 5 * 0.002;
}
this.moveHeadUp = function(){
groupedHead.rotation.z += 5 * 0.0015;
}
this.moveHeadDown = function(){
groupedHead.rotation.z -= 5 * 0.0015;
}
};
export var Penguin = function() {
this.mesh = new THREE.Object3D();
//GEOMETRIES
const featherTexture = loader.load('./textures/penguin.jpg');
const bodyGeometry = new THREE.BoxGeometry(3, 6, 3);
const bellyGeometry = new THREE.BoxGeometry(1, 4, 2.8);
const wingGeometry = new THREE.ConeBufferGeometry(1.5,.2,3);
const footGeometry = new THREE.BoxGeometry(1.2,0.15,0.7);
const beakGeometry = new THREE.ConeBufferGeometry(.3,1,3);
const eyesGeometry = new THREE.BoxGeometry(.2, .5, .2);
const tailGeometry = new THREE.BoxGeometry(2,0.15,1.5);
//MATERIALS
const material = new THREE.MeshPhongMaterial({ color: 0x505050 });
const bellyMaterial = new THREE.MeshPhongMaterial({ color: 0xE0E0E0 });
const beakMaterial = new THREE.MeshPhongMaterial({color: 0xFF8C00 })
const eyeMaterial = new THREE.MeshPhongMaterial({ color: 0x000000});
//MESHES
// Create a mesh for the chicken's body
const bodyMesh = new THREE.Mesh(bodyGeometry, material);
const tailMesh = new THREE.Mesh(tailGeometry, material);
const bellyMesh = new THREE.Mesh(bellyGeometry, bellyMaterial);
//legs meshes
//wings meshes
const leftWingMesh = new THREE.Mesh(wingGeometry, new THREE.MeshPhongMaterial( { map: featherTexture }));;
const rightWingMesh = new THREE.Mesh(wingGeometry, new THREE.MeshPhongMaterial( { map: featherTexture }));
//feet meshes
const leftFootMesh = new THREE.Mesh(footGeometry, beakMaterial);
const rightFootMesh = new THREE.Mesh(footGeometry, beakMaterial);
//beak mesh
const beakMeshUp = new THREE.Mesh(beakGeometry, beakMaterial);
//tongue mesh
//eyes meshes
const leftEyeMesh = new THREE.Mesh(eyesGeometry, eyeMaterial);
const rightEyeMesh = new THREE.Mesh(eyesGeometry, eyeMaterial);
//POSITIONS & ROTATIONS
leftWingMesh.rotation.x = Math.PI / 2;
leftWingMesh.rotation.z = Math.PI;
leftWingMesh.position.set(0,.5,-1.65);
rightWingMesh.rotation.x = Math.PI / 2;
rightWingMesh.position.set(0,.5,1.65);
leftFootMesh.position.set(1.7,-2.9,-0.5);
rightFootMesh.position.set(1.7,-2.9,0.5);
beakMeshUp.position.set(2,1.7,0);
beakMeshUp.rotation.z=4.5;
beakMeshUp.rotation.x=-1.5;
bellyMesh.position.set(1.1,-.7,0);
leftEyeMesh.position.set(1.5,2.5,0.6);
rightEyeMesh.position.set(1.5,2.5,-0.6);
tailMesh.position.set(-2,-2.8,0)
const groupedHead = new THREE.Group();
groupedHead.add(beakMeshUp);
groupedHead.add(leftEyeMesh);
groupedHead.add(rightEyeMesh);
// Add the body and head meshes to the `Chicken` object
this.mesh.add(bodyMesh);
this.mesh.add(groupedHead);
this.mesh.add(bellyMesh);
this.mesh.add(leftWingMesh);
this.mesh.add(rightWingMesh);
this.mesh.add(leftFootMesh);
this.mesh.add(rightFootMesh);
this.mesh.add(tailMesh);
var tic = 0;
var toc = 0;
var ticMax = 20;
var tocMax = 20;
this.setTicToc = function(t1){
ticMax = t1;
tocMax = t1;
console.log(this.tocMax);
}
this.animationUp = function(){
if(tic<ticMax){
toc = 0;
this.moveWingsUp();
this.moveFeetUp();
//this.moveLegsUp();
tic++;
}
else if(toc<tocMax){
this.animationDown();
toc++;
}
else{tic=0;}
}
this.animationDown = function(){
this.moveWingsDown();
this.moveFeetDown();
//this.moveLegsDown();
}
this.moveWingsUp = function(){
leftWingMesh.rotation.x += 20.5*0.0005;
leftWingMesh.position.z -= 12.5*0.0005;
rightWingMesh.rotation.x -= 20.5*0.0005;
rightWingMesh.position.z += 12.5*0.0005;
}
this.moveWingsDown = function(){
leftWingMesh.rotation.x -= 20.5*0.0005;
leftWingMesh.position.z += 12.5*0.0005;
rightWingMesh.rotation.x += 20.5*0.0005;
rightWingMesh.position.z -= 12.5*0.0005;
}
this.moveFeetUp= function(){
leftFootMesh.rotation.z += 8 * 0.0005;
rightFootMesh.rotation.z += 8 * 0.0005;
tailMesh.rotation.z -= 10 * 0.0005;
}
this.moveFeetDown= function(){
leftFootMesh.rotation.z -= 8 * 0.0005;
rightFootMesh.rotation.z -= 8 * 0.0005;
tailMesh.rotation.z += 10 * 0.0005;
}
};
export var Chef = function() {
this.mesh = new THREE.Object3D();
const bodyGeometry = new THREE.BoxGeometry(3, 4, 2);
const material = new THREE.MeshPhongMaterial({ color: 0xffffff });
const bodyMesh = new THREE.Mesh(bodyGeometry, material);
const headGeometry = new THREE.BoxGeometry(1.5, 1.5, 1.5);
const headMaterial = new THREE.MeshPhongMaterial({ color: 0xFFCDCD });
const headMesh = new THREE.Mesh(headGeometry, headMaterial);
// Position the head mesh on top of the body mesh
headMesh.position.set(0, 3, 0);
const armGeometry = new THREE.BoxGeometry(0.5, 3, 0.75);
const armMaterial = new THREE.MeshPhongMaterial({ color: 0xFFCDCD });
const leftArmMesh = new THREE.Mesh(armGeometry, armMaterial);
// Position the left arm mesh on the side of the body mesh
leftArmMesh.position.set(2, 1.25, 1);
leftArmMesh.rotation.set(1.7,0,0);
const rightArmMesh = new THREE.Mesh(armGeometry, armMaterial);
// Position the right arm mesh on the other side of the body mesh
rightArmMesh.position.set(-2, 2, 1);
rightArmMesh.rotation.set(-2, 0, 0);
const legGeometry = new THREE.BoxGeometry(0.75, 3.2, 0.5);
const legMaterial = new THREE.MeshPhongMaterial({ color: 0xFFCDCD });
const leftLegMesh = new THREE.Mesh(legGeometry, legMaterial);
// Position the left leg mesh below the body mesh
leftLegMesh.position.set(0.7, -3.25, 0);
const rightLegMesh = new THREE.Mesh(legGeometry, legMaterial);
// Position the right leg mesh below the body mesh
rightLegMesh.position.set(-0.7, -3.25, 0);
const hatGeometry = new THREE.CylinderBufferGeometry(.7,.7,1.5,6);
const hatTopGeometry = new THREE.CylinderBufferGeometry(1,1,.8,5);
const knifeGripGeometry = new THREE.BoxBufferGeometry(.2,.2,1.2);
const bladeTexture = loader.load('./textures/blade.png');
const bladeMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.08,1,2),
new THREE.MeshPhongMaterial( { map: bladeTexture } )
);
const gripMaterial = new THREE.MeshPhongMaterial({ color: 0x000000 });
const gripMesh = new THREE.Mesh(knifeGripGeometry,gripMaterial);
const hatTopMesh = new THREE.Mesh(hatTopGeometry,material);
const hatMesh = new THREE.Mesh(hatGeometry,material);
hatMesh.position.set(0,4.5,0);
hatTopMesh.position.set(0,5.5,0);
gripMesh.rotation.x=2;
bladeMesh.rotation.x=2;
gripMesh.position.set(-2,3,2.5);
bladeMesh.position.set(-2,3.8,3.3);
//grouping elements
const groupedRightArm = new THREE.Group();
groupedRightArm.add(rightArmMesh);
groupedRightArm.add(gripMesh);
groupedRightArm.add(bladeMesh);
const groupedHeadChef = new THREE.Group();
groupedHeadChef.add(headMesh);
groupedHeadChef.add(hatMesh);
groupedHeadChef.add(hatTopMesh);
// Add the body, head, arms, and legs meshes to the `Dummy` object
this.mesh.add(bodyMesh);
this.mesh.add(leftArmMesh);
this.mesh.add(groupedRightArm);
this.mesh.add(leftLegMesh);
this.mesh.add(rightLegMesh);
this.mesh.add(groupedHeadChef);
var tic = 0;
var toc = 0;
var ticMax = 20;
var tocMax = 20;
this.setTicToc = function(t1){
ticMax = t1;
tocMax = t1;
console.log(this.tocMax);
}
this.animationUp = function(){
if(tic<ticMax){
toc = 0;
groupedHeadChef.rotation.x += .5 * 0.005;
groupedRightArm.rotation.x -= 1.5 * 0.005;
leftLegMesh.rotation.x +=1.7 * 0.005;
leftLegMesh.position.z -=1.9 * 0.005;
rightLegMesh.rotation.x -=1.7 * 0.005;
rightLegMesh.position.z +=1.9 * 0.005;
leftArmMesh.rotation.x -= 2.3 * 0.005;
tic++;
}
else if(toc<tocMax){
this.animationDown();
toc++;
}
else{tic=0;}
}
this.animationDown = function(){
groupedHeadChef.rotation.x -= .5 * 0.005;
groupedRightArm.rotation.x += 1.5 * 0.005;
leftLegMesh.rotation.x -=1.7 * 0.005;
rightLegMesh.rotation.x +=1.7 * 0.005;
rightLegMesh.position.z -=1.9 * 0.005;
leftLegMesh.position.z +=1.9 * 0.005;
leftArmMesh.rotation.x += 2.3 * 0.005;
}
this.animationDied = function(){
this.mesh.rotation.y += .5 *0.005;
}
};