Files

235 lines
20 KiB
HTML

<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=1080, height=1920" />
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
<script type="importmap">
{ "imports": { "three": "https://cdn.jsdelivr.net/npm/three@0.169.0/build/three.module.js", "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.169.0/examples/jsm/" } }
</script>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { margin: 0; width: 1080px; height: 1920px; overflow: hidden; background: #0f1535; }
#root { position: relative; width: 100%; height: 100%; }
#world { position: absolute; inset: 0; width: 1080px; height: 1920px; display: block; }
</style>
</head>
<body>
<!-- 날씨각 소개 릴스(3D). 세상은 Three.js 한 장면(섬·하늘·구름·아이콘, test-design/weather 디오라마를 가져옴), 글·칩·폰은 위에 얹는 sub-composition -->
<div id="root" data-composition-id="main" data-start="0" data-duration="21" data-width="1080" data-height="1920">
<canvas id="world" width="1080" height="1920"></canvas>
<div id="o1" data-composition-id="o1" data-composition-src="compositions/o1.html" data-start="0" data-duration="3" data-track-index="2" data-track-kind="graphics" data-width="1080" data-height="1920"></div>
<div id="o2" data-composition-id="o2" data-composition-src="compositions/o2.html" data-start="3" data-duration="3" data-track-index="2" data-track-kind="graphics" data-width="1080" data-height="1920"></div>
<div id="o3" data-composition-id="o3" data-composition-src="compositions/o3.html" data-start="6" data-duration="2.5" data-track-index="2" data-track-kind="graphics" data-width="1080" data-height="1920"></div>
<div id="o4" data-composition-id="o4" data-composition-src="compositions/o4.html" data-start="8.5" data-duration="6" data-track-index="2" data-track-kind="graphics" data-width="1080" data-height="1920"></div>
<div id="o5" data-composition-id="o5" data-composition-src="compositions/o5.html" data-start="14.5" data-duration="3" data-track-index="2" data-track-kind="graphics" data-width="1080" data-height="1920"></div>
<div id="o6" data-composition-id="o6" data-composition-src="compositions/o6.html" data-start="17.5" data-duration="3.5" data-track-index="2" data-track-kind="graphics" data-width="1080" data-height="1920"></div>
</div>
<script type="module">
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
import { makeCloud, makeDrop, JELLY, animate as animateChars } from './assets/characters.js';
// 결정적 난수: 프레임을 어느 순서로 그려도 같은 별·구름 자리
function mulberry32(a) { return () => { a |= 0; a = (a + 0x6d2b79f5) | 0; let t = Math.imul(a ^ (a >>> 15), 1 | a); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; }
const rand = mulberry32(20261024);
const rnd = (a, b) => a + rand() * (b - a);
const W = 1080, H = 1920;
const canvas = document.getElementById('world');
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, preserveDrawingBuffer: true });
renderer.setPixelRatio(1);
renderer.setSize(W, H, false);
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(62, W / H, 0.1, 3000);
// 하늘: 브랜드 색 그라데이션 돔 (위 색 → 지평선 색). 분위기(mood) 0 새벽 · 1 낮 · 2 흐림 · 3 노을 · 4 밤 사이를 보간
const PAL = [['#ffb7a3', '#ffe6cf'], ['#3f8fe0', '#dff0ff'], ['#8a95ad', '#d3d8e2'], ['#4a3f8f', '#ff8a4a'], ['#0b1230', '#2a3570']].map(([a, b]) => [new THREE.Color(a), new THREE.Color(b)]);
const domeMat = new THREE.ShaderMaterial({
side: THREE.BackSide, depthWrite: false, toneMapped: false,
uniforms: { top: { value: new THREE.Color('#3f8fe0') }, bottom: { value: new THREE.Color('#dff0ff') }, sun: { value: new THREE.Vector3(0, 1, 0) }, glow: { value: 0.0 }, glowColor: { value: new THREE.Color('#ffd27a') } },
vertexShader: 'varying vec3 vDir; void main(){ vDir = normalize(position); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }',
fragmentShader: 'uniform vec3 top; uniform vec3 bottom; uniform vec3 sun; uniform float glow; uniform vec3 glowColor; varying vec3 vDir; void main(){ float h = clamp(vDir.y * 1.6 + 0.25, 0.0, 1.0); vec3 c = mix(bottom, top, smoothstep(0.0, 1.0, h)); float d = max(dot(normalize(vDir), normalize(sun)), 0.0); c += glowColor * glow * pow(d, 28.0) * 1.4 + glowColor * glow * pow(d, 4.0) * 0.25; gl_FragColor = vec4(c, 1.0); }',
});
const dome = new THREE.Mesh(new THREE.SphereGeometry(2000, 32, 24), domeMat);
scene.add(dome);
const sunDir = new THREE.Vector3();
const hemi = new THREE.HemisphereLight(0xdfefff, 0x6a7aa0, 1.4);
const sunLight = new THREE.DirectionalLight(0xffffff, 2.2);
const fill = new THREE.DirectionalLight(0xfff4ea, 0);
scene.add(hemi, sunLight, sunLight.target, fill, fill.target);
// 별
const starN = 1600, sp = new Float32Array(starN * 3);
for (let i = 0; i < starN; i++) {
const th = rand() * Math.PI * 2, ph = Math.acos(rand() * 0.92);
sp.set([Math.sin(ph) * Math.cos(th) * 900, Math.cos(ph) * 900 - 40, Math.sin(ph) * Math.sin(th) * 900], i * 3);
}
const starGeo = new THREE.BufferGeometry();
starGeo.setAttribute('position', new THREE.BufferAttribute(sp, 3));
const starMat = new THREE.PointsMaterial({ color: 0xffffff, size: 2.4, sizeAttenuation: false, transparent: true, opacity: 0, depthWrite: false });
scene.add(new THREE.Points(starGeo, starMat));
// 상태: 타임라인이 이 값을 움직이고, 프레임마다 읽어서 그린다
const S = { elev: 9, azim: 168, turb: 3, ray: 2.4, mie: 0.004, g: 0.8, exp: 0.38, camX: 0, camY: 1.4, camZ: 12, lookY: 4.5, lookX: 0, cloud: 1, stars: 0, island: 0, pass: 0, rise: 0, spin: 0, mood: 0, glow: 0.6, nightIcons: 0, chars: 1, charsEnd: 0, iconWalk: 0, iconCamp: 0, iconSunset: 0, rain: 0 };
const tex = new THREE.TextureLoader();
const sprite = (name, s) => {
const map = tex.load(`assets/icons/${name}.png`);
map.colorSpace = THREE.SRGBColorSpace;
const spr = new THREE.Sprite(new THREE.SpriteMaterial({ map, transparent: true, depthWrite: false, toneMapped: false, opacity: 0 }));
spr.scale.set(s, s, 1);
scene.add(spr);
return spr;
};
// 하늘에 뜬 날씨각 3D 아이콘 (첫 장면), 비 (흐림 장면), 섬 옆 활동 아이콘 (증명 장면)
const skyIcons = [['sun', 3.0, 2.6, -9, 2.2], ['umbrella', -3.0, 1.2, -11, 1.8], ['bike', 2.6, -0.4, -5, 1.4], ['laundry', -1.4, -1.2, -15, 1.7]].map(([n, x, y, z, s], i) => { const o = sprite(n, s); o.position.set(x, y, z); o.userData = { x, y, z, phase: i * 1.3, amp: 0.18 + (i % 3) * 0.07 }; return o; });
const rainIcon = sprite('rain', 3.2); rainIcon.position.set(-2.4, 6.5, -12);
// 날씨각 캐릭터 구름 캐릭터(초록 털뭉치)·물방울 캐릭터(파란 젤리): 카메라 앞 한 벌, 섬 위 한 벌
const envTex = new THREE.PMREMGenerator(renderer).fromScene(new RoomEnvironment(), 0.04).texture;
const cloudA = makeCloud(), dropA = makeDrop(envTex);
const cloudB = makeCloud(22), dropB = makeDrop(envTex);
scene.add(cloudA.group, dropA.group);
const walkIcon = sprite('walk', 2.2), campIcon = sprite('camping', 2.2), sunsetIcon = sprite('sunset', 2.6);
// 밤하늘의 각 무리 (폰 화면 대신): 68가지 중 아홉
const NIGHT = [['hangang', -4.2, 2.0, 2.2], ['drive', 3.8, 3.2, 2.0], ['walk', -1.2, 5.2, 1.8], ['camping', 4.6, 7.4, 1.9], ['stars', -4.8, 8.6, 2.0], ['running', 1.4, 0.6, 1.6], ['laundry', -3.4, -1.6, 1.5], ['bike', 5.2, -0.4, 1.6], ['picnic', 0.6, 9.8, 1.7]].map(([n, x, y, sc], i) => { const o = sprite(n, sc * 1.45); o.userData = { x, y, phase: i * 0.9, sc: sc * 1.45 }; return o; });
// 구름: 날씨각 Fluent 3D 구름
const cloudTex = tex.load('assets/icons/cloud.png');
cloudTex.colorSpace = THREE.SRGBColorSpace;
const cloudMat = new THREE.SpriteMaterial({ map: cloudTex, transparent: true, depthWrite: false, toneMapped: false });
const passMat = cloudMat.clone();
const clouds = new THREE.Group(), passClouds = new THREE.Group();
scene.add(clouds, passClouds);
const side = () => (rand() < 0.3 ? -1 : 1);
const addCloud = (group, mat, x, y, z, s) => { const c = new THREE.Sprite(mat); c.scale.set(s * (rand() < 0.5 ? -1 : 1), s, 1); c.position.set(x, y, z); c.userData = { drift: rnd(0.15, 0.5), x }; group.add(c); };
for (let i = 0; i < 7; i++) addCloud(clouds, cloudMat, side() * rnd(12, 40), rnd(9, 19), rnd(-70, -40), rnd(8, 16));
for (let i = 0; i < 18; i++) addCloud(passClouds, passMat, rnd(-8, 8), rnd(-1, 8), rnd(-38, -18), rnd(6, 12));
for (let i = 0; i < 12; i++) addCloud(clouds, cloudMat, side() * rnd(30, 130), rnd(16, 40), rnd(-280, -170), rnd(24, 44));
// 가을 섬 (Kenney Nature Kit, CC0)
const loader = new GLTFLoader();
const load = (url) => loader.loadAsync(url).then((g) => g.scene);
const names = ['cliff_block_rock', 'tree_oak', 'tree_default', 'tree_fat', 'tree_pineRoundA', 'tree_pineRoundC', 'rock_largeA', 'rock_smallC', 'flower_redA', 'flower_yellowB', 'mushroom_redGroup', 'tent_smallOpen', 'campfire_stones', 'grass_large', 'plant_bushLarge'];
const island = new THREE.Group();
const mats = {
leaf: new THREE.MeshStandardMaterial({ color: 0xff7a2e, roughness: 0.9, flatShading: true }),
pine: new THREE.MeshStandardMaterial({ color: 0x3a8f6a, roughness: 0.9, flatShading: true }),
grass: new THREE.MeshStandardMaterial({ color: 0xc8b25a, roughness: 1, flatShading: true }),
dirt: new THREE.MeshStandardMaterial({ color: 0xc77a52, roughness: 1, flatShading: true }),
wood: new THREE.MeshStandardMaterial({ color: 0x9a5a3c, roughness: 1, flatShading: true }),
};
const pick = (mat, model) => { const n = mat.name.toLowerCase(); if (n.startsWith('leafs')) return model.startsWith('tree_pine') ? mats.pine : mats.leaf; if (n === 'grass') return mats.grass; if (n === 'dirt') return mats.dirt; if (n.startsWith('wood')) return mats.wood; return mat; };
const build = (async () => {
const M = Object.fromEntries(await Promise.all(names.map(async (n) => [n, await load(`assets/models/${n}.glb`)])));
const put = (name, x, z, s = 1, ry = 0, y = 1) => { const o = M[name].clone(true); o.traverse((m) => { if (m.isMesh) m.material = pick(m.material, name); }); o.position.set(x, y, z); o.scale.setScalar(s); o.rotation.y = ry; island.add(o); return o; };
for (let x = -1; x <= 1; x++) for (let z = -1; z <= 1; z++) put('cliff_block_rock', x, z, 1, 0, 0);
put('cliff_block_rock', 0, 0, 0.7, 0.4, -0.7);
put('tree_oak', -0.95, -0.85, 1.25, 0.3); put('tree_default', 0.2, -1, 1.05, 1.2); put('tree_fat', -1.1, 0.3, 0.95, 2);
put('tree_pineRoundA', 1.05, -0.55, 1.1); put('tree_pineRoundC', 1.15, 0.55, 0.9, 0.8);
put('tent_smallOpen', 0.15, 0.45, 0.9, -0.5); put('campfire_stones', -0.35, 0.95, 0.8);
put('rock_largeA', 0.95, 1.05, 0.55, 1.1); put('rock_smallC', -0.75, 1.15, 0.8);
put('grass_large', 0.55, -0.05, 0.8); put('plant_bushLarge', -0.4, -0.05, 0.7, 1.5);
put('flower_redA', -1.15, 1.1); put('flower_yellowB', 0.55, 1.15, 1, 1); put('mushroom_redGroup', -0.05, -0.55, 0.8);
// 섬 위에 서 있는 구름·물방울 캐릭터 (섬과 함께 돈다)
cloudB.group.position.set(-0.85, 1.42, 1.25); cloudB.group.scale.setScalar(0.36); island.add(cloudB.group);
dropB.group.position.set(0.9, 1.5, 1.35); dropB.group.scale.setScalar(0.34); island.add(dropB.group);
island.position.set(0, -2.6, -118); island.scale.setScalar(2.0); island.rotation.x = 0.05;
scene.add(island);
})();
window.__hf = window.__hf || {}; window.__hf.buildReady = window.__hf.buildReady || {};
window.__hf.buildReady.main = build;
// 타임라인: 하늘·카메라·아이콘 상태 (절대 초). 위에 얹는 글과 같은 박자
const tl = gsap.timeline({ paused: true });
const at = (pos, dur, vars, ease = 'sine.inOut') => tl.to(S, { ...vars, duration: Math.max(0.01, dur), ease }, pos);
// 0~3 새벽에서 낮으로: 해가 뜨고 카메라가 구름을 뚫고 앞으로
at(0, 2.6, { rise: 1 }, 'power2.out');
at(0, 2.4, { mood: 1, glow: 0.9 });
at(3, 0.8, { mood: 2, glow: 0.1 });
at(5.9, 0.9, { mood: 1, glow: 0.8 });
at(5.6, 0.5, { chars: 0 }, 'power2.in');
at(8.5, 5.5, { mood: 3, glow: 1.2 });
at(14.3, 1.2, { mood: 4, glow: 0 });
at(0, 3, { camZ: -20, camY: 2.2, lookY: 9, elev: 40, azim: 196, turb: 2.0, ray: 2.6, mie: 0.003, exp: 0.36 });
at(0.2, 0.8, { pass: 0.85 }); at(1.3, 0.9, { pass: 0 });
// 3~6 흐림: 하늘이 탁해지고 비 아이콘
at(3, 0.8, { turb: 14, ray: 0.8, mie: 0.02, g: 0.7, cloud: 0.4, exp: 0.26, elev: 18, pass: 0.45 });
at(3.2, 0.5, { rain: 1 }, 'back.out(1.5)');
at(3, 3, { camZ: -34, lookY: 5 }, 'none');
// 6~8.5 맑게 걷히고 섬으로 하강
at(5.9, 0.9, { turb: 2.2, ray: 2.6, mie: 0.004, g: 0.8, cloud: 1, exp: 0.38, rain: 0, pass: 0 });
at(6, 2.5, { camZ: -103, camY: 1.4, lookY: 3.2, island: 1 }, 'power2.inOut');
// 8.5~14.5 섬 주위: 황금빛으로 기울며 세 아이콘이 차례로 뜬다
at(8.5, 6, { spin: 1.6, camX: -1.2, lookX: -0.3, camZ: -106, lookY: 3.0 }, 'none');
at(8.5, 6, { elev: 2.4, turb: 4.0, ray: 3.2, mie: 0.008, g: 0.93, exp: 0.5 });
at(8.8, 0.5, { iconWalk: 1 }, 'back.out(1.6)');
at(10.8, 0.5, { iconCamp: 1 }, 'back.out(1.6)');
at(12.8, 0.5, { iconSunset: 1 }, 'back.out(1.6)');
// 14.5~21 밤: 해가 지고 별이 켜지고 카메라가 위를 본다
at(14.3, 1.2, { elev: -9, exp: 0.26, stars: 1, camY: 5, lookY: 13, camX: 0, lookX: 0, iconWalk: 0, iconCamp: 0, iconSunset: 0 });
at(15.5, 5.5, { camY: 7, lookY: 16 }, 'none');
at(15.0, 0.9, { nightIcons: 1 }, 'back.out(1.4)');
at(17.7, 0.7, { charsEnd: 1 }, 'back.out(1.3)');
at(17.3, 0.3, { nightIcons: 0 }, 'power2.in');
tl.to({}, { duration: 0.1 }, 20.9);
const warm = new THREE.Color(0xffa060), noon = new THREE.Color(0xffffff), dusk = new THREE.Color(0xff6a6a);
const cloudDay = new THREE.Color(0xffffff), cloudGray = new THREE.Color(0x9aa3b5);
const tintDay = new THREE.Color(0xffffff), tintDusk = new THREE.Color(0xffb59a), tintNight = new THREE.Color(0x3a4378), cloudTint = new THREE.Color();
const C = THREE.MathUtils;
function renderAt(t) {
tl.seek(t, false);
camera.position.set(S.camX, S.camY, S.camZ);
camera.lookAt(S.camX + S.lookX, S.lookY, S.camZ - 30);
const elev = S.elev - (1 - S.rise) * 12;
sunDir.setFromSphericalCoords(1, C.degToRad(90 - elev), C.degToRad(S.azim));
{ const m = C.clamp(S.mood, 0, 4), i = Math.min(3, Math.floor(m)), f = m - i; domeMat.uniforms.top.value.copy(PAL[i][0]).lerp(PAL[i + 1][0], f); domeMat.uniforms.bottom.value.copy(PAL[i][1]).lerp(PAL[i + 1][1], f); domeMat.uniforms.sun.value.copy(sunDir); domeMat.uniforms.glow.value = S.glow; domeMat.uniforms.glowColor.value.set(m > 2.5 ? '#ffb070' : '#fff1c2'); }
renderer.toneMappingExposure = 0.9;
const day = C.clamp(elev / 30, 0, 1), low = C.clamp(1 - elev / 12, 0, 1), night = C.clamp(-elev / 6, 0, 1);
sunLight.position.copy(sunDir).multiplyScalar(100).add(camera.position); sunLight.target.position.copy(camera.position);
sunLight.color.copy(noon).lerp(warm, low).lerp(dusk, C.clamp(-elev / 3, 0, 1));
sunLight.intensity = C.clamp((elev + 4) / 10, 0.05, 1) * 2.4;
hemi.intensity = 0.35 + day * 1.1; hemi.color.setHSL(0.6 - low * 0.55, 0.5, 0.75 - low * 0.1);
cloudTint.copy(tintDay).lerp(tintDusk, low).lerp(tintNight, night);
cloudMat.color.copy(cloudDay).lerp(cloudGray, 1 - S.cloud).multiply(cloudTint);
passMat.color.copy(cloudMat.color); passMat.opacity = S.pass; passClouds.visible = S.pass > 0.01;
fill.position.copy(camera.position).add(new THREE.Vector3(-4, 6, 6)); fill.target.position.copy(island.position); fill.intensity = S.island * (1.6 - night * 0.8);
for (const c of [...clouds.children, ...passClouds.children]) c.position.x = c.userData.x + Math.sin(t * 0.05 + c.userData.drift * 9) * c.userData.drift * 6;
skyIcons.forEach((s, i) => { const fall = C.clamp(1 - S.rise, 0, 1); s.position.y = s.userData.y + fall * 14 + Math.sin(t * 1.1 + s.userData.phase) * s.userData.amp; s.material.opacity = S.rise * (1 - C.clamp((t - 2.4) / 0.6, 0, 1)); s.material.rotation = Math.sin(t * 0.8 + s.userData.phase) * 0.06; });
rainIcon.material.opacity = S.rain; rainIcon.position.y = 6.5 - (1 - S.rain) * 3 + Math.sin(t * 1.3) * 0.15; rainIcon.position.z = S.camZ - 14;
// 섬 옆 활동 아이콘: 섬 기준 자리, 카메라 쪽으로 살짝 띄움
const ip = island.position;
walkIcon.position.set(ip.x - 4.2, ip.y + 5.2 + Math.sin(t * 1.2) * 0.12, ip.z + 2.2); walkIcon.material.opacity = S.iconWalk; walkIcon.scale.setScalar(2.2 * (0.4 + 0.6 * S.iconWalk));
campIcon.position.set(ip.x + 4.0, ip.y + 4.8 + Math.sin(t * 1.1 + 1) * 0.12, ip.z + 2.6); campIcon.material.opacity = S.iconCamp; campIcon.scale.setScalar(2.2 * (0.4 + 0.6 * S.iconCamp));
sunsetIcon.position.set(ip.x + 0.4, ip.y + 7.6 + Math.sin(t * 0.9 + 2) * 0.12, ip.z + 1.5); sunsetIcon.material.opacity = S.iconSunset; sunsetIcon.scale.setScalar(2.6 * (0.4 + 0.6 * S.iconSunset));
NIGHT.forEach((o, i) => { const k = C.clamp(S.nightIcons - i * 0.06, 0, 1); o.material.opacity = k; o.scale.setScalar(o.userData.sc * (0.3 + 0.7 * k)); o.position.set(S.camX + o.userData.x, S.lookY + o.userData.y - 2 + Math.sin(t * 1.1 + o.userData.phase) * 0.15, S.camZ - 30); });
// 카메라 앞 구름·물방울 캐릭터: 첫 장면엔 아래 양쪽, 섬 장면엔 화면 밖(아래), 밤엔 다시 올라온다
{ const up = Math.max(S.chars, S.nightIcons, S.charsEnd), drop = (1 - up) * 7;
cloudA.group.position.set(S.camX - 1.55, S.camY - 1.25 - drop + Math.sin(t * 1.3) * 0.08, S.camZ - 7.5); cloudA.group.scale.setScalar(0.66);
dropA.group.position.set(S.camX + 1.6, S.camY - 1.2 - drop + Math.sin(t * 1.3 + 1.7) * 0.08, S.camZ - 7.5); dropA.group.scale.setScalar(0.64);
cloudA.group.lookAt(camera.position); dropA.group.lookAt(camera.position);
animateChars(cloudA, dropA, t, 0); animateChars(cloudB, dropB, t, 2.1);
const warm = C.clamp(S.mood - 2, 0, 1) * (1 - C.clamp(S.mood - 3, 0, 1)), nightK = C.clamp(S.mood - 3, 0, 1);
for (const b of [cloudA, cloudB]) { b.uniforms.uTint.value = warm; b.uniforms.uNight.value = nightK; }
for (const m of [dropA, dropB]) { m.front.color.copy(JELLY.blue).lerp(JELLY.warm, warm * 0.75).lerp(JELLY.night, nightK * 0.5); m.back.color.copy(m.front.color); }
}
starMat.opacity = S.stars;
island.visible = S.island > 0.01;
island.rotation.y = -0.6 + S.spin * 0.9;
renderer.render(scene, camera);
}
window.addEventListener('hf-seek', (e) => { e.detail.waitUntil?.(build); renderAt(e.detail.time); });
build.then(() => renderAt(0));
window.__timelines["main"] = gsap.timeline({ paused: true });
</script>
</body>
</html>