Skip to content

Commit 0166f82

Browse files
committed
Video360: a threejs texture can take a video directly
1 parent 0a63aa7 commit 0166f82

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
var loaded = false;
66

77
window.api = {
8-
version: "0.9.0",
8+
version: "0.9.1",
99
thumbnail: {}
1010
};
1111

ui/video360.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
var
66
sceneCreated,
7-
canvas,
8-
canvasCtx,
97
scene,
108
renderer,
119
texture,
@@ -28,40 +26,25 @@ function createScene() {
2826
scene.add( camera );
2927

3028
// Sphere's texture:
31-
canvas = document.createElement( "canvas" );
32-
canvasCtx = canvas.getContext( "2d" );
33-
texture = new THREE.Texture( canvas );
29+
texture = new THREE.Texture();
3430
texture.minFilter = THREE.LinearFilter;
3531

3632
// Sphere, texture:
3733
sphere = new THREE.Mesh(
3834
new THREE.SphereGeometry( 1, 32, 32, 0, Math.PI * 2, 0, Math.PI ),
39-
new THREE.MeshBasicMaterial({
40-
map: texture,
41-
overdraw: true,
42-
side: THREE.BackSide
43-
})
35+
new THREE.MeshBasicMaterial( { map: texture } )
4436
);
37+
sphere.scale.x = -1;
4538
scene.add( sphere );
4639
}
4740

4841
function frame( obj ) {
4942
if ( !ui.isSeeking ) {
50-
// Update the renderer's dimensions:
5143
renderer.setSize( window.innerWidth, window.innerHeight );
5244
camera.aspect = window.innerWidth / window.innerHeight;
5345
camera.updateProjectionMatrix();
54-
55-
// Sphere's texture:
56-
canvas.width = api.videoElement.videoWidth;
57-
canvas.height = api.videoElement.videoHeight;
58-
canvasCtx.save();
59-
canvasCtx.scale( -1, 1 );
60-
canvasCtx.drawImage( api.videoElement, -canvas.width, 0, canvas.width, canvas.height );
61-
canvasCtx.restore();
46+
texture.image = api.videoElement;
6247
texture.needsUpdate = true;
63-
64-
// Render:
6548
renderer.render( scene, camera );
6649
}
6750
}

0 commit comments

Comments
 (0)