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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<style>
|
| 2 |
+
@import url('https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@900&family=Rokkitt:wght@900&display=swap');
|
| 3 |
+
body{
|
| 4 |
+
overflow: hidden;
|
| 5 |
+
margin: 0;
|
| 6 |
+
}
|
| 7 |
+
.text1 {
|
| 8 |
+
position: absolute;
|
| 9 |
+
top: 3vh;
|
| 10 |
+
left: calc(50% - 50vh);
|
| 11 |
+
}
|
| 12 |
+
.text2 {
|
| 13 |
+
position: absolute;
|
| 14 |
+
bottom: 4vh;
|
| 15 |
+
left: 50%;
|
| 16 |
+
}
|
| 17 |
+
.retro {
|
| 18 |
+
font-family: "Roboto Slab";
|
| 19 |
+
font-size: 13vh;
|
| 20 |
+
display: block;
|
| 21 |
+
color: #000;
|
| 22 |
+
text-shadow: -0.5vh 0 #8800aa, 0 0.5vh #8800aa, 0.5vh 0 #aa0088, 0 -0.5vh #aa0088;
|
| 23 |
+
}
|
| 24 |
+
</style>
|
| 25 |
+
|
| 26 |
+
<div class="text1">
|
| 27 |
+
<span class="retro">RETRO</span>
|
| 28 |
+
</div>
|
| 29 |
+
<div class="text2">
|
| 30 |
+
<span class="retro">WAVE</span>
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<script type="module">
|
| 34 |
+
import * as THREE from "https://cdn.jsdelivr.net/npm/three@0.123.0/build/three.module.js";
|
| 35 |
+
import { OrbitControls } from "https://cdn.jsdelivr.net/npm/three@0.123.0/examples/jsm/controls/OrbitControls.js";
|
| 36 |
+
import { TWEEN } from "https://cdn.jsdelivr.net/npm/three@0.123.0/examples/jsm/libs/tween.module.min.js";
|
| 37 |
+
|
| 38 |
+
let scene = new THREE.Scene();
|
| 39 |
+
let camera = new THREE.PerspectiveCamera(60, innerWidth / innerHeight, 1, 100);
|
| 40 |
+
camera.position.set(-5, 10, 20);
|
| 41 |
+
let renderer = new THREE.WebGLRenderer({antialias: true});
|
| 42 |
+
renderer.setSize(innerWidth, innerHeight);
|
| 43 |
+
document.querySelector("#inference").appendChild(renderer.domElement);
|
| 44 |
+
|
| 45 |
+
const textureCube = generateCubeMap();
|
| 46 |
+
|
| 47 |
+
let controls = new OrbitControls(camera, renderer.domElement);
|
| 48 |
+
controls.enableZoom = false;
|
| 49 |
+
controls.enablePan = false;
|
| 50 |
+
controls.enableKeys = false;
|
| 51 |
+
|
| 52 |
+
let square = new THREE.GridHelper(20, 1, 0xaaaaff, 0xaaaff);
|
| 53 |
+
square.position.y = 0.01;
|
| 54 |
+
scene.add(square);
|
| 55 |
+
|
| 56 |
+
let grid = new THREE.GridHelper(20, 10, "magenta", "magenta");
|
| 57 |
+
console.log(grid.geometry.attributes.position.count);
|
| 58 |
+
let moveable = [];
|
| 59 |
+
for(let i = 0; i < grid.geometry.attributes.position.count / 4; i++){
|
| 60 |
+
moveable.push(1, 1, 0, 0);
|
| 61 |
+
}
|
| 62 |
+
console.log(moveable.length)
|
| 63 |
+
grid.geometry.setAttribute("moveable", new THREE.Float32BufferAttribute(moveable, 1));
|
| 64 |
+
let uniforms = {
|
| 65 |
+
time: {value: 0},
|
| 66 |
+
speed: {value: 1},
|
| 67 |
+
size: {value: 20}
|
| 68 |
+
}
|
| 69 |
+
grid.material.onBeforeCompile = shader => {
|
| 70 |
+
shader.uniforms.time = uniforms.time;
|
| 71 |
+
shader.uniforms.speed = uniforms.speed;
|
| 72 |
+
shader.uniforms.size = uniforms.size;
|
| 73 |
+
shader.vertexShader = `
|
| 74 |
+
uniform float time;
|
| 75 |
+
uniform float speed;
|
| 76 |
+
uniform float size;
|
| 77 |
+
attribute float moveable;
|
| 78 |
+
${shader.vertexShader}
|
| 79 |
+
`.replace(
|
| 80 |
+
`#include <begin_vertex>`,
|
| 81 |
+
`#include <begin_vertex>
|
| 82 |
+
|
| 83 |
+
if (floor(moveable + 0.1) > 0.5){
|
| 84 |
+
float start = size * -0.5;
|
| 85 |
+
float zPos = mod( (position.z - start) + (time * speed), size) + start;
|
| 86 |
+
transformed.z = zPos;
|
| 87 |
+
}
|
| 88 |
+
`
|
| 89 |
+
);
|
| 90 |
+
console.log(shader.vertexShader)
|
| 91 |
+
}
|
| 92 |
+
scene.add(grid);
|
| 93 |
+
|
| 94 |
+
// palm
|
| 95 |
+
let base = new THREE.Object3D();
|
| 96 |
+
|
| 97 |
+
let baseSpline = new THREE.CatmullRomCurve3([
|
| 98 |
+
new THREE.Vector2(),
|
| 99 |
+
new THREE.Vector2(3, 0),
|
| 100 |
+
new THREE.Vector2(2.5, -7),
|
| 101 |
+
new THREE.Vector2(-4, -6),
|
| 102 |
+
new THREE.Vector2(-4.8, 0)
|
| 103 |
+
], true, "catmullrom", 0.1);
|
| 104 |
+
let baseG = new THREE.ExtrudeBufferGeometry(new THREE.Shape(baseSpline.getPoints(50)), {depth: 0.2, bevelEnabled: true, bevelThickness: 0.8, bevelSize: 0.2});
|
| 105 |
+
let baseObject = new THREE.Mesh(baseG, new THREE.MeshBasicMaterial({color: "magenta", wireframe: false, envMap: textureCube}));
|
| 106 |
+
base.add(baseObject);
|
| 107 |
+
scene.add(base);
|
| 108 |
+
let phalanxes = [];
|
| 109 |
+
let f1 = createFinger(new THREE.Object3D(), 0.8, false); // pinky
|
| 110 |
+
let f2 = createFinger(new THREE.Object3D(), 0.95, false); // ring
|
| 111 |
+
let f3 = createFinger(new THREE.Object3D(), 1, false); // middle
|
| 112 |
+
let f4 = createFinger(new THREE.Object3D(), 0.95, false); // index
|
| 113 |
+
let f5Base = new THREE.Object3D();
|
| 114 |
+
let f5 = createFinger(new THREE.Object3D(), 0.75, true); // thumb
|
| 115 |
+
f5Base.add(f5);
|
| 116 |
+
base.add(f1, f2, f3, f4, f5Base);
|
| 117 |
+
|
| 118 |
+
f1.position.set( -4, 0.2, 0);
|
| 119 |
+
f2.position.set( -2, 0.2, 0);
|
| 120 |
+
f3.position.set( 0, 0.2, 0);
|
| 121 |
+
f4.position.set( 2, 0.2, 0);
|
| 122 |
+
f5Base.position.set( 3, -3, 0);
|
| 123 |
+
f5Base.rotation.set( 0, 0, THREE.MathUtils.degToRad(-60));
|
| 124 |
+
f5Base.updateMatrixWorld();
|
| 125 |
+
|
| 126 |
+
let g = createPhalanxGeom(1, 3);
|
| 127 |
+
let m = new THREE.MeshBasicMaterial({color: "aqua", wireframe: false, envMap: textureCube});
|
| 128 |
+
let o = new THREE.InstancedMesh(g, m, phalanxes.length);
|
| 129 |
+
phalanxes.forEach( (ph, i) => {
|
| 130 |
+
ph.updateMatrixWorld();
|
| 131 |
+
o.setMatrixAt(i, ph.matrixWorld);
|
| 132 |
+
})
|
| 133 |
+
scene.add(o);
|
| 134 |
+
|
| 135 |
+
window.addEventListener( 'resize', onWindowResize, false );
|
| 136 |
+
|
| 137 |
+
let t = new TWEEN.Tween({value: Math.PI * 0.075})
|
| 138 |
+
.to({value: Math.PI * 0.45}, 4000)
|
| 139 |
+
.easing(TWEEN.Easing.Quadratic.InOut)
|
| 140 |
+
.repeat(Infinity)
|
| 141 |
+
.yoyo(true)
|
| 142 |
+
.onUpdate(val => {
|
| 143 |
+
phalanxes.forEach((ph, i) => {
|
| 144 |
+
ph.rotation.x = val.value;
|
| 145 |
+
ph.updateMatrixWorld();
|
| 146 |
+
o.setMatrixAt(i, ph.matrixWorld)
|
| 147 |
+
});
|
| 148 |
+
o.instanceMatrix.needsUpdate = true;
|
| 149 |
+
});
|
| 150 |
+
t.start();
|
| 151 |
+
|
| 152 |
+
let clock = new THREE.Clock();
|
| 153 |
+
|
| 154 |
+
renderer.setAnimationLoop(() => {
|
| 155 |
+
let t = clock.getElapsedTime();
|
| 156 |
+
TWEEN.update();
|
| 157 |
+
uniforms.time.value = t;
|
| 158 |
+
base.rotation.x = (Math.sin(t * 0.125) * 0.5 + 0.5) * -Math.PI * 0.5;
|
| 159 |
+
base.rotation.y = -t * 0.125;
|
| 160 |
+
renderer.render(scene, camera);
|
| 161 |
+
});
|
| 162 |
+
|
| 163 |
+
function onWindowResize() {
|
| 164 |
+
|
| 165 |
+
camera.aspect = innerWidth / innerHeight;
|
| 166 |
+
camera.updateProjectionMatrix();
|
| 167 |
+
|
| 168 |
+
renderer.setSize( innerWidth, innerHeight );
|
| 169 |
+
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
function createFinger(phalanx, scale, isThumb){
|
| 173 |
+
phalanxes.push(phalanx);
|
| 174 |
+
let current = phalanx;
|
| 175 |
+
for(let i = 0; i < (isThumb ? 1 : 2); i++){
|
| 176 |
+
let p = new THREE.Object3D();
|
| 177 |
+
p.position.y = 3;
|
| 178 |
+
p.scale.setScalar(0.85);
|
| 179 |
+
current.add(p);
|
| 180 |
+
phalanxes.push(p);
|
| 181 |
+
current = p;
|
| 182 |
+
}
|
| 183 |
+
phalanx.scale.setScalar(scale);
|
| 184 |
+
return phalanx;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
function createPhalanxGeom(R, L){
|
| 188 |
+
|
| 189 |
+
let r = R * 0.85;
|
| 190 |
+
let R1 = R - r;
|
| 191 |
+
let a = Math.asin(R1 / L);
|
| 192 |
+
|
| 193 |
+
let path = new THREE.Path();
|
| 194 |
+
path.absarc(0, 0, R, Math.PI * 1.5, a);
|
| 195 |
+
path.absarc(0, L, r, a, Math.PI * 0.5);
|
| 196 |
+
|
| 197 |
+
let pts = path.getPoints(5);
|
| 198 |
+
|
| 199 |
+
let g = new THREE.LatheBufferGeometry(pts);
|
| 200 |
+
|
| 201 |
+
return g;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
function generateCubeMap(){
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
let images = [];
|
| 208 |
+
|
| 209 |
+
let c = document.createElement("canvas");
|
| 210 |
+
c.width = 4;
|
| 211 |
+
c.height = c.width;
|
| 212 |
+
let ctx = c.getContext("2d");
|
| 213 |
+
for(let i= 0; i < 6;i++){
|
| 214 |
+
ctx.fillStyle = "#fff";
|
| 215 |
+
ctx.fillRect(0, 0, c.width, c.height);
|
| 216 |
+
|
| 217 |
+
for(let j = 0; j < (c.width * c.height) / 2; j++){
|
| 218 |
+
ctx.fillStyle = Math.random() < 0.5 ? "#f0f" : "#40f";
|
| 219 |
+
ctx.fillRect(
|
| 220 |
+
Math.floor(Math.random() * c.width),
|
| 221 |
+
Math.floor(Math.random() * c.height),
|
| 222 |
+
2,
|
| 223 |
+
1
|
| 224 |
+
);
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
images.push(c.toDataURL());
|
| 228 |
+
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
let cm = new THREE.CubeTextureLoader().load(images);
|
| 232 |
+
|
| 233 |
+
console.log(cm);
|
| 234 |
+
|
| 235 |
+
return cm;
|
| 236 |
+
}
|
| 237 |
+
</script>
|