-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
676 lines (544 loc) · 21.9 KB
/
test.html
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
669
670
671
672
673
674
675
676
<html lang="en">
<head>
<title>Projects</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
<style>
body{
overflow: hidden;
background-color: #000000;
margin: 0px;
background-size: cover;
background-repeat: no-repeat;
}
a {
color: #2fa1d6;
}
p {
max-width: 600px;
margin-left: auto;
margin-right: auto;
padding: 0 2em;
}
</style>
</head>
<body>
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "./build/three.module.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import Stats from './jsm/libs/stats.module.js';
import { GUI } from './jsm/libs/lil-gui.module.min.js';
import { OrbitControls } from './jsm/controls/OrbitControls.js';
import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
import { CSS3DRenderer, CSS3DObject } from './jsm/renderers/CSS3DRenderer.js';
import { FontLoader } from './jsm/loaders/FontLoader.js';
import { TextGeometry } from './jsm/geometries/TextGeometry.js';
import { ShadowMapViewer } from './jsm/utils/ShadowMapViewer.js';
const SHADOW_MAP_WIDTH = 2048, SHADOW_MAP_HEIGHT = 1024;
let container, stats, clock, gui, mixer, actions, activeAction, previousAction;
let camera, scene, renderer, model, face,renderer2,scene2;
let video, videoImage, videoImageContext, videoTexture;
let video2, videoImage2, videoImageContext2, videoTexture2;
let video3, videoImage3, videoImageContext3, videoTexture3;
let video4, videoImage4, videoImageContext4, videoTexture4;
let light, light2,light3,light4,light5;
const api = { state: 'Walking' };
let current_state = 'Idle';
var xSpeed = 0.1;
var ySpeed = 0.25;
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 200 );
camera.position.set( 45, 20, 40 );
scene = new THREE.Scene();
clock = new THREE.Clock();
// lights
const dirLight = new THREE.DirectionalLight( 0xffffff,0.05 );
dirLight.position.set( 0, 20, 10 );
scene.add( dirLight );
light2 = new THREE.SpotLight( 0xab5cff,10, 0, Math.PI / 5, 0.3 );
light2.position.set(20, 10, 0);
light2.target.position.set( 20, 0 ,0);
light2.castShadow = true;
light2.shadow.camera.near = 100;
light2.shadow.camera.far = 500;
light2.shadow.bias = 0.0001;
light2.shadow.mapSize.width = SHADOW_MAP_WIDTH;
light2.shadow.mapSize.height = SHADOW_MAP_HEIGHT;
scene.add( light2 );
scene.add( light2.target );
light = new THREE.SpotLight( 0xab5cff,5, 0, Math.PI / 5, 0.3 );
light.position.set(30, 0, 30);
light.target.position.set( 0, 20 ,15);
light.castShadow = true;
light.shadow.camera.near = 100;
light.shadow.camera.far = 500;
light.shadow.bias = 0.0001;
light.shadow.mapSize.width = SHADOW_MAP_WIDTH;
light.shadow.mapSize.height = SHADOW_MAP_HEIGHT;
light3 = new THREE.SpotLight( 0xab5cff,5, 0, Math.PI / 5, 0.3 );
light3.position.set(30, 0, 70);
light3.target.position.set( 0, 20 ,60);
light3.castShadow = true;
light3.shadow.camera.near = 100;
light3.shadow.camera.far = 500;
light3.shadow.bias = 0.0001;
light3.shadow.mapSize.width = SHADOW_MAP_WIDTH;
light3.shadow.mapSize.height = SHADOW_MAP_HEIGHT;
light4 = new THREE.SpotLight( 0xab5cff,5, 0, Math.PI / 5, 0.3 );
light4.position.set(30, 0, 110);
light4.target.position.set( 0, 20 ,100);
light4.castShadow = true;
light4.shadow.camera.near = 100;
light4.shadow.camera.far = 500;
light4.shadow.bias = 0.0001;
light4.shadow.mapSize.width = SHADOW_MAP_WIDTH;
light4.shadow.mapSize.height = SHADOW_MAP_HEIGHT;
light5 = new THREE.SpotLight( 0xab5cff,5, 0, Math.PI / 5, 0.3 );
light5.position.set(30, 0, 150);
light5.target.position.set( 0, 20 ,140);
light5.castShadow = true;
light5.shadow.camera.near = 100;
light5.shadow.camera.far = 500;
light5.shadow.bias = 0.0001;
light5.shadow.mapSize.width = SHADOW_MAP_WIDTH;
light5.shadow.mapSize.height = SHADOW_MAP_HEIGHT;
const loader = new GLTFLoader();
loader.load( './board/collision.glb', function ( gltf ) {
scene.add( gltf.scene );
gltf.scene.position.set(0,0,10);
gltf.scene.scale.set(5,5,5);
gltf.scene.rotateX(-3.14/2);
gltf.scene.rotateZ(3.14/4);
} );
const loader2 = new GLTFLoader();
loader2.load( './board/collision.glb', function ( gltf ) {
scene.add( gltf.scene );
gltf.scene.position.set(0,0,50);
gltf.scene.scale.set(5,5,5);
gltf.scene.rotateX(-3.14/2);
gltf.scene.rotateZ(3.14/4);
} );
const loader3 = new GLTFLoader();
loader3.load( './board/collision.glb', function ( gltf ) {
scene.add( gltf.scene );
gltf.scene.position.set(0,0,90);
gltf.scene.scale.set(5,5,5);
gltf.scene.rotateX(-3.14/2);
gltf.scene.rotateZ(3.14/4);
} );
const loader4 = new GLTFLoader();
loader4.load( './board/collision.glb', function ( gltf ) {
scene.add( gltf.scene );
gltf.scene.position.set(0,0,130);
gltf.scene.scale.set(5,5,5);
gltf.scene.rotateX(-3.14/2);
gltf.scene.rotateZ(3.14/4);
} );
const loader5 = new GLTFLoader();
loader5.load( 'models/gltf/RobotExpressive/RobotExpressive.glb', function ( gltf ) {
model = gltf.scene;
model.scale.set(1.5,1.5,1.5);
model.position.set(20,0,0);
scene.add( model );
createGUI( model, gltf.animations );
}, undefined, function ( e ) {
console.error( e );
} );
const loader6 = new GLTFLoader();
loader6.load( 'videos/ground/scene.gltf', function ( gltf ) {
let model2 = gltf.scene;
model2.scale.set(25,.2,25);
model2.position.set(0,0,0);
scene.add( model2 );
}, undefined, function ( e ) {
console.error( e );
} );
const loader7 = new GLTFLoader();
loader7.load( 'videos/ground/scene.gltf', function ( gltf ) {
let model3 = gltf.scene;
model3.scale.set(25,.2,25);
model3.position.set(0,0,50);
scene.add( model3 );
}, undefined, function ( e ) {
console.error( e );
} );
const loader9 = new GLTFLoader();
loader9.load( 'videos/ground/scene.gltf', function ( gltf ) {
let model4 = gltf.scene;
model4.scale.set(25,.2,25);
model4.position.set(0,0,100);
scene.add( model4 );
}, undefined, function ( e ) {
console.error( e );
} );
const loader8 = new GLTFLoader();
loader8.load( 'videos/ground/scene.gltf', function ( gltf ) {
let model5 = gltf.scene;
model5.scale.set(25,.2,25);
model5.position.set(0,0,150);
scene.add( model5 );
}, undefined, function ( e ) {
console.error( e );
} );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.domElement.style.top = 0;
renderer.domElement.style.zIndex = '1';
container.appendChild( renderer.domElement );
window.addEventListener( 'resize', onWindowResize );
// stats
stats = new Stats();
container.appendChild( stats.dom );
//video playback
video = document.createElement( 'video' );
video.src = "./videos/arm.mp4";
video.type="video/mp4;"
video.codecs="avc1.42E01E, mp4a.40.2";
video.load(); // must call after setting/changing source
video.play();
videoImage = document.createElement( 'canvas' );
videoImage.width = 1920;
videoImage.height = 1080;
videoImageContext = videoImage.getContext( '2d' );
// background color if no video present
videoImageContext.fillStyle = '#000000';
videoImageContext.fillRect( 0, 0, videoImage.width, videoImage.height );
videoTexture = new THREE.Texture( videoImage );
videoTexture.minFilter = THREE.LinearFilter;
videoTexture.magFilter = THREE.LinearFilter;
var movieMaterial = new THREE.MeshBasicMaterial( { map: videoTexture, overdraw: true, side:THREE.DoubleSide } );
// the geometry on which the movie will be displayed;
// movie image will be scaled to fit these dimensions.
var movieGeometry = new THREE.PlaneGeometry( 24, 16 , 4, 4 );
var movieScreen = new THREE.Mesh( movieGeometry, movieMaterial );
movieScreen.position.set(1.2,9,10.5);
movieScreen.rotateY(3.14/2.575);
scene.add(movieScreen);
//video2
video2 = document.createElement( 'video' );
video2.src = "./videos/arm.mp4";
video2.type="video/mp4;"
video2.codecs="avc1.42E01E, mp4a.40.2";
video2.load(); // must call after setting/changing source
video2.play();
videoImage2 = document.createElement( 'canvas' );
videoImage2.width = 1920;
videoImage2.height = 1080;
videoImageContext2 = videoImage2.getContext( '2d' );
videoImageContext2.fillStyle = '#000000';
videoImageContext2.fillRect( 0, 0, videoImage2.width, videoImage2.height );
videoTexture2 = new THREE.Texture( videoImage2 );
videoTexture2.minFilter = THREE.LinearFilter;
videoTexture2.magFilter = THREE.LinearFilter;
var movieMaterial2 = new THREE.MeshBasicMaterial( { map: videoTexture2, overdraw: true, side:THREE.DoubleSide } );
var movieGeometry2 = new THREE.PlaneGeometry( 24, 16 , 4, 4 );
var movieScreen2 = new THREE.Mesh( movieGeometry2, movieMaterial2 );
movieScreen2.position.set(1.2,9,50.5);
movieScreen2.rotateY(3.14/2.575);
scene.add(movieScreen2);
//video3
video3 = document.createElement( 'video' );
video3.src = "./videos/arm.mp4";
video3.type="video/mp4;"
video3.codecs="avc1.42E01E, mp4a.40.2";
video3.load(); // must call after setting/changing source
video3.play();
videoImage3 = document.createElement( 'canvas' );
videoImage3.width = 1920;
videoImage3.height = 1080;
videoImageContext3 = videoImage3.getContext( '2d' );
videoImageContext3.fillStyle = '#000000';
videoImageContext3.fillRect( 0, 0, videoImage3.width, videoImage3.height );
videoTexture3 = new THREE.Texture( videoImage3 );
videoTexture3.minFilter = THREE.LinearFilter;
videoTexture3.magFilter = THREE.LinearFilter;
let movieMaterial3 = new THREE.MeshBasicMaterial( { map: videoTexture3, overdraw: true, side:THREE.DoubleSide } );
let movieGeometry3 = new THREE.PlaneGeometry( 24, 16 , 4, 4 );
let movieScreen3 = new THREE.Mesh( movieGeometry3, movieMaterial3 );
movieScreen3.position.set(1.2,9,90.5);
movieScreen3.rotateY(3.14/2.575);
scene.add(movieScreen3);
//video4
video4 = document.createElement( 'video' );
video4.src = "./videos/arm.mp4";
video4.type="video/mp4;"
video4.codecs="avc1.42E01E, mp4a.40.2";
video4.load(); // must call after setting/changing source
video4.play();
videoImage4 = document.createElement( 'canvas' );
videoImage4.width = 1920;
videoImage4.height = 1080;
videoImageContext4 = videoImage4.getContext( '2d' );
videoImageContext4.fillStyle = '#000000';
videoImageContext4.fillRect( 0, 0, videoImage4.width, videoImage4.height );
videoTexture4 = new THREE.Texture( videoImage4 );
videoTexture4.minFilter = THREE.LinearFilter;
videoTexture4.magFilter = THREE.LinearFilter;
let movieMaterial4 = new THREE.MeshBasicMaterial( { map: videoTexture4, overdraw: true, side:THREE.DoubleSide } );
let movieGeometry4 = new THREE.PlaneGeometry( 24, 16 , 4, 4 );
let movieScreen4 = new THREE.Mesh( movieGeometry4, movieMaterial4 );
movieScreen4.position.set(1.2,9,130.5);
movieScreen4.rotateY(3.14/2.575);
scene.add(movieScreen4);
//font on screen 1
const loader_font = new FontLoader();
loader_font.load('fonts/helvetiker_bold.typeface.json', function ( font ) {
const textGeo = new TextGeometry( 'ROS NAVIGATION', {
font: font,
size: 2,
height: 2,
curveSegments: 12,
bevelThickness: .1,
bevelSize: .1,
bevelEnabled: true
} );
const textGeo2 = new TextGeometry( 'CODE EDITOR', {
font: font,
size: 2,
height: 2,
curveSegments: 12,
bevelThickness: .1,
bevelSize: .1,
bevelEnabled: true
} );
const textGeo3 = new TextGeometry( 'PORTFOLIO WEBSITE', {
font: font,
size: 1.5,
height: 2,
curveSegments: 12,
bevelThickness: .1,
bevelSize: .1,
bevelEnabled: true
} );
const textGeo4 = new TextGeometry( 'SCHOOL MANAGEMENT SYSTEM', {
font: font,
size: 1.1,
height: 2,
curveSegments: 12,
bevelThickness: .1,
bevelSize: .1,
bevelEnabled: true
} );
const textMaterial = new THREE.MeshPhongMaterial( { color: 0xff0000, specular: 0xffffff } );
const mesh1 = new THREE.Mesh( textGeo, textMaterial );
mesh1.position.x = -4;
mesh1.position.y = 18.45;
mesh1.position.z = 21;
mesh1.rotation.y = 3.14/2.575;
mesh1.castShadow = true;
mesh1.receiveShadow = true;
scene.add( mesh1 )
const mesh2 = new THREE.Mesh( textGeo2, textMaterial );
mesh2.position.x = -4.5;
mesh2.position.y = 18.45;
mesh2.position.z = 59;
mesh2.rotation.y = 3.14/2.575;
mesh2.castShadow = true;
mesh2.receiveShadow = true;
scene.add( mesh2 )
const mesh3 = new THREE.Mesh( textGeo3, textMaterial );
mesh3.position.x = -3;
mesh3.position.y = 18.45;
mesh3.position.z = 100;
mesh3.rotation.y = 3.14/2.575;
mesh3.castShadow = true;
mesh3.receiveShadow = true;
scene.add( mesh3 )
const mesh4 = new THREE.Mesh( textGeo4, textMaterial );
mesh4.position.x = -4;
mesh4.position.y = 18.45;
mesh4.position.z = 141;
mesh4.rotation.y = 3.14/2.575;
mesh4.castShadow = true;
mesh4.receiveShadow = true;
scene.add( mesh4 )
});
const controls = new OrbitControls( camera, renderer.domElement );
controls.enablePan = true;
controls.minDistance = 5;
controls.maxDistance = 500;
document.addEventListener("keydown", onDocumentKeyDown, false);
}
function onDocumentKeyDown(event) {
var keyCode = event.which;
if(model.position.z >10)
{
scene.add( light );
scene.add( light.target );
}
if(model.position.z >130)
{
scene.add( light5 );
scene.add( light5.target );
}
if(model.position.z >50)
{
scene.add( light3 );
scene.add( light3.target );
}
if(model.position.z >90)
{
scene.add( light4 );
scene.add( light4.target );
}
if((model.position.z > 10 && model.position.z< 10.5) || (model.position.z > 50 && model.position.z< 50.5) ||(model.position.z > 90 && model.position.z< 90.5) || (model.position.z > 130 && model.position.z< 130.5))
{
current_state='ThumbsUp';
fadeToAction('Jump',0.5);
fadeToAction('Walking',0.5);
}
console.log(model.rotation.y);
if (keyCode == 38 && model.rotation.y == 0) {
model.position.z += ySpeed;
camera.position.set( camera.position.x, camera.position.y, camera.position.z+ ySpeed );
light2.position.set(20, 10, model.position.z);
light2.target.position.set(20, 0 ,model.position.z);
scene.add(light2.target);
}
else if (keyCode == 38 && model.rotation.y == 3.14) {
model.position.z -= ySpeed;
camera.position.set( camera.position.x, camera.position.y, camera.position.z- ySpeed );
light2.position.set(20, 10, model.position.z);
light2.target.position.set(20, 0 ,model.position.z);
scene.add(light2.target);
}
else if (keyCode == 40 ) {
if(model.rotation.y ==3.14)
{model.rotation.y = 0;
}
else
{model.rotation.y = 3.14;}
}
if (keyCode == 35)
{
window.open('Ros.html','_parent');
}
else if (keyCode == 34) {
window.open('.html','_parent');
}
else if (keyCode == 66) {
window.open('robot.html','_parent');}
render();
};
function createGUI( model, animations ) {
const states = [ '↑ ', 'Walking', 'Running', 'Dance', 'Death', 'Sitting', 'Standing' ];
const emotes = [ 'Jump', 'Yes', 'No', 'Wave', 'Punch', 'ThumbsUp' ];
gui = new GUI();
var options = {
Move_Forward: '↑',
Move_Backward: '↓',
Move_Left: '←',
Move_Right: '→'
}
var options2 = {
Project: 'Press-Key',
Autonomous_Robot: '1',
Code_Editor: '2',
Portfolio_Website: '3',
School_Mgmt_System: '4'
}
const statesFolder = gui.addFolder( 'ROBOT CONTROL' );
statesFolder.add(options, 'Move_Forward');
statesFolder.add(options, 'Move_Backward');
statesFolder.add(options, 'Move_Left');
statesFolder.add(options, 'Move_Right');
const statesFolder2 = gui.addFolder( 'GO TO PROJECT LINK' );
statesFolder2.add(options2, 'Project');
statesFolder2.add(options2, 'Autonomous_Robot');
statesFolder2.add(options2, 'Code_Editor');
statesFolder2.add(options2, 'Portfolio_Website');
statesFolder2.add(options2, 'School_Mgmt_System');
statesFolder.open();
mixer = new THREE.AnimationMixer( model );
actions = {};
for ( let i = 0; i < animations.length; i ++ ) {
const clip = animations[ i ];
const action = mixer.clipAction( clip );
actions[ clip.name ] = action;
if ( emotes.indexOf( clip.name ) >= 0 || states.indexOf( clip.name ) >= 4 ) {
action.clampWhenFinished = true;
action.loop = THREE.LoopOnce;
}
}
// emotes
function restoreState() {
mixer.removeEventListener( 'finished', restoreState );
fadeToAction( api.state, 0.2 );
}
activeAction = actions[ 'Walking' ];
activeAction.play();
}
function fadeToAction( name, duration ) {
previousAction = activeAction;
activeAction = actions[ name ];
if ( previousAction !== activeAction ) {
previousAction.fadeOut( duration );
}
activeAction
.reset()
.setEffectiveTimeScale( 1 )
.setEffectiveWeight( 1 )
.fadeIn( duration )
.play();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function render() {
if ( video.readyState === video.HAVE_ENOUGH_DATA )
{
videoImageContext.drawImage( video, 1, 1 );
if ( videoTexture )
videoTexture.needsUpdate = true;
}
if ( video2.readyState === video2.HAVE_ENOUGH_DATA )
{
videoImageContext2.drawImage( video2, 1, 1 );
if ( videoTexture2 )
videoTexture2.needsUpdate = true;
}
if ( video3.readyState === video2.HAVE_ENOUGH_DATA )
{
videoImageContext3.drawImage( video3, 1, 1 );
if ( videoTexture3 )
videoTexture3.needsUpdate = true;
}
if ( video4.readyState === video4.HAVE_ENOUGH_DATA )
{
videoImageContext4.drawImage( video4, 0, 0 );
if ( videoTexture4 )
videoTexture4.needsUpdate = true;
}
renderer.render( scene, camera );
}
function animate() {
const dt = clock.getDelta();
if ( mixer ) mixer.update( dt );
requestAnimationFrame( animate );
render();
video.play();
video2.play();
video3.play();
video4.play();
}
</script>
</body>
</html>