Branchwell

Become a Pro / full-access-films · becomeapro.ai / films / outro-logo.js

1const canvas = document.getElementById("logo3d");
2const renderer = new THREE.WebGLRenderer({ canvas, alpha: true, antialias: true, preserveDrawingBuffer: true });
3renderer.setPixelRatio(window.devicePixelRatio || 1);
4renderer.setSize(1920, 1080, false);
5const scene = new THREE.Scene();
6const camera = new THREE.PerspectiveCamera(30, 1920 / 1080, 1, 3000);
7camera.position.z = 324;
8scene.add(new THREE.AmbientLight(0xffffff, 0.9));
9const key = new THREE.DirectionalLight(0xffffff, 2.4);
10key.position.set(-80, 90, 240);
11scene.add(key);
12const rim = new THREE.DirectionalLight(0x7cc4f2, 2.2);
13rim.position.set(160, -40, 90);
14scene.add(rim);
15const logo = new THREE.Group();
16[["3 49.94 7.14 57.11 56.86 57.11 36.14 21.24 32 28.41 44.43 49.94", 0x46aae9],
17 ["56.86 57.11 61 49.94 36.14 6.89 15.43 42.76 23.71 42.76 36.14 21.24", 0x2a7fb8],
18 ["36.14 6.89 27.86 6.89 3 49.94 44.43 49.94 40.29 42.76 15.43 42.76", 0xffffff]].forEach(([points, color]) => {
19 const v = points.split(" ").map(Number), shape = new THREE.Shape();
20 for (let i = 0; i < v.length; i += 2) {
21 const x = v[i] - 32, y = 32 - v[i + 1];
22 i ? shape.lineTo(x, y) : shape.moveTo(x, y);
23 }
24 shape.closePath();
25 const geometry = new THREE.ExtrudeGeometry(shape, { depth: 9, bevelEnabled: true, bevelSize: 0.5, bevelThickness: 0.7, bevelSegments: 3 });
26 geometry.translate(0, 0, -4.5);
27 logo.add(new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ color, metalness: 0.2, roughness: 0.32 })));
28});
29logo.position.y = 26;
30scene.add(logo);
31const state = { spin: 0, idle: 0 };
32function draw() {
33 const left = 1 - state.spin;
34 logo.rotation.y = -Math.PI * 11.8 * Math.pow(left, 2.5) + (0.24 * Math.sin(state.idle * 2.4) + 0.1) * state.spin;
35 logo.rotation.x = -0.1 * state.spin;
36 logo.position.z = 243 * left;
37 logo.position.y = 26 * state.spin * state.spin;
38 key.position.x = -140 + 150 * state.idle;
39 renderer.render(scene, camera);
40}
41tl.fromTo("#logo3d", { opacity: 0 }, { opacity: 1, duration: 0.5, ease: "none" }, 2.35);
42tl.to(state, { spin: 1, duration: 3.2, ease: "power1.out" }, 1.91);
43tl.to(state, { idle: 1, duration: DURATION, ease: "none" }, 0);
44tl.eventCallback("onUpdate", draw);
45draw();