Init Main project
This commit is contained in:
commit
9e581ae67f
220 changed files with 253987 additions and 0 deletions
12
.dockerignore
Normal file
12
.dockerignore
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
prototype/dist
|
||||||
|
prototype/data/db.json
|
||||||
|
prototype/data/db.json.tmp
|
||||||
|
prototype/data/ml_policy_weights.json
|
||||||
|
prototype/.gmat-work
|
||||||
|
.git
|
||||||
|
.env
|
||||||
|
.vscode
|
||||||
|
How
|
||||||
|
*.md
|
||||||
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
.env
|
||||||
|
data/db.json
|
||||||
|
.gmat-work
|
||||||
|
*.tsbuildinfo
|
||||||
|
*/data/db.json
|
||||||
|
*/dist/*
|
||||||
|
*/node_modules/*
|
||||||
1
.vscode/settings.json
vendored
Normal file
1
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{}
|
||||||
56
Dockerfile
Normal file
56
Dockerfile
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
# ---------- TypeScript build stage ----------
|
||||||
|
FROM node:26-alpine AS build
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY tsconfig.json tsconfig.base.json tsconfig.shared.json tsconfig.server.json tsconfig.client.json ./
|
||||||
|
COPY src ./src
|
||||||
|
COPY public ./public
|
||||||
|
COPY scripts ./scripts
|
||||||
|
COPY data ./data
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# ---------- Production Node dependencies ----------
|
||||||
|
FROM node:26-alpine AS deps
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci --omit=dev && npm cache clean --force
|
||||||
|
|
||||||
|
# ---------- Runtime stage (Arch Linux to match host GMAT glibc ABI) ----------
|
||||||
|
FROM archlinux:latest
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN pacman -Syu --noconfirm --needed nodejs python python-numpy \
|
||||||
|
&& rm -rf /var/cache/pacman/pkg/* \
|
||||||
|
&& groupadd -g 1000 node \
|
||||||
|
&& useradd -u 1000 -g node -m -s /bin/sh node \
|
||||||
|
&& mkdir -p /app/state /app/state/gmat-work /opt/gmat \
|
||||||
|
&& chown -R node:node /app/state
|
||||||
|
|
||||||
|
ENV NODE_ENV=production \
|
||||||
|
PORT=3000 \
|
||||||
|
DATA_FILE=/app/state/db.json \
|
||||||
|
ML_WEIGHTS_PATH=/app/state/ml_policy_weights.json \
|
||||||
|
GMAT_BIN=/opt/gmat/bin/GmatConsole-R2026a \
|
||||||
|
GMAT_CONSOLE_BIN=/opt/gmat/bin/GmatConsole-R2026a \
|
||||||
|
GMAT_WORK_DIR=/app/state/gmat-work \
|
||||||
|
ML_AI_ENABLED=1 \
|
||||||
|
ML_PYTHON_BIN=python3
|
||||||
|
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY models ./models
|
||||||
|
COPY --from=build /app/dist ./dist
|
||||||
|
COPY public ./public
|
||||||
|
COPY data ./data
|
||||||
|
COPY scripts/ml_agent.py ./scripts/ml_agent.py
|
||||||
|
|
||||||
|
USER node
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
|
||||||
|
CMD ["node", "-e", "fetch('http://127.0.0.1:' + (process.env.PORT || 3000) + '/api/info').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"]
|
||||||
|
|
||||||
|
CMD ["node", "dist/server/index.js"]
|
||||||
80
How/Plan.md
Normal file
80
How/Plan.md
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
# Space Gaem: You Will Feel the Pain
|
||||||
|
|
||||||
|
Space mission game where you run a company/space agency sponsored by governments to run space missions and explorations, and grow your company by successfully completing missions in the most efficient way using your budget.
|
||||||
|
Needs to be as realistic as possible while being playable.
|
||||||
|
|
||||||
|
## How this will work??
|
||||||
|
|
||||||
|
- Server
|
||||||
|
- Node.js TypeScript Express server
|
||||||
|
- Multiplayer: server is already authoritative - one shared persistent world state, multiple player agencies connecting at once
|
||||||
|
- Player sessions/accounts (simple: name + token, or just pick an agency name)
|
||||||
|
- WebSocket (or SSE) channel for live events: other players' launches, market ticks, competitor actions, shared solar system time
|
||||||
|
- Takes Client input and data to simulate missions and updates game state
|
||||||
|
- Sends game state to Client
|
||||||
|
- Renders simulated animations and sends to the client
|
||||||
|
- Simulated solar system (Required) and time passing/economy?
|
||||||
|
- Other players (AI) do missions and stuff
|
||||||
|
- Market dynamics and economy
|
||||||
|
- Multiplayer hooks: shared mission contract board (contracts contested between players+AI), shared launch windows, world events (solar weather, anomalies) affect everyone
|
||||||
|
> Physics is layered by fidelity:
|
||||||
|
> - Design validation: rocket equation (dv = Isp*g0*ln(m0/mf)), dv budget vs mission requirement, structural/thermal sanity checks. Instant, player-facing.
|
||||||
|
> - Ascent simulation: custom point-mass 6-DOF-lite (thrust, drag Cd estimate, gravity loss, gravity turn pitch program, staging events). Produces believable ascent, Max-Q, heating; decides if the rocket survives. Runs server-side at high rate.
|
||||||
|
> - Orbital phase: GMAT (already compiled) for player rocket missions. .gmat script templates per canonical mission type (LEO, lunar flyby, Mars transfer...), parameterized by launch date, C3/dv, payload. Run headless on design validation, cache trajectory, stream as telemetry. GMAT is point-mass only - no staging/aero/structures.
|
||||||
|
> - Background sim: Ephemeris service (SPICE kernels / VSOP87) for accurate solar system + real probes/telescopes positions at any game time. Real spacecraft kernels = real probes for free. Kepler propagation for fictional background probes.
|
||||||
|
> - Aero scope: trajectory shape only (drag, Max-Q, stability margin CP-vs-CG). No CFD-grade lift/flutter/wind - approximation is invisible to players.
|
||||||
|
|
||||||
|
- Client
|
||||||
|
- Node.js TypeScript Express.JS+Three.js frontend server that serves the game interface and bridges the game state from the server to the client
|
||||||
|
- Renders shit
|
||||||
|
- Takes user input
|
||||||
|
- Sends user input to server
|
||||||
|
- Rocket design is modular/constrained - design surface is the SAME on all difficulties, difficulty is NOT feature-gated
|
||||||
|
- Design tiers (player-selectable, cosmetic/UX depth not gating):
|
||||||
|
- Casual: pick stages, engine, tank size from presets
|
||||||
|
- Standard: tune dimensions (diameter, length, propellant load), pick materials per part
|
||||||
|
- Expert: same + mesh import (.obj/.stl) for custom part shapes, per-material layup, structural/thermal sim active. Shapes via parametric dims/meshes, NOT STEP/IGES B-rep.
|
||||||
|
- Materials (Al 7075, carbon fiber, Inconel, ablative phenolic...) feed mass/strength/thermal params into the sim. Simplified stress checks (sigma = F/A, shell buckling, ablation) - convincing approximation, not FEA.
|
||||||
|
- Design gameplay loop: Mission briefing (hard constraints: dv, payload, launch window) -> Budget -> Design rocket (parts + live dv/mass/cost meters vs requirements) -> Validate -> Test flight (ascent sim, Max-Q, staging, failure feedback) -> Launch (GMAT trajectory + telemetry playback) -> Debrief (scored on propellant margin, cost underrun, time)
|
||||||
|
|
||||||
|
- Difficulty model: NOT feature gates. Difficulty scales via:
|
||||||
|
- Budget caps (tighter budgets = forced efficiency)
|
||||||
|
- Harder mission parameters (tighter dv margins, smaller launch windows, more extreme targets)
|
||||||
|
- AI competitor agencies get better (better designs, win more contracts)
|
||||||
|
- Requirement/approval strictness (see below)
|
||||||
|
|
||||||
|
- Requirements & maturity system (NASA CML/TRL-inspired):
|
||||||
|
- Each requirement = machine-checkable rule {id, appliesTo, check(design), severity: mandatory|waiverable}
|
||||||
|
- Design screen shows live compliance checklist, checks re-run on every edit
|
||||||
|
- Design maturity levels gate progression: rough concept -> PDR/CDR-style review gates -> flight ready. Early concepts cheap to iterate, only mature designs can fly
|
||||||
|
- Waiver system: skip a requirement = costs budget + adds risk roll at launch
|
||||||
|
- Encode ~30-50 high-impact rules per mission type (mass limits, propellant compatibility, fracture control, pyro constraints, reentry heating, planetary protection). We enforce the engineering, not the literal standards text.
|
||||||
|
|
||||||
|
## Gameplay
|
||||||
|
|
||||||
|
- Player creates agency (shared world: your agency exists alongside other players' agencies)
|
||||||
|
- Player selects who to work for from a list of offers (offers may be contested - first to accept wins?)
|
||||||
|
- Player selects mission
|
||||||
|
- Player gets paid budget
|
||||||
|
- Player designs rocket, models rocket components and mission parameters
|
||||||
|
- Player makes sure the rocket is operable and livable for the crew
|
||||||
|
- Player tests rocket (Uses up budget every test)
|
||||||
|
- Player launches rocket (other players can watch your launch live on the shared map)
|
||||||
|
- Player completes mission
|
||||||
|
- Player gets increased budget for successful missions depending on how well they did
|
||||||
|
- etc.
|
||||||
|
|
||||||
|
## Multiplayer specifics
|
||||||
|
|
||||||
|
- Shared persistent world: one server process owns solar system time, market state, all agencies (player + AI)
|
||||||
|
- Async-friendly design: missions take real/simulated time - you launch, do other things, get notified on completion (fits rocket missions naturally, no need for real-time action)
|
||||||
|
- Live spectate: any player can watch an active launch/mission playback on the solar system map
|
||||||
|
- Competition: shared contract board, leaderboards (missions completed, budget earned, efficiency rating), rival agencies poaching your offers
|
||||||
|
- Optional co-op later: joint missions, shared stations, trading payload capacity
|
||||||
|
|
||||||
|
## Non player game loop
|
||||||
|
|
||||||
|
- Simulated solar system (Required) and time passing/economy?
|
||||||
|
- Other players (AI) do missions and stuff (AI fills the world so it feels alive even with few human players)
|
||||||
|
- Market dynamics and economy (shared across all players - prices react to everyone)
|
||||||
|
- etc.
|
||||||
18
How/Plan2.md
Normal file
18
How/Plan2.md
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
1. Flight computing is now a part and is required, can be overloaded/damaged, and can be affected by stray radiation
|
||||||
|
2. New random events, such as stray radiation and meteorites which have to be taken into account pre-launch
|
||||||
|
3. R&D Unlocks now also include better diagnostics both in-flight compute and pre-flight checks and graphs, supported by GMAT, as better diagnostics are always better.
|
||||||
|
4. Figure out how to fix the sideways movement bug when launching non-straight path rockets.
|
||||||
|
5. ML supported AI players, separate from standard AI players. (Might be hard to implement, but maybe?)
|
||||||
|
6. Cleanup unused models from disk and git history, takes up waay to much space.
|
||||||
|
7. Light Mode + A mode with less UI effects because this shit is so eye hurting.
|
||||||
|
8. Have different contractors have different contracts available at a given time, though duplicates should happen, such as not everyone has all missions, but like half.
|
||||||
|
|
||||||
|
Priority index:
|
||||||
|
- 1
|
||||||
|
- 3
|
||||||
|
- 4
|
||||||
|
- 7
|
||||||
|
- 8
|
||||||
|
- 2
|
||||||
|
- 5 (?)
|
||||||
|
- 6 (This will be done later on with my supervision)
|
||||||
7
How/Plan3.md
Normal file
7
How/Plan3.md
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
1. In the main menu, when hovering over any of the difficulties, sandbox also lights up. It should only light up when hovered over directly.
|
||||||
|
2. Fix the cheap looking graphics and wrong looking particles
|
||||||
|
3. Saving, sharing and loading rocket designs, better editor functionality including editor history, undo+redo, better editor errors such as which part isn't unlocked, which stage is errored etc.
|
||||||
|
4. Update the AI players (Both ML and standard) to be more competent, all flight director AI's keep going bankrupt.
|
||||||
|
5. Cleanup code and optimise where possible.
|
||||||
|
|
||||||
|
69. Mobile support?!?!?!? Hell naww
|
||||||
8
How/Plan4.md
Normal file
8
How/Plan4.md
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
1. Thrusters fire rendering offset too high.
|
||||||
|
2. Rocket stages, due to being too far apart, look like they're connected through the tip of their cones, when they should look to be connected by a full diameter only differentiated by a slight bottleneck.
|
||||||
|
3. The in-flight log should be above the flight stats, instead of at the bottom right.
|
||||||
|
4. AI players should be affected by all conditions the same as normal players and must overcome them, accordingly to their own difficulty.
|
||||||
|
5. The bottom right buttons should be pushed to the left when the sidebar opens, to prevent button overlap.
|
||||||
|
6. AI players are competent, yes, but they should still be affected by player-like cooldowns so they don't just spam missions.
|
||||||
|
7. AI players are currently stupidly good, and never fail even when low skill, and basically never go bankrupt.
|
||||||
|
8. You should only be able to take the same contract after doing 3 other contracts, unless it's the only contract you can do. True for all player types.
|
||||||
2
How/Plan5.md
Normal file
2
How/Plan5.md
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
1. Add tooltips to every terminologic label etc.
|
||||||
|
2. Add disposable fuel tanks that are added *on* a stage instead of *as* a stage, same as those big extra fuel tanks in real life.
|
||||||
2
How/Plan6.md
Normal file
2
How/Plan6.md
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
1. Split up codebase into smaller modular chunks.
|
||||||
|
2. Cleanup unused assets and git history.
|
||||||
17
README.md
Normal file
17
README.md
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Space Gaem: You Will Feel the Pain
|
||||||
|
|
||||||
|
## Made by [tyuXX] for the 2026 NASA Space Apps Challenge event.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Space mission simulation game where you choose a contractor and finish space flight contracts for them and run a space agency.
|
||||||
|
|
||||||
|
## How to run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm ci
|
||||||
|
npm run bs
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
8
SGYWFTP.code-workspace
Normal file
8
SGYWFTP.code-workspace
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
62
data/materials.json
Normal file
62
data/materials.json
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "al-7075",
|
||||||
|
"name": "Aluminum 7075-T6",
|
||||||
|
"description": "Aerospace-grade zinc-aluminum alloy. Balanced strength, low cost, moderate temperature ceiling.",
|
||||||
|
"densityFactor": 1.0,
|
||||||
|
"yieldStrengthMPa": 503,
|
||||||
|
"maxTempK": 450,
|
||||||
|
"costFactor": 1.0,
|
||||||
|
"colorHex": "#c8d2de",
|
||||||
|
"metalness": 0.65,
|
||||||
|
"roughness": 0.35
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "al-li-2195",
|
||||||
|
"name": "Aluminum-Lithium 2195",
|
||||||
|
"description": "Cryogenic-ready aerospace alloy used on modern super-heavy tanks. Lighter with higher stiffness.",
|
||||||
|
"densityFactor": 0.88,
|
||||||
|
"yieldStrengthMPa": 560,
|
||||||
|
"maxTempK": 490,
|
||||||
|
"costFactor": 1.45,
|
||||||
|
"colorHex": "#dbe4ee",
|
||||||
|
"metalness": 0.72,
|
||||||
|
"roughness": 0.28
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "carbon-epoxy",
|
||||||
|
"name": "IM7 Carbon-Epoxy Composite",
|
||||||
|
"description": "Ultra-light filament-wound carbon composite. Maximum mass fraction, sensitive to high heat.",
|
||||||
|
"densityFactor": 0.68,
|
||||||
|
"yieldStrengthMPa": 780,
|
||||||
|
"maxTempK": 430,
|
||||||
|
"costFactor": 1.85,
|
||||||
|
"colorHex": "#262b34",
|
||||||
|
"metalness": 0.25,
|
||||||
|
"roughness": 0.45
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "stainless-304l",
|
||||||
|
"name": "Cryo-Hardened 304L Steel",
|
||||||
|
"description": "Heavy but cheap and thermally resilient steel shell capable of surviving intense reentry and aero heating.",
|
||||||
|
"densityFactor": 1.28,
|
||||||
|
"yieldStrengthMPa": 680,
|
||||||
|
"maxTempK": 1150,
|
||||||
|
"costFactor": 0.65,
|
||||||
|
"colorHex": "#aeb8c4",
|
||||||
|
"metalness": 0.92,
|
||||||
|
"roughness": 0.18
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "inconel-718",
|
||||||
|
"name": "Inconel-718 Superalloy",
|
||||||
|
"description": "Nickel-chromium superalloy built for extreme thermal and structural loads.",
|
||||||
|
"densityFactor": 1.55,
|
||||||
|
"yieldStrengthMPa": 1030,
|
||||||
|
"maxTempK": 1450,
|
||||||
|
"costFactor": 2.4,
|
||||||
|
"colorHex": "#7d776f",
|
||||||
|
"metalness": 0.85,
|
||||||
|
"roughness": 0.32
|
||||||
|
}
|
||||||
|
]
|
||||||
474
data/missions.json
Normal file
474
data/missions.json
Normal file
|
|
@ -0,0 +1,474 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "vleo-cubesat",
|
||||||
|
"name": "VLEO Tech Demonstrator",
|
||||||
|
"description": "Deploy a university CubeSat bus into very low Earth orbit for atmospheric drag calibration.",
|
||||||
|
"requiredDv": 8400,
|
||||||
|
"payloadMass": 350,
|
||||||
|
"recommendedPayloadId": "payload-cubesat-2u",
|
||||||
|
"budget": 32000000,
|
||||||
|
"target": "vleo",
|
||||||
|
"targetName": "Very Low Earth Orbit",
|
||||||
|
"targetOrbit": { "periapsisKm": 220, "apoapsisKm": 260, "inclinationDeg": 51.6 },
|
||||||
|
"maxGLoad": 9.0,
|
||||||
|
"minFairingAltKm": 70,
|
||||||
|
"launchWindowPeriodSec": 5400,
|
||||||
|
"tier": 0,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": false,
|
||||||
|
"bonusObjectives": ["Hold apoapsis within 25 km of 260 km", "No waivers used"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "leo-cargo-small",
|
||||||
|
"name": "LEO Resupply Logistics",
|
||||||
|
"description": "Deliver pressurized cargo and calibration CubeSats to a 410 km ISS-inclination orbit.",
|
||||||
|
"requiredDv": 9300,
|
||||||
|
"payloadMass": 600,
|
||||||
|
"recommendedPayloadId": "payload-cubesat-1u",
|
||||||
|
"budget": 46000000,
|
||||||
|
"target": "leo",
|
||||||
|
"targetName": "Low Earth Orbit",
|
||||||
|
"targetOrbit": { "periapsisKm": 390, "apoapsisKm": 420, "inclinationDeg": 51.6 },
|
||||||
|
"maxGLoad": 7.5,
|
||||||
|
"minFairingAltKm": 80,
|
||||||
|
"launchWindowPeriodSec": 5400,
|
||||||
|
"tier": 0,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": false,
|
||||||
|
"bonusObjectives": ["Under 75% contract cost", "Max-Q under 38 kPa"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "sso-landsat",
|
||||||
|
"name": "SSO Multispectral Earth Survey",
|
||||||
|
"description": "Inject a Landsat-class imager into a high-inclination Sun-Synchronous Orbit.",
|
||||||
|
"requiredDv": 9650,
|
||||||
|
"payloadMass": 2700,
|
||||||
|
"recommendedPayloadId": "payload-landsat8",
|
||||||
|
"budget": 68000000,
|
||||||
|
"target": "sso",
|
||||||
|
"targetName": "Sun-Synchronous Orbit",
|
||||||
|
"targetOrbit": { "periapsisKm": 695, "apoapsisKm": 715, "inclinationDeg": 98.2 },
|
||||||
|
"maxGLoad": 7.0,
|
||||||
|
"minFairingAltKm": 85,
|
||||||
|
"launchWindowPeriodSec": 7200,
|
||||||
|
"tier": 0,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": false,
|
||||||
|
"bonusObjectives": ["Target inclination 98.2° ± 1.5°", "Zero waivers"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "sso-terra-aqua",
|
||||||
|
"name": "Earth Climate EOS-Terra Deployment",
|
||||||
|
"description": "Launch a multi-instrument climate observatory into 705 km polar orbit.",
|
||||||
|
"requiredDv": 9800,
|
||||||
|
"payloadMass": 4800,
|
||||||
|
"recommendedPayloadId": "payload-terra",
|
||||||
|
"budget": 82000000,
|
||||||
|
"target": "sso",
|
||||||
|
"targetName": "Sun-Synchronous Orbit",
|
||||||
|
"targetOrbit": { "periapsisKm": 700, "apoapsisKm": 715, "inclinationDeg": 98.2 },
|
||||||
|
"maxGLoad": 6.5,
|
||||||
|
"minFairingAltKm": 85,
|
||||||
|
"launchWindowPeriodSec": 7200,
|
||||||
|
"tier": 1,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": false,
|
||||||
|
"bonusObjectives": ["Peak load < 6.0 G", "Remaining propellant margin > 4%"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "leo-crew-taxi",
|
||||||
|
"name": "LEO Orbital Crew Rotation",
|
||||||
|
"description": "Transport astronauts to orbital station altitude. Requires LAS, ECLSS, and strict G-load limits.",
|
||||||
|
"requiredDv": 9450,
|
||||||
|
"payloadMass": 4200,
|
||||||
|
"recommendedPayloadId": "payload-esas-crew",
|
||||||
|
"budget": 115000000,
|
||||||
|
"target": "leo",
|
||||||
|
"targetName": "Low Earth Orbit (Station)",
|
||||||
|
"targetOrbit": { "periapsisKm": 400, "apoapsisKm": 420, "inclinationDeg": 51.6 },
|
||||||
|
"maxGLoad": 4.5,
|
||||||
|
"minFairingAltKm": 75,
|
||||||
|
"launchWindowPeriodSec": 5400,
|
||||||
|
"tier": 1,
|
||||||
|
"crewed": true,
|
||||||
|
"advanced": false,
|
||||||
|
"bonusObjectives": ["Peak acceleration ≤ 4.2 G", "Flight-Ready maturity"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "leo-hubble-service",
|
||||||
|
"name": "Optical Observatory Deployment",
|
||||||
|
"description": "Place a Hubble-class 2.4m telescope into 540 km orbit with ultra-low vibration tolerance.",
|
||||||
|
"requiredDv": 9700,
|
||||||
|
"payloadMass": 11110,
|
||||||
|
"recommendedPayloadId": "payload-hubble",
|
||||||
|
"budget": 135000000,
|
||||||
|
"target": "leo",
|
||||||
|
"targetName": "540 km Observatory Orbit",
|
||||||
|
"targetOrbit": { "periapsisKm": 535, "apoapsisKm": 545, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 4.8,
|
||||||
|
"minFairingAltKm": 92,
|
||||||
|
"launchWindowPeriodSec": 5400,
|
||||||
|
"tier": 1,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": false,
|
||||||
|
"bonusObjectives": ["Fairing jettison ≥ 95 km", "Max-Q ≤ 34 kPa"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "geo-tdrs-relay",
|
||||||
|
"name": "GEO Communications Relay (TDRS)",
|
||||||
|
"description": "Deliver a TDRS communications satellite to Geostationary Transfer / GEO using a restartable upper stage.",
|
||||||
|
"requiredDv": 11600,
|
||||||
|
"payloadMass": 3500,
|
||||||
|
"recommendedPayloadId": "payload-tdrs",
|
||||||
|
"budget": 145000000,
|
||||||
|
"target": "geo",
|
||||||
|
"targetName": "Geostationary Orbit",
|
||||||
|
"targetOrbit": { "periapsisKm": 35700, "apoapsisKm": 35850, "inclinationDeg": 0.5 },
|
||||||
|
"maxGLoad": 6.0,
|
||||||
|
"minFairingAltKm": 88,
|
||||||
|
"launchWindowPeriodSec": 10800,
|
||||||
|
"tier": 2,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["Restartable upper stage", "Inclination ≤ 2.0°"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "heo-chandra",
|
||||||
|
"name": "High-Earth X-Ray Observatory",
|
||||||
|
"description": "Launch a Chandra-class X-ray observatory into a highly eccentric radiation-clearing orbit.",
|
||||||
|
"requiredDv": 11900,
|
||||||
|
"payloadMass": 4800,
|
||||||
|
"recommendedPayloadId": "payload-chandra",
|
||||||
|
"budget": 165000000,
|
||||||
|
"target": "geo",
|
||||||
|
"targetName": "High Elliptical Orbit",
|
||||||
|
"targetOrbit": { "periapsisKm": 10000, "apoapsisKm": 139000, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 5.2,
|
||||||
|
"minFairingAltKm": 90,
|
||||||
|
"launchWindowPeriodSec": 14400,
|
||||||
|
"tier": 2,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["Cryo avionics shielding", "No waivers"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "l1-dscovr",
|
||||||
|
"name": "Sun-Earth L1 Weather Sentinel",
|
||||||
|
"description": "Send DSCOVR to the Sun-Earth L1 Lagrange point for real-time solar storm warning.",
|
||||||
|
"requiredDv": 12200,
|
||||||
|
"payloadMass": 600,
|
||||||
|
"recommendedPayloadId": "payload-dscovr",
|
||||||
|
"budget": 125000000,
|
||||||
|
"target": "l1",
|
||||||
|
"targetName": "Sun-Earth L1",
|
||||||
|
"targetOrbit": { "periapsisKm": 185, "apoapsisKm": 1500000, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 7.5,
|
||||||
|
"minFairingAltKm": 90,
|
||||||
|
"launchWindowPeriodSec": 14400,
|
||||||
|
"tier": 2,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["Launch within optimal window", "Cost < $90M"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "lunar-orbiter-lro",
|
||||||
|
"name": "Lunar Reconnaissance Survey",
|
||||||
|
"description": "Execute trans-lunar injection for an LRO polar mapping spacecraft.",
|
||||||
|
"requiredDv": 12650,
|
||||||
|
"payloadMass": 1200,
|
||||||
|
"recommendedPayloadId": "payload-lro",
|
||||||
|
"budget": 170000000,
|
||||||
|
"target": "lunar",
|
||||||
|
"targetName": "Lunar Polar Orbit",
|
||||||
|
"targetOrbit": { "periapsisKm": 185, "apoapsisKm": 384400, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 6.8,
|
||||||
|
"minFairingAltKm": 90,
|
||||||
|
"launchWindowPeriodSec": 18000,
|
||||||
|
"tier": 2,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["Optimal TLI launch window", "Restartable upper stage"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "l2-jwst-observatory",
|
||||||
|
"name": "L2 Deep-Field Infrared Telescope",
|
||||||
|
"description": "Precision injection for a wide-fairing JWST infrared observatory with ultra-strict G-load and acoustic limits.",
|
||||||
|
"requiredDv": 12750,
|
||||||
|
"payloadMass": 6200,
|
||||||
|
"recommendedPayloadId": "payload-jwst",
|
||||||
|
"budget": 280000000,
|
||||||
|
"target": "l1",
|
||||||
|
"targetName": "Sun-Earth L2 Halo",
|
||||||
|
"targetOrbit": { "periapsisKm": 200, "apoapsisKm": 1500000, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 4.2,
|
||||||
|
"minFairingAltKm": 100,
|
||||||
|
"launchWindowPeriodSec": 18000,
|
||||||
|
"tier": 3,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["Peak G ≤ 4.0 G", "Fairing ≥ 105 km", "Zero waivers"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "lunar-gateway-core",
|
||||||
|
"name": "Cislunar Gateway Core Assembly",
|
||||||
|
"description": "Heavy-lift delivery of the Gateway Core power and habitation module to cislunar NRHO.",
|
||||||
|
"requiredDv": 13100,
|
||||||
|
"payloadMass": 12500,
|
||||||
|
"recommendedPayloadId": "payload-gateway",
|
||||||
|
"budget": 320000000,
|
||||||
|
"target": "lunar",
|
||||||
|
"targetName": "Lunar NRHO",
|
||||||
|
"targetOrbit": { "periapsisKm": 200, "apoapsisKm": 384400, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 5.0,
|
||||||
|
"minFairingAltKm": 95,
|
||||||
|
"launchWindowPeriodSec": 18000,
|
||||||
|
"tier": 3,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["3-stage heavy stack", "Cost underrun ≥ 15%"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "moon-landing-crew",
|
||||||
|
"name": "Artemis-Class Crewed Lunar Landing",
|
||||||
|
"description": "Carry astronauts and a lunar lander on a complete trans-lunar profile. Zero room for error.",
|
||||||
|
"requiredDv": 14600,
|
||||||
|
"payloadMass": 15100,
|
||||||
|
"recommendedPayloadId": "payload-apollo-lm",
|
||||||
|
"budget": 460000000,
|
||||||
|
"target": "moon-landing",
|
||||||
|
"targetName": "Lunar Surface",
|
||||||
|
"targetOrbit": { "periapsisKm": 185, "apoapsisKm": 384400, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 4.5,
|
||||||
|
"minFairingAltKm": 95,
|
||||||
|
"launchWindowPeriodSec": 21600,
|
||||||
|
"tier": 3,
|
||||||
|
"crewed": true,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["LAS + Full ECLSS active", "Zero waivers", "Optimal launch window"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "mars-orbiter-mro",
|
||||||
|
"name": "Mars Reconnaissance Orbiter",
|
||||||
|
"description": "Interplanetary Hohmann transfer injecting an MRO mapping satellite into Mars orbit.",
|
||||||
|
"requiredDv": 13400,
|
||||||
|
"payloadMass": 2180,
|
||||||
|
"recommendedPayloadId": "payload-mro",
|
||||||
|
"budget": 260000000,
|
||||||
|
"target": "mars",
|
||||||
|
"targetName": "Mars Orbit",
|
||||||
|
"targetOrbit": { "periapsisKm": 250, "apoapsisKm": 54600000, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 6.5,
|
||||||
|
"minFairingAltKm": 90,
|
||||||
|
"launchWindowPeriodSec": 28800,
|
||||||
|
"tier": 2,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["Optimal Mars synodic window", "High-Isp upper stage"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "mars-rover-perseverance",
|
||||||
|
"name": "Mars 2020 Rover Aeroshell",
|
||||||
|
"description": "Direct interplanetary injection for a nuclear-powered Martian rover & skycrane.",
|
||||||
|
"requiredDv": 13850,
|
||||||
|
"payloadMass": 3850,
|
||||||
|
"recommendedPayloadId": "payload-perseverance",
|
||||||
|
"budget": 350000000,
|
||||||
|
"target": "mars",
|
||||||
|
"targetName": "Mars Surface (Jezero)",
|
||||||
|
"targetOrbit": { "periapsisKm": 200, "apoapsisKm": 54600000, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 6.5,
|
||||||
|
"minFairingAltKm": 95,
|
||||||
|
"launchWindowPeriodSec": 28800,
|
||||||
|
"tier": 3,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["Thermal shield included", "Optimal Mars launch window"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "asteroid-osiris",
|
||||||
|
"name": "Bennu (1999 RQ36) Sample Return",
|
||||||
|
"description": "Rendezvous with near-Earth asteroid 1999 RQ36 using an electric/hypergolic kick stage.",
|
||||||
|
"requiredDv": 13200,
|
||||||
|
"payloadMass": 2110,
|
||||||
|
"recommendedPayloadId": "payload-osiris",
|
||||||
|
"budget": 290000000,
|
||||||
|
"target": "asteroid",
|
||||||
|
"targetName": "Asteroid 1999 RQ36",
|
||||||
|
"targetOrbit": { "periapsisKm": 200, "apoapsisKm": 32000000, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 7.0,
|
||||||
|
"minFairingAltKm": 90,
|
||||||
|
"launchWindowPeriodSec": 25200,
|
||||||
|
"tier": 2,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["Xenon or Hypergolic upper kick", "No waivers"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "jupiter-juno",
|
||||||
|
"name": "Jovian Deep-Space Polar Probe",
|
||||||
|
"description": "High-C3 outer-planet trajectory sending a radiation-hardened Juno orbiter to Jupiter.",
|
||||||
|
"requiredDv": 15200,
|
||||||
|
"payloadMass": 3625,
|
||||||
|
"recommendedPayloadId": "payload-juno",
|
||||||
|
"budget": 440000000,
|
||||||
|
"target": "jupiter",
|
||||||
|
"targetName": "Jupiter Polar Orbit",
|
||||||
|
"targetOrbit": { "periapsisKm": 200, "apoapsisKm": 628000000, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 6.5,
|
||||||
|
"minFairingAltKm": 95,
|
||||||
|
"launchWindowPeriodSec": 36000,
|
||||||
|
"tier": 3,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["Optimal Jupiter window", "Zero waivers"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "solar-parker-probe",
|
||||||
|
"name": "Solar Corona Close Approach",
|
||||||
|
"description": "Extreme C3 retrograde trajectory dropping Parker Solar Probe deep into the solar corona.",
|
||||||
|
"requiredDv": 15800,
|
||||||
|
"payloadMass": 685,
|
||||||
|
"recommendedPayloadId": "payload-parker",
|
||||||
|
"budget": 490000000,
|
||||||
|
"target": "solar",
|
||||||
|
"targetName": "Solar Corona",
|
||||||
|
"targetOrbit": { "periapsisKm": 200, "apoapsisKm": 140000000, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 8.5,
|
||||||
|
"minFairingAltKm": 95,
|
||||||
|
"launchWindowPeriodSec": 36000,
|
||||||
|
"tier": 3,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"bonusObjectives": ["Inconel/Heatshield thermal protection", "High-Isp upper stage"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conv-molniya-sigint-constellation",
|
||||||
|
"name": "High-Eccentricity Tundra/Molniya Comms Relay",
|
||||||
|
"description": "Insert a heavy polar relay into a 63.4° elliptical Molniya orbit crossing the Van Allen radiation belts with continuous ground link and Stage 1 recovery.",
|
||||||
|
"requiredDv": 12300,
|
||||||
|
"payloadMass": 3600,
|
||||||
|
"recommendedPayloadId": "payload-tdrs",
|
||||||
|
"budget": 185000000,
|
||||||
|
"target": "geo",
|
||||||
|
"targetName": "Molniya High-Eccentricity",
|
||||||
|
"targetOrbit": { "periapsisKm": 600, "apoapsisKm": 39800, "inclinationDeg": 63.4 },
|
||||||
|
"maxGLoad": 6.5,
|
||||||
|
"minFairingAltKm": 95,
|
||||||
|
"launchWindowPeriodSec": 1200,
|
||||||
|
"tier": 2,
|
||||||
|
"crewed": false,
|
||||||
|
"isReusable": true,
|
||||||
|
"advanced": true,
|
||||||
|
"isConvoluted": true,
|
||||||
|
"minSignalHealthPct": 82,
|
||||||
|
"minPowerMarginPct": 20,
|
||||||
|
"minEfficiencyScore": 65,
|
||||||
|
"requiredGroundNetwork": "global-dsn",
|
||||||
|
"eclipseFraction": 0.25,
|
||||||
|
"radiationHazard": "moderate",
|
||||||
|
"requiredInstrumentsMin": 2,
|
||||||
|
"multiLegWaypoints": ["High-Inc Parking (63.4°)", "Van Allen Radiation Transit", "Apogee Perigee Kick", "Booster Return Burn"],
|
||||||
|
"bonusObjectives": [
|
||||||
|
"Maintain >= 82% Ground Control Signal Health",
|
||||||
|
"Reusable Stage 1 recovery kit",
|
||||||
|
"Carry >= 2 instruments at >= 65 Efficiency Score"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conv-venus-aerobot-sample",
|
||||||
|
"name": "Venus Cloud-Deck Aerobot & Polar Relay",
|
||||||
|
"description": "Deploy an aerobrake descent bus and high-rate polar atmospheric relay around Venus through heavy thermal eclipse and radiation belts.",
|
||||||
|
"requiredDv": 13200,
|
||||||
|
"payloadMass": 3850,
|
||||||
|
"recommendedPayloadId": "payload-perseverance",
|
||||||
|
"budget": 235000000,
|
||||||
|
"target": "solar",
|
||||||
|
"targetName": "Venus Polar / Cloud Deck",
|
||||||
|
"targetOrbit": { "periapsisKm": 250, "apoapsisKm": 42000000, "inclinationDeg": 88.5 },
|
||||||
|
"maxGLoad": 7.5,
|
||||||
|
"minFairingAltKm": 95,
|
||||||
|
"launchWindowPeriodSec": 2100,
|
||||||
|
"tier": 3,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"isConvoluted": true,
|
||||||
|
"minSignalHealthPct": 78,
|
||||||
|
"minPowerMarginPct": 22,
|
||||||
|
"minEfficiencyScore": 65,
|
||||||
|
"requiredGroundNetwork": "global-dsn",
|
||||||
|
"eclipseFraction": 0.30,
|
||||||
|
"radiationHazard": "moderate",
|
||||||
|
"requiredInstrumentsMin": 2,
|
||||||
|
"multiLegWaypoints": ["LEO Parking (190 km)", "Heliocentric Inbound Transfer", "Venus Aero-Braking Pass", "Cloud-Deck Relay Lock"],
|
||||||
|
"bonusObjectives": [
|
||||||
|
"Deploy 2+ scientific instruments",
|
||||||
|
"Maintain >= 78% DSN Signal Health",
|
||||||
|
"Achieve >= 22% EOL Power Margin"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conv-lunar-south-pole-comms-hab",
|
||||||
|
"name": "Artemis Shackleton Rim Crewed Hab & Relay",
|
||||||
|
"description": "Deliver a 4-person polar habitat & optical comms relay to Lunar South Pole NRHO under tight crew G-load, eclipse shadow, and telemetry guarantees.",
|
||||||
|
"requiredDv": 14500,
|
||||||
|
"payloadMass": 12500,
|
||||||
|
"recommendedPayloadId": "payload-gateway",
|
||||||
|
"budget": 315000000,
|
||||||
|
"target": "moon-landing",
|
||||||
|
"targetName": "Lunar South Pole (Shackleton)",
|
||||||
|
"targetOrbit": { "periapsisKm": 100, "apoapsisKm": 384400, "inclinationDeg": 89.2 },
|
||||||
|
"maxGLoad": 4.2,
|
||||||
|
"minFairingAltKm": 85,
|
||||||
|
"launchWindowPeriodSec": 1800,
|
||||||
|
"tier": 3,
|
||||||
|
"crewed": true,
|
||||||
|
"crewCap": 4,
|
||||||
|
"advanced": true,
|
||||||
|
"isConvoluted": true,
|
||||||
|
"minSignalHealthPct": 85,
|
||||||
|
"minPowerMarginPct": 25,
|
||||||
|
"minEfficiencyScore": 62,
|
||||||
|
"requiredGroundNetwork": "global-dsn",
|
||||||
|
"eclipseFraction": 0.35,
|
||||||
|
"radiationHazard": "moderate",
|
||||||
|
"requiredInstrumentsMin": 2,
|
||||||
|
"multiLegWaypoints": ["LEO Parking (195 km)", "Trans-Lunar Injection", "NRHO Polar Capture", "Shackleton Powered Descent"],
|
||||||
|
"bonusObjectives": [
|
||||||
|
"Peak crew G-load <= 4.2 G",
|
||||||
|
"Maintain >= 85% Ground Link across Lunar South Pole",
|
||||||
|
"Survive 35% eclipse shadow with >= 25% power margin"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "conv-europa-clipper-recon",
|
||||||
|
"name": "Europa Clipper Multi-Flyby & Ice-Radar Flagship",
|
||||||
|
"description": "Ultra-high-C3 outer-planet flagship enduring extreme Jovian radiation and 5.2 AU sunlight drop while streaming synthetic-aperture ice-radar data over optical DSN.",
|
||||||
|
"requiredDv": 15400,
|
||||||
|
"payloadMass": 4200,
|
||||||
|
"recommendedPayloadId": "payload-juno",
|
||||||
|
"budget": 345000000,
|
||||||
|
"target": "jupiter",
|
||||||
|
"targetName": "Jovian / Europa Ice Torus",
|
||||||
|
"targetOrbit": { "periapsisKm": 300, "apoapsisKm": 628000000, "inclinationDeg": 28.5 },
|
||||||
|
"maxGLoad": 7.5,
|
||||||
|
"minFairingAltKm": 100,
|
||||||
|
"launchWindowPeriodSec": 2800,
|
||||||
|
"tier": 3,
|
||||||
|
"crewed": false,
|
||||||
|
"advanced": true,
|
||||||
|
"isConvoluted": true,
|
||||||
|
"minSignalHealthPct": 75,
|
||||||
|
"minPowerMarginPct": 20,
|
||||||
|
"minEfficiencyScore": 65,
|
||||||
|
"requiredGroundNetwork": "optical-deep-space",
|
||||||
|
"eclipseFraction": 0.25,
|
||||||
|
"radiationHazard": "extreme",
|
||||||
|
"requiredInstrumentsMin": 3,
|
||||||
|
"multiLegWaypoints": ["LEO Parking (200 km)", "Jovian C3 Escape Burn", "Jovian Magnetosphere Transit", "Europa 25 km Ice-Radar Flyby"],
|
||||||
|
"bonusObjectives": [
|
||||||
|
"Equip RTG or Fission power for 5.2 AU Jovian flux",
|
||||||
|
"Use Optical Deep Space Network + Ka-Band (>=75% signal)",
|
||||||
|
"Carry 3+ science instruments at >= 65 Efficiency Score"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
73
data/ml_policy_weights.json
Normal file
73
data/ml_policy_weights.json
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"episodes": 25,
|
||||||
|
"avgReward": 0.8404,
|
||||||
|
"sharedWeights": [
|
||||||
|
0.36027,
|
||||||
|
1.37763,
|
||||||
|
1.56151,
|
||||||
|
0.32181,
|
||||||
|
0.6428,
|
||||||
|
-0.43268,
|
||||||
|
-0.33653,
|
||||||
|
-0.24038,
|
||||||
|
-0.33653,
|
||||||
|
0.65789
|
||||||
|
],
|
||||||
|
"hiddenBias": [
|
||||||
|
0.1,
|
||||||
|
-0.05,
|
||||||
|
0.15,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"agencies": {
|
||||||
|
"DeepOrbit RL": {
|
||||||
|
"weights": [
|
||||||
|
0.28952,
|
||||||
|
1.33298,
|
||||||
|
1.34644,
|
||||||
|
0.23897,
|
||||||
|
0.6728,
|
||||||
|
-0.43015,
|
||||||
|
-0.33456,
|
||||||
|
-0.23897,
|
||||||
|
-0.33456,
|
||||||
|
0.60932
|
||||||
|
],
|
||||||
|
"episodes": 9,
|
||||||
|
"avgReward": 0.8191
|
||||||
|
},
|
||||||
|
"Perceptron Aerospace": {
|
||||||
|
"weights": [
|
||||||
|
0.54546,
|
||||||
|
1.40555,
|
||||||
|
2.09993,
|
||||||
|
0.3922,
|
||||||
|
0.63745,
|
||||||
|
-0.41723,
|
||||||
|
-0.32452,
|
||||||
|
-0.23181,
|
||||||
|
-0.32452,
|
||||||
|
0.78385
|
||||||
|
],
|
||||||
|
"episodes": 15,
|
||||||
|
"avgReward": 0.9581
|
||||||
|
},
|
||||||
|
"AlphaThrust Neural": {
|
||||||
|
"weights": [
|
||||||
|
0.17186,
|
||||||
|
1.38076,
|
||||||
|
1.01144,
|
||||||
|
0.24794,
|
||||||
|
0.64614,
|
||||||
|
-0.44631,
|
||||||
|
-0.34713,
|
||||||
|
-0.24794,
|
||||||
|
-0.34713,
|
||||||
|
0.5202
|
||||||
|
],
|
||||||
|
"episodes": 1,
|
||||||
|
"avgReward": -0.735
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
data/models_index.json
Normal file
36
data/models_index.json
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
{
|
||||||
|
"note": "Curated index of NASA 3D GLB models under /models/nasa_3d_glb/ plus /models/cat_3d_model_free.glb.",
|
||||||
|
"models": [
|
||||||
|
{ "file": "nasa_3d_glb/Mobile Launcher (assembled).glb", "name": "Mobile Launcher", "category": "ground" },
|
||||||
|
{ "file": "nasa_3d_glb/Gantry.glb", "name": "Launch Gantry", "category": "ground" },
|
||||||
|
{ "file": "nasa_3d_glb/Vehicle Assembly Building (VAB).glb", "name": "VAB", "category": "ground" },
|
||||||
|
{ "file": "nasa_3d_glb/Saturn V.glb", "name": "Saturn V", "category": "rocket" },
|
||||||
|
{ "file": "nasa_3d_glb/External tank.glb", "name": "Cryogenic Tank", "category": "tank" },
|
||||||
|
{ "file": "nasa_3d_glb/Solid Rocket Booster.glb", "name": "Solid Booster", "category": "engine" },
|
||||||
|
{ "file": "nasa_3d_glb/Space Shuttle (D) eng.glb", "name": "RS-25 Engine", "category": "engine" },
|
||||||
|
{ "file": "nasa_3d_glb/International Space Station (ISS) (A).glb", "name": "ISS", "category": "station" },
|
||||||
|
{ "file": "nasa_3d_glb/Gateway Core.glb", "name": "Gateway Core", "category": "station" },
|
||||||
|
{ "file": "nasa_3d_glb/Hubble Space Telescope (A).glb", "name": "Hubble", "category": "telescope" },
|
||||||
|
{ "file": "nasa_3d_glb/James Webb Space Telescope (A).glb", "name": "JWST", "category": "telescope" },
|
||||||
|
{ "file": "nasa_3d_glb/Nancy Grace Roman Space Telescope (A).glb", "name": "Roman Telescope", "category": "telescope" },
|
||||||
|
{ "file": "nasa_3d_glb/Chandra X-ray Observatory.glb", "name": "Chandra", "category": "telescope" },
|
||||||
|
{ "file": "nasa_3d_glb/Terra.glb", "name": "Terra", "category": "earth-observer" },
|
||||||
|
{ "file": "nasa_3d_glb/Aqua (A).glb", "name": "Aqua", "category": "earth-observer" },
|
||||||
|
{ "file": "nasa_3d_glb/Landsat 8.glb", "name": "Landsat 8", "category": "earth-observer" },
|
||||||
|
{ "file": "nasa_3d_glb/Deep Space Climate Observatory (DSCOVR) (Triana).glb", "name": "DSCOVR", "category": "space-weather" },
|
||||||
|
{ "file": "nasa_3d_glb/Tracking and Data Relay Satellites (TDRS) (A).glb", "name": "TDRS", "category": "relay" },
|
||||||
|
{ "file": "nasa_3d_glb/Lunar Reconnaissance Orbiter (A).glb", "name": "LRO", "category": "lunar-orbiter" },
|
||||||
|
{ "file": "nasa_3d_glb/Apollo Lunar Module.glb", "name": "Apollo Lunar Module", "category": "lander" },
|
||||||
|
{ "file": "nasa_3d_glb/ESAS Crew Module.glb", "name": "ESAS Crew Module", "category": "crew" },
|
||||||
|
{ "file": "nasa_3d_glb/Mars Reconnaissance Orbiter (MRO) (A).glb", "name": "MRO", "category": "mars-orbiter" },
|
||||||
|
{ "file": "nasa_3d_glb/Mars 2020 Perseverance Rover.glb", "name": "Perseverance Rover", "category": "mars-lander" },
|
||||||
|
{ "file": "nasa_3d_glb/Viking Lander.glb", "name": "Viking Lander", "category": "mars-lander" },
|
||||||
|
{ "file": "nasa_3d_glb/Voyager Probe (A).glb", "name": "Voyager", "category": "probe" },
|
||||||
|
{ "file": "nasa_3d_glb/Juno (A).glb", "name": "Juno", "category": "probe" },
|
||||||
|
{ "file": "nasa_3d_glb/Cassini-Huygens (A).glb", "name": "Cassini", "category": "probe" },
|
||||||
|
{ "file": "nasa_3d_glb/Parker Solar Probe.glb", "name": "Parker Solar Probe", "category": "probe" },
|
||||||
|
{ "file": "nasa_3d_glb/OSIRIS-REx.glb", "name": "OSIRIS-REx", "category": "probe" },
|
||||||
|
{ "file": "nasa_3d_glb/1999 RQ36 asteroid.glb", "name": "Asteroid Bennu (1999 RQ36)", "category": "body" },
|
||||||
|
{ "file": "cat_3d_model_free.glb", "name": "Pad Mascot Placeholder", "category": "placeholder" }
|
||||||
|
]
|
||||||
|
}
|
||||||
841
data/parts.json
Normal file
841
data/parts.json
Normal file
|
|
@ -0,0 +1,841 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "eng-merlin-1d",
|
||||||
|
"kind": "engine",
|
||||||
|
"name": "Kerolox Booster Engine (Merlin-1D Class)",
|
||||||
|
"description": "High-TWR RP-1/LOX gas-generator sea-level engine. Ideal for clustered first stages.",
|
||||||
|
"propellantType": "kerolox",
|
||||||
|
"dryMass": 470,
|
||||||
|
"thrust": 845000,
|
||||||
|
"isp": 282,
|
||||||
|
"ispVac": 311,
|
||||||
|
"restartable": true,
|
||||||
|
"gimbalDeg": 5,
|
||||||
|
"diameter": 1.1,
|
||||||
|
"length": 2.4,
|
||||||
|
"cost": 1100000,
|
||||||
|
"maxQ": 58000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "eng-merlin-vac",
|
||||||
|
"kind": "engine",
|
||||||
|
"name": "Kerolox Vacuum Engine (MVac Class)",
|
||||||
|
"description": "Large radiatively cooled niobium bell for RP-1/LOX upper stages.",
|
||||||
|
"propellantType": "kerolox",
|
||||||
|
"dryMass": 560,
|
||||||
|
"thrust": 981000,
|
||||||
|
"isp": 210,
|
||||||
|
"ispVac": 348,
|
||||||
|
"restartable": true,
|
||||||
|
"gimbalDeg": 4,
|
||||||
|
"diameter": 2.6,
|
||||||
|
"length": 3.4,
|
||||||
|
"cost": 1600000,
|
||||||
|
"maxQ": 42000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "eng-raptor-sl",
|
||||||
|
"kind": "engine",
|
||||||
|
"name": "Methalox FFSC Engine (Raptor Class)",
|
||||||
|
"description": "Full-flow staged combustion methane/LOX engine combining high chamber pressure and clean throttling.",
|
||||||
|
"propellantType": "methalox",
|
||||||
|
"dryMass": 1525,
|
||||||
|
"thrust": 2250000,
|
||||||
|
"isp": 327,
|
||||||
|
"ispVac": 355,
|
||||||
|
"restartable": true,
|
||||||
|
"gimbalDeg": 8,
|
||||||
|
"diameter": 1.3,
|
||||||
|
"length": 3.1,
|
||||||
|
"cost": 2600000,
|
||||||
|
"maxQ": 65000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "eng-rs25",
|
||||||
|
"kind": "engine",
|
||||||
|
"name": "Hydrolox Staged Engine (RS-25 Class)",
|
||||||
|
"description": "Cryogenic LH2/LOX engine derived from Shuttle heritage. High efficiency and deep throttle.",
|
||||||
|
"propellantType": "hydrolox",
|
||||||
|
"dryMass": 3528,
|
||||||
|
"thrust": 2279000,
|
||||||
|
"isp": 366,
|
||||||
|
"ispVac": 452,
|
||||||
|
"restartable": false,
|
||||||
|
"gimbalDeg": 10,
|
||||||
|
"diameter": 2.4,
|
||||||
|
"length": 4.3,
|
||||||
|
"cost": 8500000,
|
||||||
|
"maxQ": 62000,
|
||||||
|
"modelFile": "nasa_3d_glb/Space Shuttle (D) eng.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "eng-rl10",
|
||||||
|
"kind": "engine",
|
||||||
|
"name": "Cryo Upper Engine (RL-10C Class)",
|
||||||
|
"description": "Restartable expander-cycle hydrolox vacuum engine for precision orbital insertion and TLI.",
|
||||||
|
"propellantType": "hydrolox",
|
||||||
|
"dryMass": 301,
|
||||||
|
"thrust": 110000,
|
||||||
|
"isp": 260,
|
||||||
|
"ispVac": 454,
|
||||||
|
"restartable": true,
|
||||||
|
"gimbalDeg": 4,
|
||||||
|
"diameter": 1.8,
|
||||||
|
"length": 2.3,
|
||||||
|
"cost": 3200000,
|
||||||
|
"maxQ": 38000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "eng-solid-srb",
|
||||||
|
"kind": "engine",
|
||||||
|
"name": "Segmented Solid Booster (SRB Class)",
|
||||||
|
"description": "Massive solid rocket booster delivering extreme liftoff thrust at low Isp. Cannot throttle or restart.",
|
||||||
|
"propellantType": "solid",
|
||||||
|
"dryMass": 14000,
|
||||||
|
"thrust": 12500000,
|
||||||
|
"isp": 242,
|
||||||
|
"ispVac": 269,
|
||||||
|
"restartable": false,
|
||||||
|
"gimbalDeg": 3,
|
||||||
|
"diameter": 3.7,
|
||||||
|
"length": 14.0,
|
||||||
|
"cost": 16000000,
|
||||||
|
"maxQ": 72000,
|
||||||
|
"modelFile": "nasa_3d_glb/Solid Rocket Booster.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "eng-aj10-hyper",
|
||||||
|
"kind": "engine",
|
||||||
|
"name": "Hypergolic Orbital Thruster (AJ10 Class)",
|
||||||
|
"description": "Storable NTO/MMH pressure-fed engine with ultra-reliable deep-space multi-restart capability.",
|
||||||
|
"propellantType": "hypergolic",
|
||||||
|
"dryMass": 120,
|
||||||
|
"thrust": 43600,
|
||||||
|
"isp": 210,
|
||||||
|
"ispVac": 319,
|
||||||
|
"restartable": true,
|
||||||
|
"gimbalDeg": 6,
|
||||||
|
"diameter": 1.2,
|
||||||
|
"length": 1.9,
|
||||||
|
"cost": 1400000,
|
||||||
|
"maxQ": 48000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "eng-ion-hall",
|
||||||
|
"kind": "engine",
|
||||||
|
"name": "Xenon Hall Effect Thruster (NEXT-C Class)",
|
||||||
|
"description": "Solar-electric xenon propulsion with extreme Isp for long-duration deep space transfers.",
|
||||||
|
"propellantType": "xenon",
|
||||||
|
"dryMass": 68,
|
||||||
|
"thrust": 8500,
|
||||||
|
"isp": 1200,
|
||||||
|
"ispVac": 3200,
|
||||||
|
"restartable": true,
|
||||||
|
"gimbalDeg": 2,
|
||||||
|
"diameter": 0.9,
|
||||||
|
"length": 1.0,
|
||||||
|
"cost": 4800000,
|
||||||
|
"maxQ": 35000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "eng-j2x",
|
||||||
|
"kind": "engine",
|
||||||
|
"name": "Hydrolox Upper Engine (J-2X Class)",
|
||||||
|
"description": "High-thrust restartable cryogenic LH2/LOX upper-stage engine built for heavy cislunar injection and Earth departure stages.",
|
||||||
|
"propellantType": "hydrolox",
|
||||||
|
"dryMass": 2470,
|
||||||
|
"thrust": 1310000,
|
||||||
|
"isp": 300,
|
||||||
|
"ispVac": 448,
|
||||||
|
"restartable": true,
|
||||||
|
"gimbalDeg": 6,
|
||||||
|
"diameter": 3.0,
|
||||||
|
"length": 4.7,
|
||||||
|
"cost": 5400000,
|
||||||
|
"maxQ": 48000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "eng-raptor-vac",
|
||||||
|
"kind": "engine",
|
||||||
|
"name": "Methalox Vacuum Engine (RVac Class)",
|
||||||
|
"description": "Full-flow staged-combustion methalox vacuum engine with a large radiation-cooled nozzle extension for super-heavy orbital transfer.",
|
||||||
|
"propellantType": "methalox",
|
||||||
|
"dryMass": 1750,
|
||||||
|
"thrust": 2550000,
|
||||||
|
"isp": 240,
|
||||||
|
"ispVac": 380,
|
||||||
|
"restartable": true,
|
||||||
|
"gimbalDeg": 5,
|
||||||
|
"diameter": 2.4,
|
||||||
|
"length": 4.2,
|
||||||
|
"cost": 3400000,
|
||||||
|
"maxQ": 45000
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": "tank-small-kero",
|
||||||
|
"kind": "tank",
|
||||||
|
"name": "Light RP-1/LOX Tank",
|
||||||
|
"description": "Compact kerolox tank suited for upper stages or small launchers.",
|
||||||
|
"propellantType": "kerolox",
|
||||||
|
"dryMass": 1450,
|
||||||
|
"propellantMass": 28000,
|
||||||
|
"diameter": 2.4,
|
||||||
|
"length": 7.5,
|
||||||
|
"cost": 2200000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tank-med-kero",
|
||||||
|
"kind": "tank",
|
||||||
|
"name": "Medium RP-1/LOX Tank",
|
||||||
|
"description": "3.7 m workhorse kerolox propellant stage tank.",
|
||||||
|
"propellantType": "kerolox",
|
||||||
|
"dryMass": 8500,
|
||||||
|
"propellantMass": 195000,
|
||||||
|
"diameter": 3.7,
|
||||||
|
"length": 22.0,
|
||||||
|
"cost": 9500000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tank-large-kero",
|
||||||
|
"kind": "tank",
|
||||||
|
"name": "Heavy RP-1/LOX Booster Tank",
|
||||||
|
"description": "5.2 m heavy-lift kerolox core tank.",
|
||||||
|
"propellantType": "kerolox",
|
||||||
|
"dryMass": 19000,
|
||||||
|
"propellantMass": 460000,
|
||||||
|
"diameter": 5.2,
|
||||||
|
"length": 34.0,
|
||||||
|
"cost": 21000000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tank-med-hydro",
|
||||||
|
"kind": "tank",
|
||||||
|
"name": "Centaur-Class LH2/LOX Tank",
|
||||||
|
"description": "Insulated cryogenic hydrogen upper-stage tank with low structural dry mass.",
|
||||||
|
"propellantType": "hydrolox",
|
||||||
|
"dryMass": 2400,
|
||||||
|
"propellantMass": 48000,
|
||||||
|
"diameter": 3.7,
|
||||||
|
"length": 12.5,
|
||||||
|
"cost": 6800000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tank-large-hydro",
|
||||||
|
"kind": "tank",
|
||||||
|
"name": "Heavy Cryo Core Tank (SLS-Class)",
|
||||||
|
"description": "Foam-insulated 8.4 m cryogenic LH2/LOX core tank.",
|
||||||
|
"propellantType": "hydrolox",
|
||||||
|
"dryMass": 38000,
|
||||||
|
"propellantMass": 730000,
|
||||||
|
"diameter": 8.4,
|
||||||
|
"length": 44.0,
|
||||||
|
"cost": 36000000,
|
||||||
|
"modelFile": "nasa_3d_glb/External tank.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tank-med-metha",
|
||||||
|
"kind": "tank",
|
||||||
|
"name": "Medium CH4/LOX Tank",
|
||||||
|
"description": "Balanced subcooled methalox tank for reusable or heavy orbital stages.",
|
||||||
|
"propellantType": "methalox",
|
||||||
|
"dryMass": 9200,
|
||||||
|
"propellantMass": 220000,
|
||||||
|
"diameter": 4.5,
|
||||||
|
"length": 24.0,
|
||||||
|
"cost": 11500000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tank-large-metha",
|
||||||
|
"kind": "tank",
|
||||||
|
"name": "Super-Heavy CH4/LOX Tank",
|
||||||
|
"description": "9.0 m methalox super-heavy booster tank.",
|
||||||
|
"propellantType": "methalox",
|
||||||
|
"dryMass": 36000,
|
||||||
|
"propellantMass": 980000,
|
||||||
|
"diameter": 9.0,
|
||||||
|
"length": 46.0,
|
||||||
|
"cost": 29000000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tank-hypergolic",
|
||||||
|
"kind": "tank",
|
||||||
|
"name": "Storable Service Propellant Tank",
|
||||||
|
"description": "Titanium-lined NTO/MMH tank for orbital maneuvering and transfer stages.",
|
||||||
|
"propellantType": "hypergolic",
|
||||||
|
"dryMass": 620,
|
||||||
|
"propellantMass": 9200,
|
||||||
|
"diameter": 2.4,
|
||||||
|
"length": 4.2,
|
||||||
|
"cost": 2800000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tank-xenon",
|
||||||
|
"kind": "tank",
|
||||||
|
"name": "High-Pressure Xenon Tank",
|
||||||
|
"description": "Composite overwrapped xenon reservoir for electric propulsion stages.",
|
||||||
|
"propellantType": "xenon",
|
||||||
|
"dryMass": 140,
|
||||||
|
"propellantMass": 1200,
|
||||||
|
"diameter": 1.8,
|
||||||
|
"length": 2.0,
|
||||||
|
"cost": 3100000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tank-srb-casing",
|
||||||
|
"kind": "tank",
|
||||||
|
"name": "PBAN Solid Propellant Grain Casing",
|
||||||
|
"description": "Pre-cast solid composite propellant grain segments.",
|
||||||
|
"propellantType": "solid",
|
||||||
|
"dryMass": 28000,
|
||||||
|
"propellantMass": 460000,
|
||||||
|
"diameter": 3.7,
|
||||||
|
"length": 31.0,
|
||||||
|
"cost": 14000000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "drop-tank-kero-light",
|
||||||
|
"kind": "tank",
|
||||||
|
"isDropTank": true,
|
||||||
|
"name": "Aerodynamic RP-1/LOX Drop Tank (1.5m)",
|
||||||
|
"description": "Disposable conformal side fuel pod with streamlined ogive cap. Crossfeeds into stage engines first and jettisons when dry.",
|
||||||
|
"propellantType": "kerolox",
|
||||||
|
"dryMass": 680,
|
||||||
|
"propellantMass": 18500,
|
||||||
|
"diameter": 1.5,
|
||||||
|
"length": 11.5,
|
||||||
|
"cost": 1250000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "drop-tank-kero-heavy",
|
||||||
|
"kind": "tank",
|
||||||
|
"isDropTank": true,
|
||||||
|
"name": "Conformal Heavy RP-1/LOX Drop Tank (2.4m)",
|
||||||
|
"description": "High-capacity external kerolox auxiliary tank with aero nosecone and quick-disconnect manifold.",
|
||||||
|
"propellantType": "kerolox",
|
||||||
|
"dryMass": 2900,
|
||||||
|
"propellantMass": 82000,
|
||||||
|
"diameter": 2.4,
|
||||||
|
"length": 18.0,
|
||||||
|
"cost": 4200000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "drop-tank-hypergolic",
|
||||||
|
"kind": "tank",
|
||||||
|
"isDropTank": true,
|
||||||
|
"name": "Storable External Fuel Pod (NTO/MMH)",
|
||||||
|
"description": "Compact disposable hypergolic saddle tank extending deep-space transfer stage endurance.",
|
||||||
|
"propellantType": "hypergolic",
|
||||||
|
"dryMass": 180,
|
||||||
|
"propellantMass": 3600,
|
||||||
|
"diameter": 1.0,
|
||||||
|
"length": 4.5,
|
||||||
|
"cost": 950000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "drop-tank-hydro-et",
|
||||||
|
"kind": "tank",
|
||||||
|
"isDropTank": true,
|
||||||
|
"name": "Shuttle-Class Cryo External Tank (LH2/LOX)",
|
||||||
|
"description": "Massive foam-insulated disposable belly external tank feeding stage engines before mid-ascent release.",
|
||||||
|
"propellantType": "hydrolox",
|
||||||
|
"dryMass": 14500,
|
||||||
|
"propellantMass": 340000,
|
||||||
|
"diameter": 4.2,
|
||||||
|
"length": 28.0,
|
||||||
|
"cost": 12500000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "drop-tank-metha-pair",
|
||||||
|
"kind": "tank",
|
||||||
|
"isDropTank": true,
|
||||||
|
"name": "Subcooled Methalox Drop Tank (2.2m)",
|
||||||
|
"description": "Streamlined external CH4/LOX drop tank designed for high-energy reusable/heavy boosters.",
|
||||||
|
"propellantType": "methalox",
|
||||||
|
"dryMass": 1850,
|
||||||
|
"propellantMass": 52000,
|
||||||
|
"diameter": 2.2,
|
||||||
|
"length": 15.0,
|
||||||
|
"cost": 3400000
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": "struct-frame-std",
|
||||||
|
"kind": "structure",
|
||||||
|
"name": "Standard Avionics & Thrust Ring",
|
||||||
|
"description": "Flight computer, IMU, telemetry bus, and standard thrust-transfer ring.",
|
||||||
|
"dryMass": 950,
|
||||||
|
"diameter": 3.7,
|
||||||
|
"length": 2.4,
|
||||||
|
"cost": 1800000,
|
||||||
|
"maxQ": 52000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "struct-frame-heavy",
|
||||||
|
"kind": "structure",
|
||||||
|
"name": "Heavy Orthogrid Thrust Frame",
|
||||||
|
"description": "Machined orthogrid structural bay engineered for high Max-Q and heavy upper stacks.",
|
||||||
|
"dryMass": 2600,
|
||||||
|
"diameter": 5.2,
|
||||||
|
"length": 3.2,
|
||||||
|
"cost": 4200000,
|
||||||
|
"maxQ": 78000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "struct-cryo-frame",
|
||||||
|
"kind": "structure",
|
||||||
|
"name": "Cryo-Insulated Avionics Skirt",
|
||||||
|
"description": "Thermally isolated avionics bay with MLI radiation shielding for deep space.",
|
||||||
|
"dryMass": 1400,
|
||||||
|
"diameter": 3.7,
|
||||||
|
"length": 2.6,
|
||||||
|
"cost": 3500000,
|
||||||
|
"maxQ": 62000
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": "interstage-std",
|
||||||
|
"kind": "interstage",
|
||||||
|
"name": "Pneumatic Stage Pusher Interstage",
|
||||||
|
"description": "Clean pneumatic separation ring between matched-diameter stages.",
|
||||||
|
"dryMass": 850,
|
||||||
|
"diameter": 3.7,
|
||||||
|
"length": 2.8,
|
||||||
|
"cost": 1400000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "interstage-tapered",
|
||||||
|
"kind": "interstage",
|
||||||
|
"name": "Tapered Conical Adapter",
|
||||||
|
"description": "Structural conical frustum allowing safe diameter transitions between stages.",
|
||||||
|
"dryMass": 1350,
|
||||||
|
"diameter": 5.2,
|
||||||
|
"length": 3.8,
|
||||||
|
"cost": 2200000
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": "fairing-small",
|
||||||
|
"kind": "fairing",
|
||||||
|
"name": "Compact 2.8m Composite Fairing",
|
||||||
|
"description": "Aerodynamic payload shroud for CubeSats and compact Earth observers.",
|
||||||
|
"dryMass": 480,
|
||||||
|
"diameter": 2.8,
|
||||||
|
"length": 7.5,
|
||||||
|
"maxPayloadDiameter": 2.5,
|
||||||
|
"maxPayloadLength": 6.5,
|
||||||
|
"cost": 1500000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "fairing-standard",
|
||||||
|
"kind": "fairing",
|
||||||
|
"name": "Standard 5.2m Clamshell Fairing",
|
||||||
|
"description": "Acoustic-damped clamshell fairing suited for orbital telescopes and planetary probes.",
|
||||||
|
"dryMass": 1750,
|
||||||
|
"diameter": 5.2,
|
||||||
|
"length": 15.0,
|
||||||
|
"maxPayloadDiameter": 4.7,
|
||||||
|
"maxPayloadLength": 14.0,
|
||||||
|
"cost": 4800000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "fairing-wide",
|
||||||
|
"kind": "fairing",
|
||||||
|
"name": "Super-Heavy 11.5m Hammerhead Fairing",
|
||||||
|
"description": "Massive composite fairing built for unfolded observatories and lunar landers.",
|
||||||
|
"dryMass": 4600,
|
||||||
|
"diameter": 11.5,
|
||||||
|
"length": 23.0,
|
||||||
|
"maxPayloadDiameter": 11.0,
|
||||||
|
"maxPayloadLength": 21.5,
|
||||||
|
"cost": 11000000
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": "fins-grid",
|
||||||
|
"kind": "fins",
|
||||||
|
"name": "Titanium Aero Grid Fins",
|
||||||
|
"description": "Aerodynamic stabilizers shifting CP aft for enhanced ascent stability.",
|
||||||
|
"dryMass": 650,
|
||||||
|
"diameter": 3.7,
|
||||||
|
"length": 1.6,
|
||||||
|
"cost": 900000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "heatshield-pica",
|
||||||
|
"kind": "heatshield",
|
||||||
|
"name": "PICA-X Phenolic Heatshield",
|
||||||
|
"description": "Ablative thermal protection tile shield for high-energy entry and solar storms.",
|
||||||
|
"dryMass": 920,
|
||||||
|
"diameter": 4.5,
|
||||||
|
"length": 1.2,
|
||||||
|
"cost": 2400000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "las-tower",
|
||||||
|
"kind": "las",
|
||||||
|
"name": "Launch Abort System (LAS)",
|
||||||
|
"description": "Solid puller escape tower protecting crewed capsules during pad/ascent anomalies.",
|
||||||
|
"dryMass": 2800,
|
||||||
|
"diameter": 2.2,
|
||||||
|
"length": 6.0,
|
||||||
|
"cost": 7500000
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": "comp-cots-mcu",
|
||||||
|
"kind": "computer",
|
||||||
|
"name": "GD-80 COTS Microcontroller Array",
|
||||||
|
"description": "Commercial off-the-shelf microcontroller array. Cheap and light for simple 1-2 stage boosters, but easily overloaded by large engine clusters or unshielded radiation.",
|
||||||
|
"dryMass": 45,
|
||||||
|
"diameter": 1.2,
|
||||||
|
"length": 0.45,
|
||||||
|
"cost": 380000,
|
||||||
|
"maxTempK": 390,
|
||||||
|
"maxGLoad": 10.0,
|
||||||
|
"computeCapacityIps": 85,
|
||||||
|
"radHardeningLevel": 1,
|
||||||
|
"diagnosticTier": 1,
|
||||||
|
"powerDrawKw": 0.18,
|
||||||
|
"faultScrubRate": 0.15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "comp-std-avionics",
|
||||||
|
"kind": "computer",
|
||||||
|
"name": "Vega-II Dual-String Flight Computer",
|
||||||
|
"description": "Standard aerospace dual-string flight computer with baseline watchdog protection and TVC gimbal bus.",
|
||||||
|
"dryMass": 95,
|
||||||
|
"diameter": 1.8,
|
||||||
|
"length": 0.55,
|
||||||
|
"cost": 950000,
|
||||||
|
"maxTempK": 450,
|
||||||
|
"maxGLoad": 13.0,
|
||||||
|
"computeCapacityIps": 145,
|
||||||
|
"radHardeningLevel": 2,
|
||||||
|
"diagnosticTier": 1,
|
||||||
|
"powerDrawKw": 0.32,
|
||||||
|
"faultScrubRate": 0.35
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "comp-fault-tolerant",
|
||||||
|
"kind": "computer",
|
||||||
|
"name": "RAD750 Triple-Modular Avionics",
|
||||||
|
"description": "Radiation-hardened triple-modular voting flight computer. Supports multi-engine clusters, live ECC fault scrubbing, and Tier-2 telemetry.",
|
||||||
|
"dryMass": 130,
|
||||||
|
"diameter": 2.2,
|
||||||
|
"length": 0.65,
|
||||||
|
"cost": 2400000,
|
||||||
|
"maxTempK": 520,
|
||||||
|
"maxGLoad": 16.0,
|
||||||
|
"computeCapacityIps": 240,
|
||||||
|
"radHardeningLevel": 3,
|
||||||
|
"diagnosticTier": 2,
|
||||||
|
"powerDrawKw": 0.48,
|
||||||
|
"faultScrubRate": 0.65,
|
||||||
|
"techNode": "avionics-diagnostics-2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "comp-rad-quad",
|
||||||
|
"kind": "computer",
|
||||||
|
"name": "Aegis-IV Quad-Redundant Rad-Hard Computer",
|
||||||
|
"description": "Deep-space quad-redundant avionics vault with full Van Allen / SAA radiation shielding and GMAT closed-loop guidance.",
|
||||||
|
"dryMass": 185,
|
||||||
|
"diameter": 2.6,
|
||||||
|
"length": 0.75,
|
||||||
|
"cost": 4800000,
|
||||||
|
"maxTempK": 620,
|
||||||
|
"maxGLoad": 20.0,
|
||||||
|
"computeCapacityIps": 360,
|
||||||
|
"radHardeningLevel": 4,
|
||||||
|
"diagnosticTier": 3,
|
||||||
|
"powerDrawKw": 0.65,
|
||||||
|
"faultScrubRate": 0.90,
|
||||||
|
"techNode": "gmat-orbital-diagnostics-3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "comp-quantum-nav",
|
||||||
|
"kind": "computer",
|
||||||
|
"name": "Chronos-X Optical/Neural Guidance Core",
|
||||||
|
"description": "Next-generation optical star-tracker and neural flight computer capable of running 3-stage super-heavy clusters and full science payloads simultaneously.",
|
||||||
|
"dryMass": 140,
|
||||||
|
"diameter": 2.4,
|
||||||
|
"length": 0.60,
|
||||||
|
"cost": 6500000,
|
||||||
|
"maxTempK": 580,
|
||||||
|
"maxGLoad": 18.0,
|
||||||
|
"computeCapacityIps": 480,
|
||||||
|
"radHardeningLevel": 4,
|
||||||
|
"diagnosticTier": 3,
|
||||||
|
"powerDrawKw": 0.85,
|
||||||
|
"faultScrubRate": 0.94,
|
||||||
|
"techNode": "gmat-orbital-diagnostics-3"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": "payload-cubesat-1u",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "CubeSat (1U Generic)",
|
||||||
|
"description": "Standardized 1U research nanosatellite.",
|
||||||
|
"dryMass": 150,
|
||||||
|
"diameter": 0.6,
|
||||||
|
"length": 0.9,
|
||||||
|
"cost": 450000,
|
||||||
|
"maxGLoad": 12,
|
||||||
|
"modelFile": "nasa_3d_glb/CubeSat - 1 RU Generic.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-cubesat-2u",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "CubeSat (2U Dual Bus)",
|
||||||
|
"description": "2U university technology demonstration spacecraft.",
|
||||||
|
"dryMass": 350,
|
||||||
|
"diameter": 0.8,
|
||||||
|
"length": 1.4,
|
||||||
|
"cost": 750000,
|
||||||
|
"maxGLoad": 11,
|
||||||
|
"modelFile": "nasa_3d_glb/CubeSat - 2 RU Generic.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-terra",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Terra Earth Observation Bus",
|
||||||
|
"description": "Flagship Earth science remote sensing spacecraft.",
|
||||||
|
"dryMass": 4800,
|
||||||
|
"diameter": 3.5,
|
||||||
|
"length": 6.8,
|
||||||
|
"cost": 4500000,
|
||||||
|
"maxGLoad": 6.5,
|
||||||
|
"modelFile": "nasa_3d_glb/Terra.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-aqua",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Aqua Hydrological Orbiter",
|
||||||
|
"description": "Sun-synchronous atmospheric and ocean water-cycle monitor.",
|
||||||
|
"dryMass": 2934,
|
||||||
|
"diameter": 3.1,
|
||||||
|
"length": 6.4,
|
||||||
|
"cost": 3900000,
|
||||||
|
"maxGLoad": 6.5,
|
||||||
|
"modelFile": "nasa_3d_glb/Aqua (A).glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-landsat8",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Landsat-8 Multispectral Imager",
|
||||||
|
"description": "High-resolution land surface thermal & optical imager.",
|
||||||
|
"dryMass": 2700,
|
||||||
|
"diameter": 2.4,
|
||||||
|
"length": 4.3,
|
||||||
|
"cost": 3500000,
|
||||||
|
"maxGLoad": 7.0,
|
||||||
|
"modelFile": "nasa_3d_glb/Landsat 8.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-dscovr",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "DSCOVR Space Weather Sentinel",
|
||||||
|
"description": "Sun-Earth L1 solar wind and coronal mass ejection sentinel.",
|
||||||
|
"dryMass": 570,
|
||||||
|
"diameter": 2.2,
|
||||||
|
"length": 4.8,
|
||||||
|
"cost": 3100000,
|
||||||
|
"maxGLoad": 7.5,
|
||||||
|
"modelFile": "nasa_3d_glb/Deep Space Climate Observatory (DSCOVR) (Triana).glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-tdrs",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "TDRS Geostationary Relay",
|
||||||
|
"description": "High-gain S/Ku/Ka-band tracking and data relay satellite.",
|
||||||
|
"dryMass": 3454,
|
||||||
|
"diameter": 3.9,
|
||||||
|
"length": 6.2,
|
||||||
|
"cost": 6500000,
|
||||||
|
"maxGLoad": 6.0,
|
||||||
|
"modelFile": "nasa_3d_glb/Tracking and Data Relay Satellites (TDRS) (A).glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-hubble",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Hubble-Class Space Telescope",
|
||||||
|
"description": "2.4m optical space observatory with delicate gyroscopes.",
|
||||||
|
"dryMass": 11110,
|
||||||
|
"diameter": 4.3,
|
||||||
|
"length": 13.2,
|
||||||
|
"cost": 14000000,
|
||||||
|
"maxGLoad": 4.8,
|
||||||
|
"modelFile": "nasa_3d_glb/Hubble Space Telescope (A).glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-jwst",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "JWST Infrared Observatory",
|
||||||
|
"description": "Segmented gold-mirror L2 observatory. Very sensitive to vibration & G-loads.",
|
||||||
|
"dryMass": 6200,
|
||||||
|
"diameter": 10.7,
|
||||||
|
"length": 20.2,
|
||||||
|
"cost": 24000000,
|
||||||
|
"maxGLoad": 4.2,
|
||||||
|
"modelFile": "nasa_3d_glb/James Webb Space Telescope (A).glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-roman",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Nancy Grace Roman Telescope",
|
||||||
|
"description": "Wide-field infrared dark-energy and exoplanet survey observatory.",
|
||||||
|
"dryMass": 4166,
|
||||||
|
"diameter": 4.2,
|
||||||
|
"length": 12.7,
|
||||||
|
"cost": 13000000,
|
||||||
|
"maxGLoad": 5.0,
|
||||||
|
"modelFile": "nasa_3d_glb/Nancy Grace Roman Space Telescope (A).glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-chandra",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Chandra X-Ray Observatory",
|
||||||
|
"description": "High-energy astrophysics observatory for elliptical high-Earth orbit.",
|
||||||
|
"dryMass": 4800,
|
||||||
|
"diameter": 4.2,
|
||||||
|
"length": 13.8,
|
||||||
|
"cost": 12000000,
|
||||||
|
"maxGLoad": 5.2,
|
||||||
|
"modelFile": "nasa_3d_glb/Chandra X-ray Observatory.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-lro",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "LRO Lunar Reconnaissance Orbiter",
|
||||||
|
"description": "Polar lunar mapping spacecraft with laser altimeter.",
|
||||||
|
"dryMass": 1000,
|
||||||
|
"diameter": 3.6,
|
||||||
|
"length": 6.4,
|
||||||
|
"cost": 4800000,
|
||||||
|
"maxGLoad": 6.8,
|
||||||
|
"modelFile": "nasa_3d_glb/Lunar Reconnaissance Orbiter (A).glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-apollo-lm",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Apollo-Class Lunar Lander",
|
||||||
|
"description": "Two-stage crewed lunar descent and ascent vehicle.",
|
||||||
|
"dryMass": 15100,
|
||||||
|
"diameter": 4.3,
|
||||||
|
"length": 7.0,
|
||||||
|
"cost": 18000000,
|
||||||
|
"maxGLoad": 4.5,
|
||||||
|
"crewedCapable": true,
|
||||||
|
"modelFile": "nasa_3d_glb/Apollo Lunar Module.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-esas-crew",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "ESAS Deep-Space Crew Module",
|
||||||
|
"description": "Pressurized crew capsule with heatshield and docking port.",
|
||||||
|
"dryMass": 8500,
|
||||||
|
"diameter": 4.5,
|
||||||
|
"length": 6.2,
|
||||||
|
"cost": 11000000,
|
||||||
|
"maxGLoad": 4.5,
|
||||||
|
"crewedCapable": true,
|
||||||
|
"modelFile": "nasa_3d_glb/ESAS Crew Module.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-gateway",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Lunar Gateway Core Habitat",
|
||||||
|
"description": "Power & propulsion cislunar station core module.",
|
||||||
|
"dryMass": 12500,
|
||||||
|
"diameter": 4.5,
|
||||||
|
"length": 10.5,
|
||||||
|
"cost": 19500000,
|
||||||
|
"maxGLoad": 5.0,
|
||||||
|
"crewedCapable": true,
|
||||||
|
"modelFile": "nasa_3d_glb/Gateway Core.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-mro",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "MRO Mars Reconnaissance Orbiter",
|
||||||
|
"description": "High-bandwidth Mars science and relay orbiter.",
|
||||||
|
"dryMass": 2180,
|
||||||
|
"diameter": 4.4,
|
||||||
|
"length": 6.5,
|
||||||
|
"cost": 7200000,
|
||||||
|
"maxGLoad": 6.5,
|
||||||
|
"modelFile": "nasa_3d_glb/Mars Reconnaissance Orbiter (MRO) (A).glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-perseverance",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Perseverance Mars Rover Aeroshell",
|
||||||
|
"description": "Nuclear-powered Martian surface rover & skycrane descent stage.",
|
||||||
|
"dryMass": 3850,
|
||||||
|
"diameter": 4.5,
|
||||||
|
"length": 4.8,
|
||||||
|
"cost": 14000000,
|
||||||
|
"maxGLoad": 6.5,
|
||||||
|
"modelFile": "nasa_3d_glb/Mars 2020 Perseverance Rover.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-viking",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Viking-Class Mars Lander",
|
||||||
|
"description": "Stationary Martian surface biology and meteorology lander.",
|
||||||
|
"dryMass": 2400,
|
||||||
|
"diameter": 3.6,
|
||||||
|
"length": 3.2,
|
||||||
|
"cost": 6500000,
|
||||||
|
"maxGLoad": 7.0,
|
||||||
|
"modelFile": "nasa_3d_glb/Viking Lander.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-voyager",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Voyager Interstellar Probe",
|
||||||
|
"description": "RTG-powered outer-planet and interstellar plasma probe.",
|
||||||
|
"dryMass": 825,
|
||||||
|
"diameter": 3.7,
|
||||||
|
"length": 3.7,
|
||||||
|
"cost": 9500000,
|
||||||
|
"maxGLoad": 8.0,
|
||||||
|
"modelFile": "nasa_3d_glb/Voyager Probe (A).glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-juno",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Juno Jovian Polar Probe",
|
||||||
|
"description": "Radiation-vaulted solar-powered Jupiter polar orbiter.",
|
||||||
|
"dryMass": 3625,
|
||||||
|
"diameter": 4.5,
|
||||||
|
"length": 6.0,
|
||||||
|
"cost": 12500000,
|
||||||
|
"maxGLoad": 6.5,
|
||||||
|
"modelFile": "nasa_3d_glb/Juno (A).glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-parker",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "Parker Solar Corona Probe",
|
||||||
|
"description": "Carbon-shielded extreme-perihelion heliophysics probe.",
|
||||||
|
"dryMass": 685,
|
||||||
|
"diameter": 2.4,
|
||||||
|
"length": 3.0,
|
||||||
|
"cost": 10500000,
|
||||||
|
"maxGLoad": 8.5,
|
||||||
|
"modelFile": "nasa_3d_glb/Parker Solar Probe.glb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "payload-osiris",
|
||||||
|
"kind": "payload",
|
||||||
|
"name": "OSIRIS-REx Sample Return Probe",
|
||||||
|
"description": "Asteroid Bennu (1999 RQ36) touch-and-go regolith sampler.",
|
||||||
|
"dryMass": 2110,
|
||||||
|
"diameter": 3.2,
|
||||||
|
"length": 4.5,
|
||||||
|
"cost": 8900000,
|
||||||
|
"maxGLoad": 7.0,
|
||||||
|
"modelFile": "nasa_3d_glb/OSIRIS-REx.glb"
|
||||||
|
}
|
||||||
|
]
|
||||||
56
data/sponsors.json
Normal file
56
data/sponsors.json
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "nasa",
|
||||||
|
"name": "NASA",
|
||||||
|
"flag": "US",
|
||||||
|
"budgetMult": 1.05,
|
||||||
|
"waiverCostMult": 1.1,
|
||||||
|
"reputationMult": 1.15,
|
||||||
|
"description": "National Aeronautics and Space Administration. Balanced budgets, strict safety culture, bonus reputation."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "esa",
|
||||||
|
"name": "ESA",
|
||||||
|
"flag": "EU",
|
||||||
|
"budgetMult": 0.95,
|
||||||
|
"waiverCostMult": 0.9,
|
||||||
|
"reputationMult": 1.1,
|
||||||
|
"description": "European Space Agency. Precision science missions with streamlined international compliance."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "jaxa",
|
||||||
|
"name": "JAXA",
|
||||||
|
"flag": "JP",
|
||||||
|
"budgetMult": 0.92,
|
||||||
|
"waiverCostMult": 1.0,
|
||||||
|
"reputationMult": 1.2,
|
||||||
|
"description": "Japan Aerospace Exploration Agency. Rewards deep-space engineering discipline and high efficiency."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "csa",
|
||||||
|
"name": "CSA",
|
||||||
|
"flag": "CA",
|
||||||
|
"budgetMult": 0.88,
|
||||||
|
"waiverCostMult": 0.85,
|
||||||
|
"reputationMult": 1.15,
|
||||||
|
"description": "Canadian Space Agency. Lean budget multiplier with reduced waiver fees."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "isro",
|
||||||
|
"name": "ISRO",
|
||||||
|
"flag": "IN",
|
||||||
|
"budgetMult": 0.82,
|
||||||
|
"waiverCostMult": 0.75,
|
||||||
|
"reputationMult": 1.25,
|
||||||
|
"description": "Indian Space Research Organisation. Ultra-frugal contracts that reward extreme cost-efficiency."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "gsdistance",
|
||||||
|
"name": "GsDistance Orbital",
|
||||||
|
"flag": "GD",
|
||||||
|
"budgetMult": 1.2,
|
||||||
|
"waiverCostMult": 0.7,
|
||||||
|
"reputationMult": 0.95,
|
||||||
|
"description": "Commercial launch & telemetry consortium. Higher upfront capital and flexible waivers, lower prestige gain."
|
||||||
|
}
|
||||||
|
]
|
||||||
35
docker-compose.yml
Normal file
35
docker-compose.yml
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
init: true
|
||||||
|
environment:
|
||||||
|
- PORT=3000
|
||||||
|
- DATA_FILE=/app/state/db.json
|
||||||
|
- ML_WEIGHTS_PATH=/app/state/ml_policy_weights.json
|
||||||
|
- GMAT_BIN=/opt/gmat/bin/GmatConsole-R2026a
|
||||||
|
- GMAT_CONSOLE_BIN=/opt/gmat/bin/GmatConsole-R2026a
|
||||||
|
- GMAT_WORK_DIR=/app/state/gmat-work
|
||||||
|
- ML_AI_ENABLED=${ML_AI_ENABLED:-1}
|
||||||
|
- SIM_RATE=${SIM_RATE:-30}
|
||||||
|
- AI_DISABLED=${AI_DISABLED:-0}
|
||||||
|
- SPACEGAEM_PASSWORD=${SPACEGAEM_PASSWORD:-}
|
||||||
|
volumes:
|
||||||
|
- sgywftp_game_state:/app/state
|
||||||
|
- ${GMAT_DIST_DIR:-../GMAT/GMAT-R2026a-Linux-x64}:/opt/gmat:ro
|
||||||
|
# No exposed ports - only reachable via the tunnel
|
||||||
|
restart: unless-stopped
|
||||||
|
# ports:
|
||||||
|
# - "3000:3000"
|
||||||
|
|
||||||
|
cloudflared:
|
||||||
|
image: cloudflare/cloudflared:latest
|
||||||
|
command: tunnel --no-autoupdate run --token ${TUNNEL_TOKEN}
|
||||||
|
environment:
|
||||||
|
- TUNNEL_TOKEN=${TUNNEL_TOKEN}
|
||||||
|
depends_on:
|
||||||
|
app:
|
||||||
|
condition: service_healthy
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
sgywftp_game_state:
|
||||||
BIN
models/cat_3d_model_free.glb
Normal file
BIN
models/cat_3d_model_free.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/1999 RQ36 asteroid.glb
Normal file
BIN
models/nasa_3d_glb/1999 RQ36 asteroid.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Apollo Lunar Module.glb
Normal file
BIN
models/nasa_3d_glb/Apollo Lunar Module.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Aqua (A).glb
Normal file
BIN
models/nasa_3d_glb/Aqua (A).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Cassini-Huygens (A).glb
Normal file
BIN
models/nasa_3d_glb/Cassini-Huygens (A).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Chandra X-ray Observatory.glb
Normal file
BIN
models/nasa_3d_glb/Chandra X-ray Observatory.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/CubeSat - 1 RU Generic.glb
Normal file
BIN
models/nasa_3d_glb/CubeSat - 1 RU Generic.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/CubeSat - 2 RU Generic.glb
Normal file
BIN
models/nasa_3d_glb/CubeSat - 2 RU Generic.glb
Normal file
Binary file not shown.
Binary file not shown.
BIN
models/nasa_3d_glb/ESAS Crew Module.glb
Normal file
BIN
models/nasa_3d_glb/ESAS Crew Module.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/External tank.glb
Normal file
BIN
models/nasa_3d_glb/External tank.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Gantry.glb
Normal file
BIN
models/nasa_3d_glb/Gantry.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Hubble Space Telescope (A).glb
Normal file
BIN
models/nasa_3d_glb/Hubble Space Telescope (A).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/International Space Station (ISS) (A).glb
Normal file
BIN
models/nasa_3d_glb/International Space Station (ISS) (A).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/James Webb Space Telescope (A).glb
Normal file
BIN
models/nasa_3d_glb/James Webb Space Telescope (A).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Juno (A).glb
Normal file
BIN
models/nasa_3d_glb/Juno (A).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Landsat 8.glb
Normal file
BIN
models/nasa_3d_glb/Landsat 8.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Lunar Reconnaissance Orbiter (A).glb
Normal file
BIN
models/nasa_3d_glb/Lunar Reconnaissance Orbiter (A).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Mars 2020 Perseverance Rover.glb
Normal file
BIN
models/nasa_3d_glb/Mars 2020 Perseverance Rover.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Mars Reconnaissance Orbiter (MRO) (A).glb
Normal file
BIN
models/nasa_3d_glb/Mars Reconnaissance Orbiter (MRO) (A).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Mobile Launcher (assembled).glb
Normal file
BIN
models/nasa_3d_glb/Mobile Launcher (assembled).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Nancy Grace Roman Space Telescope (A).glb
Normal file
BIN
models/nasa_3d_glb/Nancy Grace Roman Space Telescope (A).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/OSIRIS-REx.glb
Normal file
BIN
models/nasa_3d_glb/OSIRIS-REx.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Parker Solar Probe.glb
Normal file
BIN
models/nasa_3d_glb/Parker Solar Probe.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Saturn V.glb
Normal file
BIN
models/nasa_3d_glb/Saturn V.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Solid Rocket Booster.glb
Normal file
BIN
models/nasa_3d_glb/Solid Rocket Booster.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Space Shuttle (D) eng.glb
Normal file
BIN
models/nasa_3d_glb/Space Shuttle (D) eng.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Terra.glb
Normal file
BIN
models/nasa_3d_glb/Terra.glb
Normal file
Binary file not shown.
Binary file not shown.
BIN
models/nasa_3d_glb/Vehicle Assembly Building (VAB).glb
Normal file
BIN
models/nasa_3d_glb/Vehicle Assembly Building (VAB).glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Viking Lander.glb
Normal file
BIN
models/nasa_3d_glb/Viking Lander.glb
Normal file
Binary file not shown.
BIN
models/nasa_3d_glb/Voyager Probe (A).glb
Normal file
BIN
models/nasa_3d_glb/Voyager Probe (A).glb
Normal file
Binary file not shown.
1877
package-lock.json
generated
Normal file
1877
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
38
package.json
Normal file
38
package.json
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
"name": "org.gsdistance.spacegaem",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "Space mission design game made to be as realistic as I could make it.",
|
||||||
|
"keywords": [
|
||||||
|
"Space",
|
||||||
|
"NASA",
|
||||||
|
"Game"
|
||||||
|
],
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git.gsdistance.org/tyuXX/SGYWFTP"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"author": "tyuXX",
|
||||||
|
"$schema": "https://json.schemastore.org/package.json",
|
||||||
|
"type": "module",
|
||||||
|
"main": "dist/server/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"bs": "npm run build && npm start",
|
||||||
|
"build": "tsc -b && node scripts/build-client.mjs",
|
||||||
|
"check": "tsc -b --emitDeclarationOnly",
|
||||||
|
"dev": "tsc -b --watch",
|
||||||
|
"dev:client": "node scripts/build-client.mjs --watch",
|
||||||
|
"start": "node dist/server/index.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^5.3.0",
|
||||||
|
"three": "^0.187.0",
|
||||||
|
"typescript": "^7.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/express": "^5.0.6",
|
||||||
|
"@types/node": "^26.6.6",
|
||||||
|
"@types/three": "^0.187.0",
|
||||||
|
"esbuild": "^0.28.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
32
public/css/base.css
Normal file
32
public/css/base.css
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* Ace of base */
|
||||||
|
.screen {
|
||||||
|
position: absolute; inset: 0;
|
||||||
|
display: flex; flex-direction: column;
|
||||||
|
}
|
||||||
|
.screen-center {
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
height: 100%; padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
|
||||||
|
.col { display: flex; flex-direction: column; gap: 12px; }
|
||||||
|
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
|
||||||
|
.grow { flex: 1; }
|
||||||
|
|
||||||
|
h1, h2, h3 {
|
||||||
|
font-family: var(--mono);
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
h2 { font-size: 16px; }
|
||||||
|
h3 { font-size: 13px; }
|
||||||
|
|
||||||
|
.mono { font-family: var(--mono); }
|
||||||
|
.dim { color: var(--text-dim); }
|
||||||
|
.faint { color: var(--text-faint); }
|
||||||
|
.accent { color: var(--sim-accent); transition: color 0.4s ease; }
|
||||||
|
.brand { color: var(--brand-blue); }
|
||||||
|
.amber { color: var(--amber); }
|
||||||
|
.green { color: var(--green); }
|
||||||
|
.red { color: var(--red); }
|
||||||
133
public/css/components.css
Normal file
133
public/css/components.css
Normal file
|
|
@ -0,0 +1,133 @@
|
||||||
|
/* Chamfers, chamfers, and yes. More chamfers. */
|
||||||
|
.panel {
|
||||||
|
background: var(--bg-panel);
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
clip-path: var(--chamfer);
|
||||||
|
position: relative;
|
||||||
|
transition: border-color 0.35s ease;
|
||||||
|
}
|
||||||
|
.panel::before {
|
||||||
|
content: '';
|
||||||
|
display: block; height: 2px;
|
||||||
|
background: linear-gradient(90deg, var(--sim-accent), transparent 70%);
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-grid { display: grid; gap: 12px; }
|
||||||
|
.card {
|
||||||
|
padding: 14px 16px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
clip-path: var(--chamfer-sm);
|
||||||
|
background: var(--bg-panel);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.16s ease, background-color 0.16s ease, transform 0.12s ease;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.card::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute; top: 0; left: 0; right: 0; height: 2px;
|
||||||
|
background: var(--border);
|
||||||
|
transition: background 0.16s ease;
|
||||||
|
}
|
||||||
|
.card:hover { border-color: var(--sim-accent); background: var(--bg-elevated); }
|
||||||
|
.card:hover::before { background: var(--sim-accent); }
|
||||||
|
.card.selected { border-color: var(--brand-blue); background: var(--bg-elevated); box-shadow: inset 0 0 18px var(--sim-glow); }
|
||||||
|
.card.selected::before { background: var(--brand-blue); }
|
||||||
|
.card h3 { margin-bottom: 6px; }
|
||||||
|
.card .sub { color: var(--text-dim); font-size: 12px; line-height: 1.5; }
|
||||||
|
.card .meta { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 11px; color: var(--text-dim); font-family: var(--mono); }
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
display: inline-flex; align-items: center; justify-content: center; gap: 8px;
|
||||||
|
padding: 10px 20px;
|
||||||
|
background: var(--bg-elevated);
|
||||||
|
border: 1px solid var(--border-bright);
|
||||||
|
clip-path: var(--chamfer-sm);
|
||||||
|
color: var(--text);
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 11px; font-weight: 700; letter-spacing: 0.12em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease, transform 0.08s ease;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
.btn:hover:not(:disabled) {
|
||||||
|
border-color: var(--sim-accent);
|
||||||
|
color: var(--sim-accent);
|
||||||
|
background: var(--bg-hover);
|
||||||
|
}
|
||||||
|
.btn:active:not(:disabled) { transform: translateY(1px); }
|
||||||
|
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
|
||||||
|
|
||||||
|
.btn.primary {
|
||||||
|
background: rgba(52, 152, 219, 0.18);
|
||||||
|
border-color: var(--brand-strong);
|
||||||
|
color: #dbeafe;
|
||||||
|
}
|
||||||
|
.btn.primary:hover:not(:disabled) {
|
||||||
|
background: rgba(52, 152, 219, 0.34);
|
||||||
|
border-color: var(--brand-blue);
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
.btn.warn {
|
||||||
|
background: rgba(245, 158, 11, 0.15);
|
||||||
|
border-color: var(--amber);
|
||||||
|
color: #fde68a;
|
||||||
|
}
|
||||||
|
.btn.danger {
|
||||||
|
background: rgba(248, 113, 113, 0.12);
|
||||||
|
border-color: rgba(248, 113, 113, 0.5);
|
||||||
|
color: #fecaca;
|
||||||
|
}
|
||||||
|
.btn.danger:hover:not(:disabled) { border-color: var(--red); color: var(--red); background: rgba(248, 113, 113, 0.22); }
|
||||||
|
.btn.ghost { background: rgba(18, 22, 31, 0.65); border-color: var(--border); color: var(--text-dim); }
|
||||||
|
.btn.ghost:hover:not(:disabled) { border-color: var(--border-bright); color: var(--text); }
|
||||||
|
.btn.sm { padding: 6px 12px; font-size: 10px; }
|
||||||
|
.btn.xs { padding: 4px 8px; font-size: 9px; letter-spacing: 0.08em; }
|
||||||
|
.btn.selected {
|
||||||
|
border-color: var(--sim-accent);
|
||||||
|
color: var(--sim-accent);
|
||||||
|
background: var(--sim-glow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.input, select.input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 9px 12px;
|
||||||
|
background: var(--bg-deep);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
clip-path: var(--chamfer-sm);
|
||||||
|
color: var(--text);
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 12px;
|
||||||
|
outline: none;
|
||||||
|
transition: border-color 0.15s;
|
||||||
|
}
|
||||||
|
.input:focus { border-color: var(--brand-blue); }
|
||||||
|
.input::placeholder { color: var(--text-faint); }
|
||||||
|
|
||||||
|
input[type="range"].slider {
|
||||||
|
width: 100%;
|
||||||
|
accent-color: var(--sim-accent);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
label.field {
|
||||||
|
display: flex; flex-direction: column; gap: 6px;
|
||||||
|
font-family: var(--mono); font-size: 10px; color: var(--text-dim);
|
||||||
|
text-transform: uppercase; letter-spacing: 0.12em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
display: inline-flex; align-items: center; gap: 5px;
|
||||||
|
padding: 2px 8px;
|
||||||
|
font-family: var(--mono); font-size: 9px; font-weight: 700; letter-spacing: 0.1em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
border: 1px solid var(--border-bright); color: var(--text-dim);
|
||||||
|
background: rgba(11, 14, 20, 0.7);
|
||||||
|
clip-path: var(--chamfer-sm);
|
||||||
|
}
|
||||||
|
.badge.ok { color: var(--green); border-color: rgba(52, 211, 153, 0.5); }
|
||||||
|
.badge.warn { color: var(--amber); border-color: rgba(245, 158, 11, 0.55); }
|
||||||
|
.badge.err { color: var(--red); border-color: rgba(248, 113, 113, 0.55); }
|
||||||
|
.badge.info { color: var(--sim-accent); border-color: var(--sim-accent-dim); }
|
||||||
272
public/css/hud.css
Normal file
272
public/css/hud.css
Normal file
|
|
@ -0,0 +1,272 @@
|
||||||
|
/* Modals, toasts, notification window, co-op toggle vicodins, value chart, grid (forgot which one), and toggles. */
|
||||||
|
.modal-overlay {
|
||||||
|
position: fixed; inset: 0; background: rgba(7, 10, 15, 0.84); backdrop-filter: blur(4px);
|
||||||
|
display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
|
||||||
|
}
|
||||||
|
.modal { width: min(500px, 100%); max-height: 85vh; overflow-y: auto; padding: 24px; }
|
||||||
|
.modal h3 { font-size: 14px; margin-bottom: 14px; color: var(--brand-blue); }
|
||||||
|
|
||||||
|
#toast-root, .toast-root {
|
||||||
|
position: fixed; bottom: 64px; right: 20px; z-index: 200;
|
||||||
|
display: flex; flex-direction: column; gap: 8px; pointer-events: none;
|
||||||
|
}
|
||||||
|
.toast {
|
||||||
|
padding: 11px 16px; clip-path: var(--chamfer-sm);
|
||||||
|
font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; max-width: 380px;
|
||||||
|
background: var(--bg-elevated); border: 1px solid var(--border-bright);
|
||||||
|
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
|
||||||
|
animation: slideIn 0.2s ease;
|
||||||
|
}
|
||||||
|
.toast.ok { border-color: var(--green); }
|
||||||
|
.toast.err { border-color: var(--red); }
|
||||||
|
.toast.info { border-color: var(--brand-blue); }
|
||||||
|
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
|
||||||
|
|
||||||
|
#notif-drawer-root {
|
||||||
|
position: fixed; bottom: 14px; right: 16px; z-index: 180;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.notif-drawer-wrap {
|
||||||
|
display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
|
||||||
|
}
|
||||||
|
.notif-drawer-wrap > * { pointer-events: auto; }
|
||||||
|
|
||||||
|
.notif-toggle-bar {
|
||||||
|
display: flex; align-items: center;
|
||||||
|
background: rgba(18, 22, 31, 0.94); backdrop-filter: blur(8px);
|
||||||
|
border: 1px solid var(--border-bright); clip-path: var(--chamfer-sm);
|
||||||
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
|
||||||
|
max-width: 360px; overflow: hidden;
|
||||||
|
}
|
||||||
|
.notif-toggle-main {
|
||||||
|
display: flex; align-items: center; gap: 8px; padding: 7px 11px;
|
||||||
|
background: none; border: none; color: var(--text); cursor: pointer;
|
||||||
|
min-width: 0; text-align: left;
|
||||||
|
}
|
||||||
|
.notif-toggle-main:hover { background: var(--bg-hover); }
|
||||||
|
.notif-preview {
|
||||||
|
font-size: 10px; max-width: 170px; overflow: hidden;
|
||||||
|
text-overflow: ellipsis; white-space: nowrap;
|
||||||
|
}
|
||||||
|
.notif-hide-btn {
|
||||||
|
padding: 7px 9px; background: rgba(11, 14, 20, 0.5); border: none;
|
||||||
|
border-left: 1px solid var(--border); color: var(--text-dim); cursor: pointer;
|
||||||
|
font-family: var(--mono); font-size: 12px; line-height: 1;
|
||||||
|
}
|
||||||
|
.notif-hide-btn:hover { color: var(--text); background: var(--bg-hover); }
|
||||||
|
.notif-mini-pill {
|
||||||
|
padding: 6px 10px; background: rgba(18, 22, 31, 0.9);
|
||||||
|
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
|
||||||
|
}
|
||||||
|
|
||||||
|
.notif-drawer {
|
||||||
|
width: min(370px, calc(100vw - var(--right-sidebar-offset, 0px) - 32px)); max-height: 340px;
|
||||||
|
display: flex; flex-direction: column; padding: 10px 12px; gap: 8px;
|
||||||
|
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
|
||||||
|
}
|
||||||
|
.notif-header { padding-bottom: 4px; border-bottom: 1px solid rgba(42, 52, 73, 0.6); }
|
||||||
|
.notif-tabs { display: flex; gap: 5px; flex-wrap: wrap; }
|
||||||
|
.notif-list {
|
||||||
|
flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
|
||||||
|
max-height: 230px; padding-right: 3px;
|
||||||
|
}
|
||||||
|
.notif-item {
|
||||||
|
padding: 7px 9px; background: var(--bg-deep); border: 1px solid var(--border);
|
||||||
|
border-left-width: 3px; clip-path: var(--chamfer-sm);
|
||||||
|
font-family: var(--mono); font-size: 11px; line-height: 1.35;
|
||||||
|
}
|
||||||
|
.notif-item.ok { border-left-color: var(--green); }
|
||||||
|
.notif-item.err { border-left-color: var(--red); }
|
||||||
|
.notif-item.warn { border-left-color: var(--amber); }
|
||||||
|
.notif-item.info { border-left-color: var(--brand-blue); }
|
||||||
|
.notif-msg { color: var(--text); word-break: break-word; }
|
||||||
|
|
||||||
|
.list-page {
|
||||||
|
padding-bottom: 58px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar { width: 7px; height: 7px; }
|
||||||
|
::-webkit-scrollbar-thumb { background: var(--border-bright); }
|
||||||
|
::-webkit-scrollbar-track { background: transparent; }
|
||||||
|
|
||||||
|
.loading {
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
color: var(--text-dim); font-family: var(--mono); font-size: 11px;
|
||||||
|
letter-spacing: 0.18em; text-transform: uppercase; padding: 16px;
|
||||||
|
}
|
||||||
|
.loading::after { content: '...'; animation: dots 1.2s steps(4) infinite; }
|
||||||
|
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
|
||||||
|
|
||||||
|
@media (max-width: 960px) {
|
||||||
|
.dash-root, .builder-root, .param-root, .map-root, .onboard-layout, .list-page .cols {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-template-rows: 45vh 1fr;
|
||||||
|
}
|
||||||
|
.dash-sidebar, .builder-body, .param-side, .map-sidebar {
|
||||||
|
padding-bottom: 58px;
|
||||||
|
}
|
||||||
|
#hud-bottom-right {
|
||||||
|
right: 16px !important;
|
||||||
|
max-width: calc(100vw - 32px) !important;
|
||||||
|
}
|
||||||
|
.notif-drawer {
|
||||||
|
width: min(370px, calc(100vw - 32px)) !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.builder-summary-bar {
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
background: rgba(11, 14, 20, 0.72);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
.builder-summary-bar .summary-pills {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px 10px;
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.builder-coop-bar {
|
||||||
|
padding: 6px 12px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
background: rgba(18, 22, 31, 0.85);
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 5px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.station-pill {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
padding: 3px 8px;
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 9px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
background: var(--bg-deep);
|
||||||
|
color: var(--text-dim);
|
||||||
|
clip-path: var(--chamfer-sm);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.15s, color 0.15s, background-color 0.15s;
|
||||||
|
}
|
||||||
|
.station-pill:hover {
|
||||||
|
border-color: var(--brand-blue);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.station-pill.ready {
|
||||||
|
border-color: rgba(52, 211, 153, 0.55);
|
||||||
|
color: var(--green);
|
||||||
|
background: rgba(52, 211, 153, 0.08);
|
||||||
|
}
|
||||||
|
.station-pill.occupied {
|
||||||
|
border-color: var(--sim-accent-dim);
|
||||||
|
color: var(--sim-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.value-chart {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
background: var(--bg-deep);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
clip-path: var(--chamfer-sm);
|
||||||
|
padding: 10px 12px;
|
||||||
|
}
|
||||||
|
.value-bar-track {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
height: 18px;
|
||||||
|
background: rgba(25, 32, 46, 0.8);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
.value-seg {
|
||||||
|
height: 100%;
|
||||||
|
transition: width 0.25s ease;
|
||||||
|
min-width: 2px;
|
||||||
|
}
|
||||||
|
.value-seg.base { background: var(--brand-strong); }
|
||||||
|
.value-seg.science { background: var(--green); }
|
||||||
|
.value-seg.eff { background: var(--violet); }
|
||||||
|
.value-seg.bonus { background: var(--amber); }
|
||||||
|
.value-seg.hw { background: #ef4444; }
|
||||||
|
.value-seg.bus { background: #f97316; }
|
||||||
|
.value-seg.ops { background: #eab308; }
|
||||||
|
|
||||||
|
.bus-power-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.bus-power-cell {
|
||||||
|
background: var(--bg-deep);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
clip-path: var(--chamfer-sm);
|
||||||
|
padding: 7px 9px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
.bus-power-cell .k {
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 9px;
|
||||||
|
color: var(--text-faint);
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
.bus-power-cell .v {
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
#hud-bottom-right {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 14px;
|
||||||
|
right: calc(16px + var(--right-sidebar-offset, 0px));
|
||||||
|
z-index: 180;
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
justify-content: flex-end;
|
||||||
|
flex-wrap: wrap-reverse;
|
||||||
|
gap: 8px;
|
||||||
|
max-width: calc(100vw - var(--right-sidebar-offset, 0px) - 32px);
|
||||||
|
transition: right 0.18s ease, max-width 0.18s ease;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
#hud-bottom-right > * {
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
#notif-drawer-root {
|
||||||
|
position: static;
|
||||||
|
}
|
||||||
|
.comfort-pill-bar {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.comfort-btn {
|
||||||
|
padding: 6px 10px;
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.06em;
|
||||||
|
background: var(--bg-panel-solid);
|
||||||
|
border: 1px solid var(--border-bright);
|
||||||
|
color: var(--text-dim);
|
||||||
|
clip-path: var(--chamfer-sm);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.comfort-btn:hover {
|
||||||
|
border-color: var(--sim-accent);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.comfort-btn.active {
|
||||||
|
border-color: var(--brand-blue);
|
||||||
|
color: var(--brand-blue);
|
||||||
|
background: var(--bg-elevated);
|
||||||
|
}
|
||||||
220
public/css/screens.css
Normal file
220
public/css/screens.css
Normal file
|
|
@ -0,0 +1,220 @@
|
||||||
|
/* Screen-specific layouts for menu, auth, onboarding, dashboard, builder, config, map, launch, and debrief. Not much to say about this one I suppose :( #whatthehellisexpress.js */
|
||||||
|
.menu-root {
|
||||||
|
position: absolute; inset: 0; z-index: 2;
|
||||||
|
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
||||||
|
pointer-events: none; padding: 24px;
|
||||||
|
}
|
||||||
|
.menu-root .btn, .menu-root .menu-card { pointer-events: auto; }
|
||||||
|
|
||||||
|
.menu-brand-pill {
|
||||||
|
font-family: var(--mono); font-size: 10px; letter-spacing: 0.25em;
|
||||||
|
text-transform: uppercase; color: var(--brand-blue);
|
||||||
|
border: 1px solid var(--sim-accent-dim); background: rgba(11, 14, 20, 0.75);
|
||||||
|
padding: 5px 14px; margin-bottom: 18px; clip-path: var(--chamfer-sm);
|
||||||
|
}
|
||||||
|
.menu-title {
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: clamp(32px, 5.5vw, 66px);
|
||||||
|
font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase;
|
||||||
|
text-align: center; color: #f8fafc;
|
||||||
|
text-shadow: 0 0 36px var(--sim-glow), 0 0 12px rgba(52, 152, 219, 0.35);
|
||||||
|
}
|
||||||
|
.menu-title::after {
|
||||||
|
content: ''; display: block; height: 2px; margin: 12px auto 0; width: 72%;
|
||||||
|
background: linear-gradient(90deg, transparent, var(--brand-blue), transparent);
|
||||||
|
}
|
||||||
|
.menu-subtitle {
|
||||||
|
color: var(--text-dim); letter-spacing: 0.42em; text-transform: uppercase;
|
||||||
|
font-size: 11px; font-family: var(--mono); margin: 14px 0 42px; text-align: center;
|
||||||
|
}
|
||||||
|
.menu-buttons { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
|
||||||
|
.menu-buttons .btn { min-width: 190px; padding: 14px 28px; font-size: 12px; }
|
||||||
|
.menu-footer {
|
||||||
|
position: absolute; bottom: 18px; font-size: 10px; color: var(--text-faint);
|
||||||
|
letter-spacing: 0.16em; font-family: var(--mono); text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-card { width: min(580px, 100%); padding: 28px; }
|
||||||
|
.auth-card h2 { font-size: 18px; margin-bottom: 6px; }
|
||||||
|
.auth-card .sub { color: var(--text-dim); font-size: 12px; margin-bottom: 22px; line-height: 1.5; }
|
||||||
|
.auth-error { color: var(--red); font-size: 12px; min-height: 16px; font-family: var(--mono); }
|
||||||
|
|
||||||
|
.diff-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
|
||||||
|
.diff-card {
|
||||||
|
display: flex; flex-direction: column; gap: 4px; text-align: left;
|
||||||
|
padding: 10px 12px; text-transform: none; letter-spacing: 0.02em; font-weight: 500;
|
||||||
|
}
|
||||||
|
.diff-card .dc-head {
|
||||||
|
display: flex; justify-content: space-between; align-items: center; width: 100%;
|
||||||
|
font-family: var(--mono); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
|
||||||
|
}
|
||||||
|
.diff-card .dc-sub { font-size: 11px; color: var(--text-dim); line-height: 1.35; }
|
||||||
|
.diff-card .dc-meta { font-family: var(--mono); font-size: 10px; color: var(--text-faint); }
|
||||||
|
|
||||||
|
.onboard-layout {
|
||||||
|
display: grid; grid-template-columns: 1fr 340px; gap: 20px; height: 100%; padding: 22px; overflow: hidden;
|
||||||
|
}
|
||||||
|
.onboard-scroll { overflow-y: auto; padding-right: 6px; }
|
||||||
|
.onboard-preview { display: flex; flex-direction: column; gap: 12px; }
|
||||||
|
.onboard-preview-box {
|
||||||
|
height: 280px; position: relative; border: 1px solid var(--border);
|
||||||
|
background: var(--bg-deep); clip-path: var(--chamfer-sm); overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dash-root { display: grid; grid-template-columns: 1fr 370px; height: 100%; }
|
||||||
|
.dash-viewport { position: relative; overflow: hidden; }
|
||||||
|
.dash-viewport canvas { display: block; }
|
||||||
|
.dash-header {
|
||||||
|
position: absolute; top: 0; left: 0; right: 0;
|
||||||
|
display: flex; justify-content: space-between; align-items: center; gap: 12px;
|
||||||
|
padding: 14px 20px; z-index: 5;
|
||||||
|
background: linear-gradient(180deg, rgba(11, 14, 20, 0.92), transparent);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.dash-header > * { pointer-events: auto; }
|
||||||
|
.dash-header h1 { font-size: 15px; }
|
||||||
|
|
||||||
|
.dash-overlay-bottom {
|
||||||
|
position: absolute; bottom: 16px; left: 20px; right: 20px; z-index: 5;
|
||||||
|
display: flex; justify-content: space-between; align-items: flex-end; gap: 12px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.dash-overlay-bottom > * { pointer-events: auto; }
|
||||||
|
|
||||||
|
.dash-sidebar {
|
||||||
|
border-left: 1px solid var(--border);
|
||||||
|
background: var(--bg-panel-solid);
|
||||||
|
padding: 18px; overflow-y: auto;
|
||||||
|
display: flex; flex-direction: column; gap: 14px;
|
||||||
|
}
|
||||||
|
.dash-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: auto; padding-top: 8px; }
|
||||||
|
.dash-nav .btn { justify-content: flex-start; padding: 11px 12px; font-size: 10px; }
|
||||||
|
.dash-nav .btn.full-span { grid-column: 1 / -1; justify-content: center; padding: 13px 16px; font-size: 12px; }
|
||||||
|
|
||||||
|
.stat-row {
|
||||||
|
display: flex; justify-content: space-between; align-items: center; gap: 8px;
|
||||||
|
font-size: 12px; padding: 6px 0; border-bottom: 1px solid rgba(42, 52, 73, 0.55);
|
||||||
|
font-family: var(--mono);
|
||||||
|
}
|
||||||
|
.stat-row .k { color: var(--text-dim); text-transform: uppercase; font-size: 10px; letter-spacing: 0.08em; }
|
||||||
|
.stat-row .v { font-size: 12px; text-align: right; }
|
||||||
|
|
||||||
|
.builder-root { display: grid; grid-template-columns: 1fr 440px; height: 100%; }
|
||||||
|
.builder-viewport { position: relative; border-right: 1px solid var(--border); overflow: hidden; }
|
||||||
|
.builder-sidebar {
|
||||||
|
background: var(--bg-panel-solid);
|
||||||
|
display: flex; flex-direction: column; overflow: hidden;
|
||||||
|
}
|
||||||
|
.builder-tier-bar {
|
||||||
|
display: flex; gap: 6px; padding: 10px 12px;
|
||||||
|
border-bottom: 1px solid var(--border); background: var(--bg-deep); align-items: center;
|
||||||
|
}
|
||||||
|
.builder-tabs { display: flex; border-bottom: 1px solid var(--border); background: rgba(11, 14, 20, 0.5); }
|
||||||
|
.builder-tabs button {
|
||||||
|
flex: 1; padding: 11px 6px; background: none; border: none; color: var(--text-dim);
|
||||||
|
font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
|
||||||
|
cursor: pointer; border-bottom: 2px solid transparent; transition: color 0.15s, border-color 0.15s;
|
||||||
|
}
|
||||||
|
.builder-tabs button.active { color: var(--sim-accent); border-bottom-color: var(--sim-accent); }
|
||||||
|
.builder-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
|
||||||
|
|
||||||
|
.stage-card {
|
||||||
|
border: 1px solid var(--border); clip-path: var(--chamfer-sm);
|
||||||
|
padding: 12px; background: var(--bg-elevated); display: flex; flex-direction: column; gap: 9px;
|
||||||
|
}
|
||||||
|
.stage-card.active { border-color: var(--brand-blue); }
|
||||||
|
|
||||||
|
.slot-group {
|
||||||
|
background: rgba(11, 14, 20, 0.55); border: 1px solid var(--border);
|
||||||
|
padding: 8px 10px; display: flex; flex-direction: column; gap: 6px;
|
||||||
|
}
|
||||||
|
.slot-title {
|
||||||
|
font-family: var(--mono); font-size: 9px; font-weight: 700; letter-spacing: 0.12em;
|
||||||
|
text-transform: uppercase; color: var(--sim-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
|
||||||
|
.stat-box { background: var(--bg-deep); border: 1px solid var(--border); clip-path: var(--chamfer-sm); padding: 9px 11px; }
|
||||||
|
.stat-box .k { font-family: var(--mono); font-size: 9px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.1em; }
|
||||||
|
.stat-box .v { font-family: var(--mono); font-size: 13px; margin-top: 3px; font-weight: 700; }
|
||||||
|
.stat-box .v.good { color: var(--green); }
|
||||||
|
.stat-box .v.bad { color: var(--red); }
|
||||||
|
.stat-box .v.warn { color: var(--amber); }
|
||||||
|
|
||||||
|
.rule-item {
|
||||||
|
border: 1px solid var(--border); padding: 8px 10px; background: var(--bg-deep);
|
||||||
|
clip-path: var(--chamfer-sm); display: flex; flex-direction: column; gap: 4px; font-size: 11px;
|
||||||
|
}
|
||||||
|
.rule-item.fail { border-color: rgba(248, 113, 113, 0.5); }
|
||||||
|
.rule-item.waived { border-color: rgba(245, 158, 11, 0.55); }
|
||||||
|
.rule-item.pass { border-color: rgba(52, 211, 153, 0.25); }
|
||||||
|
|
||||||
|
.builder-hud-bottom {
|
||||||
|
position: absolute; left: 16px; bottom: 16px; z-index: 4;
|
||||||
|
display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none;
|
||||||
|
}
|
||||||
|
.builder-hud-bottom > * { pointer-events: auto; }
|
||||||
|
|
||||||
|
.param-root { display: grid; grid-template-columns: 1fr 440px; height: 100%; overflow: hidden; }
|
||||||
|
.param-main { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
|
||||||
|
.param-side {
|
||||||
|
border-left: 1px solid var(--border); background: var(--bg-panel-solid);
|
||||||
|
padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
|
||||||
|
}
|
||||||
|
.canvas-box {
|
||||||
|
width: 100%; background: var(--bg-deep); border: 1px solid var(--border);
|
||||||
|
clip-path: var(--chamfer-sm); display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.map-root { display: grid; grid-template-columns: 1fr 340px; height: 100%; }
|
||||||
|
.map-viewport { position: relative; overflow: hidden; }
|
||||||
|
.map-sidebar {
|
||||||
|
border-left: 1px solid var(--border); background: var(--bg-panel-solid);
|
||||||
|
padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
|
||||||
|
}
|
||||||
|
.map-sidebar h3 { font-size: 11px; color: var(--text-dim); margin-top: 8px; }
|
||||||
|
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 11px; padding: 3px 0; font-family: var(--mono); cursor: pointer; }
|
||||||
|
.legend-item:hover { color: var(--sim-accent); }
|
||||||
|
.legend-dot { width: 8px; height: 8px; display: inline-block; }
|
||||||
|
|
||||||
|
.launch-root { display: flex; flex-direction: column; height: 100%; }
|
||||||
|
.launch-viewport { flex: 1; position: relative; overflow: hidden; }
|
||||||
|
.launch-hud-stack {
|
||||||
|
position: absolute; left: 20px; bottom: 20px; z-index: 5;
|
||||||
|
display: flex; flex-direction: column; gap: 10px; align-items: flex-start;
|
||||||
|
max-height: calc(100vh - 110px);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.launch-hud-stack > * { pointer-events: auto; }
|
||||||
|
.launch-hud {
|
||||||
|
background: rgba(11, 14, 20, 0.88); backdrop-filter: blur(8px);
|
||||||
|
border: 1px solid var(--border); clip-path: var(--chamfer);
|
||||||
|
padding: 14px 16px; min-width: 310px; width: min(335px, calc(100vw - 40px));
|
||||||
|
font-family: var(--mono); font-size: 11px;
|
||||||
|
}
|
||||||
|
.launch-events {
|
||||||
|
background: rgba(11, 14, 20, 0.86); backdrop-filter: blur(8px);
|
||||||
|
border: 1px solid var(--border); clip-path: var(--chamfer-sm);
|
||||||
|
padding: 12px 14px; width: min(335px, calc(100vw - 40px));
|
||||||
|
max-height: 185px; overflow-y: auto;
|
||||||
|
font-family: var(--mono); font-size: 11px;
|
||||||
|
}
|
||||||
|
.launch-banner {
|
||||||
|
position: absolute; top: 24px; left: 50%; transform: translateX(-50%);
|
||||||
|
font-family: var(--mono); font-size: 22px; font-weight: 800; letter-spacing: 0.32em;
|
||||||
|
text-transform: uppercase; color: var(--sim-accent);
|
||||||
|
text-shadow: 0 0 28px var(--sim-glow); z-index: 6; pointer-events: none;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.launch-controls { position: absolute; top: 18px; right: 20px; display: flex; gap: 8px; z-index: 6; }
|
||||||
|
.launch-title-left { position: absolute; top: 18px; left: 20px; z-index: 6; display: flex; flex-direction: column; gap: 4px; }
|
||||||
|
|
||||||
|
.list-page { padding: 22px; overflow-y: auto; height: 100%; display: flex; flex-direction: column; gap: 16px; }
|
||||||
|
.list-page .cols { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 20px; }
|
||||||
|
|
||||||
|
.debrief-root { display: flex; align-items: center; justify-content: center; height: 100%; padding: 20px; overflow-y: auto; }
|
||||||
|
.debrief-card { width: min(640px, 100%); padding: 30px; }
|
||||||
|
.score-ring { display: flex; align-items: center; gap: 22px; margin: 18px 0; }
|
||||||
|
.grade { font-size: 68px; font-weight: 800; font-family: var(--mono); line-height: 1; }
|
||||||
|
.grade.s { color: var(--brand-blue); } .grade.a { color: var(--green); }
|
||||||
|
.grade.b { color: var(--amber); } .grade.c { color: var(--red); } .grade.f { color: var(--red); }
|
||||||
7
public/css/style.css
Normal file
7
public/css/style.css
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
/* İmport modular CSS layers for Space Gaem: You Will Feel the Pain. */
|
||||||
|
@import './tokens.css';
|
||||||
|
@import './base.css';
|
||||||
|
@import './components.css';
|
||||||
|
@import './screens.css';
|
||||||
|
@import './hud.css';
|
||||||
|
@import './themes.css';
|
||||||
221
public/css/themes.css
Normal file
221
public/css/themes.css
Normal file
|
|
@ -0,0 +1,221 @@
|
||||||
|
/* Daylight light mode overrides (for the blind), reduce-effecties mode (for the not-blind), and terminology tooltips (I needed that). */
|
||||||
|
:root[data-color-mode="light"] {
|
||||||
|
--bg-deep: #f1f5f9;
|
||||||
|
--bg-panel: rgba(255, 255, 255, 0.96);
|
||||||
|
--bg-panel-solid: #ffffff;
|
||||||
|
--bg-elevated: #e2e8f0;
|
||||||
|
--bg-hover: #cbd5e1;
|
||||||
|
--border: #cbd5e1;
|
||||||
|
--border-bright: #94a3b8;
|
||||||
|
--text: #0f172a;
|
||||||
|
--text-dim: #475569;
|
||||||
|
--text-faint: #64748b;
|
||||||
|
--brand-blue: #0284c7;
|
||||||
|
--brand-strong: #0369a1;
|
||||||
|
--sim-accent: #0284c7;
|
||||||
|
--sim-accent-dim: rgba(2, 132, 199, 0.25);
|
||||||
|
--sim-glow: rgba(2, 132, 199, 0.12);
|
||||||
|
--green: #059669;
|
||||||
|
--amber: #d97706;
|
||||||
|
--red: #dc2626;
|
||||||
|
--violet: #7c3aed;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root[data-color-mode="light"] body::before {
|
||||||
|
background-image:
|
||||||
|
radial-gradient(circle at 50% 10%, rgba(2, 132, 199, 0.08), transparent 60%),
|
||||||
|
linear-gradient(rgba(15, 23, 42, 0.03) 1px, transparent 1px),
|
||||||
|
linear-gradient(90deg, rgba(15, 23, 42, 0.03) 1px, transparent 1px);
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .menu-title {
|
||||||
|
color: #0f172a;
|
||||||
|
text-shadow: none;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .menu-brand-pill {
|
||||||
|
background: rgba(255, 255, 255, 0.92);
|
||||||
|
color: #0369a1;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .btn.primary {
|
||||||
|
background: #0284c7;
|
||||||
|
border-color: #0369a1;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .btn.primary:hover:not(:disabled) {
|
||||||
|
background: #0369a1;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .btn.warn {
|
||||||
|
background: rgba(217, 119, 6, 0.14);
|
||||||
|
color: #92400e;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .btn.danger {
|
||||||
|
background: rgba(220, 38, 38, 0.12);
|
||||||
|
color: #991b1b;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .btn.ghost {
|
||||||
|
background: #ffffff;
|
||||||
|
border-color: #cbd5e1;
|
||||||
|
color: #475569;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .badge {
|
||||||
|
background: #f8fafc;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .dash-header {
|
||||||
|
background: linear-gradient(180deg, rgba(241, 245, 249, 0.94), transparent);
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .builder-tabs,
|
||||||
|
:root[data-color-mode="light"] .slot-group,
|
||||||
|
:root[data-color-mode="light"] .builder-summary-bar,
|
||||||
|
:root[data-color-mode="light"] .builder-coop-bar {
|
||||||
|
background: #f8fafc;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .launch-hud,
|
||||||
|
:root[data-color-mode="light"] .launch-events,
|
||||||
|
:root[data-color-mode="light"] .notif-toggle-bar,
|
||||||
|
:root[data-color-mode="light"] .notif-mini-pill {
|
||||||
|
background: rgba(255, 255, 255, 0.95);
|
||||||
|
box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .modal-overlay {
|
||||||
|
background: rgba(15, 23, 42, 0.42);
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .value-bar-track {
|
||||||
|
background: #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root.reduced-effects {
|
||||||
|
--chamfer: none;
|
||||||
|
--chamfer-sm: none;
|
||||||
|
--sim-glow: transparent;
|
||||||
|
}
|
||||||
|
:root.reduced-effects body::before {
|
||||||
|
background-image: none !important;
|
||||||
|
}
|
||||||
|
:root.reduced-effects *,
|
||||||
|
:root.reduced-effects *::before,
|
||||||
|
:root.reduced-effects *::after {
|
||||||
|
text-shadow: none !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
backdrop-filter: none !important;
|
||||||
|
-webkit-backdrop-filter: none !important;
|
||||||
|
animation: none !important;
|
||||||
|
transition-duration: 0.05s !important;
|
||||||
|
}
|
||||||
|
:root.reduced-effects .panel,
|
||||||
|
:root.reduced-effects .card,
|
||||||
|
:root.reduced-effects .btn,
|
||||||
|
:root.reduced-effects .input,
|
||||||
|
:root.reduced-effects .badge,
|
||||||
|
:root.reduced-effects .stat-box,
|
||||||
|
:root.reduced-effects .stage-card,
|
||||||
|
:root.reduced-effects .rule-item,
|
||||||
|
:root.reduced-effects .launch-hud,
|
||||||
|
:root.reduced-effects .launch-events,
|
||||||
|
:root.reduced-effects .comfort-btn,
|
||||||
|
:root.reduced-effects .notif-toggle-bar,
|
||||||
|
:root.reduced-effects .hud-tooltip {
|
||||||
|
clip-path: none !important;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.term-wrap {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tip-badge {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 1px solid var(--border-bright);
|
||||||
|
background: rgba(15, 23, 42, 0.72);
|
||||||
|
color: var(--text-dim);
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 700;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: help;
|
||||||
|
flex-shrink: 0;
|
||||||
|
transition: color 0.14s, border-color 0.14s, background 0.14s;
|
||||||
|
}
|
||||||
|
.tip-badge:hover,
|
||||||
|
.tip-badge:focus-visible {
|
||||||
|
color: var(--sim-accent);
|
||||||
|
border-color: var(--sim-accent);
|
||||||
|
background: rgba(96, 165, 250, 0.16);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hud-tooltip {
|
||||||
|
position: fixed;
|
||||||
|
z-index: 9500;
|
||||||
|
max-width: min(320px, calc(100vw - 20px));
|
||||||
|
padding: 9px 11px;
|
||||||
|
background: var(--bg-panel-solid);
|
||||||
|
border: 1px solid var(--sim-accent);
|
||||||
|
clip-path: var(--chamfer-sm);
|
||||||
|
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55), 0 0 14px var(--sim-glow);
|
||||||
|
pointer-events: none;
|
||||||
|
color: var(--text);
|
||||||
|
font-family: var(--sans);
|
||||||
|
}
|
||||||
|
.hud-tooltip[hidden] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.hud-tooltip-cat {
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 9px;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: var(--sim-accent);
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
.hud-tooltip-title {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--text);
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
.hud-tooltip-body {
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 1.45;
|
||||||
|
color: var(--text-dim);
|
||||||
|
}
|
||||||
|
.hud-tooltip-formula {
|
||||||
|
margin-top: 6px;
|
||||||
|
padding: 4px 6px;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: rgba(15, 23, 42, 0.75);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--brand-blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
:root[data-color-mode="light"] .tip-badge {
|
||||||
|
background: #e2e8f0;
|
||||||
|
border-color: #94a3b8;
|
||||||
|
color: #334155;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .tip-badge:hover,
|
||||||
|
:root[data-color-mode="light"] .tip-badge:focus-visible {
|
||||||
|
background: rgba(2, 132, 199, 0.14);
|
||||||
|
border-color: #0284c7;
|
||||||
|
color: #0369a1;
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .hud-tooltip {
|
||||||
|
background: #ffffff;
|
||||||
|
border-color: #0284c7;
|
||||||
|
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
|
||||||
|
}
|
||||||
|
:root[data-color-mode="light"] .hud-tooltip-formula {
|
||||||
|
background: #f1f5f9;
|
||||||
|
border-color: #cbd5e1;
|
||||||
|
color: #0369a1;
|
||||||
|
}
|
||||||
99
public/css/tokens.css
Normal file
99
public/css/tokens.css
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
/* ### Oh wait I can't say that. */
|
||||||
|
:root {
|
||||||
|
--bg-deep: #0b0e14;
|
||||||
|
--bg-panel: rgba(18, 22, 31, 0.92);
|
||||||
|
--bg-panel-solid: #12161f;
|
||||||
|
--bg-elevated: #19202e;
|
||||||
|
--bg-hover: #212a3c;
|
||||||
|
--border: #2a3449;
|
||||||
|
--border-bright: #3d4d6b;
|
||||||
|
--text: #e2e8f0;
|
||||||
|
--text-dim: #94a3b8;
|
||||||
|
--text-faint: #64748b;
|
||||||
|
--brand-blue: #60a5fa;
|
||||||
|
--brand-strong: #3498db;
|
||||||
|
--sim-accent: #60a5fa;
|
||||||
|
--sim-accent-dim: rgba(96, 165, 250, 0.25);
|
||||||
|
--sim-glow: rgba(96, 165, 250, 0.14);
|
||||||
|
--green: #34d399;
|
||||||
|
--amber: #f59e0b;
|
||||||
|
--red: #f87171;
|
||||||
|
--violet: #a78bfa;
|
||||||
|
--mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
|
||||||
|
--sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
--chamfer: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
|
||||||
|
--chamfer-sm: polygon(0 0, calc(100% - 7px) 0, 100% 7px, 100% 100%, 7px 100%, 0 calc(100% - 7px));
|
||||||
|
}
|
||||||
|
|
||||||
|
body[data-target="lunar"], body[data-target="moon-landing"] {
|
||||||
|
--sim-accent: #93c5fd;
|
||||||
|
--sim-accent-dim: rgba(147, 197, 253, 0.26);
|
||||||
|
--sim-glow: rgba(147, 197, 253, 0.14);
|
||||||
|
}
|
||||||
|
body[data-target="mars"] {
|
||||||
|
--sim-accent: #fb923c;
|
||||||
|
--sim-accent-dim: rgba(251, 146, 60, 0.28);
|
||||||
|
--sim-glow: rgba(251, 146, 60, 0.14);
|
||||||
|
}
|
||||||
|
body[data-target="jupiter"], body[data-target="asteroid"] {
|
||||||
|
--sim-accent: #a78bfa;
|
||||||
|
--sim-accent-dim: rgba(167, 139, 250, 0.28);
|
||||||
|
--sim-glow: rgba(167, 139, 250, 0.14);
|
||||||
|
}
|
||||||
|
body[data-target="solar"], body[data-target="l1"] {
|
||||||
|
--sim-accent: #fbbf24;
|
||||||
|
--sim-accent-dim: rgba(251, 191, 36, 0.28);
|
||||||
|
--sim-glow: rgba(251, 191, 36, 0.14);
|
||||||
|
}
|
||||||
|
|
||||||
|
body[data-weather="solar-wind"] {
|
||||||
|
--sim-accent: #38bdf8;
|
||||||
|
--sim-accent-dim: rgba(56, 189, 248, 0.30);
|
||||||
|
--sim-glow: rgba(56, 189, 248, 0.16);
|
||||||
|
}
|
||||||
|
body[data-weather="solar-storm"] {
|
||||||
|
--sim-accent: #f59e0b;
|
||||||
|
--sim-accent-dim: rgba(245, 158, 11, 0.34);
|
||||||
|
--sim-glow: rgba(245, 158, 11, 0.18);
|
||||||
|
}
|
||||||
|
body[data-weather="radiation-storm"] {
|
||||||
|
--sim-accent: #f87171;
|
||||||
|
--sim-accent-dim: rgba(248, 113, 113, 0.34);
|
||||||
|
--sim-glow: rgba(248, 113, 113, 0.18);
|
||||||
|
}
|
||||||
|
body[data-weather="micrometeoroid"] {
|
||||||
|
--sim-accent: #c084fc;
|
||||||
|
--sim-accent-dim: rgba(192, 132, 252, 0.32);
|
||||||
|
--sim-glow: rgba(192, 132, 252, 0.16);
|
||||||
|
}
|
||||||
|
body[data-dynamic-theme="off"] {
|
||||||
|
--sim-accent: var(--brand-blue);
|
||||||
|
--sim-accent-dim: rgba(96, 165, 250, 0.25);
|
||||||
|
--sim-glow: rgba(96, 165, 250, 0.14);
|
||||||
|
}
|
||||||
|
|
||||||
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
height: 100%;
|
||||||
|
background: var(--bg-deep);
|
||||||
|
color: var(--text);
|
||||||
|
font-family: var(--sans);
|
||||||
|
font-size: 14px;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: background-color 0.6s ease, color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
body::before {
|
||||||
|
content: '';
|
||||||
|
position: fixed; inset: 0; pointer-events: none; z-index: 0;
|
||||||
|
background-image:
|
||||||
|
radial-gradient(circle at 50% 15%, var(--sim-glow), transparent 65%),
|
||||||
|
linear-gradient(rgba(148, 163, 184, 0.03) 1px, transparent 1px),
|
||||||
|
linear-gradient(90deg, rgba(148, 163, 184, 0.03) 1px, transparent 1px);
|
||||||
|
background-size: 100% 100%, 44px 44px, 44px 44px;
|
||||||
|
transition: background 0.6s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
#app { height: 100vh; width: 100vw; position: relative; z-index: 1; }
|
||||||
|
#app > * { position: absolute; inset: 0; }
|
||||||
24
public/index.html
Normal file
24
public/index.html
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<!--
|
||||||
|
Space Gaem: You Will Feel the Pain
|
||||||
|
GsDistance.org 2026 - Made by [tyuXX] for NASA Spaceapps Challenge 2026
|
||||||
|
-->
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Space Gaem: You Will Feel the Pain · GsDistance</title>
|
||||||
|
<style>html, body { margin: 0; padding: 0; background: #0b0e14; color: #e2e8f0; }</style>
|
||||||
|
<link rel="stylesheet" href="/bundle/style.css" />
|
||||||
|
</head>
|
||||||
|
<body data-weather="nominal" data-target="earth" data-phase="idle">
|
||||||
|
<div id="app"></div>
|
||||||
|
<div id="modal-root"></div>
|
||||||
|
<div id="toast-root"></div>
|
||||||
|
<div id="hud-bottom-right">
|
||||||
|
<div id="comfort-controls-root"></div>
|
||||||
|
<div id="notif-drawer-root"></div>
|
||||||
|
</div>
|
||||||
|
<script type="module" src="/bundle/app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1751
public/vendor/addons/controls/OrbitControls.js
vendored
Normal file
1751
public/vendor/addons/controls/OrbitControls.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
170
public/vendor/addons/environments/RoomEnvironment.js
vendored
Normal file
170
public/vendor/addons/environments/RoomEnvironment.js
vendored
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
import {
|
||||||
|
BackSide,
|
||||||
|
BoxGeometry,
|
||||||
|
InstancedMesh,
|
||||||
|
Mesh,
|
||||||
|
MeshLambertMaterial,
|
||||||
|
MeshStandardMaterial,
|
||||||
|
PointLight,
|
||||||
|
Scene,
|
||||||
|
Object3D,
|
||||||
|
} from "three";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a scene with a basic room setup that can be used as
|
||||||
|
* input for {@link PMREMGenerator#fromScene}. The resulting PMREM represents the room's
|
||||||
|
* lighting and can be used for Image Based Lighting by assigning it to {@link Scene#environment}
|
||||||
|
* or directly as an environment map to PBR materials.
|
||||||
|
*
|
||||||
|
* The implementation is based on the [EnvironmentScene](https://github.com/google/model-viewer/blob/master/packages/model-viewer/src/three-components/EnvironmentScene.ts)
|
||||||
|
* component from the `model-viewer` project.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const environment = new RoomEnvironment();
|
||||||
|
* const pmremGenerator = new THREE.PMREMGenerator( renderer );
|
||||||
|
*
|
||||||
|
* const envMap = pmremGenerator.fromScene( environment ).texture;
|
||||||
|
* scene.environment = envMap;
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @augments Scene
|
||||||
|
* @three_import import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
|
||||||
|
*/
|
||||||
|
class RoomEnvironment extends Scene {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "RoomEnvironment";
|
||||||
|
this.position.y = -3.5;
|
||||||
|
|
||||||
|
const geometry = new BoxGeometry();
|
||||||
|
geometry.deleteAttribute("uv");
|
||||||
|
|
||||||
|
const roomMaterial = new MeshStandardMaterial({ side: BackSide });
|
||||||
|
const boxMaterial = new MeshStandardMaterial();
|
||||||
|
|
||||||
|
const mainLight = new PointLight(0xffffff, 900, 28, 2);
|
||||||
|
mainLight.position.set(0.418, 16.199, 0.3);
|
||||||
|
this.add(mainLight);
|
||||||
|
|
||||||
|
const room = new Mesh(geometry, roomMaterial);
|
||||||
|
room.position.set(-0.757, 13.219, 0.717);
|
||||||
|
room.scale.set(31.713, 28.305, 28.591);
|
||||||
|
this.add(room);
|
||||||
|
|
||||||
|
const boxes = new InstancedMesh(geometry, boxMaterial, 6);
|
||||||
|
const transform = new Object3D();
|
||||||
|
|
||||||
|
// box1
|
||||||
|
transform.position.set(-10.906, 2.009, 1.846);
|
||||||
|
transform.rotation.set(0, -0.195, 0);
|
||||||
|
transform.scale.set(2.328, 7.905, 4.651);
|
||||||
|
transform.updateMatrix();
|
||||||
|
boxes.setMatrixAt(0, transform.matrix);
|
||||||
|
|
||||||
|
// box2
|
||||||
|
transform.position.set(-5.607, -0.754, -0.758);
|
||||||
|
transform.rotation.set(0, 0.994, 0);
|
||||||
|
transform.scale.set(1.97, 1.534, 3.955);
|
||||||
|
transform.updateMatrix();
|
||||||
|
boxes.setMatrixAt(1, transform.matrix);
|
||||||
|
|
||||||
|
// box3
|
||||||
|
transform.position.set(6.167, 0.857, 7.803);
|
||||||
|
transform.rotation.set(0, 0.561, 0);
|
||||||
|
transform.scale.set(3.927, 6.285, 3.687);
|
||||||
|
transform.updateMatrix();
|
||||||
|
boxes.setMatrixAt(2, transform.matrix);
|
||||||
|
|
||||||
|
// box4
|
||||||
|
transform.position.set(-2.017, 0.018, 6.124);
|
||||||
|
transform.rotation.set(0, 0.333, 0);
|
||||||
|
transform.scale.set(2.002, 4.566, 2.064);
|
||||||
|
transform.updateMatrix();
|
||||||
|
boxes.setMatrixAt(3, transform.matrix);
|
||||||
|
|
||||||
|
// box5
|
||||||
|
transform.position.set(2.291, -0.756, -2.621);
|
||||||
|
transform.rotation.set(0, -0.286, 0);
|
||||||
|
transform.scale.set(1.546, 1.552, 1.496);
|
||||||
|
transform.updateMatrix();
|
||||||
|
boxes.setMatrixAt(4, transform.matrix);
|
||||||
|
|
||||||
|
// box6
|
||||||
|
transform.position.set(-2.193, -0.369, -5.547);
|
||||||
|
transform.rotation.set(0, 0.516, 0);
|
||||||
|
transform.scale.set(3.875, 3.487, 2.986);
|
||||||
|
transform.updateMatrix();
|
||||||
|
boxes.setMatrixAt(5, transform.matrix);
|
||||||
|
|
||||||
|
this.add(boxes);
|
||||||
|
|
||||||
|
// -x right
|
||||||
|
const light1 = new Mesh(geometry, createAreaLightMaterial(50));
|
||||||
|
light1.position.set(-16.116, 14.37, 8.208);
|
||||||
|
light1.scale.set(0.1, 2.428, 2.739);
|
||||||
|
this.add(light1);
|
||||||
|
|
||||||
|
// -x left
|
||||||
|
const light2 = new Mesh(geometry, createAreaLightMaterial(50));
|
||||||
|
light2.position.set(-16.109, 18.021, -8.207);
|
||||||
|
light2.scale.set(0.1, 2.425, 2.751);
|
||||||
|
this.add(light2);
|
||||||
|
|
||||||
|
// +x
|
||||||
|
const light3 = new Mesh(geometry, createAreaLightMaterial(17));
|
||||||
|
light3.position.set(14.904, 12.198, -1.832);
|
||||||
|
light3.scale.set(0.15, 4.265, 6.331);
|
||||||
|
this.add(light3);
|
||||||
|
|
||||||
|
// +z
|
||||||
|
const light4 = new Mesh(geometry, createAreaLightMaterial(43));
|
||||||
|
light4.position.set(-0.462, 8.89, 14.52);
|
||||||
|
light4.scale.set(4.38, 5.441, 0.088);
|
||||||
|
this.add(light4);
|
||||||
|
|
||||||
|
// -z
|
||||||
|
const light5 = new Mesh(geometry, createAreaLightMaterial(20));
|
||||||
|
light5.position.set(3.235, 11.486, -12.541);
|
||||||
|
light5.scale.set(2.5, 2.0, 0.1);
|
||||||
|
this.add(light5);
|
||||||
|
|
||||||
|
// +y
|
||||||
|
const light6 = new Mesh(geometry, createAreaLightMaterial(100));
|
||||||
|
light6.position.set(0.0, 20.0, 0.0);
|
||||||
|
light6.scale.set(1.0, 0.1, 1.0);
|
||||||
|
this.add(light6);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees internal resources. This method should be called
|
||||||
|
* when the environment is no longer required.
|
||||||
|
*/
|
||||||
|
dispose() {
|
||||||
|
const resources = new Set();
|
||||||
|
|
||||||
|
this.traverse((object) => {
|
||||||
|
if (object.isMesh) {
|
||||||
|
resources.add(object.geometry);
|
||||||
|
resources.add(object.material);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const resource of resources) {
|
||||||
|
resource.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAreaLightMaterial(intensity) {
|
||||||
|
// create an emissive-only material. see #31348
|
||||||
|
const material = new MeshLambertMaterial({
|
||||||
|
color: 0x000000,
|
||||||
|
emissive: 0xffffff,
|
||||||
|
emissiveIntensity: intensity,
|
||||||
|
});
|
||||||
|
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { RoomEnvironment };
|
||||||
31
public/vendor/addons/libs/draco/README.md
vendored
Normal file
31
public/vendor/addons/libs/draco/README.md
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Draco 3D Data Compression
|
||||||
|
|
||||||
|
Draco is an open-source library for compressing and decompressing 3D geometric meshes and point clouds. It is intended to improve the storage and transmission of 3D graphics.
|
||||||
|
|
||||||
|
[Website](https://google.github.io/draco/) | [GitHub](https://github.com/google/draco)
|
||||||
|
|
||||||
|
## Contents
|
||||||
|
|
||||||
|
This folder contains three utilities:
|
||||||
|
|
||||||
|
* `draco_decoder.js` — Emscripten-compiled decoder, compatible with any modern browser.
|
||||||
|
* `draco_decoder.wasm` — WebAssembly decoder, compatible with newer browsers and devices.
|
||||||
|
* `draco_wasm_wrapper.js` — JavaScript wrapper for the WASM decoder.
|
||||||
|
|
||||||
|
Each file is provided in two variations:
|
||||||
|
|
||||||
|
* **Default:** Latest stable builds, tracking the project's [master branch](https://github.com/google/draco).
|
||||||
|
* **glTF:** Builds targeted by the [glTF mesh compression extension](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression), tracking the [corresponding Draco branch](https://github.com/google/draco/tree/gltf_2.0_draco_extension).
|
||||||
|
|
||||||
|
Either variation may be used with `DRACOLoader`:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var dracoLoader = new DRACOLoader();
|
||||||
|
dracoLoader.setDecoderPath('path/to/decoders/');
|
||||||
|
```
|
||||||
|
|
||||||
|
Further [documentation on GitHub](https://github.com/google/draco/tree/master/javascript/example#static-loading-javascript-decoder).
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[Apache License 2.0](https://github.com/google/draco/blob/master/LICENSE)
|
||||||
74285
public/vendor/addons/libs/draco/draco_decoder.js
vendored
Normal file
74285
public/vendor/addons/libs/draco/draco_decoder.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
public/vendor/addons/libs/draco/draco_decoder.wasm
vendored
Normal file
BIN
public/vendor/addons/libs/draco/draco_decoder.wasm
vendored
Normal file
Binary file not shown.
2537
public/vendor/addons/libs/draco/draco_wasm_wrapper.js
vendored
Normal file
2537
public/vendor/addons/libs/draco/draco_wasm_wrapper.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
50651
public/vendor/addons/libs/draco/gltf/draco_decoder.js
vendored
Normal file
50651
public/vendor/addons/libs/draco/gltf/draco_decoder.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
public/vendor/addons/libs/draco/gltf/draco_decoder.wasm
vendored
Normal file
BIN
public/vendor/addons/libs/draco/gltf/draco_decoder.wasm
vendored
Normal file
Binary file not shown.
2517
public/vendor/addons/libs/draco/gltf/draco_wasm_wrapper.js
vendored
Normal file
2517
public/vendor/addons/libs/draco/gltf/draco_wasm_wrapper.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
735
public/vendor/addons/loaders/DRACOLoader.js
vendored
Normal file
735
public/vendor/addons/loaders/DRACOLoader.js
vendored
Normal file
|
|
@ -0,0 +1,735 @@
|
||||||
|
import {
|
||||||
|
BufferAttribute,
|
||||||
|
BufferGeometry,
|
||||||
|
Color,
|
||||||
|
ColorManagement,
|
||||||
|
FileLoader,
|
||||||
|
Loader,
|
||||||
|
LinearSRGBColorSpace,
|
||||||
|
SRGBColorSpace,
|
||||||
|
InterleavedBuffer,
|
||||||
|
InterleavedBufferAttribute,
|
||||||
|
LoaderUtils,
|
||||||
|
} from "three";
|
||||||
|
|
||||||
|
const _taskCache = new WeakMap();
|
||||||
|
|
||||||
|
const WASM_BIN_URL = new URL(
|
||||||
|
"../libs/draco/draco_decoder.wasm",
|
||||||
|
import.meta.url,
|
||||||
|
).toString();
|
||||||
|
const WASM_JS_URL = new URL(
|
||||||
|
"../libs/draco/draco_wasm_wrapper.js",
|
||||||
|
import.meta.url,
|
||||||
|
).toString();
|
||||||
|
const JS_URL = new URL(
|
||||||
|
"../libs/draco/draco_decoder.js",
|
||||||
|
import.meta.url,
|
||||||
|
).toString();
|
||||||
|
|
||||||
|
const DRACO_GLTF_CONFIG = {
|
||||||
|
js: new URL(
|
||||||
|
"../libs/draco/gltf/draco_wasm_wrapper.js",
|
||||||
|
import.meta.url,
|
||||||
|
).toString(),
|
||||||
|
wasm: new URL(
|
||||||
|
"../libs/draco/gltf/draco_decoder.wasm",
|
||||||
|
import.meta.url,
|
||||||
|
).toString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A loader for the Draco format.
|
||||||
|
*
|
||||||
|
* [Draco](https://google.github.io/draco/) is an open source library for compressing
|
||||||
|
* and decompressing 3D meshes and point clouds. Compressed geometry can be significantly smaller,
|
||||||
|
* at the cost of additional decoding time on the client device.
|
||||||
|
*
|
||||||
|
* Standalone Draco files have a `.drc` extension, and contain vertex positions, normals, colors,
|
||||||
|
* and other attributes. Draco files do not contain materials, textures, animation, or node hierarchies –
|
||||||
|
* to use these features, embed Draco geometry inside of a glTF file. A normal glTF file can be converted
|
||||||
|
* to a Draco-compressed glTF file using [glTF-Pipeline](https://github.com/CesiumGS/gltf-pipeline).
|
||||||
|
* When using Draco with glTF, an instance of `DRACOLoader` will be used internally by {@link GLTFLoader}.
|
||||||
|
*
|
||||||
|
* It is recommended to create one DRACOLoader instance and reuse it to avoid loading and creating
|
||||||
|
* multiple decoder instances.
|
||||||
|
*
|
||||||
|
* `DRACOLoader` will automatically use either the JS or the WASM decoding library, based on
|
||||||
|
* browser capabilities.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const loader = new DRACOLoader();
|
||||||
|
* const geometry = await loader.loadAsync( 'models/draco/bunny.drc' );
|
||||||
|
* geometry.computeVertexNormals(); // optional
|
||||||
|
*
|
||||||
|
* loader.dispose();
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @augments Loader
|
||||||
|
* @three_import import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
|
||||||
|
*/
|
||||||
|
class DRACOLoader extends Loader {
|
||||||
|
/**
|
||||||
|
* Constructs a new Draco loader.
|
||||||
|
*
|
||||||
|
* @param {LoadingManager} [manager] - The loading manager.
|
||||||
|
*/
|
||||||
|
constructor(manager) {
|
||||||
|
super(manager);
|
||||||
|
|
||||||
|
this.decoderPaths = {
|
||||||
|
js: WASM_JS_URL,
|
||||||
|
wasm: WASM_BIN_URL,
|
||||||
|
dep_js: JS_URL,
|
||||||
|
};
|
||||||
|
this.decoderConfig = {};
|
||||||
|
this.decoderBinary = null;
|
||||||
|
this.decoderPending = null;
|
||||||
|
|
||||||
|
this.workerLimit = 4;
|
||||||
|
this.workerPool = [];
|
||||||
|
this.workerNextTaskID = 1;
|
||||||
|
this.workerSourceURL = "";
|
||||||
|
|
||||||
|
this.defaultAttributeIDs = {
|
||||||
|
position: "POSITION",
|
||||||
|
normal: "NORMAL",
|
||||||
|
color: "COLOR",
|
||||||
|
uv: "TEX_COORD",
|
||||||
|
};
|
||||||
|
this.defaultAttributeTypes = {
|
||||||
|
position: "Float32Array",
|
||||||
|
normal: "Float32Array",
|
||||||
|
color: "Float32Array",
|
||||||
|
uv: "Float32Array",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
|
||||||
|
*
|
||||||
|
* @param {string|{js:string, wasm:string}} path - The decoder path, or a config object with explicit URLs for each decoder file.
|
||||||
|
* @return {DRACOLoader} A reference to this loader.
|
||||||
|
*/
|
||||||
|
setDecoderPath(path) {
|
||||||
|
const { decoderPaths } = this;
|
||||||
|
if (typeof path === "object") {
|
||||||
|
decoderPaths.js = path.js;
|
||||||
|
decoderPaths.wasm = path.wasm;
|
||||||
|
decoderPaths.dep_js = null;
|
||||||
|
} else {
|
||||||
|
decoderPaths.js = LoaderUtils.resolveURL("draco_wasm_wrapper.js", path);
|
||||||
|
decoderPaths.wasm = LoaderUtils.resolveURL("draco_decoder.wasm", path);
|
||||||
|
decoderPaths.dep_js = LoaderUtils.resolveURL("draco_decoder.js", path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* @param {{type:('js'|'wasm')}} config - The decoder config.
|
||||||
|
* @return {DRACOLoader} A reference to this loader.
|
||||||
|
*/
|
||||||
|
setDecoderConfig(config) {
|
||||||
|
console.warn(
|
||||||
|
"THREE.DRACOLoader: setDecoderConfig to has been deprecated and will be removed in r194.",
|
||||||
|
);
|
||||||
|
this.decoderConfig = config;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the maximum number of Web Workers to be used during decoding.
|
||||||
|
* A lower limit may be preferable if workers are also for other tasks in the application.
|
||||||
|
*
|
||||||
|
* @param {number} workerLimit - The worker limit.
|
||||||
|
* @return {DRACOLoader} A reference to this loader.
|
||||||
|
*/
|
||||||
|
setWorkerLimit(workerLimit) {
|
||||||
|
this.workerLimit = workerLimit;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts loading from the given URL and passes the loaded Draco asset
|
||||||
|
* to the `onLoad()` callback.
|
||||||
|
*
|
||||||
|
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
|
||||||
|
* @param {function(BufferGeometry)} onLoad - Executed when the loading process has been finished.
|
||||||
|
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
|
||||||
|
* @param {onErrorCallback} onError - Executed when errors occur.
|
||||||
|
*/
|
||||||
|
load(url, onLoad, onProgress, onError) {
|
||||||
|
const loader = new FileLoader(this.manager);
|
||||||
|
loader.setPriority(this.priority);
|
||||||
|
loader.setCache(this.cache);
|
||||||
|
|
||||||
|
loader.setPath(this.path);
|
||||||
|
loader.setResponseType("arraybuffer");
|
||||||
|
loader.setRequestHeader(this.requestHeader);
|
||||||
|
loader.setWithCredentials(this.withCredentials);
|
||||||
|
|
||||||
|
loader.load(
|
||||||
|
url,
|
||||||
|
(buffer) => {
|
||||||
|
this.parse(buffer, onLoad, onError);
|
||||||
|
},
|
||||||
|
onProgress,
|
||||||
|
onError,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given Draco data.
|
||||||
|
*
|
||||||
|
* @param {ArrayBuffer} buffer - The raw Draco data as an array buffer.
|
||||||
|
* @param {function(BufferGeometry)} onLoad - Executed when the loading/parsing process has been finished.
|
||||||
|
* @param {onErrorCallback} onError - Executed when errors occur.
|
||||||
|
*/
|
||||||
|
parse(buffer, onLoad, onError = () => {}) {
|
||||||
|
this.decodeDracoFile(
|
||||||
|
buffer,
|
||||||
|
onLoad,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
SRGBColorSpace,
|
||||||
|
onError,
|
||||||
|
).catch(onError);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
decodeDracoFile(
|
||||||
|
buffer,
|
||||||
|
callback,
|
||||||
|
attributeIDs,
|
||||||
|
attributeTypes,
|
||||||
|
vertexColorSpace = LinearSRGBColorSpace,
|
||||||
|
onError = () => {},
|
||||||
|
) {
|
||||||
|
const taskConfig = {
|
||||||
|
attributeIDs: attributeIDs || this.defaultAttributeIDs,
|
||||||
|
attributeTypes: attributeTypes || this.defaultAttributeTypes,
|
||||||
|
useUniqueIDs: !!attributeIDs,
|
||||||
|
vertexColorSpace: vertexColorSpace,
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.decodeGeometry(buffer, taskConfig)
|
||||||
|
.then(callback)
|
||||||
|
.catch(onError);
|
||||||
|
}
|
||||||
|
|
||||||
|
decodeGeometry(buffer, taskConfig) {
|
||||||
|
const taskKey = JSON.stringify(taskConfig);
|
||||||
|
|
||||||
|
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
|
||||||
|
// again from this thread.
|
||||||
|
if (_taskCache.has(buffer)) {
|
||||||
|
const cachedTask = _taskCache.get(buffer);
|
||||||
|
|
||||||
|
if (cachedTask.key === taskKey) {
|
||||||
|
return cachedTask.promise;
|
||||||
|
} else if (buffer.byteLength === 0) {
|
||||||
|
// Technically, it would be possible to wait for the previous task to complete,
|
||||||
|
// transfer the buffer back, and decode again with the second configuration. That
|
||||||
|
// is complex, and I don't know of any reason to decode a Draco buffer twice in
|
||||||
|
// different ways, so this is left unimplemented.
|
||||||
|
throw new Error(
|
||||||
|
"THREE.DRACOLoader: Unable to re-decode a buffer with different " +
|
||||||
|
"settings. Buffer has already been transferred.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
let worker;
|
||||||
|
const taskID = this.workerNextTaskID++;
|
||||||
|
const taskCost = buffer.byteLength;
|
||||||
|
|
||||||
|
// Obtain a worker and assign a task, and construct a geometry instance
|
||||||
|
// when the task completes.
|
||||||
|
const geometryPending = this._getWorker(taskID, taskCost)
|
||||||
|
.then((_worker) => {
|
||||||
|
worker = _worker;
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
worker._callbacks[taskID] = { resolve, reject };
|
||||||
|
|
||||||
|
worker.postMessage(
|
||||||
|
{ type: "decode", id: taskID, taskConfig, buffer },
|
||||||
|
[buffer],
|
||||||
|
);
|
||||||
|
|
||||||
|
// this.debug();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then((message) => this._createGeometry(message.geometry));
|
||||||
|
|
||||||
|
// Remove task from the task list.
|
||||||
|
// Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)
|
||||||
|
geometryPending
|
||||||
|
.catch(() => true)
|
||||||
|
.then(() => {
|
||||||
|
if (worker && taskID) {
|
||||||
|
this._releaseTask(worker, taskID);
|
||||||
|
|
||||||
|
// this.debug();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Cache the task result.
|
||||||
|
_taskCache.set(buffer, {
|
||||||
|
key: taskKey,
|
||||||
|
promise: geometryPending,
|
||||||
|
});
|
||||||
|
|
||||||
|
return geometryPending;
|
||||||
|
}
|
||||||
|
|
||||||
|
_createGeometry(geometryData) {
|
||||||
|
const geometry = new BufferGeometry();
|
||||||
|
|
||||||
|
if (geometryData.index) {
|
||||||
|
geometry.setIndex(new BufferAttribute(geometryData.index.array, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < geometryData.attributes.length; i++) {
|
||||||
|
const { name, array, itemSize, stride, vertexColorSpace } =
|
||||||
|
geometryData.attributes[i];
|
||||||
|
|
||||||
|
let attribute;
|
||||||
|
|
||||||
|
if (itemSize === stride) {
|
||||||
|
attribute = new BufferAttribute(array, itemSize);
|
||||||
|
} else {
|
||||||
|
const buffer = new InterleavedBuffer(array, stride);
|
||||||
|
|
||||||
|
attribute = new InterleavedBufferAttribute(buffer, itemSize, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name === "color") {
|
||||||
|
this._assignVertexColorSpace(attribute, vertexColorSpace);
|
||||||
|
|
||||||
|
attribute.normalized = array instanceof Float32Array === false;
|
||||||
|
}
|
||||||
|
|
||||||
|
geometry.setAttribute(name, attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
return geometry;
|
||||||
|
}
|
||||||
|
|
||||||
|
_assignVertexColorSpace(attribute, inputColorSpace) {
|
||||||
|
// While .drc files do not specify colorspace, the only 'official' tooling
|
||||||
|
// is PLY and OBJ converters, which use sRGB. We'll assume sRGB when a .drc
|
||||||
|
// file is passed into .load() or .parse(). GLTFLoader uses internal APIs
|
||||||
|
// to decode geometry, and vertex colors are already Linear-sRGB in there.
|
||||||
|
|
||||||
|
if (inputColorSpace !== SRGBColorSpace) return;
|
||||||
|
|
||||||
|
const _color = new Color();
|
||||||
|
|
||||||
|
for (let i = 0, il = attribute.count; i < il; i++) {
|
||||||
|
_color.fromBufferAttribute(attribute, i);
|
||||||
|
ColorManagement.colorSpaceToWorking(_color, SRGBColorSpace);
|
||||||
|
attribute.setXYZ(i, _color.r, _color.g, _color.b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_loadLibrary(url, responseType) {
|
||||||
|
const loader = new FileLoader(this.manager);
|
||||||
|
loader.setPriority(this.priority);
|
||||||
|
loader.setCache(this.cache);
|
||||||
|
loader.setResponseType(responseType);
|
||||||
|
loader.setWithCredentials(this.withCredentials);
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
loader.load(url, resolve, undefined, reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
preload() {
|
||||||
|
this._initDecoder();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
_initDecoder() {
|
||||||
|
if (this.decoderPending) return this.decoderPending;
|
||||||
|
|
||||||
|
const useJS =
|
||||||
|
typeof WebAssembly !== "object" || this.decoderConfig.type === "js";
|
||||||
|
const librariesPending = [];
|
||||||
|
|
||||||
|
const { decoderPaths } = this;
|
||||||
|
if (useJS) {
|
||||||
|
if (decoderPaths.dep_js === null) {
|
||||||
|
throw new Error(
|
||||||
|
"THREE.DRACOLoader: WebAssembly is required when using a custom decoder paths.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
librariesPending.push(this._loadLibrary(decoderPaths.dep_js, "text"));
|
||||||
|
} else {
|
||||||
|
librariesPending.push(this._loadLibrary(decoderPaths.js, "text"));
|
||||||
|
librariesPending.push(
|
||||||
|
this._loadLibrary(decoderPaths.wasm, "arraybuffer"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.decoderPending = Promise.all(librariesPending).then((libraries) => {
|
||||||
|
const jsContent = libraries[0];
|
||||||
|
|
||||||
|
if (!useJS) {
|
||||||
|
this.decoderConfig.wasmBinary = libraries[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn = DRACOWorker.toString();
|
||||||
|
|
||||||
|
const body = [
|
||||||
|
"/* draco decoder */",
|
||||||
|
jsContent,
|
||||||
|
"",
|
||||||
|
"/* worker */",
|
||||||
|
fn.substring(fn.indexOf("{") + 1, fn.lastIndexOf("}")),
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
this.workerSourceURL = URL.createObjectURL(new Blob([body]));
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.decoderPending;
|
||||||
|
}
|
||||||
|
|
||||||
|
_getWorker(taskID, taskCost) {
|
||||||
|
return this._initDecoder().then(() => {
|
||||||
|
if (this.workerPool.length < this.workerLimit) {
|
||||||
|
const worker = new Worker(this.workerSourceURL);
|
||||||
|
|
||||||
|
worker._callbacks = {};
|
||||||
|
worker._taskCosts = {};
|
||||||
|
worker._taskLoad = 0;
|
||||||
|
|
||||||
|
worker.postMessage({ type: "init", decoderConfig: this.decoderConfig });
|
||||||
|
|
||||||
|
worker.onmessage = function (e) {
|
||||||
|
const message = e.data;
|
||||||
|
|
||||||
|
switch (message.type) {
|
||||||
|
case "decode":
|
||||||
|
worker._callbacks[message.id].resolve(message);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "error":
|
||||||
|
worker._callbacks[message.id].reject(message);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
console.error(
|
||||||
|
'THREE.DRACOLoader: Unexpected message, "' + message.type + '"',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.workerPool.push(worker);
|
||||||
|
} else {
|
||||||
|
this.workerPool.sort(function (a, b) {
|
||||||
|
return a._taskLoad > b._taskLoad ? -1 : 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const worker = this.workerPool[this.workerPool.length - 1];
|
||||||
|
worker._taskCosts[taskID] = taskCost;
|
||||||
|
worker._taskLoad += taskCost;
|
||||||
|
return worker;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_releaseTask(worker, taskID) {
|
||||||
|
worker._taskLoad -= worker._taskCosts[taskID];
|
||||||
|
delete worker._callbacks[taskID];
|
||||||
|
delete worker._taskCosts[taskID];
|
||||||
|
}
|
||||||
|
|
||||||
|
debug() {
|
||||||
|
console.log(
|
||||||
|
"Task load: ",
|
||||||
|
this.workerPool.map((worker) => worker._taskLoad),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
dispose() {
|
||||||
|
for (let i = 0; i < this.workerPool.length; ++i) {
|
||||||
|
this.workerPool[i].terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.workerPool.length = 0;
|
||||||
|
|
||||||
|
if (this.workerSourceURL !== "") {
|
||||||
|
URL.revokeObjectURL(this.workerSourceURL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* WEB WORKER */
|
||||||
|
|
||||||
|
function DRACOWorker() {
|
||||||
|
let decoderConfig;
|
||||||
|
let decoderPending;
|
||||||
|
|
||||||
|
onmessage = function (e) {
|
||||||
|
const message = e.data;
|
||||||
|
|
||||||
|
switch (message.type) {
|
||||||
|
case "init":
|
||||||
|
decoderConfig = message.decoderConfig;
|
||||||
|
decoderPending = new Promise(function (resolve /*, reject*/) {
|
||||||
|
decoderConfig.onModuleLoaded = function (draco) {
|
||||||
|
// Module is Promise-like. Wrap before resolving to avoid loop.
|
||||||
|
resolve({ draco: draco });
|
||||||
|
};
|
||||||
|
|
||||||
|
DracoDecoderModule(decoderConfig); // eslint-disable-line no-undef
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "decode":
|
||||||
|
const buffer = message.buffer;
|
||||||
|
const taskConfig = message.taskConfig;
|
||||||
|
decoderPending.then((module) => {
|
||||||
|
const draco = module.draco;
|
||||||
|
const decoder = new draco.Decoder();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const geometry = decodeGeometry(
|
||||||
|
draco,
|
||||||
|
decoder,
|
||||||
|
new Int8Array(buffer),
|
||||||
|
taskConfig,
|
||||||
|
);
|
||||||
|
|
||||||
|
const buffers = geometry.attributes.map(
|
||||||
|
(attr) => attr.array.buffer,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (geometry.index) buffers.push(geometry.index.array.buffer);
|
||||||
|
|
||||||
|
self.postMessage(
|
||||||
|
{ type: "decode", id: message.id, geometry },
|
||||||
|
buffers,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
self.postMessage({
|
||||||
|
type: "error",
|
||||||
|
id: message.id,
|
||||||
|
error: error.message,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
draco.destroy(decoder);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function decodeGeometry(draco, decoder, array, taskConfig) {
|
||||||
|
const attributeIDs = taskConfig.attributeIDs;
|
||||||
|
const attributeTypes = taskConfig.attributeTypes;
|
||||||
|
|
||||||
|
let dracoGeometry;
|
||||||
|
let decodingStatus;
|
||||||
|
|
||||||
|
const geometryType = decoder.GetEncodedGeometryType(array);
|
||||||
|
|
||||||
|
if (geometryType === draco.TRIANGULAR_MESH) {
|
||||||
|
dracoGeometry = new draco.Mesh();
|
||||||
|
decodingStatus = decoder.DecodeArrayToMesh(
|
||||||
|
array,
|
||||||
|
array.byteLength,
|
||||||
|
dracoGeometry,
|
||||||
|
);
|
||||||
|
} else if (geometryType === draco.POINT_CLOUD) {
|
||||||
|
dracoGeometry = new draco.PointCloud();
|
||||||
|
decodingStatus = decoder.DecodeArrayToPointCloud(
|
||||||
|
array,
|
||||||
|
array.byteLength,
|
||||||
|
dracoGeometry,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw new Error("THREE.DRACOLoader: Unexpected geometry type.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!decodingStatus.ok() || dracoGeometry.ptr === 0) {
|
||||||
|
throw new Error(
|
||||||
|
"THREE.DRACOLoader: Decoding failed: " + decodingStatus.error_msg(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const geometry = { index: null, attributes: [] };
|
||||||
|
|
||||||
|
// Gather all vertex attributes.
|
||||||
|
for (const attributeName in attributeIDs) {
|
||||||
|
const attributeType = self[attributeTypes[attributeName]];
|
||||||
|
|
||||||
|
let attribute;
|
||||||
|
let attributeID;
|
||||||
|
|
||||||
|
// A Draco file may be created with default vertex attributes, whose attribute IDs
|
||||||
|
// are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
|
||||||
|
// a Draco file may contain a custom set of attributes, identified by known unique
|
||||||
|
// IDs. glTF files always do the latter, and `.drc` files typically do the former.
|
||||||
|
if (taskConfig.useUniqueIDs) {
|
||||||
|
attributeID = attributeIDs[attributeName];
|
||||||
|
attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeID);
|
||||||
|
} else {
|
||||||
|
attributeID = decoder.GetAttributeId(
|
||||||
|
dracoGeometry,
|
||||||
|
draco[attributeIDs[attributeName]],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (attributeID === -1) continue;
|
||||||
|
|
||||||
|
attribute = decoder.GetAttribute(dracoGeometry, attributeID);
|
||||||
|
}
|
||||||
|
|
||||||
|
const attributeResult = decodeAttribute(
|
||||||
|
draco,
|
||||||
|
decoder,
|
||||||
|
dracoGeometry,
|
||||||
|
attributeName,
|
||||||
|
attributeType,
|
||||||
|
attribute,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (attributeName === "color") {
|
||||||
|
attributeResult.vertexColorSpace = taskConfig.vertexColorSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
geometry.attributes.push(attributeResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add index.
|
||||||
|
if (geometryType === draco.TRIANGULAR_MESH) {
|
||||||
|
geometry.index = decodeIndex(draco, decoder, dracoGeometry);
|
||||||
|
}
|
||||||
|
|
||||||
|
draco.destroy(dracoGeometry);
|
||||||
|
|
||||||
|
return geometry;
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeIndex(draco, decoder, dracoGeometry) {
|
||||||
|
const numFaces = dracoGeometry.num_faces();
|
||||||
|
const numIndices = numFaces * 3;
|
||||||
|
const byteLength = numIndices * 4;
|
||||||
|
|
||||||
|
const ptr = draco._malloc(byteLength);
|
||||||
|
decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
|
||||||
|
const index = new Uint32Array(
|
||||||
|
draco.HEAPF32.buffer,
|
||||||
|
ptr,
|
||||||
|
numIndices,
|
||||||
|
).slice();
|
||||||
|
draco._free(ptr);
|
||||||
|
|
||||||
|
return { array: index, itemSize: 1 };
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeAttribute(
|
||||||
|
draco,
|
||||||
|
decoder,
|
||||||
|
dracoGeometry,
|
||||||
|
attributeName,
|
||||||
|
TypedArray,
|
||||||
|
attribute,
|
||||||
|
) {
|
||||||
|
const count = dracoGeometry.num_points();
|
||||||
|
const itemSize = attribute.num_components();
|
||||||
|
const dracoDataType = getDracoDataType(draco, TypedArray);
|
||||||
|
|
||||||
|
// Reference: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#data-alignment
|
||||||
|
const srcByteStride = itemSize * TypedArray.BYTES_PER_ELEMENT;
|
||||||
|
const dstByteStride = Math.ceil(srcByteStride / 4) * 4;
|
||||||
|
|
||||||
|
const dstStride = dstByteStride / TypedArray.BYTES_PER_ELEMENT;
|
||||||
|
|
||||||
|
const srcByteLength = count * srcByteStride;
|
||||||
|
const dstByteLength = count * dstByteStride;
|
||||||
|
|
||||||
|
const ptr = draco._malloc(srcByteLength);
|
||||||
|
decoder.GetAttributeDataArrayForAllPoints(
|
||||||
|
dracoGeometry,
|
||||||
|
attribute,
|
||||||
|
dracoDataType,
|
||||||
|
srcByteLength,
|
||||||
|
ptr,
|
||||||
|
);
|
||||||
|
|
||||||
|
const srcArray = new TypedArray(
|
||||||
|
draco.HEAPF32.buffer,
|
||||||
|
ptr,
|
||||||
|
srcByteLength / TypedArray.BYTES_PER_ELEMENT,
|
||||||
|
);
|
||||||
|
let dstArray;
|
||||||
|
|
||||||
|
if (srcByteStride === dstByteStride) {
|
||||||
|
// THREE.BufferAttribute
|
||||||
|
|
||||||
|
dstArray = srcArray.slice();
|
||||||
|
} else {
|
||||||
|
// THREE.InterleavedBufferAttribute
|
||||||
|
|
||||||
|
dstArray = new TypedArray(dstByteLength / TypedArray.BYTES_PER_ELEMENT);
|
||||||
|
|
||||||
|
let dstOffset = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
for (let j = 0; j < itemSize; j++) {
|
||||||
|
dstArray[dstOffset + j] = srcArray[i * itemSize + j];
|
||||||
|
}
|
||||||
|
|
||||||
|
dstOffset += dstStride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
draco._free(ptr);
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: attributeName,
|
||||||
|
count: count,
|
||||||
|
itemSize: itemSize,
|
||||||
|
array: dstArray,
|
||||||
|
stride: dstStride,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDracoDataType(draco, TypedArray) {
|
||||||
|
switch (TypedArray) {
|
||||||
|
case Float32Array:
|
||||||
|
return draco.DT_FLOAT32;
|
||||||
|
case Int8Array:
|
||||||
|
return draco.DT_INT8;
|
||||||
|
case Int16Array:
|
||||||
|
return draco.DT_INT16;
|
||||||
|
case Int32Array:
|
||||||
|
return draco.DT_INT32;
|
||||||
|
case Uint8Array:
|
||||||
|
return draco.DT_UINT8;
|
||||||
|
case Uint16Array:
|
||||||
|
return draco.DT_UINT16;
|
||||||
|
case Uint32Array:
|
||||||
|
return draco.DT_UINT32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DRACOLoader, DRACO_GLTF_CONFIG };
|
||||||
4629
public/vendor/addons/loaders/GLTFLoader.js
vendored
Normal file
4629
public/vendor/addons/loaders/GLTFLoader.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
337
public/vendor/addons/postprocessing/EffectComposer.js
vendored
Normal file
337
public/vendor/addons/postprocessing/EffectComposer.js
vendored
Normal file
|
|
@ -0,0 +1,337 @@
|
||||||
|
import {
|
||||||
|
HalfFloatType,
|
||||||
|
NoBlending,
|
||||||
|
Timer,
|
||||||
|
Vector2,
|
||||||
|
WebGLRenderTarget,
|
||||||
|
} from "three";
|
||||||
|
import { CopyShader } from "../shaders/CopyShader.js";
|
||||||
|
import { ShaderPass } from "./ShaderPass.js";
|
||||||
|
import { ClearMaskPass, MaskPass } from "./MaskPass.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to implement post-processing effects in three.js.
|
||||||
|
* The class manages a chain of post-processing passes to produce the final visual result.
|
||||||
|
* Post-processing passes are executed in order of their addition/insertion.
|
||||||
|
* The last pass is automatically rendered to screen.
|
||||||
|
*
|
||||||
|
* This module can only be used with {@link WebGLRenderer}.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const composer = new EffectComposer( renderer );
|
||||||
|
*
|
||||||
|
* // adding some passes
|
||||||
|
* const renderPass = new RenderPass( scene, camera );
|
||||||
|
* composer.addPass( renderPass );
|
||||||
|
*
|
||||||
|
* const glitchPass = new GlitchPass();
|
||||||
|
* composer.addPass( glitchPass );
|
||||||
|
*
|
||||||
|
* const outputPass = new OutputPass()
|
||||||
|
* composer.addPass( outputPass );
|
||||||
|
*
|
||||||
|
* function animate() {
|
||||||
|
*
|
||||||
|
* composer.render(); // instead of renderer.render()
|
||||||
|
*
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @three_import import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
|
||||||
|
*/
|
||||||
|
class EffectComposer {
|
||||||
|
/**
|
||||||
|
* Constructs a new effect composer.
|
||||||
|
*
|
||||||
|
* @param {WebGLRenderer} renderer - The renderer.
|
||||||
|
* @param {WebGLRenderTarget} [renderTarget] - This render target and a clone will
|
||||||
|
* be used as the internal read and write buffers. If not given, the composer creates
|
||||||
|
* the buffers automatically.
|
||||||
|
*/
|
||||||
|
constructor(renderer, renderTarget) {
|
||||||
|
/**
|
||||||
|
* The renderer.
|
||||||
|
*
|
||||||
|
* @type {WebGLRenderer}
|
||||||
|
*/
|
||||||
|
this.renderer = renderer;
|
||||||
|
|
||||||
|
this._pixelRatio = renderer.getPixelRatio();
|
||||||
|
|
||||||
|
if (renderTarget === undefined) {
|
||||||
|
const size = renderer.getSize(new Vector2());
|
||||||
|
this._width = size.width;
|
||||||
|
this._height = size.height;
|
||||||
|
|
||||||
|
renderTarget = new WebGLRenderTarget(
|
||||||
|
this._width * this._pixelRatio,
|
||||||
|
this._height * this._pixelRatio,
|
||||||
|
{ type: HalfFloatType },
|
||||||
|
);
|
||||||
|
renderTarget.texture.name = "EffectComposer.rt1";
|
||||||
|
} else {
|
||||||
|
this._width = renderTarget.width;
|
||||||
|
this._height = renderTarget.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderTarget1 = renderTarget;
|
||||||
|
this.renderTarget2 = renderTarget.clone();
|
||||||
|
this.renderTarget2.texture.name = "EffectComposer.rt2";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the internal write buffer. Passes usually write
|
||||||
|
* their result into this buffer.
|
||||||
|
*
|
||||||
|
* @type {WebGLRenderTarget}
|
||||||
|
*/
|
||||||
|
this.writeBuffer = this.renderTarget1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the internal read buffer. Passes usually read
|
||||||
|
* the previous render result from this buffer.
|
||||||
|
*
|
||||||
|
* @type {WebGLRenderTarget}
|
||||||
|
*/
|
||||||
|
this.readBuffer = this.renderTarget2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the final pass is rendered to the screen (default framebuffer) or not.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
this.renderToScreen = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array representing the (ordered) chain of post-processing passes.
|
||||||
|
*
|
||||||
|
* @type {Array<Pass>}
|
||||||
|
*/
|
||||||
|
this.passes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A copy pass used for internal swap operations.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @type {ShaderPass}
|
||||||
|
*/
|
||||||
|
this.copyPass = new ShaderPass(CopyShader);
|
||||||
|
this.copyPass.material.blending = NoBlending;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The internal timer for managing time data.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @type {Timer}
|
||||||
|
*/
|
||||||
|
this.timer = new Timer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps the internal read/write buffers.
|
||||||
|
*/
|
||||||
|
swapBuffers() {
|
||||||
|
const tmp = this.readBuffer;
|
||||||
|
this.readBuffer = this.writeBuffer;
|
||||||
|
this.writeBuffer = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the given pass to the pass chain.
|
||||||
|
*
|
||||||
|
* @param {Pass} pass - The pass to add.
|
||||||
|
*/
|
||||||
|
addPass(pass) {
|
||||||
|
this.passes.push(pass);
|
||||||
|
pass.setSize(
|
||||||
|
this._width * this._pixelRatio,
|
||||||
|
this._height * this._pixelRatio,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts the given pass at a given index.
|
||||||
|
*
|
||||||
|
* @param {Pass} pass - The pass to insert.
|
||||||
|
* @param {number} index - The index into the pass chain.
|
||||||
|
*/
|
||||||
|
insertPass(pass, index) {
|
||||||
|
this.passes.splice(index, 0, pass);
|
||||||
|
pass.setSize(
|
||||||
|
this._width * this._pixelRatio,
|
||||||
|
this._height * this._pixelRatio,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the given pass from the pass chain.
|
||||||
|
*
|
||||||
|
* @param {Pass} pass - The pass to remove.
|
||||||
|
*/
|
||||||
|
removePass(pass) {
|
||||||
|
const index = this.passes.indexOf(pass);
|
||||||
|
|
||||||
|
if (index !== -1) {
|
||||||
|
this.passes.splice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns `true` if the pass for the given index is the last enabled pass in the pass chain.
|
||||||
|
*
|
||||||
|
* @param {number} passIndex - The pass index.
|
||||||
|
* @return {boolean} Whether the pass for the given index is the last pass in the pass chain.
|
||||||
|
*/
|
||||||
|
isLastEnabledPass(passIndex) {
|
||||||
|
for (let i = passIndex + 1; i < this.passes.length; i++) {
|
||||||
|
if (this.passes[i].enabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes all enabled post-processing passes in order to produce the final frame.
|
||||||
|
*
|
||||||
|
* @param {number} deltaTime - The delta time in seconds. If not given, the composer computes
|
||||||
|
* its own time delta value.
|
||||||
|
*/
|
||||||
|
render(deltaTime) {
|
||||||
|
// deltaTime value is in seconds
|
||||||
|
|
||||||
|
this.timer.update();
|
||||||
|
|
||||||
|
if (deltaTime === undefined) {
|
||||||
|
deltaTime = this.timer.getDelta();
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentRenderTarget = this.renderer.getRenderTarget();
|
||||||
|
|
||||||
|
let maskActive = false;
|
||||||
|
|
||||||
|
for (let i = 0, il = this.passes.length; i < il; i++) {
|
||||||
|
const pass = this.passes[i];
|
||||||
|
|
||||||
|
if (pass.enabled === false) continue;
|
||||||
|
|
||||||
|
pass.renderToScreen = this.renderToScreen && this.isLastEnabledPass(i);
|
||||||
|
pass.render(
|
||||||
|
this.renderer,
|
||||||
|
this.writeBuffer,
|
||||||
|
this.readBuffer,
|
||||||
|
deltaTime,
|
||||||
|
maskActive,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (pass.needsSwap) {
|
||||||
|
if (maskActive) {
|
||||||
|
const context = this.renderer.getContext();
|
||||||
|
const stencil = this.renderer.state.buffers.stencil;
|
||||||
|
|
||||||
|
//context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff );
|
||||||
|
stencil.setFunc(context.NOTEQUAL, 1, 0xffffffff);
|
||||||
|
|
||||||
|
this.copyPass.render(
|
||||||
|
this.renderer,
|
||||||
|
this.writeBuffer,
|
||||||
|
this.readBuffer,
|
||||||
|
deltaTime,
|
||||||
|
);
|
||||||
|
|
||||||
|
//context.stencilFunc( context.EQUAL, 1, 0xffffffff );
|
||||||
|
stencil.setFunc(context.EQUAL, 1, 0xffffffff);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.swapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MaskPass !== undefined) {
|
||||||
|
if (pass instanceof MaskPass) {
|
||||||
|
maskActive = true;
|
||||||
|
} else if (pass instanceof ClearMaskPass) {
|
||||||
|
maskActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderer.setRenderTarget(currentRenderTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the internal state of the EffectComposer.
|
||||||
|
*
|
||||||
|
* @param {WebGLRenderTarget} [renderTarget] - This render target has the same purpose like
|
||||||
|
* the one from the constructor. If set, it is used to setup the read and write buffers.
|
||||||
|
*/
|
||||||
|
reset(renderTarget) {
|
||||||
|
if (renderTarget === undefined) {
|
||||||
|
const size = this.renderer.getSize(new Vector2());
|
||||||
|
this._pixelRatio = this.renderer.getPixelRatio();
|
||||||
|
this._width = size.width;
|
||||||
|
this._height = size.height;
|
||||||
|
|
||||||
|
renderTarget = this.renderTarget1.clone();
|
||||||
|
renderTarget.setSize(
|
||||||
|
this._width * this._pixelRatio,
|
||||||
|
this._height * this._pixelRatio,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderTarget1.dispose();
|
||||||
|
this.renderTarget2.dispose();
|
||||||
|
this.renderTarget1 = renderTarget;
|
||||||
|
this.renderTarget2 = renderTarget.clone();
|
||||||
|
|
||||||
|
this.writeBuffer = this.renderTarget1;
|
||||||
|
this.readBuffer = this.renderTarget2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resizes the internal read and write buffers as well as all passes. Similar to {@link WebGLRenderer#setSize},
|
||||||
|
* this method honors the current pixel ration.
|
||||||
|
*
|
||||||
|
* @param {number} width - The width in logical pixels.
|
||||||
|
* @param {number} height - The height in logical pixels.
|
||||||
|
*/
|
||||||
|
setSize(width, height) {
|
||||||
|
this._width = width;
|
||||||
|
this._height = height;
|
||||||
|
|
||||||
|
const effectiveWidth = this._width * this._pixelRatio;
|
||||||
|
const effectiveHeight = this._height * this._pixelRatio;
|
||||||
|
|
||||||
|
this.renderTarget1.setSize(effectiveWidth, effectiveHeight);
|
||||||
|
this.renderTarget2.setSize(effectiveWidth, effectiveHeight);
|
||||||
|
|
||||||
|
for (let i = 0; i < this.passes.length; i++) {
|
||||||
|
this.passes[i].setSize(effectiveWidth, effectiveHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets device pixel ratio. This is usually used for HiDPI device to prevent blurring output.
|
||||||
|
* Setting the pixel ratio will automatically resize the composer.
|
||||||
|
*
|
||||||
|
* @param {number} pixelRatio - The pixel ratio to set.
|
||||||
|
*/
|
||||||
|
setPixelRatio(pixelRatio) {
|
||||||
|
this._pixelRatio = pixelRatio;
|
||||||
|
|
||||||
|
this.setSize(this._width, this._height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the GPU-related resources allocated by this instance. Call this
|
||||||
|
* method whenever the composer is no longer used in your app.
|
||||||
|
*/
|
||||||
|
dispose() {
|
||||||
|
this.renderTarget1.dispose();
|
||||||
|
this.renderTarget2.dispose();
|
||||||
|
|
||||||
|
this.copyPass.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { EffectComposer };
|
||||||
183
public/vendor/addons/postprocessing/MaskPass.js
vendored
Normal file
183
public/vendor/addons/postprocessing/MaskPass.js
vendored
Normal file
|
|
@ -0,0 +1,183 @@
|
||||||
|
import { Pass } from "./Pass.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This pass can be used to define a mask during post processing.
|
||||||
|
* Meaning only areas of subsequent post processing are affected
|
||||||
|
* which lie in the masking area of this pass. Internally, the masking
|
||||||
|
* is implemented with the stencil buffer.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const maskPass = new MaskPass( scene, camera );
|
||||||
|
* composer.addPass( maskPass );
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @augments Pass
|
||||||
|
* @three_import import { MaskPass } from 'three/addons/postprocessing/MaskPass.js';
|
||||||
|
*/
|
||||||
|
class MaskPass extends Pass {
|
||||||
|
/**
|
||||||
|
* Constructs a new mask pass.
|
||||||
|
*
|
||||||
|
* @param {Scene} scene - The 3D objects in this scene will define the mask.
|
||||||
|
* @param {Camera} camera - The camera.
|
||||||
|
*/
|
||||||
|
constructor(scene, camera) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scene that defines the mask.
|
||||||
|
*
|
||||||
|
* @type {Scene}
|
||||||
|
*/
|
||||||
|
this.scene = scene;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The camera.
|
||||||
|
*
|
||||||
|
* @type {Camera}
|
||||||
|
*/
|
||||||
|
this.camera = camera;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwritten to perform a clear operation by default.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
this.clear = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwritten to disable the swap.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
this.needsSwap = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to inverse the mask or not.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
this.inverse = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a mask pass with the configured scene and camera.
|
||||||
|
*
|
||||||
|
* @param {WebGLRenderer} renderer - The renderer.
|
||||||
|
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||||
|
* destination for the pass.
|
||||||
|
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||||
|
* previous pass from this buffer.
|
||||||
|
* @param {number} deltaTime - The delta time in seconds.
|
||||||
|
* @param {boolean} maskActive - Whether masking is active or not.
|
||||||
|
*/
|
||||||
|
render(renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) {
|
||||||
|
const context = renderer.getContext();
|
||||||
|
const state = renderer.state;
|
||||||
|
|
||||||
|
// don't update color or depth
|
||||||
|
|
||||||
|
state.buffers.color.setMask(false);
|
||||||
|
state.buffers.depth.setMask(false);
|
||||||
|
|
||||||
|
// lock buffers
|
||||||
|
|
||||||
|
state.buffers.color.setLocked(true);
|
||||||
|
state.buffers.depth.setLocked(true);
|
||||||
|
|
||||||
|
// set up stencil
|
||||||
|
|
||||||
|
let writeValue, clearValue;
|
||||||
|
|
||||||
|
if (this.inverse) {
|
||||||
|
writeValue = 0;
|
||||||
|
clearValue = 1;
|
||||||
|
} else {
|
||||||
|
writeValue = 1;
|
||||||
|
clearValue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.buffers.stencil.setTest(true);
|
||||||
|
state.buffers.stencil.setOp(
|
||||||
|
context.REPLACE,
|
||||||
|
context.REPLACE,
|
||||||
|
context.REPLACE,
|
||||||
|
);
|
||||||
|
state.buffers.stencil.setFunc(context.ALWAYS, writeValue, 0xffffffff);
|
||||||
|
state.buffers.stencil.setClear(clearValue);
|
||||||
|
state.buffers.stencil.setLocked(true);
|
||||||
|
|
||||||
|
// draw into the stencil buffer
|
||||||
|
|
||||||
|
renderer.setRenderTarget(readBuffer);
|
||||||
|
if (this.clear) renderer.clear();
|
||||||
|
renderer.render(this.scene, this.camera);
|
||||||
|
|
||||||
|
renderer.setRenderTarget(writeBuffer);
|
||||||
|
if (this.clear) renderer.clear();
|
||||||
|
renderer.render(this.scene, this.camera);
|
||||||
|
|
||||||
|
// unlock color and depth buffer and make them writable for subsequent rendering/clearing
|
||||||
|
|
||||||
|
state.buffers.color.setLocked(false);
|
||||||
|
state.buffers.depth.setLocked(false);
|
||||||
|
|
||||||
|
state.buffers.color.setMask(true);
|
||||||
|
state.buffers.depth.setMask(true);
|
||||||
|
|
||||||
|
// only render where stencil is set to 1
|
||||||
|
|
||||||
|
state.buffers.stencil.setLocked(false);
|
||||||
|
state.buffers.stencil.setFunc(context.EQUAL, 1, 0xffffffff); // draw if == 1
|
||||||
|
state.buffers.stencil.setOp(context.KEEP, context.KEEP, context.KEEP);
|
||||||
|
state.buffers.stencil.setLocked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This pass can be used to clear a mask previously defined with {@link MaskPass}.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const clearPass = new ClearMaskPass();
|
||||||
|
* composer.addPass( clearPass );
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @augments Pass
|
||||||
|
*/
|
||||||
|
class ClearMaskPass extends Pass {
|
||||||
|
/**
|
||||||
|
* Constructs a new clear mask pass.
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwritten to disable the swap.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
this.needsSwap = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the clear of the currently defined mask.
|
||||||
|
*
|
||||||
|
* @param {WebGLRenderer} renderer - The renderer.
|
||||||
|
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||||
|
* destination for the pass.
|
||||||
|
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||||
|
* previous pass from this buffer.
|
||||||
|
* @param {number} deltaTime - The delta time in seconds.
|
||||||
|
* @param {boolean} maskActive - Whether masking is active or not.
|
||||||
|
*/
|
||||||
|
render(renderer /*, writeBuffer, readBuffer, deltaTime, maskActive */) {
|
||||||
|
renderer.state.buffers.stencil.setLocked(false);
|
||||||
|
renderer.state.buffers.stencil.setTest(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { MaskPass, ClearMaskPass };
|
||||||
150
public/vendor/addons/postprocessing/OutputPass.js
vendored
Normal file
150
public/vendor/addons/postprocessing/OutputPass.js
vendored
Normal file
|
|
@ -0,0 +1,150 @@
|
||||||
|
import {
|
||||||
|
ColorManagement,
|
||||||
|
RawShaderMaterial,
|
||||||
|
UniformsUtils,
|
||||||
|
LinearToneMapping,
|
||||||
|
ReinhardToneMapping,
|
||||||
|
CineonToneMapping,
|
||||||
|
AgXToneMapping,
|
||||||
|
ACESFilmicToneMapping,
|
||||||
|
NeutralToneMapping,
|
||||||
|
CustomToneMapping,
|
||||||
|
SRGBTransfer,
|
||||||
|
} from "three";
|
||||||
|
import { Pass, FullScreenQuad } from "./Pass.js";
|
||||||
|
import { OutputShader } from "../shaders/OutputShader.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This pass is responsible for including tone mapping and color space conversion
|
||||||
|
* into your pass chain. In most cases, this pass should be included at the end
|
||||||
|
* of each pass chain. If a pass requires sRGB input (e.g. like FXAA), the pass
|
||||||
|
* must follow `OutputPass` in the pass chain.
|
||||||
|
*
|
||||||
|
* The tone mapping and color space settings are extracted from the renderer.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const outputPass = new OutputPass();
|
||||||
|
* composer.addPass( outputPass );
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @augments Pass
|
||||||
|
* @three_import import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
|
||||||
|
*/
|
||||||
|
class OutputPass extends Pass {
|
||||||
|
/**
|
||||||
|
* Constructs a new output pass.
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This flag indicates that this is an output pass.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @readonly
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
this.isOutputPass = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pass uniforms.
|
||||||
|
*
|
||||||
|
* @type {Object}
|
||||||
|
*/
|
||||||
|
this.uniforms = UniformsUtils.clone(OutputShader.uniforms);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pass material.
|
||||||
|
*
|
||||||
|
* @type {RawShaderMaterial}
|
||||||
|
*/
|
||||||
|
this.material = new RawShaderMaterial({
|
||||||
|
name: OutputShader.name,
|
||||||
|
uniforms: this.uniforms,
|
||||||
|
vertexShader: OutputShader.vertexShader,
|
||||||
|
fragmentShader: OutputShader.fragmentShader,
|
||||||
|
});
|
||||||
|
|
||||||
|
// internals
|
||||||
|
|
||||||
|
this._fsQuad = new FullScreenQuad(this.material);
|
||||||
|
|
||||||
|
this._outputColorSpace = null;
|
||||||
|
this._toneMapping = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the output pass.
|
||||||
|
*
|
||||||
|
* @param {WebGLRenderer} renderer - The renderer.
|
||||||
|
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||||
|
* destination for the pass.
|
||||||
|
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||||
|
* previous pass from this buffer.
|
||||||
|
* @param {number} deltaTime - The delta time in seconds.
|
||||||
|
* @param {boolean} maskActive - Whether masking is active or not.
|
||||||
|
*/
|
||||||
|
render(renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) {
|
||||||
|
this.uniforms["tDiffuse"].value = readBuffer.texture;
|
||||||
|
this.uniforms["toneMappingExposure"].value = renderer.toneMappingExposure;
|
||||||
|
|
||||||
|
// rebuild defines if required
|
||||||
|
|
||||||
|
if (
|
||||||
|
this._outputColorSpace !== renderer.outputColorSpace ||
|
||||||
|
this._toneMapping !== renderer.toneMapping
|
||||||
|
) {
|
||||||
|
this._outputColorSpace = renderer.outputColorSpace;
|
||||||
|
this._toneMapping = renderer.toneMapping;
|
||||||
|
|
||||||
|
this.material.defines = {};
|
||||||
|
|
||||||
|
if (ColorManagement.getTransfer(this._outputColorSpace) === SRGBTransfer)
|
||||||
|
this.material.defines.SRGB_TRANSFER = "";
|
||||||
|
|
||||||
|
if (this._toneMapping === LinearToneMapping)
|
||||||
|
this.material.defines.LINEAR_TONE_MAPPING = "";
|
||||||
|
else if (this._toneMapping === ReinhardToneMapping)
|
||||||
|
this.material.defines.REINHARD_TONE_MAPPING = "";
|
||||||
|
else if (this._toneMapping === CineonToneMapping)
|
||||||
|
this.material.defines.CINEON_TONE_MAPPING = "";
|
||||||
|
else if (this._toneMapping === ACESFilmicToneMapping)
|
||||||
|
this.material.defines.ACES_FILMIC_TONE_MAPPING = "";
|
||||||
|
else if (this._toneMapping === AgXToneMapping)
|
||||||
|
this.material.defines.AGX_TONE_MAPPING = "";
|
||||||
|
else if (this._toneMapping === NeutralToneMapping)
|
||||||
|
this.material.defines.NEUTRAL_TONE_MAPPING = "";
|
||||||
|
else if (this._toneMapping === CustomToneMapping)
|
||||||
|
this.material.defines.CUSTOM_TONE_MAPPING = "";
|
||||||
|
|
||||||
|
this.material.needsUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
if (this.renderToScreen === true) {
|
||||||
|
renderer.setRenderTarget(null);
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
} else {
|
||||||
|
renderer.setRenderTarget(writeBuffer);
|
||||||
|
if (this.clear)
|
||||||
|
renderer.clear(
|
||||||
|
renderer.autoClearColor,
|
||||||
|
renderer.autoClearDepth,
|
||||||
|
renderer.autoClearStencil,
|
||||||
|
);
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the GPU-related resources allocated by this instance. Call this
|
||||||
|
* method whenever the pass is no longer used in your app.
|
||||||
|
*/
|
||||||
|
dispose() {
|
||||||
|
this.material.dispose();
|
||||||
|
this._fsQuad.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { OutputPass };
|
||||||
171
public/vendor/addons/postprocessing/Pass.js
vendored
Normal file
171
public/vendor/addons/postprocessing/Pass.js
vendored
Normal file
|
|
@ -0,0 +1,171 @@
|
||||||
|
import {
|
||||||
|
BufferGeometry,
|
||||||
|
Float32BufferAttribute,
|
||||||
|
OrthographicCamera,
|
||||||
|
Mesh,
|
||||||
|
} from "three";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for all post processing passes.
|
||||||
|
*
|
||||||
|
* This module is only relevant for post processing with {@link WebGLRenderer}.
|
||||||
|
*
|
||||||
|
* @abstract
|
||||||
|
* @three_import import { Pass } from 'three/addons/postprocessing/Pass.js';
|
||||||
|
*/
|
||||||
|
class Pass {
|
||||||
|
/**
|
||||||
|
* Constructs a new pass.
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
/**
|
||||||
|
* This flag can be used for type testing.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @readonly
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
this.isPass = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to `true`, the pass is processed by the composer.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
this.enabled = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to `true`, the pass indicates to swap read and write buffer after rendering.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
this.needsSwap = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to `true`, the pass clears its buffer before rendering
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
this.clear = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to `true`, the result of the pass is rendered to screen. The last pass in the composers
|
||||||
|
* pass chain gets automatically rendered to screen, no matter how this property is configured.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
this.renderToScreen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the size of the pass.
|
||||||
|
*
|
||||||
|
* @abstract
|
||||||
|
* @param {number} width - The width to set.
|
||||||
|
* @param {number} height - The height to set.
|
||||||
|
*/
|
||||||
|
setSize(/* width, height */) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method holds the render logic of a pass. It must be implemented in all derived classes.
|
||||||
|
*
|
||||||
|
* @abstract
|
||||||
|
* @param {WebGLRenderer} renderer - The renderer.
|
||||||
|
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||||
|
* destination for the pass.
|
||||||
|
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||||
|
* previous pass from this buffer.
|
||||||
|
* @param {number} deltaTime - The delta time in seconds.
|
||||||
|
* @param {boolean} maskActive - Whether masking is active or not.
|
||||||
|
*/
|
||||||
|
render(/* renderer, writeBuffer, readBuffer, deltaTime, maskActive */) {
|
||||||
|
console.error("THREE.Pass: .render() must be implemented in derived pass.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the GPU-related resources allocated by this instance. Call this
|
||||||
|
* method whenever the pass is no longer used in your app.
|
||||||
|
*
|
||||||
|
* @abstract
|
||||||
|
*/
|
||||||
|
dispose() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper for passes that need to fill the viewport with a single quad.
|
||||||
|
|
||||||
|
const _camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
||||||
|
|
||||||
|
// https://github.com/mrdoob/three.js/pull/21358
|
||||||
|
|
||||||
|
class FullscreenTriangleGeometry extends BufferGeometry {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.setAttribute(
|
||||||
|
"position",
|
||||||
|
new Float32BufferAttribute([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3),
|
||||||
|
);
|
||||||
|
this.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const _geometry = new FullscreenTriangleGeometry();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This module is a helper for passes which need to render a full
|
||||||
|
* screen effect which is quite common in context of post processing.
|
||||||
|
*
|
||||||
|
* The intended usage is to reuse a single full screen quad for rendering
|
||||||
|
* subsequent passes by just reassigning the `material` reference.
|
||||||
|
*
|
||||||
|
* This module can only be used with {@link WebGLRenderer}.
|
||||||
|
*
|
||||||
|
* @augments Mesh
|
||||||
|
* @three_import import { FullScreenQuad } from 'three/addons/postprocessing/Pass.js';
|
||||||
|
*/
|
||||||
|
class FullScreenQuad {
|
||||||
|
/**
|
||||||
|
* Constructs a new full screen quad.
|
||||||
|
*
|
||||||
|
* @param {?Material} material - The material to render te full screen quad with.
|
||||||
|
*/
|
||||||
|
constructor(material) {
|
||||||
|
this._mesh = new Mesh(_geometry, material);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the GPU-related resources allocated by this instance. Call this
|
||||||
|
* method whenever the instance is no longer used in your app.
|
||||||
|
*/
|
||||||
|
dispose() {
|
||||||
|
this._mesh.geometry.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the full screen quad.
|
||||||
|
*
|
||||||
|
* @param {WebGLRenderer} renderer - The renderer.
|
||||||
|
*/
|
||||||
|
render(renderer) {
|
||||||
|
renderer.render(this._mesh, _camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The quad's material.
|
||||||
|
*
|
||||||
|
* @type {?Material}
|
||||||
|
*/
|
||||||
|
get material() {
|
||||||
|
return this._mesh.material;
|
||||||
|
}
|
||||||
|
|
||||||
|
set material(value) {
|
||||||
|
this._mesh.material = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Pass, FullScreenQuad };
|
||||||
179
public/vendor/addons/postprocessing/RenderPass.js
vendored
Normal file
179
public/vendor/addons/postprocessing/RenderPass.js
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
||||||
|
import { Color } from "three";
|
||||||
|
import { Pass } from "./Pass.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a render pass. It takes a camera and a scene and produces
|
||||||
|
* a beauty pass for subsequent post processing effects.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const renderPass = new RenderPass( scene, camera );
|
||||||
|
* composer.addPass( renderPass );
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @augments Pass
|
||||||
|
* @three_import import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
|
||||||
|
*/
|
||||||
|
class RenderPass extends Pass {
|
||||||
|
/**
|
||||||
|
* Constructs a new render pass.
|
||||||
|
*
|
||||||
|
* @param {Scene} scene - The scene to render.
|
||||||
|
* @param {Camera} camera - The camera.
|
||||||
|
* @param {?Material} [overrideMaterial=null] - The override material. If set, this material is used
|
||||||
|
* for all objects in the scene.
|
||||||
|
* @param {?(number|Color|string)} [clearColor=null] - The clear color of the render pass.
|
||||||
|
* @param {?number} [clearAlpha=null] - The clear alpha of the render pass.
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
scene,
|
||||||
|
camera,
|
||||||
|
overrideMaterial = null,
|
||||||
|
clearColor = null,
|
||||||
|
clearAlpha = null,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scene to render.
|
||||||
|
*
|
||||||
|
* @type {Scene}
|
||||||
|
*/
|
||||||
|
this.scene = scene;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The camera.
|
||||||
|
*
|
||||||
|
* @type {Camera}
|
||||||
|
*/
|
||||||
|
this.camera = camera;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The override material. If set, this material is used
|
||||||
|
* for all objects in the scene.
|
||||||
|
*
|
||||||
|
* @type {?Material}
|
||||||
|
* @default null
|
||||||
|
*/
|
||||||
|
this.overrideMaterial = overrideMaterial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The clear color of the render pass.
|
||||||
|
*
|
||||||
|
* @type {?(number|Color|string)}
|
||||||
|
* @default null
|
||||||
|
*/
|
||||||
|
this.clearColor = clearColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The clear alpha of the render pass.
|
||||||
|
*
|
||||||
|
* @type {?number}
|
||||||
|
* @default null
|
||||||
|
*/
|
||||||
|
this.clearAlpha = clearAlpha;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwritten to perform a clear operation by default.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
this.clear = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to `true`, only the depth can be cleared when `clear` is to `false`.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
this.clearDepth = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwritten to disable the swap.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
this.needsSwap = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This flag indicates that this pass renders the scene itself.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @readonly
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
this.isRenderPass = true;
|
||||||
|
|
||||||
|
this._oldClearColor = new Color();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a beauty pass with the configured scene and camera.
|
||||||
|
*
|
||||||
|
* @param {WebGLRenderer} renderer - The renderer.
|
||||||
|
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||||
|
* destination for the pass.
|
||||||
|
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||||
|
* previous pass from this buffer.
|
||||||
|
* @param {number} deltaTime - The delta time in seconds.
|
||||||
|
* @param {boolean} maskActive - Whether masking is active or not.
|
||||||
|
*/
|
||||||
|
render(renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) {
|
||||||
|
const oldAutoClear = renderer.autoClear;
|
||||||
|
renderer.autoClear = false;
|
||||||
|
|
||||||
|
let oldClearAlpha, oldOverrideMaterial;
|
||||||
|
|
||||||
|
if (this.overrideMaterial !== null) {
|
||||||
|
oldOverrideMaterial = this.scene.overrideMaterial;
|
||||||
|
|
||||||
|
this.scene.overrideMaterial = this.overrideMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.clearColor !== null) {
|
||||||
|
renderer.getClearColor(this._oldClearColor);
|
||||||
|
renderer.setClearColor(this.clearColor, renderer.getClearAlpha());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.clearAlpha !== null) {
|
||||||
|
oldClearAlpha = renderer.getClearAlpha();
|
||||||
|
renderer.setClearAlpha(this.clearAlpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.clearDepth == true) {
|
||||||
|
renderer.clearDepth();
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.setRenderTarget(this.renderToScreen ? null : readBuffer);
|
||||||
|
|
||||||
|
if (this.clear === true) {
|
||||||
|
// TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
|
||||||
|
renderer.clear(
|
||||||
|
renderer.autoClearColor,
|
||||||
|
renderer.autoClearDepth,
|
||||||
|
renderer.autoClearStencil,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.render(this.scene, this.camera);
|
||||||
|
|
||||||
|
// restore
|
||||||
|
|
||||||
|
if (this.clearColor !== null) {
|
||||||
|
renderer.setClearColor(this._oldClearColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.clearAlpha !== null) {
|
||||||
|
renderer.setClearAlpha(oldClearAlpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.overrideMaterial !== null) {
|
||||||
|
this.scene.overrideMaterial = oldOverrideMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.autoClear = oldAutoClear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { RenderPass };
|
||||||
117
public/vendor/addons/postprocessing/ShaderPass.js
vendored
Normal file
117
public/vendor/addons/postprocessing/ShaderPass.js
vendored
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
import { ShaderMaterial, UniformsUtils } from "three";
|
||||||
|
import { Pass, FullScreenQuad } from "./Pass.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This pass can be used to create a post processing effect
|
||||||
|
* with a raw GLSL shader object. Useful for implementing custom
|
||||||
|
* effects.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const fxaaPass = new ShaderPass( FXAAShader );
|
||||||
|
* composer.addPass( fxaaPass );
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @augments Pass
|
||||||
|
* @three_import import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
|
||||||
|
*/
|
||||||
|
class ShaderPass extends Pass {
|
||||||
|
/**
|
||||||
|
* Constructs a new shader pass.
|
||||||
|
*
|
||||||
|
* @param {Object|ShaderMaterial} [shader] - A shader object holding vertex and fragment shader as well as
|
||||||
|
* defines and uniforms. It's also valid to pass a custom shader material.
|
||||||
|
* @param {string} [textureID='tDiffuse'] - The name of the texture uniform that should sample
|
||||||
|
* the read buffer.
|
||||||
|
*/
|
||||||
|
constructor(shader, textureID = "tDiffuse") {
|
||||||
|
super();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the texture uniform that should sample the read buffer.
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @default 'tDiffuse'
|
||||||
|
*/
|
||||||
|
this.textureID = textureID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pass uniforms.
|
||||||
|
*
|
||||||
|
* @type {?Object}
|
||||||
|
*/
|
||||||
|
this.uniforms = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pass material.
|
||||||
|
*
|
||||||
|
* @type {?ShaderMaterial}
|
||||||
|
*/
|
||||||
|
this.material = null;
|
||||||
|
|
||||||
|
if (shader instanceof ShaderMaterial) {
|
||||||
|
this.uniforms = shader.uniforms;
|
||||||
|
|
||||||
|
this.material = shader;
|
||||||
|
} else if (shader) {
|
||||||
|
this.uniforms = UniformsUtils.clone(shader.uniforms);
|
||||||
|
|
||||||
|
this.material = new ShaderMaterial({
|
||||||
|
name: shader.name !== undefined ? shader.name : "unspecified",
|
||||||
|
defines: Object.assign({}, shader.defines),
|
||||||
|
uniforms: this.uniforms,
|
||||||
|
vertexShader: shader.vertexShader,
|
||||||
|
fragmentShader: shader.fragmentShader,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// internals
|
||||||
|
|
||||||
|
this._fsQuad = new FullScreenQuad(this.material);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the shader pass.
|
||||||
|
*
|
||||||
|
* @param {WebGLRenderer} renderer - The renderer.
|
||||||
|
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||||
|
* destination for the pass.
|
||||||
|
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||||
|
* previous pass from this buffer.
|
||||||
|
* @param {number} deltaTime - The delta time in seconds.
|
||||||
|
* @param {boolean} maskActive - Whether masking is active or not.
|
||||||
|
*/
|
||||||
|
render(renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) {
|
||||||
|
if (this.uniforms[this.textureID]) {
|
||||||
|
this.uniforms[this.textureID].value = readBuffer.texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._fsQuad.material = this.material;
|
||||||
|
|
||||||
|
if (this.renderToScreen) {
|
||||||
|
renderer.setRenderTarget(null);
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
} else {
|
||||||
|
renderer.setRenderTarget(writeBuffer);
|
||||||
|
// TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
|
||||||
|
if (this.clear)
|
||||||
|
renderer.clear(
|
||||||
|
renderer.autoClearColor,
|
||||||
|
renderer.autoClearDepth,
|
||||||
|
renderer.autoClearStencil,
|
||||||
|
);
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the GPU-related resources allocated by this instance. Call this
|
||||||
|
* method whenever the pass is no longer used in your app.
|
||||||
|
*/
|
||||||
|
dispose() {
|
||||||
|
this.material.dispose();
|
||||||
|
|
||||||
|
this._fsQuad.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ShaderPass };
|
||||||
541
public/vendor/addons/postprocessing/UnrealBloomPass.js
vendored
Normal file
541
public/vendor/addons/postprocessing/UnrealBloomPass.js
vendored
Normal file
|
|
@ -0,0 +1,541 @@
|
||||||
|
import {
|
||||||
|
AdditiveBlending,
|
||||||
|
Color,
|
||||||
|
HalfFloatType,
|
||||||
|
MeshBasicMaterial,
|
||||||
|
ShaderMaterial,
|
||||||
|
UniformsUtils,
|
||||||
|
Vector2,
|
||||||
|
Vector3,
|
||||||
|
WebGLRenderTarget,
|
||||||
|
} from "three";
|
||||||
|
import { Pass, FullScreenQuad } from "./Pass.js";
|
||||||
|
import { CopyShader } from "../shaders/CopyShader.js";
|
||||||
|
import { LuminosityHighPassShader } from "../shaders/LuminosityHighPassShader.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This pass is inspired by the bloom pass of Unreal Engine. It creates a
|
||||||
|
* mip map chain of bloom textures and blurs them with different radii. Because
|
||||||
|
* of the weighted combination of mips, and because larger blurs are done on
|
||||||
|
* higher mips, this effect provides good quality and performance.
|
||||||
|
*
|
||||||
|
* When using this pass, tone mapping must be enabled in the renderer settings.
|
||||||
|
*
|
||||||
|
* Reference:
|
||||||
|
* - [Bloom in Unreal Engine](https://docs.unrealengine.com/latest/INT/Engine/Rendering/PostProcessEffects/Bloom/)
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const resolution = new THREE.Vector2( window.innerWidth, window.innerHeight );
|
||||||
|
* const bloomPass = new UnrealBloomPass( resolution, 1.5, 0.4, 0.85 );
|
||||||
|
* composer.addPass( bloomPass );
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @augments Pass
|
||||||
|
* @three_import import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
|
||||||
|
*/
|
||||||
|
class UnrealBloomPass extends Pass {
|
||||||
|
/**
|
||||||
|
* Constructs a new Unreal Bloom pass.
|
||||||
|
*
|
||||||
|
* @param {Vector2} [resolution] - The effect's resolution.
|
||||||
|
* @param {number} [strength=1] - The Bloom strength.
|
||||||
|
* @param {number} radius - The Bloom radius.
|
||||||
|
* @param {number} threshold - The luminance threshold limits which bright areas contribute to the Bloom effect.
|
||||||
|
*/
|
||||||
|
constructor(resolution, strength = 1, radius, threshold) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Bloom strength.
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
* @default 1
|
||||||
|
*/
|
||||||
|
this.strength = strength;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Bloom radius. Must be in the range `[0,1]`.
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.radius = radius;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The luminance threshold limits which bright areas contribute to the Bloom effect.
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.threshold = threshold;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The effect's resolution.
|
||||||
|
*
|
||||||
|
* @type {Vector2}
|
||||||
|
* @default (256,256)
|
||||||
|
*/
|
||||||
|
this.resolution =
|
||||||
|
resolution !== undefined
|
||||||
|
? new Vector2(resolution.x, resolution.y)
|
||||||
|
: new Vector2(256, 256);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The effect's clear color
|
||||||
|
*
|
||||||
|
* @type {Color}
|
||||||
|
* @default (0,0,0)
|
||||||
|
*/
|
||||||
|
this.clearColor = new Color(0, 0, 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwritten to disable the swap.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
this.needsSwap = false;
|
||||||
|
|
||||||
|
// internals
|
||||||
|
|
||||||
|
// render targets
|
||||||
|
this.renderTargetsHorizontal = [];
|
||||||
|
this.renderTargetsVertical = [];
|
||||||
|
this.nMips = 5;
|
||||||
|
let resx = Math.round(this.resolution.x / 2);
|
||||||
|
let resy = Math.round(this.resolution.y / 2);
|
||||||
|
|
||||||
|
this.renderTargetBright = new WebGLRenderTarget(resx, resy, {
|
||||||
|
type: HalfFloatType,
|
||||||
|
depthBuffer: false,
|
||||||
|
});
|
||||||
|
this.renderTargetBright.texture.name = "UnrealBloomPass.bright";
|
||||||
|
this.renderTargetBright.texture.generateMipmaps = false;
|
||||||
|
|
||||||
|
for (let i = 0; i < this.nMips; i++) {
|
||||||
|
const renderTargetHorizontal = new WebGLRenderTarget(resx, resy, {
|
||||||
|
type: HalfFloatType,
|
||||||
|
depthBuffer: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
renderTargetHorizontal.texture.name = "UnrealBloomPass.h" + i;
|
||||||
|
renderTargetHorizontal.texture.generateMipmaps = false;
|
||||||
|
|
||||||
|
this.renderTargetsHorizontal.push(renderTargetHorizontal);
|
||||||
|
|
||||||
|
const renderTargetVertical = new WebGLRenderTarget(resx, resy, {
|
||||||
|
type: HalfFloatType,
|
||||||
|
depthBuffer: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
renderTargetVertical.texture.name = "UnrealBloomPass.v" + i;
|
||||||
|
renderTargetVertical.texture.generateMipmaps = false;
|
||||||
|
|
||||||
|
this.renderTargetsVertical.push(renderTargetVertical);
|
||||||
|
|
||||||
|
resx = Math.round(resx / 2);
|
||||||
|
|
||||||
|
resy = Math.round(resy / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// luminosity high pass material
|
||||||
|
|
||||||
|
const highPassShader = LuminosityHighPassShader;
|
||||||
|
this.highPassUniforms = UniformsUtils.clone(highPassShader.uniforms);
|
||||||
|
|
||||||
|
this.highPassUniforms["luminosityThreshold"].value = threshold;
|
||||||
|
this.highPassUniforms["smoothWidth"].value = 0.01;
|
||||||
|
|
||||||
|
this.materialHighPassFilter = new ShaderMaterial({
|
||||||
|
uniforms: this.highPassUniforms,
|
||||||
|
vertexShader: highPassShader.vertexShader,
|
||||||
|
fragmentShader: highPassShader.fragmentShader,
|
||||||
|
});
|
||||||
|
|
||||||
|
// gaussian blur materials
|
||||||
|
|
||||||
|
this.separableBlurMaterials = [];
|
||||||
|
// These sizes have been changed to account for the altered coefficients-calculation to avoid blockiness,
|
||||||
|
// while retaining the same blur-strength. For details see https://github.com/mrdoob/three.js/pull/31528
|
||||||
|
const kernelSizeArray = [6, 10, 14, 18, 22];
|
||||||
|
resx = Math.round(this.resolution.x / 2);
|
||||||
|
resy = Math.round(this.resolution.y / 2);
|
||||||
|
|
||||||
|
for (let i = 0; i < this.nMips; i++) {
|
||||||
|
this.separableBlurMaterials.push(
|
||||||
|
this._getSeparableBlurMaterial(kernelSizeArray[i]),
|
||||||
|
);
|
||||||
|
|
||||||
|
this.separableBlurMaterials[i].uniforms["invSize"].value = new Vector2(
|
||||||
|
1 / resx,
|
||||||
|
1 / resy,
|
||||||
|
);
|
||||||
|
|
||||||
|
resx = Math.round(resx / 2);
|
||||||
|
|
||||||
|
resy = Math.round(resy / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// composite material
|
||||||
|
|
||||||
|
this.compositeMaterial = this._getCompositeMaterial(this.nMips);
|
||||||
|
this.compositeMaterial.uniforms["blurTexture1"].value =
|
||||||
|
this.renderTargetsVertical[0].texture;
|
||||||
|
this.compositeMaterial.uniforms["blurTexture2"].value =
|
||||||
|
this.renderTargetsVertical[1].texture;
|
||||||
|
this.compositeMaterial.uniforms["blurTexture3"].value =
|
||||||
|
this.renderTargetsVertical[2].texture;
|
||||||
|
this.compositeMaterial.uniforms["blurTexture4"].value =
|
||||||
|
this.renderTargetsVertical[3].texture;
|
||||||
|
this.compositeMaterial.uniforms["blurTexture5"].value =
|
||||||
|
this.renderTargetsVertical[4].texture;
|
||||||
|
this.compositeMaterial.uniforms["bloomStrength"].value = strength;
|
||||||
|
this.compositeMaterial.uniforms["bloomRadius"].value = 0.1;
|
||||||
|
|
||||||
|
const bloomFactors = [1.0, 0.8, 0.6, 0.4, 0.2];
|
||||||
|
this.compositeMaterial.uniforms["bloomFactors"].value = bloomFactors;
|
||||||
|
this.bloomTintColors = [
|
||||||
|
new Vector3(1, 1, 1),
|
||||||
|
new Vector3(1, 1, 1),
|
||||||
|
new Vector3(1, 1, 1),
|
||||||
|
new Vector3(1, 1, 1),
|
||||||
|
new Vector3(1, 1, 1),
|
||||||
|
];
|
||||||
|
this.compositeMaterial.uniforms["bloomTintColors"].value =
|
||||||
|
this.bloomTintColors;
|
||||||
|
|
||||||
|
// blend material
|
||||||
|
|
||||||
|
this.copyUniforms = UniformsUtils.clone(CopyShader.uniforms);
|
||||||
|
|
||||||
|
this.blendMaterial = new ShaderMaterial({
|
||||||
|
uniforms: this.copyUniforms,
|
||||||
|
vertexShader: CopyShader.vertexShader,
|
||||||
|
fragmentShader: CopyShader.fragmentShader,
|
||||||
|
premultipliedAlpha: true,
|
||||||
|
blending: AdditiveBlending,
|
||||||
|
depthTest: false,
|
||||||
|
depthWrite: false,
|
||||||
|
transparent: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
this._oldClearColor = new Color();
|
||||||
|
this._oldClearAlpha = 1;
|
||||||
|
|
||||||
|
this._basic = new MeshBasicMaterial();
|
||||||
|
|
||||||
|
this._fsQuad = new FullScreenQuad(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the GPU-related resources allocated by this instance. Call this
|
||||||
|
* method whenever the pass is no longer used in your app.
|
||||||
|
*/
|
||||||
|
dispose() {
|
||||||
|
for (let i = 0; i < this.renderTargetsHorizontal.length; i++) {
|
||||||
|
this.renderTargetsHorizontal[i].dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < this.renderTargetsVertical.length; i++) {
|
||||||
|
this.renderTargetsVertical[i].dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderTargetBright.dispose();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
for (let i = 0; i < this.separableBlurMaterials.length; i++) {
|
||||||
|
this.separableBlurMaterials[i].dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.compositeMaterial.dispose();
|
||||||
|
this.blendMaterial.dispose();
|
||||||
|
this._basic.dispose();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
this._fsQuad.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the size of the pass.
|
||||||
|
*
|
||||||
|
* @param {number} width - The width to set.
|
||||||
|
* @param {number} height - The height to set.
|
||||||
|
*/
|
||||||
|
setSize(width, height) {
|
||||||
|
let resx = Math.round(width / 2);
|
||||||
|
let resy = Math.round(height / 2);
|
||||||
|
|
||||||
|
this.renderTargetBright.setSize(resx, resy);
|
||||||
|
|
||||||
|
for (let i = 0; i < this.nMips; i++) {
|
||||||
|
this.renderTargetsHorizontal[i].setSize(resx, resy);
|
||||||
|
this.renderTargetsVertical[i].setSize(resx, resy);
|
||||||
|
|
||||||
|
this.separableBlurMaterials[i].uniforms["invSize"].value = new Vector2(
|
||||||
|
1 / resx,
|
||||||
|
1 / resy,
|
||||||
|
);
|
||||||
|
|
||||||
|
resx = Math.round(resx / 2);
|
||||||
|
resy = Math.round(resy / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the Bloom pass.
|
||||||
|
*
|
||||||
|
* @param {WebGLRenderer} renderer - The renderer.
|
||||||
|
* @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
|
||||||
|
* destination for the pass.
|
||||||
|
* @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
|
||||||
|
* previous pass from this buffer.
|
||||||
|
* @param {number} deltaTime - The delta time in seconds.
|
||||||
|
* @param {boolean} maskActive - Whether masking is active or not.
|
||||||
|
*/
|
||||||
|
render(renderer, writeBuffer, readBuffer, deltaTime, maskActive) {
|
||||||
|
renderer.getClearColor(this._oldClearColor);
|
||||||
|
this._oldClearAlpha = renderer.getClearAlpha();
|
||||||
|
const oldAutoClear = renderer.autoClear;
|
||||||
|
renderer.autoClear = false;
|
||||||
|
|
||||||
|
renderer.setClearColor(this.clearColor, 0);
|
||||||
|
|
||||||
|
if (maskActive) renderer.state.buffers.stencil.setTest(false);
|
||||||
|
|
||||||
|
// Render input to screen
|
||||||
|
|
||||||
|
if (this.renderToScreen) {
|
||||||
|
this._fsQuad.material = this._basic;
|
||||||
|
this._basic.map = readBuffer.texture;
|
||||||
|
|
||||||
|
renderer.setRenderTarget(null);
|
||||||
|
renderer.clear();
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Extract Bright Areas
|
||||||
|
|
||||||
|
this.highPassUniforms["tDiffuse"].value = readBuffer.texture;
|
||||||
|
this.highPassUniforms["luminosityThreshold"].value = this.threshold;
|
||||||
|
this._fsQuad.material = this.materialHighPassFilter;
|
||||||
|
|
||||||
|
renderer.setRenderTarget(this.renderTargetBright);
|
||||||
|
renderer.clear();
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
|
||||||
|
// 2. Blur All the mips progressively
|
||||||
|
|
||||||
|
let inputRenderTarget = this.renderTargetBright;
|
||||||
|
|
||||||
|
for (let i = 0; i < this.nMips; i++) {
|
||||||
|
this._fsQuad.material = this.separableBlurMaterials[i];
|
||||||
|
|
||||||
|
this.separableBlurMaterials[i].uniforms["colorTexture"].value =
|
||||||
|
inputRenderTarget.texture;
|
||||||
|
this.separableBlurMaterials[i].uniforms["direction"].value =
|
||||||
|
UnrealBloomPass.BlurDirectionX;
|
||||||
|
renderer.setRenderTarget(this.renderTargetsHorizontal[i]);
|
||||||
|
renderer.clear();
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
|
||||||
|
this.separableBlurMaterials[i].uniforms["colorTexture"].value =
|
||||||
|
this.renderTargetsHorizontal[i].texture;
|
||||||
|
this.separableBlurMaterials[i].uniforms["direction"].value =
|
||||||
|
UnrealBloomPass.BlurDirectionY;
|
||||||
|
renderer.setRenderTarget(this.renderTargetsVertical[i]);
|
||||||
|
renderer.clear();
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
|
||||||
|
inputRenderTarget = this.renderTargetsVertical[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Composite All the mips
|
||||||
|
|
||||||
|
this._fsQuad.material = this.compositeMaterial;
|
||||||
|
this.compositeMaterial.uniforms["bloomStrength"].value = this.strength;
|
||||||
|
this.compositeMaterial.uniforms["bloomRadius"].value = this.radius;
|
||||||
|
this.compositeMaterial.uniforms["bloomTintColors"].value =
|
||||||
|
this.bloomTintColors;
|
||||||
|
|
||||||
|
renderer.setRenderTarget(this.renderTargetsHorizontal[0]);
|
||||||
|
renderer.clear();
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
|
||||||
|
// Blend it additively over the input texture
|
||||||
|
|
||||||
|
this._fsQuad.material = this.blendMaterial;
|
||||||
|
this.copyUniforms["tDiffuse"].value =
|
||||||
|
this.renderTargetsHorizontal[0].texture;
|
||||||
|
|
||||||
|
if (maskActive) renderer.state.buffers.stencil.setTest(true);
|
||||||
|
|
||||||
|
if (this.renderToScreen) {
|
||||||
|
renderer.setRenderTarget(null);
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
} else {
|
||||||
|
renderer.setRenderTarget(readBuffer);
|
||||||
|
this._fsQuad.render(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore renderer settings
|
||||||
|
|
||||||
|
renderer.setClearColor(this._oldClearColor, this._oldClearAlpha);
|
||||||
|
renderer.autoClear = oldAutoClear;
|
||||||
|
}
|
||||||
|
|
||||||
|
// internals
|
||||||
|
|
||||||
|
_getSeparableBlurMaterial(kernelRadius) {
|
||||||
|
const coefficients = [];
|
||||||
|
const sigma = kernelRadius / 3;
|
||||||
|
|
||||||
|
for (let i = 0; i < kernelRadius; i++) {
|
||||||
|
coefficients.push(
|
||||||
|
(0.39894 * Math.exp((-0.5 * i * i) / (sigma * sigma))) / sigma,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge adjacent taps into single bilinear fetches (linear sampling)
|
||||||
|
|
||||||
|
const offsets = [];
|
||||||
|
const weights = [];
|
||||||
|
|
||||||
|
for (let i = 1; i < kernelRadius; i += 2) {
|
||||||
|
const wa = coefficients[i];
|
||||||
|
const wb = i + 1 < kernelRadius ? coefficients[i + 1] : 0;
|
||||||
|
const w = wa + wb;
|
||||||
|
|
||||||
|
offsets.push((i * wa + (i + 1) * wb) / w);
|
||||||
|
weights.push(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ShaderMaterial({
|
||||||
|
defines: {
|
||||||
|
KERNEL_PAIRS: offsets.length,
|
||||||
|
},
|
||||||
|
|
||||||
|
uniforms: {
|
||||||
|
colorTexture: { value: null },
|
||||||
|
invSize: { value: new Vector2(0.5, 0.5) }, // inverse texture size
|
||||||
|
direction: { value: new Vector2(0.5, 0.5) },
|
||||||
|
centerWeight: { value: coefficients[0] },
|
||||||
|
gaussianOffsets: { value: offsets },
|
||||||
|
gaussianWeights: { value: weights },
|
||||||
|
},
|
||||||
|
|
||||||
|
vertexShader: /* glsl */ `
|
||||||
|
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
vUv = uv;
|
||||||
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||||
|
|
||||||
|
}`,
|
||||||
|
|
||||||
|
fragmentShader: /* glsl */ `
|
||||||
|
|
||||||
|
#include <common>
|
||||||
|
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
uniform sampler2D colorTexture;
|
||||||
|
uniform vec2 invSize;
|
||||||
|
uniform vec2 direction;
|
||||||
|
uniform float centerWeight;
|
||||||
|
uniform float gaussianOffsets[KERNEL_PAIRS];
|
||||||
|
uniform float gaussianWeights[KERNEL_PAIRS];
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
vec3 diffuseSum = texture2D( colorTexture, vUv ).rgb * centerWeight;
|
||||||
|
|
||||||
|
for ( int i = 0; i < KERNEL_PAIRS; i ++ ) {
|
||||||
|
|
||||||
|
vec2 uvOffset = direction * invSize * gaussianOffsets[ i ];
|
||||||
|
vec3 sample1 = texture2D( colorTexture, vUv + uvOffset ).rgb;
|
||||||
|
vec3 sample2 = texture2D( colorTexture, vUv - uvOffset ).rgb;
|
||||||
|
diffuseSum += ( sample1 + sample2 ) * gaussianWeights[ i ];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
gl_FragColor = vec4( diffuseSum, 1.0 );
|
||||||
|
|
||||||
|
}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_getCompositeMaterial(nMips) {
|
||||||
|
return new ShaderMaterial({
|
||||||
|
defines: {
|
||||||
|
NUM_MIPS: nMips,
|
||||||
|
},
|
||||||
|
|
||||||
|
uniforms: {
|
||||||
|
blurTexture1: { value: null },
|
||||||
|
blurTexture2: { value: null },
|
||||||
|
blurTexture3: { value: null },
|
||||||
|
blurTexture4: { value: null },
|
||||||
|
blurTexture5: { value: null },
|
||||||
|
bloomStrength: { value: 1.0 },
|
||||||
|
bloomFactors: { value: null },
|
||||||
|
bloomTintColors: { value: null },
|
||||||
|
bloomRadius: { value: 0.0 },
|
||||||
|
},
|
||||||
|
|
||||||
|
vertexShader: /* glsl */ `
|
||||||
|
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
vUv = uv;
|
||||||
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||||
|
|
||||||
|
}`,
|
||||||
|
|
||||||
|
fragmentShader: /* glsl */ `
|
||||||
|
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
uniform sampler2D blurTexture1;
|
||||||
|
uniform sampler2D blurTexture2;
|
||||||
|
uniform sampler2D blurTexture3;
|
||||||
|
uniform sampler2D blurTexture4;
|
||||||
|
uniform sampler2D blurTexture5;
|
||||||
|
uniform float bloomStrength;
|
||||||
|
uniform float bloomRadius;
|
||||||
|
uniform float bloomFactors[NUM_MIPS];
|
||||||
|
uniform vec3 bloomTintColors[NUM_MIPS];
|
||||||
|
|
||||||
|
float lerpBloomFactor( const in float factor ) {
|
||||||
|
|
||||||
|
float mirrorFactor = 1.2 - factor;
|
||||||
|
return mix( factor, mirrorFactor, bloomRadius );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
// 3.0 for backwards compatibility with previous alpha-based intensity
|
||||||
|
vec3 bloom = 3.0 * bloomStrength * (
|
||||||
|
lerpBloomFactor( bloomFactors[ 0 ] ) * bloomTintColors[ 0 ] * texture2D( blurTexture1, vUv ).rgb +
|
||||||
|
lerpBloomFactor( bloomFactors[ 1 ] ) * bloomTintColors[ 1 ] * texture2D( blurTexture2, vUv ).rgb +
|
||||||
|
lerpBloomFactor( bloomFactors[ 2 ] ) * bloomTintColors[ 2 ] * texture2D( blurTexture3, vUv ).rgb +
|
||||||
|
lerpBloomFactor( bloomFactors[ 3 ] ) * bloomTintColors[ 3 ] * texture2D( blurTexture4, vUv ).rgb +
|
||||||
|
lerpBloomFactor( bloomFactors[ 4 ] ) * bloomTintColors[ 4 ] * texture2D( blurTexture5, vUv ).rgb
|
||||||
|
);
|
||||||
|
|
||||||
|
float bloomAlpha = max( bloom.r, max( bloom.g, bloom.b ) );
|
||||||
|
gl_FragColor = vec4( bloom, bloomAlpha );
|
||||||
|
|
||||||
|
}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UnrealBloomPass.BlurDirectionX = new Vector2(1.0, 0.0);
|
||||||
|
UnrealBloomPass.BlurDirectionY = new Vector2(0.0, 1.0);
|
||||||
|
|
||||||
|
export { UnrealBloomPass };
|
||||||
48
public/vendor/addons/shaders/CopyShader.js
vendored
Normal file
48
public/vendor/addons/shaders/CopyShader.js
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
* @module CopyShader
|
||||||
|
* @three_import import { CopyShader } from 'three/addons/shaders/CopyShader.js';
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full-screen copy shader pass.
|
||||||
|
*
|
||||||
|
* @constant
|
||||||
|
* @type {ShaderMaterial~Shader}
|
||||||
|
*/
|
||||||
|
const CopyShader = {
|
||||||
|
name: "CopyShader",
|
||||||
|
|
||||||
|
uniforms: {
|
||||||
|
tDiffuse: { value: null },
|
||||||
|
opacity: { value: 1.0 },
|
||||||
|
},
|
||||||
|
|
||||||
|
vertexShader: /* glsl */ `
|
||||||
|
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
vUv = uv;
|
||||||
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||||
|
|
||||||
|
}`,
|
||||||
|
|
||||||
|
fragmentShader: /* glsl */ `
|
||||||
|
|
||||||
|
uniform float opacity;
|
||||||
|
|
||||||
|
uniform sampler2D tDiffuse;
|
||||||
|
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
vec4 texel = texture2D( tDiffuse, vUv );
|
||||||
|
gl_FragColor = opacity * texel;
|
||||||
|
|
||||||
|
|
||||||
|
}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
export { CopyShader };
|
||||||
62
public/vendor/addons/shaders/LuminosityHighPassShader.js
vendored
Normal file
62
public/vendor/addons/shaders/LuminosityHighPassShader.js
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import { Color } from "three";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @module LuminosityHighPassShader
|
||||||
|
* @three_import import { LuminosityHighPassShader } from 'three/addons/shaders/LuminosityHighPassShader.js';
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Luminosity high pass shader.
|
||||||
|
*
|
||||||
|
* @constant
|
||||||
|
* @type {ShaderMaterial~Shader}
|
||||||
|
*/
|
||||||
|
const LuminosityHighPassShader = {
|
||||||
|
name: "LuminosityHighPassShader",
|
||||||
|
|
||||||
|
uniforms: {
|
||||||
|
tDiffuse: { value: null },
|
||||||
|
luminosityThreshold: { value: 1.0 },
|
||||||
|
smoothWidth: { value: 1.0 },
|
||||||
|
defaultColor: { value: new Color(0x000000) },
|
||||||
|
defaultOpacity: { value: 0.0 },
|
||||||
|
},
|
||||||
|
|
||||||
|
vertexShader: /* glsl */ `
|
||||||
|
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
vUv = uv;
|
||||||
|
|
||||||
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||||
|
|
||||||
|
}`,
|
||||||
|
|
||||||
|
fragmentShader: /* glsl */ `
|
||||||
|
|
||||||
|
uniform sampler2D tDiffuse;
|
||||||
|
uniform vec3 defaultColor;
|
||||||
|
uniform float defaultOpacity;
|
||||||
|
uniform float luminosityThreshold;
|
||||||
|
uniform float smoothWidth;
|
||||||
|
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
vec4 texel = texture2D( tDiffuse, vUv );
|
||||||
|
|
||||||
|
float v = luminance( texel.xyz );
|
||||||
|
|
||||||
|
vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );
|
||||||
|
|
||||||
|
float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );
|
||||||
|
|
||||||
|
gl_FragColor = mix( outputColor, texel, alpha );
|
||||||
|
|
||||||
|
}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
export { LuminosityHighPassShader };
|
||||||
99
public/vendor/addons/shaders/OutputShader.js
vendored
Normal file
99
public/vendor/addons/shaders/OutputShader.js
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
/**
|
||||||
|
* @module OutputShader
|
||||||
|
* @three_import import { OutputShader } from 'three/addons/shaders/OutputShader.js';
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs tone mapping and color space conversion for
|
||||||
|
* FX workflows.
|
||||||
|
*
|
||||||
|
* Used by {@link OutputPass}.
|
||||||
|
*
|
||||||
|
* @constant
|
||||||
|
* @type {ShaderMaterial~Shader}
|
||||||
|
*/
|
||||||
|
const OutputShader = {
|
||||||
|
name: "OutputShader",
|
||||||
|
|
||||||
|
uniforms: {
|
||||||
|
tDiffuse: { value: null },
|
||||||
|
toneMappingExposure: { value: 1 },
|
||||||
|
},
|
||||||
|
|
||||||
|
vertexShader: /* glsl */ `
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
|
uniform mat4 modelViewMatrix;
|
||||||
|
uniform mat4 projectionMatrix;
|
||||||
|
|
||||||
|
attribute vec3 position;
|
||||||
|
attribute vec2 uv;
|
||||||
|
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
vUv = uv;
|
||||||
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||||
|
|
||||||
|
}`,
|
||||||
|
|
||||||
|
fragmentShader: /* glsl */ `
|
||||||
|
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
|
uniform sampler2D tDiffuse;
|
||||||
|
|
||||||
|
#include <tonemapping_pars_fragment>
|
||||||
|
#include <colorspace_pars_fragment>
|
||||||
|
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
gl_FragColor = texture2D( tDiffuse, vUv );
|
||||||
|
|
||||||
|
// tone mapping
|
||||||
|
|
||||||
|
#ifdef LINEAR_TONE_MAPPING
|
||||||
|
|
||||||
|
gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );
|
||||||
|
|
||||||
|
#elif defined( REINHARD_TONE_MAPPING )
|
||||||
|
|
||||||
|
gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );
|
||||||
|
|
||||||
|
#elif defined( CINEON_TONE_MAPPING )
|
||||||
|
|
||||||
|
gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );
|
||||||
|
|
||||||
|
#elif defined( ACES_FILMIC_TONE_MAPPING )
|
||||||
|
|
||||||
|
gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );
|
||||||
|
|
||||||
|
#elif defined( AGX_TONE_MAPPING )
|
||||||
|
|
||||||
|
gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );
|
||||||
|
|
||||||
|
#elif defined( NEUTRAL_TONE_MAPPING )
|
||||||
|
|
||||||
|
gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );
|
||||||
|
|
||||||
|
#elif defined( CUSTOM_TONE_MAPPING )
|
||||||
|
|
||||||
|
gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// color space
|
||||||
|
|
||||||
|
#ifdef SRGB_TRANSFER
|
||||||
|
|
||||||
|
gl_FragColor = sRGBTransferOETF( gl_FragColor );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
export { OutputShader };
|
||||||
1413
public/vendor/addons/utils/BufferGeometryUtils.js
vendored
Normal file
1413
public/vendor/addons/utils/BufferGeometryUtils.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
411
public/vendor/addons/utils/SkeletonUtils.js
vendored
Normal file
411
public/vendor/addons/utils/SkeletonUtils.js
vendored
Normal file
|
|
@ -0,0 +1,411 @@
|
||||||
|
import {
|
||||||
|
AnimationClip,
|
||||||
|
AnimationMixer,
|
||||||
|
Matrix4,
|
||||||
|
Quaternion,
|
||||||
|
QuaternionKeyframeTrack,
|
||||||
|
SkeletonHelper,
|
||||||
|
Vector3,
|
||||||
|
VectorKeyframeTrack,
|
||||||
|
} from "three";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @module SkeletonUtils
|
||||||
|
* @three_import import * as SkeletonUtils from 'three/addons/utils/SkeletonUtils.js';
|
||||||
|
*/
|
||||||
|
|
||||||
|
function getBoneName(bone, options) {
|
||||||
|
if (options.getBoneName !== undefined) {
|
||||||
|
return options.getBoneName(bone);
|
||||||
|
}
|
||||||
|
|
||||||
|
return options.names[bone.name];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retargets the skeleton from the given source to the target.
|
||||||
|
*
|
||||||
|
* Both `target` and `source` can be a 3D object with a skeleton property (e.g. a skinned mesh)
|
||||||
|
* or a {@link Skeleton} directly.
|
||||||
|
*
|
||||||
|
* @param {Object3D|Skeleton} target - The target object.
|
||||||
|
* @param {Object3D|Skeleton} source - The source object.
|
||||||
|
* @param {module:SkeletonUtils~RetargetOptions} options - The options.
|
||||||
|
*/
|
||||||
|
function retarget(target, source, options = {}) {
|
||||||
|
const quat = new Quaternion(),
|
||||||
|
scale = new Vector3(),
|
||||||
|
relativeMatrix = new Matrix4(),
|
||||||
|
globalMatrix = new Matrix4();
|
||||||
|
|
||||||
|
options.preserveBoneMatrix =
|
||||||
|
options.preserveBoneMatrix !== undefined
|
||||||
|
? options.preserveBoneMatrix
|
||||||
|
: true;
|
||||||
|
options.preserveBonePositions =
|
||||||
|
options.preserveBonePositions !== undefined
|
||||||
|
? options.preserveBonePositions
|
||||||
|
: true;
|
||||||
|
options.useTargetMatrix =
|
||||||
|
options.useTargetMatrix !== undefined ? options.useTargetMatrix : false;
|
||||||
|
options.hip = options.hip !== undefined ? options.hip : "hip";
|
||||||
|
options.hipInfluence =
|
||||||
|
options.hipInfluence !== undefined
|
||||||
|
? options.hipInfluence
|
||||||
|
: new Vector3(1, 1, 1);
|
||||||
|
options.scale = options.scale !== undefined ? options.scale : 1;
|
||||||
|
options.names = options.names || {};
|
||||||
|
|
||||||
|
const sourceBones = source.isObject3D
|
||||||
|
? source.skeleton.bones
|
||||||
|
: getBones(source),
|
||||||
|
bones = target.isObject3D ? target.skeleton.bones : getBones(target);
|
||||||
|
|
||||||
|
let bone, name, boneTo, bonesPosition;
|
||||||
|
|
||||||
|
// reset bones
|
||||||
|
|
||||||
|
if (target.isObject3D) {
|
||||||
|
target.skeleton.pose();
|
||||||
|
} else {
|
||||||
|
options.useTargetMatrix = true;
|
||||||
|
options.preserveBoneMatrix = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.preserveBonePositions) {
|
||||||
|
bonesPosition = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < bones.length; i++) {
|
||||||
|
bonesPosition.push(bones[i].position.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.preserveBoneMatrix) {
|
||||||
|
// reset matrix
|
||||||
|
|
||||||
|
target.updateMatrixWorld();
|
||||||
|
|
||||||
|
target.matrixWorld.identity();
|
||||||
|
|
||||||
|
// reset children matrix
|
||||||
|
|
||||||
|
for (let i = 0; i < target.children.length; ++i) {
|
||||||
|
target.children[i].updateMatrixWorld(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < bones.length; ++i) {
|
||||||
|
bone = bones[i];
|
||||||
|
name = getBoneName(bone, options);
|
||||||
|
|
||||||
|
boneTo = getBoneByName(name, sourceBones);
|
||||||
|
|
||||||
|
globalMatrix.copy(bone.matrixWorld);
|
||||||
|
|
||||||
|
if (boneTo) {
|
||||||
|
boneTo.updateMatrixWorld();
|
||||||
|
|
||||||
|
if (options.useTargetMatrix) {
|
||||||
|
relativeMatrix.copy(boneTo.matrixWorld);
|
||||||
|
} else {
|
||||||
|
relativeMatrix.copy(target.matrixWorld).invert();
|
||||||
|
relativeMatrix.multiply(boneTo.matrixWorld);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore scale to extract rotation
|
||||||
|
|
||||||
|
scale.setFromMatrixScale(relativeMatrix);
|
||||||
|
relativeMatrix.scale(scale.set(1 / scale.x, 1 / scale.y, 1 / scale.z));
|
||||||
|
|
||||||
|
// apply to global matrix
|
||||||
|
|
||||||
|
globalMatrix.makeRotationFromQuaternion(
|
||||||
|
quat.setFromRotationMatrix(relativeMatrix),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (target.isObject3D) {
|
||||||
|
if (options.localOffsets) {
|
||||||
|
if (options.localOffsets[bone.name]) {
|
||||||
|
globalMatrix.multiply(options.localOffsets[bone.name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
globalMatrix.copyPosition(relativeMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name === options.hip) {
|
||||||
|
globalMatrix.elements[12] *= options.scale * options.hipInfluence.x;
|
||||||
|
globalMatrix.elements[13] *= options.scale * options.hipInfluence.y;
|
||||||
|
globalMatrix.elements[14] *= options.scale * options.hipInfluence.z;
|
||||||
|
|
||||||
|
if (options.hipPosition !== undefined) {
|
||||||
|
globalMatrix.elements[12] += options.hipPosition.x * options.scale;
|
||||||
|
globalMatrix.elements[13] += options.hipPosition.y * options.scale;
|
||||||
|
globalMatrix.elements[14] += options.hipPosition.z * options.scale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bone.parent) {
|
||||||
|
bone.matrix.copy(bone.parent.matrixWorld).invert();
|
||||||
|
bone.matrix.multiply(globalMatrix);
|
||||||
|
} else {
|
||||||
|
bone.matrix.copy(globalMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
bone.matrix.decompose(bone.position, bone.quaternion, bone.scale);
|
||||||
|
|
||||||
|
bone.updateMatrixWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.preserveBonePositions) {
|
||||||
|
for (let i = 0; i < bones.length; ++i) {
|
||||||
|
bone = bones[i];
|
||||||
|
name = getBoneName(bone, options) || bone.name;
|
||||||
|
|
||||||
|
if (name !== options.hip) {
|
||||||
|
bone.position.copy(bonesPosition[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.preserveBoneMatrix) {
|
||||||
|
// restore matrix
|
||||||
|
|
||||||
|
target.updateMatrixWorld(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retargets the animation clip of the source to the target 3D object.
|
||||||
|
*
|
||||||
|
* The `source` can be a 3D object with a skeleton property (e.g. a skinned mesh)
|
||||||
|
* or a {@link Skeleton} directly.
|
||||||
|
*
|
||||||
|
* @param {Object3D} target - The target 3D object. Must have a `skeleton` property.
|
||||||
|
* @param {Object3D|Skeleton} source - The source object.
|
||||||
|
* @param {AnimationClip} clip - The animation clip.
|
||||||
|
* @param {module:SkeletonUtils~RetargetOptions} options - The options.
|
||||||
|
* @return {AnimationClip} The retargeted animation clip.
|
||||||
|
*/
|
||||||
|
function retargetClip(target, source, clip, options = {}) {
|
||||||
|
options.useFirstFramePosition =
|
||||||
|
options.useFirstFramePosition !== undefined
|
||||||
|
? options.useFirstFramePosition
|
||||||
|
: false;
|
||||||
|
|
||||||
|
// Calculate the fps from the source clip based on the track with the most frames, unless fps is already provided.
|
||||||
|
options.fps =
|
||||||
|
options.fps !== undefined
|
||||||
|
? options.fps
|
||||||
|
: Math.max(...clip.tracks.map((track) => track.times.length)) /
|
||||||
|
clip.duration;
|
||||||
|
options.names = options.names || [];
|
||||||
|
|
||||||
|
if (!source.isObject3D) {
|
||||||
|
source = getHelperFromSkeleton(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
const numFrames = Math.round(clip.duration * (options.fps / 1000) * 1000),
|
||||||
|
delta = clip.duration / (numFrames - 1),
|
||||||
|
convertedTracks = [],
|
||||||
|
mixer = new AnimationMixer(source),
|
||||||
|
bones = getBones(target.skeleton),
|
||||||
|
boneDatas = [];
|
||||||
|
|
||||||
|
let positionOffset, bone, boneTo, boneData, name;
|
||||||
|
|
||||||
|
mixer.clipAction(clip).play();
|
||||||
|
|
||||||
|
// trim
|
||||||
|
|
||||||
|
let start = 0,
|
||||||
|
end = numFrames;
|
||||||
|
|
||||||
|
if (options.trim !== undefined) {
|
||||||
|
start = Math.round(options.trim[0] * options.fps);
|
||||||
|
end =
|
||||||
|
Math.min(Math.round(options.trim[1] * options.fps), numFrames) - start;
|
||||||
|
|
||||||
|
mixer.update(options.trim[0]);
|
||||||
|
} else {
|
||||||
|
mixer.update(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
source.updateMatrixWorld();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
for (let frame = 0; frame < end; ++frame) {
|
||||||
|
const time = frame * delta;
|
||||||
|
|
||||||
|
retarget(target, source, options);
|
||||||
|
|
||||||
|
for (let j = 0; j < bones.length; ++j) {
|
||||||
|
bone = bones[j];
|
||||||
|
name = getBoneName(bone, options) || bone.name;
|
||||||
|
boneTo = getBoneByName(name, source.skeleton);
|
||||||
|
|
||||||
|
if (boneTo) {
|
||||||
|
boneData = boneDatas[j] = boneDatas[j] || { bone: bone };
|
||||||
|
|
||||||
|
if (options.hip === name) {
|
||||||
|
if (!boneData.pos) {
|
||||||
|
boneData.pos = {
|
||||||
|
times: new Float32Array(end),
|
||||||
|
values: new Float32Array(end * 3),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.useFirstFramePosition) {
|
||||||
|
if (frame === 0) {
|
||||||
|
positionOffset = bone.position.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
bone.position.sub(positionOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
boneData.pos.times[frame] = time;
|
||||||
|
|
||||||
|
bone.position.toArray(boneData.pos.values, frame * 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!boneData.quat) {
|
||||||
|
boneData.quat = {
|
||||||
|
times: new Float32Array(end),
|
||||||
|
values: new Float32Array(end * 4),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
boneData.quat.times[frame] = time;
|
||||||
|
|
||||||
|
bone.quaternion.toArray(boneData.quat.values, frame * 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame === end - 2) {
|
||||||
|
// last mixer update before final loop iteration
|
||||||
|
// make sure we do not go over or equal to clip duration
|
||||||
|
mixer.update(delta - 0.0000001);
|
||||||
|
} else {
|
||||||
|
mixer.update(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
source.updateMatrixWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < boneDatas.length; ++i) {
|
||||||
|
boneData = boneDatas[i];
|
||||||
|
|
||||||
|
if (boneData) {
|
||||||
|
if (boneData.pos) {
|
||||||
|
convertedTracks.push(
|
||||||
|
new VectorKeyframeTrack(
|
||||||
|
".bones[" + boneData.bone.name + "].position",
|
||||||
|
boneData.pos.times,
|
||||||
|
boneData.pos.values,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
convertedTracks.push(
|
||||||
|
new QuaternionKeyframeTrack(
|
||||||
|
".bones[" + boneData.bone.name + "].quaternion",
|
||||||
|
boneData.quat.times,
|
||||||
|
boneData.quat.values,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mixer.uncacheAction(clip);
|
||||||
|
|
||||||
|
return new AnimationClip(clip.name, -1, convertedTracks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones the given 3D object and its descendants, ensuring that any `SkinnedMesh` instances are
|
||||||
|
* correctly associated with their bones. Bones are also cloned, and must be descendants of the
|
||||||
|
* object passed to this method. Other data, like geometries and materials, are reused by reference.
|
||||||
|
*
|
||||||
|
* @param {Object3D} source - The 3D object to clone.
|
||||||
|
* @return {Object3D} The cloned 3D object.
|
||||||
|
*/
|
||||||
|
function clone(source) {
|
||||||
|
const sourceLookup = new Map();
|
||||||
|
const cloneLookup = new Map();
|
||||||
|
|
||||||
|
const clone = source.clone();
|
||||||
|
|
||||||
|
parallelTraverse(source, clone, function (sourceNode, clonedNode) {
|
||||||
|
sourceLookup.set(clonedNode, sourceNode);
|
||||||
|
cloneLookup.set(sourceNode, clonedNode);
|
||||||
|
});
|
||||||
|
|
||||||
|
clone.traverse(function (node) {
|
||||||
|
if (!node.isSkinnedMesh) return;
|
||||||
|
|
||||||
|
const clonedMesh = node;
|
||||||
|
const sourceMesh = sourceLookup.get(node);
|
||||||
|
const sourceBones = sourceMesh.skeleton.bones;
|
||||||
|
|
||||||
|
clonedMesh.skeleton = sourceMesh.skeleton.clone();
|
||||||
|
clonedMesh.bindMatrix.copy(sourceMesh.bindMatrix);
|
||||||
|
|
||||||
|
clonedMesh.skeleton.bones = sourceBones.map(function (bone) {
|
||||||
|
return cloneLookup.get(bone);
|
||||||
|
});
|
||||||
|
|
||||||
|
clonedMesh.bind(clonedMesh.skeleton, clonedMesh.bindMatrix);
|
||||||
|
});
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
// internal helper
|
||||||
|
|
||||||
|
function getBoneByName(name, skeleton) {
|
||||||
|
for (let i = 0, bones = getBones(skeleton); i < bones.length; i++) {
|
||||||
|
if (name === bones[i].name) return bones[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBones(skeleton) {
|
||||||
|
return Array.isArray(skeleton) ? skeleton : skeleton.bones;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHelperFromSkeleton(skeleton) {
|
||||||
|
const source = new SkeletonHelper(skeleton.bones[0]);
|
||||||
|
source.skeleton = skeleton;
|
||||||
|
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parallelTraverse(a, b, callback) {
|
||||||
|
callback(a, b);
|
||||||
|
|
||||||
|
for (let i = 0; i < a.children.length; i++) {
|
||||||
|
parallelTraverse(a.children[i], b.children[i], callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retarget options of `SkeletonUtils`.
|
||||||
|
*
|
||||||
|
* @typedef {Object} module:SkeletonUtils~RetargetOptions
|
||||||
|
* @property {boolean} [useFirstFramePosition=false] - Whether to use the position of the first frame or not.
|
||||||
|
* @property {number} [fps] - The FPS of the clip.
|
||||||
|
* @property {Object<string,string>} [names] - A dictionary for mapping target to source bone names.
|
||||||
|
* @property {function(string):string} [getBoneName] - A function for mapping bone names. Alternative to `names`.
|
||||||
|
* @property {Array<number>} [trim] - Whether to trim the clip or not. If set the array should hold two values for the start and end.
|
||||||
|
* @property {boolean} [preserveBoneMatrix=true] - Whether to preserve bone matrices or not.
|
||||||
|
* @property {boolean} [preserveBonePositions=true] - Whether to preserve bone positions or not.
|
||||||
|
* @property {boolean} [useTargetMatrix=false] - Whether to use the target matrix or not.
|
||||||
|
* @property {string} [hip='hip'] - The name of the source's hip bone.
|
||||||
|
* @property {Vector3} [hipInfluence=(1,1,1)] - The hip influence.
|
||||||
|
* @property {number} [scale=1] - The scale.
|
||||||
|
* @property {Object<string,Matrix4>} [localOffsets] - Per-bone local offset matrices, keyed by bone name.
|
||||||
|
* @property {Vector3} [hipPosition] - An additional position offset applied to the hip bone.
|
||||||
|
**/
|
||||||
|
|
||||||
|
export { retarget, retargetClip, clone };
|
||||||
57243
public/vendor/three.core.js
vendored
Normal file
57243
public/vendor/three.core.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
19637
public/vendor/three.module.js
vendored
Normal file
19637
public/vendor/three.module.js
vendored
Normal file
File diff suppressed because one or more lines are too long
55
scripts/build-client.mjs
Normal file
55
scripts/build-client.mjs
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
// Bundles and minifies client TypeScript and modular CSS into dist/bundle/.
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import * as esbuild from 'esbuild';
|
||||||
|
|
||||||
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
const APP_ROOT = path.resolve(__dirname, '..');
|
||||||
|
const BUNDLE_DIR = path.join(APP_ROOT, 'dist', 'bundle');
|
||||||
|
const COMMON_OPTIONS = {
|
||||||
|
bundle: true,
|
||||||
|
minify: true,
|
||||||
|
sourcemap: true,
|
||||||
|
legalComments: 'eof',
|
||||||
|
logLevel: 'info',
|
||||||
|
};
|
||||||
|
const CLIENT_TARGETS = [
|
||||||
|
{
|
||||||
|
...COMMON_OPTIONS,
|
||||||
|
entryPoints: [path.join(APP_ROOT, 'src', 'client', 'app.ts')],
|
||||||
|
outfile: path.join(BUNDLE_DIR, 'app.js'),
|
||||||
|
format: 'esm',
|
||||||
|
platform: 'browser',
|
||||||
|
target: ['es2022'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...COMMON_OPTIONS,
|
||||||
|
entryPoints: [path.join(APP_ROOT, 'public', 'css', 'style.css')],
|
||||||
|
outfile: path.join(BUNDLE_DIR, 'style.css'),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const watchMode = process.argv.includes('--watch');
|
||||||
|
fs.rmSync(BUNDLE_DIR, { recursive: true, force: true });
|
||||||
|
fs.mkdirSync(BUNDLE_DIR, { recursive: true });
|
||||||
|
if (!watchMode) {
|
||||||
|
await Promise.all(CLIENT_TARGETS.map((opts) => esbuild.build(opts)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const contexts = await Promise.all(CLIENT_TARGETS.map((opts) => esbuild.context(opts)));
|
||||||
|
await Promise.all(contexts.map((ctx) => ctx.watch()));
|
||||||
|
console.log('[esbuild] Watching client JS & CSS...');
|
||||||
|
const shutdown = async () => {
|
||||||
|
await Promise.all(contexts.map((ctx) => ctx.dispose()));
|
||||||
|
process.exit(0);
|
||||||
|
};
|
||||||
|
process.on('SIGINT', shutdown);
|
||||||
|
process.on('SIGTERM', shutdown);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
305
scripts/ml_agent.py
Normal file
305
scripts/ml_agent.py
Normal file
|
|
@ -0,0 +1,305 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# Optional ML AI subprocess bridge for Space Gaem providing status, policy prediction, and online training over JSON.
|
||||||
|
# No idea if this works or not, but I think it kinda does. Hopefully.
|
||||||
|
from __future__ import annotations
|
||||||
|
import argparse
|
||||||
|
import importlib.util
|
||||||
|
import json
|
||||||
|
import math
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
|
DEFAULT_WEIGHTS_PATH = Path(__file__).resolve().parent.parent / "data" / "ml_policy_weights.json"
|
||||||
|
FEATURE_NAMES = [
|
||||||
|
"bias",
|
||||||
|
"dv_margin_proxy",
|
||||||
|
"budget_per_dv",
|
||||||
|
"tier_norm",
|
||||||
|
"is_home_sponsor",
|
||||||
|
"rad_hazard",
|
||||||
|
"meteor_hazard",
|
||||||
|
"shear_hazard",
|
||||||
|
"weather_sev",
|
||||||
|
"skill",
|
||||||
|
]
|
||||||
|
|
||||||
|
def detect_backends() -> Dict[str, Any]:
|
||||||
|
candidates = ["onnxruntime", "torch", "sklearn", "numpy"]
|
||||||
|
available = [pkg for pkg in candidates if importlib.util.find_spec(pkg) is not None]
|
||||||
|
if "onnxruntime" in available:
|
||||||
|
active = "onnxruntime"
|
||||||
|
elif "torch" in available:
|
||||||
|
active = "pytorch"
|
||||||
|
elif "sklearn" in available:
|
||||||
|
active = "sklearn-sgd"
|
||||||
|
elif "numpy" in available:
|
||||||
|
active = "numpy-mlp"
|
||||||
|
else:
|
||||||
|
active = "python-stdlib-mlp"
|
||||||
|
return {"active": active, "availablePackages": available}
|
||||||
|
|
||||||
|
def default_weights_store() -> Dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"version": 1,
|
||||||
|
"episodes": 0,
|
||||||
|
"avgReward": 0.0,
|
||||||
|
"sharedWeights": [0.2, 1.35, 1.1, 0.25, 0.65, -0.45, -0.35, -0.25, -0.35, 0.55],
|
||||||
|
"hiddenBias": [0.1, -0.05, 0.15, 0.0],
|
||||||
|
"agencies": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
def load_weights(path: Path) -> Dict[str, Any]:
|
||||||
|
if not path.exists():
|
||||||
|
return default_weights_store()
|
||||||
|
try:
|
||||||
|
data = json.loads(path.read_text(encoding="utf-8"))
|
||||||
|
base = default_weights_store()
|
||||||
|
base.update(data)
|
||||||
|
if len(base.get("sharedWeights", [])) != len(FEATURE_NAMES):
|
||||||
|
base["sharedWeights"] = default_weights_store()["sharedWeights"]
|
||||||
|
return base
|
||||||
|
except Exception:
|
||||||
|
return default_weights_store()
|
||||||
|
|
||||||
|
def save_weights(path: Path, data: Dict[str, Any]) -> None:
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
tmp = path.with_suffix(".tmp")
|
||||||
|
tmp.write_text(json.dumps(data, indent=2), encoding="utf-8")
|
||||||
|
os.replace(tmp, path)
|
||||||
|
|
||||||
|
def dot(a: List[float], b: List[float]) -> float:
|
||||||
|
return sum(float(x) * float(y) for x, y in zip(a, b))
|
||||||
|
|
||||||
|
def sigmoid(z: float) -> float:
|
||||||
|
if z > 30:
|
||||||
|
return 1.0
|
||||||
|
if z < -30:
|
||||||
|
return 0.0
|
||||||
|
return 1.0 / (1.0 + math.exp(-z))
|
||||||
|
|
||||||
|
def _candidate_penalty(candidate: Dict[str, Any], payload: Dict[str, Any]) -> float:
|
||||||
|
agency = payload.get("agency") or {}
|
||||||
|
treasury = max(1e6, float(agency.get("treasury", 60e6)))
|
||||||
|
difficulty = str(agency.get("difficulty", "engineer"))
|
||||||
|
unlocked = set(agency.get("unlockedTechs") or ["starter"])
|
||||||
|
has_high_isp = difficulty in ("sandbox", "explorer") or bool(
|
||||||
|
unlocked.intersection({"cryo-hydrolox", "methalox-reusable", "heavy-lift", "deep-space-ion"})
|
||||||
|
)
|
||||||
|
req_dv = max(1000.0, float(candidate.get("requiredDv", 9500)))
|
||||||
|
tier = float(candidate.get("tier", 0))
|
||||||
|
est_cost = max(6e6, (req_dv / 9500.0) * 14.5e6 + tier * 5.5e6)
|
||||||
|
penalty = 0.0
|
||||||
|
if not has_high_isp and req_dv > 9800.0:
|
||||||
|
penalty += 2.4
|
||||||
|
if est_cost > treasury * 0.68:
|
||||||
|
penalty += 2.5
|
||||||
|
return penalty
|
||||||
|
|
||||||
|
def extract_features(candidate: Dict[str, Any], payload: Dict[str, Any]) -> List[float]:
|
||||||
|
agency = payload.get("agency") or {}
|
||||||
|
treasury = max(1e6, float(agency.get("treasury", 60e6)))
|
||||||
|
skill = float(agency.get("aiSkill", 0.85))
|
||||||
|
difficulty = str(agency.get("difficulty", "engineer"))
|
||||||
|
unlocked = set(agency.get("unlockedTechs") or ["starter"])
|
||||||
|
has_high_isp = difficulty in ("sandbox", "explorer") or bool(
|
||||||
|
unlocked.intersection({"cryo-hydrolox", "methalox-reusable", "heavy-lift", "deep-space-ion"})
|
||||||
|
)
|
||||||
|
req_dv = max(1000.0, float(candidate.get("requiredDv", 9500)))
|
||||||
|
budget = float(candidate.get("budget", 20e6))
|
||||||
|
tier = float(candidate.get("tier", 0))
|
||||||
|
is_home = 1.0 if candidate.get("isHomeSponsor") else 0.0
|
||||||
|
hazards = payload.get("hazards") or []
|
||||||
|
rad_haz = 1.0 if any(h.get("kind") == "stray-radiation" for h in hazards) else 0.0
|
||||||
|
met_haz = 1.0 if any(h.get("kind") == "meteorite-stream" for h in hazards) else 0.0
|
||||||
|
shear_haz = 1.0 if any(h.get("kind") == "jet-stream-shear" for h in hazards) else 0.0
|
||||||
|
weather = str(payload.get("weather", "nominal"))
|
||||||
|
weather_sev = 0.0 if weather == "nominal" else (0.35 if weather == "solar-wind" else 0.8)
|
||||||
|
tech_bonus_dv = 2600.0 if has_high_isp else 0.0
|
||||||
|
est_cap_dv = 9400.0 + tech_bonus_dv + min(2.0, treasury / 60e6) * 1200.0 + skill * 1000.0
|
||||||
|
afford_penalty = 1.0 if (max(6e6, (req_dv / 9500.0) * 14.5e6 + tier * 5.5e6) > treasury * 0.68) else 0.0
|
||||||
|
dv_margin_proxy = max(-2.0, min(2.0, (est_cap_dv - req_dv) / 4000.0 - afford_penalty))
|
||||||
|
budget_per_dv = min(3.0, (budget / 1e6) / max(1.0, req_dv / 1000.0))
|
||||||
|
tier_norm = min(1.0, tier / 3.0)
|
||||||
|
return [
|
||||||
|
1.0,
|
||||||
|
dv_margin_proxy,
|
||||||
|
budget_per_dv,
|
||||||
|
tier_norm,
|
||||||
|
is_home,
|
||||||
|
rad_haz,
|
||||||
|
met_haz,
|
||||||
|
shear_haz,
|
||||||
|
weather_sev,
|
||||||
|
skill,
|
||||||
|
]
|
||||||
|
|
||||||
|
def handle_status(weights_path: Path) -> Dict[str, Any]:
|
||||||
|
backends = detect_backends()
|
||||||
|
store = load_weights(weights_path)
|
||||||
|
return {
|
||||||
|
"ok": True,
|
||||||
|
"pythonVersion": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
|
||||||
|
"backend": backends["active"],
|
||||||
|
"availablePackages": backends["availablePackages"],
|
||||||
|
"weightsPath": str(weights_path),
|
||||||
|
"weightsLoaded": weights_path.exists(),
|
||||||
|
"episodes": int(store.get("episodes", 0)),
|
||||||
|
"avgReward": round(float(store.get("avgReward", 0.0)), 4),
|
||||||
|
}
|
||||||
|
|
||||||
|
def handle_predict(payload: Dict[str, Any], weights_path: Path) -> Dict[str, Any]:
|
||||||
|
backends = detect_backends()
|
||||||
|
store = load_weights(weights_path)
|
||||||
|
agency = payload.get("agency") or {}
|
||||||
|
agency_name = str(agency.get("name", ""))
|
||||||
|
ag_entry = store.get("agencies", {}).get(agency_name, {})
|
||||||
|
weights = ag_entry.get("weights") or store["sharedWeights"]
|
||||||
|
if len(weights) != len(FEATURE_NAMES):
|
||||||
|
weights = store["sharedWeights"]
|
||||||
|
candidates = payload.get("candidates") or []
|
||||||
|
best_id = None
|
||||||
|
best_tpl = None
|
||||||
|
best_cand: Dict[str, Any] = {}
|
||||||
|
best_score = -1e9
|
||||||
|
scores: List[Dict[str, Any]] = []
|
||||||
|
use_torch = False
|
||||||
|
if backends["active"] == "pytorch":
|
||||||
|
try:
|
||||||
|
import torch
|
||||||
|
use_torch = True
|
||||||
|
w_tensor = torch.tensor(weights, dtype=torch.float32)
|
||||||
|
for c in candidates:
|
||||||
|
feats = extract_features(c, payload)
|
||||||
|
x_tensor = torch.tensor(feats, dtype=torch.float32)
|
||||||
|
logit = float(torch.dot(w_tensor, x_tensor).item()) - _candidate_penalty(c, payload)
|
||||||
|
prob = sigmoid(logit)
|
||||||
|
scores.append({"offerId": c.get("offerId") or c.get("id"), "score": round(prob, 4)})
|
||||||
|
if logit > best_score:
|
||||||
|
best_score = logit
|
||||||
|
best_id = c.get("offerId") or c.get("id")
|
||||||
|
best_tpl = c.get("templateId") or c.get("id")
|
||||||
|
best_cand = c
|
||||||
|
except Exception:
|
||||||
|
use_torch = False
|
||||||
|
if not use_torch:
|
||||||
|
for c in candidates:
|
||||||
|
feats = extract_features(c, payload)
|
||||||
|
logit = dot(weights, feats) - _candidate_penalty(c, payload)
|
||||||
|
prob = sigmoid(logit)
|
||||||
|
scores.append({"offerId": c.get("offerId") or c.get("id"), "score": round(prob, 4)})
|
||||||
|
if logit > best_score:
|
||||||
|
best_score = logit
|
||||||
|
best_id = c.get("offerId") or c.get("id")
|
||||||
|
best_tpl = c.get("templateId") or c.get("id")
|
||||||
|
best_cand = c
|
||||||
|
hazards = payload.get("hazards") or []
|
||||||
|
has_shear = any(h.get("kind") == "jet-stream-shear" for h in hazards)
|
||||||
|
has_rad = any(h.get("kind") == "stray-radiation" for h in hazards) or best_cand.get("radiationHazard") == "extreme"
|
||||||
|
skill = float(agency.get("aiSkill", 0.85))
|
||||||
|
best_dv = float(best_cand.get("requiredDv", 9500))
|
||||||
|
pitch_kick = 7.4 if has_shear else (10.1 if best_dv > 10600 else 8.8 + skill * 1.1)
|
||||||
|
return {
|
||||||
|
"ok": True,
|
||||||
|
"backend": backends["active"],
|
||||||
|
"selectedOfferId": best_id,
|
||||||
|
"selectedTemplateId": best_tpl,
|
||||||
|
"policyConfidence": round(sigmoid(best_score), 3) if candidates else 0.5,
|
||||||
|
"suggestedPitchKickDeg": round(pitch_kick, 2),
|
||||||
|
"suggestedMaxQThrottle": round(0.66 if has_shear else 0.78, 2),
|
||||||
|
"suggestedPreferRadHard": bool(has_rad),
|
||||||
|
"scores": scores[:8],
|
||||||
|
}
|
||||||
|
|
||||||
|
def handle_train(payload: Dict[str, Any], weights_path: Path) -> Dict[str, Any]:
|
||||||
|
backends = detect_backends()
|
||||||
|
store = load_weights(weights_path)
|
||||||
|
agency_name = str(payload.get("agencyName", "ML-AI"))
|
||||||
|
reward = max(-1.5, min(2.0, float(payload.get("reward", 0.0))))
|
||||||
|
candidate = payload.get("candidate") or {}
|
||||||
|
feats = payload.get("features") or extract_features(candidate, payload)
|
||||||
|
if len(feats) != len(FEATURE_NAMES):
|
||||||
|
feats = default_weights_store()["sharedWeights"]
|
||||||
|
ag_map = store.setdefault("agencies", {})
|
||||||
|
ag_entry = ag_map.setdefault(
|
||||||
|
agency_name,
|
||||||
|
{"weights": list(store["sharedWeights"]), "episodes": 0, "avgReward": 0.0},
|
||||||
|
)
|
||||||
|
lr = 0.045
|
||||||
|
baseline = float(ag_entry.get("avgReward", 0.0))
|
||||||
|
advantage = reward - baseline * 0.5
|
||||||
|
if backends["active"] == "pytorch":
|
||||||
|
try:
|
||||||
|
import torch
|
||||||
|
w_t = torch.tensor(ag_entry["weights"], dtype=torch.float32)
|
||||||
|
x_t = torch.tensor(feats, dtype=torch.float32)
|
||||||
|
pred = torch.sigmoid(torch.dot(w_t, x_t))
|
||||||
|
grad_scale = lr * (advantage - 0.15 * float(pred.item()))
|
||||||
|
new_w = torch.clamp(w_t * 0.995 + grad_scale * x_t, -4.0, 4.0)
|
||||||
|
ag_entry["weights"] = [round(float(v), 5) for v in new_w.tolist()]
|
||||||
|
except Exception:
|
||||||
|
pred = sigmoid(dot(ag_entry["weights"], feats))
|
||||||
|
ag_entry["weights"] = [
|
||||||
|
round(max(-4.0, min(4.0, w * 0.995 + lr * (advantage - 0.15 * pred) * f)), 5)
|
||||||
|
for w, f in zip(ag_entry["weights"], feats)
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
pred = sigmoid(dot(ag_entry["weights"], feats))
|
||||||
|
ag_entry["weights"] = [
|
||||||
|
round(max(-4.0, min(4.0, w * 0.995 + lr * (advantage - 0.15 * pred) * f)), 5)
|
||||||
|
for w, f in zip(ag_entry["weights"], feats)
|
||||||
|
]
|
||||||
|
store["sharedWeights"] = [
|
||||||
|
round(0.92 * sw + 0.08 * aw, 5)
|
||||||
|
for sw, aw in zip(store["sharedWeights"], ag_entry["weights"])
|
||||||
|
]
|
||||||
|
ep_ag = int(ag_entry.get("episodes", 0)) + 1
|
||||||
|
ag_entry["episodes"] = ep_ag
|
||||||
|
ag_entry["avgReward"] = round(((ep_ag - 1) * float(ag_entry.get("avgReward", 0.0)) + reward) / ep_ag, 4)
|
||||||
|
ep_tot = int(store.get("episodes", 0)) + 1
|
||||||
|
store["episodes"] = ep_tot
|
||||||
|
store["avgReward"] = round(((ep_tot - 1) * float(store.get("avgReward", 0.0)) + reward) / ep_tot, 4)
|
||||||
|
save_weights(weights_path, store)
|
||||||
|
return {
|
||||||
|
"ok": True,
|
||||||
|
"backend": backends["active"],
|
||||||
|
"agencyEpisodes": ep_ag,
|
||||||
|
"agencyAvgReward": ag_entry["avgReward"],
|
||||||
|
"episodes": ep_tot,
|
||||||
|
"avgReward": store["avgReward"],
|
||||||
|
}
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
parser = argparse.ArgumentParser(description="Space Gaem optional ML AI bridge")
|
||||||
|
parser.add_argument("action", nargs="?", default="status", choices=["status", "predict", "train"])
|
||||||
|
parser.add_argument("--payload", default="", help="JSON payload string")
|
||||||
|
parser.add_argument("--weights", default=str(DEFAULT_WEIGHTS_PATH), help="Path to policy weights JSON")
|
||||||
|
args = parser.parse_args()
|
||||||
|
payload: Dict[str, Any] = {}
|
||||||
|
raw = args.payload.strip()
|
||||||
|
if raw == "-":
|
||||||
|
raw = sys.stdin.read().strip()
|
||||||
|
elif not raw and not sys.stdin.isatty():
|
||||||
|
raw = sys.stdin.read().strip()
|
||||||
|
if raw:
|
||||||
|
try:
|
||||||
|
payload = json.loads(raw)
|
||||||
|
except Exception as exc:
|
||||||
|
print(json.dumps({"ok": False, "error": f"Invalid JSON payload: {exc}"}))
|
||||||
|
return 1
|
||||||
|
action = payload.get("action") or args.action
|
||||||
|
weights_path = Path(args.weights)
|
||||||
|
if action == "status":
|
||||||
|
out = handle_status(weights_path)
|
||||||
|
elif action == "predict":
|
||||||
|
out = handle_predict(payload, weights_path)
|
||||||
|
elif action == "train":
|
||||||
|
out = handle_train(payload, weights_path)
|
||||||
|
else:
|
||||||
|
out = {"ok": False, "error": f"Unknown action {action}"}
|
||||||
|
print(json.dumps(out))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
170
src/client/api.ts
Normal file
170
src/client/api.ts
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
// Client HTTP API wrapper, token/settings localStorage helpers -> (this fails half the time but oh well), and SSE stream connection.
|
||||||
|
import type {
|
||||||
|
LockedDesignItemInfo,
|
||||||
|
RocketDesign,
|
||||||
|
SavedRocketBlueprint,
|
||||||
|
} from "../shared/types.js";
|
||||||
|
|
||||||
|
export interface ClientSettings {
|
||||||
|
quality: "low" | "medium" | "high";
|
||||||
|
sound: boolean;
|
||||||
|
notifications: boolean;
|
||||||
|
dynamicTheme: boolean;
|
||||||
|
colorMode: "dark" | "light";
|
||||||
|
reducedEffects: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TOKEN_KEY = "spacegaem_proto_token";
|
||||||
|
const SETTINGS_KEY = "spacegaem_proto_settings";
|
||||||
|
|
||||||
|
export function getToken(): string | null {
|
||||||
|
return localStorage.getItem(TOKEN_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setToken(t: string | null): void {
|
||||||
|
if (t) localStorage.setItem(TOKEN_KEY, t);
|
||||||
|
else localStorage.removeItem(TOKEN_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSettings(): ClientSettings {
|
||||||
|
try {
|
||||||
|
const raw = JSON.parse(
|
||||||
|
localStorage.getItem(SETTINGS_KEY) ?? "{}",
|
||||||
|
) as Partial<ClientSettings>;
|
||||||
|
return {
|
||||||
|
quality: raw.quality ?? "high",
|
||||||
|
sound: raw.sound ?? true,
|
||||||
|
notifications: raw.notifications ?? true,
|
||||||
|
dynamicTheme: raw.dynamicTheme ?? true,
|
||||||
|
colorMode: raw.colorMode === "light" ? "light" : "dark",
|
||||||
|
reducedEffects: raw.reducedEffects ?? false,
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
return {
|
||||||
|
quality: "high",
|
||||||
|
sound: true,
|
||||||
|
notifications: true,
|
||||||
|
dynamicTheme: true,
|
||||||
|
colorMode: "dark",
|
||||||
|
reducedEffects: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveSettings(s: ClientSettings): void {
|
||||||
|
localStorage.setItem(SETTINGS_KEY, JSON.stringify(s));
|
||||||
|
document.body.dataset.dynamicTheme = s.dynamicTheme ? "on" : "off";
|
||||||
|
document.documentElement.dataset.colorMode = s.colorMode;
|
||||||
|
document.documentElement.classList.toggle(
|
||||||
|
"reduced-effects",
|
||||||
|
!!s.reducedEffects,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function request<T = any>(
|
||||||
|
method: string,
|
||||||
|
url: string,
|
||||||
|
body?: unknown,
|
||||||
|
auth = true,
|
||||||
|
): Promise<T> {
|
||||||
|
const headers: Record<string, string> = {};
|
||||||
|
if (body !== undefined) headers["Content-Type"] = "application/json";
|
||||||
|
const token = getToken();
|
||||||
|
if (auth && token) headers.Authorization = `Bearer ${token}`;
|
||||||
|
const res = await fetch(url, {
|
||||||
|
method,
|
||||||
|
headers,
|
||||||
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||||
|
});
|
||||||
|
const text = await res.text();
|
||||||
|
let data: any = null;
|
||||||
|
try {
|
||||||
|
data = text ? JSON.parse(text) : null;
|
||||||
|
} catch {
|
||||||
|
data = { error: text };
|
||||||
|
}
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(data?.error ?? `HTTP ${res.status}`);
|
||||||
|
}
|
||||||
|
return data as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const api = {
|
||||||
|
get: <T = any>(url: string, auth = true) =>
|
||||||
|
request<T>("GET", url, undefined, auth),
|
||||||
|
post: <T = any>(url: string, body: unknown, auth = true) =>
|
||||||
|
request<T>("POST", url, body, auth),
|
||||||
|
delete: <T = any>(url: string, auth = true) =>
|
||||||
|
request<T>("DELETE", url, undefined, auth),
|
||||||
|
getMlStatus: () => request<any>("GET", "/api/ml-status", undefined, false),
|
||||||
|
toggleMlBridge: (enabled?: boolean) =>
|
||||||
|
request<any>("POST", "/api/ml-toggle", { enabled }, true),
|
||||||
|
getDesigns: () =>
|
||||||
|
request<{
|
||||||
|
ok: boolean;
|
||||||
|
myDesigns: SavedRocketBlueprint[];
|
||||||
|
communityDesigns: SavedRocketBlueprint[];
|
||||||
|
}>("GET", "/api/agency/designs", undefined, true),
|
||||||
|
saveDesignBlueprint: (payload: {
|
||||||
|
id?: string;
|
||||||
|
name: string;
|
||||||
|
design: RocketDesign;
|
||||||
|
notes?: string;
|
||||||
|
isPublic?: boolean;
|
||||||
|
targetHint?: string;
|
||||||
|
}) =>
|
||||||
|
request<{
|
||||||
|
ok: boolean;
|
||||||
|
blueprint: SavedRocketBlueprint;
|
||||||
|
shareCode: string;
|
||||||
|
myDesigns: SavedRocketBlueprint[];
|
||||||
|
communityDesigns: SavedRocketBlueprint[];
|
||||||
|
}>("POST", "/api/agency/designs", payload, true),
|
||||||
|
deleteDesignBlueprint: (id: string) =>
|
||||||
|
request<{
|
||||||
|
ok: boolean;
|
||||||
|
myDesigns: SavedRocketBlueprint[];
|
||||||
|
communityDesigns: SavedRocketBlueprint[];
|
||||||
|
}>(
|
||||||
|
"DELETE",
|
||||||
|
`/api/agency/designs/${encodeURIComponent(id)}`,
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
importDesignBlueprint: (payload: {
|
||||||
|
codeOrJson: string;
|
||||||
|
name?: string;
|
||||||
|
saveToHangar?: boolean;
|
||||||
|
}) =>
|
||||||
|
request<{
|
||||||
|
ok: boolean;
|
||||||
|
design: RocketDesign;
|
||||||
|
shareCode: string;
|
||||||
|
lockedItems: LockedDesignItemInfo[];
|
||||||
|
summary: {
|
||||||
|
totalDv: number;
|
||||||
|
totalCost: number;
|
||||||
|
stageCount: number;
|
||||||
|
designTier: string;
|
||||||
|
};
|
||||||
|
blueprint?: SavedRocketBlueprint;
|
||||||
|
myDesigns?: SavedRocketBlueprint[];
|
||||||
|
}>("POST", "/api/agency/designs/import", payload, true),
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface LiveEvent {
|
||||||
|
type: string;
|
||||||
|
data?: Record<string, any>;
|
||||||
|
at?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function connectEvents(onEvent: (ev: LiveEvent) => void): EventSource {
|
||||||
|
const es = new EventSource("/api/events");
|
||||||
|
es.onmessage = (msg) => {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(msg.data) as LiveEvent;
|
||||||
|
onEvent(parsed);
|
||||||
|
} catch {}
|
||||||
|
};
|
||||||
|
return es;
|
||||||
|
}
|
||||||
140
src/client/app.ts
Normal file
140
src/client/app.ts
Normal file
|
|
@ -0,0 +1,140 @@
|
||||||
|
// Literally everything (pls help me my autocorrect is trying to insult me how does this even work)
|
||||||
|
import { getSettings, saveSettings } from "./api.js";
|
||||||
|
import { navigate, registerScreenRenderers } from "./router.js";
|
||||||
|
import {
|
||||||
|
loadCatalogs,
|
||||||
|
refreshMe,
|
||||||
|
refreshWorld,
|
||||||
|
startEvents,
|
||||||
|
} from "./session.js";
|
||||||
|
import {
|
||||||
|
applyThemeFromState,
|
||||||
|
type DebriefScreenParams,
|
||||||
|
type LaunchScreenParams,
|
||||||
|
state,
|
||||||
|
} from "./state.js";
|
||||||
|
import {
|
||||||
|
getColorMode,
|
||||||
|
isReducedEffects,
|
||||||
|
toggleColorMode,
|
||||||
|
toggleReducedEffects,
|
||||||
|
} from "./theme.js";
|
||||||
|
import {
|
||||||
|
clear,
|
||||||
|
h,
|
||||||
|
initNotificationDrawer,
|
||||||
|
initTooltipController,
|
||||||
|
toast,
|
||||||
|
} from "./ui.js";
|
||||||
|
import { renderAuth } from "./screens/auth.js";
|
||||||
|
import { renderContracts } from "./screens/contracts.js";
|
||||||
|
import { renderDashboard } from "./screens/dashboard.js";
|
||||||
|
import { renderDebrief } from "./screens/debrief.js";
|
||||||
|
import { renderLaunchSequence } from "./screens/launchSequence.js";
|
||||||
|
import { renderMainMenu } from "./screens/mainMenu.js";
|
||||||
|
import { renderMissionConfig } from "./screens/missionConfig.js";
|
||||||
|
import { renderOnboarding } from "./screens/onboarding.js";
|
||||||
|
import { renderRocketBuilder } from "./screens/rocketBuilder.js";
|
||||||
|
import { renderWorldMap } from "./screens/worldMap.js";
|
||||||
|
|
||||||
|
registerScreenRenderers({
|
||||||
|
mainMenu: (el) => renderMainMenu(el),
|
||||||
|
auth: (el) => renderAuth(el),
|
||||||
|
onboarding: (el) => renderOnboarding(el),
|
||||||
|
dashboard: (el) => renderDashboard(el),
|
||||||
|
builder: (el) => renderRocketBuilder(el),
|
||||||
|
config: (el) => renderMissionConfig(el),
|
||||||
|
launch: (el, p) => renderLaunchSequence(el, p as LaunchScreenParams),
|
||||||
|
debrief: (el, p) => renderDebrief(el, p as DebriefScreenParams),
|
||||||
|
contracts: (el) => renderContracts(el),
|
||||||
|
worldMap: (el) => renderWorldMap(el),
|
||||||
|
});
|
||||||
|
|
||||||
|
function renderComfortToolbar(): void {
|
||||||
|
const root = document.getElementById("comfort-controls-root");
|
||||||
|
if (!root) return;
|
||||||
|
clear(root);
|
||||||
|
const mode = getColorMode();
|
||||||
|
const reduced = isReducedEffects();
|
||||||
|
root.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "comfort-pill-bar" },
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `comfort-btn ${mode === "light" ? "active" : ""}`,
|
||||||
|
title: "Toggle Daylight Light Mode / Dark Mode",
|
||||||
|
onClick: () => {
|
||||||
|
toggleColorMode();
|
||||||
|
renderComfortToolbar();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mode === "light" ? "SUN LIGHT" : "DARK",
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `comfort-btn ${reduced ? "active" : ""}`,
|
||||||
|
title:
|
||||||
|
"Toggle Eye-Saver (Reduced Effects: disables glows, scanlines & shake)",
|
||||||
|
onClick: () => {
|
||||||
|
toggleReducedEffects();
|
||||||
|
applyThemeFromState();
|
||||||
|
renderComfortToolbar();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
reduced ? "EYE-SAVER ON" : "EYE-SAVER",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitForStylesAndLoad(): Promise<void> {
|
||||||
|
const pendingLinks = Array.from(
|
||||||
|
document.querySelectorAll('link[rel="stylesheet"]'),
|
||||||
|
) as HTMLLinkElement[];
|
||||||
|
const cssPromises = pendingLinks
|
||||||
|
.filter((link) => !link.sheet)
|
||||||
|
.map(
|
||||||
|
(link) =>
|
||||||
|
new Promise<void>((resolve) => {
|
||||||
|
link.addEventListener("load", () => resolve(), { once: true });
|
||||||
|
link.addEventListener("error", () => resolve(), { once: true });
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const loadPromise =
|
||||||
|
document.readyState === "complete"
|
||||||
|
? Promise.resolve()
|
||||||
|
: new Promise<void>((resolve) => {
|
||||||
|
window.addEventListener("load", () => resolve(), { once: true });
|
||||||
|
});
|
||||||
|
await Promise.race([
|
||||||
|
Promise.all([loadPromise, ...cssPromises]).then(() => undefined),
|
||||||
|
new Promise<void>((resolve) => window.setTimeout(resolve, 1500)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function boot(): Promise<void> {
|
||||||
|
saveSettings(getSettings());
|
||||||
|
applyThemeFromState();
|
||||||
|
renderComfortToolbar();
|
||||||
|
window.addEventListener("sgywftp:theme-changed", renderComfortToolbar);
|
||||||
|
initNotificationDrawer();
|
||||||
|
initTooltipController();
|
||||||
|
const readyPromise = waitForStylesAndLoad();
|
||||||
|
try {
|
||||||
|
await loadCatalogs();
|
||||||
|
} catch (err) {
|
||||||
|
toast(`Failed to load mission catalogs: ${(err as Error).message}`, "err");
|
||||||
|
}
|
||||||
|
await refreshMe();
|
||||||
|
if (state.agency) {
|
||||||
|
await refreshWorld();
|
||||||
|
startEvents();
|
||||||
|
}
|
||||||
|
await readyPromise;
|
||||||
|
navigate("mainMenu");
|
||||||
|
}
|
||||||
|
|
||||||
|
void boot();
|
||||||
389
src/client/glossary.ts
Normal file
389
src/client/glossary.ts
Normal file
|
|
@ -0,0 +1,389 @@
|
||||||
|
// Terminologic glossary, cus I forget what this shit means every 2 seconds pls don't ask me this, I not know rockeet siençe
|
||||||
|
export interface GlossaryEntry {
|
||||||
|
title: string;
|
||||||
|
summary: string;
|
||||||
|
formula?: string;
|
||||||
|
category:
|
||||||
|
| "Propulsion"
|
||||||
|
| "Structures & Aero"
|
||||||
|
| "Flight & Orbit"
|
||||||
|
| "Avionics & Bus"
|
||||||
|
| "Program & Compliance";
|
||||||
|
}
|
||||||
|
|
||||||
|
const TERMINOLOGY_GLOSSARY_RAW = {
|
||||||
|
dv: {
|
||||||
|
title: "Delta-v (Δv)",
|
||||||
|
summary:
|
||||||
|
"Total velocity-change capability of the launch vehicle across all stages. Includes gravity, drag, and steering losses during ascent.",
|
||||||
|
formula:
|
||||||
|
"Δv = Isp · g0 · ln(m_wet / m_dry) (two-phase when jettisoning drop tanks)",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
dv_margin: {
|
||||||
|
title: "Delta-v Margin",
|
||||||
|
summary:
|
||||||
|
"Difference between your rocket Δv and the mission target requirement. Positive margin provides reserve for wind shear, throttling, and guidance dispersion.",
|
||||||
|
formula: "Margin = Vehicle Δv − Required Δv",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
req_dv: {
|
||||||
|
title: "Required Delta-v",
|
||||||
|
summary:
|
||||||
|
"Minimum velocity budget needed to enter the target orbit, including inclination plane cost, Earth ascent losses (~1,400–1,800 m/s), and transfer burns.",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
twr: {
|
||||||
|
title: "Thrust-to-Weight Ratio (TWR)",
|
||||||
|
summary:
|
||||||
|
"Total engine thrust divided by vehicle Earth weight at liftoff. Must exceed 1.02 to lift off the pad; 1.30–1.70 minimizes gravity losses without excessive Max-Q.",
|
||||||
|
formula: "TWR = Thrust / (Wet Mass × 9.81 m/s²)",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
stage_twr: {
|
||||||
|
title: "Stage Ignition TWR",
|
||||||
|
summary:
|
||||||
|
"Thrust-to-weight ratio at the moment this stage ignites in flight. Upper stages should maintain ≥ 0.50 so the vehicle climbs past apoapsis before falling back.",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
isp: {
|
||||||
|
title: "Specific Impulse (Isp)",
|
||||||
|
summary:
|
||||||
|
"Propellant fuel efficiency measured in seconds (higher means more thrust per kg burned per second). Vacuum Isp is higher than sea-level Isp due to zero atmospheric backpressure.",
|
||||||
|
formula: "ve = Isp · g0 (effective exhaust velocity)",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
nozzle_ratio: {
|
||||||
|
title: "Nozzle Expansion Ratio",
|
||||||
|
summary:
|
||||||
|
"Bell exit-area scaling factor. Smaller bells (0.85–1.0×) resist sea-level flow separation near liftoff; wider bells (1.15–1.4×) boost vacuum Isp on upper stages.",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
gimbal: {
|
||||||
|
title: "Gimbal Deflection Range",
|
||||||
|
summary:
|
||||||
|
"Maximum nozzle pivot angle (± degrees) for Thrust Vector Control (TVC). Enables steering during the pitch-over turn and counters aerodynamic instability or wind shear.",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
propellant_chemistry: {
|
||||||
|
title: "Propellant Chemistry",
|
||||||
|
summary:
|
||||||
|
"Kerolox (RP-1/LOX) is dense with high thrust; Hydrolox (LH2/LOX) offers top Isp but needs bulky insulated tanks; Methalox balances density & efficiency; Hypergolic is storable; Solid cannot throttle.",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
crossfeed: {
|
||||||
|
title: "Propellant Crossfeed",
|
||||||
|
summary:
|
||||||
|
"Plumbing manifold that draws fuel and oxidizer from external drop tanks first while keeping the core tank full, allowing empty external casings to drop early mid-burn.",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
drop_tanks: {
|
||||||
|
title: "Disposable Drop Tanks",
|
||||||
|
summary:
|
||||||
|
"Aerodynamic external tanks mounted radially onto a liquid stage (e.g., 1× Shuttle-style belly tank or 2×–6× side pods). Drained first via crossfeed and jettisoned empty mid-burn to raise Δv.",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
fill_ratio: {
|
||||||
|
title: "Tank Fill Ratio",
|
||||||
|
summary:
|
||||||
|
"Percentage of propellant volume loaded before launch (Expert mode). Offloading propellant lowers liftoff weight and raises TWR at the cost of reduced total Δv.",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
engine_count: {
|
||||||
|
title: "Engine Cluster Count",
|
||||||
|
summary:
|
||||||
|
"Number of identical engines mounted on this stage thrust structure. Multiplies stage thrust and mass flow proportionally while keeping the same propellant tank.",
|
||||||
|
category: "Propulsion",
|
||||||
|
},
|
||||||
|
wet_dry_mass: {
|
||||||
|
title: "Wet vs Dry Mass",
|
||||||
|
summary:
|
||||||
|
"Wet mass is fueled liftoff mass (structure + engines + payload + propellant). Dry mass is structural mass remaining at burnout. Rocket Δv grows with the ratio of Wet to Dry mass.",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
cg_cp: {
|
||||||
|
title: "CG vs CP (Center of Gravity / Pressure)",
|
||||||
|
summary:
|
||||||
|
"CG is the mass balance point; CP is where aerodynamic lift acts. Keeping CG ahead of (above) CP makes the rocket naturally arrow-stable in flight.",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
stability_calibers: {
|
||||||
|
title: "Static Stability Margin (Calibers)",
|
||||||
|
summary:
|
||||||
|
"Distance from Center of Pressure up to Center of Gravity divided by hull diameter. Positive calibers passively stabilize ascent; deeply negative values risk tumbling under Max-Q.",
|
||||||
|
formula: "Margin = (CG_y − CP_y) / Max Diameter",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
fineness: {
|
||||||
|
title: "Fineness Ratio (L / D)",
|
||||||
|
summary:
|
||||||
|
"Ratio of overall rocket height to maximum fuselage diameter. Tall slender rockets (> 20.5 L/D) cut frontal drag but endure sharper structural bending during Max-Q.",
|
||||||
|
formula: "L/D = Total Height / Max Diameter",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
buckling: {
|
||||||
|
title: "Axial Buckling Ratio",
|
||||||
|
summary:
|
||||||
|
"Ratio of peak compressive/bending launch load to the airframe shell limit. Must remain below 1.00; thicken walls or upgrade hull materials/structures if exceeded.",
|
||||||
|
formula: "Buckling = Peak Axial + Wind Load / Shell Yield Capacity",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
max_q: {
|
||||||
|
title: "Max-Q (Maximum Dynamic Pressure)",
|
||||||
|
summary:
|
||||||
|
"Peak aerodynamic pressure q = ½ ρ v² experienced in the dense lower atmosphere near Mach 1. Over-speeding or soft walls above stage Max-Q limit cause structural breakup.",
|
||||||
|
formula: "q = ½ · ρ(alt) · v²",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
wall_factor: {
|
||||||
|
title: "Wall Thickness Multiplier",
|
||||||
|
summary:
|
||||||
|
"Scales airframe skin gauge above/below baseline. Thicker walls raise buckling and Max-Q structural limits while adding dry mass.",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
airframe_material: {
|
||||||
|
title: "Hull Material",
|
||||||
|
summary:
|
||||||
|
"Alloys and composites trade mass density against yield strength and heat tolerance: Al-Li and Carbon Composite shave dry weight; Stainless Steel resists high thermal loads.",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
interstage: {
|
||||||
|
title: "Interstage Adapter",
|
||||||
|
summary:
|
||||||
|
"Structural shroud/truss bridging two stage diameters and enclosing upper-stage engine bells with pneumatic or pyrotechnic separation latches.",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
grid_fins: {
|
||||||
|
title: "Aerodynamic Fins / Grid Fins",
|
||||||
|
summary:
|
||||||
|
"Tail-mounted fins generating restoring drag force aft of the Center of Gravity, pulling CP downward to stabilize top-heavy or wide-fairing rockets.",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
heatshield: {
|
||||||
|
title: "TPS Heatshield Blanket",
|
||||||
|
summary:
|
||||||
|
"Thermal Protection System ablative or tile cladding that raises stage survival temperature against high-speed atmospheric friction and reentry plasma.",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
fairing: {
|
||||||
|
title: "Payload Fairing",
|
||||||
|
summary:
|
||||||
|
"Clamshell nose shroud shielding satellites from supersonic airflow, wind shear, and debris. Automatically jettisoned once outside dense atmosphere (~80–120 km).",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
las: {
|
||||||
|
title: "Launch Abort System (LAS)",
|
||||||
|
summary:
|
||||||
|
"High-thrust solid escape tower mounted atop crew capsules to yank astronauts clear of pad fires or mid-ascent booster failures.",
|
||||||
|
category: "Structures & Aero",
|
||||||
|
},
|
||||||
|
apoapsis: {
|
||||||
|
title: "Apoapsis (Ap)",
|
||||||
|
summary:
|
||||||
|
"Highest altitude point along an orbital ellipse. Reaching target apoapsis allows coasting upward before a final circularization burn raises periapsis.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
periapsis: {
|
||||||
|
title: "Periapsis (Pe)",
|
||||||
|
summary:
|
||||||
|
"Lowest altitude point along an orbit. Must stay above Earth dense atmosphere (≥ 90 km) for a stable non-decaying parking orbit.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
inclination: {
|
||||||
|
title: "Orbital Inclination (i)",
|
||||||
|
summary:
|
||||||
|
"Angle between the orbital plane and Earth equator (0° equatorial, 28.5° KSC, 97.5° polar Sun-synchronous). Higher inclination loses surface rotational launch assist.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
mach: {
|
||||||
|
title: "Mach Number",
|
||||||
|
summary:
|
||||||
|
"Airspeed divided by the local speed of sound at current altitude temperature. Transonic shock waves and drag peak sharply between Mach 0.85 and 1.25.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
g_load: {
|
||||||
|
title: "Axial Acceleration (G-Load)",
|
||||||
|
summary:
|
||||||
|
"Total acceleration felt by vehicle structure and crew in multiples of Earth gravity (9.81 m/s²). Crewed capsules enforce strict G-limits as propellant empties.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
heat_flux: {
|
||||||
|
title: "Aerodynamic Heat Flux",
|
||||||
|
summary:
|
||||||
|
"Stagnation heating power (W/cm²) transferred from compressed supersonic air onto the nosecone, drop tanks, and exposed structures.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
flight_path_angle: {
|
||||||
|
title: "Pitch & Gravity Turn",
|
||||||
|
summary:
|
||||||
|
"Vehicle nose angle relative to the local horizon (90° straight up, 0° horizontal). A crisp pitch-over kick lets gravity bend velocity efficiently toward orbit.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
meco_seco: {
|
||||||
|
title: "MECO / SECO",
|
||||||
|
summary:
|
||||||
|
"Main Engine Cutoff (first-stage shutdown and separation) and Second/Sustainer Engine Cutoff (upper stage shutdown once target orbit corridor is met).",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
burnout_metrics: {
|
||||||
|
title: "Burnout Velocity & Downrange",
|
||||||
|
summary:
|
||||||
|
"Speed and great-circle distance traveled east/azimuth from the launch pad when orbital insertion or fuel exhaustion occurs.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
dv_remaining: {
|
||||||
|
title: "Remaining Δv Reserve",
|
||||||
|
summary:
|
||||||
|
"Unspent velocity-change impulse remaining after parking orbit insertion, used for circularization or trans-lunar / planetary injection burns.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
park_orbit_quality: {
|
||||||
|
title: "Orbit Insertion Grade",
|
||||||
|
summary:
|
||||||
|
"Precision rating (A+ to Failed) comparing achieved Apoapsis, Periapsis, and Inclination corridor accuracy against mission tolerances.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
max_q_throttle: {
|
||||||
|
title: "Max-Q Throttle Limit",
|
||||||
|
summary:
|
||||||
|
"Automated engine throttle-down near Max-Q (~Mach 0.9–1.5) to prevent aerodynamic dynamic pressure from exceeding airframe yield stress.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
fairing_sep_alt: {
|
||||||
|
title: "Fairing Separation Altitude",
|
||||||
|
summary:
|
||||||
|
"Altitude (km) at which the protective payload shroud jettisons. Jettisoning too low risks aero/micrometeoroid payload damage; too high hauls unnecessary mass.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
turn_end_alt: {
|
||||||
|
title: "Gravity Turn End Altitude",
|
||||||
|
summary:
|
||||||
|
"Altitude at which guidance finishes flattening toward horizontal (0°). Too low burns in thick air; too high wastes propellant fighting gravity.",
|
||||||
|
category: "Flight & Orbit",
|
||||||
|
},
|
||||||
|
flight_computer: {
|
||||||
|
title: "Flight Computer (GNC)",
|
||||||
|
summary:
|
||||||
|
"Guidance, Navigation & Control avionics processing attitude loops, crossfeed valve sequencing, telemetry encoding, and fault voting.",
|
||||||
|
category: "Avionics & Bus",
|
||||||
|
},
|
||||||
|
rad_hardening: {
|
||||||
|
title: "Radiation Hardening (RAD)",
|
||||||
|
summary:
|
||||||
|
"Chip-level shielding & Triple Modular Redundancy resisting cosmic rays and solar proton storms that trigger Single-Event Upsets (SEUs).",
|
||||||
|
category: "Avionics & Bus",
|
||||||
|
},
|
||||||
|
cpu_load: {
|
||||||
|
title: "Peak CPU Load",
|
||||||
|
summary:
|
||||||
|
"Flight computer processor utilization across multi-engine throttling, drop-tank crossfeed logic, comms, and hazard avoidance. Exceeding 92–100% risks guidance freeze.",
|
||||||
|
category: "Avionics & Bus",
|
||||||
|
},
|
||||||
|
seu: {
|
||||||
|
title: "Single-Event Upsets (SEUs)",
|
||||||
|
summary:
|
||||||
|
"Transient bit-flips caused by ionizing radiation during solar storms or high-altitude belts. Unshielded avionics suffer cumulative resets if SEUs spike.",
|
||||||
|
category: "Avionics & Bus",
|
||||||
|
},
|
||||||
|
reliability_risk: {
|
||||||
|
title: "Hardware Defect Risk",
|
||||||
|
summary:
|
||||||
|
"Estimated per-flight component malfunction chance derived from part maturity, thermal/Max-Q margins, and manufacturing quality control.",
|
||||||
|
category: "Avionics & Bus",
|
||||||
|
},
|
||||||
|
maturity: {
|
||||||
|
title: "Design Maturity",
|
||||||
|
summary:
|
||||||
|
"Flight qualification tier (Concept → Prototype → Flight-Proven). Test flights and successful missions lower hardware failure probability and insurance costs.",
|
||||||
|
category: "Avionics & Bus",
|
||||||
|
},
|
||||||
|
spacecraft_bus: {
|
||||||
|
title: "Spacecraft Bus & Power",
|
||||||
|
summary:
|
||||||
|
"Payload support subsystems: solar arrays or RTGs, batteries, Reaction Control System (RCS), and thermal radiators needed to keep the mission alive in space.",
|
||||||
|
category: "Avionics & Bus",
|
||||||
|
},
|
||||||
|
power_margin: {
|
||||||
|
title: "Electrical Power Margin",
|
||||||
|
summary:
|
||||||
|
"Generated solar/RTG wattage minus continuous bus, heater, and comms transmitter consumption. Negative balance causes battery depletion and brownouts.",
|
||||||
|
category: "Avionics & Bus",
|
||||||
|
},
|
||||||
|
comms_link: {
|
||||||
|
title: "Comms Signal Health",
|
||||||
|
summary:
|
||||||
|
"RF/Optical telemetry link quality balancing antenna dish gain, transmitter band (S/X/Ka/Optical), Earth tracking network tier, and distance attenuation.",
|
||||||
|
category: "Avionics & Bus",
|
||||||
|
},
|
||||||
|
telemetry_freq: {
|
||||||
|
title: "Tracking Station & Link Band",
|
||||||
|
summary:
|
||||||
|
"Ground antenna handover across range stations (Regional vs Global Deep Space Network) and carrier frequency carrying live guidance and health frames.",
|
||||||
|
category: "Avionics & Bus",
|
||||||
|
},
|
||||||
|
crew_eclss: {
|
||||||
|
title: "Crew Capacity & ECLSS",
|
||||||
|
summary:
|
||||||
|
"Astronaut seats aboard the flight and Environmental Control & Life Support System rating governing oxygen regeneration, CO2 scrubbing, and emergency reserve.",
|
||||||
|
category: "Program & Compliance",
|
||||||
|
},
|
||||||
|
safety_compliance: {
|
||||||
|
title: "Engineering & Safety Compliance",
|
||||||
|
summary:
|
||||||
|
"Pre-launch Range Safety rules (PROP, STR, FLT, SAF, AVN, BUS). Blocking failures halt launch; advisory warnings may require design fixes or a paid Waiver.",
|
||||||
|
category: "Program & Compliance",
|
||||||
|
},
|
||||||
|
waivers: {
|
||||||
|
title: "Flight Safety Waiver",
|
||||||
|
summary:
|
||||||
|
"Regulatory exception allowing launch despite an advisory compliance flag for an added fee and increased in-flight risk. Critical safety rules cannot be waived.",
|
||||||
|
category: "Program & Compliance",
|
||||||
|
},
|
||||||
|
rd_tech: {
|
||||||
|
title: "R&D Tech Tree",
|
||||||
|
summary:
|
||||||
|
"Agency research investments unlocking advanced engines, high-capacity external drop tanks, low-mass alloys, and deep-space avionics.",
|
||||||
|
category: "Program & Compliance",
|
||||||
|
},
|
||||||
|
difficulty: {
|
||||||
|
title: "Simulation Difficulty",
|
||||||
|
summary:
|
||||||
|
"Controls engineering realism: Casual grants forgiving margins; Standard balances physics & finance; Expert enables tank fill ratios, severe wind shear, and radiation SEUs.",
|
||||||
|
category: "Program & Compliance",
|
||||||
|
},
|
||||||
|
design_tier: {
|
||||||
|
title: "Builder Architecture Mode",
|
||||||
|
summary:
|
||||||
|
"Guided mode uses structured per-stage slots + drop-tank symmetry controls; Pro Freeform enables direct 3D axis placement, arbitrary radial pods, and custom part stacking.",
|
||||||
|
category: "Program & Compliance",
|
||||||
|
},
|
||||||
|
contract_tier: {
|
||||||
|
title: "Contract Tier & Payout",
|
||||||
|
summary:
|
||||||
|
"Mission difficulty bracket (T1–T5) setting payload mass, orbital destination, deadline window, completion payout, and penalty upon loss or cancellation.",
|
||||||
|
category: "Program & Compliance",
|
||||||
|
},
|
||||||
|
space_weather: {
|
||||||
|
title: "Space Weather & Range Hazards",
|
||||||
|
summary:
|
||||||
|
"Forecast solar wind, proton storms (raising SEU risk), upper atmospheric wind shear (spiking Max-Q loads), and micrometeoroid flux affecting launch timing.",
|
||||||
|
category: "Program & Compliance",
|
||||||
|
},
|
||||||
|
launch_cost: {
|
||||||
|
title: "Total Mission Cost",
|
||||||
|
summary:
|
||||||
|
"Total expenditure debited upon launch: stages, engines, core & disposable tanks, avionics, payload integration, range fees, and any active waivers.",
|
||||||
|
category: "Program & Compliance",
|
||||||
|
},
|
||||||
|
ground_network: {
|
||||||
|
title: "Ground Tracking Network",
|
||||||
|
summary:
|
||||||
|
"Earth dish infrastructure tier (Regional vs Global DSN) needed to maintain command uplink downrange and across deep-space distances.",
|
||||||
|
category: "Program & Compliance",
|
||||||
|
},
|
||||||
|
} as const satisfies Record<string, GlossaryEntry>;
|
||||||
|
|
||||||
|
export type GlossaryKey = keyof typeof TERMINOLOGY_GLOSSARY_RAW;
|
||||||
|
|
||||||
|
export const TERMINOLOGY_GLOSSARY: Record<GlossaryKey, GlossaryEntry> =
|
||||||
|
TERMINOLOGY_GLOSSARY_RAW;
|
||||||
57
src/client/router.ts
Normal file
57
src/client/router.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
// (Tech support with -4 hours of sleep and 6th mug of coffee) Uhm, sir, have you tried turning it off and on again?
|
||||||
|
// Oh.
|
||||||
|
// Oh...
|
||||||
|
import { type ScreenName, setCurrentScreen } from "./state.js";
|
||||||
|
import { clear, hideTooltip } from "./ui.js";
|
||||||
|
|
||||||
|
export type ScreenRenderer = (
|
||||||
|
appEl: HTMLElement,
|
||||||
|
params: Record<string, any>,
|
||||||
|
) => (() => void) | void;
|
||||||
|
|
||||||
|
const appEl = document.getElementById("app") as HTMLElement;
|
||||||
|
let activeCleanup: (() => void) | null = null;
|
||||||
|
let screenRenderers: Partial<Record<ScreenName, ScreenRenderer>> = {};
|
||||||
|
|
||||||
|
const RIGHT_SIDEBAR_OFFSET_PX: Partial<Record<ScreenName, number>> = {
|
||||||
|
dashboard: 370,
|
||||||
|
builder: 440,
|
||||||
|
config: 440,
|
||||||
|
worldMap: 340,
|
||||||
|
};
|
||||||
|
|
||||||
|
export function registerScreenRenderers(
|
||||||
|
renderers: Partial<Record<ScreenName, ScreenRenderer>>,
|
||||||
|
): void {
|
||||||
|
screenRenderers = renderers;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function navigate(
|
||||||
|
screen: ScreenName,
|
||||||
|
params: Record<string, any> = {},
|
||||||
|
): void {
|
||||||
|
if (activeCleanup) {
|
||||||
|
try {
|
||||||
|
activeCleanup();
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("Cleanup error:", err);
|
||||||
|
}
|
||||||
|
activeCleanup = null;
|
||||||
|
}
|
||||||
|
setCurrentScreen(screen);
|
||||||
|
const sidebarOffset = RIGHT_SIDEBAR_OFFSET_PX[screen] ?? 0;
|
||||||
|
document.documentElement.style.setProperty(
|
||||||
|
"--right-sidebar-offset",
|
||||||
|
`${sidebarOffset}px`,
|
||||||
|
);
|
||||||
|
document.documentElement.classList.toggle(
|
||||||
|
"has-right-sidebar",
|
||||||
|
sidebarOffset > 0,
|
||||||
|
);
|
||||||
|
clear(appEl);
|
||||||
|
hideTooltip();
|
||||||
|
const cleanup = screenRenderers[screen]?.(appEl, params);
|
||||||
|
if (typeof cleanup === "function") {
|
||||||
|
activeCleanup = cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
192
src/client/screens/auth.ts
Normal file
192
src/client/screens/auth.ts
Normal file
|
|
@ -0,0 +1,192 @@
|
||||||
|
// Login, registration, and difficulty selector screen.
|
||||||
|
import { api, setToken } from "../api.js";
|
||||||
|
import { navigate } from "../router.js";
|
||||||
|
import { refreshMe, refreshWorld, startEvents } from "../session.js";
|
||||||
|
import { state } from "../state.js";
|
||||||
|
import { DIFFICULTY_PROFILES } from "../../shared/physics.js";
|
||||||
|
import type { AgencyState, CanonicalDifficulty } from "../../shared/types.js";
|
||||||
|
import { h, toast } from "../ui.js";
|
||||||
|
|
||||||
|
export function renderAuth(root: HTMLElement): void {
|
||||||
|
let mode: "login" | "register" = "register";
|
||||||
|
let difficulty: CanonicalDifficulty = "enthusiast";
|
||||||
|
const nameInput = h("input", {
|
||||||
|
class: "input",
|
||||||
|
placeholder: "e.g. Aether Aerospace",
|
||||||
|
autocomplete: "organization",
|
||||||
|
});
|
||||||
|
const pwdInput = h("input", {
|
||||||
|
class: "input",
|
||||||
|
type: "password",
|
||||||
|
placeholder: "Account passphrase (min 4 chars)",
|
||||||
|
autocomplete: "current-password",
|
||||||
|
});
|
||||||
|
const errEl = h("div", { class: "auth-error" });
|
||||||
|
const tabLogin = h(
|
||||||
|
"button",
|
||||||
|
{ class: "btn sm ghost" },
|
||||||
|
"Existing Agency Login",
|
||||||
|
);
|
||||||
|
const tabRegister = h(
|
||||||
|
"button",
|
||||||
|
{ class: "btn sm primary" },
|
||||||
|
"Register New Agency",
|
||||||
|
);
|
||||||
|
const diffKeys: CanonicalDifficulty[] = [
|
||||||
|
"sandbox",
|
||||||
|
"explorer",
|
||||||
|
"enthusiast",
|
||||||
|
"engineer",
|
||||||
|
"director",
|
||||||
|
];
|
||||||
|
const diffButtons = {} as Record<CanonicalDifficulty, HTMLButtonElement>;
|
||||||
|
for (const k of diffKeys) {
|
||||||
|
const prof = DIFFICULTY_PROFILES[k];
|
||||||
|
diffButtons[k] = h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `btn diff-card ${k === difficulty ? "selected" : ""}`,
|
||||||
|
type: "button",
|
||||||
|
style: k === "sandbox" ? { gridColumn: "1 / -1" } : undefined,
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "dc-head" },
|
||||||
|
h("span", {}, prof.label),
|
||||||
|
h("span", { class: "accent" }, prof.audience),
|
||||||
|
),
|
||||||
|
h("div", { class: "dc-sub" }, prof.tagline),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "dc-meta" },
|
||||||
|
k === "sandbox"
|
||||||
|
? "Unlimited ($10B) • All Missions & R&D • Zero Penalties"
|
||||||
|
: `$${Math.round(prof.startingFunds / 1e6)}M Start • ±${prof.orbitTolPct}% Orbit • ${prof.maxBailouts} Bailout${prof.maxBailouts === 1 ? "" : "s"}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const diffGroup = h(
|
||||||
|
"div",
|
||||||
|
{ class: "field" },
|
||||||
|
h("span", {}, "Program Difficulty & Experience Tier"),
|
||||||
|
h("div", { class: "diff-picker" }, ...diffKeys.map((k) => diffButtons[k])),
|
||||||
|
);
|
||||||
|
const submitBtn = h(
|
||||||
|
"button",
|
||||||
|
{ class: "btn primary", type: "submit" },
|
||||||
|
"Establish Agency",
|
||||||
|
);
|
||||||
|
function syncMode() {
|
||||||
|
tabLogin.className = `btn sm ${mode === "login" ? "primary" : "ghost"}`;
|
||||||
|
tabRegister.className = `btn sm ${mode === "register" ? "primary" : "ghost"}`;
|
||||||
|
diffGroup.style.display = mode === "register" ? "flex" : "none";
|
||||||
|
submitBtn.textContent =
|
||||||
|
mode === "register" ? "Establish Agency" : "Authenticate & Enter";
|
||||||
|
errEl.textContent = "";
|
||||||
|
}
|
||||||
|
tabLogin.addEventListener("click", () => {
|
||||||
|
mode = "login";
|
||||||
|
syncMode();
|
||||||
|
});
|
||||||
|
tabRegister.addEventListener("click", () => {
|
||||||
|
mode = "register";
|
||||||
|
syncMode();
|
||||||
|
});
|
||||||
|
diffKeys.forEach((d) => {
|
||||||
|
diffButtons[d].addEventListener("click", () => {
|
||||||
|
difficulty = d;
|
||||||
|
diffKeys.forEach((k) => {
|
||||||
|
diffButtons[k].classList.toggle("selected", k === d);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const form = h(
|
||||||
|
"form",
|
||||||
|
{
|
||||||
|
class: "col",
|
||||||
|
onSubmit: async (ev: Event) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
errEl.textContent = "";
|
||||||
|
const name = nameInput.value.trim();
|
||||||
|
const password = pwdInput.value;
|
||||||
|
if (name.length < 2) {
|
||||||
|
errEl.textContent = "Agency name must be at least 2 characters.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (password.length < 4) {
|
||||||
|
errEl.textContent = "Password must be at least 4 characters.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
submitBtn.disabled = true;
|
||||||
|
try {
|
||||||
|
const endpoint =
|
||||||
|
mode === "register" ? "/api/auth/register" : "/api/auth/login";
|
||||||
|
const payload =
|
||||||
|
mode === "register"
|
||||||
|
? { name, password, difficulty }
|
||||||
|
: { name, password };
|
||||||
|
const res = await api.post<{ token: string; agency: AgencyState }>(
|
||||||
|
endpoint,
|
||||||
|
payload,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
setToken(res.token);
|
||||||
|
state.agency = res.agency;
|
||||||
|
state.account = { name: res.agency.name };
|
||||||
|
await refreshMe();
|
||||||
|
await refreshWorld();
|
||||||
|
startEvents();
|
||||||
|
toast(
|
||||||
|
mode === "register"
|
||||||
|
? `Welcome aboard, ${res.agency.name}.`
|
||||||
|
: `Authenticated as ${res.agency.name}.`,
|
||||||
|
"ok",
|
||||||
|
);
|
||||||
|
if (!res.agency.sponsorId) navigate("onboarding");
|
||||||
|
else navigate("dashboard");
|
||||||
|
} catch (err) {
|
||||||
|
errEl.textContent = (err as Error).message;
|
||||||
|
submitBtn.disabled = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h("label", { class: "field" }, "Agency Name", nameInput),
|
||||||
|
h("label", { class: "field" }, "Passphrase", pwdInput),
|
||||||
|
diffGroup,
|
||||||
|
errEl,
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row spread", style: { marginTop: "6px" } },
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn ghost sm",
|
||||||
|
type: "button",
|
||||||
|
onClick: () => navigate("mainMenu"),
|
||||||
|
},
|
||||||
|
"Back",
|
||||||
|
),
|
||||||
|
submitBtn,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const card = h(
|
||||||
|
"div",
|
||||||
|
{ class: "panel auth-card col" },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row", style: { marginBottom: "4px" } },
|
||||||
|
tabRegister,
|
||||||
|
tabLogin,
|
||||||
|
),
|
||||||
|
h("h2", {}, "Agency Credentials"),
|
||||||
|
h(
|
||||||
|
"p",
|
||||||
|
{ class: "sub" },
|
||||||
|
"Register a new launch provider (agency name is public on the leaderboard) or log into an existing agency.",
|
||||||
|
),
|
||||||
|
form,
|
||||||
|
);
|
||||||
|
syncMode();
|
||||||
|
root.appendChild(h("div", { class: "screen screen-center" }, card));
|
||||||
|
setTimeout(() => nameInput.focus(), 40);
|
||||||
|
}
|
||||||
546
src/client/screens/builder/blueprintsModal.ts
Normal file
546
src/client/screens/builder/blueprintsModal.ts
Normal file
|
|
@ -0,0 +1,546 @@
|
||||||
|
// Hangar blueprints save/load/import and SGYW1 share code modal
|
||||||
|
import { api } from "../../api.js";
|
||||||
|
import { state } from "../../state.js";
|
||||||
|
import {
|
||||||
|
buildRocket,
|
||||||
|
decodeRocketShareCode,
|
||||||
|
encodeRocketShareCode,
|
||||||
|
normalizeDesign,
|
||||||
|
} from "../../../shared/physics.js";
|
||||||
|
import type {
|
||||||
|
LockedDesignItemInfo,
|
||||||
|
RocketDesign,
|
||||||
|
SavedRocketBlueprint,
|
||||||
|
} from "../../../shared/types.js";
|
||||||
|
import { clear, fmtMoney, fmtNum, h, modal, toast } from "../../ui.js";
|
||||||
|
import { curAgency, priceOfPart, type BuilderContext } from "./context.js";
|
||||||
|
import { recordHistory } from "./history.js";
|
||||||
|
|
||||||
|
export async function openBlueprintsModal(ctx: BuilderContext): Promise<void> {
|
||||||
|
const { contract } = ctx;
|
||||||
|
let myDesigns: SavedRocketBlueprint[] = [
|
||||||
|
...(curAgency(ctx).savedDesigns ?? []),
|
||||||
|
];
|
||||||
|
let communityDesigns: SavedRocketBlueprint[] = [];
|
||||||
|
const rootWrap = h("div", {
|
||||||
|
style: {
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
gap: "12px",
|
||||||
|
maxHeight: "72vh",
|
||||||
|
overflowY: "auto",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const m = modal("Vehicle Hangar: Save, Load & Share Blueprints", rootWrap, [
|
||||||
|
{ label: "Close", kind: "ghost" },
|
||||||
|
]);
|
||||||
|
m.el.style.maxWidth = "780px";
|
||||||
|
m.el.style.width = "94vw";
|
||||||
|
const loadDesignIntoBuilder = (
|
||||||
|
raw: RocketDesign,
|
||||||
|
label: string,
|
||||||
|
locked: LockedDesignItemInfo[] = [],
|
||||||
|
) => {
|
||||||
|
ctx.design = normalizeDesign(
|
||||||
|
structuredClone(raw),
|
||||||
|
state.parts,
|
||||||
|
state.materials,
|
||||||
|
);
|
||||||
|
ctx.activeStageIdx = 0;
|
||||||
|
if (ctx.design.designTier === "pro") {
|
||||||
|
ctx.selectedProUid = ctx.design.proParts?.[0]?.uid ?? null;
|
||||||
|
}
|
||||||
|
recordHistory(ctx, `Load blueprint: ${label}`);
|
||||||
|
ctx.refreshEngineering(true, true);
|
||||||
|
ctx.renderAll();
|
||||||
|
m.close();
|
||||||
|
if (locked.length > 0) {
|
||||||
|
toast(
|
||||||
|
`Loaded "${label}" with ${locked.length} locked R&D item(s). Check Diagnostics panel to unlock or swap.`,
|
||||||
|
"warn",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
toast(`Loaded blueprint "${label}".`, "ok");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const copyText = async (txt: string, okMsg: string) => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(txt);
|
||||||
|
toast(okMsg, "ok");
|
||||||
|
} catch {
|
||||||
|
const tmp = h("textarea", {
|
||||||
|
value: txt,
|
||||||
|
style: { position: "fixed", left: "-9999px" },
|
||||||
|
}) as HTMLTextAreaElement;
|
||||||
|
document.body.appendChild(tmp);
|
||||||
|
tmp.select();
|
||||||
|
document.execCommand("copy");
|
||||||
|
tmp.remove();
|
||||||
|
toast(okMsg, "ok");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const renderModalBody = (
|
||||||
|
importPreview?: {
|
||||||
|
design: RocketDesign;
|
||||||
|
shareCode: string;
|
||||||
|
lockedItems: LockedDesignItemInfo[];
|
||||||
|
summary: {
|
||||||
|
totalDv: number;
|
||||||
|
totalCost: number;
|
||||||
|
stageCount: number;
|
||||||
|
designTier: string;
|
||||||
|
};
|
||||||
|
} | null,
|
||||||
|
) => {
|
||||||
|
clear(rootWrap);
|
||||||
|
const saveNameInput = h("input", {
|
||||||
|
class: "input",
|
||||||
|
value: ctx.design.name || "Custom Launcher",
|
||||||
|
placeholder: "Blueprint name",
|
||||||
|
}) as HTMLInputElement;
|
||||||
|
const saveNotesInput = h("input", {
|
||||||
|
class: "input",
|
||||||
|
placeholder: "Mission / notes (optional)",
|
||||||
|
}) as HTMLInputElement;
|
||||||
|
const publishChk = h("input", { type: "checkbox" }) as HTMLInputElement;
|
||||||
|
const shareCodeStr = encodeRocketShareCode(ctx.design);
|
||||||
|
const shareCodeBox = h("input", {
|
||||||
|
class: "input mono",
|
||||||
|
readonly: true,
|
||||||
|
value: shareCodeStr,
|
||||||
|
style: { fontSize: "10px" },
|
||||||
|
}) as HTMLInputElement;
|
||||||
|
rootWrap.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "panel", style: { padding: "10px" } },
|
||||||
|
h(
|
||||||
|
"strong",
|
||||||
|
{ class: "mono", style: { fontSize: "11px" } },
|
||||||
|
"SAVE & EXPORT CURRENT VEHICLE",
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "row",
|
||||||
|
style: { gap: "8px", marginTop: "8px", flexWrap: "wrap" },
|
||||||
|
},
|
||||||
|
h("label", { class: "field grow" }, "Name", saveNameInput),
|
||||||
|
h("label", { class: "field grow" }, "Notes", saveNotesInput),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "row spread",
|
||||||
|
style: { marginTop: "8px", flexWrap: "wrap", gap: "8px" },
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "row", style: { fontSize: "11px", gap: "6px" } },
|
||||||
|
publishChk,
|
||||||
|
h("span", {}, "Publish to Community Hangar"),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row", style: { gap: "6px" } },
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs primary",
|
||||||
|
onClick: async () => {
|
||||||
|
try {
|
||||||
|
const res = await api.saveDesignBlueprint({
|
||||||
|
name:
|
||||||
|
saveNameInput.value.trim() ||
|
||||||
|
ctx.design.name ||
|
||||||
|
"Unnamed Rocket",
|
||||||
|
design: ctx.design,
|
||||||
|
notes: saveNotesInput.value.trim() || undefined,
|
||||||
|
isPublic: publishChk.checked,
|
||||||
|
targetHint: contract?.targetName,
|
||||||
|
});
|
||||||
|
myDesigns = res.myDesigns;
|
||||||
|
communityDesigns = res.communityDesigns;
|
||||||
|
if (state.agency) state.agency.savedDesigns = res.myDesigns;
|
||||||
|
toast(`Saved "${res.blueprint.name}" to Hangar!`, "ok");
|
||||||
|
renderModalBody(importPreview);
|
||||||
|
} catch (err) {
|
||||||
|
toast((err as Error).message, "err");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Save to Hangar",
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs ghost",
|
||||||
|
onClick: () => {
|
||||||
|
const payload = JSON.stringify(
|
||||||
|
{
|
||||||
|
name: saveNameInput.value.trim() || ctx.design.name,
|
||||||
|
design: ctx.design,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
const blob = new Blob([payload], {
|
||||||
|
type: "application/json",
|
||||||
|
});
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = url;
|
||||||
|
a.download = `${(ctx.design.name || "rocket").replace(/[^a-z0-9_-]+/gi, "_").toLowerCase()}.rocket.json`;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
toast("Downloaded .rocket.json file.", "info");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Download .rocket.json",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row", style: { marginTop: "8px", gap: "6px" } },
|
||||||
|
shareCodeBox,
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs selected",
|
||||||
|
onClick: () =>
|
||||||
|
void copyText(
|
||||||
|
shareCodeStr,
|
||||||
|
"Copied SGYW1 share code to clipboard!",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
"Copy Share Code",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const importTextArea = h("textarea", {
|
||||||
|
class: "input mono",
|
||||||
|
rows: 2,
|
||||||
|
placeholder: "Paste SGYW1:... share code or RocketDesign JSON here",
|
||||||
|
style: { fontSize: "10px", width: "100%" },
|
||||||
|
}) as HTMLTextAreaElement;
|
||||||
|
const saveImportedChk = h("input", {
|
||||||
|
type: "checkbox",
|
||||||
|
checked: true,
|
||||||
|
}) as HTMLInputElement;
|
||||||
|
const fileInput = h("input", {
|
||||||
|
type: "file",
|
||||||
|
accept: ".json,.rocket.json,application/json",
|
||||||
|
style: { fontSize: "11px" },
|
||||||
|
}) as HTMLInputElement;
|
||||||
|
fileInput.addEventListener("change", async () => {
|
||||||
|
const f = fileInput.files?.[0];
|
||||||
|
if (!f) return;
|
||||||
|
importTextArea.value = await f.text();
|
||||||
|
toast(`Loaded JSON from ${f.name}. Click Import & Preview.`, "info");
|
||||||
|
});
|
||||||
|
const previewBox = importPreview
|
||||||
|
? h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "panel",
|
||||||
|
style: {
|
||||||
|
padding: "8px 10px",
|
||||||
|
marginTop: "8px",
|
||||||
|
borderColor:
|
||||||
|
importPreview.lockedItems.length > 0
|
||||||
|
? "var(--amber)"
|
||||||
|
: "var(--green)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row spread", style: { gap: "8px", flexWrap: "wrap" } },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{},
|
||||||
|
h(
|
||||||
|
"strong",
|
||||||
|
{ style: { fontSize: "11px" } },
|
||||||
|
`${importPreview.design.name} (${importPreview.summary.designTier.toUpperCase()})`,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "dim mono", style: { fontSize: "10px" } },
|
||||||
|
`Δv ${fmtNum(importPreview.summary.totalDv)} m/s • Cost ${fmtMoney(importPreview.summary.totalCost)} • ${importPreview.summary.stageCount} stage(s)`,
|
||||||
|
),
|
||||||
|
importPreview.lockedItems.length > 0
|
||||||
|
? h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "amber",
|
||||||
|
style: { fontSize: "10px", marginTop: "3px" },
|
||||||
|
},
|
||||||
|
`Warning: ${importPreview.lockedItems.length} locked part(s): ${importPreview.lockedItems.map((l) => `${l.partOrMatName} (${l.techName})`).join(", ")}`,
|
||||||
|
)
|
||||||
|
: h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "green",
|
||||||
|
style: { fontSize: "10px", marginTop: "3px" },
|
||||||
|
},
|
||||||
|
"All R&D technologies unlocked for your agency.",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs primary",
|
||||||
|
onClick: () =>
|
||||||
|
loadDesignIntoBuilder(
|
||||||
|
importPreview.design,
|
||||||
|
importPreview.design.name || "Imported Rocket",
|
||||||
|
importPreview.lockedItems,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
"Load Imported Rocket",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
rootWrap.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "panel", style: { padding: "10px" } },
|
||||||
|
h(
|
||||||
|
"strong",
|
||||||
|
{ class: "mono", style: { fontSize: "11px" } },
|
||||||
|
"IMPORT SHARE CODE OR JSON",
|
||||||
|
),
|
||||||
|
h("div", { style: { marginTop: "6px" } }, importTextArea),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "row spread",
|
||||||
|
style: { marginTop: "6px", flexWrap: "wrap", gap: "8px" },
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row", style: { gap: "8px", flexWrap: "wrap" } },
|
||||||
|
fileInput,
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "row", style: { fontSize: "11px", gap: "4px" } },
|
||||||
|
saveImportedChk,
|
||||||
|
h("span", {}, "Also save copy to My Hangar"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs primary",
|
||||||
|
onClick: async () => {
|
||||||
|
const codeOrJson = importTextArea.value.trim();
|
||||||
|
if (!codeOrJson) {
|
||||||
|
toast(
|
||||||
|
"Paste a share code or choose a JSON file first.",
|
||||||
|
"warn",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const res = await api.importDesignBlueprint({
|
||||||
|
codeOrJson,
|
||||||
|
saveToHangar: saveImportedChk.checked,
|
||||||
|
});
|
||||||
|
if (res.myDesigns) {
|
||||||
|
myDesigns = res.myDesigns;
|
||||||
|
if (state.agency) state.agency.savedDesigns = res.myDesigns;
|
||||||
|
}
|
||||||
|
renderModalBody({
|
||||||
|
design: res.design,
|
||||||
|
shareCode: res.shareCode,
|
||||||
|
lockedItems: res.lockedItems,
|
||||||
|
summary: res.summary,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
try {
|
||||||
|
const localDecoded = decodeRocketShareCode(
|
||||||
|
codeOrJson,
|
||||||
|
state.parts,
|
||||||
|
state.materials,
|
||||||
|
);
|
||||||
|
const asm = buildRocket(
|
||||||
|
localDecoded,
|
||||||
|
state.parts,
|
||||||
|
state.materials,
|
||||||
|
{
|
||||||
|
priceOf: (p, m) => priceOfPart(ctx, p, m),
|
||||||
|
difficulty: curAgency(ctx).difficulty,
|
||||||
|
unlockedTechs: curAgency(ctx).unlockedTechs ?? [],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
renderModalBody({
|
||||||
|
design: localDecoded,
|
||||||
|
shareCode: encodeRocketShareCode(localDecoded),
|
||||||
|
lockedItems: [],
|
||||||
|
summary: {
|
||||||
|
totalDv: Math.round(asm.totalDv),
|
||||||
|
totalCost: Math.round(asm.totalCost),
|
||||||
|
stageCount: localDecoded.stages.length,
|
||||||
|
designTier: localDecoded.designTier ?? "basic",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
toast((err as Error).message, "err");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Import & Preview",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
previewBox,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const renderBpSection = (
|
||||||
|
title: string,
|
||||||
|
items: SavedRocketBlueprint[],
|
||||||
|
canDelete: boolean,
|
||||||
|
) => {
|
||||||
|
return h(
|
||||||
|
"div",
|
||||||
|
{ class: "panel", style: { padding: "10px" } },
|
||||||
|
h(
|
||||||
|
"strong",
|
||||||
|
{ class: "mono", style: { fontSize: "11px" } },
|
||||||
|
`${title} (${items.length})`,
|
||||||
|
),
|
||||||
|
items.length === 0
|
||||||
|
? h(
|
||||||
|
"div",
|
||||||
|
{ class: "dim", style: { fontSize: "11px", marginTop: "6px" } },
|
||||||
|
"No blueprints stored here yet.",
|
||||||
|
)
|
||||||
|
: h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
style: {
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
gap: "6px",
|
||||||
|
marginTop: "8px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...items.map((bp) =>
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "panel row spread",
|
||||||
|
style: {
|
||||||
|
padding: "8px 10px",
|
||||||
|
gap: "8px",
|
||||||
|
flexWrap: "wrap",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ style: { minWidth: "220px" } },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ style: { fontSize: "12px", fontWeight: "600" } },
|
||||||
|
`${bp.name} `,
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "badge info", style: { fontSize: "9px" } },
|
||||||
|
(bp.designTier ?? "basic").toUpperCase(),
|
||||||
|
),
|
||||||
|
bp.isPublic
|
||||||
|
? h(
|
||||||
|
"span",
|
||||||
|
{
|
||||||
|
class: "badge ok",
|
||||||
|
style: { fontSize: "9px", marginLeft: "4px" },
|
||||||
|
},
|
||||||
|
"PUBLIC",
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "dim mono", style: { fontSize: "10px" } },
|
||||||
|
`By ${bp.authorAgency} • ${bp.stageCount ?? bp.design.stages.length} stg • Δv ${fmtNum(bp.totalDv ?? 0)} m/s • ${fmtMoney(bp.totalCost ?? 0)}`,
|
||||||
|
),
|
||||||
|
bp.notes
|
||||||
|
? h(
|
||||||
|
"div",
|
||||||
|
{ class: "dim", style: { fontSize: "10px" } },
|
||||||
|
bp.notes,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row", style: { gap: "6px" } },
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs primary",
|
||||||
|
onClick: () =>
|
||||||
|
loadDesignIntoBuilder(bp.design, bp.name),
|
||||||
|
},
|
||||||
|
"Load",
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs ghost",
|
||||||
|
onClick: () =>
|
||||||
|
void copyText(
|
||||||
|
encodeRocketShareCode(bp.design),
|
||||||
|
`Copied code for "${bp.name}"!`,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
"Copy Code",
|
||||||
|
),
|
||||||
|
canDelete
|
||||||
|
? h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs danger",
|
||||||
|
onClick: async () => {
|
||||||
|
try {
|
||||||
|
const res = await api.deleteDesignBlueprint(
|
||||||
|
bp.id,
|
||||||
|
);
|
||||||
|
myDesigns = res.myDesigns;
|
||||||
|
communityDesigns = res.communityDesigns;
|
||||||
|
if (state.agency)
|
||||||
|
state.agency.savedDesigns = res.myDesigns;
|
||||||
|
toast(`Deleted "${bp.name}".`, "info");
|
||||||
|
renderModalBody(importPreview);
|
||||||
|
} catch (err) {
|
||||||
|
toast((err as Error).message, "err");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Delete",
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
rootWrap.appendChild(renderBpSection("MY AGENCY HANGAR", myDesigns, true));
|
||||||
|
rootWrap.appendChild(
|
||||||
|
renderBpSection("SERVER COMMUNITY BLUEPRINTS", communityDesigns, false),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
renderModalBody(null);
|
||||||
|
try {
|
||||||
|
const res = await api.getDesigns();
|
||||||
|
myDesigns = res.myDesigns;
|
||||||
|
communityDesigns = res.communityDesigns;
|
||||||
|
renderModalBody(null);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
131
src/client/screens/builder/context.ts
Normal file
131
src/client/screens/builder/context.ts
Normal file
|
|
@ -0,0 +1,131 @@
|
||||||
|
// Shared mutable state, context interface, and part pricing/lock helpers for Rocket Builder
|
||||||
|
// Read the room. Get it? Context? Cus read the room is basically like get the context? No? Ok... I'll see myself out.
|
||||||
|
import * as THREE from "three";
|
||||||
|
import { state } from "../../state.js";
|
||||||
|
import type { RocketMeshHandle } from "../../three/rocketMesh.js";
|
||||||
|
import type { ManagedView } from "../../three/sceneManager.js";
|
||||||
|
import {
|
||||||
|
buildRocket,
|
||||||
|
getRequiredTechNode,
|
||||||
|
isPartUnlocked,
|
||||||
|
validateDesign,
|
||||||
|
} from "../../../shared/physics.js";
|
||||||
|
import type {
|
||||||
|
AgencyState,
|
||||||
|
CoachDiagnostic,
|
||||||
|
ContractOffer,
|
||||||
|
ContractValueEstimate,
|
||||||
|
DesignReliabilityReport,
|
||||||
|
MaterialSpec,
|
||||||
|
MaturityLevel,
|
||||||
|
MissionTemplate,
|
||||||
|
Part,
|
||||||
|
RocketDesign,
|
||||||
|
Sponsor,
|
||||||
|
} from "../../../shared/types.js";
|
||||||
|
|
||||||
|
export const MATURITY_ORDER: MaturityLevel[] = [
|
||||||
|
"concept",
|
||||||
|
"pdr",
|
||||||
|
"cdr",
|
||||||
|
"flight-ready",
|
||||||
|
];
|
||||||
|
export const MAX_HISTORY_ENTRIES = 50;
|
||||||
|
|
||||||
|
export interface HistoryEntry {
|
||||||
|
snapshot: RocketDesign;
|
||||||
|
label: string;
|
||||||
|
at: number;
|
||||||
|
coalesceKey?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BuilderTab = "stages" | "payload" | "compliance" | "value";
|
||||||
|
|
||||||
|
export interface BuilderDragState {
|
||||||
|
uid: string;
|
||||||
|
startHitY: number;
|
||||||
|
startYBottom: number;
|
||||||
|
startHitX: number;
|
||||||
|
startHitZ: number;
|
||||||
|
startRadial: number;
|
||||||
|
startGroupPosY: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BuilderContext {
|
||||||
|
agency: AgencyState;
|
||||||
|
contract: ContractOffer | MissionTemplate | null;
|
||||||
|
sponsor: Sponsor | undefined;
|
||||||
|
design: RocketDesign;
|
||||||
|
history: HistoryEntry[];
|
||||||
|
historyIndex: number;
|
||||||
|
lastRecordedJson: string;
|
||||||
|
suppressHistory: boolean;
|
||||||
|
activeTab: BuilderTab;
|
||||||
|
activeStageIdx: number;
|
||||||
|
fairingCutaway: boolean;
|
||||||
|
showCenters: boolean;
|
||||||
|
selectedProUid: string | null;
|
||||||
|
priceMultipliers: Record<string, number>;
|
||||||
|
viewportEl: HTMLElement;
|
||||||
|
sidebarEl: HTMLElement;
|
||||||
|
bodyEl: HTMLElement;
|
||||||
|
tierBar: HTMLElement;
|
||||||
|
summaryBar: HTMLElement;
|
||||||
|
coopBar: HTMLElement;
|
||||||
|
tabsBar: HTMLElement;
|
||||||
|
footerBar: HTMLElement;
|
||||||
|
hudStatsRow: HTMLElement;
|
||||||
|
undoBtn: HTMLButtonElement;
|
||||||
|
redoBtn: HTMLButtonElement;
|
||||||
|
historyBtn: HTMLButtonElement;
|
||||||
|
proDragHint: HTMLElement;
|
||||||
|
cgCpBtn: HTMLButtonElement;
|
||||||
|
view: ManagedView;
|
||||||
|
dragPlane: THREE.Mesh;
|
||||||
|
currentMesh: RocketMeshHandle | null;
|
||||||
|
buildToken: number;
|
||||||
|
rebuildTimer: ReturnType<typeof setTimeout> | null;
|
||||||
|
isDragging3D: boolean;
|
||||||
|
dragState: BuilderDragState | null;
|
||||||
|
latestValidation: ReturnType<typeof validateDesign> | null;
|
||||||
|
latestAssembly: ReturnType<typeof buildRocket> | null;
|
||||||
|
latestReliability: DesignReliabilityReport | null;
|
||||||
|
latestValueEstimate: ContractValueEstimate | null;
|
||||||
|
latestCoach: CoachDiagnostic[];
|
||||||
|
refreshEngineering: (refitCamera?: boolean, immediate?: boolean) => void;
|
||||||
|
renderSidebarBody: () => void;
|
||||||
|
renderAll: () => void;
|
||||||
|
renderTierAndTabs: () => void;
|
||||||
|
renderSummaryAndCoopBars: () => void;
|
||||||
|
scheduleRebuild3D: (
|
||||||
|
asm: ReturnType<typeof buildRocket>,
|
||||||
|
refitCamera?: boolean,
|
||||||
|
immediate?: boolean,
|
||||||
|
) => void;
|
||||||
|
renderHudOverlay: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function curAgency(ctx: BuilderContext): AgencyState {
|
||||||
|
return state.agency ?? ctx.agency;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function partLockTag(ctx: BuilderContext, id: string): string {
|
||||||
|
const ag = curAgency(ctx);
|
||||||
|
if (isPartUnlocked(id, ag)) return "";
|
||||||
|
const node = getRequiredTechNode(id);
|
||||||
|
return node
|
||||||
|
? ` [LOCKED: ${node.name} ($${(node.cost / 1e6).toFixed(1)}M)]`
|
||||||
|
: " [LOCKED]";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function priceOfPart(
|
||||||
|
ctx: BuilderContext,
|
||||||
|
part: Part,
|
||||||
|
material?: MaterialSpec,
|
||||||
|
): number {
|
||||||
|
const pm = ctx.priceMultipliers[part.id] ?? 1;
|
||||||
|
const mm = material
|
||||||
|
? (ctx.priceMultipliers[`mat:${material.id}`] ?? 1) * material.costFactor
|
||||||
|
: 1;
|
||||||
|
return Math.round(part.cost * pm * mm);
|
||||||
|
}
|
||||||
526
src/client/screens/builder/diagnosticsBar.ts
Normal file
526
src/client/screens/builder/diagnosticsBar.ts
Normal file
|
|
@ -0,0 +1,526 @@
|
||||||
|
// Hardware diagnostics panel, one-click quick fixes, and advice
|
||||||
|
import { api } from "../../api.js";
|
||||||
|
import { state } from "../../state.js";
|
||||||
|
import {
|
||||||
|
createStarterStage,
|
||||||
|
getDifficultyProfile,
|
||||||
|
isPartUnlocked,
|
||||||
|
} from "../../../shared/physics.js";
|
||||||
|
import type {
|
||||||
|
AgencyState,
|
||||||
|
LockedDesignItemInfo,
|
||||||
|
RocketDesign,
|
||||||
|
StageDiagnosticItem,
|
||||||
|
} from "../../../shared/types.js";
|
||||||
|
import { fmtMoney, h, term, toast } from "../../ui.js";
|
||||||
|
import { curAgency, type BuilderContext } from "./context.js";
|
||||||
|
import { recordHistory } from "./history.js";
|
||||||
|
|
||||||
|
export function renderDiagnosticsSection(ctx: BuilderContext): void {
|
||||||
|
const { bodyEl } = ctx;
|
||||||
|
if (!ctx.latestValidation) return;
|
||||||
|
const runDiagnosticFix = async (diag: StageDiagnosticItem) => {
|
||||||
|
const ag = curAgency(ctx);
|
||||||
|
if (diag.actionKind === "unlock-tech" && diag.techId) {
|
||||||
|
try {
|
||||||
|
const res = await api.post<{ agency: AgencyState }>(
|
||||||
|
"/api/agency/unlock-tech",
|
||||||
|
{
|
||||||
|
techId: diag.techId,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
state.agency = res.agency;
|
||||||
|
toast(`Researched tech for ${diag.title}!`, "ok");
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderAll();
|
||||||
|
} catch (err) {
|
||||||
|
toast((err as Error).message, "err");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
diag.actionKind === "swap-part" &&
|
||||||
|
diag.targetPartOrMatId &&
|
||||||
|
diag.fallbackId
|
||||||
|
) {
|
||||||
|
let changed = false;
|
||||||
|
const swapInStage = (st: RocketDesign["stages"][number]) => {
|
||||||
|
if (st.engineId === diag.targetPartOrMatId) {
|
||||||
|
st.engineId = diag.fallbackId!;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (st.tankId === diag.targetPartOrMatId) {
|
||||||
|
st.tankId = diag.fallbackId!;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (st.dropTankId === diag.targetPartOrMatId) {
|
||||||
|
st.dropTankId = diag.fallbackId!;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (st.structureId === diag.targetPartOrMatId) {
|
||||||
|
st.structureId = diag.fallbackId!;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (st.materialId === diag.targetPartOrMatId) {
|
||||||
|
st.materialId = diag.fallbackId!;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (st.interstageId === diag.targetPartOrMatId) {
|
||||||
|
st.interstageId = diag.fallbackId!;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (diag.stageIndex != null && ctx.design.stages[diag.stageIndex]) {
|
||||||
|
swapInStage(ctx.design.stages[diag.stageIndex]);
|
||||||
|
} else {
|
||||||
|
ctx.design.stages.forEach(swapInStage);
|
||||||
|
}
|
||||||
|
if (ctx.design.fairingId === diag.targetPartOrMatId) {
|
||||||
|
ctx.design.fairingId = diag.fallbackId;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (ctx.design.computerId === diag.targetPartOrMatId) {
|
||||||
|
ctx.design.computerId = diag.fallbackId;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (ctx.design.payloadPartId === diag.targetPartOrMatId) {
|
||||||
|
ctx.design.payloadPartId = diag.fallbackId;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
for (const pp of ctx.design.proParts ?? []) {
|
||||||
|
if (pp.partId === diag.targetPartOrMatId) {
|
||||||
|
pp.partId = diag.fallbackId;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (pp.materialId === diag.targetPartOrMatId) {
|
||||||
|
pp.materialId = diag.fallbackId;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
recordHistory(ctx, `Swap locked component -> ${diag.fallbackId}`);
|
||||||
|
ctx.refreshEngineering(true, true);
|
||||||
|
ctx.renderAll();
|
||||||
|
toast("Swapped to unlocked fallback component.", "ok");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (diag.actionKind === "auto-pair-tank") {
|
||||||
|
const sIdx = diag.stageIndex ?? ctx.activeStageIdx;
|
||||||
|
const st = ctx.design.stages[sIdx];
|
||||||
|
if (!st) return;
|
||||||
|
const eng = state.parts.find((p) => p.id === st.engineId);
|
||||||
|
const tanks = state.parts.filter(
|
||||||
|
(p) => p.kind === "tank" && !p.isDropTank,
|
||||||
|
);
|
||||||
|
const compat =
|
||||||
|
tanks.find(
|
||||||
|
(t) =>
|
||||||
|
t.propellantType === eng?.propellantType &&
|
||||||
|
isPartUnlocked(t.id, ag),
|
||||||
|
) ?? tanks.find((t) => t.propellantType === eng?.propellantType);
|
||||||
|
if (compat) {
|
||||||
|
st.tankId = compat.id;
|
||||||
|
ctx.activeStageIdx = sIdx;
|
||||||
|
ctx.activeTab = "stages";
|
||||||
|
recordHistory(ctx, `Auto-pair tank on Stage ${sIdx + 1}`);
|
||||||
|
ctx.refreshEngineering(true, true);
|
||||||
|
ctx.renderAll();
|
||||||
|
toast(`Paired ${compat.name} to Stage ${sIdx + 1}.`, "ok");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (diag.actionKind === "enable-fins") {
|
||||||
|
const sIdx = diag.stageIndex ?? 0;
|
||||||
|
if (ctx.design.stages[sIdx]) {
|
||||||
|
ctx.design.stages[sIdx].hasFins = true;
|
||||||
|
ctx.activeStageIdx = sIdx;
|
||||||
|
ctx.activeTab = "stages";
|
||||||
|
recordHistory(ctx, `Enable Stage ${sIdx + 1} fins`);
|
||||||
|
ctx.refreshEngineering(true, true);
|
||||||
|
ctx.renderAll();
|
||||||
|
toast(`Enabled aerodynamic fins on Stage ${sIdx + 1}.`, "ok");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (diag.actionKind === "add-stage") {
|
||||||
|
if (ctx.design.stages.length < 4) {
|
||||||
|
ctx.design.stages.push(createStarterStage("upper"));
|
||||||
|
ctx.activeStageIdx = ctx.design.stages.length - 1;
|
||||||
|
ctx.activeTab = "stages";
|
||||||
|
recordHistory(ctx, "Add upper stage (quick-fix)");
|
||||||
|
ctx.refreshEngineering(true, true);
|
||||||
|
ctx.renderAll();
|
||||||
|
toast(`Added Stage ${ctx.design.stages.length} for extra Δv.`, "ok");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (diag.actionKind === "select-computer") {
|
||||||
|
const computers = state.parts
|
||||||
|
.filter((p) => p.kind === "computer" && isPartUnlocked(p.id, ag))
|
||||||
|
.sort(
|
||||||
|
(a, b) =>
|
||||||
|
(b.computeCapacityIps ?? 100) - (a.computeCapacityIps ?? 100),
|
||||||
|
);
|
||||||
|
const best = computers[0];
|
||||||
|
if (best && best.id !== ctx.design.computerId) {
|
||||||
|
ctx.design.computerId = best.id;
|
||||||
|
if (ctx.design.designTier === "pro" && ctx.design.proParts) {
|
||||||
|
const ex = ctx.design.proParts.find((p) => p.role === "computer");
|
||||||
|
if (ex) {
|
||||||
|
ex.partId = best.id;
|
||||||
|
ex.diameter = best.diameter;
|
||||||
|
ex.length = best.length;
|
||||||
|
} else {
|
||||||
|
ctx.design.proParts.push({
|
||||||
|
uid: `pro-comp-${Date.now()}`,
|
||||||
|
role: "computer",
|
||||||
|
partId: best.id,
|
||||||
|
stageIndex: Math.max(0, ctx.design.stages.length - 1),
|
||||||
|
yBottom: Math.max(
|
||||||
|
0.5,
|
||||||
|
(ctx.latestAssembly?.fairingY ?? 20) - 0.6,
|
||||||
|
),
|
||||||
|
radialOffset: 0,
|
||||||
|
radialAngleDeg: 0,
|
||||||
|
symmetry: 1,
|
||||||
|
diameter: best.diameter,
|
||||||
|
length: best.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
recordHistory(ctx, `Select flight computer ${best.name}`);
|
||||||
|
ctx.refreshEngineering(true, true);
|
||||||
|
ctx.renderAll();
|
||||||
|
toast(`Installed ${best.name}.`, "ok");
|
||||||
|
} else {
|
||||||
|
ctx.activeTab = "payload";
|
||||||
|
ctx.renderAll();
|
||||||
|
toast("Opened Fairing, Payload & Avionics tab.", "info");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (diag.actionKind === "waive-rule" && diag.ruleId) {
|
||||||
|
const waived = new Set(ctx.design.waivedRuleIds ?? []);
|
||||||
|
if (!waived.has(diag.ruleId)) {
|
||||||
|
waived.add(diag.ruleId);
|
||||||
|
ctx.design.waivedRuleIds = Array.from(waived);
|
||||||
|
recordHistory(ctx, `Grant compliance waiver ${diag.code}`);
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderAll();
|
||||||
|
toast(`Waived ${diag.code} (${diag.title}).`, "warn");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (diag.actionKind === "jump-stage") {
|
||||||
|
if (diag.stageIndex != null && ctx.design.stages[diag.stageIndex]) {
|
||||||
|
ctx.activeStageIdx = diag.stageIndex;
|
||||||
|
ctx.activeTab = "stages";
|
||||||
|
} else if (
|
||||||
|
diag.locationLabel.includes("Fairing") ||
|
||||||
|
diag.locationLabel.includes("Avionics")
|
||||||
|
) {
|
||||||
|
ctx.activeTab = "payload";
|
||||||
|
} else {
|
||||||
|
ctx.activeTab = "compliance";
|
||||||
|
}
|
||||||
|
ctx.renderAll();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const lockedItemsList = ctx.latestValidation.lockedItems ?? [];
|
||||||
|
const diagItems = ctx.latestValidation.stageDiagnostics ?? [];
|
||||||
|
if (diagItems.length > 0 || lockedItemsList.length > 0) {
|
||||||
|
const ag = curAgency(ctx);
|
||||||
|
const lockByPartStage = new Map<string, LockedDesignItemInfo>();
|
||||||
|
for (const li of lockedItemsList) {
|
||||||
|
lockByPartStage.set(`${li.partOrMatId}:${li.stageIndex ?? -1}`, li);
|
||||||
|
}
|
||||||
|
const errCount = diagItems.filter((d) => d.severity === "error").length;
|
||||||
|
const warnCount = diagItems.filter((d) => d.severity === "warn").length;
|
||||||
|
bodyEl.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "panel",
|
||||||
|
style: {
|
||||||
|
padding: "10px",
|
||||||
|
marginBottom: "8px",
|
||||||
|
borderColor: errCount > 0 ? "var(--red)" : "var(--amber)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row spread" },
|
||||||
|
h(
|
||||||
|
"strong",
|
||||||
|
{
|
||||||
|
class: `${errCount > 0 ? "red" : "amber"} mono`,
|
||||||
|
style: { fontSize: "11px" },
|
||||||
|
},
|
||||||
|
`STAGE & HARDWARE DIAGNOSTICS (${errCount} ERR • ${warnCount} WARN)`,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "dim mono", style: { fontSize: "10px" } },
|
||||||
|
`${lockedItemsList.length} locked R&D`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
...diagItems.slice(0, 12).map((diag) => {
|
||||||
|
const lockMeta = diag.targetPartOrMatId
|
||||||
|
? lockByPartStage.get(
|
||||||
|
`${diag.targetPartOrMatId}:${diag.stageIndex ?? -1}`,
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
|
const repMet = lockMeta
|
||||||
|
? (ag.reputation ?? 0) >= lockMeta.techMinReputation
|
||||||
|
: true;
|
||||||
|
const canAfford = lockMeta ? ag.treasury >= lockMeta.techCost : true;
|
||||||
|
return h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "panel",
|
||||||
|
style: {
|
||||||
|
padding: "6px 8px",
|
||||||
|
marginTop: "6px",
|
||||||
|
borderColor:
|
||||||
|
diag.severity === "error"
|
||||||
|
? "rgba(239,68,68,0.45)"
|
||||||
|
: "rgba(245,158,11,0.45)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row spread", style: { gap: "6px", flexWrap: "wrap" } },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row", style: { gap: "6px", flexWrap: "wrap" } },
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{
|
||||||
|
class: `badge ${diag.severity === "error" ? "err" : "warn"}`,
|
||||||
|
style: { fontSize: "9px" },
|
||||||
|
},
|
||||||
|
diag.locationLabel,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||||
|
diag.code,
|
||||||
|
),
|
||||||
|
h("strong", { style: { fontSize: "11px" } }, diag.title),
|
||||||
|
),
|
||||||
|
diag.stageIndex != null &&
|
||||||
|
ctx.design.stages[diag.stageIndex] &&
|
||||||
|
ctx.design.designTier !== "pro" &&
|
||||||
|
diag.actionKind !== "jump-stage"
|
||||||
|
? h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs ghost",
|
||||||
|
onClick: () => {
|
||||||
|
ctx.activeStageIdx = diag.stageIndex!;
|
||||||
|
ctx.activeTab = "stages";
|
||||||
|
ctx.renderAll();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
`Go Stage ${diag.stageIndex + 1}`,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "dim", style: { fontSize: "11px", marginTop: "3px" } },
|
||||||
|
diag.detail,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "row",
|
||||||
|
style: { gap: "6px", marginTop: "5px", flexWrap: "wrap" },
|
||||||
|
},
|
||||||
|
diag.actionKind
|
||||||
|
? h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `btn xs ${diag.actionKind === "waive-rule" ? "ghost" : "primary"}`,
|
||||||
|
disabled:
|
||||||
|
diag.actionKind === "unlock-tech" &&
|
||||||
|
(!repMet || !canAfford),
|
||||||
|
title:
|
||||||
|
diag.actionKind === "unlock-tech" && !repMet
|
||||||
|
? `Requires ${lockMeta?.techMinReputation} Reputation`
|
||||||
|
: diag.actionKind === "unlock-tech" && !canAfford
|
||||||
|
? "Insufficient treasury"
|
||||||
|
: undefined,
|
||||||
|
onClick: () => void runDiagnosticFix(diag),
|
||||||
|
},
|
||||||
|
diag.actionLabel ?? "Fix",
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
lockMeta?.fallbackUnlockedId
|
||||||
|
? h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs selected",
|
||||||
|
onClick: () =>
|
||||||
|
void runDiagnosticFix({
|
||||||
|
...diag,
|
||||||
|
actionKind: "swap-part",
|
||||||
|
fallbackId: lockMeta.fallbackUnlockedId,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
`Swap → ${lockMeta.fallbackUnlockedName ?? lockMeta.fallbackUnlockedId}`,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
diagItems.length > 12
|
||||||
|
? h(
|
||||||
|
"div",
|
||||||
|
{ class: "dim", style: { fontSize: "10px", marginTop: "6px" } },
|
||||||
|
`+ ${diagItems.length - 12} more items in NASA CML / TRL tab.`,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (ctx.latestReliability) {
|
||||||
|
const sfFee = Math.max(
|
||||||
|
450_000,
|
||||||
|
Math.round((ctx.latestAssembly?.totalCost ?? 0) * 0.04),
|
||||||
|
);
|
||||||
|
bodyEl.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "panel", style: { padding: "8px 10px", marginBottom: "8px" } },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row spread" },
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "mono", style: { fontSize: "10px" } },
|
||||||
|
term("REL:", "reliability_risk"),
|
||||||
|
` ${ctx.latestReliability.reliabilityPct.toFixed(1)}% • Defect Risk ${ctx.latestReliability.anomalyRiskPct.toFixed(1)}%${ctx.latestReliability.staticFired ? " (STATIC FIRED)" : ""}`,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `btn xs ${ctx.latestReliability.staticFired ? "ghost" : "primary"}`,
|
||||||
|
disabled: ctx.latestReliability.staticFired,
|
||||||
|
onClick: async () => {
|
||||||
|
try {
|
||||||
|
const res = await api.post<{
|
||||||
|
fee: number;
|
||||||
|
agency: AgencyState;
|
||||||
|
}>("/api/agency/static-fire", {
|
||||||
|
design: ctx.design,
|
||||||
|
});
|
||||||
|
state.agency = res.agency;
|
||||||
|
toast(
|
||||||
|
`Static fire verified (-${fmtMoney(res.fee)}). Defect risk reduced by 8%.`,
|
||||||
|
"ok",
|
||||||
|
);
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
} catch (err) {
|
||||||
|
toast((err as Error).message, "err");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ctx.latestReliability.staticFired
|
||||||
|
? "Static Fired OK"
|
||||||
|
: `Static Fire (${fmtMoney(sfFee)})`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (ctx.latestCoach.length > 0) {
|
||||||
|
const prof = getDifficultyProfile(curAgency(ctx).difficulty);
|
||||||
|
const headerTitle =
|
||||||
|
prof.coachMode === "explorer"
|
||||||
|
? "EXPLORER MISSION COACH"
|
||||||
|
: prof.coachMode === "encyclopedia"
|
||||||
|
? "AEROSPACE ENCYCLOPEDIA"
|
||||||
|
: "FLIGHT DIRECTOR TELEMETRY";
|
||||||
|
bodyEl.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "panel",
|
||||||
|
style: {
|
||||||
|
padding: "8px 10px",
|
||||||
|
marginBottom: "8px",
|
||||||
|
borderColor: "var(--sim-accent-dim)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "mono accent",
|
||||||
|
style: { fontSize: "10px", fontWeight: "700", marginBottom: "4px" },
|
||||||
|
},
|
||||||
|
headerTitle,
|
||||||
|
),
|
||||||
|
...ctx.latestCoach
|
||||||
|
.slice(0, 2)
|
||||||
|
.map((c) =>
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
style: {
|
||||||
|
fontSize: "11px",
|
||||||
|
marginTop: "4px",
|
||||||
|
paddingTop: "4px",
|
||||||
|
borderTop: "1px solid var(--border)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row", style: { gap: "6px" } },
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{
|
||||||
|
class: `badge ${c.severity === "critical" ? "err" : c.severity === "warn" ? "warn" : "info"}`,
|
||||||
|
},
|
||||||
|
c.conceptTag ?? c.code,
|
||||||
|
),
|
||||||
|
h("strong", {}, c.title),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "dim",
|
||||||
|
style: { lineHeight: "1.35", marginTop: "2px" },
|
||||||
|
},
|
||||||
|
c.explanation,
|
||||||
|
),
|
||||||
|
c.formula
|
||||||
|
? h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "mono accent",
|
||||||
|
style: { fontSize: "10px", marginTop: "2px" },
|
||||||
|
},
|
||||||
|
c.formula,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "mono",
|
||||||
|
style: {
|
||||||
|
fontSize: "10px",
|
||||||
|
color: "var(--green)",
|
||||||
|
marginTop: "2px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
`Tip: ${c.actionHint}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
337
src/client/screens/builder/engineeringBar.ts
Normal file
337
src/client/screens/builder/engineeringBar.ts
Normal file
|
|
@ -0,0 +1,337 @@
|
||||||
|
// Rocket Builder tier selector, tabs, evaluation pipeline, summary vicodins, and co-op thingies
|
||||||
|
import { api } from "../../api.js";
|
||||||
|
import { state } from "../../state.js";
|
||||||
|
import {
|
||||||
|
buildRocket,
|
||||||
|
computeDesignReliability,
|
||||||
|
convertStagesToProParts,
|
||||||
|
createDefaultTeamStations,
|
||||||
|
estimateContractValue,
|
||||||
|
generateCoachDiagnostics,
|
||||||
|
TEAM_STATION_DEFS,
|
||||||
|
validateDesign,
|
||||||
|
} from "../../../shared/physics.js";
|
||||||
|
import type {
|
||||||
|
AgencyState,
|
||||||
|
DesignTier,
|
||||||
|
MaterialSpec,
|
||||||
|
Part,
|
||||||
|
TeamStationId,
|
||||||
|
} from "../../../shared/types.js";
|
||||||
|
import { clear, fmtMoney, h, term, toast } from "../../ui.js";
|
||||||
|
import { curAgency, priceOfPart, type BuilderContext } from "./context.js";
|
||||||
|
|
||||||
|
export function renderTierAndTabs(ctx: BuilderContext): void {
|
||||||
|
clear(ctx.tierBar);
|
||||||
|
ctx.tierBar.appendChild(
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "mono dim", style: { fontSize: "10px", marginRight: "auto" } },
|
||||||
|
term("FIDELITY TIER", "design_tier"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
(["casual", "standard", "expert", "pro"] as DesignTier[]).forEach((t) => {
|
||||||
|
ctx.tierBar.appendChild(
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `btn xs ${ctx.design.designTier === t ? "selected" : "ghost"}`,
|
||||||
|
onClick: () => {
|
||||||
|
ctx.design.designTier = t;
|
||||||
|
if (t === "pro") {
|
||||||
|
if (!ctx.design.proParts || ctx.design.proParts.length === 0) {
|
||||||
|
ctx.design.proParts = convertStagesToProParts(
|
||||||
|
ctx.design,
|
||||||
|
state.parts,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!ctx.selectedProUid && ctx.design.proParts.length > 0) {
|
||||||
|
ctx.selectedProUid = ctx.design.proParts[0].uid;
|
||||||
|
}
|
||||||
|
if (ctx.activeTab === "stages") ctx.showCenters = true;
|
||||||
|
}
|
||||||
|
ctx.proDragHint.style.display =
|
||||||
|
t === "pro" ? "inline-flex" : "none";
|
||||||
|
ctx.cgCpBtn.textContent = ctx.showCenters
|
||||||
|
? "CG / CP: ON"
|
||||||
|
: "CG / CP: OFF";
|
||||||
|
ctx.cgCpBtn.classList.toggle("selected", ctx.showCenters);
|
||||||
|
ctx.cgCpBtn.classList.toggle("ghost", !ctx.showCenters);
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderAll();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
t === "pro" ? "PRO" : t.toUpperCase(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
clear(ctx.tabsBar);
|
||||||
|
const tabs: Array<{ id: typeof ctx.activeTab; label: string }> = [
|
||||||
|
{
|
||||||
|
id: "stages",
|
||||||
|
label:
|
||||||
|
ctx.design.designTier === "pro"
|
||||||
|
? `Pro Assembly (${ctx.design.proParts?.length ?? 0})`
|
||||||
|
: `Stages (${ctx.design.stages.length})`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "payload",
|
||||||
|
label:
|
||||||
|
ctx.design.designTier === "pro"
|
||||||
|
? "Aero & Payload"
|
||||||
|
: "Fairing & Payload",
|
||||||
|
},
|
||||||
|
{ id: "compliance", label: "NASA CML / TRL" },
|
||||||
|
{ id: "value", label: "Contract & Value" },
|
||||||
|
];
|
||||||
|
for (const tb of tabs) {
|
||||||
|
ctx.tabsBar.appendChild(
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: ctx.activeTab === tb.id ? "active" : "",
|
||||||
|
onClick: () => {
|
||||||
|
ctx.activeTab = tb.id;
|
||||||
|
ctx.renderAll();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tb.label,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function evaluateNow(ctx: BuilderContext): void {
|
||||||
|
const priceOf = (part: Part, material?: MaterialSpec) =>
|
||||||
|
priceOfPart(ctx, part, material);
|
||||||
|
if (ctx.design.designTier === "pro" && ctx.design.proParts) {
|
||||||
|
const fPart = ctx.design.proParts.find((p) => p.role === "fairing");
|
||||||
|
const pPart = ctx.design.proParts.find((p) => p.role === "payload");
|
||||||
|
const lPart = ctx.design.proParts.find((p) => p.role === "las");
|
||||||
|
const cPart = ctx.design.proParts.find((p) => p.role === "computer");
|
||||||
|
ctx.design.fairingId = fPart ? fPart.partId : "";
|
||||||
|
ctx.design.payloadPartId = pPart ? pPart.partId : null;
|
||||||
|
ctx.design.hasLaunchAbort = !!lPart;
|
||||||
|
if (cPart) ctx.design.computerId = cPart.partId;
|
||||||
|
}
|
||||||
|
const effectiveMission = ctx.contract
|
||||||
|
? {
|
||||||
|
...ctx.contract,
|
||||||
|
payloadMass:
|
||||||
|
ctx.contract.payloadMass +
|
||||||
|
(ctx.contract.crewed && ctx.agency?.crewConfig
|
||||||
|
? ctx.agency.crewConfig.crewSize *
|
||||||
|
(85 + 15 * ctx.agency.crewConfig.lifeSupport) +
|
||||||
|
500 * ctx.agency.crewConfig.lifeSupport
|
||||||
|
: 0),
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
ctx.latestAssembly = buildRocket(ctx.design, state.parts, state.materials, {
|
||||||
|
priceOf,
|
||||||
|
mission: effectiveMission,
|
||||||
|
difficulty: curAgency(ctx).difficulty,
|
||||||
|
weather: state.world?.weather ?? "nominal",
|
||||||
|
unlockedTechs: curAgency(ctx).unlockedTechs ?? [],
|
||||||
|
});
|
||||||
|
ctx.latestValidation = validateDesign(
|
||||||
|
ctx.design,
|
||||||
|
state.parts,
|
||||||
|
state.materials,
|
||||||
|
{
|
||||||
|
mission: effectiveMission,
|
||||||
|
simTime: state.world?.simTime ?? 0,
|
||||||
|
weather: state.world?.weather ?? "nominal",
|
||||||
|
activeHazards: state.world?.activeHazards ?? [],
|
||||||
|
unlockedTechs: curAgency(ctx).unlockedTechs ?? [],
|
||||||
|
difficulty: curAgency(ctx).difficulty,
|
||||||
|
waiverCostMult: ctx.sponsor?.waiverCostMult ?? 1.0,
|
||||||
|
crewedSeats: curAgency(ctx).crewConfig?.crewSize ?? 0,
|
||||||
|
eclssLevel: curAgency(ctx).crewConfig?.lifeSupport ?? 0,
|
||||||
|
priceOf,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
ctx.latestReliability = computeDesignReliability(
|
||||||
|
ctx.design,
|
||||||
|
ctx.latestAssembly,
|
||||||
|
curAgency(ctx),
|
||||||
|
);
|
||||||
|
ctx.latestValueEstimate = estimateContractValue(
|
||||||
|
ctx.design,
|
||||||
|
ctx.latestAssembly,
|
||||||
|
ctx.latestValidation,
|
||||||
|
{
|
||||||
|
mission: effectiveMission,
|
||||||
|
difficulty: curAgency(ctx).difficulty,
|
||||||
|
sponsorReputationMult: ctx.sponsor?.reputationMult ?? 1.0,
|
||||||
|
staticFired: false,
|
||||||
|
launchInsured: !!curAgency(ctx).launchInsured,
|
||||||
|
anomalyRiskPct: ctx.latestReliability.anomalyRiskPct,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
ctx.latestCoach = generateCoachDiagnostics(
|
||||||
|
ctx.design,
|
||||||
|
ctx.latestAssembly,
|
||||||
|
ctx.latestValidation,
|
||||||
|
effectiveMission,
|
||||||
|
curAgency(ctx).difficulty,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function renderSummaryAndCoopBars(ctx: BuilderContext): void {
|
||||||
|
clear(ctx.summaryBar);
|
||||||
|
const val = ctx.latestValueEstimate;
|
||||||
|
const bus = ctx.latestAssembly?.spacecraftBus;
|
||||||
|
const reqSig = ctx.contract?.minSignalHealthPct ?? 60;
|
||||||
|
const reqPwr = ctx.contract?.minPowerMarginPct ?? 10;
|
||||||
|
const sigCls = bus
|
||||||
|
? bus.signalHealthPct >= reqSig
|
||||||
|
? "green"
|
||||||
|
: bus.signalHealthPct >= reqSig - 10
|
||||||
|
? "amber"
|
||||||
|
: "red"
|
||||||
|
: "dim";
|
||||||
|
const pwrCls = bus
|
||||||
|
? bus.powerMarginPct >= reqPwr
|
||||||
|
? "green"
|
||||||
|
: bus.powerMarginPct >= 0
|
||||||
|
? "amber"
|
||||||
|
: "red"
|
||||||
|
: "dim";
|
||||||
|
const gradeCls =
|
||||||
|
bus?.efficiencyGrade === "S" || bus?.efficiencyGrade === "A"
|
||||||
|
? "green"
|
||||||
|
: bus?.efficiencyGrade === "B"
|
||||||
|
? "accent"
|
||||||
|
: bus?.efficiencyGrade === "C"
|
||||||
|
? "amber"
|
||||||
|
: "red";
|
||||||
|
const profitCls = val
|
||||||
|
? val.projectedNetProfitNominal >= 0
|
||||||
|
? "green"
|
||||||
|
: "red"
|
||||||
|
: "dim";
|
||||||
|
ctx.summaryBar.append(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "spread", style: { gap: "8px" } },
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{
|
||||||
|
class: "mono",
|
||||||
|
style: {
|
||||||
|
fontSize: "10px",
|
||||||
|
fontWeight: "700",
|
||||||
|
color: ctx.contract ? "var(--brand-blue)" : "var(--text-dim)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ctx.contract
|
||||||
|
? `${ctx.contract.name} • ${ctx.contract.targetName}${ctx.contract.isConvoluted ? " [CONVOLUTED]" : ""}`
|
||||||
|
: "Sandbox / Free-Flight Test Stand (No Active Contract)",
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `btn xs ${ctx.activeTab === "value" ? "selected" : "ghost"}`,
|
||||||
|
onClick: () => {
|
||||||
|
ctx.activeTab = "value";
|
||||||
|
ctx.renderAll();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Value Chart →",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "summary-pills" },
|
||||||
|
ctx.contract && val
|
||||||
|
? h("span", {}, `Budget: ${fmtMoney(ctx.contract.budget)}`)
|
||||||
|
: null,
|
||||||
|
val
|
||||||
|
? h(
|
||||||
|
"span",
|
||||||
|
{ class: profitCls },
|
||||||
|
`Net EV: ${fmtMoney(val.projectedNetProfitNominal)}`,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
bus
|
||||||
|
? h(
|
||||||
|
"span",
|
||||||
|
{ class: gradeCls },
|
||||||
|
`Eff ${bus.efficiencyGrade} (${bus.efficiencyScore})`,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
bus ? h("span", { class: sigCls }, `Sig ${bus.signalHealthPct}%`) : null,
|
||||||
|
bus
|
||||||
|
? h(
|
||||||
|
"span",
|
||||||
|
{ class: pwrCls },
|
||||||
|
`Pwr ${bus.powerMarginPct >= 0 ? "+" : ""}${bus.powerMarginPct}%`,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
bus
|
||||||
|
? h("span", { class: "dim" }, `${fmtMoney(bus.costPerKgPayload)}/kg`)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
clear(ctx.coopBar);
|
||||||
|
const ag = curAgency(ctx);
|
||||||
|
const stations = ag.teamStations ?? createDefaultTeamStations();
|
||||||
|
const readyCount = TEAM_STATION_DEFS.filter(
|
||||||
|
(d) => stations[d.id]?.ready,
|
||||||
|
).length;
|
||||||
|
ctx.coopBar.appendChild(
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "mono dim", style: { fontSize: "9px", marginRight: "4px" } },
|
||||||
|
`CO-OP (${readyCount}/4)`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
for (const def of TEAM_STATION_DEFS) {
|
||||||
|
const st = stations[def.id] ?? {
|
||||||
|
stationId: def.id as TeamStationId,
|
||||||
|
title: def.title,
|
||||||
|
operatorName: "Unassigned",
|
||||||
|
ready: false,
|
||||||
|
updatedAt: 0,
|
||||||
|
};
|
||||||
|
const cls = st.ready
|
||||||
|
? "ready"
|
||||||
|
: st.operatorName !== "Unassigned"
|
||||||
|
? "occupied"
|
||||||
|
: "";
|
||||||
|
const shortOp =
|
||||||
|
st.operatorName === "Unassigned" ? "OPEN" : st.operatorName.slice(0, 10);
|
||||||
|
ctx.coopBar.appendChild(
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `station-pill ${cls}`,
|
||||||
|
title: `${def.title}: ${def.scope} (Click to claim / toggle Ready)`,
|
||||||
|
onClick: async () => {
|
||||||
|
try {
|
||||||
|
const opName = state.account?.name || ag.name;
|
||||||
|
const nextReady = st.operatorName === opName ? !st.ready : false;
|
||||||
|
const res = await api.post<{
|
||||||
|
teamStations: AgencyState["teamStations"];
|
||||||
|
agency: AgencyState;
|
||||||
|
}>("/api/agency/station", {
|
||||||
|
stationId: def.id,
|
||||||
|
operatorName: opName,
|
||||||
|
ready: nextReady,
|
||||||
|
});
|
||||||
|
if (state.agency) state.agency.teamStations = res.teamStations;
|
||||||
|
renderSummaryAndCoopBars(ctx);
|
||||||
|
toast(
|
||||||
|
`${def.title}: ${opName} (${nextReady ? "READY" : "ACTIVE"})`,
|
||||||
|
"info",
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
toast((err as Error).message, "err");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
`${def.id.toUpperCase()}: ${shortOp} ${st.ready ? "✓" : "○"}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
169
src/client/screens/builder/history.ts
Normal file
169
src/client/screens/builder/history.ts
Normal file
|
|
@ -0,0 +1,169 @@
|
||||||
|
// Undo/redo timeline history and restore modal for Rocket Builder
|
||||||
|
// Everything needs an undo button
|
||||||
|
import { state } from "../../state.js";
|
||||||
|
import { normalizeDesign } from "../../../shared/physics.js";
|
||||||
|
import { h, modal, toast } from "../../ui.js";
|
||||||
|
import { MAX_HISTORY_ENTRIES, type BuilderContext } from "./context.js";
|
||||||
|
|
||||||
|
export function updateHistoryButtons(ctx: BuilderContext): void {
|
||||||
|
ctx.undoBtn.disabled = ctx.historyIndex <= 0;
|
||||||
|
ctx.redoBtn.disabled = ctx.historyIndex >= ctx.history.length - 1;
|
||||||
|
ctx.historyBtn.textContent = `History (${ctx.historyIndex + 1}/${ctx.history.length})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function recordHistory(
|
||||||
|
ctx: BuilderContext,
|
||||||
|
label: string,
|
||||||
|
coalesceKey?: string,
|
||||||
|
): void {
|
||||||
|
if (ctx.suppressHistory) return;
|
||||||
|
const serialized = JSON.stringify(ctx.design);
|
||||||
|
if (serialized === ctx.lastRecordedJson) return;
|
||||||
|
const now = Date.now();
|
||||||
|
const snap = structuredClone(ctx.design);
|
||||||
|
if (ctx.historyIndex < ctx.history.length - 1) {
|
||||||
|
ctx.history = ctx.history.slice(0, ctx.historyIndex + 1);
|
||||||
|
}
|
||||||
|
const top = ctx.history[ctx.historyIndex];
|
||||||
|
if (coalesceKey && top?.coalesceKey === coalesceKey && now - top.at < 950) {
|
||||||
|
top.snapshot = snap;
|
||||||
|
top.at = now;
|
||||||
|
if (label && label !== "Adjust vehicle parameters") top.label = label;
|
||||||
|
} else {
|
||||||
|
ctx.history.push({ snapshot: snap, label, at: now, coalesceKey });
|
||||||
|
if (ctx.history.length > MAX_HISTORY_ENTRIES) {
|
||||||
|
ctx.history.shift();
|
||||||
|
}
|
||||||
|
ctx.historyIndex = ctx.history.length - 1;
|
||||||
|
}
|
||||||
|
ctx.lastRecordedJson = serialized;
|
||||||
|
updateHistoryButtons(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function applyHistoryIndex(ctx: BuilderContext, idx: number): void {
|
||||||
|
if (idx < 0 || idx >= ctx.history.length) return;
|
||||||
|
ctx.suppressHistory = true;
|
||||||
|
try {
|
||||||
|
ctx.historyIndex = idx;
|
||||||
|
ctx.design = normalizeDesign(
|
||||||
|
structuredClone(ctx.history[idx].snapshot),
|
||||||
|
state.parts,
|
||||||
|
state.materials,
|
||||||
|
);
|
||||||
|
if (ctx.activeStageIdx >= ctx.design.stages.length) {
|
||||||
|
ctx.activeStageIdx = Math.max(0, ctx.design.stages.length - 1);
|
||||||
|
}
|
||||||
|
ctx.lastRecordedJson = JSON.stringify(ctx.design);
|
||||||
|
ctx.renderAll();
|
||||||
|
} finally {
|
||||||
|
ctx.suppressHistory = false;
|
||||||
|
updateHistoryButtons(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function undoEdit(ctx: BuilderContext): void {
|
||||||
|
if (ctx.historyIndex <= 0) return;
|
||||||
|
const label = ctx.history[ctx.historyIndex]?.label ?? "edit";
|
||||||
|
applyHistoryIndex(ctx, ctx.historyIndex - 1);
|
||||||
|
toast(`Undid: ${label}`, "info");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function redoEdit(ctx: BuilderContext): void {
|
||||||
|
if (ctx.historyIndex >= ctx.history.length - 1) return;
|
||||||
|
applyHistoryIndex(ctx, ctx.historyIndex + 1);
|
||||||
|
toast(`Redid: ${ctx.history[ctx.historyIndex]?.label ?? "edit"}`, "info");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openHistoryModal(ctx: BuilderContext): void {
|
||||||
|
const listWrap = h("div", {
|
||||||
|
style: {
|
||||||
|
maxHeight: "55vh",
|
||||||
|
overflowY: "auto",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
gap: "6px",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const entriesDesc = ctx.history
|
||||||
|
.map((entry, idx) => ({ entry, idx }))
|
||||||
|
.reverse();
|
||||||
|
for (const { entry, idx } of entriesDesc) {
|
||||||
|
const isCurrent = idx === ctx.historyIndex;
|
||||||
|
const isFuture = idx > ctx.historyIndex;
|
||||||
|
listWrap.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "panel row spread",
|
||||||
|
style: {
|
||||||
|
padding: "8px 10px",
|
||||||
|
borderColor: isCurrent ? "var(--brand-blue)" : "var(--border)",
|
||||||
|
opacity: isFuture ? "0.62" : "1",
|
||||||
|
gap: "8px",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "mono",
|
||||||
|
style: {
|
||||||
|
fontSize: "11px",
|
||||||
|
fontWeight: isCurrent ? "700" : "500",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
`#${idx + 1} ${entry.label}${isCurrent ? " (Current)" : isFuture ? " (Undone)" : ""}`,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "dim", style: { fontSize: "10px" } },
|
||||||
|
`${new Date(entry.at).toLocaleTimeString()} • ${entry.snapshot.stages.length} stage(s) • Tier: ${entry.snapshot.designTier ?? "basic"}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `btn xs ${isCurrent ? "selected" : "primary"}`,
|
||||||
|
disabled: isCurrent,
|
||||||
|
onClick: () => {
|
||||||
|
applyHistoryIndex(ctx, idx);
|
||||||
|
m.close();
|
||||||
|
toast(
|
||||||
|
`Restored ctx.history step #${idx + 1}: ${entry.label}`,
|
||||||
|
"info",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isCurrent ? "Active" : "Restore",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const m = modal(
|
||||||
|
"Editor History Timeline",
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{},
|
||||||
|
h(
|
||||||
|
"p",
|
||||||
|
{ class: "dim", style: { fontSize: "12px", marginBottom: "10px" } },
|
||||||
|
"Click any checkpoint to jump cleanly across your edits (up to 50 recent checkpoints). Keyboard shortcuts: Ctrl+Z / Ctrl+Y.",
|
||||||
|
),
|
||||||
|
listWrap,
|
||||||
|
),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
label: "Undo",
|
||||||
|
kind: "ghost",
|
||||||
|
onClick: () => {
|
||||||
|
undoEdit(ctx);
|
||||||
|
m.close();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ label: "Close", kind: "primary" },
|
||||||
|
],
|
||||||
|
);
|
||||||
|
m.el.style.maxWidth = "560px";
|
||||||
|
}
|
||||||
733
src/client/screens/builder/payloadTab.ts
Normal file
733
src/client/screens/builder/payloadTab.ts
Normal file
|
|
@ -0,0 +1,733 @@
|
||||||
|
// Rocket Builder Avionics, Aero profile, Fairing, Payload, and Spacecraft Bus tab
|
||||||
|
import { state } from "../../state.js";
|
||||||
|
import {
|
||||||
|
createDefaultSpacecraftConfig,
|
||||||
|
GROUND_NETWORK_SPECS,
|
||||||
|
SCIENCE_INSTRUMENTS,
|
||||||
|
SPACECRAFT_COMMS_SYSTEMS,
|
||||||
|
SPACECRAFT_POWER_SYSTEMS,
|
||||||
|
} from "../../../shared/physics.js";
|
||||||
|
import type { GroundNetworkTier } from "../../../shared/types.js";
|
||||||
|
import { fmtMoney, fmtNum, h, term } from "../../ui.js";
|
||||||
|
import { partLockTag, type BuilderContext } from "./context.js";
|
||||||
|
|
||||||
|
export function renderPayloadTab(ctx: BuilderContext): void {
|
||||||
|
const { bodyEl, contract } = ctx;
|
||||||
|
const lockTag = (id: string) => partLockTag(ctx, id);
|
||||||
|
const fairings = state.parts.filter((p) => p.kind === "fairing");
|
||||||
|
const payloads = state.parts.filter((p) => p.kind === "payload");
|
||||||
|
const computers = state.parts.filter((p) => p.kind === "computer");
|
||||||
|
const aero = ctx.latestAssembly!.aero;
|
||||||
|
const compPart = ctx.latestAssembly?.computerPart;
|
||||||
|
const baseLoad = Math.round(ctx.latestAssembly?.computeLoadBasePct ?? 0);
|
||||||
|
const peakLoad = Math.round(ctx.latestAssembly?.peakComputeLoadEstPct ?? 0);
|
||||||
|
const diagTier = ctx.latestAssembly?.effectiveDiagnosticTier ?? 1;
|
||||||
|
const compSel = h(
|
||||||
|
"select",
|
||||||
|
{
|
||||||
|
class: "input",
|
||||||
|
onChange: () => {
|
||||||
|
ctx.design.computerId = compSel.value;
|
||||||
|
if (ctx.design.designTier === "pro" && ctx.design.proParts) {
|
||||||
|
const idx = ctx.design.proParts.findIndex(
|
||||||
|
(p) => p.role === "computer",
|
||||||
|
);
|
||||||
|
const part = state.parts.find((p) => p.id === compSel.value);
|
||||||
|
if (part) {
|
||||||
|
if (idx >= 0) {
|
||||||
|
ctx.design.proParts[idx].partId = part.id;
|
||||||
|
} else {
|
||||||
|
ctx.design.proParts.push({
|
||||||
|
uid: `pro-comp-${Date.now()}`,
|
||||||
|
role: "computer",
|
||||||
|
partId: part.id,
|
||||||
|
stageIndex: Math.max(0, ctx.design.stages.length - 1),
|
||||||
|
yBottom: Math.max(
|
||||||
|
0.5,
|
||||||
|
(ctx.latestAssembly?.fairingY ?? 20) - 0.6,
|
||||||
|
),
|
||||||
|
radialOffset: 0,
|
||||||
|
radialAngleDeg: 0,
|
||||||
|
symmetry: 1,
|
||||||
|
diameter: part.diameter,
|
||||||
|
length: part.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.refreshEngineering(true, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{ value: "", selected: !ctx.design.computerId },
|
||||||
|
"— None Attached (Fails AVN-01 Compliance) —",
|
||||||
|
),
|
||||||
|
...computers.map((c) =>
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{ value: c.id, selected: c.id === ctx.design.computerId },
|
||||||
|
`${c.name} (${c.computeCapacityIps ?? 100} MIPS • Rad-Hard L${c.radHardeningLevel ?? 1} • Scrub ${Math.round((c.faultScrubRate ?? 0) * 100)}%)${lockTag(c.id)}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const computerCard = h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "stage-card active",
|
||||||
|
style: {
|
||||||
|
marginBottom: "10px",
|
||||||
|
borderColor:
|
||||||
|
!compPart || peakLoad > 125
|
||||||
|
? "var(--red)"
|
||||||
|
: peakLoad > 95
|
||||||
|
? "var(--amber)"
|
||||||
|
: "var(--brand-blue)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "spread" },
|
||||||
|
h("h3", {}, term("Flight Computer & Avionics Core", "flight_computer")),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{
|
||||||
|
class: `badge ${peakLoad > 125 ? "err" : peakLoad > 95 ? "warn" : "ok"}`,
|
||||||
|
},
|
||||||
|
`DIAG TIER ${diagTier}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-group" },
|
||||||
|
h("label", { class: "field" }, "Flight Computer Hardware", compSel),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "k" },
|
||||||
|
term("Compute Load (Nominal / Max-Q Peak)", "cpu_load"),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{
|
||||||
|
class: `v ${peakLoad > 125 ? "red" : peakLoad > 95 ? "amber" : "green"}`,
|
||||||
|
},
|
||||||
|
`${baseLoad}% / ${peakLoad}%`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
compPart
|
||||||
|
? h(
|
||||||
|
"div",
|
||||||
|
{ class: "col", style: { gap: "2px", fontSize: "11px" } },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "k" },
|
||||||
|
term("Radiation Hardening & Scrubbing", "rad_hardening"),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "v" },
|
||||||
|
`L${compPart.radHardeningLevel ?? 1} (${Math.round((compPart.faultScrubRate ?? 0) * 100)}% EDAC scrub)`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h("span", { class: "k" }, "Avionics Power / Thermal Cap"),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "v" },
|
||||||
|
`${compPart.powerDrawKw ?? 0.5} kW • ${compPart.maxTempK ?? 400} K`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: h(
|
||||||
|
"p",
|
||||||
|
{ class: "red mono", style: { fontSize: "11px" } },
|
||||||
|
"CRITICAL: Vehicle has no Flight Computer! Select avionics above to enable GNC & pass AVN-01.",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
bodyEl.appendChild(computerCard);
|
||||||
|
const activeHazards = state.world?.activeHazards ?? [];
|
||||||
|
if (activeHazards.length > 0) {
|
||||||
|
bodyEl.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
class: "panel",
|
||||||
|
style: {
|
||||||
|
padding: "10px",
|
||||||
|
marginBottom: "10px",
|
||||||
|
borderColor: "var(--amber)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "spread", style: { marginBottom: "4px" } },
|
||||||
|
h(
|
||||||
|
"h3",
|
||||||
|
{},
|
||||||
|
term("Active Pre-Launch Hazard Advisory", "space_weather"),
|
||||||
|
),
|
||||||
|
h("span", { class: "badge warn" }, `${activeHazards.length} ACTIVE`),
|
||||||
|
),
|
||||||
|
...activeHazards.map((hz) =>
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ style: { fontSize: "11px", marginTop: "4px" } },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "amber mono", style: { fontWeight: "700" } },
|
||||||
|
`${hz.title} (${hz.altMinKm}–${hz.altMaxKm} km)`,
|
||||||
|
),
|
||||||
|
h("div", { class: "dim" }, hz.countermeasureHint),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const aeroCard = h(
|
||||||
|
"div",
|
||||||
|
{ class: "stage-card active", style: { marginBottom: "10px" } },
|
||||||
|
h("h3", {}, term("Shape-Based Aerodynamic Profile", "fineness")),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h("span", { class: "k" }, "Projected Frontal Area"),
|
||||||
|
h("span", { class: "v" }, `${aero.frontalAreaM2.toFixed(2)} m²`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h("span", { class: "k" }, "Base Zero-Lift Cd"),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: `v ${aero.baseCd <= 0.42 ? "green" : "amber"}` },
|
||||||
|
aero.baseCd.toFixed(3),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h("span", { class: "k" }, "Step / Frustum Penalty"),
|
||||||
|
h("span", { class: "v" }, `+${aero.stepPenaltyCd.toFixed(3)} Cd`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h("span", { class: "k" }, "Radial Interference Drag"),
|
||||||
|
h("span", { class: "v" }, `+${aero.radialInterferenceCd.toFixed(3)} Cd`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h("span", { class: "k" }, term("Nose Fineness / Shroud", "fairing")),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: `v ${aero.hasExposedBluntNose ? "red" : "green"}` },
|
||||||
|
aero.hasExposedBluntNose
|
||||||
|
? "EXPOSED BLUNT NOSE (+0.44 Cd)"
|
||||||
|
: `${aero.noseFinenessRatio.toFixed(2)} L/D Fairing`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h("span", { class: "k" }, term("Fin Restoring Moment", "grid_fins")),
|
||||||
|
h("span", { class: "v" }, `${fmtNum(aero.finRestoringMoment)} N·m/rad`),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
bodyEl.appendChild(aeroCard);
|
||||||
|
if (ctx.design.designTier === "pro") {
|
||||||
|
const massInput = h("input", {
|
||||||
|
type: "number",
|
||||||
|
class: "input",
|
||||||
|
min: 0,
|
||||||
|
max: 150000,
|
||||||
|
step: 100,
|
||||||
|
value: ctx.design.payloadMass,
|
||||||
|
onInput: () => {
|
||||||
|
ctx.design.payloadMass = Math.max(0, Number(massInput.value) || 0);
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
bodyEl.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stage-card active" },
|
||||||
|
h("h3", {}, "Pro Payload & Mission Mass"),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "dim", style: { fontSize: "11px", marginBottom: "6px" } },
|
||||||
|
"In Pro mode, mount or reposition Fairings, Payloads, and LAS Towers inside the Pro Assembly tab.",
|
||||||
|
),
|
||||||
|
h("label", { class: "field" }, "Payload Mass Override (kg)", massInput),
|
||||||
|
contract
|
||||||
|
? h(
|
||||||
|
"div",
|
||||||
|
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||||
|
`Contract payload requirement: ${fmtNum(contract.payloadMass)} kg`,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
renderSpacecraftBusSection(ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const fairingSel = h(
|
||||||
|
"select",
|
||||||
|
{
|
||||||
|
class: "input",
|
||||||
|
onChange: () => {
|
||||||
|
ctx.design.fairingId = fairingSel.value;
|
||||||
|
ctx.refreshEngineering(true, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...fairings.map((f) =>
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{ value: f.id, selected: f.id === ctx.design.fairingId },
|
||||||
|
`${f.name} (Max Payload Ø ${f.maxPayloadDiameter ?? f.diameter}m, Max-Q ${(f.maxQ ?? 55000) / 1000} kPa)${lockTag(f.id)}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const payloadSel = h(
|
||||||
|
"select",
|
||||||
|
{
|
||||||
|
class: "input",
|
||||||
|
onChange: () => {
|
||||||
|
ctx.design.payloadPartId = payloadSel.value;
|
||||||
|
const p = payloads.find((x) => x.id === payloadSel.value);
|
||||||
|
if (p) ctx.design.payloadMass = p.dryMass;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...payloads.map((p) =>
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{ value: p.id, selected: p.id === ctx.design.payloadPartId },
|
||||||
|
`${p.name} (${fmtNum(p.dryMass)} kg${p.crewedCapable ? ", CREWED" : ""})`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const lasChk = h("input", {
|
||||||
|
type: "checkbox",
|
||||||
|
checked: !!ctx.design.hasLaunchAbort,
|
||||||
|
onChange: () => {
|
||||||
|
ctx.design.hasLaunchAbort = lasChk.checked;
|
||||||
|
ctx.refreshEngineering(true, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const contractMassInput = h("input", {
|
||||||
|
type: "number",
|
||||||
|
class: "input",
|
||||||
|
min: 0,
|
||||||
|
max: 150000,
|
||||||
|
step: 100,
|
||||||
|
value: ctx.design.payloadMass,
|
||||||
|
onInput: () => {
|
||||||
|
ctx.design.payloadMass = Math.max(
|
||||||
|
0,
|
||||||
|
Number(contractMassInput.value) || 0,
|
||||||
|
);
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
bodyEl.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stage-card active" },
|
||||||
|
h("h3", {}, "Fairing & NASA Spacecraft Integration"),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-group" },
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "field" },
|
||||||
|
term("Payload Fairing Shroud", "fairing"),
|
||||||
|
fairingSel,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-group" },
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "field" },
|
||||||
|
"NASA 3D Spacecraft / Capsule",
|
||||||
|
payloadSel,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-group" },
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "field" },
|
||||||
|
"Payload Bus Mass (kg)",
|
||||||
|
contractMassInput,
|
||||||
|
),
|
||||||
|
contract
|
||||||
|
? h(
|
||||||
|
"div",
|
||||||
|
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||||
|
`Contract payload requirement: ${fmtNum(contract.payloadMass)} kg`,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-group" },
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "row", style: { cursor: "pointer", fontSize: "12px" } },
|
||||||
|
lasChk,
|
||||||
|
term(
|
||||||
|
"Mount Launch Abort Escape Tower (+1,400 kg, mandatory for crewed missions)",
|
||||||
|
"las",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
renderSpacecraftBusSection(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function renderSpacecraftBusSection(ctx: BuilderContext): void {
|
||||||
|
const { bodyEl, contract } = ctx;
|
||||||
|
if (!ctx.design.spacecraftConfig) {
|
||||||
|
ctx.design.spacecraftConfig = createDefaultSpacecraftConfig(contract);
|
||||||
|
}
|
||||||
|
const sc = ctx.design.spacecraftConfig;
|
||||||
|
const bus = ctx.latestAssembly?.spacecraftBus;
|
||||||
|
if (!bus) return;
|
||||||
|
const pwrSel = h(
|
||||||
|
"select",
|
||||||
|
{
|
||||||
|
class: "input",
|
||||||
|
onChange: () => {
|
||||||
|
sc.powerSystemId = pwrSel.value;
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...SPACECRAFT_POWER_SYSTEMS.map((p) =>
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{ value: p.id, selected: p.id === sc.powerSystemId },
|
||||||
|
`${p.name} (${p.powerWattsAt1AU}W @1AU • ${p.massKg}kg • ${fmtMoney(p.cost)})`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const commSel = h(
|
||||||
|
"select",
|
||||||
|
{
|
||||||
|
class: "input",
|
||||||
|
onChange: () => {
|
||||||
|
sc.commsSystemId = commSel.value;
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...SPACECRAFT_COMMS_SYSTEMS.map((c) =>
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{ value: c.id, selected: c.id === sc.commsSystemId },
|
||||||
|
`${c.name} (${c.baseDataRateMbps} Mbps • ${c.powerDrawWatts}W • ${fmtMoney(c.cost)})`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const netSel = h(
|
||||||
|
"select",
|
||||||
|
{
|
||||||
|
class: "input",
|
||||||
|
onChange: () => {
|
||||||
|
sc.groundNetworkTier = netSel.value as GroundNetworkTier;
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...Object.values(GROUND_NETWORK_SPECS).map((n) =>
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{
|
||||||
|
value: n.id,
|
||||||
|
selected: n.id === (sc.groundNetworkTier ?? "regional"),
|
||||||
|
},
|
||||||
|
`${n.name} (${n.coveragePct}% cov • +${fmtMoney(n.cost)})`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const lifeInput = h("input", {
|
||||||
|
type: "number",
|
||||||
|
class: "input",
|
||||||
|
min: 1,
|
||||||
|
max: 15,
|
||||||
|
step: 1,
|
||||||
|
value: sc.missionLifetimeYears,
|
||||||
|
onInput: () => {
|
||||||
|
sc.missionLifetimeYears = Math.max(
|
||||||
|
1,
|
||||||
|
Math.min(15, Math.round(Number(lifeInput.value) || 3)),
|
||||||
|
);
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const pwrMarginOk = bus.powerMarginPct >= (contract?.minPowerMarginPct ?? 10);
|
||||||
|
const sigOk = bus.signalHealthPct >= (contract?.minSignalHealthPct ?? 60);
|
||||||
|
const dataOk = bus.dataMarginMbps >= 0;
|
||||||
|
const instList = h(
|
||||||
|
"div",
|
||||||
|
{ class: "col", style: { gap: "6px" } },
|
||||||
|
...SCIENCE_INSTRUMENTS.map((inst) => {
|
||||||
|
const checked = sc.instrumentIds.includes(inst.id);
|
||||||
|
const disabled = !checked && sc.instrumentIds.length >= 4;
|
||||||
|
const chk = h("input", {
|
||||||
|
type: "checkbox",
|
||||||
|
checked,
|
||||||
|
disabled,
|
||||||
|
onChange: () => {
|
||||||
|
if (chk.checked) {
|
||||||
|
if (
|
||||||
|
!sc.instrumentIds.includes(inst.id) &&
|
||||||
|
sc.instrumentIds.length < 4
|
||||||
|
) {
|
||||||
|
sc.instrumentIds = [...sc.instrumentIds, inst.id];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sc.instrumentIds = sc.instrumentIds.filter((id) => id !== inst.id);
|
||||||
|
}
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return h(
|
||||||
|
"label",
|
||||||
|
{
|
||||||
|
class: "rule-item " + (checked ? "pass" : ""),
|
||||||
|
style: { cursor: disabled ? "not-allowed" : "pointer" },
|
||||||
|
},
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "spread", style: { gap: "8px" } },
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "row", style: { gap: "6px" } },
|
||||||
|
chk,
|
||||||
|
h("strong", {}, inst.name),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "mono green", style: { fontSize: "10px" } },
|
||||||
|
`+${inst.scienceBonusPct}% Sci • +${inst.researchPointsBonus} RP`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||||
|
`${inst.massKg} kg • ${inst.powerDrawWatts}W • ${inst.dataRateMbps} Mbps • ${fmtMoney(inst.cost)}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
bodyEl.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stage-card active", style: { marginTop: "10px" } },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "spread" },
|
||||||
|
h(
|
||||||
|
"h3",
|
||||||
|
{},
|
||||||
|
term("Spacecraft Bus, Ground Control & Science", "spacecraft_bus"),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: `badge ${sigOk && pwrMarginOk ? "ok" : "warn"}` },
|
||||||
|
`Eff Grade ${bus.efficiencyGrade}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-group" },
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "field" },
|
||||||
|
term("Power Generation Subsystem", "power_margin"),
|
||||||
|
pwrSel,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-group" },
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "field" },
|
||||||
|
term("Onboard Comms Transponder", "comms_link"),
|
||||||
|
commSel,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-group" },
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "field" },
|
||||||
|
term("Ground Control Antenna Network", "ground_network"),
|
||||||
|
netSel,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-group" },
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "field" },
|
||||||
|
"Planned Mission Lifetime (Years)",
|
||||||
|
lifeInput,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-title", style: { marginTop: "4px" } },
|
||||||
|
`Power Budget Breakdown (Solar Flux ${Math.round(bus.solarFluxFactor * 100)}%)`,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "bus-power-grid" },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "bus-power-cell" },
|
||||||
|
h("span", { class: "k" }, "EOL Supply"),
|
||||||
|
h("span", { class: "v accent" }, `${bus.endOfLifePowerWatts} W`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "bus-power-cell" },
|
||||||
|
h("span", { class: "k" }, "Total Load"),
|
||||||
|
h("span", { class: "v" }, `${bus.requiredPowerWatts} W`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "bus-power-cell" },
|
||||||
|
h("span", { class: "k" }, "Avionics & ADCS"),
|
||||||
|
h("span", { class: "v" }, `${bus.avionicsPowerWatts} W`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "bus-power-cell" },
|
||||||
|
h("span", { class: "k" }, "Comms RF/Laser"),
|
||||||
|
h("span", { class: "v" }, `${bus.commsPowerWatts} W`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "bus-power-cell" },
|
||||||
|
h("span", { class: "k" }, "Science Suite"),
|
||||||
|
h("span", { class: "v" }, `${bus.instrumentsPowerWatts} W`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "bus-power-cell" },
|
||||||
|
h("span", { class: "k" }, "Thermal + ECLSS"),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "v" },
|
||||||
|
`${bus.thermalEclipsePowerWatts + bus.eclssPowerWatts} W`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "k" },
|
||||||
|
term(
|
||||||
|
`Power Margin (Req >= ${contract?.minPowerMarginPct ?? 10}%)`,
|
||||||
|
"power_margin",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{
|
||||||
|
class: `v ${pwrMarginOk ? "green" : bus.powerMarginPct >= 0 ? "amber" : "red"}`,
|
||||||
|
},
|
||||||
|
`${bus.powerMarginWatts >= 0 ? "+" : ""}${bus.powerMarginWatts} W (${bus.powerMarginPct >= 0 ? "+" : ""}${bus.powerMarginPct}%)`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-title", style: { marginTop: "4px" } },
|
||||||
|
term("Ground Control Telemetry & Link Health", "comms_link"),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "k" },
|
||||||
|
`Link Health (Req >= ${contract?.minSignalHealthPct ?? 60}%)`,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: `v ${sigOk ? "green" : "red"}` },
|
||||||
|
`${bus.signalHealthPct}% (${bus.linkStatus})`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h("span", { class: "k" }, "RF/Optical Link Margin"),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{
|
||||||
|
class: `v ${bus.linkMarginDb >= 3 ? "green" : bus.linkMarginDb >= 0 ? "amber" : "red"}`,
|
||||||
|
},
|
||||||
|
`${bus.linkMarginDb >= 0 ? "+" : ""}${bus.linkMarginDb.toFixed(1)} dB`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h("span", { class: "k" }, "Ground Station Coverage"),
|
||||||
|
h("span", { class: "v" }, `${bus.groundStationCoveragePct}%`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "stat-row" },
|
||||||
|
h("span", { class: "k" }, "Downlink vs Data Load"),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: `v ${dataOk ? "green" : "red"}` },
|
||||||
|
`${bus.downlinkCapacityMbps.toFixed(1)} / ${bus.requiredDataRateMbps.toFixed(1)} Mbps`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "spread", style: { marginTop: "6px" } },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-title" },
|
||||||
|
`Science Instruments (${sc.instrumentIds.length}/4)`,
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||||
|
`Req Min: ${contract?.requiredInstrumentsMin ?? 0}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
instList,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
513
src/client/screens/builder/proTab.ts
Normal file
513
src/client/screens/builder/proTab.ts
Normal file
|
|
@ -0,0 +1,513 @@
|
||||||
|
// Rocket Builder Pro tier free-form part mixer and per-part inspector
|
||||||
|
import { state } from "../../state.js";
|
||||||
|
import { convertStagesToProParts } from "../../../shared/physics.js";
|
||||||
|
import type { Part, ProPlacedPart } from "../../../shared/types.js";
|
||||||
|
import { h, term, toast } from "../../ui.js";
|
||||||
|
import { partLockTag, type BuilderContext } from "./context.js";
|
||||||
|
|
||||||
|
export function addProPartFromPalette(
|
||||||
|
ctx: BuilderContext,
|
||||||
|
part: Part,
|
||||||
|
radial = false,
|
||||||
|
asDropTank = false,
|
||||||
|
): void {
|
||||||
|
if (!ctx.design.proParts)
|
||||||
|
ctx.design.proParts = convertStagesToProParts(ctx.design, state.parts);
|
||||||
|
const list = ctx.design.proParts;
|
||||||
|
const selected = list.find((p) => p.uid === ctx.selectedProUid);
|
||||||
|
const topY = list.reduce((m, p) => Math.max(m, p.yBottom + p.length), 0);
|
||||||
|
const stageIndex = selected
|
||||||
|
? selected.stageIndex
|
||||||
|
: Math.max(0, (ctx.latestAssembly?.stages.length ?? 1) - 1);
|
||||||
|
const uid = `pro-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
|
||||||
|
const markDropTank =
|
||||||
|
part.kind === "tank" && (asDropTank || !!part.isDropTank);
|
||||||
|
let radialOffset = 0;
|
||||||
|
let symmetry: 1 | 2 | 3 | 4 | 6 | 8 = part.kind === "fins" ? 4 : 1;
|
||||||
|
let yBottom = Number(topY.toFixed(2));
|
||||||
|
if (radial || markDropTank) {
|
||||||
|
const coreR = selected ? selected.diameter / 2 : 1.85;
|
||||||
|
radialOffset = Number(
|
||||||
|
(coreR + part.diameter * 0.5 + (markDropTank ? 0.18 : 0)).toFixed(2),
|
||||||
|
);
|
||||||
|
symmetry =
|
||||||
|
part.kind === "fins" ? 4 : part.id === "drop-tank-hydro-et" ? 1 : 2;
|
||||||
|
yBottom = selected ? selected.yBottom : 0;
|
||||||
|
}
|
||||||
|
const item: ProPlacedPart = {
|
||||||
|
uid,
|
||||||
|
role: part.kind,
|
||||||
|
partId: part.id,
|
||||||
|
stageIndex,
|
||||||
|
yBottom,
|
||||||
|
radialOffset,
|
||||||
|
radialAngleDeg: 0,
|
||||||
|
symmetry,
|
||||||
|
diameter: part.diameter,
|
||||||
|
length:
|
||||||
|
part.kind === "heatshield"
|
||||||
|
? Number((part.length * 0.5).toFixed(2))
|
||||||
|
: part.length,
|
||||||
|
propellantFill: part.kind === "tank" ? 1.0 : undefined,
|
||||||
|
isDropTank: markDropTank || undefined,
|
||||||
|
materialId:
|
||||||
|
part.kind === "tank" ||
|
||||||
|
part.kind === "structure" ||
|
||||||
|
part.kind === "interstage"
|
||||||
|
? (state.materials[0]?.id ?? "al-7075")
|
||||||
|
: undefined,
|
||||||
|
};
|
||||||
|
list.push(item);
|
||||||
|
ctx.selectedProUid = uid;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderTierAndTabs();
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
toast(
|
||||||
|
`Mounted ${part.name}${markDropTank ? ` as ${symmetry}× external drop tank(s)` : radial ? " radially (2×)" : " on stack"}.`,
|
||||||
|
"info",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function renderProTab(ctx: BuilderContext): void {
|
||||||
|
const { bodyEl } = ctx;
|
||||||
|
const lockTag = (id: string) => partLockTag(ctx, id);
|
||||||
|
if (!ctx.design.proParts)
|
||||||
|
ctx.design.proParts = convertStagesToProParts(ctx.design, state.parts);
|
||||||
|
const partsList = ctx.design.proParts;
|
||||||
|
const paletteSel = h(
|
||||||
|
"select",
|
||||||
|
{ class: "input" },
|
||||||
|
...state.parts.map((p) =>
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{ value: p.id },
|
||||||
|
`[${p.kind.toUpperCase()}] ${p.name} (${p.diameter}m × ${p.length}m)${lockTag(p.id)}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const paletteCard = h(
|
||||||
|
"div",
|
||||||
|
{ class: "stage-card active" },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "spread" },
|
||||||
|
h("h3", {}, "Free Part Mixer"),
|
||||||
|
h("span", { class: "badge info" }, `${partsList.length} parts`),
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "mono dim", style: { fontSize: "10px", marginBottom: "6px" } },
|
||||||
|
"Drag pieces directly in 3D or mount centerline / radial strap-ons below. Shape & radial interference determine drag Cd and CG/CP.",
|
||||||
|
),
|
||||||
|
paletteSel,
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row", style: { marginTop: "6px" } },
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs primary grow",
|
||||||
|
onClick: () => {
|
||||||
|
const p = state.parts.find((x) => x.id === paletteSel.value);
|
||||||
|
if (p) addProPartFromPalette(ctx, p, false);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"+ Mount on Stack Top",
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs grow",
|
||||||
|
onClick: () => {
|
||||||
|
const p = state.parts.find((x) => x.id === paletteSel.value);
|
||||||
|
if (p) addProPartFromPalette(ctx, p, true);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"+ Mount Radially (2×)",
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs grow",
|
||||||
|
onClick: () => {
|
||||||
|
const p = state.parts.find((x) => x.id === paletteSel.value);
|
||||||
|
if (!p) return;
|
||||||
|
if (p.kind !== "tank") {
|
||||||
|
toast(
|
||||||
|
"Select a propellant Tank or Drop Tank in the palette to attach as crossfeed.",
|
||||||
|
"warn",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addProPartFromPalette(ctx, p, true, true);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"+ Drop Tank",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
bodyEl.appendChild(paletteCard);
|
||||||
|
const sorted = [...partsList].sort(
|
||||||
|
(a, b) =>
|
||||||
|
b.yBottom + b.length - (a.yBottom + a.length) ||
|
||||||
|
a.radialOffset - b.radialOffset,
|
||||||
|
);
|
||||||
|
const listBox = h("div", {
|
||||||
|
class: "col",
|
||||||
|
style: {
|
||||||
|
maxHeight: "175px",
|
||||||
|
overflowY: "auto",
|
||||||
|
gap: "4px",
|
||||||
|
marginBottom: "8px",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
for (const pp of sorted) {
|
||||||
|
const pSpec = state.parts.find((x) => x.id === pp.partId);
|
||||||
|
const isSel = pp.uid === ctx.selectedProUid;
|
||||||
|
listBox.appendChild(
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `btn xs ${isSel ? "selected" : "ghost"}`,
|
||||||
|
style: { justifyContent: "space-between", textAlign: "left" },
|
||||||
|
onClick: () => {
|
||||||
|
ctx.selectedProUid = pp.uid;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
h("span", {}, `S${pp.stageIndex + 1} • ${pSpec?.name ?? pp.partId}`),
|
||||||
|
h(
|
||||||
|
"span",
|
||||||
|
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||||
|
`Y=${pp.yBottom.toFixed(1)} R=${pp.radialOffset.toFixed(1)} (${pp.symmetry}×)`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
bodyEl.appendChild(
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-group" },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "slot-title" },
|
||||||
|
"Mounted Parts Hierarchy (Top → Bottom)",
|
||||||
|
),
|
||||||
|
listBox,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const sel =
|
||||||
|
partsList.find((x) => x.uid === ctx.selectedProUid) ?? partsList[0];
|
||||||
|
if (!sel) return;
|
||||||
|
ctx.selectedProUid = sel.uid;
|
||||||
|
const sameRoleParts = state.parts.filter((x) => x.kind === sel.role);
|
||||||
|
const roleModelSel = h(
|
||||||
|
"select",
|
||||||
|
{
|
||||||
|
class: "input",
|
||||||
|
onChange: () => {
|
||||||
|
sel.partId = roleModelSel.value;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...sameRoleParts.map((p) =>
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{ value: p.id, selected: p.id === sel.partId },
|
||||||
|
`${p.name} (${p.propellantType ?? p.kind})${lockTag(p.id)}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const stageSel = h(
|
||||||
|
"select",
|
||||||
|
{
|
||||||
|
class: "input",
|
||||||
|
onChange: () => {
|
||||||
|
sel.stageIndex = Number(stageSel.value);
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...[0, 1, 2, 3].map((i) =>
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{ value: String(i), selected: sel.stageIndex === i },
|
||||||
|
`Stage ${i + 1}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const yLabel = h("span", {}, `Vertical Y (${sel.yBottom.toFixed(1)} m)`);
|
||||||
|
const ySlider = h("input", {
|
||||||
|
type: "range",
|
||||||
|
class: "slider",
|
||||||
|
min: 0,
|
||||||
|
max: 85,
|
||||||
|
step: 0.1,
|
||||||
|
value: sel.yBottom,
|
||||||
|
onInput: () => {
|
||||||
|
sel.yBottom = Number(ySlider.value);
|
||||||
|
yLabel.textContent = `Vertical Y (${sel.yBottom.toFixed(1)} m)`;
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const rLabel = h(
|
||||||
|
"span",
|
||||||
|
{},
|
||||||
|
`Radial Offset R (${sel.radialOffset.toFixed(2)} m)`,
|
||||||
|
);
|
||||||
|
const rSlider = h("input", {
|
||||||
|
type: "range",
|
||||||
|
class: "slider",
|
||||||
|
min: 0,
|
||||||
|
max: 8.5,
|
||||||
|
step: 0.05,
|
||||||
|
value: sel.radialOffset,
|
||||||
|
onInput: () => {
|
||||||
|
sel.radialOffset = Number(rSlider.value);
|
||||||
|
rLabel.textContent = `Radial Offset R (${sel.radialOffset.toFixed(2)} m)`;
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const angLabel = h(
|
||||||
|
"span",
|
||||||
|
{},
|
||||||
|
`Radial Angle (${Math.round(sel.radialAngleDeg)}°)`,
|
||||||
|
);
|
||||||
|
const angSlider = h("input", {
|
||||||
|
type: "range",
|
||||||
|
class: "slider",
|
||||||
|
min: 0,
|
||||||
|
max: 355,
|
||||||
|
step: 5,
|
||||||
|
value: sel.radialAngleDeg,
|
||||||
|
onInput: () => {
|
||||||
|
sel.radialAngleDeg = Number(angSlider.value);
|
||||||
|
angLabel.textContent = `Radial Angle (${Math.round(sel.radialAngleDeg)}°)`;
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const dLabel = h("span", {}, `Diameter (${sel.diameter.toFixed(1)} m)`);
|
||||||
|
const dSlider = h("input", {
|
||||||
|
type: "range",
|
||||||
|
class: "slider",
|
||||||
|
min: 0.6,
|
||||||
|
max: 11.5,
|
||||||
|
step: 0.1,
|
||||||
|
value: sel.diameter,
|
||||||
|
onInput: () => {
|
||||||
|
sel.diameter = Number(dSlider.value);
|
||||||
|
dLabel.textContent = `Diameter (${sel.diameter.toFixed(1)} m)`;
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const lLabel = h("span", {}, `Length (${sel.length.toFixed(1)} m)`);
|
||||||
|
const lSlider = h("input", {
|
||||||
|
type: "range",
|
||||||
|
class: "slider",
|
||||||
|
min: 0.4,
|
||||||
|
max: 48.0,
|
||||||
|
step: 0.2,
|
||||||
|
value: sel.length,
|
||||||
|
onInput: () => {
|
||||||
|
sel.length = Number(lSlider.value);
|
||||||
|
lLabel.textContent = `Length (${sel.length.toFixed(1)} m)`;
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const symRow = h(
|
||||||
|
"div",
|
||||||
|
{ class: "row", style: { gap: "4px", flexWrap: "wrap" } },
|
||||||
|
...([1, 2, 3, 4, 6, 8] as const).map((sym) =>
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: `btn xs ${sel.symmetry === sym ? "selected" : "ghost"}`,
|
||||||
|
onClick: () => {
|
||||||
|
sel.symmetry = sym;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
`${sym}×`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const extraControls: Array<HTMLElement | null> = [];
|
||||||
|
if (sel.role === "tank") {
|
||||||
|
const fValEl = h(
|
||||||
|
"span",
|
||||||
|
{ class: "mono dim" },
|
||||||
|
`(${Math.round((sel.propellantFill ?? 1) * 100)}%)`,
|
||||||
|
);
|
||||||
|
const fLabel = h(
|
||||||
|
"span",
|
||||||
|
{ class: "row", style: { gap: "4px" } },
|
||||||
|
term("Propellant Fill", "fill_ratio"),
|
||||||
|
fValEl,
|
||||||
|
);
|
||||||
|
const fSlider = h("input", {
|
||||||
|
type: "range",
|
||||||
|
class: "slider",
|
||||||
|
min: 0.2,
|
||||||
|
max: 1.0,
|
||||||
|
step: 0.05,
|
||||||
|
value: sel.propellantFill ?? 1.0,
|
||||||
|
onInput: () => {
|
||||||
|
sel.propellantFill = Number(fSlider.value);
|
||||||
|
fValEl.textContent = `(${Math.round((sel.propellantFill ?? 1) * 100)}%)`;
|
||||||
|
ctx.refreshEngineering(false, false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
extraControls.push(h("label", { class: "field" }, fLabel, fSlider));
|
||||||
|
const dropChk = h("input", {
|
||||||
|
type: "checkbox",
|
||||||
|
checked: !!sel.isDropTank,
|
||||||
|
onChange: () => {
|
||||||
|
sel.isDropTank = dropChk.checked || undefined;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
extraControls.push(
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{
|
||||||
|
class: "row",
|
||||||
|
style: { cursor: "pointer", fontSize: "11px", marginTop: "4px" },
|
||||||
|
},
|
||||||
|
dropChk,
|
||||||
|
term("External Drop Tank (Crossfeed Jettison)", "crossfeed"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
sel.role === "tank" ||
|
||||||
|
sel.role === "structure" ||
|
||||||
|
sel.role === "interstage"
|
||||||
|
) {
|
||||||
|
const mSel = h(
|
||||||
|
"select",
|
||||||
|
{
|
||||||
|
class: "input",
|
||||||
|
onChange: () => {
|
||||||
|
sel.materialId = mSel.value;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...state.materials.map((m) =>
|
||||||
|
h(
|
||||||
|
"option",
|
||||||
|
{ value: m.id, selected: m.id === sel.materialId },
|
||||||
|
`${m.name} (${m.yieldStrengthMPa} MPa)${lockTag(m.id)}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
extraControls.push(
|
||||||
|
h(
|
||||||
|
"label",
|
||||||
|
{ class: "field" },
|
||||||
|
term("Structural Material", "airframe_material"),
|
||||||
|
mSel,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const inspector = h(
|
||||||
|
"div",
|
||||||
|
{ class: "stage-card active" },
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "spread" },
|
||||||
|
h("h3", {}, `Inspector // ${sel.role.toUpperCase()}`),
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row" },
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs ghost",
|
||||||
|
onClick: () => {
|
||||||
|
const clone: ProPlacedPart = {
|
||||||
|
...structuredClone(sel),
|
||||||
|
uid: `pro-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 5)}`,
|
||||||
|
yBottom: Number((sel.yBottom + sel.length).toFixed(2)),
|
||||||
|
};
|
||||||
|
partsList.push(clone);
|
||||||
|
ctx.selectedProUid = clone.uid;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderTierAndTabs();
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Duplicate",
|
||||||
|
),
|
||||||
|
partsList.length > 1
|
||||||
|
? h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs danger",
|
||||||
|
onClick: () => {
|
||||||
|
const i = partsList.findIndex((x) => x.uid === sel.uid);
|
||||||
|
if (i >= 0) partsList.splice(i, 1);
|
||||||
|
ctx.selectedProUid = partsList[0]?.uid ?? null;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderTierAndTabs();
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Delete",
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
h("label", { class: "field" }, "Component Model", roleModelSel),
|
||||||
|
h("label", { class: "field" }, "Stage Assignment", stageSel),
|
||||||
|
h("label", { class: "field" }, yLabel, ySlider),
|
||||||
|
h("label", { class: "field" }, rLabel, rSlider),
|
||||||
|
h("label", { class: "field" }, angLabel, angSlider),
|
||||||
|
h("div", { class: "field" }, h("span", {}, "Radial Symmetry"), symRow),
|
||||||
|
h("label", { class: "field" }, dLabel, dSlider),
|
||||||
|
h("label", { class: "field" }, lLabel, lSlider),
|
||||||
|
...extraControls,
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
{ class: "row", style: { marginTop: "6px" } },
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs ghost grow",
|
||||||
|
onClick: () => {
|
||||||
|
sel.radialOffset = 0;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Snap Centerline (R=0)",
|
||||||
|
),
|
||||||
|
h(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
class: "btn xs ghost grow",
|
||||||
|
onClick: () => {
|
||||||
|
const below = partsList
|
||||||
|
.filter(
|
||||||
|
(x) =>
|
||||||
|
x.uid !== sel.uid &&
|
||||||
|
Math.abs(x.radialOffset - sel.radialOffset) < 1.2 &&
|
||||||
|
x.yBottom + x.length <= sel.yBottom + sel.length + 0.5,
|
||||||
|
)
|
||||||
|
.sort((a, b) => b.yBottom + b.length - (a.yBottom + a.length))[0];
|
||||||
|
sel.yBottom = below
|
||||||
|
? Number((below.yBottom + below.length).toFixed(2))
|
||||||
|
: 0;
|
||||||
|
ctx.refreshEngineering(false, true);
|
||||||
|
ctx.renderSidebarBody();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Snap Down Flush",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
bodyEl.appendChild(inspector);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue