pub struct ObjectRef(/* private fields */);Expand description
One node of the scene graph: three.js’ Object3D reference, a newtype over
Rc<RefCell<Object3D>>.
Every inherent method here is the port of a three.js Object3D method that
reads or writes parent/children; the transform-only methods stay inherent
methods on Object3D itself. They live on the handle rather than on
&mut Object3D because every one of them needs to reach outside the object
it is called on — up to the parent or down into the children — which a
&mut Object3D cannot do.
ObjectRef derefs to RefCell<Object3D>, so node.borrow() and
node.borrow_mut() reach the object exactly as they did when ObjectRef was a
type alias.
Implementations§
Source§impl ObjectRef
impl ObjectRef
Sourcepub fn ptr_eq(a: &ObjectRef, b: &ObjectRef) -> bool
pub fn ptr_eq(a: &ObjectRef, b: &ObjectRef) -> bool
a === b: whether two handles are the same object. Was Rc::ptr_eq.
Sourcepub fn downgrade(&self) -> WeakObjectRef
pub fn downgrade(&self) -> WeakObjectRef
The weak handle Object3D.parent holds.
Sourcepub fn as_ptr(&self) -> *const RefCell<Object3D>
pub fn as_ptr(&self) -> *const RefCell<Object3D>
The address of the object, for a consumer keying a cache on identity.
Note that an address is only unique among live nodes — see
docs/scene-graph.md, “Identity and eviction”; object.id is the
collision-free key the renderer itself uses.
Sourcepub fn children(&self) -> Vec<ObjectRef>
pub fn children(&self) -> Vec<ObjectRef>
Object3D.children, cloned (cheap: a Vec of Rcs). Cloning is what
lets a traversal run without holding a borrow on the parent.
Sourcepub fn remove_from_parent(&self) -> &Self
pub fn remove_from_parent(&self) -> &Self
Object3D.removeFromParent().
Sourcepub fn add_event_listener(
&self,
ty: SceneEventType,
listener: impl Fn(&SceneEvent, &ObjectRef) + 'static,
) -> ListenerHandle
pub fn add_event_listener( &self, ty: SceneEventType, listener: impl Fn(&SceneEvent, &ObjectRef) + 'static, ) -> ListenerHandle
EventDispatcher.addEventListener( type, listener ): listener is
called with every event of type ty dispatched on this object, and
with the object itself (three’s event.target). The returned handle
stands for the listener in remove_event_listener and
has_event_listener.
Sourcepub fn has_event_listener(
&self,
ty: SceneEventType,
handle: ListenerHandle,
) -> bool
pub fn has_event_listener( &self, ty: SceneEventType, handle: ListenerHandle, ) -> bool
EventDispatcher.hasEventListener( type, listener ).
Sourcepub fn remove_event_listener(&self, ty: SceneEventType, handle: ListenerHandle)
pub fn remove_event_listener(&self, ty: SceneEventType, handle: ListenerHandle)
EventDispatcher.removeEventListener( type, listener ). A handle that
is not registered for ty is ignored, as three ignores an unknown
listener. Safe to call from inside a listener, on itself or any other:
a dispatch already under way still calls every listener it started
with.
Sourcepub fn dispatch_event(&self, event: &SceneEvent)
pub fn dispatch_event(&self, event: &SceneEvent)
EventDispatcher.dispatchEvent( event ): calls every listener of the
event’s type, in the order they were added, with this node as the
target. The list is copied first and no borrow of the object is held
during the calls, so a listener may borrow the node, change the tree
(which dispatches again) or add and remove listeners.
Sourcepub fn get_object_by_id(&self, id: u32) -> Option<ObjectRef>
pub fn get_object_by_id(&self, id: u32) -> Option<ObjectRef>
Object3D.getObjectById( id ).
Sourcepub fn get_object_by_name(&self, name: &str) -> Option<ObjectRef>
pub fn get_object_by_name(&self, name: &str) -> Option<ObjectRef>
Object3D.getObjectByName( name ).
Sourcepub fn get_object_by_property(
&self,
test: &dyn Fn(&Object3D) -> bool,
) -> Option<ObjectRef>
pub fn get_object_by_property( &self, test: &dyn Fn(&Object3D) -> bool, ) -> Option<ObjectRef>
Object3D.getObjectByProperty( name, value ). Rust has no dynamic
property lookup, so the property test is a predicate.
Sourcepub fn get_objects_by_property(
&self,
test: &dyn Fn(&Object3D) -> bool,
) -> Vec<ObjectRef>
pub fn get_objects_by_property( &self, test: &dyn Fn(&Object3D) -> bool, ) -> Vec<ObjectRef>
Object3D.getObjectsByProperty( name, value, result ).
Sourcepub fn traverse_visible(&self, callback: &mut dyn FnMut(&ObjectRef))
pub fn traverse_visible(&self, callback: &mut dyn FnMut(&ObjectRef))
Object3D.traverseVisible( callback ).
Sourcepub fn traverse_ancestors(&self, callback: &mut dyn FnMut(&ObjectRef))
pub fn traverse_ancestors(&self, callback: &mut dyn FnMut(&ObjectRef))
Object3D.traverseAncestors( callback ).
Sourcepub fn update_matrix_world(&self, force: bool)
pub fn update_matrix_world(&self, force: bool)
Object3D.updateMatrixWorld( force ).
Sourcepub fn update_world_matrix(&self, update_parents: bool, update_children: bool)
pub fn update_world_matrix(&self, update_parents: bool, update_children: bool)
Object3D.updateWorldMatrix( updateParents, updateChildren ).
Sourcepub fn get_world_position(&self) -> Vector3
pub fn get_world_position(&self) -> Vector3
Object3D.getWorldPosition( target ).
Sourcepub fn get_world_quaternion(&self) -> Quaternion
pub fn get_world_quaternion(&self) -> Quaternion
Object3D.getWorldQuaternion( target ).
Sourcepub fn get_world_scale(&self) -> Vector3
pub fn get_world_scale(&self) -> Vector3
Object3D.getWorldScale( target ).
Sourcepub fn get_world_direction(&self) -> Vector3
pub fn get_world_direction(&self) -> Vector3
Object3D.getWorldDirection( target ).
Sourcepub fn local_to_world(&self, vector: &mut Vector3)
pub fn local_to_world(&self, vector: &mut Vector3)
Object3D.localToWorld( vector ).
Sourcepub fn world_to_local(&self, vector: &mut Vector3)
pub fn world_to_local(&self, vector: &mut Vector3)
Object3D.worldToLocal( vector ).
Sourcepub fn apply_matrix4(&self, m: &Matrix4)
pub fn apply_matrix4(&self, m: &Matrix4)
Object3D.applyMatrix4( matrix ) — the inherent method, reached through
the cell so attach() can use it.
Methods from Deref<Target = RefCell<Object3D>>§
1.24.0 · Sourcepub fn replace(&self, t: T) -> T
pub fn replace(&self, t: T) -> T
Replaces the wrapped value with a new one, returning the old value, without deinitializing either one.
This function corresponds to std::mem::replace.
§Panics
Panics if the value is currently borrowed.
§Examples
use std::cell::RefCell;
let cell = RefCell::new(5);
let old_value = cell.replace(6);
assert_eq!(old_value, 5);
assert_eq!(cell, RefCell::new(6));1.35.0 · Sourcepub fn replace_with<F>(&self, f: F) -> T
pub fn replace_with<F>(&self, f: F) -> T
Replaces the wrapped value with a new one computed from f, returning
the old value, without deinitializing either one.
§Panics
Panics if the value is currently borrowed.
§Examples
use std::cell::RefCell;
let cell = RefCell::new(5);
let old_value = cell.replace_with(|&mut old| old + 1);
assert_eq!(old_value, 5);
assert_eq!(cell, RefCell::new(6));1.24.0 · Sourcepub fn swap(&self, other: &RefCell<T>)
pub fn swap(&self, other: &RefCell<T>)
Swaps the wrapped value of self with the wrapped value of other,
without deinitializing either one.
This function corresponds to std::mem::swap.
§Panics
Panics if the value in either RefCell is currently borrowed, or
if self and other point to the same RefCell.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
let d = RefCell::new(6);
c.swap(&d);
assert_eq!(c, RefCell::new(6));
assert_eq!(d, RefCell::new(5));1.0.0 · Sourcepub fn borrow(&self) -> Ref<'_, T>
pub fn borrow(&self) -> Ref<'_, T>
Immutably borrows the wrapped value.
The borrow lasts until the returned Ref exits scope. Multiple
immutable borrows can be taken out at the same time.
§Panics
Panics if the value is currently mutably borrowed. For a non-panicking variant, use
try_borrow.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
let borrowed_five = c.borrow();
let borrowed_five2 = c.borrow();An example of panic:
use std::cell::RefCell;
let c = RefCell::new(5);
let m = c.borrow_mut();
let b = c.borrow(); // this causes a panic1.13.0 · Sourcepub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>
pub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>
Immutably borrows the wrapped value, returning an error if the value is currently mutably borrowed.
The borrow lasts until the returned Ref exits scope. Multiple immutable borrows can be
taken out at the same time.
This is the non-panicking variant of borrow.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
{
let m = c.borrow_mut();
assert!(c.try_borrow().is_err());
}
{
let m = c.borrow();
assert!(c.try_borrow().is_ok());
}1.0.0 · Sourcepub fn borrow_mut(&self) -> RefMut<'_, T>
pub fn borrow_mut(&self) -> RefMut<'_, T>
Mutably borrows the wrapped value.
The borrow lasts until the returned RefMut or all RefMuts derived
from it exit scope. The value cannot be borrowed while this borrow is
active.
§Panics
Panics if the value is currently borrowed. For a non-panicking variant, use
try_borrow_mut.
§Examples
use std::cell::RefCell;
let c = RefCell::new("hello".to_owned());
*c.borrow_mut() = "bonjour".to_owned();
assert_eq!(&*c.borrow(), "bonjour");An example of panic:
use std::cell::RefCell;
let c = RefCell::new(5);
let m = c.borrow();
let b = c.borrow_mut(); // this causes a panic1.13.0 · Sourcepub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>
pub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>
Mutably borrows the wrapped value, returning an error if the value is currently borrowed.
The borrow lasts until the returned RefMut or all RefMuts derived
from it exit scope. The value cannot be borrowed while this borrow is
active.
This is the non-panicking variant of borrow_mut.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
{
let m = c.borrow();
assert!(c.try_borrow_mut().is_err());
}
assert!(c.try_borrow_mut().is_ok());1.12.0 · Sourcepub fn as_ptr(&self) -> *mut T
pub fn as_ptr(&self) -> *mut T
Returns a raw pointer to the underlying data in this cell.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
let ptr = c.as_ptr();1.37.0 · Sourcepub unsafe fn try_borrow_unguarded(&self) -> Result<&T, BorrowError>
pub unsafe fn try_borrow_unguarded(&self) -> Result<&T, BorrowError>
Immutably borrows the wrapped value, returning an error if the value is currently mutably borrowed.
§Safety
Unlike RefCell::borrow, this method is unsafe because it does not
return a Ref, thus leaving the borrow flag untouched. Mutably
borrowing the RefCell while the reference returned by this method
is alive is undefined behavior.
§Examples
use std::cell::RefCell;
let c = RefCell::new(5);
{
let m = c.borrow_mut();
assert!(unsafe { c.try_borrow_unguarded() }.is_err());
}
{
let m = c.borrow();
assert!(unsafe { c.try_borrow_unguarded() }.is_ok());
}