Struct three::scene::SyncGuard [] [src]

pub struct SyncGuard<'a> { /* fields omitted */ }

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);
    }
}

Methods

impl<'a> SyncGuard<'a>
[src]

[src]

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

Panics

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

[src]

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

Panics

Panics if the doesn't have this object::Base.

Trait Implementations

Auto Trait Implementations

impl<'a> !Send for SyncGuard<'a>

impl<'a> !Sync for SyncGuard<'a>