Add wandering space alien cameo to the background scene
- Introduce a green wireframe alien with red eyes that spawns off-screen, waddles among the palms, waves at the camera, and strolls away on a randomized schedule - Bump PWA cache version (bri-tunes-v10) so installed clients pick up the new bg-grid.js - Serve /sw.js with Cache-Control: no-cache so browsers revalidate and notice the service worker update promptly
This commit is contained in:
parent
46d30a767f
commit
e32bb119bb
|
|
@ -607,6 +607,206 @@ if (canvas) {
|
|||
flyby.active = entry;
|
||||
}
|
||||
|
||||
// ---------- Space alien (green with red eyes) — wanders among the palms ----------
|
||||
// Pops in off-screen, waddles around among the palm trees, occasionally
|
||||
// turns and waves at the camera, then strolls off-screen and reappears later.
|
||||
function makeAlien() {
|
||||
const g = new THREE.Group();
|
||||
const green = new THREE.LineBasicMaterial({ color: 0x59f0a0, transparent: true, opacity: 0.95 });
|
||||
const red = new THREE.LineBasicMaterial({ color: 0xff2b4a, transparent: true, opacity: 0.95 });
|
||||
|
||||
// Peanut body + big faceted head (faces +Z)
|
||||
const body = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.IcosahedronGeometry(0.32, 1)), green);
|
||||
body.position.set(0, 0.98, 0);
|
||||
body.scale.set(1, 1.35, 1);
|
||||
g.add(body);
|
||||
const head = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.IcosahedronGeometry(0.44, 1)), green);
|
||||
head.position.set(0, 1.62, 0);
|
||||
g.add(head);
|
||||
|
||||
// Big round red eyes + a tiny smile
|
||||
for (const ex of [-0.19, 0.19]) {
|
||||
const eye = new THREE.LineLoop(new THREE.BufferGeometry().setFromPoints(circlePtsZ(0.11, 8)), red);
|
||||
eye.position.set(ex, 1.68, 0.36);
|
||||
g.add(eye);
|
||||
}
|
||||
g.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints([
|
||||
new THREE.Vector3(-0.10, 1.46, 0.38), new THREE.Vector3(0, 1.41, 0.40), new THREE.Vector3(0.10, 1.46, 0.38),
|
||||
]), red));
|
||||
|
||||
// Antennae with little red tips
|
||||
for (const s of [-1, 1]) {
|
||||
g.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints([
|
||||
new THREE.Vector3(s * 0.14, 2.0, 0), new THREE.Vector3(s * 0.30, 2.42, 0),
|
||||
]), green));
|
||||
const tip = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.IcosahedronGeometry(0.07, 0)), red);
|
||||
tip.position.set(s * 0.30, 2.42, 0);
|
||||
g.add(tip);
|
||||
}
|
||||
|
||||
// Arms: pivot at the shoulder so they can swing and wave
|
||||
function makeArm(side) {
|
||||
const pivot = new THREE.Group();
|
||||
pivot.position.set(side * 0.42, 1.28, 0);
|
||||
pivot.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints([
|
||||
new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, -0.45, 0),
|
||||
]), green));
|
||||
const hand = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.IcosahedronGeometry(0.08, 0)), green);
|
||||
hand.position.set(0, -0.5, 0);
|
||||
pivot.add(hand);
|
||||
pivot.rotation.z = side * 0.22; // rest: hanging slightly out to the side
|
||||
g.add(pivot);
|
||||
return pivot;
|
||||
}
|
||||
const armL = makeArm(-1);
|
||||
const armR = makeArm(1);
|
||||
|
||||
// Legs: hip pivot -> thigh -> knee pivot -> shin + toe
|
||||
function makeLeg(side) {
|
||||
const hip = new THREE.Group();
|
||||
hip.position.set(side * 0.17, 0.68, 0);
|
||||
hip.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints([
|
||||
new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, -0.34, 0),
|
||||
]), green));
|
||||
const knee = new THREE.Group();
|
||||
knee.position.set(0, -0.34, 0);
|
||||
knee.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints([
|
||||
new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, -0.3, 0),
|
||||
]), green));
|
||||
knee.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints([
|
||||
new THREE.Vector3(0, 0, 0), new THREE.Vector3(0.05, 0.02, 0.15),
|
||||
]), green));
|
||||
hip.add(knee);
|
||||
g.add(hip);
|
||||
return { hip, knee };
|
||||
}
|
||||
const legL = makeLeg(-1);
|
||||
const legR = makeLeg(1);
|
||||
|
||||
return { group: g, armL, armR, legL, legR };
|
||||
}
|
||||
|
||||
const alien = makeAlien();
|
||||
alien.group.visible = false;
|
||||
scene.add(alien.group);
|
||||
|
||||
const alienState = {
|
||||
active: false,
|
||||
mode: 'hidden', // walk | wave | leave
|
||||
t: 0,
|
||||
waveDur: 0,
|
||||
phase: Math.random() * Math.PI * 2, // walk-cycle phase
|
||||
speed: 2.3,
|
||||
nextAt: performance.now() + rnd(12000, 25000),
|
||||
target: new THREE.Vector3(),
|
||||
};
|
||||
|
||||
function alienFace(dx, dz, dt) {
|
||||
let dy = Math.atan2(dx, dz) - alien.group.rotation.y;
|
||||
dy = Math.atan2(Math.sin(dy), Math.cos(dy)); // shortest arc
|
||||
alien.group.rotation.y += dy * Math.min(1, dt * 6);
|
||||
}
|
||||
|
||||
function alienPickLeaveTarget() {
|
||||
const side = Math.random() < 0.5 ? -1 : 1;
|
||||
alienState.target.set(side * rnd(45, 70), 0, alien.group.position.z + rnd(-4, 4));
|
||||
}
|
||||
|
||||
function poseAlien() {
|
||||
const st = alienState;
|
||||
const s = Math.sin(st.phase);
|
||||
if (st.mode === 'wave') {
|
||||
// Left arm up waving, other arm at rest, little happy hop
|
||||
const w = Math.sin(st.t * 9);
|
||||
alien.armL.rotation.x = 0;
|
||||
alien.armL.rotation.z = -2.3 + w * 0.4;
|
||||
alien.armR.rotation.x = 0;
|
||||
alien.armR.rotation.z = 0.22;
|
||||
alien.legL.hip.rotation.x = 0; alien.legL.knee.rotation.x = 0;
|
||||
alien.legR.hip.rotation.x = 0; alien.legR.knee.rotation.x = 0;
|
||||
alien.group.rotation.x = 0;
|
||||
alien.group.position.y = Math.max(0, Math.sin(st.t * 5)) * 0.08;
|
||||
} else {
|
||||
// Waddle: legs swing, knees bend when a leg is forward, arms counter-swing
|
||||
alien.legL.hip.rotation.x = s * 0.55;
|
||||
alien.legR.hip.rotation.x = -s * 0.55;
|
||||
alien.legL.knee.rotation.x = -Math.max(0, s) * 0.7;
|
||||
alien.legR.knee.rotation.x = -Math.max(0, -s) * 0.7;
|
||||
alien.armL.rotation.x = -s * 0.35;
|
||||
alien.armR.rotation.x = s * 0.35;
|
||||
alien.armL.rotation.z = -0.22;
|
||||
alien.armR.rotation.z = 0.22;
|
||||
alien.group.rotation.x = 0.05; // slight forward lean
|
||||
alien.group.position.y = Math.abs(Math.cos(st.phase)) * 0.05; // step bob
|
||||
}
|
||||
}
|
||||
|
||||
function updateAlien(dt, now) {
|
||||
const st = alienState;
|
||||
const g = alien.group;
|
||||
|
||||
if (!st.active) {
|
||||
if (now < st.nextAt) return;
|
||||
// Appear off-screen at the side, fairly close to the camera for a
|
||||
// good view (z < 0, in front of the camera)
|
||||
const side = Math.random() < 0.5 ? -1 : 1;
|
||||
g.position.set(side * rnd(30, 45), 0, -rnd(8, 22));
|
||||
st.target.set(rnd(-8, 8), 0, -rnd(8, 18));
|
||||
st.mode = 'walk';
|
||||
st.t = 0;
|
||||
st.active = true;
|
||||
g.visible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
st.t += dt;
|
||||
|
||||
if (st.mode === 'wave') {
|
||||
// Face the camera, wave, hop a bit, then head off
|
||||
alienFace(camera.position.x - g.position.x, camera.position.z - g.position.z, dt);
|
||||
if (st.t > st.waveDur) {
|
||||
st.mode = 'leave';
|
||||
st.t = 0;
|
||||
alienPickLeaveTarget();
|
||||
}
|
||||
poseAlien();
|
||||
return;
|
||||
}
|
||||
|
||||
// walk / leave: head toward the target
|
||||
const dx = st.target.x - g.position.x;
|
||||
const dz = st.target.z - g.position.z;
|
||||
const dist = Math.hypot(dx, dz);
|
||||
if (dist > 0.4) {
|
||||
const step = Math.min(dist, st.speed * dt);
|
||||
g.position.x += (dx / dist) * step;
|
||||
g.position.z += (dz / dist) * step;
|
||||
st.phase += dt * 7;
|
||||
alienFace(dx, dz, dt);
|
||||
poseAlien();
|
||||
return;
|
||||
}
|
||||
|
||||
if (st.mode === 'walk') {
|
||||
if (Math.random() < 0.4) {
|
||||
st.mode = 'wave';
|
||||
st.t = 0;
|
||||
st.waveDur = rnd(1.3, 2.4);
|
||||
} else {
|
||||
st.mode = 'leave';
|
||||
st.t = 0;
|
||||
alienPickLeaveTarget();
|
||||
}
|
||||
poseAlien();
|
||||
return;
|
||||
}
|
||||
|
||||
// Finished strolling off-screen — hide until the next cameo
|
||||
st.active = false;
|
||||
g.visible = false;
|
||||
st.nextAt = now + rnd(30000, 75000);
|
||||
}
|
||||
|
||||
|
||||
// ---------- Sky: stars and moon (in front of the sunset backdrop) ----------
|
||||
// Starfield rides along with the moon: as the moon crosses the sky, the
|
||||
|
|
@ -954,6 +1154,9 @@ if (canvas) {
|
|||
}
|
||||
}
|
||||
|
||||
// Space alien: spawn, wander, wave, depart
|
||||
updateAlien(dt, now);
|
||||
|
||||
// Street lamps: glow, beam and ground pool all breathe with the beat
|
||||
lampMat.opacity = 0.55 + state.beat * 0.35;
|
||||
beamMat.opacity = 0.1 + state.beat * 0.14;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const CACHE = 'bri-tunes-v9';
|
||||
const CACHE = 'bri-tunes-v10'; // bump so installed PWAs pull the new bg-grid.js (moon cycle, starfield drift, alien)
|
||||
const STATIC_PRECACHE = [
|
||||
'/',
|
||||
'/static/css/app.css',
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ app.use(express.json());
|
|||
// Service worker — must be at root scope to intercept all page requests.
|
||||
app.get('/sw.js', (req, res) => {
|
||||
res.set('Service-Worker-Allowed', '/');
|
||||
// Always revalidate so browsers notice a new SW (cache version bump) promptly.
|
||||
res.set('Cache-Control', 'no-cache');
|
||||
res.sendFile(path.join(__dirname, '..', 'public', 'sw.js'));
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue