Build production-ready editor authoring workflows
CI / Format, lint, test, build (push) Waiting to run

This commit is contained in:
Rbanh committed 2026-07-11 12:41:04 -04:00
1 parent cc1fa6ea3b
commit 0553a85220
163 files changed
+34547 -1565

No files matched your search

+224 -4
View File
@@ -15,6 +15,41 @@ impl ActorId {
}
}
/// Stable scene-document identity and its authored subscene references.
///
/// This is persisted as a reflected scene resource. Cross-scene ownership never
/// depends on runtime [`Entity`] identifiers.
#[derive(Resource, Reflect, Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Resource, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct SceneComposition {
pub scene_id: String,
#[serde(default)]
pub subscenes: Vec<SubsceneReference>,
}
/// One stable, project-relative reference in a [`SceneComposition`].
#[derive(Reflect, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct SubsceneReference {
pub id: String,
pub path: String,
#[serde(default = "default_true")]
pub visible: bool,
#[serde(default = "default_true")]
pub locked: bool,
}
impl Default for SubsceneReference {
fn default() -> Self {
Self {
id: String::new(),
path: String::new(),
visible: true,
locked: true,
}
}
}
/// User-facing actor display name, separate from Bevy's runtime [`Name`].
#[derive(Component, Reflect, Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Component, Default, Debug, PartialEq, Serialize, Deserialize)]
@@ -162,6 +197,11 @@ pub const COMPONENT_OBJECTIVE_MARKER: &str = "shared::components::ObjectiveMarke
pub const COMPONENT_PREFAB_INSTANCE: &str = "shared::components::PrefabInstance";
pub const COMPONENT_POST_PROCESS_VOLUME: &str = "shared::components::PostProcessVolumeDesc";
pub const COMPONENT_PROJECT_SUN: &str = "shared::components::ProjectSun";
pub const COMPONENT_AUDIO_SOURCE_DESC: &str = "shared::components::AudioSourceDesc";
pub const COMPONENT_AUDIO_LISTENER_DESC: &str = "shared::components::AudioListenerDesc";
/// Stable imported sub-asset identifier used by authored audio clip references.
pub const AUDIO_CLIP_SUB_ASSET_ID: &str = "audio:source";
/// Reference to an imported content-browser asset or sub-asset.
#[derive(Reflect, Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
@@ -205,6 +245,135 @@ impl EditorAssetRef {
}
}
/// Distance curve used by an authored spatial audio source.
#[derive(Reflect, Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
pub enum AudioRolloff {
Linear,
#[default]
Inverse,
Exponential,
}
/// Serializable distance attenuation parameters for spatial audio playback.
#[derive(Reflect, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct AudioAttenuationDesc {
/// Radius in meters inside which the source plays at full gain.
#[serde(default = "default_audio_min_distance")]
pub min_distance: f32,
/// Radius in meters at which distance attenuation reaches silence.
#[serde(default = "default_audio_max_distance")]
pub max_distance: f32,
#[serde(default)]
pub rolloff: AudioRolloff,
/// Curve strength. `1.0` is the neutral authored value.
#[serde(default = "default_audio_rolloff_factor")]
pub rolloff_factor: f32,
}
impl Default for AudioAttenuationDesc {
fn default() -> Self {
Self {
min_distance: default_audio_min_distance(),
max_distance: default_audio_max_distance(),
rolloff: AudioRolloff::default(),
rolloff_factor: default_audio_rolloff_factor(),
}
}
}
fn default_audio_min_distance() -> f32 {
1.0
}
fn default_audio_max_distance() -> f32 {
25.0
}
fn default_audio_rolloff_factor() -> f32 {
1.0
}
fn default_audio_pitch() -> f32 {
1.0
}
fn default_audio_spatial_blend() -> f32 {
1.0
}
fn default_audio_bus() -> String {
settings::AUDIO_BUS_SFX_ID.to_string()
}
fn default_audio_ear_gap() -> f32 {
0.2
}
/// Scene-authored audio source. Runtime playback components are derived from this descriptor.
#[derive(Component, Reflect, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[reflect(Component, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct AudioSourceDesc {
#[serde(default)]
pub clip: Option<EditorAssetRef>,
/// Source gain in decibels before bus gain is applied.
#[serde(default)]
pub gain_db: f32,
#[serde(default = "default_audio_pitch")]
pub pitch: f32,
#[serde(default)]
pub looping: bool,
#[serde(default = "default_true")]
pub autoplay: bool,
/// Continuous authored blend where `0.0` is 2D and `1.0` is fully spatial.
#[serde(default = "default_audio_spatial_blend")]
pub spatial_blend: f32,
#[serde(default)]
pub attenuation: AudioAttenuationDesc,
/// Stable project audio bus ID.
#[serde(default = "default_audio_bus")]
pub bus: String,
}
impl Default for AudioSourceDesc {
fn default() -> Self {
Self {
clip: None,
gain_db: 0.0,
pitch: default_audio_pitch(),
looping: false,
autoplay: true,
spatial_blend: default_audio_spatial_blend(),
attenuation: AudioAttenuationDesc::default(),
bus: default_audio_bus(),
}
}
}
/// Scene-authored spatial listener. Runtime selection resolves enabled listeners by priority.
#[derive(Component, Reflect, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[reflect(Component, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct AudioListenerDesc {
#[serde(default = "default_true")]
pub enabled: bool,
#[serde(default)]
pub priority: i32,
/// Distance in meters between the listener's virtual ears.
#[serde(default = "default_audio_ear_gap")]
pub ear_gap: f32,
}
impl Default for AudioListenerDesc {
fn default() -> Self {
Self {
enabled: true,
priority: 0,
ear_gap: default_audio_ear_gap(),
}
}
}
/// Marker for entities that belong to editable/savable level data.
#[derive(Component, Reflect, Default, Debug, Clone, Copy, Serialize, Deserialize)]
#[reflect(Component, Default, Debug, Serialize, Deserialize)]
@@ -769,6 +938,9 @@ impl Default for MaterialDesc {
#[derive(Component, Reflect, Default, Debug, Clone, Serialize, Deserialize)]
#[reflect(Component, Default, Debug, Serialize, Deserialize)]
pub struct ModelRef {
/// Stable asset-registry UUID. Empty only for legacy or unresolved references.
#[serde(default)]
pub asset_id: String,
/// Asset path relative to `assets/`, e.g. `models/foo.glb` or `models/foo.fbx`.
pub path: String,
/// Scene index within the model file (`#SceneN` for FBX; glTF scene index otherwise).
@@ -778,11 +950,17 @@ pub struct ModelRef {
impl ModelRef {
pub fn new(path: impl Into<String>) -> Self {
Self {
asset_id: String::new(),
path: path.into(),
scene_index: 0,
}
}
pub fn with_asset_id(mut self, asset_id: impl Into<String>) -> Self {
self.asset_id = asset_id.into();
self
}
/// Asset-server path for FBX `#SceneN` labels (see `bevy_ufbx`).
pub fn fbx_scene_asset_path(path: &str, scene_index: usize) -> String {
format!("{path}#Scene{scene_index}")
@@ -791,7 +969,7 @@ impl ModelRef {
/// Reflectable reference to a saved `.scn.ron` dynamic scene under `assets/`.
/// Hydration turns this into a `DynamicWorldRoot`.
#[derive(Component, Reflect, Default, Debug, Clone, Serialize, Deserialize)]
#[derive(Component, Reflect, Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Component, Default, Debug, Serialize, Deserialize)]
pub struct PrefabRef {
/// Asset path relative to `assets/`, e.g. "prefabs/foo.scn.ron".
@@ -805,7 +983,7 @@ impl PrefabRef {
}
/// Marks a placed prefab instance with stable registry identity.
#[derive(Component, Reflect, Debug, Clone, Default, Serialize, Deserialize)]
#[derive(Component, Reflect, Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Component, Default, Debug, Serialize, Deserialize)]
pub struct PrefabInstance {
/// Stable asset registry UUID string.
@@ -950,7 +1128,7 @@ pub struct ObjectiveMarker {
pub struct HierarchySiblingIndex(pub i32);
/// Authoring visibility saved with the scene; hydration maps this to ECS [`Visibility`].
#[derive(Component, Reflect, Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Component, Reflect, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Component, Default, Debug, Serialize, Deserialize)]
pub struct EditorVisibility {
pub visible: bool,
@@ -978,6 +1156,8 @@ pub enum ActorKind {
PostProcessVolume,
TeamSpawn,
Objective,
AudioSource,
AudioListener,
}
/// Inspector upper bound for point/spot [`LightDesc::intensity`] (lumens).
@@ -1251,7 +1431,10 @@ impl Default for PhysicsBody {
#[cfg(test)]
mod tests {
use super::ModelRef;
use super::{
AudioListenerDesc, AudioRolloff, AudioSourceDesc, EditorAssetRef, ModelRef,
AUDIO_CLIP_SUB_ASSET_ID,
};
use bevy::light::light_consts;
#[test]
@@ -1275,4 +1458,41 @@ mod tests {
"models/foo.fbx#Scene2"
);
}
#[test]
fn legacy_model_ref_without_asset_id_remains_readable() {
let model: ModelRef = ron::from_str(
r#"(
path: "assets/models/legacy.glb",
scene_index: 2,
)"#,
)
.expect("legacy ModelRef should deserialize");
assert!(model.asset_id.is_empty());
assert_eq!(model.path, "assets/models/legacy.glb");
assert_eq!(model.scene_index, 2);
}
#[test]
fn audio_authoring_descriptors_round_trip() {
let source = AudioSourceDesc {
clip: Some(
EditorAssetRef::new("clip-id", AUDIO_CLIP_SUB_ASSET_ID, "Alarm")
.with_source_path("assets/audio/alarm.ogg"),
),
gain_db: -3.0,
pitch: 0.9,
looping: true,
..Default::default()
};
let serialized = ron::to_string(&(source.clone(), AudioListenerDesc::default())).unwrap();
let (parsed_source, parsed_listener): (AudioSourceDesc, AudioListenerDesc) =
ron::from_str(&serialized).unwrap();
assert_eq!(parsed_source, source);
assert_eq!(parsed_listener, AudioListenerDesc::default());
assert_eq!(parsed_source.attenuation.rolloff, AudioRolloff::Inverse);
assert_eq!(parsed_source.bus, settings::AUDIO_BUS_SFX_ID);
}
}