JSFiddle - React, Tailwind, and code Playground
by orion_prime
HTML
<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>
CSS
:root {
--main-color: #ff6f69;
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*::-webkit-input-placeholder {
color: #666;
opacity: 1;
}
*:-moz-placeholder {
color: #666;
opacity: 1;
}
*::-moz-placeholder {
color: #666;
opacity: 1;
}
*:-ms-input-placeholder {
color: #666;
opacity: 1;
}
body input:focus:required:invalid,
body textarea:focus:required:invalid {
color: #666;
}
body input:required:valid,
body textarea:required:valid {
color: #666;
}
html, body {
height: 100%;
}
body {
font-size: 16px;
min-width: 320px;
position: relative;
line-height: 1.65;
overflow-x: hidden;
}
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}
::selection {
background-color: #fff;
color: #fff;
}
a, a:hover, a:focus, a:active {
outline: none !important;
text-decoration: none;
color: #000;
}
.grid-container {
display: grid;
max-width: 1200px;
margin: 0 auto;
}
/*min-height:32vh;*/
section {
width: 100%;
height: 100vh;
display: grid;
justify-items: center;
}
JavaScript
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 = 16; let height = 9; let radius = 0.2;
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...