bevy_symbios_shape 0.6.0

Bevy integration for Symbios Shape.
Documentation
//! Spatial query view over the most recently derived [`ShapeModel`].
//!
//! After every [`SpawnShapeExt::spawn_shape`] call, the full upstream model
//! is stored in the [`LastDerivedModel`] resource so downstream systems can
//! ask spatial questions about the spawned terminals (e.g. "does this
//! prospective placement collide with any emitted terminal?") without
//! re-deriving the grammar.
//!
//! For low-level access, the upstream [`symbios_shape::TerminalQuery`] and
//! [`symbios_shape::obb_overlap`] are re-exported from the crate root.
//!
//! [`ShapeModel`]: symbios_shape::ShapeModel
//! [`SpawnShapeExt::spawn_shape`]: crate::spawner::SpawnShapeExt::spawn_shape

use bevy::prelude::Resource;
use symbios_shape::{Scope, ShapeModel, TerminalQuery};

/// Resource holding the most recently derived [`ShapeModel`].
///
/// Overwritten on every [`SpawnShapeExt::spawn_shape`] call (last-spawn wins).
/// Initialised empty by [`BevySymbiosShapePlugin`].
///
/// Field 0 is `pub` so callers can use the upstream
/// [`ShapeModel`]/[`TerminalQuery`] APIs directly without going through this
/// wrapper.
///
/// [`SpawnShapeExt::spawn_shape`]: crate::spawner::SpawnShapeExt::spawn_shape
/// [`BevySymbiosShapePlugin`]: crate::BevySymbiosShapePlugin
#[derive(Resource, Debug, Default, Clone)]
pub struct LastDerivedModel(pub ShapeModel);

impl LastDerivedModel {
    /// Borrow the underlying model.
    pub fn model(&self) -> &ShapeModel {
        &self.0
    }

    /// Returns a [`TerminalQuery`] view over the model's terminals.
    pub fn query(&self) -> TerminalQuery<'_> {
        self.0.query()
    }

    /// Convenience: returns `true` if any terminal's OBB overlaps `scope`.
    /// Equivalent to `self.query().overlaps(scope)`.
    pub fn overlaps(&self, scope: &Scope) -> bool {
        self.0.query().overlaps(scope)
    }
}