Struct three::scene::SyncGuard

source ·
pub struct SyncGuard<'a> { /* private fields */ }
Expand description

SyncGuard is used to obtain information about scene nodes in the most effective way.

Examples

Imagine that you have your own helper type Enemy:

struct Enemy {
    mesh: three::Mesh,
    is_visible: bool,
}

You need this wrapper around three::Mesh to cache some information - in our case, visibility.

In your game you contain all your enemy objects in Vec<Enemy>. In the main loop you need to iterate over all the enemies and make them visible or not, basing on current position. The most obvious way is to use object::Base::sync, but it’s not the best idea from the side of performance. Instead, you can create SyncGuard and use its resolve method to effectively walk through every enemy in your game:

let mut sync = win.scene.sync_guard();
for mut enemy in &mut enemies {
    let node = sync.resolve(enemy);
    let position = node.transform.position;
    if position.x > 10.0 {
        enemy.is_visible = false;
        enemy.set_visible(false);
    } else {
        enemy.is_visible = true;
        enemy.set_visible(true);
    }
}

Implementations

Obtains objects’s local space Node in an effective way.

Panics

Panics if scene doesn’t have this object::Base.

Obtains objects’s world Node by traversing the scene graph. Note: this can be slow.

Panics

Panics if the scene doesn’t have this object::Base.

Obtains internal state data for object.

Three-rs objects normally expose a write-only interface, making it possible to change an object’s internal values but not possible to read those values. SyncGuard allows for that data to be read in a controlled way.

Each object type has its own internal data, and not all object types can provide access to meaningful data. The following types provide specific data you can use:

The other object types do not have a user-facing way to represent their internal data, and so return ().

Returns an iterator that walks all the objects in root’s hierarchy.

Walks the children of root, recursively walking the children of any Group objects found until all objects in the hierarchy have been visited. The hierarchy is walked depth-first, and objects are yielded in the order they are visited.

Finds a node in a group, or any of its children, by name.

Performs a depth-first search starting with root looking for an object with name. Returns the Base for the first object found with a matching name, otherwise returns None if no such object is found. Note that if more than one such object exists in the hierarchy, then only the first one discovered will be returned.

Returns an iterator of all objects under root with the specified name.

Performs a depth-first search starting with root, yielding each object in the hierarchy matching name.

Finds the first object in a group, or any of its children, of type T.

Performs a depth-first search starting with root, recusively descending into any Group objects found. Returns the first object of type T encountered in the hierarchy.

Returns an iterator yielding all objects in the hierarchy of root of type T.

Performs a depth-first search starting with root, recursively descending into any Group objects found, yielding each object of type T found in the hierarchy.

Attempts to find an object of type T in the group or any of its children.

Performs a depth-first search starting with root, recursively searching Group objects, until an object of type T that matches name is found. Note that if T is Group and root matches name, then it will be returned.

Returns an iterator yielding all children of root of type T named name.

Performs a depth-first search starting with root, recursively searching Group objects, yielding any objects of T that match name. Note that if T is Group and root matches name, then it will be the first object yielded by the iterator.

Attempts to downcast a Base to its concrete object type.

If the downcast succeeds, the concrete object is returned. Returns None if the downcast fails.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Sets value as a parameter of self.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.