-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
94 lines (80 loc) · 2.95 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example chromakey video in three.js</title>
</head>
<body>
<style>
#video {
display: flex;
width: 85dvw;
max-width: 100%;
height: auto;
object-fit: contain;
object-position: right;
aspect-ratio: 16 / 9;
margin-left: auto;
}
#video-canvas {
position: fixed;
top: 0;
left: 0;
z-index: 999;
width: 800px;
height: auto;
aspect-ratio: 16 / 9;
}
</style>
<video id="video" src="assets/breadcrumbs.mp4" muted autoplay loop></video>
<canvas id="video-canvas"></canvas>
<script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@v0.149.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@v0.149.0/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import ChromaKeyMaterial from './chromakey-three-js.js';
// Creating a scene and camera
const scene = new THREE.Scene();
const canvas = document.getElementById('video-canvas');
const camera = new THREE.PerspectiveCamera(75, canvas.clientWidth / canvas.clientHeight, 0.1, 1000);
const light = new THREE.PointLight(0xffffff, 1, 1000);
light.position.set(10, 10, 10);
camera.position.z = 10;
// Creating a renderer
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
})
renderer.setSize(canvas.clientWidth, canvas.clientHeight);
document.body.appendChild(renderer.domElement);
setTimeout(() => {
const myGreenScreenMaterial = new ChromaKeyMaterial("video", 0xd432);
const myGeometry = new THREE.PlaneGeometry(16, 9);
const myGreenScreenVideoObject = new THREE.Mesh(myGeometry, myGreenScreenMaterial);
// console.log(myGreenScreenMaterial, myGreenScreenVideoObject, 'myGreenScreenMaterial, myGreenScreenVideoObject')
const basicMaterial = new THREE.MeshBasicMaterial({color: 0xFFCC00});
const testMesh = new THREE.Mesh(myGeometry, basicMaterial); // a plane to put a background behind the video
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
renderer.render( scene, camera );
}
scene.add(light);
scene.add(camera);
scene.add(testMesh);
scene.add(myGreenScreenVideoObject);
animate();
}, 1500)
</script>
</body>
</html>