Init Main project

This commit is contained in:
tyuXX 2026-11-15 12:57:24 +03:00
commit 9e581ae67f
220 changed files with 253987 additions and 0 deletions

View file

@ -0,0 +1,213 @@
// Renders individual parts (tanks, engines, avionics, structures, shrouds).
import * as THREE from "three";
import type { PlacedComponent } from "../../../shared/types.js";
import {
buildOgiveFairingGeo,
buildParabolicBellGeo,
buildStageConnector,
} from "./geometry.js";
import {
ACCENT_STRIPE_MAT,
addSelectionHalo,
AVIONICS_RING_MAT,
DARK_NOZZLE_MAT,
FAIRING_SOLID_MAT,
SHUTTLE_FOAM_MAT,
} from "./materials.js";
export function buildSinglePartCopy(
comp: PlacedComponent,
tankMat: THREE.MeshStandardMaterial,
nextStageDia: number,
isSelected: boolean,
stageDia: number = comp.diameter,
): THREE.Group {
const g = new THREE.Group();
const r = comp.diameter / 2;
if (comp.role === "engine") {
const skirt = new THREE.Mesh(
new THREE.CylinderGeometry(r * 0.55, r * 0.38, comp.length * 0.22, 18),
AVIONICS_RING_MAT,
);
skirt.position.y = comp.length * 0.89;
g.add(skirt);
const bellH = comp.length * 0.8;
const bell = new THREE.Mesh(
buildParabolicBellGeo(r, bellH),
DARK_NOZZLE_MAT,
);
bell.castShadow = true;
bell.receiveShadow = true;
g.add(bell);
const lip = new THREE.Mesh(
new THREE.TorusGeometry(r * 0.97, Math.max(0.025, r * 0.06), 8, 22),
DARK_NOZZLE_MAT,
);
lip.rotation.x = Math.PI / 2;
lip.position.y = 0.03;
g.add(lip);
} else if (comp.role === "tank") {
if (comp.isDropTank) {
const barrelMat =
comp.part.id === "drop-tank-hydro-et" ? SHUTTLE_FOAM_MAT : tankMat;
const aftH = Math.max(0.28, comp.length * 0.06);
const noseH = Math.max(0.55, comp.length * 0.22);
const cylLen = Math.max(0.6, comp.length - aftH - noseH);
const aftCap = new THREE.Mesh(
new THREE.CylinderGeometry(r, r * 0.62, aftH, 32),
barrelMat,
);
aftCap.position.y = aftH / 2;
aftCap.castShadow = true;
aftCap.receiveShadow = true;
g.add(aftCap);
const tankMesh = new THREE.Mesh(
new THREE.CylinderGeometry(r, r, cylLen, 36),
barrelMat,
);
tankMesh.position.y = aftH + cylLen / 2;
tankMesh.castShadow = true;
tankMesh.receiveShadow = true;
g.add(tankMesh);
const nose = new THREE.Mesh(
new THREE.CylinderGeometry(r * 0.14, r, noseH, 36),
barrelMat,
);
nose.position.y = aftH + cylLen + noseH / 2;
nose.castShadow = true;
g.add(nose);
const noseTip = new THREE.Mesh(
new THREE.SphereGeometry(r * 0.14, 16, 10),
AVIONICS_RING_MAT,
);
noseTip.position.y = aftH + cylLen + noseH;
g.add(noseTip);
for (const frac of [0.16, 0.54, 0.92]) {
const band = new THREE.Mesh(
new THREE.CylinderGeometry(r * 1.018, r * 1.018, 0.14, 36),
AVIONICS_RING_MAT,
);
band.position.y = aftH + cylLen * frac;
g.add(band);
}
} else {
const tankMesh = new THREE.Mesh(
new THREE.CylinderGeometry(r, r, comp.length, 48),
tankMat,
);
tankMesh.position.y = comp.length / 2;
tankMesh.castShadow = true;
tankMesh.receiveShadow = true;
g.add(tankMesh);
for (const frac of [0.15, 0.5, 0.85]) {
const ring = new THREE.Mesh(
new THREE.CylinderGeometry(r * 1.012, r * 1.012, 0.16, 48),
AVIONICS_RING_MAT,
);
ring.position.y = comp.length * frac;
ring.castShadow = true;
g.add(ring);
}
const raceway = new THREE.Mesh(
new THREE.BoxGeometry(
Math.max(0.12, r * 0.08),
comp.length * 0.94,
Math.max(0.08, r * 0.06),
),
AVIONICS_RING_MAT,
);
raceway.position.set(0, comp.length / 2, r * 0.995);
g.add(raceway);
}
} else if (comp.role === "heatshield") {
const shield = new THREE.Mesh(
new THREE.CylinderGeometry(r * 1.03, r * 1.03, comp.length, 32),
new THREE.MeshStandardMaterial({
color: 0x451a03,
metalness: 0.3,
roughness: 0.85,
}),
);
shield.position.y = comp.length / 2;
g.add(shield);
} else if (comp.role === "structure") {
const avionics = new THREE.Mesh(
new THREE.CylinderGeometry(r, r, comp.length, 48),
tankMat,
);
avionics.position.y = comp.length / 2;
avionics.castShadow = true;
avionics.receiveShadow = true;
g.add(avionics);
const botTrim = new THREE.Mesh(
new THREE.CylinderGeometry(
r * 1.008,
r * 1.008,
Math.min(0.24, comp.length * 0.22),
48,
),
AVIONICS_RING_MAT,
);
botTrim.position.y = Math.min(0.12, comp.length * 0.11);
g.add(botTrim);
const topTrim = new THREE.Mesh(
new THREE.CylinderGeometry(
r * 1.008,
r * 1.008,
Math.min(0.24, comp.length * 0.22),
48,
),
AVIONICS_RING_MAT,
);
topTrim.position.y = comp.length - Math.min(0.12, comp.length * 0.11);
g.add(topTrim);
const stripe = new THREE.Mesh(
new THREE.CylinderGeometry(r * 1.012, r * 1.012, 0.2, 48),
ACCENT_STRIPE_MAT,
);
stripe.position.y = comp.length * 0.5;
g.add(stripe);
} else if (comp.role === "interstage") {
const botR = stageDia / 2;
const topR = nextStageDia > 0.2 ? nextStageDia / 2 : r;
g.add(buildStageConnector(botR, topR, Math.max(0.6, comp.length), tankMat));
} else if (comp.role === "computer") {
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(
r * 1.02,
r * 1.02,
Math.max(0.45, comp.length),
24,
),
new THREE.MeshStandardMaterial({
color: 0x0f172a,
metalness: 0.72,
roughness: 0.28,
}),
);
collar.position.y = Math.max(0.45, comp.length) / 2;
const ledColor =
(comp.part.radHardeningLevel ?? 1) >= 3
? 0x34d399
: (comp.part.radHardeningLevel ?? 1) >= 2
? 0x38bdf8
: 0xf59e0b;
const busRing = new THREE.Mesh(
new THREE.TorusGeometry(r * 1.03, 0.055, 8, 28),
new THREE.MeshBasicMaterial({ color: ledColor }),
);
busRing.rotation.x = Math.PI / 2;
busRing.position.y = Math.max(0.45, comp.length) * 0.55;
g.add(collar, busRing);
} else if (comp.role === "fairing") {
const shroud = new THREE.Mesh(
buildOgiveFairingGeo(r, comp.length),
FAIRING_SOLID_MAT,
);
shroud.castShadow = true;
shroud.receiveShadow = true;
g.add(shroud);
}
if (isSelected) addSelectionHalo(g, comp);
return g;
}