Add brush authoring schema
CI / Format, lint, test, build (push) Waiting to run

This commit is contained in:
Rbanh committed 2026-06-06 05:42:19 -04:00
1 parent cc6acb188d
commit 9f95ba3082
24 files changed
+891 -78

No files matched your search

+181
View File
@@ -146,6 +146,7 @@ pub fn inspector_component_active(order: Option<&InspectorOrder>, type_name: &st
}
pub const COMPONENT_PRIMITIVE: &str = "shared::components::Primitive";
pub const COMPONENT_BRUSH_DESC: &str = "shared::components::BrushDesc";
pub const COMPONENT_STATIC_MESH_RENDERER: &str = "shared::components::StaticMeshRenderer";
pub const COMPONENT_MATERIAL_DESC: &str = "shared::components::MaterialDesc";
pub const COMPONENT_MATERIAL_OVERRIDE: &str = "shared::components::MaterialOverride";
@@ -267,6 +268,185 @@ impl Default for Primitive {
}
}
/// Brush boolean role. Subtractive brushes are authored now but CSG is applied
/// by later tooling.
#[derive(Reflect, Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
pub enum BrushKind {
#[default]
Additive,
SubtractiveMarker,
}
/// Serializable convex brush plane. Plane equation is `normal.dot(point) = distance`.
#[derive(Reflect, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct BrushPlaneDesc {
pub normal: Vec3,
pub distance: f32,
}
impl Default for BrushPlaneDesc {
fn default() -> Self {
Self {
normal: Vec3::Y,
distance: 0.0,
}
}
}
/// One polygon face on a convex authoring brush.
#[derive(Reflect, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct BrushFaceDesc {
#[serde(default)]
pub id: ComponentInstanceId,
pub plane: BrushPlaneDesc,
#[serde(default)]
pub vertices: Vec<Vec3>,
#[serde(default)]
pub material: Option<EditorAssetRef>,
#[serde(default)]
pub texture: Option<EditorAssetRef>,
#[serde(default)]
pub uv_offset: Vec2,
#[serde(default = "default_uv_scale")]
pub uv_scale: Vec2,
#[serde(default)]
pub uv_rotation: f32,
#[serde(default)]
pub smoothing_group: u32,
}
impl Default for BrushFaceDesc {
fn default() -> Self {
Self {
id: ComponentInstanceId::default(),
plane: BrushPlaneDesc::default(),
vertices: Vec::new(),
material: None,
texture: None,
uv_offset: Vec2::ZERO,
uv_scale: default_uv_scale(),
uv_rotation: 0.0,
smoothing_group: 0,
}
}
}
fn default_uv_scale() -> Vec2 {
Vec2::ONE
}
/// Convex brush authoring data. Hydration turns this into generated mesh
/// children while the scene stores only this component.
#[derive(Component, Reflect, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[reflect(Component, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct BrushDesc {
pub kind: BrushKind,
#[serde(default)]
pub faces: Vec<BrushFaceDesc>,
#[serde(default = "default_true")]
pub cast_shadows: bool,
#[serde(default = "default_true")]
pub receive_shadows: bool,
}
impl BrushDesc {
pub fn cuboid(size: Vec3) -> Self {
let hx = size.x.max(0.001) * 0.5;
let hy = size.y.max(0.001) * 0.5;
let hz = size.z.max(0.001) * 0.5;
let faces = vec![
brush_face(
"face:+x",
Vec3::X,
vec![
Vec3::new(hx, -hy, -hz),
Vec3::new(hx, hy, -hz),
Vec3::new(hx, hy, hz),
Vec3::new(hx, -hy, hz),
],
),
brush_face(
"face:-x",
Vec3::NEG_X,
vec![
Vec3::new(-hx, -hy, hz),
Vec3::new(-hx, hy, hz),
Vec3::new(-hx, hy, -hz),
Vec3::new(-hx, -hy, -hz),
],
),
brush_face(
"face:+y",
Vec3::Y,
vec![
Vec3::new(-hx, hy, -hz),
Vec3::new(-hx, hy, hz),
Vec3::new(hx, hy, hz),
Vec3::new(hx, hy, -hz),
],
),
brush_face(
"face:-y",
Vec3::NEG_Y,
vec![
Vec3::new(-hx, -hy, hz),
Vec3::new(-hx, -hy, -hz),
Vec3::new(hx, -hy, -hz),
Vec3::new(hx, -hy, hz),
],
),
brush_face(
"face:+z",
Vec3::Z,
vec![
Vec3::new(hx, -hy, hz),
Vec3::new(hx, hy, hz),
Vec3::new(-hx, hy, hz),
Vec3::new(-hx, -hy, hz),
],
),
brush_face(
"face:-z",
Vec3::NEG_Z,
vec![
Vec3::new(-hx, -hy, -hz),
Vec3::new(-hx, hy, -hz),
Vec3::new(hx, hy, -hz),
Vec3::new(hx, -hy, -hz),
],
),
];
Self {
kind: BrushKind::Additive,
faces,
cast_shadows: true,
receive_shadows: true,
}
}
}
impl Default for BrushDesc {
fn default() -> Self {
Self::cuboid(Vec3::ONE)
}
}
fn brush_face(id: &str, normal: Vec3, vertices: Vec<Vec3>) -> BrushFaceDesc {
let distance = vertices
.first()
.map(|vertex| normal.dot(*vertex))
.unwrap_or(0.0);
BrushFaceDesc {
id: ComponentInstanceId::new(id),
plane: BrushPlaneDesc { normal, distance },
vertices,
..Default::default()
}
}
/// Legacy static mesh collision setting kept only for loading older scenes.
#[derive(Reflect, Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
@@ -736,6 +916,7 @@ impl Default for EditorVisibility {
#[reflect(Component, Debug, PartialEq, Serialize, Deserialize)]
pub enum ActorKind {
Empty,
Brush,
StaticMesh,
ImportedModel,
Light,