Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md

Large diffs are not rendered by default.

Binary file modified e63334287a3deaa3/ironwing/assets/aircraft.glb
Binary file not shown.
Binary file modified e63334287a3deaa3/ironwing/assets/ships.glb
Binary file not shown.
61 changes: 56 additions & 5 deletions e63334287a3deaa3/ironwing/js/art.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,15 +476,27 @@
m.name = name; m.userData.linear = true; return (GM[key] = m);
}
function tinted(m, team, table) {
if (!team || !m.color || m.name === 'glass' || m.name === 'deck') return m;
if (!team || !m.color || m.name === 'glass' || m.name === 'deck' || m.name === 'tex_deck') return m;
const key = m.uuid + team; if (GM[key]) return GM[key];
const c = m.clone(); c.color.copy(table[team] || table.blue); c.userData.linear = true; return (GM[key] = c);
}
// the hero models' baked sets (tools/vehicles/texbake.py): albedo (sRGB), normal and ORM maps come with the file;
// only the environment strength is set here, once per set, so every clone shares one material
const TEXM = {};
function texMat(m, group) {
const key = m.name; if (TEXM[key]) return TEXM[key];
m.envMapIntensity = key === 'tex_deck' ? 0.35 : group === 'air' ? 0.8 : 0.6; m.vertexColors = false;
if (m.map) m.map.anisotropy = 4;
// Low keeps only the colour map: the normal and ORM lookups over a screen full of deck doubled the frame time in
// the software renderer, and Low is for the slowest machines
if (IW.world.Q && IW.world.Q.name === 'low') { m.normalMap = m.roughnessMap = m.metalnessMap = m.aoMap = null; m.roughness = key === 'tex_deck' ? 0.85 : 0.55; m.metalness = key === 'tex_deck' ? 0.05 : 0.2; }
m.userData.linear = true; return (TEXM[key] = m);
}
function prep(root, group) {
root.traverse(o => {
if (!o.isMesh) return;
const name = (o.material && o.material.name || 'paint').replace(/\.\d+$/, '');
o.material = gm(name, group); o.geometry.userData.shared = true;
o.material = /^tex_/.test(name) ? texMat(o.material, group) : gm(name, group); o.geometry.userData.shared = true;
o.castShadow = group !== 'ground' || !/_dead$/.test(o.name); o.receiveShadow = group !== 'air';
});
}
Expand Down Expand Up @@ -512,6 +524,9 @@
root.children.filter(o => /_gun[LR]\d+$/.test(o.name)).sort((a, b) => +a.name.match(/\d+$/)[0] - +b.name.match(/\d+$/)[0]).forEach(g => parts.guns.push(g));
parts.cockpitEye = get('_cockpitEye');
for (const side of ['L', 'R']) { const g = get('_gear' + side); if (g) parts.legs.push({ piv: g, side: Math.sign(g.position.x) || 1 }); }
// moving parts that only some types have: the sliding hood (the player's type) and the bomb-bay doors
parts.canopy = get('_canopy'); parts.bays = [get('_bayL'), get('_bayR')].filter(Boolean);
const cz0 = parts.canopy ? parts.canopy.position.z : 0, cy0 = parts.canopy ? parts.canopy.position.y : 0;
if (hero) {
parts.aileronL = get('_aileronL'); parts.aileronR = get('_aileronR'); parts.rudder = get('_rudder');
parts.elevators = [get('_elevatorL'), get('_elevatorR')].filter(Boolean); parts.flaps = [get('_flapsL'), get('_flapsR')].filter(Boolean);
Expand All @@ -520,9 +535,20 @@
if (lod) lod.visible = false;
root.userData.kind = kind;
root.traverse(o => { if (o.isMesh) o.castShadow = true; });
let spin = 0, far = false;
// the outer left wing panel can tear off (A.breakup); keep where it and the aileron on it belong
const wo = parts.wingOut = get('_wingOut'); parts.hi = hi;
const home = o => o && { o, p: o.position.clone(), q: o.quaternion.clone(), s: o.scale.clone() };
parts.home = [home(wo), home(parts.aileronL)].filter(Boolean);
let spin = 0, far = false, gearK = -1, hoodK = 0, bayK = 0;
const ease = k => k * k * (3 - 2 * k);
return {
root, parts,
// put back a torn-off wing (the player's aircraft is reused after a crash)
reset() {
if (!parts.broken) return; parts.broken = false; root.scale.x = 1;
for (const h of parts.home) { IW.fx.release(h.o); root.add(h.o); h.o.position.copy(h.p); h.o.quaternion.copy(h.q); h.o.scale.copy(h.s); }
if (wo && !hi.includes(wo)) hi.push(wo);
},
animate(dt, rpm, ctl) {
// the reduced copy far away (never for your own aircraft)
const isFar = !!(!hero && lod && root.position.distanceToSquared(IW.world.camera.position) > 450 * 450);
Expand All @@ -536,11 +562,35 @@
if (parts.rudder) parts.rudder.rotation.y = ctl.yaw * 0.4;
for (const f of parts.flaps) f.rotation.x = ctl.flaps * 0.6;
}
const k = ctl ? ctl.gear : 0;
for (const L of parts.legs) { L.piv.visible = k > 0.02; L.piv.rotation.z = (1 - k) * L.side * Math.PI / 2 * 0.98; }
// the gear folds inward into the wing roots, easing in and out of each end of its travel; the legs vanish
// only once they are inside the wing
// (the player's ctl.gear already moves over the gear time; an AI aircraft gives only where it wants the gear)
const want = ctl ? ctl.gear : 0; if (gearK < 0) gearK = want;
gearK = ctl && ctl.ai ? IW.clamp(gearK + Math.sign(want - gearK) * dt / 2.4, 0, 1) : want;
const e = ease(IW.clamp(gearK, 0, 1));
for (const L of parts.legs) { L.piv.visible = e > 0.015; L.piv.rotation.z = -(1 - e) * L.side * Math.PI / 2 * 0.97; }
// the hood slides back on the deck and closes for flight; the bay doors swing open for a bombing run
if (parts.canopy) { hoodK = IW.clamp(hoodK + Math.sign((ctl && ctl.canopy ? 1 : 0) - hoodK) * dt / 1.4, 0, 1); const h = ease(hoodK); parts.canopy.position.z = cz0 - h * 0.62; parts.canopy.position.y = cy0 + h * 0.03; }
if (parts.bays.length) { bayK = IW.clamp(bayK + Math.sign((ctl && ctl.bay ? 1 : 0) - bayK) * dt / 1.6, 0, 1); const b = ease(bayK) * 1.45; parts.bays[0].rotation.z = b; if (parts.bays[1]) parts.bays[1].rotation.z = -b; }
}
};
};
// a shot-down aircraft loses its outer wing panel (doIt: the caller's dice). Half the time the whole aircraft is
// mirrored first, so it is the right wing that goes. Returns { side: the roll direction toward the missing wing
// (+1 rolls right), at: the break in the aircraft's own frame, for the smoke } or null.
A.breakup = function (model, vel, doIt) {
const P = model.parts, wo = P && P.wingOut; if (!doIt || !wo || P.broken || !wo.parent) return null;
P.broken = true; const mir = Math.random() < 0.5; if (mir) model.root.scale.x = -1;
if (P.aileronL) wo.attach(P.aileronL);
const i = P.hi.indexOf(wo); if (i >= 0) P.hi.splice(i, 1);
wo.visible = true;
model.root.updateMatrixWorld(true);
const out = new THREE.Vector3(mir ? -1 : 1, 0, 0).applyQuaternion(model.root.quaternion);
const h = P.home[0].p, at = new THREE.Vector3(mir ? -h.x : h.x, h.y, h.z);
if (IW.fx.tearFlash) IW.fx.tearFlash(wo.getWorldPosition(new THREE.Vector3()));
IW.fx.detach(wo, vel.clone().addScaledVector(out, 7).add(new THREE.Vector3(0, 4, 0)), 3 + Math.random() * 4);
return { side: mir ? 1 : -1, at };
};
A.ship = function (kind, team) {
const root = clone(kind); if (!root) return SA.ship(kind, team);
root.traverse(o => { if (o.isMesh) o.material = tinted(o.material, team === 'blue' ? 'blue' : 'red', TINT); });
Expand All @@ -553,6 +603,7 @@
}
const lod = get('_lod1'), hi = root.children.filter(o => o !== lod && (o.isMesh || o.type === 'Group'));
if (lod) { lod.visible = false; root.onBeforeRender = null; out.lod = { lod, hi, far: false }; }
out.radars = root.children.filter(o => /_radar\d+$/.test(o.name)); // turned by the ship (units.js)
return out;
};
A.shipLod = function (art, dist) { // called by the ship each frame
Expand Down
31 changes: 21 additions & 10 deletions e63334287a3deaa3/ironwing/js/flight.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
P.q.setFromUnitVectors(new V3(0, 0, 1), d); P.vel.copy(d).multiplyScalar(spot.speed || 120);
}
P.prev.copy(P.pos); P.prevQ.copy(P.q); P.render.copy(P.pos); P.renderQ.copy(P.q);
if (P.model.reset) P.model.reset(); // a wing torn off last time goes back on
P.trailSt = {}; P.spinRate = 3.2; P.smokeAt = null;
P.model.root.visible = true;
IW.camera.reset();
};
Expand Down Expand Up @@ -224,7 +226,9 @@
function crash(why) {
if (!P.alive) return;
P.alive = false; P.state = 'dead'; P.hp = 0; P.grounded = false;
IW.fx.explode(P.pos, 1.6, 'air'); IW.fx.splash && IW.world.landAt(P.pos.x, P.pos.z) < 0 && IW.fx.splash(P.pos, 1.2);
const sea = IW.world.landAt(P.pos.x, P.pos.z) < 0;
IW.fx.explode(P.pos, 1.6, sea ? 'air' : 'ground'); IW.fx.debris(P.pos, P.vel, 5, 0.8, 'air');
if (sea) { IW.fx.splash(P.pos, 1.2); IW.fx.foam(P.pos, 4, 16, 30, 0.9); } else IW.fx.burn(P.pos.clone().setY(Math.max(0, IW.world.landAt(P.pos.x, P.pos.z))), 20, 1);
P.model.root.visible = false; P.deadT = 0;
IW.emit('playerDown', why);
}
Expand All @@ -238,16 +242,25 @@
function shotDown() {
if (!P.alive) return;
P.alive = false; P.state = 'dead'; P.deadT = 0; P.hp = 0;
IW.fx.explode(P.pos, 0.8, 'air');
IW.fx.explode(P.pos, 0.8, 'air'); IW.fx.debris(P.pos, P.vel, 4, 0.7, 'air');
// as with the AI: maybe a wing panel tears off, and the wreck rolls toward it
const br = IW.art.breakup && IW.art.breakup(P.model, P.vel, IW.forceBreak || Math.random() < 0.5);
P.spinRate = br ? br.side * 4.2 : 3.2; P.smokeAt = br ? br.at : new V3(0, 0, 3); P.trailSt = {};
IW.emit('playerShotDown');
}
function deadStep(dt) {
P.deadT += dt;
if (P.model.root.visible) {
P.vel.y -= T.g * dt; P.vel.multiplyScalar(Math.exp(-0.3 * dt)); P.pos.addScaledVector(P.vel, dt);
tq.setFromAxisAngle(new V3(0, 0, 1), 3.2 * dt); P.q.multiply(tq);
if ((P.smokeT -= dt) <= 0) { P.smokeT = 0.03; IW.fx.firePuff(P.pos, P.vel, 3); IW.fx.smokePuff(P.pos, P.vel, 3, true, 5); }
if (P.pos.y < IW.world.groundAt(P.pos.x, P.pos.z) + 1 || P.deadT > 14) { IW.fx.explode(P.pos, 1.5, 'air'); if (IW.world.landAt(P.pos.x, P.pos.z) < 0) IW.fx.splash(P.pos, 1.5); P.model.root.visible = false; IW.emit('playerDown', 'Shot down.'); }
tq.setFromAxisAngle(new V3(0, 0, 1), (P.spinRate || 3.2) * dt); P.q.multiply(tq);
P.vel.applyAxisAngle(new V3(0, 1, 0), (P.spinRate || 3.2) * 0.08 * Math.min(1, P.deadT) * dt);
IW.fx.trail(tA.copy(P.smokeAt || new V3(0, 0, 3)).applyQuaternion(P.q).add(P.pos), P.vel, 1, dt, P.trailSt || (P.trailSt = {}));
if (P.pos.y < IW.world.groundAt(P.pos.x, P.pos.z) + 1 || P.deadT > 14) {
const sea = IW.world.landAt(P.pos.x, P.pos.z) < 0;
IW.fx.explode(P.pos, 1.5, sea ? 'air' : 'ground');
if (sea) { IW.fx.splash(P.pos, 1.5); IW.fx.foam(P.pos, 4, 18, 30, 0.9); } else IW.fx.burn(P.pos.clone().setY(Math.max(0, IW.world.landAt(P.pos.x, P.pos.z))), 20, 1);
P.model.root.visible = false; IW.emit('playerDown', 'Shot down.');
}
}
}

