Add CSG tree API surface
This commit is contained in:
parent
3c8b37b53f
commit
915e0b37ce
12 changed files with 517 additions and 14 deletions
|
|
@ -12,6 +12,7 @@ mod convex;
|
|||
mod dsl;
|
||||
mod mesh;
|
||||
mod primitives;
|
||||
mod tree;
|
||||
|
||||
pub use assembler::{Assembler, BuildOutput, BuildReport, BuildWarning};
|
||||
pub use brush::{Aabb, Brush, BrushId, BrushOp, MaterialId, PolygonCategory, Primitive};
|
||||
|
|
@ -21,3 +22,7 @@ pub use mesh::TriangleMesh;
|
|||
pub use primitives::{
|
||||
DomeCapZSpec, FloretArmSpec, append_cylinder_z, append_dome_cap_z, append_floret_arm,
|
||||
};
|
||||
pub use tree::{
|
||||
CsgBranchOp, CsgNode, CsgNodeId, CsgOperationType, CsgTree, CsgTreeArena, CsgTreeBranch,
|
||||
CsgTreeBrush,
|
||||
};
|
||||
|
|
|
|||
306
crates/vg_csg/src/tree.rs
Normal file
306
crates/vg_csg/src/tree.rs
Normal file
|
|
@ -0,0 +1,306 @@
|
|||
use crate::{Assembler, Brush, BrushId, BrushOp, MaterialId, Primitive};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct CsgNodeId(pub u32);
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct CsgTreeBrush {
|
||||
pub node: CsgNodeId,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct CsgTreeBranch {
|
||||
pub node: CsgNodeId,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct CsgTree {
|
||||
pub root: CsgNodeId,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum CsgOperationType {
|
||||
Additive = 0,
|
||||
Subtractive = 1,
|
||||
Intersecting = 2,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum CsgBranchOp {
|
||||
Addition,
|
||||
Subtraction,
|
||||
Common,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum CsgNode {
|
||||
Brush(Brush),
|
||||
Branch {
|
||||
name: String,
|
||||
op: CsgBranchOp,
|
||||
children: Vec<CsgNodeId>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct CsgTreeArena {
|
||||
nodes: Vec<CsgNode>,
|
||||
}
|
||||
|
||||
impl CsgTreeArena {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn nodes(&self) -> &[CsgNode] {
|
||||
&self.nodes
|
||||
}
|
||||
|
||||
pub fn node(&self, id: CsgNodeId) -> Option<&CsgNode> {
|
||||
self.nodes.get(id.0 as usize)
|
||||
}
|
||||
|
||||
pub fn node_mut(&mut self, id: CsgNodeId) -> Option<&mut CsgNode> {
|
||||
self.nodes.get_mut(id.0 as usize)
|
||||
}
|
||||
|
||||
pub fn brush_count(&self) -> usize {
|
||||
self.nodes
|
||||
.iter()
|
||||
.filter(|node| matches!(node, CsgNode::Brush(_)))
|
||||
.count()
|
||||
}
|
||||
|
||||
pub fn branch_count(&self) -> usize {
|
||||
self.nodes
|
||||
.iter()
|
||||
.filter(|node| matches!(node, CsgNode::Branch { .. }))
|
||||
.count()
|
||||
}
|
||||
|
||||
pub fn generate_brush(
|
||||
&mut self,
|
||||
name: impl Into<String>,
|
||||
operation: CsgOperationType,
|
||||
primitive: Primitive,
|
||||
material: MaterialId,
|
||||
) -> CsgTreeBrush {
|
||||
let id = CsgNodeId(self.nodes.len() as u32);
|
||||
let brush = Brush::new(
|
||||
BrushId(id.0),
|
||||
name,
|
||||
operation.into_brush_op(),
|
||||
primitive,
|
||||
material,
|
||||
);
|
||||
self.nodes.push(CsgNode::Brush(brush));
|
||||
CsgTreeBrush { node: id }
|
||||
}
|
||||
|
||||
pub fn generate_branch(
|
||||
&mut self,
|
||||
name: impl Into<String>,
|
||||
op: CsgBranchOp,
|
||||
children: impl IntoIterator<Item = CsgNodeId>,
|
||||
) -> CsgTreeBranch {
|
||||
let id = CsgNodeId(self.nodes.len() as u32);
|
||||
self.nodes.push(CsgNode::Branch {
|
||||
name: name.into(),
|
||||
op,
|
||||
children: children.into_iter().collect(),
|
||||
});
|
||||
CsgTreeBranch { node: id }
|
||||
}
|
||||
|
||||
pub fn generate_tree(&self, root: CsgNodeId) -> CsgTree {
|
||||
CsgTree { root }
|
||||
}
|
||||
|
||||
pub fn set_brush_operation_type(
|
||||
&mut self,
|
||||
brush: CsgTreeBrush,
|
||||
operation: CsgOperationType,
|
||||
) -> bool {
|
||||
let Some(CsgNode::Brush(node)) = self.node_mut(brush.node) else {
|
||||
return false;
|
||||
};
|
||||
node.op = operation.into_brush_op();
|
||||
node.set_dirty();
|
||||
true
|
||||
}
|
||||
|
||||
pub fn set_branch_operation_type(&mut self, branch: CsgTreeBranch, op: CsgBranchOp) -> bool {
|
||||
let Some(CsgNode::Branch { op: current_op, .. }) = self.node_mut(branch.node) else {
|
||||
return false;
|
||||
};
|
||||
*current_op = op;
|
||||
true
|
||||
}
|
||||
|
||||
pub fn set_child_nodes(
|
||||
&mut self,
|
||||
branch: CsgTreeBranch,
|
||||
children: impl IntoIterator<Item = CsgNodeId>,
|
||||
) -> bool {
|
||||
let Some(CsgNode::Branch {
|
||||
children: current_children,
|
||||
..
|
||||
}) = self.node_mut(branch.node)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
*current_children = children.into_iter().collect();
|
||||
true
|
||||
}
|
||||
|
||||
pub fn child_nodes(&self, branch: CsgTreeBranch) -> Option<&[CsgNodeId]> {
|
||||
let Some(CsgNode::Branch { children, .. }) = self.node(branch.node) else {
|
||||
return None;
|
||||
};
|
||||
Some(children)
|
||||
}
|
||||
|
||||
pub fn compile_tree_to_assembler(&self, tree: CsgTree) -> Assembler {
|
||||
let mut assembler = Assembler::new();
|
||||
self.compile_node(tree.root, &mut assembler, None);
|
||||
assembler
|
||||
}
|
||||
|
||||
fn compile_node(
|
||||
&self,
|
||||
id: CsgNodeId,
|
||||
assembler: &mut Assembler,
|
||||
operation_override: Option<CsgOperationType>,
|
||||
) {
|
||||
let Some(node) = self.node(id) else {
|
||||
return;
|
||||
};
|
||||
|
||||
match node {
|
||||
CsgNode::Brush(brush) => {
|
||||
let op = operation_override
|
||||
.map(CsgOperationType::into_brush_op)
|
||||
.unwrap_or(brush.op);
|
||||
assembler.add_brush(
|
||||
brush.name.clone(),
|
||||
op,
|
||||
brush.primitive.clone(),
|
||||
brush.material,
|
||||
);
|
||||
}
|
||||
CsgNode::Branch { op, children, .. } => match op {
|
||||
CsgBranchOp::Addition => {
|
||||
for child in children {
|
||||
self.compile_node(*child, assembler, operation_override);
|
||||
}
|
||||
}
|
||||
CsgBranchOp::Subtraction => {
|
||||
if let Some((first, rest)) = children.split_first() {
|
||||
self.compile_node(*first, assembler, operation_override);
|
||||
for child in rest {
|
||||
self.compile_node(
|
||||
*child,
|
||||
assembler,
|
||||
Some(CsgOperationType::Subtractive),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
CsgBranchOp::Common => {
|
||||
for child in children {
|
||||
self.compile_node(*child, assembler, Some(CsgOperationType::Intersecting));
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CsgOperationType {
|
||||
pub fn into_brush_op(self) -> BrushOp {
|
||||
match self {
|
||||
Self::Additive => BrushOp::Add,
|
||||
Self::Subtractive => BrushOp::Subtract,
|
||||
Self::Intersecting => BrushOp::Intersect,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BrushOp> for CsgOperationType {
|
||||
fn from(value: BrushOp) -> Self {
|
||||
match value {
|
||||
BrushOp::Add => Self::Additive,
|
||||
BrushOp::Subtract => Self::Subtractive,
|
||||
BrushOp::Intersect => Self::Intersecting,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bevy_math::Vec3;
|
||||
|
||||
use super::*;
|
||||
use crate::{Aabb, Primitive};
|
||||
|
||||
#[test]
|
||||
fn tree_subtraction_compiles_to_ordered_brush_stream() {
|
||||
let mut arena = CsgTreeArena::new();
|
||||
let solid = arena.generate_brush(
|
||||
"solid",
|
||||
CsgOperationType::Additive,
|
||||
Primitive::Box {
|
||||
bounds: Aabb::from_center_size(Vec3::ZERO, Vec3::splat(4.0)),
|
||||
},
|
||||
MaterialId(1),
|
||||
);
|
||||
let void = arena.generate_brush(
|
||||
"void",
|
||||
CsgOperationType::Additive,
|
||||
Primitive::Box {
|
||||
bounds: Aabb::from_center_size(Vec3::ZERO, Vec3::splat(2.0)),
|
||||
},
|
||||
MaterialId(0),
|
||||
);
|
||||
let branch = arena.generate_branch(
|
||||
"solid minus void",
|
||||
CsgBranchOp::Subtraction,
|
||||
[solid.node, void.node],
|
||||
);
|
||||
let assembler = arena.compile_tree_to_assembler(arena.generate_tree(branch.node));
|
||||
|
||||
assert_eq!(assembler.brushes().len(), 2);
|
||||
assert_eq!(assembler.brushes()[0].op, BrushOp::Add);
|
||||
assert_eq!(assembler.brushes()[1].op, BrushOp::Subtract);
|
||||
assert_eq!(assembler.build().report.emitted_convex_fragments, 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tree_edit_api_replaces_children_and_operations() {
|
||||
let mut arena = CsgTreeArena::new();
|
||||
let a = arena.generate_brush(
|
||||
"a",
|
||||
CsgOperationType::Additive,
|
||||
Primitive::Box {
|
||||
bounds: Aabb::from_center_size(Vec3::ZERO, Vec3::splat(2.0)),
|
||||
},
|
||||
MaterialId(1),
|
||||
);
|
||||
let b = arena.generate_brush(
|
||||
"b",
|
||||
CsgOperationType::Additive,
|
||||
Primitive::Box {
|
||||
bounds: Aabb::from_center_size(Vec3::X, Vec3::splat(1.0)),
|
||||
},
|
||||
MaterialId(1),
|
||||
);
|
||||
let branch = arena.generate_branch("branch", CsgBranchOp::Addition, [a.node]);
|
||||
|
||||
assert!(arena.set_child_nodes(branch, [a.node, b.node]));
|
||||
assert_eq!(arena.child_nodes(branch).expect("branch").len(), 2);
|
||||
assert!(arena.set_branch_operation_type(branch, CsgBranchOp::Subtraction));
|
||||
assert!(arena.set_brush_operation_type(b, CsgOperationType::Subtractive));
|
||||
assert_eq!(arena.brush_count(), 2);
|
||||
assert_eq!(arena.branch_count(), 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
use bevy_math::{Quat, Vec3};
|
||||
use vg_csg::{Aabb, Assembler, ConvexSolid, MaterialId, PolygonCategory};
|
||||
use vg_csg::{
|
||||
Aabb, Assembler, ConvexSolid, CsgBranchOp, CsgOperationType, CsgTreeArena, MaterialId,
|
||||
PolygonCategory, Primitive,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn parity_polygon_category_vocabulary_matches_public_demo() {
|
||||
|
|
@ -13,6 +16,44 @@ fn parity_polygon_category_vocabulary_matches_public_demo() {
|
|||
assert_eq!(categories.len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parity_operation_type_ordinals_match_public_api() {
|
||||
assert_eq!(CsgOperationType::Additive as u8, 0);
|
||||
assert_eq!(CsgOperationType::Subtractive as u8, 1);
|
||||
assert_eq!(CsgOperationType::Intersecting as u8, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parity_demo_branch_vocabulary_matches_public_demo() {
|
||||
let branches = [
|
||||
CsgBranchOp::Addition,
|
||||
CsgBranchOp::Subtraction,
|
||||
CsgBranchOp::Common,
|
||||
];
|
||||
|
||||
assert_eq!(branches.len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parity_tree_api_exposes_brush_branch_tree_handles() {
|
||||
let mut arena = CsgTreeArena::new();
|
||||
let brush = arena.generate_brush(
|
||||
"brush",
|
||||
CsgOperationType::Additive,
|
||||
Primitive::Box {
|
||||
bounds: Aabb::from_center_size(Vec3::ZERO, Vec3::ONE),
|
||||
},
|
||||
MaterialId(1),
|
||||
);
|
||||
let branch = arena.generate_branch("branch", CsgBranchOp::Addition, [brush.node]);
|
||||
let tree = arena.generate_tree(branch.node);
|
||||
|
||||
assert_eq!(arena.brush_count(), 1);
|
||||
assert_eq!(arena.branch_count(), 1);
|
||||
assert_eq!(arena.child_nodes(branch).expect("branch"), &[brush.node]);
|
||||
assert_eq!(tree.root, branch.node);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parity_box_brush_observable_counts_match_realtime_csg_demo() {
|
||||
let solid = ConvexSolid::box_from_center_size(
|
||||
|
|
|
|||
|
|
@ -13,14 +13,16 @@ fn main() {
|
|||
.emit(&ctx, &mut tree);
|
||||
|
||||
let compiled = tree.compile();
|
||||
let tree_compiled = tree.compile_csg_tree().expect("example emits claims");
|
||||
let output = compiled.assembler.build();
|
||||
|
||||
println!(
|
||||
"claims={} solids={} voids={} brushes={} vertices={} triangles={} warnings={}",
|
||||
"claims={} solids={} voids={} brushes={} tree_nodes={} vertices={} triangles={} warnings={}",
|
||||
tree.claims().len(),
|
||||
compiled.solid_claims,
|
||||
compiled.void_claims,
|
||||
compiled.brush_ids.len(),
|
||||
tree_compiled.arena.nodes().len(),
|
||||
output.mesh.vertex_count(),
|
||||
output.mesh.triangle_count(),
|
||||
output.report.warnings.len()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
use bevy_math::{Quat, Vec3};
|
||||
use vg_csg::{Assembler, BrushId, MaterialId};
|
||||
use vg_csg::{
|
||||
Assembler, BrushId, CsgBranchOp, CsgNodeId, CsgOperationType, CsgTree, CsgTreeArena,
|
||||
CsgTreeBranch, MaterialId, Primitive,
|
||||
};
|
||||
|
||||
use crate::Frame;
|
||||
|
||||
|
|
@ -177,6 +180,53 @@ impl ClaimTree {
|
|||
void_claims: self.count_kind(ClaimKind::Void),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compile_csg_tree(&self) -> Option<TreeCompileReport> {
|
||||
if self.claims.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut arena = CsgTreeArena::new();
|
||||
let mut solid_nodes = Vec::new();
|
||||
let mut void_nodes = Vec::new();
|
||||
|
||||
for claim in &self.claims {
|
||||
let primitive = claim.primitive();
|
||||
let brush = arena.generate_brush(
|
||||
&claim.name,
|
||||
CsgOperationType::Additive,
|
||||
primitive,
|
||||
claim.material,
|
||||
);
|
||||
|
||||
match claim.kind {
|
||||
ClaimKind::Solid => solid_nodes.push(brush.node),
|
||||
ClaimKind::Void => void_nodes.push(brush.node),
|
||||
}
|
||||
}
|
||||
|
||||
let solid_root = branch_or_single(&mut arena, "solids", CsgBranchOp::Addition, solid_nodes);
|
||||
let root = if void_nodes.is_empty() {
|
||||
solid_root
|
||||
} else {
|
||||
let void_root =
|
||||
branch_or_single(&mut arena, "voids", CsgBranchOp::Addition, void_nodes);
|
||||
arena
|
||||
.generate_branch(
|
||||
"grammar result",
|
||||
CsgBranchOp::Subtraction,
|
||||
[solid_root, void_root],
|
||||
)
|
||||
.node
|
||||
};
|
||||
|
||||
Some(TreeCompileReport {
|
||||
tree: arena.generate_tree(root),
|
||||
arena,
|
||||
solid_claims: self.count_kind(ClaimKind::Solid),
|
||||
void_claims: self.count_kind(ClaimKind::Void),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -187,6 +237,52 @@ pub struct CompileReport {
|
|||
pub void_claims: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TreeCompileReport {
|
||||
pub arena: CsgTreeArena,
|
||||
pub tree: CsgTree,
|
||||
pub solid_claims: usize,
|
||||
pub void_claims: usize,
|
||||
}
|
||||
|
||||
impl TreeCompileReport {
|
||||
pub fn compile_to_assembler(&self) -> Assembler {
|
||||
self.arena.compile_tree_to_assembler(self.tree)
|
||||
}
|
||||
}
|
||||
|
||||
fn branch_or_single(
|
||||
arena: &mut CsgTreeArena,
|
||||
name: &str,
|
||||
op: CsgBranchOp,
|
||||
nodes: Vec<CsgNodeId>,
|
||||
) -> CsgNodeId {
|
||||
if nodes.len() == 1 {
|
||||
nodes[0]
|
||||
} else {
|
||||
CsgTreeBranch {
|
||||
node: arena.generate_branch(name, op, nodes).node,
|
||||
}
|
||||
.node
|
||||
}
|
||||
}
|
||||
|
||||
impl Claim {
|
||||
fn primitive(&self) -> Primitive {
|
||||
if self.is_axis_aligned() {
|
||||
Primitive::Box {
|
||||
bounds: vg_csg::Aabb::from_center_size(self.center, self.size),
|
||||
}
|
||||
} else {
|
||||
Primitive::OrientedBox {
|
||||
center: self.center,
|
||||
size: self.size,
|
||||
rotation: self.rotation,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bevy_math::Vec3;
|
||||
|
|
@ -215,6 +311,27 @@ mod tests {
|
|||
assert_eq!(report.assembler.brushes().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn claim_tree_compiles_nested_csg_tree_intent() {
|
||||
let mut tree = ClaimTree::new();
|
||||
tree.push(Claim::solid_box(
|
||||
"wall",
|
||||
Vec3::ZERO,
|
||||
Vec3::new(4.0, 0.25, 3.0),
|
||||
MaterialId(1),
|
||||
));
|
||||
tree.push(Claim::void_box(
|
||||
"door",
|
||||
Vec3::new(0.0, 0.0, -0.25),
|
||||
Vec3::new(1.0, 0.5, 1.5),
|
||||
));
|
||||
|
||||
let report = tree.compile_csg_tree().expect("non-empty tree");
|
||||
assert_eq!(report.solid_claims, 1);
|
||||
assert_eq!(report.void_claims, 1);
|
||||
assert_eq!(report.compile_to_assembler().brushes().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oriented_claims_compile_to_oriented_brushes() {
|
||||
let mut tree = ClaimTree::new();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ mod context;
|
|||
mod frame;
|
||||
mod rules;
|
||||
|
||||
pub use claim::{Claim, ClaimKind, ClaimTag, ClaimTree, CompileReport};
|
||||
pub use claim::{Claim, ClaimKind, ClaimTag, ClaimTree, CompileReport, TreeCompileReport};
|
||||
pub use context::{GrammarContext, Materials};
|
||||
pub use frame::Frame;
|
||||
pub use rules::{CorridorSpec, DoorSpec, GalleryChainSpec, RoomSpec, Rule, RuleSet};
|
||||
|
|
|
|||
|
|
@ -405,11 +405,13 @@ mod tests {
|
|||
);
|
||||
|
||||
let report = tree.compile();
|
||||
let tree_report = tree.compile_csg_tree().expect("claims compile to tree");
|
||||
let output = report.assembler.build();
|
||||
let door_void = Aabb::from_center_size(Vec3::new(3.0, 0.0, 1.1), Vec3::new(0.7, 1.4, 2.2));
|
||||
|
||||
assert!(output.mesh.triangle_count() > 60);
|
||||
assert!(output.report.warnings.is_empty());
|
||||
assert!(tree_report.arena.nodes().len() > report.brush_ids.len());
|
||||
for tri in output.mesh.indices.chunks_exact(3) {
|
||||
let center = (output.mesh.positions[tri[0] as usize]
|
||||
+ output.mesh.positions[tri[1] as usize]
|
||||
|
|
@ -433,9 +435,11 @@ mod tests {
|
|||
assert!(tree.claims().iter().any(|claim| !claim.is_axis_aligned()));
|
||||
|
||||
let report = tree.compile();
|
||||
let tree_report = tree.compile_csg_tree().expect("claims compile to tree");
|
||||
let output = report.assembler.build();
|
||||
assert!(output.mesh.triangle_count() > 150);
|
||||
assert!(output.report.warnings.is_empty());
|
||||
assert!(tree_report.arena.nodes().len() > report.brush_ids.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -34,6 +34,18 @@ The first expansion adds local `Frame`s, deterministic seeded variation, and
|
|||
`RuleSet`/`GalleryChainSpec` composition. This is the rule: every richer grammar
|
||||
feature must sharpen spatial intent before it increases mesh complexity.
|
||||
|
||||
The second expansion adds generated CSG tree intent. `ClaimTree` can still
|
||||
compile to the flat assembler stream for the current backend, but it can also
|
||||
emit a `CsgTreeArena` where solids are grouped under addition, voids are grouped
|
||||
under addition, and the result is represented as `solids - voids`. This is the
|
||||
bridge from grammar-as-list to grammar-as-boolean-program.
|
||||
|
||||
Current example output:
|
||||
|
||||
```text
|
||||
claims=42 solids=36 voids=6 brushes=42 tree_nodes=45
|
||||
```
|
||||
|
||||
The rule is simple: future procedural generators should feed CSG with authored
|
||||
space claims instead of bypassing the tree with final triangles. Cities,
|
||||
habitats, corridors, and districts can grow from fields and grammars, but hard
|
||||
|
|
|
|||
|
|
@ -247,6 +247,20 @@ Process brush:
|
|||
emit visible pieces into render mesh
|
||||
```
|
||||
|
||||
`vg_csg` now exposes the first version of that public tree surface:
|
||||
|
||||
- `CsgOperationType::{Additive, Subtractive, Intersecting}` with parity-tested
|
||||
ordinals matching the public API
|
||||
- `CsgBranchOp::{Addition, Subtraction, Common}` matching the public demo
|
||||
- `CsgTreeArena`, `CsgTree`, `CsgTreeBranch`, `CsgTreeBrush`, and `CsgNodeId`
|
||||
- branch child replacement and operation mutation
|
||||
- brush operation mutation
|
||||
- compilation from tree intent into the current ordered assembler backend
|
||||
|
||||
This is still not the final classifier kernel. It is the API skeleton that lets
|
||||
grammar and editor code speak in RealtimeCSG-shaped boolean trees while the
|
||||
backend grows into the category router.
|
||||
|
||||
Algorithm migration steps:
|
||||
|
||||
1. Add polygon categories and visible/reversed flags to `vg_csg`.
|
||||
|
|
|
|||
|
|
@ -43,10 +43,11 @@ handles Blender scene machinery and evaluated evidence.
|
|||
RealtimeCSG's public Unity repo exposes a useful brush/tree/operation/generation
|
||||
model, but not the optimized native C++ kernel or a supported runtime editing
|
||||
API. Sander van Rossen's older public `LogicalError/Realtime-CSG-demo` and blog
|
||||
series are now the preferred clean research inputs. Current `vg_csg`: ordered
|
||||
brushes, exact AABB and oriented-box subtraction via convex plane splitting,
|
||||
additive `CylinderZ`, `DomeCapZ`, and `FloretArm` primitives, Bevy-math mesh
|
||||
buffers, `LevelDsl`, tests, clippy, and an example room. Research note:
|
||||
series are now the preferred clean research inputs. Current `vg_csg`: public
|
||||
CSG operation/branch/tree/brush handle surface, child and operation mutation,
|
||||
ordered assembler backend, exact AABB and oriented-box subtraction via convex
|
||||
plane splitting, additive `CylinderZ`, `DomeCapZ`, and `FloretArm` primitives,
|
||||
Bevy-math mesh buffers, tests, clippy, and examples. Research note:
|
||||
`docs/research/realtime-csg-bevy-assembler.md`.
|
||||
Where `vg_csg` overlaps public RealtimeCSG/demo behavior, add exact observable
|
||||
parity fixtures instead of approximate plausibility tests.
|
||||
|
|
@ -64,10 +65,10 @@ Repo-local Geometry Script clone notes live in
|
|||
`.\tools\setup_geometry_script_clone.ps1` if `external/geometry-script` is
|
||||
missing.
|
||||
|
||||
The current next action is to add generated CSG tree structure to `vg_grammar`
|
||||
and explicit polygon categories to `vg_csg`: grammar should emit nested boolean
|
||||
intent instead of only a flat brush list, while the kernel should classify
|
||||
source polygons through that tree.
|
||||
The current next action is to replace the ordered assembler backend with the
|
||||
category-router kernel behind the existing CSG tree API: implement source
|
||||
polygon categories, visible/reversed flags, brush/branch bounds, and
|
||||
boolean-tree classification while preserving current parity fixtures.
|
||||
|
||||
## Important Invariants
|
||||
|
||||
|
|
|
|||
|
|
@ -54,3 +54,4 @@
|
|||
{"ts": "2026-05-07T00:12:44+00:00", "type": "implementation", "status": "accepted", "note": "Built the first Dream Machine grammar layer: new vg_grammar crate with semantic solid/void ClaimTree, GrammarContext materials, RoomSpec/CorridorSpec/DoorSpec rules, a dream_room example, and tests proving grammar emits claims that compile into vg_csg brushes and leave doorway voids empty. The authoring split is now grammar writes spatial claims, CSG adjudicates matter, mesh is cache."}
|
||||
{"ts": "2026-05-07T00:19:35+00:00", "type": "implementation", "status": "accepted", "note": "Extended the Dream Machine grammar with local frames, oriented claims, deterministic seeded variation, RuleSet composition, and GalleryChainSpec. The dream_room example now emits a rotated four-room chain as 42 semantic claims into vg_csg; workspace tests and clippy prove the grammar still preserves void claims through CSG assembly."}
|
||||
{"ts": "2026-05-07T00:21:11+00:00", "type": "implementation", "status": "accepted", "note": "Added exact parity testing doctrine and first vg_csg parity fixtures for public RealtimeCSG-overlapping seams: polygon category vocabulary, six-plane/six-polygon box brush counts, and six surviving regions for centered box subtraction. Future matching API surface should get countable parity fixtures, not approximate plausibility checks."}
|
||||
{"ts": "2026-05-07T00:31:59+00:00", "type": "implementation", "status": "accepted", "note": "Expanded the Rust API toward RealtimeCSG shape: added CsgTreeArena, CsgTree/CsgTreeBranch/CsgTreeBrush handles, CsgOperationType ordinals, CsgBranchOp vocabulary, branch child/operation mutation, brush operation mutation, tree-to-assembler compilation, grammar ClaimTree CSG tree emission, and parity fixtures for operation ordinals, branch vocabulary, and handle topology."}
|
||||
|
|
|
|||
|
|
@ -110,8 +110,8 @@ data_flow:
|
|||
- If state grows faster than understanding, cut it back.
|
||||
|
||||
current_status:
|
||||
summary: VibeGeometry has verified Geometry Script translations for local samples, official Blender demos, and IRCSS French Houses footholds, plus from-scratch Aetheria Bloom and Lucent tether habitat builds. Durable lessons now driving the pipeline: Python orchestrates intent and batching; Geometry Script emits inspectable node groups; source-bound scenes need explicit coordinate contracts before ornament; spin-gravity habitats need ground planes orthogonal to their tether/rotation axis; utility petals, radiators, and solar arrays belong outside pressure glass and may need Citadel-scale presence; large habitat parts need visible load paths across coordinate frames; organic city maps need street fields, irregular parcels, parks, and land-use gradients rather than grids; dense detail must be batched; institutional spaces should model power as surfaces, rails, overlays, thresholds, shader behavior, and camera evidence; and visual acceptance needs domain-facing inspection renders plus verifier checks, not only overview renders. The first reusable `vibegeometry/` helper library now carries coordinate frames, fields, batching, Blender scene primitives, and verifier helpers used by the Bloom and Lucent builds. The Rust crate `vg_csg` now has a convex-brush stepping-stone kernel: RealtimeCSG-inspired ordered brushes, operation types, generation tracking, exact AABB and oriented-box subtraction via convex plane splitting, additive cylinder/dome/floret primitives, mesh-array output, DSL coverage, tests, clippy, and a sample room. Exact parity fixtures now guard public RealtimeCSG-overlapping seams such as category vocabulary, box brush counts, and centered box subtraction regions. The `vg_grammar` crate is the Dream Machine authoring layer: semantic solid/void claims with tags compile into `vg_csg`; it now supports local frames, oriented claims, deterministic seeded variation, rule composition, and generated gallery chains. Public RealtimeCSG demo/source research points the target away from fragment carving and toward faster polygon classification through boolean trees. Known graph-tooling blockers remain repeat-zone feedback, repeat Top outputs, foreach zones, and gizmo nodes.
|
||||
next_action: Add generated CSG tree structure to `vg_grammar` and explicit polygon categories to `vg_csg`: grammar should emit nested boolean intent instead of only a flat brush list, while the kernel should classify source polygons through that tree.
|
||||
summary: VibeGeometry has verified Geometry Script translations for local samples, official Blender demos, and IRCSS French Houses footholds, plus from-scratch Aetheria Bloom and Lucent tether habitat builds. Durable lessons now driving the pipeline: Python orchestrates intent and batching; Geometry Script emits inspectable node groups; source-bound scenes need explicit coordinate contracts before ornament; spin-gravity habitats need ground planes orthogonal to their tether/rotation axis; utility petals, radiators, and solar arrays belong outside pressure glass and may need Citadel-scale presence; large habitat parts need visible load paths across coordinate frames; organic city maps need street fields, irregular parcels, parks, and land-use gradients rather than grids; dense detail must be batched; institutional spaces should model power as surfaces, rails, overlays, thresholds, shader behavior, and camera evidence; and visual acceptance needs domain-facing inspection renders plus verifier checks, not only overview renders. The first reusable `vibegeometry/` helper library now carries coordinate frames, fields, batching, Blender scene primitives, and verifier helpers used by the Bloom and Lucent builds. The Rust crate `vg_csg` now has a RealtimeCSG-shaped API skeleton plus a convex-brush stepping-stone kernel: CSG operation ordinals, branch vocabulary, tree/branch/brush handles, child and operation mutation, exact parity fixtures, ordered assembler compilation, AABB/oriented-box subtraction via convex plane splitting, additive cylinder/dome/floret primitives, mesh-array output, tests, clippy, and examples. The `vg_grammar` crate is the Dream Machine authoring layer: semantic solid/void claims with tags compile into flat `vg_csg` brushes or generated CSG tree intent; it supports local frames, oriented claims, deterministic seeded variation, rule composition, and generated gallery chains. Public RealtimeCSG demo/source research points the target away from fragment carving and toward faster polygon classification through boolean trees. Known graph-tooling blockers remain repeat-zone feedback, repeat Top outputs, foreach zones, and gizmo nodes.
|
||||
next_action: Replace the ordered assembler backend with the category-router kernel behind the existing CSG tree API: implement source polygon categories, visible/reversed flags, brush/branch bounds, and boolean-tree classification while preserving current parity fixtures.
|
||||
remotes:
|
||||
vibegeometry: https://github.com/GameCult/VibeGeometry
|
||||
geometry_script_fork: https://github.com/GameCult/geometry-script
|
||||
|
|
|
|||
Loading…
Reference in a new issue