芯级居中左右均分助推器,箭体与发动机仪表圈按直径比绘制,栅格翼改画在助推器顶部
parent
fc749505a5
commit
f241a49936
|
|
@ -22,36 +22,48 @@ class RocketStage(BaseModel):
|
|||
fuel_mass_kg: float = Field(gt=0)
|
||||
max_thrust_n: float = Field(gt=0)
|
||||
specific_impulse_s: float = Field(gt=0)
|
||||
engine_count: int = Field(gt=0)
|
||||
engine_count: int = Field(ge=0, description="本级发动机数量;一级的这里是芯级自己的台数,不含助推器")
|
||||
length_ratio: float = Field(gt=0, le=1)
|
||||
|
||||
|
||||
class RocketAppearance(BaseModel):
|
||||
"""3D 外观构型(可选)。留空的字段由前端按公开资料通用规律推断。"""
|
||||
"""纯外观特征(可选):只登记无法从参数推导的特征件。
|
||||
|
||||
构型(助推器数量、各自的发动机数量与直径)一律在 boosters 里登记,
|
||||
这里不重复存放,否则同一件事会有两处数值。
|
||||
"""
|
||||
|
||||
booster_count: int | None = Field(default=None, ge=0, le=8, description="捆绑助推器/侧芯级数量,0 为单芯级")
|
||||
engines_per_booster: int | None = Field(default=None, ge=1, le=33, description="每个助推器的发动机数量")
|
||||
core_engine_count: int | None = Field(
|
||||
default=None, ge=1, le=33, description="芯级一级发动机数量;stage_1.engine_count 仍是含助推器的总数"
|
||||
)
|
||||
booster_diameter_ratio: float | None = Field(default=None, gt=0, le=1, description="助推器直径 / 芯级直径")
|
||||
grid_fins: bool | None = Field(default=None, description="一级顶部栅格翼(回收构型)")
|
||||
fairing: bool | None = Field(default=None, description="是否有载荷整流罩;false 表示二级自身带头锥与襟翼(星舰)")
|
||||
|
||||
|
||||
class RocketBoosters(BaseModel):
|
||||
"""捆绑助推器组合参数(可选)。
|
||||
"""捆绑助推器组(可选):数量、发动机、直径比与推进参数都登记在助推器自己身上。
|
||||
|
||||
口径与一级一致,但只统计助推器这一组:thrust_n / dry_mass_kg / fuel_mass_kg 都是
|
||||
全部助推器加起来的合计值。芯级 = stage_1 减去本组,因此不会有两套数字互相矛盾;
|
||||
助推器比冲单独登记,芯级比冲沿用 stage_1.specific_impulse_s。
|
||||
stage_1 自此只描述芯级,起飞推力 = stage_1.max_thrust_n + boosters.thrust_n,
|
||||
不再用「一级合计减去助推器」的口径。
|
||||
推进参数(推力 / 比冲 / 干重 / 推进剂)要么整体登记、要么整体留空:
|
||||
留空表示该型号的助推器只登记了构型(用于绘制外形),物理仍按一级整段计算。
|
||||
"""
|
||||
|
||||
count: int = Field(ge=1, le=8, description="助推器数量")
|
||||
thrust_n: float = Field(gt=0, description="全部助推器合计推力,不含芯级")
|
||||
specific_impulse_s: float = Field(gt=0, description="助推器比冲;芯级比冲取 stage_1")
|
||||
dry_mass_kg: float = Field(gt=0, description="全部助推器合计干重")
|
||||
fuel_mass_kg: float = Field(gt=0, description="全部助推器合计推进剂")
|
||||
engine_count: int = Field(ge=1, le=33, description="每台助推器的发动机数量")
|
||||
diameter_ratio: float | None = Field(
|
||||
default=None, gt=0, le=1, description="助推器直径 / 芯级直径,留空按 0.45 绘制"
|
||||
)
|
||||
thrust_n: float | None = Field(default=None, gt=0, description="全部助推器合计推力")
|
||||
specific_impulse_s: float | None = Field(default=None, gt=0, description="助推器比冲")
|
||||
dry_mass_kg: float | None = Field(default=None, gt=0, description="全部助推器合计干重")
|
||||
fuel_mass_kg: float | None = Field(default=None, gt=0, description="全部助推器合计推进剂")
|
||||
|
||||
@model_validator(mode="after")
|
||||
def physics_all_or_none(self) -> "RocketBoosters":
|
||||
given = [name for name in BOOSTER_PHYSICS_FIELDS if getattr(self, name) is not None]
|
||||
if given and len(given) != len(BOOSTER_PHYSICS_FIELDS):
|
||||
raise ValueError(
|
||||
"助推器推进参数必须整体登记或整体留空(留空表示仅登记构型)"
|
||||
)
|
||||
return self
|
||||
|
||||
|
||||
class RocketBase(BaseModel):
|
||||
|
|
@ -86,28 +98,12 @@ class RocketBase(BaseModel):
|
|||
def normalize_code(cls, value: str) -> str:
|
||||
return value.strip().lower()
|
||||
|
||||
@model_validator(mode="after")
|
||||
def boosters_within_stage1(self) -> "RocketBase":
|
||||
"""助推器是一级的子集,否则一级数据自相矛盾(分离时会算出负推力/负质量)。"""
|
||||
check_boosters_within_stage1(self.stage_1, self.boosters)
|
||||
return self
|
||||
|
||||
|
||||
class RocketCreate(RocketBase):
|
||||
pass
|
||||
|
||||
|
||||
def check_boosters_within_stage1(stage_1: RocketStage | None, boosters: RocketBoosters | None) -> None:
|
||||
if stage_1 is None or boosters is None:
|
||||
return
|
||||
pairs = (
|
||||
("boosters.thrust_n", boosters.thrust_n, stage_1.max_thrust_n),
|
||||
("boosters.dry_mass_kg", boosters.dry_mass_kg, stage_1.dry_mass_kg),
|
||||
("boosters.fuel_mass_kg", boosters.fuel_mass_kg, stage_1.fuel_mass_kg),
|
||||
)
|
||||
for name, value, total in pairs:
|
||||
if value > total:
|
||||
raise ValueError(f"{name} 不能大于 stage_1 的对应值({value:g} > {total:g})")
|
||||
BOOSTER_PHYSICS_FIELDS = ("thrust_n", "specific_impulse_s", "dry_mass_kg", "fuel_mass_kg")
|
||||
|
||||
|
||||
class RocketUpdate(BaseModel):
|
||||
|
|
@ -142,12 +138,6 @@ class RocketUpdate(BaseModel):
|
|||
def normalize_code(cls, value: str | None) -> str | None:
|
||||
return value.strip().lower() if value else value
|
||||
|
||||
@model_validator(mode="after")
|
||||
def boosters_within_stage1(self) -> "RocketUpdate":
|
||||
# 只改 boosters 不改 stage_1 时无法交叉校验,交给前端与预置保证口径
|
||||
check_boosters_within_stage1(self.stage_1, self.boosters)
|
||||
return self
|
||||
|
||||
|
||||
class RocketResponse(RocketBase):
|
||||
id: int
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ async def lifespan(app: FastAPI):
|
|||
from app.services.rocket_preset_service import (
|
||||
ensure_high_frequency_rockets,
|
||||
ensure_rocket_appearance,
|
||||
ensure_rocket_boosters,
|
||||
ensure_booster_groups,
|
||||
)
|
||||
from app.services.rocket_event_service import ensure_launch_event_job
|
||||
from app.services.menu_service import ensure_admin_menus
|
||||
|
|
@ -95,8 +95,8 @@ async def lifespan(app: FastAPI):
|
|||
added_rockets = await ensure_high_frequency_rockets(db)
|
||||
# 早已入库的预置型号补写外观构型(管理端填过的不动)
|
||||
await ensure_rocket_appearance(db)
|
||||
# 捆绑助推器型号拆分助推器口径(要在外观预置之后,才能顺带修正外观发动机数)
|
||||
boosted = await ensure_rocket_boosters(db)
|
||||
# 助推器口径统一:发动机数量各归各位(要在外观预置之后,旧的发动机数藏在 appearance 里)
|
||||
boosted = await ensure_booster_groups(db)
|
||||
await ensure_launch_event_job(db)
|
||||
# 补插新增后台页面所需的菜单(本次:火箭发射事件)
|
||||
new_menus = await ensure_admin_menus(db)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@
|
|||
已存在的型号一律不动(管理端改过的参数以管理端为准),被删掉的型号会在下次
|
||||
启动时重新补上(与默认系统设置的行为一致)。
|
||||
|
||||
stage_1 沿用库里既有约定:捆绑助推器的发动机数量与推力并入一级登记
|
||||
(长征五号 10 台 = 芯级 2 台 + 4 个助推器各 2 台)。
|
||||
发动机数量各归各位:stage_1.engine_count 是芯级自己的台数,
|
||||
捆绑助推器的数量、每台的发动机数与直径登记在 boosters 里
|
||||
(长征五号 = 芯级 2 台 YF-77 + boosters{count: 4, engine_count: 2})。
|
||||
"""
|
||||
import logging
|
||||
from typing import Any
|
||||
|
|
@ -118,12 +119,12 @@ HIGH_FREQUENCY_ROCKETS: list[dict[str, Any]] = [
|
|||
"separation_delay_seconds": 2.5,
|
||||
"second_stage_ignition_delay_seconds": 1.2,
|
||||
"stage_1": {
|
||||
"name": "芯一级与四个助推器",
|
||||
"dry_mass_kg": 50000,
|
||||
"fuel_mass_kg": 340000,
|
||||
"max_thrust_n": 5958000,
|
||||
"name": "芯一级(4 台 YF-100)",
|
||||
"dry_mass_kg": 38000,
|
||||
"fuel_mass_kg": 190000,
|
||||
"max_thrust_n": 2979000,
|
||||
"specific_impulse_s": 264,
|
||||
"engine_count": 8,
|
||||
"engine_count": 4,
|
||||
"length_ratio": 0.6,
|
||||
},
|
||||
"stage_2": {
|
||||
|
|
@ -157,12 +158,12 @@ HIGH_FREQUENCY_ROCKETS: list[dict[str, Any]] = [
|
|||
"separation_delay_seconds": 2.5,
|
||||
"second_stage_ignition_delay_seconds": 1.2,
|
||||
"stage_1": {
|
||||
"name": "芯一级与四个助推器(10 台 YF-100)",
|
||||
"dry_mass_kg": 40000,
|
||||
"fuel_mass_kg": 470000,
|
||||
"max_thrust_n": 7200000,
|
||||
"name": "芯一级(2 台 YF-100)",
|
||||
"dry_mass_kg": 20000,
|
||||
"fuel_mass_kg": 270000,
|
||||
"max_thrust_n": 2484000,
|
||||
"specific_impulse_s": 300,
|
||||
"engine_count": 10,
|
||||
"engine_count": 2,
|
||||
"length_ratio": 0.62,
|
||||
},
|
||||
"stage_2": {
|
||||
|
|
@ -196,12 +197,12 @@ HIGH_FREQUENCY_ROCKETS: list[dict[str, Any]] = [
|
|||
"separation_delay_seconds": 2.2,
|
||||
"second_stage_ignition_delay_seconds": 1.0,
|
||||
"stage_1": {
|
||||
"name": "芯一级与四台固体助推器",
|
||||
"name": "芯一级(2 台 YF-100)",
|
||||
"dry_mass_kg": 45000,
|
||||
"fuel_mass_kg": 405000,
|
||||
"max_thrust_n": 6400000,
|
||||
"specific_impulse_s": 285,
|
||||
"engine_count": 10,
|
||||
"engine_count": 2,
|
||||
"length_ratio": 0.6,
|
||||
},
|
||||
"stage_2": {
|
||||
|
|
@ -235,12 +236,12 @@ HIGH_FREQUENCY_ROCKETS: list[dict[str, Any]] = [
|
|||
"separation_delay_seconds": 2.2,
|
||||
"second_stage_ignition_delay_seconds": 1.0,
|
||||
"stage_1": {
|
||||
"name": "芯一级与两个助推器(6 台 YF-100)",
|
||||
"dry_mass_kg": 38000,
|
||||
"fuel_mass_kg": 380000,
|
||||
"max_thrust_n": 7194000,
|
||||
"name": "芯一级(2 台 YF-100)",
|
||||
"dry_mass_kg": 26000,
|
||||
"fuel_mass_kg": 215000,
|
||||
"max_thrust_n": 2398000,
|
||||
"specific_impulse_s": 300,
|
||||
"engine_count": 6,
|
||||
"engine_count": 2,
|
||||
"length_ratio": 0.6,
|
||||
},
|
||||
"stage_2": {
|
||||
|
|
@ -274,12 +275,12 @@ HIGH_FREQUENCY_ROCKETS: list[dict[str, Any]] = [
|
|||
"separation_delay_seconds": 2.2,
|
||||
"second_stage_ignition_delay_seconds": 1.0,
|
||||
"stage_1": {
|
||||
"name": "三芯级(27 台梅林 1D)",
|
||||
"dry_mass_kg": 76800,
|
||||
"fuel_mass_kg": 1233000,
|
||||
"max_thrust_n": 22821000,
|
||||
"name": "中心级(9 台梅林 1D)",
|
||||
"dry_mass_kg": 25600,
|
||||
"fuel_mass_kg": 453000,
|
||||
"max_thrust_n": 7607000,
|
||||
"specific_impulse_s": 282,
|
||||
"engine_count": 27,
|
||||
"engine_count": 9,
|
||||
"length_ratio": 0.65,
|
||||
},
|
||||
"stage_2": {
|
||||
|
|
@ -295,67 +296,99 @@ HIGH_FREQUENCY_ROCKETS: list[dict[str, Any]] = [
|
|||
]
|
||||
|
||||
|
||||
# 外观构型预置:按 code 登记,与型号参数定义分开,因此用户手工登记的型号
|
||||
# (联盟 2、阿丽亚娜 6)也能在这里补齐构型。仅在库里 appearance 仍为空时写入,
|
||||
# 管理端填过的值不会被动。联盟 2 = 4 个侧级各 1 台 + 芯级 1 台;
|
||||
# 阿丽亚娜 6(A62)= 2 个 P120 固体助推各 1 台 + 芯级 2 台。
|
||||
# 外观特征预置:按 code 登记,与型号参数定义分开,因此用户手工登记的型号
|
||||
# (联盟 2、阿丽亚娜 6)也能在这里补齐特征件。仅在库里缺这个 key 时写入,
|
||||
# 管理端填过的值不会被动。助推器构型不在这里登记,见 ROCKET_BOOSTERS。
|
||||
ROCKET_APPEARANCES: dict[str, dict[str, Any]] = {
|
||||
"starship": {"booster_count": 0, "grid_fins": True, "fairing": False},
|
||||
"electron": {"booster_count": 0, "grid_fins": False},
|
||||
"starship": {"grid_fins": True, "fairing": False},
|
||||
"electron": {"grid_fins": False},
|
||||
"falcon-heavy": {"grid_fins": True},
|
||||
"long-march-2f": {"grid_fins": False},
|
||||
"long-march-7": {"grid_fins": False},
|
||||
"long-march-6a": {"grid_fins": False},
|
||||
"long-march-8": {"grid_fins": False},
|
||||
"soyuz-2": {"grid_fins": False},
|
||||
"ariane-6": {"grid_fins": False},
|
||||
}
|
||||
|
||||
# 助推器组预置:数量、每台的发动机数、直径比与推进参数都登记在助推器自己身上。
|
||||
# 数值都是助推器这一组的合计口径(不含芯级),芯级参数在 stage_1 里,两者相加才是起飞值。
|
||||
# 说明几点口径选择:
|
||||
# - 固体助推器登记的是平均推力(P120C 峰值 4.46 MN、平均 3.5 MN),模拟为等推力,
|
||||
# 用平均推力才能烧出真实的助推器工作时间;
|
||||
# - 猎鹰重型侧芯级与中心级是同款 F9 一级,但侧芯级提前几秒关机(省推进剂返场),
|
||||
# 因此助推器推进剂登记得比单枚一级少,中心级余量更多,分离与 MECO 时序才对得上;
|
||||
# - 助推器粗细登记为直径比(助推器直径 / 芯级直径):长征五号与长征七号 / 八号都是
|
||||
# 0.67(3.35/5.0、2.25/3.35)、猎鹰重型 1.0(三枚同款一级等粗)、联盟 2 的侧级 0.91,
|
||||
# 留空则按 0.45 推断。用比值而不是米数,箭体改粗时不会连带失真。
|
||||
ROCKET_BOOSTERS: dict[str, dict[str, Any]] = {
|
||||
# 两枚 F9 一级作侧芯级:2×7.607 MN、2×25.6 t 干重、各 9 台梅林
|
||||
"falcon-heavy": {
|
||||
"booster_count": 2,
|
||||
"engines_per_booster": 9,
|
||||
"core_engine_count": 9,
|
||||
"booster_diameter_ratio": 1.0,
|
||||
"grid_fins": True,
|
||||
"count": 2, "engine_count": 9, "diameter_ratio": 1.0,
|
||||
"thrust_n": 15214000, "specific_impulse_s": 282, "dry_mass_kg": 51200, "fuel_mass_kg": 780000,
|
||||
},
|
||||
# 4 枚 3.35 m 助推器,各 2 台 YF-100、推进剂 142.8 t、干重 13.8 t
|
||||
"long-march-5": {
|
||||
"count": 4, "engine_count": 2, "diameter_ratio": 0.67,
|
||||
"thrust_n": 9600000, "specific_impulse_s": 300, "dry_mass_kg": 55200, "fuel_mass_kg": 571200,
|
||||
},
|
||||
# 联盟 2 的四个侧级(Blok B/V/G/D),各 1 台 RD-107
|
||||
"soyuz-2": {
|
||||
"count": 4, "engine_count": 1, "diameter_ratio": 0.91,
|
||||
"thrust_n": 3352000, "specific_impulse_s": 255, "dry_mass_kg": 12000, "fuel_mass_kg": 166000,
|
||||
},
|
||||
# 长征二号 F:4 个 2.25 m 助推器各 1 台 YF-100,芯级 4 台
|
||||
"long-march-2f": {
|
||||
"booster_count": 4,
|
||||
"engines_per_booster": 1,
|
||||
"core_engine_count": 4,
|
||||
"booster_diameter_ratio": 0.67,
|
||||
"grid_fins": False,
|
||||
"count": 4, "engine_count": 1, "diameter_ratio": 0.67,
|
||||
"thrust_n": 2979000, "specific_impulse_s": 263, "dry_mass_kg": 12000, "fuel_mass_kg": 150000,
|
||||
},
|
||||
# 长征七号:4 个 2.25 m 助推器各 1 台 YF-100,芯级 2 台
|
||||
"long-march-7": {
|
||||
"booster_count": 4,
|
||||
"engines_per_booster": 2,
|
||||
"core_engine_count": 2,
|
||||
"booster_diameter_ratio": 0.67,
|
||||
"grid_fins": False,
|
||||
},
|
||||
"long-march-6a": {
|
||||
"booster_count": 4,
|
||||
"engines_per_booster": 2,
|
||||
"core_engine_count": 2,
|
||||
"booster_diameter_ratio": 0.79,
|
||||
"grid_fins": False,
|
||||
"count": 4, "engine_count": 1, "diameter_ratio": 0.67,
|
||||
"thrust_n": 4716000, "specific_impulse_s": 300, "dry_mass_kg": 20000, "fuel_mass_kg": 200000,
|
||||
},
|
||||
"long-march-8": {
|
||||
"booster_count": 2,
|
||||
"engines_per_booster": 2,
|
||||
"core_engine_count": 2,
|
||||
"booster_diameter_ratio": 0.67,
|
||||
"grid_fins": False,
|
||||
},
|
||||
"soyuz-2": {
|
||||
"booster_count": 4,
|
||||
"engines_per_booster": 1,
|
||||
"core_engine_count": 1,
|
||||
"booster_diameter_ratio": 0.75,
|
||||
"grid_fins": False,
|
||||
},
|
||||
"ariane-6": {
|
||||
"booster_count": 2,
|
||||
"engines_per_booster": 1,
|
||||
"core_engine_count": 2,
|
||||
"booster_diameter_ratio": 0.56,
|
||||
"grid_fins": False,
|
||||
"count": 2, "engine_count": 2, "diameter_ratio": 0.67,
|
||||
"thrust_n": 4796000, "specific_impulse_s": 300, "dry_mass_kg": 12000, "fuel_mass_kg": 165000,
|
||||
},
|
||||
}
|
||||
|
||||
# 只登记构型、不登记推进参数的助推器:这两个型号的公开推力口径互相矛盾
|
||||
# (阿丽亚娜 6 的一级整体就是 P120C 组合,长征六号甲的芯级推力各家说法不一),
|
||||
# 强行拆分会算出撑不起起飞的芯级推重比,因此推进参数留空 ——
|
||||
# 物理仍按一级整段计算,boosters 只决定「画几个助推器、每个几台机、多粗」。
|
||||
ROCKET_BOOSTER_GEOMETRY: dict[str, dict[str, Any]] = {
|
||||
# 阿丽亚娜 6:一级 = 4 枚 P120C,没有液体芯级,因此 stage_1.engine_count 记 0
|
||||
"ariane-6": {"count": 4, "engine_count": 1, "diameter_ratio": 0.56},
|
||||
# 长征六号甲:芯一级 2 台 YF-100 + 4 台固体助推器
|
||||
"long-march-6a": {"count": 4, "engine_count": 2, "diameter_ratio": 0.75},
|
||||
}
|
||||
|
||||
# 阿丽亚娜 6 的一级本身就是助推器组合,改写口径后芯级没有发动机
|
||||
LEGACY_STAGE1_CORE_ENGINES = {"ariane-6": 0}
|
||||
|
||||
# 预置里的 stage_1.engine_count 已是芯级口径,改口径时优先取它:
|
||||
# 「一级总数减去助推器」要靠旧数据里的每台机数,而早期预置的长征七号把每台助推器
|
||||
# 记成 2 台 YF-100(真实是 1 台),减法会凭空多出 4 台芯级发动机。
|
||||
PRESET_STAGE1_CORE_ENGINES = {r["code"]: int(r["stage_1"]["engine_count"]) for r in HIGH_FREQUENCY_ROCKETS}
|
||||
|
||||
# 旧口径把助推器机数与直径比藏在 appearance 里,改写后这些 key 全部作废
|
||||
LEGACY_APPEARANCE_KEYS = ("booster_count", "engines_per_booster", "core_engine_count", "booster_diameter_ratio")
|
||||
|
||||
# 一级从「含助推器」改写为「只有芯级」后,早期预置的级名会误导,顺带改正
|
||||
LEGACY_STAGE1_NAMES = {
|
||||
"falcon-heavy": "中心级(9 台梅林 1D)",
|
||||
"long-march-5": "芯一级(2 台 YF-77)",
|
||||
"long-march-2f": "芯一级(4 台 YF-100)",
|
||||
"long-march-7": "芯一级(2 台 YF-100)",
|
||||
"long-march-8": "芯一级(2 台 YF-100)",
|
||||
"soyuz-2": "芯级(RD-108)",
|
||||
"long-march-6a": "芯一级(2 台 YF-100)",
|
||||
}
|
||||
|
||||
|
||||
async def ensure_rocket_appearance(db: AsyncSession) -> list[str]:
|
||||
"""按 ROCKET_APPEARANCES 补写外观构型。
|
||||
"""按 ROCKET_APPEARANCES 补写外观特征件。
|
||||
|
||||
型号预置只补插缺失的型号,早已入库的型号不会带上 appearance,因此这里做一次
|
||||
幂等回填:逐字段补齐库里还没有的 key,管理端填过的值(含显式 null)一律不动。
|
||||
|
|
@ -388,62 +421,17 @@ async def ensure_rocket_appearance(db: AsyncSession) -> list[str]:
|
|||
return updated
|
||||
|
||||
|
||||
# 助推器组合预置:公开资料近似值,用于把「捆绑助推器」从一级里拆出来单独计量。
|
||||
# 数值都是一级里属于助推器的那一部分(合计口径),芯级由 stage_1 减去本组得到。
|
||||
# 说明几点口径选择:
|
||||
# - 固体助推器登记的是平均推力(P120C 峰值 4.46 MN、平均 3.5 MN),模拟为等推力,
|
||||
# 用平均推力才能烧出真实的助推器工作时间;
|
||||
# - 猎鹰重型侧芯级与中心级是同款 F9 一级,但侧芯级提前几秒关机(省推进剂返场),
|
||||
# 因此助推器推进剂登记得比单枚一级少,中心级余量更多,分离与 MECO 时序才对得上;
|
||||
# - 芯级比冲沿用 stage_1.specific_impulse_s(登记的是整段一级的有效比冲)。
|
||||
ROCKET_BOOSTERS: dict[str, dict[str, Any]] = {
|
||||
# 两枚 F9 一级作侧芯级:2×7.607 MN、2×25.6 t 干重
|
||||
"falcon-heavy": {"count": 2, "thrust_n": 15214000, "specific_impulse_s": 282, "dry_mass_kg": 51200, "fuel_mass_kg": 780000},
|
||||
# 4 枚 3.35 m 助推器,各 2 台 YF-100、推进剂 142.8 t、干重 13.8 t
|
||||
"long-march-5": {"count": 4, "thrust_n": 9600000, "specific_impulse_s": 300, "dry_mass_kg": 55200, "fuel_mass_kg": 571200},
|
||||
# 联盟 2 的四个侧级(Blok B/V/G/D),各 1 台 RD-107
|
||||
"soyuz-2": {"count": 4, "thrust_n": 3352000, "specific_impulse_s": 255, "dry_mass_kg": 12000, "fuel_mass_kg": 166000},
|
||||
# 长征二号 F:4 个助推器各 1 台,与芯级 4 台各占一半推力
|
||||
"long-march-2f": {"count": 4, "thrust_n": 2979000, "specific_impulse_s": 263, "dry_mass_kg": 12000, "fuel_mass_kg": 150000},
|
||||
# 长征七号:4 个 2.25 m 助推器各 1 台 YF-100(1.179 MN),芯级 2 台
|
||||
"long-march-7": {"count": 4, "thrust_n": 4716000, "specific_impulse_s": 300, "dry_mass_kg": 20000, "fuel_mass_kg": 200000},
|
||||
"long-march-8": {"count": 2, "thrust_n": 4796000, "specific_impulse_s": 300, "dry_mass_kg": 12000, "fuel_mass_kg": 165000},
|
||||
}
|
||||
async def ensure_booster_groups(db: AsyncSession) -> list[str]:
|
||||
"""把助推器登记统一成「助推器自己带发动机」的口径,并按预置补齐缺失的助推器组。
|
||||
|
||||
# 两个型号有意不登记 boosters:
|
||||
# - ariane-6:它的一级本来就是 P120C 助推器组,主级在 stage_2,再拆一次会把芯级算两遍;
|
||||
# - long-march-6a:公开推力口径互相矛盾(登记值里大部分发动机在助推器上),
|
||||
# 拆分后芯级推重比不足,在本简化弹道模型里无法维持飞行。
|
||||
|
||||
# 一级口径修正:早期预置把「助推器推力 + 芯级推进剂」混在一起登记(长征五号一级
|
||||
# 只有芯级的 175 t 推进剂,却登记了含助推器的 10.6 MN 推力),拆分助推器之后必须
|
||||
# 统一成「一级合计」口径。只在库里仍是旧值且还没登记 boosters 时才改,
|
||||
# 管理端改过的型号一律不动。
|
||||
STAGE1_TOTAL_FIXES: dict[str, dict[str, Any]] = {
|
||||
"long-march-5": {
|
||||
"expect": {"dry_mass_kg": 38000, "fuel_mass_kg": 175000},
|
||||
"stage_1": {
|
||||
"name": "芯一级与四个助推器(YF-77×2 + YF-100×8)",
|
||||
"dry_mass_kg": 90000,
|
||||
"fuel_mass_kg": 736500,
|
||||
},
|
||||
},
|
||||
"long-march-7": {
|
||||
# 长征七号起飞用 6 台 YF-100(芯级 2 台 + 4 个助推器各 1 台),不是 10 台
|
||||
"expect": {"engine_count": 10},
|
||||
"stage_1": {"name": "芯一级与四个助推器(6 台 YF-100)", "engine_count": 6},
|
||||
"appearance": {"core_engine_count": 2, "engines_per_booster": 1},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
async def ensure_rocket_boosters(db: AsyncSession) -> list[str]:
|
||||
"""按 ROCKET_BOOSTERS 登记助推器组合,并顺带统一一级口径。
|
||||
|
||||
与外观预置一样是幂等回填:库里已经有 boosters 的型号(包括管理端自己填的)
|
||||
一律不动,因此一级口径修正也只会对旧数据执行一次。
|
||||
一次遍历处理三种行,处理过的行在下次启动时一律不再改动:
|
||||
1. boosters 里已有 engine_count → 已是新口径(含管理端自己填的),只清理旧的 appearance key;
|
||||
2. boosters 里没有 engine_count → 旧口径:机数藏在 appearance 里、一级是含助推器的合计。
|
||||
这里把芯级发动机数写回 stage_1、机数与直径写进 boosters,并把一级的
|
||||
推力 / 干重 / 推进剂减去助推器的量 —— 减法只发生在这条分支,且只会发生一次;
|
||||
3. 只在 appearance 里画过助推器、没有 boosters → 转成「仅构型」的 boosters,
|
||||
物理仍按一级整段计算。
|
||||
"""
|
||||
codes = set(ROCKET_BOOSTERS) | set(STAGE1_TOTAL_FIXES)
|
||||
column = await db.execute(
|
||||
text("SELECT 1 FROM information_schema.columns "
|
||||
"WHERE table_name = 'rocket_configs' AND column_name = 'boosters'")
|
||||
|
|
@ -451,51 +439,86 @@ async def ensure_rocket_boosters(db: AsyncSession) -> list[str]:
|
|||
if column.first() is None:
|
||||
logger.warning("rocket_configs.boosters 列不存在,跳过助推器参数回填(执行 upgrade_db.py --apply 后重启生效)")
|
||||
return []
|
||||
|
||||
codes = set(ROCKET_BOOSTERS) | set(ROCKET_BOOSTER_GEOMETRY) | set(ROCKET_APPEARANCES)
|
||||
result = await db.execute(select(RocketConfig).where(RocketConfig.code.in_(codes)))
|
||||
|
||||
updated: list[str] = []
|
||||
for rocket in result.scalars().all():
|
||||
if rocket.boosters:
|
||||
continue
|
||||
fix = STAGE1_TOTAL_FIXES.get(rocket.code)
|
||||
if fix:
|
||||
current = dict(rocket.stage_1 or {})
|
||||
if all(current.get(key) == value for key, value in fix["expect"].items()):
|
||||
current.update(fix["stage_1"])
|
||||
rocket.stage_1 = current
|
||||
appearance = dict(rocket.appearance or {})
|
||||
appearance.update(fix.get("appearance", {}))
|
||||
rocket.appearance = appearance
|
||||
logger.info("火箭 %s 一级口径已统一为含助推器的合计值:%s", rocket.code, fix["stage_1"])
|
||||
else:
|
||||
logger.info("火箭 %s 的一级参数已被修改过,跳过口径修正", rocket.code)
|
||||
preset = ROCKET_BOOSTERS.get(rocket.code)
|
||||
if not preset:
|
||||
continue
|
||||
# 口径修正没生效(管理端自己改过一级)时,助推器数值可能超出一级总量,
|
||||
# 这种自相矛盾的数据宁可不登记,也不能让模拟算出负推力
|
||||
stage1 = rocket.stage_1 or {}
|
||||
if not _boosters_fit_stage1(preset, stage1):
|
||||
logger.warning("火箭 %s 的助推器预置超出其一级的总量,跳过登记", rocket.code)
|
||||
continue
|
||||
rocket.boosters = dict(preset)
|
||||
updated.append(rocket.code)
|
||||
appearance = dict(rocket.appearance or {})
|
||||
legacy = {key: appearance.pop(key, None) for key in LEGACY_APPEARANCE_KEYS}
|
||||
boosters = dict(rocket.boosters) if rocket.boosters else {}
|
||||
stage_1 = dict(rocket.stage_1 or {})
|
||||
changed = False
|
||||
|
||||
if boosters and "engine_count" not in boosters:
|
||||
count = int(boosters["count"])
|
||||
# 机数与直径优先取预置里的真实值,取不到才回退旧的 appearance 推断值
|
||||
preset = ROCKET_BOOSTERS.get(rocket.code) or {}
|
||||
per_booster = int(preset.get("engine_count") or legacy.get("engines_per_booster") or 1)
|
||||
boosters["engine_count"] = per_booster
|
||||
ratio = preset.get("diameter_ratio") or legacy.get("booster_diameter_ratio")
|
||||
if ratio is not None:
|
||||
boosters["diameter_ratio"] = round(float(ratio), 2)
|
||||
core_engines = LEGACY_STAGE1_CORE_ENGINES.get(
|
||||
rocket.code, PRESET_STAGE1_CORE_ENGINES.get(rocket.code)
|
||||
)
|
||||
if core_engines is None:
|
||||
core_engines = max(0, int(stage_1.get("engine_count") or 0) - count * per_booster)
|
||||
stage_1["engine_count"] = core_engines
|
||||
for stage_key, booster_key in (
|
||||
("max_thrust_n", "thrust_n"),
|
||||
("dry_mass_kg", "dry_mass_kg"),
|
||||
("fuel_mass_kg", "fuel_mass_kg"),
|
||||
):
|
||||
stage_1[stage_key] = max(0.0, float(stage_1.get(stage_key) or 0) - float(boosters.get(booster_key) or 0))
|
||||
if rocket.code in LEGACY_STAGE1_NAMES:
|
||||
stage_1["name"] = LEGACY_STAGE1_NAMES[rocket.code]
|
||||
rocket.stage_1 = stage_1
|
||||
rocket.boosters = boosters
|
||||
changed = True
|
||||
logger.info("火箭 %s 的助推器改为独立登记:芯级 %s 台,助推器 %s×%s 台",
|
||||
rocket.code, core_engines, boosters["count"], boosters["engine_count"])
|
||||
elif not boosters:
|
||||
preset = ROCKET_BOOSTERS.get(rocket.code) or ROCKET_BOOSTER_GEOMETRY.get(rocket.code)
|
||||
if preset is None and legacy.get("booster_count"):
|
||||
# 旧数据里画过助推器但没有预置(用户自己登记的型号):按旧 appearance 的值转换
|
||||
preset = {
|
||||
"count": int(legacy["booster_count"]),
|
||||
"engine_count": int(legacy.get("engines_per_booster") or 1),
|
||||
"diameter_ratio": round(float(legacy["booster_diameter_ratio"] or 0.45), 2),
|
||||
}
|
||||
if preset:
|
||||
rocket.boosters = dict(preset)
|
||||
changed = True
|
||||
logger.info("火箭 %s 登记助推器组:%s", rocket.code, preset)
|
||||
# 一级的机数口径同样要从「含助推器」改成「只有芯级」,否则芯级和助推器会把
|
||||
# 同一批发动机画两遍;只在真的要登记助推器组时改写,取不到预置就退到旧
|
||||
# appearance 里的 core_engine_count
|
||||
core_engines = LEGACY_STAGE1_CORE_ENGINES.get(rocket.code)
|
||||
if core_engines is None and preset:
|
||||
core_engines = PRESET_STAGE1_CORE_ENGINES.get(rocket.code)
|
||||
if core_engines is None and preset and legacy.get("core_engine_count"):
|
||||
core_engines = int(legacy["core_engine_count"])
|
||||
renamed = rocket.code in LEGACY_STAGE1_NAMES and stage_1.get("name") != LEGACY_STAGE1_NAMES[rocket.code]
|
||||
if core_engines is not None and stage_1.get("engine_count") != core_engines:
|
||||
stage_1["engine_count"] = core_engines
|
||||
changed = True
|
||||
if renamed:
|
||||
stage_1["name"] = LEGACY_STAGE1_NAMES[rocket.code]
|
||||
changed = True
|
||||
if changed:
|
||||
rocket.stage_1 = stage_1
|
||||
|
||||
if changed or any(value is not None for value in legacy.values()):
|
||||
rocket.appearance = appearance
|
||||
updated.append(rocket.code)
|
||||
|
||||
if updated:
|
||||
await db.flush()
|
||||
logger.info("火箭助推器参数回填:%s", ", ".join(updated))
|
||||
logger.info("火箭助推器口径统一:%s", ", ".join(updated))
|
||||
return updated
|
||||
|
||||
|
||||
def _boosters_fit_stage1(boosters: dict[str, Any], stage_1: dict[str, Any]) -> bool:
|
||||
pairs = (
|
||||
("thrust_n", "max_thrust_n"),
|
||||
("dry_mass_kg", "dry_mass_kg"),
|
||||
("fuel_mass_kg", "fuel_mass_kg"),
|
||||
)
|
||||
return all((boosters.get(key) or 0) <= (stage_1.get(total) or 0) for key, total in pairs)
|
||||
|
||||
|
||||
async def ensure_high_frequency_rockets(db: AsyncSession) -> list[str]:
|
||||
"""补齐缺失的高频型号,返回新入库的 code 列表。"""
|
||||
existing = set((await db.execute(select(RocketConfig.code))).scalars().all())
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { useFrame } from '@react-three/fiber';
|
|||
import * as THREE from 'three';
|
||||
import type { RocketConfig, SimulationState } from './types';
|
||||
import {
|
||||
boosterAngle,
|
||||
engineLayout,
|
||||
engineState,
|
||||
separationAge,
|
||||
|
|
@ -193,7 +192,8 @@ function EnginePlume({
|
|||
active,
|
||||
running,
|
||||
nozzleY = 0,
|
||||
spread = 1,
|
||||
phase = 0,
|
||||
light = false,
|
||||
}: {
|
||||
radius: number;
|
||||
length: number;
|
||||
|
|
@ -201,7 +201,10 @@ function EnginePlume({
|
|||
active: boolean;
|
||||
running: boolean;
|
||||
nozzleY?: number;
|
||||
spread?: number;
|
||||
/** 闪烁相位:同一组发动机共用一个相位,整组看起来同步燃烧 */
|
||||
phase?: number;
|
||||
/** 是否自带照明灯(一组只需要一盏,否则 33 台机就是 33 盏实时灯) */
|
||||
light?: boolean;
|
||||
}) {
|
||||
const anchorRef = useRef<THREE.Group>(null);
|
||||
const lightRef = useRef<THREE.PointLight>(null);
|
||||
|
|
@ -209,13 +212,14 @@ function EnginePlume({
|
|||
|
||||
useFrame(({ clock }) => {
|
||||
if (!anchorRef.current || !running) return;
|
||||
const flicker = 0.88 + Math.sin(clock.elapsedTime * 42) * 0.08 + Math.random() * 0.05;
|
||||
// 两个不同频率的正弦叠加,比每帧随机数稳定,也不会让整箭火焰各闪各的
|
||||
const flicker = 0.9 + Math.sin(clock.elapsedTime * 42 + phase) * 0.07 + Math.sin(clock.elapsedTime * 17 + phase * 2) * 0.04;
|
||||
const stretch = flicker * (0.45 + throttle * 0.75);
|
||||
anchorRef.current.scale.set(0.8 + throttle * 0.3, stretch, 0.8 + throttle * 0.3);
|
||||
if (lightRef.current) lightRef.current.intensity = 6 + flicker * 4 * throttle;
|
||||
if (lightRef.current) lightRef.current.intensity = (6 + flicker * 4) * throttle;
|
||||
if (diamondRef.current) {
|
||||
diamondRef.current.children.forEach((child, index) => {
|
||||
const pulse = 0.65 + Math.sin(clock.elapsedTime * 30 + index * 1.3) * 0.35;
|
||||
const pulse = 0.65 + Math.sin(clock.elapsedTime * 30 + index * 1.3 + phase) * 0.35;
|
||||
child.scale.setScalar(0.7 + pulse * 0.5 * throttle);
|
||||
});
|
||||
}
|
||||
|
|
@ -227,7 +231,7 @@ function EnginePlume({
|
|||
<group ref={anchorRef} position={[0, nozzleY, 0]}>
|
||||
{/* 外层燃气 */}
|
||||
<mesh position={[0, -length * 0.95, 0]} rotation={[Math.PI, 0, 0]}>
|
||||
<coneGeometry args={[radius * 2.2 * spread, length * 1.9, 24, 1, true]} />
|
||||
<coneGeometry args={[radius * 2.2, length * 1.9, 24, 1, true]} />
|
||||
<meshBasicMaterial color="#ff7326" transparent opacity={0.26} blending={THREE.AdditiveBlending} depthWrite={false} side={THREE.DoubleSide} />
|
||||
</mesh>
|
||||
{/* 内层亮芯 */}
|
||||
|
|
@ -249,14 +253,61 @@ function EnginePlume({
|
|||
</mesh>
|
||||
))}
|
||||
</group>
|
||||
<pointLight
|
||||
ref={lightRef}
|
||||
color="#ff9a3c"
|
||||
intensity={8}
|
||||
distance={radius * 34}
|
||||
decay={2}
|
||||
position={[0, -length * 0.35, 0]}
|
||||
/>
|
||||
{light && (
|
||||
<pointLight
|
||||
ref={lightRef}
|
||||
color="#ff9a3c"
|
||||
intensity={8}
|
||||
distance={radius * 60}
|
||||
decay={2}
|
||||
position={[0, -length * 0.35, 0]}
|
||||
/>
|
||||
)}
|
||||
</group>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一组发动机的尾焰:喷管画几台就喷几团,机位与 EngineCluster 的喷管同源
|
||||
* (都取自 engineLayout),整组共用一个闪烁相位和一盏照明灯。
|
||||
* 芯级没有发动机时整组不画(阿丽亚娜 6 的一级就是助推器组合)。
|
||||
*/
|
||||
function EngineBankPlume({
|
||||
radius,
|
||||
count,
|
||||
nozzleY,
|
||||
throttle,
|
||||
active,
|
||||
running,
|
||||
seed = 0,
|
||||
}: {
|
||||
radius: number;
|
||||
count: number;
|
||||
nozzleY: number;
|
||||
throttle: number;
|
||||
active: boolean;
|
||||
running: boolean;
|
||||
/** 组间相位差:芯级与各助推器不要完全同频闪烁 */
|
||||
seed?: number;
|
||||
}) {
|
||||
const placements = useMemo(() => engineLayout(count, radius), [count, radius]);
|
||||
if (placements.length === 0) return null;
|
||||
return (
|
||||
<group>
|
||||
{placements.map((placement, index) => (
|
||||
<group key={index} position={[placement.x, 0, placement.z]}>
|
||||
<EnginePlume
|
||||
radius={placement.bellRadius * 1.25}
|
||||
length={Math.max(placement.bellLength * 6, radius * 2.6)}
|
||||
nozzleY={nozzleY - placement.bellLength}
|
||||
throttle={throttle}
|
||||
active={active}
|
||||
running={running}
|
||||
phase={seed * 1.7 + index * 0.53}
|
||||
light={index === 0}
|
||||
/>
|
||||
</group>
|
||||
))}
|
||||
</group>
|
||||
);
|
||||
}
|
||||
|
|
@ -296,7 +347,7 @@ function FirstStageBody({
|
|||
|
||||
<StringerRings radius={radius} height={height} count={3} />
|
||||
<Raceway radius={radius} height={height} />
|
||||
{gridFins && <GridFins radius={radius} y={height * 0.88} color={accent} />}
|
||||
{gridFins && <GridFins radius={radius} y={height * 0.95} color={accent} />}
|
||||
<BodyDecal
|
||||
radius={radius}
|
||||
height={height * 0.13}
|
||||
|
|
@ -313,24 +364,44 @@ function FirstStageBody({
|
|||
);
|
||||
}
|
||||
|
||||
/** 栅格翼:细长单芯级回收构型(猎鹰 9)靠近一级顶部的四片格栅。 */
|
||||
/**
|
||||
* 栅格翼:回收构型一级顶部的四片格栅(猎鹰 9 / 猎鹰重型 / 星舰一级)。
|
||||
* 真实栅格翼约 1.8m 见方、支臂外伸半个箭体直径,因此这里按箭体半径等比放大,
|
||||
* 用支臂 + 交叉格栅画出「一眼就知道能回收」的轮廓,而不是贴在箭体上的小盒子。
|
||||
*/
|
||||
function GridFins({ radius, y, color }: { radius: number; y: number; color: string }) {
|
||||
// 局部坐标系:+X 指向箭体径向外侧,+Z 为切向(见下面的 rotation)
|
||||
const span = radius * 1.7;
|
||||
const height = radius * 1.3;
|
||||
const thickness = radius * 0.13;
|
||||
const arm = radius * 0.8;
|
||||
return (
|
||||
<group position={[0, y, 0]}>
|
||||
{[0, 1, 2, 3].map((index) => {
|
||||
const angle = (index / 4) * Math.PI * 2 + Math.PI / 4;
|
||||
return (
|
||||
<group key={index} position={[Math.cos(angle) * radius, 0, Math.sin(angle) * radius]} rotation={[0, -angle, 0]}>
|
||||
{/* 翼盒 */}
|
||||
<mesh>
|
||||
<boxGeometry args={[radius * 0.72, radius * 0.5, radius * 0.12]} />
|
||||
<meshStandardMaterial color={color} metalness={0.6} roughness={0.45} />
|
||||
{/* 支臂 */}
|
||||
<mesh position={[arm * 0.5, 0, 0]} rotation={[0, 0, Math.PI / 2]}>
|
||||
<cylinderGeometry args={[radius * 0.09, radius * 0.11, arm, 10]} />
|
||||
<meshStandardMaterial color={shade(color, -0.2)} metalness={0.7} roughness={0.4} />
|
||||
</mesh>
|
||||
{/* 格栅叶片 */}
|
||||
{[-0.24, 0, 0.24].map((offset) => (
|
||||
<mesh key={offset} position={[offset * radius, 0, radius * 0.02]}>
|
||||
<boxGeometry args={[radius * 0.06, radius * 0.46, radius * 0.16]} />
|
||||
<meshStandardMaterial color={shade(color, -0.25)} metalness={0.7} roughness={0.35} />
|
||||
{/* 格栅外框 */}
|
||||
<mesh position={[arm + span * 0.5, 0, 0]} castShadow>
|
||||
<boxGeometry args={[span, height, thickness]} />
|
||||
<meshStandardMaterial color={shade(METAL, -0.05)} metalness={0.7} roughness={0.38} />
|
||||
</mesh>
|
||||
{/* 交叉格栅叶片 */}
|
||||
{[-0.33, 0, 0.33].map((offset) => (
|
||||
<mesh key={`v${offset}`} position={[arm + span * (0.5 + offset * 0.8), 0, 0]}>
|
||||
<boxGeometry args={[thickness * 0.8, height * 0.94, thickness * 2.1]} />
|
||||
<meshStandardMaterial color={shade(METAL, -0.45)} metalness={0.8} roughness={0.3} />
|
||||
</mesh>
|
||||
))}
|
||||
{[-0.3, 0.3].map((offset) => (
|
||||
<mesh key={`h${offset}`} position={[arm + span * 0.5, offset * height, 0]}>
|
||||
<boxGeometry args={[span * 0.96, thickness * 0.8, thickness * 2.1]} />
|
||||
<meshStandardMaterial color={shade(METAL, -0.45)} metalness={0.8} roughness={0.3} />
|
||||
</mesh>
|
||||
))}
|
||||
</group>
|
||||
|
|
@ -355,6 +426,7 @@ function StrapOnBooster({
|
|||
throttle,
|
||||
active,
|
||||
running,
|
||||
gridFins = false,
|
||||
}: {
|
||||
radius: number;
|
||||
height: number;
|
||||
|
|
@ -363,6 +435,7 @@ function StrapOnBooster({
|
|||
throttle: number;
|
||||
active: boolean;
|
||||
running: boolean;
|
||||
gridFins?: boolean;
|
||||
}) {
|
||||
const bodyRadius = radius * group.radius;
|
||||
const offset = radius * group.offset;
|
||||
|
|
@ -389,19 +462,21 @@ function StrapOnBooster({
|
|||
<cylinderGeometry args={[radius * 0.06, radius * 0.06, radius * 0.34, 10]} />
|
||||
<meshStandardMaterial color={DARK} metalness={0.6} roughness={0.45} />
|
||||
</mesh>
|
||||
{/* 栅格翼:并联构型下它长在助推器(回收的那一级)顶部 */}
|
||||
{gridFins && <GridFins radius={bodyRadius} y={height * 0.9} color={shade(color, -0.55)} />}
|
||||
{/* 助推器发动机舱:只画本机自己的喷管,不借用一级总数 */}
|
||||
<group position={[0, -bodyRadius * 0.08, 0]}>
|
||||
<EngineCluster radius={bodyRadius} count={group.engines} bellColor={shade(METAL, -0.15)} showActuators={false} />
|
||||
</group>
|
||||
{/* 助推器尾焰 */}
|
||||
<EnginePlume
|
||||
{/* 助推器尾焰:与上面的喷管一一对应,几台机就几团火 */}
|
||||
<EngineBankPlume
|
||||
radius={bodyRadius}
|
||||
length={bodyRadius * 10}
|
||||
nozzleY={-bodyRadius * 0.7}
|
||||
count={group.engines}
|
||||
nozzleY={-bodyRadius * 0.16}
|
||||
throttle={throttle}
|
||||
active={active}
|
||||
running={running}
|
||||
spread={1 + group.engines * 0.04}
|
||||
seed={group.angle}
|
||||
/>
|
||||
</group>
|
||||
);
|
||||
|
|
@ -746,7 +821,8 @@ export function RocketModel({ rocket, state }: RocketModelProps) {
|
|||
const visible = boosterAge < 3.2;
|
||||
boosterRef.current.visible = visible;
|
||||
boosterRef.current.children.forEach((child, index) => {
|
||||
const angle = boosterAngle(index, boosterRef.current!.children.length);
|
||||
// 沿各自的挂载角向外散开,与捆绑位置一致
|
||||
const angle = boosterGroups[index].angle;
|
||||
child.position.set(
|
||||
Math.cos(angle) * spread,
|
||||
-0.6 * boosterAge - 0.35 * boosterAge * boosterAge,
|
||||
|
|
@ -804,13 +880,14 @@ export function RocketModel({ rocket, state }: RocketModelProps) {
|
|||
label={secondStageLabel}
|
||||
/>
|
||||
{/* 二级尾焰:自二级喷管出口向下喷出 */}
|
||||
<EnginePlume
|
||||
radius={geo.radius * 0.7}
|
||||
length={geo.radius * 8}
|
||||
nozzleY={-geo.radius * 0.5}
|
||||
<EngineBankPlume
|
||||
radius={geo.radius * 0.97}
|
||||
count={geo.stage2Engines}
|
||||
nozzleY={-geo.radius * 0.32}
|
||||
throttle={state.throttle}
|
||||
active={engines.stage2}
|
||||
running={state.isRunning}
|
||||
seed={2.4}
|
||||
/>
|
||||
</group>
|
||||
|
||||
|
|
@ -881,7 +958,7 @@ export function RocketModel({ rocket, state }: RocketModelProps) {
|
|||
color={rocket.color}
|
||||
engineCount={geo.coreEngines}
|
||||
label={firstStageLabel}
|
||||
gridFins={geo.gridFins}
|
||||
gridFins={geo.gridFins && boosterGroups.length === 0}
|
||||
/>
|
||||
{/* 捆绑助推器:先于芯级分离,分离后向四周散开 */}
|
||||
{boosterGroups.length > 0 && (
|
||||
|
|
@ -896,19 +973,20 @@ export function RocketModel({ rocket, state }: RocketModelProps) {
|
|||
throttle={state.throttle}
|
||||
active={engines.stage1 && boosterAge === null}
|
||||
running={state.isRunning}
|
||||
gridFins={geo.gridFins}
|
||||
/>
|
||||
</group>
|
||||
))}
|
||||
</group>
|
||||
)}
|
||||
<EnginePlume
|
||||
{/* 芯级尾焰:台数取芯级自己的 engine_count,为 0 时整组不画 */}
|
||||
<EngineBankPlume
|
||||
radius={geo.radius}
|
||||
length={geo.radius * 10}
|
||||
nozzleY={-geo.radius * 0.7}
|
||||
count={geo.coreEngines}
|
||||
nozzleY={-geo.radius * 0.16}
|
||||
throttle={state.throttle}
|
||||
active={engines.stage1}
|
||||
running={state.isRunning}
|
||||
spread={1 + geo.coreEngines * 0.04}
|
||||
/>
|
||||
</group>
|
||||
</group>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { RocketAppearance, RocketConfig, SimulationState } from './types';
|
||||
import type { RocketAppearance, RocketBoosters, RocketConfig, SimulationState } from './types';
|
||||
|
||||
/**
|
||||
* Visual constants for the 3D flight scene. The rocket is always drawn at a
|
||||
|
|
@ -10,7 +10,7 @@ export const VEHICLE_HEIGHT = 12;
|
|||
/** 火箭布局:单芯级(猎鹰 9 一类)或捆绑助推器 / 侧芯级(长征五号、猎鹰重型)。 */
|
||||
export type VehicleLayout = 'single-core' | 'boosters';
|
||||
|
||||
/** 未登记外观时的助推器细长比(长征五号 2.25m / 5.0m)。 */
|
||||
/** 未登记助推器直径比时的默认粗细(约 45%)。 */
|
||||
const DEFAULT_BOOSTER_DIAMETER_RATIO = 0.45;
|
||||
|
||||
export interface VehicleLayoutInfo {
|
||||
|
|
@ -45,57 +45,64 @@ export interface StageGeometry extends VehicleLayoutInfo {
|
|||
}
|
||||
|
||||
/**
|
||||
* 构型优先取管理端登记的 appearance;没有登记时再按发动机数量推断:
|
||||
* 真实的两级半火箭把「芯级 + 4 个助推器」的发动机数量合并登记在一级上
|
||||
* (长征五号 10 = 芯级 2 + 4×2 助推器),单芯级火箭则为「芯级中心机 + 外圈机」
|
||||
* (猎鹰 9 = 1 + 8)。猎鹰重型、星舰这类反例只能靠 appearance 表达。
|
||||
* 构型全部来自登记值:助推器的数量 / 每台的发动机数 / 直径比在 boosters 里,
|
||||
* 芯级机数就是 stage_1.engine_count(阿丽亚娜 6 这类「一级 = 助推器组合」的型号
|
||||
* 芯级为 0 台)。剩下只有栅格翼需要猜:细长且多发动机的单芯级(猎鹰 9)才会带。
|
||||
*/
|
||||
export function resolveVehicleLayout(
|
||||
stage1Engines: number,
|
||||
coreEngines: number,
|
||||
slenderness: number,
|
||||
boosters: RocketBoosters | null | undefined,
|
||||
appearance: RocketAppearance = {},
|
||||
): VehicleLayoutInfo {
|
||||
const heuristicBoosters = stage1Engines > 9 && (stage1Engines - 2) % 4 === 0 ? 4 : 0;
|
||||
const boosterCount = Math.round(appearance.booster_count ?? heuristicBoosters);
|
||||
const count = Math.round(boosters?.count ?? 0);
|
||||
// 没登记时按通用规律推断:细长且多发动机的单芯级才带栅格翼
|
||||
const gridFins = appearance.grid_fins ?? (count === 0 && coreEngines >= 8 && slenderness >= 15);
|
||||
|
||||
if (boosterCount <= 0) {
|
||||
if (count <= 0) {
|
||||
return {
|
||||
layout: 'single-core',
|
||||
boosterCount: 0,
|
||||
enginesPerBooster: 0,
|
||||
coreEngines: stage1Engines,
|
||||
// 细长且多发动机的单芯级(猎鹰 9)才会带栅格翼这类回收构型特征件
|
||||
gridFins: appearance.grid_fins ?? (stage1Engines >= 8 && slenderness >= 15),
|
||||
coreEngines: Math.max(0, Math.round(coreEngines)),
|
||||
gridFins,
|
||||
boosterDiameterRatio: DEFAULT_BOOSTER_DIAMETER_RATIO,
|
||||
};
|
||||
}
|
||||
|
||||
// 每台助推器的机数:4 助推器构型可按一级总数反推,其余构型需要登记
|
||||
const inferredPerBooster = boosterCount === 4 ? (stage1Engines - 2) / 4 : 1;
|
||||
const enginesPerBooster = Math.max(1, Math.round(appearance.engines_per_booster ?? inferredPerBooster));
|
||||
// 芯级机数优先用登记的 core_engine_count,没登记才用「一级总数 − 助推器机数」推算
|
||||
const coreEngines = Math.max(
|
||||
1,
|
||||
Math.round(appearance.core_engine_count ?? stage1Engines - boosterCount * enginesPerBooster),
|
||||
);
|
||||
|
||||
return {
|
||||
layout: 'boosters',
|
||||
boosterCount,
|
||||
enginesPerBooster,
|
||||
coreEngines,
|
||||
gridFins: appearance.grid_fins ?? false,
|
||||
boosterDiameterRatio: clamp(appearance.booster_diameter_ratio ?? DEFAULT_BOOSTER_DIAMETER_RATIO, 0.2, 1),
|
||||
boosterCount: count,
|
||||
enginesPerBooster: Math.max(1, Math.round(boosters!.engine_count)),
|
||||
coreEngines: Math.max(0, Math.round(coreEngines)),
|
||||
gridFins,
|
||||
boosterDiameterRatio: clamp(boosters!.diameter_ratio ?? DEFAULT_BOOSTER_DIAMETER_RATIO, 0.2, 1),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 助推器(侧芯级)的分布角:两个时与芯级并排成一线(猎鹰重型、长征八号),
|
||||
* 四个时按 X 形对称布置(长征五号一类)。
|
||||
* 跟随机位的水平方位角:相机固定在芯级侧前方(RocketFlightScene 里 lateral = pullback * 0.32),
|
||||
* 因此场景的「左右」相对世界 X 轴转了这个角度。助推器环按同一方位对齐,
|
||||
* 镜头里的左右两两成对才对称,芯级才会正好落在画面正中。
|
||||
*/
|
||||
export function boosterAngle(index: number, count: number): number {
|
||||
const base = count === 2 ? 0 : Math.PI / 4;
|
||||
return (index / Math.max(1, count)) * Math.PI * 2 + base;
|
||||
export const FOLLOW_VIEW_YAW = Math.atan(0.32);
|
||||
|
||||
/**
|
||||
* 助推器(侧芯级)的分布角:芯级留在正中心,助推器平均分成左右两组挂在芯级两侧
|
||||
* (镜头方向看就是左右各半,猎鹰重型 / 长征八号即左右各一枚),并关于镜头横轴镜像对称。
|
||||
* 同侧多枚时按「相邻两枚刚好相切」的夹角展开,既不互相插入,也没有一枚挡在芯级正前面。
|
||||
*/
|
||||
export function boosterAngle(index: number, count: number, ratio = DEFAULT_BOOSTER_DIAMETER_RATIO): number {
|
||||
const total = Math.max(1, Math.round(count));
|
||||
if (total === 1) return -FOLLOW_VIEW_YAW;
|
||||
// 奇数枚时多出来的一枚归右侧,其余左右均分
|
||||
const rightCount = Math.ceil(total / 2);
|
||||
const onRight = index < rightCount;
|
||||
const members = onRight ? rightCount : total - rightCount;
|
||||
const order = onRight ? index : index - rightCount;
|
||||
// 半径 rb 的助推器贴在同一圆周上时,相邻两枚相切所需的圆心夹角
|
||||
const step = 2 * Math.asin(clamp(ratio / (1 + ratio), 0, 0.9));
|
||||
return (onRight ? 0 : Math.PI) - FOLLOW_VIEW_YAW + (order - (members - 1) / 2) * step;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,9 +122,11 @@ export interface EngineGroup {
|
|||
}
|
||||
|
||||
export function stage1EngineGroups(layout: VehicleLayoutInfo): EngineGroup[] {
|
||||
const groups: EngineGroup[] = [
|
||||
{ kind: 'core', engines: layout.coreEngines, radius: 1, offset: 0, angle: 0 },
|
||||
];
|
||||
const groups: EngineGroup[] = [];
|
||||
// 芯级没有发动机(一级整体就是助推器组合)时不画空舱
|
||||
if (layout.coreEngines > 0) {
|
||||
groups.push({ kind: 'core', engines: layout.coreEngines, radius: 1, offset: 0, angle: 0 });
|
||||
}
|
||||
if (layout.layout !== 'boosters') return groups;
|
||||
|
||||
const radius = layout.boosterDiameterRatio;
|
||||
|
|
@ -128,7 +137,7 @@ export function stage1EngineGroups(layout: VehicleLayoutInfo): EngineGroup[] {
|
|||
engines: layout.enginesPerBooster,
|
||||
radius,
|
||||
offset,
|
||||
angle: boosterAngle(index, layout.boosterCount),
|
||||
angle: boosterAngle(index, layout.boosterCount, layout.boosterDiameterRatio),
|
||||
});
|
||||
}
|
||||
return groups;
|
||||
|
|
@ -139,8 +148,9 @@ export function layoutForRocket(rocket: RocketConfig) {
|
|||
const heightM = Math.max(1, rocket.height_m);
|
||||
const diameterM = Math.max(0.5, rocket.diameter_m);
|
||||
return resolveVehicleLayout(
|
||||
Math.max(1, Math.round(rocket.stage_1.engine_count)),
|
||||
rocket.stage_1.engine_count,
|
||||
clamp(heightM / diameterM, 4, 26),
|
||||
rocket.boosters,
|
||||
rocket.appearance ?? {},
|
||||
);
|
||||
}
|
||||
|
|
@ -193,7 +203,8 @@ export function stageGeometry(rocket: RocketConfig): StageGeometry {
|
|||
const stage1Height = stackHeight * (ratio1 / ratioSum);
|
||||
const stage2Height = stackHeight * (ratio2 / ratioSum);
|
||||
|
||||
const stage1Engines = Math.max(1, Math.round(rocket.stage_1.engine_count));
|
||||
// 一级的机数就是芯级自己的台数,可以为 0(一级整体就是助推器组合)
|
||||
const stage1Engines = Math.max(0, Math.round(rocket.stage_1.engine_count));
|
||||
|
||||
return {
|
||||
totalHeight,
|
||||
|
|
@ -208,7 +219,7 @@ export function stageGeometry(rocket: RocketConfig): StageGeometry {
|
|||
stage1Engines,
|
||||
stage2Engines: Math.max(1, Math.round(rocket.stage_2.engine_count)),
|
||||
fairing: hasFairing,
|
||||
...resolveVehicleLayout(stage1Engines, slenderness, rocket.appearance ?? {}),
|
||||
...resolveVehicleLayout(stage1Engines, slenderness, rocket.boosters, rocket.appearance ?? {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +241,8 @@ export interface EnginePlacement {
|
|||
* count 是「一组(芯级或某个助推器)」的机数,不是整箭总数。
|
||||
*/
|
||||
export function engineLayout(count: number, radius: number): EnginePlacement[] {
|
||||
const total = Math.max(1, Math.round(count));
|
||||
const total = Math.round(count);
|
||||
if (total <= 0) return [];
|
||||
const ringRadius = radius * 0.7;
|
||||
const make = (x: number, z: number, bellRadius: number, cant = 0): EnginePlacement => ({
|
||||
x,
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
import type { RocketConfig } from './types';
|
||||
|
||||
/**
|
||||
* 一级里「芯级」与「捆绑助推器」的拆分口径。
|
||||
* 一级的「芯级 + 捆绑助推器」分组口径。
|
||||
*
|
||||
* 数据库里 stage_1 始终登记一级合计(含助推器),boosters 登记其中属于助推器的那一组,
|
||||
* 芯级用减法得到,因此不会出现两套数字互相矛盾;助推器单独登记比冲,
|
||||
* 芯级比冲沿用 stage_1(那是整段一级的有效比冲,反推芯级比冲会算出错误的燃烧时间)。
|
||||
* 数据库里两侧各自独立登记:stage_1 是芯级,boosters 是助推器这一组的合计值,
|
||||
* 因此这里不再做减法。推进参数留空的助推器只描述构型(用于绘制外形),
|
||||
* 此时返回 boosters = null,物理退回「一级整段」模型。
|
||||
*/
|
||||
export interface BoosterGroup {
|
||||
count: number;
|
||||
/** 每台助推器的发动机数量 */
|
||||
engineCount: number;
|
||||
/** 全部助推器合计推力 */
|
||||
thrustN: number;
|
||||
/** 助推器比冲 */
|
||||
|
|
@ -23,31 +25,32 @@ export interface Stage1Split {
|
|||
coreThrustN: number;
|
||||
coreIspS: number;
|
||||
coreDryKg: number;
|
||||
/** 未登记助推器参数时为 null,此时物理退回「一级整段」模型 */
|
||||
/** 只登记了构型(或没有助推器)时为 null,此时物理按一级整段计算 */
|
||||
boosters: BoosterGroup | null;
|
||||
}
|
||||
|
||||
const PHYSICS_KEYS = ['thrust_n', 'specific_impulse_s', 'dry_mass_kg', 'fuel_mass_kg'] as const;
|
||||
|
||||
export function resolveStage1(rocket: RocketConfig): Stage1Split {
|
||||
const stage1 = rocket.stage_1;
|
||||
const core = {
|
||||
coreThrustN: stage1.max_thrust_n,
|
||||
coreIspS: stage1.specific_impulse_s,
|
||||
coreDryKg: stage1.dry_mass_kg,
|
||||
};
|
||||
const preset = rocket.boosters;
|
||||
if (!preset) {
|
||||
return {
|
||||
coreThrustN: stage1.max_thrust_n,
|
||||
coreIspS: stage1.specific_impulse_s,
|
||||
coreDryKg: stage1.dry_mass_kg,
|
||||
boosters: null,
|
||||
};
|
||||
if (!preset || PHYSICS_KEYS.some((key) => preset[key] == null)) {
|
||||
return { ...core, boosters: null };
|
||||
}
|
||||
return {
|
||||
coreThrustN: Math.max(0, stage1.max_thrust_n - preset.thrust_n),
|
||||
coreIspS: stage1.specific_impulse_s,
|
||||
coreDryKg: Math.max(0, stage1.dry_mass_kg - preset.dry_mass_kg),
|
||||
...core,
|
||||
boosters: {
|
||||
count: preset.count,
|
||||
thrustN: preset.thrust_n,
|
||||
ispS: preset.specific_impulse_s,
|
||||
dryKg: preset.dry_mass_kg,
|
||||
fuelKg: Math.min(preset.fuel_mass_kg, stage1.fuel_mass_kg),
|
||||
engineCount: preset.engine_count,
|
||||
thrustN: preset.thrust_n as number,
|
||||
ispS: preset.specific_impulse_s as number,
|
||||
dryKg: preset.dry_mass_kg as number,
|
||||
fuelKg: preset.fuel_mass_kg as number,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,24 +4,16 @@ export interface RocketStage {
|
|||
fuel_mass_kg: number;
|
||||
max_thrust_n: number;
|
||||
specific_impulse_s: number;
|
||||
/** 本级发动机数量;一级的这里是芯级自己的台数,不含助推器 */
|
||||
engine_count: number;
|
||||
length_ratio: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 外观构型(可选):真实火箭的构型差别无法只靠发动机数量推断,
|
||||
* 例如猎鹰重型的 27 台是「3 根等直径芯级」,星舰则没有整流罩。
|
||||
* 留空的字段由 sceneMath 按通用规律推断。
|
||||
* 纯外观特征(可选):只登记无法从参数推导的特征件。
|
||||
* 助推器数量、每台的发动机数与直径都在 boosters 里登记,这里不重复存放。
|
||||
*/
|
||||
export interface RocketAppearance {
|
||||
/** 捆绑助推器 / 侧芯级数量,0 为单芯级 */
|
||||
booster_count?: number | null;
|
||||
/** 芯级一级发动机数量;stage_1.engine_count 是含助推器的一级总数 */
|
||||
core_engine_count?: number | null;
|
||||
/** 每个助推器的发动机数量 */
|
||||
engines_per_booster?: number | null;
|
||||
/** 助推器直径 / 芯级直径 */
|
||||
booster_diameter_ratio?: number | null;
|
||||
/** 一级顶部栅格翼(回收构型) */
|
||||
grid_fins?: boolean | null;
|
||||
/** 是否有载荷整流罩;false 表示二级自身带头锥与襟翼(星舰) */
|
||||
|
|
@ -29,22 +21,26 @@ export interface RocketAppearance {
|
|||
}
|
||||
|
||||
/**
|
||||
* 捆绑助推器组合参数(可选)。
|
||||
* 捆绑助推器组(可选):数量、发动机、直径比与推进参数都登记在助推器自己身上。
|
||||
*
|
||||
* 口径与一级一致,但只统计助推器这一组:thrust_n / dry_mass_kg / fuel_mass_kg
|
||||
* 都是全部助推器的合计值。stage_1 始终是「一级合计(含助推器)」,
|
||||
* 芯级 = stage_1 减去本组,因此不存在两套数字互相矛盾。
|
||||
* stage_1 只描述芯级(engine_count 不含助推器),起飞推力 = stage_1 + boosters。
|
||||
* 四个推进参数要么整体登记、要么整体留空:留空表示该型号只登记了助推器构型
|
||||
* (用于绘制外形),物理仍按一级整段计算。
|
||||
*/
|
||||
export interface RocketBoosters {
|
||||
count: number;
|
||||
/** 全部助推器合计推力,不含芯级 */
|
||||
thrust_n: number;
|
||||
/** 助推器比冲;芯级比冲沿用 stage_1.specific_impulse_s */
|
||||
specific_impulse_s: number;
|
||||
/** 每台助推器的发动机数量 */
|
||||
engine_count: number;
|
||||
/** 助推器直径 / 芯级直径,留空按 0.45 绘制 */
|
||||
diameter_ratio?: number | null;
|
||||
/** 全部助推器合计推力 */
|
||||
thrust_n?: number | null;
|
||||
/** 助推器比冲 */
|
||||
specific_impulse_s?: number | null;
|
||||
/** 全部助推器合计干重 */
|
||||
dry_mass_kg: number;
|
||||
dry_mass_kg?: number | null;
|
||||
/** 全部助推器合计推进剂 */
|
||||
fuel_mass_kg: number;
|
||||
fuel_mass_kg?: number | null;
|
||||
}
|
||||
|
||||
export interface RocketConfig {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import type { FlightPhase, RocketConfig, SimulationState } from './types';
|
||||
import { addEvent, stepSimulation, type SimulationContext } from './physics';
|
||||
import { resolveStage1 } from './stageSplit';
|
||||
|
||||
function initialState(rocket: RocketConfig): SimulationState {
|
||||
// stage1Fuel 是一级总余量(芯级 + 助推器),扣掉助推器余量才是芯级余量,
|
||||
// 因此助推器分离后 S1% 的读法与单芯级火箭一致
|
||||
const boosterFuel = resolveStage1(rocket).boosters?.fuelKg ?? 0;
|
||||
return {
|
||||
time: 0,
|
||||
altitude: 0,
|
||||
|
|
@ -13,8 +17,8 @@ function initialState(rocket: RocketConfig): SimulationState {
|
|||
acceleration: 0,
|
||||
pitch: 90,
|
||||
dynamicPressure: 0,
|
||||
stage1Fuel: rocket.stage_1.fuel_mass_kg,
|
||||
boosterFuel: rocket.boosters?.fuel_mass_kg ?? 0,
|
||||
stage1Fuel: rocket.stage_1.fuel_mass_kg + boosterFuel,
|
||||
boosterFuel,
|
||||
stage2Fuel: rocket.stage_2.fuel_mass_kg,
|
||||
throttle: 1,
|
||||
phase: 'ready',
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import {
|
|||
type EngineGroup,
|
||||
} from '../features/rocket-simulator/sceneMath';
|
||||
import '../features/rocket-simulator/rocket-simulator.css';
|
||||
import { resolveStage1 } from '../features/rocket-simulator/stageSplit';
|
||||
|
||||
/**
|
||||
* Canonical flight milestones, in order. Each maps to an event id emitted by
|
||||
|
|
@ -169,13 +170,27 @@ function StackDiagram({ rocket }: { rocket: RocketConfig }) {
|
|||
<rect x={CX + r1 - 2.4} y={s1Top + s1H * 0.12} width={2.4} height={s1H * 0.78} fill="#20262c" />
|
||||
<rect x={CX - r1 - 1} y={engineY} width={r1 * 2 + 2} height={5} rx={2} fill="#101418" />
|
||||
{/* 栅格翼(细长单芯级回收构型) */}
|
||||
{geo.gridFins && [-1, 1].map((direction) => (
|
||||
<path
|
||||
key={direction}
|
||||
d={`M ${CX + direction * r1} ${s1Top + s1H * 0.08} l ${direction * 7} 0 l 0 6 l ${-direction * 7} 0 Z`}
|
||||
fill="#39414a"
|
||||
/>
|
||||
))}
|
||||
{geo.gridFins && [-1, 1].map((direction) => {
|
||||
const x = CX + direction * r1;
|
||||
const y = s1Top + s1H * 0.06;
|
||||
return (
|
||||
<g key={direction}>
|
||||
<path d={`M ${x} ${y} l ${direction * 11} 0 l 0 11 l ${-direction * 11} 0 Z`} fill="#39414a" />
|
||||
{[3.5, 7].map((offset) => (
|
||||
<line
|
||||
key={offset}
|
||||
x1={x + direction * offset}
|
||||
y1={y + 0.8}
|
||||
x2={x + direction * offset}
|
||||
y2={y + 10.2}
|
||||
stroke="#8f9aa3"
|
||||
strokeWidth={0.7}
|
||||
/>
|
||||
))}
|
||||
<line x1={x + direction * 0.8} y1={y + 5.5} x2={x + direction * 10.2} y2={y + 5.5} stroke="#8f9aa3" strokeWidth={0.7} />
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
{engineBells(geo.layout === 'boosters' ? geo.coreEngines : geo.stage1Engines, geo.radius, engineY + 5)}
|
||||
</g>
|
||||
|
||||
|
|
@ -239,11 +254,14 @@ function StackDiagram({ rocket }: { rocket: RocketConfig }) {
|
|||
|
||||
function VehiclePanel({ rocket, mode, stage1FuelPct, stage2FuelPct }: { rocket: RocketConfig; mode: StackMode; stage1FuelPct: number; stage2FuelPct: number }) {
|
||||
const meta = mode === 'payload' && rocket.appearance?.fairing === false ? SHIP_MODE_LABEL : STACK_MODE_LABEL[mode];
|
||||
// 两级半构型把「芯级 + 助推器」的机数合并登记在一级上,规格里拆开写才看得懂
|
||||
const layout = layoutForRocket(rocket);
|
||||
// 芯级与助推器各自登记自己的机数,规格里分开写清各是几台
|
||||
const stage1Engines = layout.layout === 'boosters'
|
||||
? `${layout.coreEngines}+${layout.boosterCount}×${layout.enginesPerBooster}`
|
||||
: `${rocket.stage_1.engine_count}`;
|
||||
: `${layout.coreEngines}`;
|
||||
// 只登记了构型的助推器不参与物理,起飞推力仍按一级整段计
|
||||
const split = resolveStage1(rocket);
|
||||
const totalThrustMN = (split.coreThrustN + (split.boosters?.thrustN ?? 0)) / 1e6;
|
||||
return (
|
||||
<div className="sx-vehicle">
|
||||
<div className="sx-panel-title"><span>VEHICLE</span><b>运载器状态</b></div>
|
||||
|
|
@ -261,7 +279,7 @@ function VehiclePanel({ rocket, mode, stage1FuelPct, stage2FuelPct }: { rocket:
|
|||
<div className="sx-spec-divider" />
|
||||
<div className="sx-spec-row"><span>箭体尺寸</span><b>{rocket.height_m.toFixed(1)} × Ø{rocket.diameter_m.toFixed(1)} m</b></div>
|
||||
<div className="sx-spec-row"><span>发动机</span><b>{stage1Engines} + {rocket.stage_2.engine_count} 台</b></div>
|
||||
<div className="sx-spec-row"><span>一级推力</span><b>{(rocket.stage_1.max_thrust_n / 1e6).toFixed(2)} MN</b></div>
|
||||
<div className="sx-spec-row"><span>起飞推力</span><b>{totalThrustMN.toFixed(2)} MN</b></div>
|
||||
<div className="sx-spec-row"><span>二级推力</span><b>{(rocket.stage_2.max_thrust_n / 1e6).toFixed(2)} MN</b></div>
|
||||
<div className="sx-spec-row"><span>载荷</span><b>{(rocket.payload_mass_kg / 1000).toFixed(1)} t</b></div>
|
||||
<div className="sx-spec-row"><span>目标轨道</span><b>{rocket.target_orbit_km} km</b></div>
|
||||
|
|
@ -483,9 +501,12 @@ function RocketMission({ rockets }: { rockets: RocketConfig[] }) {
|
|||
const rocket = rockets.find((item) => item.code === selectedCode) || rockets[0];
|
||||
const { state, toggle, reset, speed, setSpeed } = useRocketSimulation(rocket);
|
||||
|
||||
const totalFuel = rocket.stage_1.fuel_mass_kg + rocket.stage_2.fuel_mass_kg;
|
||||
// 一级推进剂的起点是「芯级 + 助推器」的合计(与 initialState 同一口径),
|
||||
// 助推器烧完先分离,余量也随之归零,因此 S1% 会在那一刻下一个台阶
|
||||
const stage1FuelKg = rocket.stage_1.fuel_mass_kg + (resolveStage1(rocket).boosters?.fuelKg ?? 0);
|
||||
const totalFuel = stage1FuelKg + rocket.stage_2.fuel_mass_kg;
|
||||
const remainingFuel = state.stage1Fuel + state.stage2Fuel;
|
||||
const stage1FuelPct = Math.max(0, state.stage1Fuel / rocket.stage_1.fuel_mass_kg * 100);
|
||||
const stage1FuelPct = Math.max(0, state.stage1Fuel / stage1FuelKg * 100);
|
||||
const stage2FuelPct = Math.max(0, state.stage2Fuel / rocket.stage_2.fuel_mass_kg * 100);
|
||||
const totalFuelPct = Math.max(0, remainingFuel / totalFuel * 100);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,21 +27,29 @@ function StageFields({ index }: { index: 1 | 2 }) {
|
|||
<Col xs={24} md={12}><NumberField name={[prefix, 'fuel_mass_kg']} label="推进剂质量" suffix="kg" /></Col>
|
||||
<Col xs={24} md={12}><NumberField name={[prefix, 'max_thrust_n']} label="最大推力" suffix="N" /></Col>
|
||||
<Col xs={24} md={12}><NumberField name={[prefix, 'specific_impulse_s']} label="比冲" suffix="s" /></Col>
|
||||
<Col xs={24} md={12}><NumberField name={[prefix, 'engine_count']} label="发动机数量" min={1} /></Col>
|
||||
<Col xs={24} md={12}>
|
||||
<NumberField
|
||||
name={[prefix, 'engine_count']}
|
||||
label={index === 1 ? '芯级发动机数(不含助推器)' : '发动机数量'}
|
||||
min={index === 1 ? 0 : 1}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} md={12}><NumberField name={[prefix, 'length_ratio']} label="箭体长度占比" min={0.01} step={0.05} /></Col>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 外观特征件(可选)。
|
||||
*
|
||||
* 助推器数量、每台的发动机数与直径都在「助推器参数」里登记,这里只放
|
||||
* 无法从参数推导的特征件;栅格翼留空时按「细长且多发动机的单芯级」推断。
|
||||
*/
|
||||
function AppearanceFields() {
|
||||
return (
|
||||
<Row gutter={16}>
|
||||
<Col span={24}><Alert type="info" showIcon style={{ marginBottom: 16 }} message="留空即按发动机数量自动推断构型;仅当 3D 外形与真实不符时才需要填写。" /></Col>
|
||||
<Col xs={24} md={6}><Form.Item name={['appearance', 'booster_count']} label="助推器数量" tooltip="捆绑助推器 / 侧芯级数量,0 为单芯级"><InputNumber min={0} max={8} style={{ width: '100%' }} placeholder="自动" /></Form.Item></Col>
|
||||
<Col xs={24} md={6}><Form.Item name={['appearance', 'engines_per_booster']} label="单个助推器发动机数" tooltip="每个助推器各自的喷管数量,决定助推器尾焰规模"><InputNumber min={1} max={33} style={{ width: '100%' }} placeholder="自动" /></Form.Item></Col>
|
||||
<Col xs={24} md={6}><Form.Item name={['appearance', 'core_engine_count']} label="芯级发动机数" tooltip="一级的 stage_1 发动机数量含助推器总数,这里单独登记芯级自己的台数(如猎鹰重型 27 = 芯级 9 + 2×9)"><InputNumber min={1} max={33} style={{ width: '100%' }} placeholder="自动" /></Form.Item></Col>
|
||||
<Col xs={24} md={6}><Form.Item name={['appearance', 'booster_diameter_ratio']} label="助推器直径比" tooltip="助推器直径 / 芯级直径"><InputNumber min={0.01} max={1} step={0.01} style={{ width: '100%' }} placeholder="0.45" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['appearance', 'grid_fins']} label="一级栅格翼" tooltip="回收构型一级顶部的栅格翼" valuePropName="checked"><Switch /></Form.Item></Col>
|
||||
<Col span={24}><Alert type="info" showIcon style={{ marginBottom: 16 }} message="这里只放特征件;助推器的数量、发动机数与直径比请到「助推器参数」里登记。" /></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['appearance', 'grid_fins']} label="一级栅格翼" tooltip="回收构型一级顶部的栅格翼;留空按箭体细长比与发动机数自动判断" valuePropName="checked"><Switch /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['appearance', 'fairing']} label="载荷整流罩" tooltip="关闭表示二级自身带头锥与襟翼(如星舰飞船)" valuePropName="checked"><Switch /></Form.Item></Col>
|
||||
</Row>
|
||||
);
|
||||
|
|
@ -50,19 +58,23 @@ function AppearanceFields() {
|
|||
/**
|
||||
* 助推器参数(可选)。
|
||||
*
|
||||
* 一级参数登记的是「芯级 + 助推器」的合计值,这里单独登记助推器那一组,
|
||||
* 芯级由减法推导,因此捆绑构型的火箭才能算出真实的助推器分离与一级关机时序。
|
||||
* 整组留空即不拆分,一级按整体燃烧到关机。
|
||||
* 助推器自己带数量、每台的发动机数与直径比;一级参数只描述芯级,
|
||||
* 起飞推力 = 一级推力 + 助推器合计推力,因此捆绑构型的火箭能算出
|
||||
* 真实的助推器分离与一级关机时序。
|
||||
* 推进参数(推力 / 比冲 / 干重 / 推进剂)要么整体登记、要么整体留空:
|
||||
* 留空表示只登记构型用于绘制外形,物理仍按一级整段燃烧到关机。
|
||||
*/
|
||||
function BoosterFields() {
|
||||
return (
|
||||
<Row gutter={16}>
|
||||
<Col span={24}><Alert type="info" showIcon style={{ marginBottom: 16 }} message="数值均为全部助推器的合计口径(不含芯级),且不能超过一级参数里的合计值;不捆绑助推器的火箭整组留空即可。" /></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'count']} label="助推器数量" tooltip="捆绑的助推器 / 侧芯级个数"><InputNumber min={1} max={8} style={{ width: '100%' }} placeholder="不拆分" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'thrust_n']} label="合计推力" tooltip="全部助推器加起来的推力,不含芯级"><InputNumber min={1} style={{ width: '100%' }} suffix="N" placeholder="例如 9600000" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'specific_impulse_s']} label="比冲" tooltip="助推器自己的比冲;芯级比冲沿用一级参数的值"><InputNumber min={1} style={{ width: '100%' }} suffix="s" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'dry_mass_kg']} label="合计干重"><InputNumber min={1} style={{ width: '100%' }} suffix="kg" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'fuel_mass_kg']} label="合计推进剂"><InputNumber min={1} style={{ width: '100%' }} suffix="kg" /></Form.Item></Col>
|
||||
<Col span={24}><Alert type="info" showIcon style={{ marginBottom: 16 }} message="推进参数为全部助推器的合计口径(不含芯级);只查得到构型时把下面四项整体留空,助推器就只决定外形,不参与物理。" /></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'count']} label="助推器数量" tooltip="捆绑的助推器 / 侧芯级个数"><InputNumber min={1} max={8} style={{ width: '100%' }} placeholder="无助推器" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'engine_count']} label="每台助推器发动机数" tooltip="单个助推器自己的喷管数量,决定助推器尾焰规模"><InputNumber min={1} max={33} style={{ width: '100%' }} placeholder="例如 2" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'diameter_ratio']} label="助推器直径比" tooltip="助推器直径 / 芯级直径,例如长征五号 3.35m / 5.0m 填 0.67、猎鹰重型三枚等粗一级填 1;留空按 0.45 绘制"><InputNumber min={0.05} max={1} step={0.01} style={{ width: '100%' }} placeholder="0.45" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'thrust_n']} label="合计推力" tooltip="全部助推器加起来的推力,不含芯级"><InputNumber min={1} style={{ width: '100%' }} suffix="N" placeholder="仅构型可留空" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'specific_impulse_s']} label="比冲" tooltip="助推器自己的比冲;芯级比冲沿用一级参数的值"><InputNumber min={1} style={{ width: '100%' }} suffix="s" placeholder="仅构型可留空" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'dry_mass_kg']} label="合计干重"><InputNumber min={1} style={{ width: '100%' }} suffix="kg" placeholder="仅构型可留空" /></Form.Item></Col>
|
||||
<Col xs={24} md={12}><Form.Item name={['boosters', 'fuel_mass_kg']} label="合计推进剂"><InputNumber min={1} style={{ width: '100%' }} suffix="kg" placeholder="仅构型可留空" /></Form.Item></Col>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
|
|
@ -120,7 +132,7 @@ export function Rockets() {
|
|||
const save = async () => {
|
||||
try {
|
||||
const values = await form.validateFields();
|
||||
// 助推器是整组可选的:没填数量就当不拆分,避免把半个对象提交给后端
|
||||
// 助推器是整组可选的:没填数量就当不捆绑,避免把半个对象提交给后端
|
||||
if (!values.boosters?.count) values.boosters = null;
|
||||
if (editing) await request.put(`/rockets/admin/${editing.id}`, values);
|
||||
else await request.post('/rockets/admin', values);
|
||||
|
|
@ -205,7 +217,7 @@ export function Rockets() {
|
|||
{ key: 'stage1', label: '一级参数', children: <StageFields index={1} /> },
|
||||
{ key: 'stage2', label: '二级参数', children: <StageFields index={2} /> },
|
||||
{ key: 'boosters', label: '助推器参数(可选)', children: <BoosterFields /> },
|
||||
{ key: 'appearance', label: '外观构型(可选)', children: <AppearanceFields /> },
|
||||
{ key: 'appearance', label: '外观特征件(可选)', children: <AppearanceFields /> },
|
||||
]} />
|
||||
</Form>
|
||||
</AdminModal>
|
||||
|
|
|
|||
Loading…
Reference in New Issue