Skip to main content

SceneModel

Struct SceneModel 

Source
pub struct SceneModel {
    pub kind: SceneKind,
    pub format: Option<u8>,
    pub uid: Option<SmolStr>,
    pub script_class: Option<SmolStr>,
    pub resource_type: Option<SmolStr>,
    pub ext_resources: FxHashMap<ExtId, ExtResource>,
    pub sub_resources: FxHashMap<ExtId, SubResource>,
    pub nodes: Vec<SceneNode>,
    pub root: Option<NodeIdx>,
    pub by_path: FxHashMap<SmolStr, NodeIdx>,
    pub unique_nodes: FxHashMap<SmolStr, NodeIdx>,
    pub problems: Vec<SceneProblem>,
    /* private fields */
}
Expand description

One parsed .tscn/.tres. Produced by crate::parse_scene; never an Err — every malformed/binary/unknown form degrades to an empty-or-partial model plus a SceneProblem. PartialEq/Eq so it can be a backdated salsa query result (Arc<SceneModel>) in M1.

Fields§

§kind: SceneKind

Scene vs resource (from the header tag).

§format: Option<u8>

The format= version: >=3 is the Godot-4.x family, 2 is 3.x, None if absent.

§uid: Option<SmolStr>

The scene/resource uid="uid://…", if present.

§script_class: Option<SmolStr>

The header script_class="…" shortcut — the root/resource’s class_name without resolving the script file.

§resource_type: Option<SmolStr>

A .tres’s own resource class (gd_resource type="…").

§ext_resources: FxHashMap<ExtId, ExtResource>

id → ext_resource (external scripts, packed scenes, textures, …).

§sub_resources: FxHashMap<ExtId, SubResource>

id → sub_resource type (the value body is skipped — we keep only the declared type).

§nodes: Vec<SceneNode>

Every node, in file order (which is tree pre-order for siblings). index = NodeIdx.0.

§root: Option<NodeIdx>

The single parent-less node, if the scene has one.

§by_path: FxHashMap<SmolStr, NodeIdx>

Full name-path from the root ("Panel/VBox/StartButton", root name excluded) → node.

§unique_nodes: FxHashMap<SmolStr, NodeIdx>

unique_name_in_owner nodes: bare name → node (the %Name lookup; scene-wide in the slice).

§problems: Vec<SceneProblem>

Non-fatal problems found while parsing (the parser never errors).

Implementations§

Source§

impl SceneModel

Source

pub fn node(&self, idx: NodeIdx) -> Option<&SceneNode>

The node at idx, if it exists.

Source

pub fn resolve_path(&self, path: &str) -> Option<NodeIdx>

Walk a name-path from the scene root. ""/"." ⇒ the root. None ⇒ no such node (M1 reads that as “degrade to Node”, never an error). A leading / (absolute) or a .. segment is out of the slice and yields None.

Source

pub fn resolve_path_from(&self, base: NodeIdx, path: &str) -> Option<NodeIdx>

Walk a name-path from an arbitrary base node (the node a script attaches to — $X is relative to that node, which is usually but not always the root). A %Name segment is a unique-name lookup (scene-wide, owner-relative), so the idiomatic Foo/%Bar and the string forms $"%Bar" / get_node("%Bar") resolve like the engine; a plain segment is a child lookup.

Source

pub fn resolve_unique(&self, path: &str) -> Option<NodeIdx>

Resolve a %-sigil path (%Name / %Name/Child/…). The leading segment is a unique name even though the % sigil was a separate token (so it isn’t in path); subsequent segments walk as normal children. Delegates to the %-aware resolve_path_from.

Source

pub fn node_with_script(&self, script_path: &str) -> Option<NodeIdx>

The node whose body script = ExtResource(id) resolves (via ext_resources[id].path) to script_path — the per-scene half of the script↔scene association.

Source

pub fn children_of( &self, idx: Option<NodeIdx>, ) -> impl Iterator<Item = (NodeIdx, &SceneNode)>

The child nodes of idx (None ⇒ the root’s children), in file order.

Source

pub fn classify_path_from( &self, base: NodeIdx, path: &str, ) -> NodePathResolution

Resolve a name-path from base, distinguishing the reason a path doesn’t resolve — so a caller can warn on a genuine Missing node while staying silent on an Escaped (../absolute) or an IntoInstance override (the M1 typing uses resolve_path_from; this is for the INVALID_NODE_PATH decision).

Source

pub fn classify_unique(&self, path: &str) -> NodePathResolution

Resolve a %-sigil path (%Name / %Name/Child). The leading segment is a unique name (the % sigil was a separate token, so it isn’t in path); subsequent segments walk as children. A missing leading unique name is genuinely Missing (no instance ambiguity — % is scene-wide).

Source

pub fn resolve_into_instance( &self, base: NodeIdx, path: &str, ) -> Option<(NodeIdx, String)>

If walking path from base descends INTO an instanced sub-scene — the walk reaches an instance node whose next (plain) child segment lives inside that sub-scene — return (instance_node, remaining_tail) so the caller can continue the walk in the sub-scene’s own tree ($Enemy/Sprite → resolve Enemy, then resolve Sprite in enemy.tscn). None if the path resolves wholly within this scene, escapes (../absolute), or misses somewhere that is not exactly an instance node — an override child under an instance stays unresolved here (typed Node, no false warning), since mapping it back into the sub-scene needs more than the boundary node. The boundary returned is the instance node itself.

Source

pub fn resolve_unique_into_instance( &self, path: &str, ) -> Option<(NodeIdx, String)>

The %-sigil counterpart of resolve_into_instance: a %Unique/Tail whose %Unique is an instance node and Tail descends into the sub-scene.

Trait Implementations§

Source§

impl Clone for SceneModel

Source§

fn clone(&self) -> SceneModel

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SceneModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SceneModel

Source§

impl PartialEq for SceneModel

Source§

fn eq(&self, other: &SceneModel) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for SceneModel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.