Expand Down Expand Up @@ -325,17 +338,15 @@
}
function effects(dt) {
P.smokeT -= dt;
if (P.smokeT <= 0 && P.hp < 55) {
P.smokeT = P.hp < 25 ? 0.04 : 0.09;
const e = P.pos.clone().addScaledVector(P.fwd(tA), 3);
IW.fx.smokePuff(e, P.vel, 1.2, P.hp < 40, 2.5); if (P.hp < 25) IW.fx.firePuff(e, P.vel, 1.2);
}
// damage shows as a trail from the engine that thickens and darkens, with fire when it is nearly gone
if (P.hp < 60 && P.alive) IW.fx.trail(P.pos.clone().addScaledVector(P.fwd(tA), 3), P.vel, IW.clamp((60 - P.hp) / 55, 0, 1) * 0.9, dt, P.trailSt || (P.trailSt = {}));
if (P.gload > 5.5 && P.speed > 90 && !IW.S.motion) { const r = tB.set(-1, 0, 0).applyQuaternion(P.q); for (const s of [1, -1]) IW.fx.contrail(P.pos.clone().addScaledVector(r, 5.6 * s)); }
}
P.frame = function (alpha, dt) {
P.render.lerpVectors(P.prev, P.pos, alpha); P.renderQ.copy(P.prevQ).slerp(P.q, alpha);
if (!P.model) return;
P.model.root.position.copy(P.render); P.model.root.quaternion.copy(P.renderQ);
P.ctl.canopy = P.alive && (P.state === 'rearm' || (P.grounded && P.throttle < 0.5)) ? 1 : 0; // the hood opens on the deck
P.model.animate(dt, P.rpm, P.ctl);
IW.audio.engine(P.rpm, P.throttle, P.speed, P.alive && IW.playing());
IW.audio.stallHorn(P.alive && (P.stalled || (P.aoa > (F.aoaLimit + 1) * deg && P.speed > 20)) && !P.grounded);
Expand Down
Loading
Loading