Skip to content

Commit e6734ae

Browse files
committed
Enable direct assignment of VideoElement
1 parent 7644248 commit e6734ae

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

three.js/examples/location-based/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ function main() {
2222

2323
const cam = new WebcamRenderer(renderer, '#video1');
2424

25+
// You can also set the video element directly
26+
// const videoElement = document.querySelector('#video1');
27+
// const cam = new WebcamRenderer(renderer, videoElement);
28+
2529
const mouseStep = THREE.MathUtils.degToRad(5);
2630

2731

three.js/src/location-based/js/webcam-renderer.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ class WebcamRenderer {
55
this.renderer = renderer;
66
this.renderer.autoClear = false;
77
this.sceneWebcam = new THREE.Scene();
8-
let video;
9-
if (videoElement === undefined) {
8+
let video = undefined;
9+
10+
if (typeof videoElement === "string") {
11+
video = document.querySelector(videoElement);
12+
} else if (videoElement instanceof HTMLVideoElement) {
13+
video = videoElement;
14+
}
15+
16+
if (video === undefined) {
1017
video = document.createElement("video");
1118
video.setAttribute("autoplay", true);
1219
video.setAttribute("playsinline", true);
1320
video.style.display = "none";
1421
document.body.appendChild(video);
15-
} else {
16-
video = document.querySelector(videoElement);
1722
}
1823
this.geom = new THREE.PlaneGeometry();
1924
this.texture = new THREE.VideoTexture(video);

0 commit comments

Comments
 (0)