<script src="https://threejs.org/build/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<section class="main"></section>
<section>
<video id="video" type="video/mp4" muted loop autoplay width="512" height="512" src="//dl.dropbox.com/s/931244iox7i0fpk/working-with-espresso.mp4" crossorigin="anonymous" ></video>
</section>
body {
margin: 0;
padding: 0;
background: #012345;
//overflow: hidden;
}
#canvas {
position: absolute;
}
#testing {
color: red;
font-family: arial;
position: absolute;
top: 100px;
}
section {
width: 100%;
height: 100vh;
display: grid;
justify-items: center;
}
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 45, window.innerWidth/window.innerHeight, 0.1, 1000 );
let renderer = new THREE.WebGLRenderer({ });
scene.background = new THREE.Color(0xdddddd);
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor(0xECF0F1);
let doc = document.querySelector('.main');
doc.appendChild( renderer.domElement );
window.addEventListener('resize', function () {
let width = window.innerWidth;
let height = window.innerHeight;
renderer.setSize(width,height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
let controls = new THREE.OrbitControls(camera,renderer.domElement);
let x = 1; let y = 1; let width = 90; let height = 50; let radius = 10;
let shape = new THREE.Shape();
shape.moveTo( x, y + radius );
shape.lineTo( x, y + height - radius );
shape.quadraticCurveTo( x, y + height, x + radius, y + height );
shape.lineTo( x + width - radius, y + height );
shape.quadraticCurveTo( x + width, y + height, x + width, y + height - radius );
shape.lineTo( x + width, y + radius );
shape.quadraticCurveTo( x + width, y, x + width - radius, y );
shape.lineTo( x + radius, y );
shape.quadraticCurveTo( x, y, x, y + radius );
const video = document.getElementById( 'video' );
const texture = new THREE.VideoTexture( video );
let geometry1 = new THREE.ShapeBufferGeometry( shape );
var uvAttribute = geometry1.attributes.uv;
let min = Infinity, max = 0
//find min max
for (var i = 0; i < uvAttribute.count; i++) {
let u = uvAttribute.getX(i);
let v = uvAttribute.getY(i);
min = Math.min(min, u, v)
max = Math.max(max, u, v)
}
//map min map to 1 to 1 range
for (var i = 0; i < uvAttribute.count; i++) {
let u = uvAttribute.getX(i);
let v = uvAttribute.getY(i);
// do something with uv
u = THREE.MathUtils.mapLinear(u, min, max, 0, 1)
v = THREE.MathUtils.mapLinear(v, min, max, 0, 1)
// write values back to attribute
uvAttribute.setXY(i, u, v);
}
const material1 = new THREE.MeshBasicMaterial({wireframe: false,side: THREE.DoubleSide,map: texture});
let mesh1 = new THREE.Mesh(geometry1, material1);
mesh1.position.y = -15;
mesh1.position.x = -45;
scene.add(mesh1);
document.addEventListener('DOMContentLoaded', function () {
video.play();
});
camera.position.z = 140;
const animate = function () {
requestAnimationFrame( animate );
renderer.render( scene, camera );
};
animate();
This Pen doesn't use any external CSS resources.