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
sourceimpl<'a> SyncGuard<'a>
impl<'a> SyncGuard<'a>
sourcepub fn resolve_data<T: 'a + Object>(&self, object: &T) -> T::Data
pub fn resolve_data<T: 'a + Object>(&self, object: &T) -> T::Data
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:
Base
: Returns anObjectType
, which provides access to the concrete object type forobject
.Group
: Returns a list of the group’s direct children.Camera
: Returns theProjection
for the camera.Ambient
: Returns theLightData
for the light.Point
: Returns theLightData
for the light.Directional
: Returns theLightData
for the light.Hemisphere
: Returns theHemisphereLightData
for the light.
The other object types do not have a user-facing way to represent their internal data,
and so return ()
.
sourcepub fn walk_hierarchy(&'a self, root: &Group) -> impl Iterator<Item = Base> + 'a
pub fn walk_hierarchy(&'a self, root: &Group) -> impl Iterator<Item = Base> + 'a
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.
sourcepub fn find_child_by_name(&self, root: &Group, name: &str) -> Option<Base>
pub fn find_child_by_name(&self, root: &Group, name: &str) -> Option<Base>
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.
sourcepub fn find_children_by_name(
&'a self,
root: &Group,
name: &'a str
) -> impl Iterator<Item = Base> + 'a
pub fn find_children_by_name(
&'a self,
root: &Group,
name: &'a str
) -> impl Iterator<Item = Base> + 'a
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
.
sourcepub fn find_child_of_type<T: DowncastObject>(&'a self, root: &Group) -> Option<T>
pub fn find_child_of_type<T: DowncastObject>(&'a self, root: &Group) -> Option<T>
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.
sourcepub fn find_children_of_type<T: DowncastObject>(
&'a self,
root: &Group
) -> impl Iterator<Item = T> + 'a
pub fn find_children_of_type<T: DowncastObject>(
&'a self,
root: &Group
) -> impl Iterator<Item = T> + 'a
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.
sourcepub fn find_child_of_type_by_name<T: DowncastObject>(
&'a self,
root: &Group,
name: &'a str
) -> Option<T>
pub fn find_child_of_type_by_name<T: DowncastObject>(
&'a self,
root: &Group,
name: &'a str
) -> Option<T>
sourcepub fn find_children_of_type_by_name<T: DowncastObject>(
&'a self,
root: &Group,
name: &'a str
) -> impl Iterator<Item = T> + 'a
pub fn find_children_of_type_by_name<T: DowncastObject>(
&'a self,
root: &Group,
name: &'a str
) -> impl Iterator<Item = T> + 'a
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.
Auto Trait Implementations
impl<'a> !RefUnwindSafe for SyncGuard<'a>
impl<'a> !Send for SyncGuard<'a>
impl<'a> !Sync for SyncGuard<'a>
impl<'a> Unpin for SyncGuard<'a>
impl<'a> !UnwindSafe for SyncGuard<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> Pointable for T
impl<T> Pointable for T
impl<T> SetParameter for T
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Resultwhere
T: Parameter<Self>,
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Resultwhere
T: Parameter<Self>,
value
as a parameter of self
.