This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathcss3d_youtube.html
135 lines (98 loc) · 3.52 KB
/
css3d_youtube.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
<!DOCTYPE html>
<html>
<head>
<title>Verge3D css3d - youtube</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 {
background-color: #ffffff;
}
#blocker {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="blocker"></div>
<!-- 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": {
"v3d": "../build/v3d.module.js",
"v3d/addons/": "./jsm/"
}
}
</script>
<script type="module">
import * as v3d from 'v3d';
import { TrackballControls } from 'v3d/addons/controls/TrackballControls.js';
import { CSS3DRenderer, CSS3DObject } from 'v3d/addons/renderers/CSS3DRenderer.js';
let camera, scene, renderer;
let controls;
function Element(id, x, y, z, ry) {
const div = document.createElement('div');
div.style.width = '480px';
div.style.height = '360px';
div.style.backgroundColor = '#000';
const iframe = document.createElement('iframe');
iframe.style.width = '480px';
iframe.style.height = '360px';
iframe.style.border = '0px';
iframe.src = ['https://www.youtube.com/embed/', id, '?rel=0'].join('');
div.appendChild(iframe);
const object = new CSS3DObject(div);
object.position.set(x, y, z);
object.rotation.y = ry;
return object;
}
init();
animate();
function init() {
const container = document.getElementById('container');
camera = new v3d.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 5000);
camera.position.set(500, 350, 750);
scene = new v3d.Scene();
renderer = new CSS3DRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);
const group = new v3d.Group();
group.add(new Element('SJOz3qjfQXU', 0, 0, 240, 0));
group.add(new Element('Y2-xZ-1HE-Q', 240, 0, 0, Math.PI / 2));
group.add(new Element('IrydklNpcFI', 0, 0, -240, Math.PI));
group.add(new Element('9ubytEsCaS0', -240, 0, 0, - Math.PI / 2));
scene.add(group);
controls = new TrackballControls(camera, renderer.domElement);
controls.rotateSpeed = 4;
window.addEventListener('resize', onWindowResize);
// Block iframe events when dragging camera
const blocker = document.getElementById('blocker');
blocker.style.display = 'none';
controls.addEventListener('start', function() {
blocker.style.display = '';
});
controls.addEventListener('end', function() {
blocker.style.display = 'none';
});
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
</script>
</body>
</html>