Skip to main content

Object3D

Struct Object3D 

Source
pub struct Object3D {
Show 32 fields pub id: u32, pub name: String, pub object_type: &'static str, pub parent: Option<WeakObjectRef>, pub children: Vec<ObjectRef>, pub visible: bool, pub layers: Layers, pub render_order: f64, pub frustum_culled: bool, pub matrix_auto_update: bool, pub matrix_world_auto_update: bool, pub matrix_world_needs_update: bool, pub matrix_alias: Option<WeakObjectRef>, pub is_camera: bool, pub is_light: bool, pub cast_shadow: bool, pub receive_shadow: bool, pub occlusion_test: bool, pub is_group: bool, pub is_scene: bool, pub position: Vector3, pub rotation: Euler, pub quaternion: Quaternion, pub scale: Vector3, pub up: Vector3, pub matrix: Matrix4, pub matrix_world: Matrix4, pub user_data: Map<String, Value>, pub payload: Payload, pub listeners: SceneEventListeners, pub on_before_render: Option<ObjectRenderHook>, pub on_after_render: Option<ObjectRenderHook>,
}
Expand description

three.js’ Object3D: the transform and the drawable state every scene node carries. The parent/children tree lives on ObjectRef, the handle that wraps this in an Rc<RefCell<..>> — see docs/scene-graph.md.

Debug is written out by hand because the render hooks are closures: it prints whether each is set.

Fields§

§id: u32

Object3D.id — a per-thread counter, three.js’ _object3DId ++.

§name: String

Object3D.name.

§object_type: &'static str

Object3D.type. 'Object3D' unless a subclass overrides it (Group sets 'Group').

§parent: Option<WeakObjectRef>

Object3D.parent, weak: see docs/scene-graph.md.

§children: Vec<ObjectRef>

Object3D.children.

§visible: bool

Object3D.visible.

§layers: Layers

Object3D.layers — tested against the camera’s in _projectObject.

§render_order: f64

Object3D.renderOrder. On a Group it becomes the groupOrder of everything below it; on a drawable it is the second render-list sort key.

§frustum_culled: bool

Object3D.frustumCulled.

§matrix_auto_update: bool

Object3D.matrixAutoUpdate (Object3D.DEFAULT_MATRIX_AUTO_UPDATE).

§matrix_world_auto_update: bool

Object3D.matrixWorldAutoUpdate (DEFAULT_MATRIX_WORLD_AUTO_UPDATE).

§matrix_world_needs_update: bool

Object3D.matrixWorldNeedsUpdate.

§matrix_alias: Option<WeakObjectRef>

this.matrix = other.matrixWorld — CameraHelper’s sharing of its camera’s world matrix object. JS aliases the two; the port copies the other node’s matrix_world into matrix at the moment updateMatrixWorld() reads matrix, which is when the alias would be observed. None for everything else, and for a clone (copy() copies the matrix’s values, not the object).

§is_camera: bool

Object3D.isCamera — lookAt() points a camera the other way round.

§is_light: bool

Object3D.isLight — as is_camera.

§cast_shadow: bool

Object3D.castShadow — whether the shadow pass draws this object.

§receive_shadow: bool

Object3D.receiveShadow — whether the object’s material samples the shadow maps, which makes it a different program from the same material on a non-receiving object.

§occlusion_test: bool

object.occlusionTest — not a declared Object3D property in three but an ad-hoc one the renderer reads (RenderList.push(), WebGPUBackend.draw()): when true the object’s draws are wrapped in an occlusion query, and renderer.isOccluded( object ) answers from its result. Being ad hoc, Object3D.copy() does not carry it, so neither does Clone.

§is_group: bool

Object3D.isGroup.

§is_scene: bool

Object3D.isScene.

§position: Vector3

Object3D.position.

§rotation: Euler

Kept in sync with quaternion by Object3D::set_rotation, the same way three.js’ Euler/Quaternion onChange callbacks keep them in sync.

§quaternion: Quaternion

Object3D.quaternion.

§scale: Vector3

Object3D.scale.

§up: Vector3

Object3D.up.

§matrix: Matrix4

Object3D.matrix, composed from position/quaternion/scale by update_matrix.

§matrix_world: Matrix4

Object3D.matrixWorld.

§user_data: Map<String, Value>

Object3D.userData — the application’s own data on the object, an open JSON object as in three.js. The node system reads it through user_data, once per draw, as UserDataNode does.

§payload: Payload

What three.js would get from subclassing: the Mesh/InstancedMesh state that makes this node drawable. See Payload.

§listeners: SceneEventListeners

object._listeners — the SceneEvent listeners, added and dispatched through ObjectRef::add_event_listener and its siblings.

§on_before_render: Option<ObjectRenderHook>

object.onBeforeRender( renderer, scene, camera, geometry, material, group ) — called by the renderer once per draw of this object in a scene render, after the scene’s matrices are updated and before anything of the pass is drawn. None is three’s empty default. See ObjectRenderHook for the arguments and docs/api.md decision 12 for where the port calls it.

§on_after_render: Option<ObjectRenderHook>

object.onAfterRender( renderer, scene, camera, geometry, material, group ) — called once per draw of this object after the scene’s pass (and its output pass, if any) has been recorded.

Implementations§

Source§

impl Object3D

Source

pub fn new_node() -> ObjectRef

A fresh Object3D as a scene-graph ObjectRef.

Source

pub fn into_node(self) -> ObjectRef

This object, moved into a scene-graph ObjectRef.

Source

pub fn set_on_before_render( &mut self, hook: impl FnMut(&ObjectRef, &Renderer, &Scene, &dyn RenderCamera, Option<&Group>) + 'static, )

object.onBeforeRender = function ( renderer, scene, camera, geometry, material, group ) { ... } — sets on_before_render. Assigning the field works too; this spares spelling out the closure’s argument types.

Source

pub fn set_on_after_render( &mut self, hook: impl FnMut(&ObjectRef, &Renderer, &Scene, &dyn RenderCamera, Option<&Group>) + 'static, )

object.onAfterRender = function ( ... ) { ... } — sets on_after_render, as set_on_before_render does.

Source

pub fn is_mesh(&self) -> bool

object.isMesh — see Payload::is_mesh.

Source

pub fn is_skinned_mesh(&self) -> bool

object.isSkinnedMesh.

Source

pub fn skinned_mesh(&self) -> Option<&SkinnedMesh>

The SkinnedMesh this object is, if it is one.

Source

pub fn skinned_mesh_mut(&mut self) -> Option<&mut SkinnedMesh>

object.isSkinnedMesh’s SkinnedMesh state, mutably.

Source

pub fn is_instanced_mesh(&self) -> bool

object.isInstancedMesh.

Source

pub fn is_line(&self) -> bool

object.isLine — see Payload::is_line.

Source

pub fn is_points(&self) -> bool

object.isPoints — see Payload::is_points.

Source

pub fn is_line_segments(&self) -> bool

object.isLineSegments.

Source

pub fn line(&self) -> Option<&Line>

Line.geometry / Line.material when this node is a line.

Source

pub fn line_mut(&mut self) -> Option<&mut Line>

Line.geometry / Line.material, mutably, when this node is a line.

Source

pub fn geometry(&self) -> Option<&Rc<BufferGeometry>>

object.geometry for a mesh or a line.

Source

pub fn material(&self) -> Option<&MeshBasicNodeMaterial>

object.material for a mesh or a line.

Source

pub fn mesh(&self) -> Option<&Mesh>

Mesh.geometry / Mesh.material when this node is a mesh.

Source

pub fn mesh_mut(&mut self) -> Option<&mut Mesh>

Mesh.geometry / Mesh.material, mutably, when this node is a mesh.

Source

pub fn light(&self) -> Option<&LightObject>

The light state when is_light is true — Light.color, Light.intensity, PointLight.distance, PointLight.decay.

Source

pub fn light_mut(&mut self) -> Option<&mut LightObject>

The light state, mutably; see light.

Source

pub fn instance_matrix(&self) -> Option<&InstancedBufferAttribute>

InstancedMesh.instanceMatrix.

Source

pub fn instance_color(&self) -> Option<&InstancedBufferAttribute>

InstancedMesh.instanceColor, None until setColorAt() is called.

Source

pub fn set_matrix_at(&mut self, index: usize, matrix: &Matrix4)

InstancedMesh.setMatrixAt( index, matrix ), reached through the payload.

Panics if this node is not an InstancedMesh, the way the JS would throw.

Source

pub fn set_color_at(&mut self, index: usize, color: &Color)

InstancedMesh.setColorAt( index, color ), reached through the payload.

Panics if this node is not an InstancedMesh, the way the JS would throw.

Source

pub fn set_rotation(&mut self, x: f64, y: f64, z: f64)

object.rotation.set( x, y, z ) — the Euler onChange callback then refreshes the quaternion, which is what updateMatrix() composes from.

Source

pub fn apply_matrix4(&mut self, m: &Matrix4)

Object3D.applyMatrix4().

Source

pub fn apply_quaternion(&mut self, q: &Quaternion)

Object3D.applyQuaternion().

Source

pub fn set_rotation_from_axis_angle(&mut self, axis: &Vector3, angle: f64)

Object3D.setRotationFromAxisAngle().

Source

pub fn set_rotation_from_euler(&mut self, euler: &Euler)

Object3D.setRotationFromEuler().

Source

pub fn set_rotation_from_matrix(&mut self, m: &Matrix4)

Object3D.setRotationFromMatrix() — the upper 3x3 of m must be a pure rotation (unscaled).

Source

pub fn set_rotation_from_quaternion(&mut self, q: &Quaternion)

Object3D.setRotationFromQuaternion() — q is assumed normalized.

Source

pub fn rotate_on_axis(&mut self, axis: &Vector3, angle: f64)

Object3D.rotateOnAxis() — rotates about an axis in object space.

Source

pub fn rotate_on_world_axis(&mut self, axis: &Vector3, angle: f64)

Object3D.rotateOnWorldAxis() — rotates about an axis in world space. Assumes the object has no rotated parent.

Source

pub fn rotate_x(&mut self, angle: f64)

Object3D.rotateX().

Source

pub fn rotate_y(&mut self, angle: f64)

Object3D.rotateY().

Source

pub fn rotate_z(&mut self, angle: f64)

Object3D.rotateZ().

Source

pub fn translate_on_axis(&mut self, axis: &Vector3, distance: f64)

Object3D.translateOnAxis() — translates along an axis in object space.

Source

pub fn translate_x(&mut self, distance: f64)

Object3D.translateX().

Source

pub fn translate_y(&mut self, distance: f64)

Object3D.translateY().

Source

pub fn translate_z(&mut self, distance: f64)

Object3D.translateZ().

Source

pub fn local_to_world(&mut self, vector: &mut Vector3)

Object3D.localToWorld().

Source

pub fn world_to_local(&mut self, vector: &mut Vector3)

Object3D.worldToLocal().

Source

pub fn look_at(&mut self, target: &Vector3)

Object3D.lookAt() for a plain object: the object’s +Z is pointed away from target (a camera or light points at it instead — see PerspectiveCamera::look_at).

Source

pub fn get_world_position(&mut self) -> Vector3

Object3D.getWorldPosition().

Source

pub fn get_world_quaternion(&mut self) -> Quaternion

Object3D.getWorldQuaternion().

Source

pub fn get_world_scale(&mut self) -> Vector3

Object3D.getWorldScale().

Source

pub fn get_world_direction(&mut self) -> Vector3

Object3D.getWorldDirection() — the object’s +Z axis in world space.

Source

pub fn update_matrix(&mut self)

Object3D.updateMatrix().

Source

pub fn update_matrix_world(&mut self, parent_matrix_world: Option<&Matrix4>)

Object3D.updateMatrixWorld() for an object whose parent’s world matrix is parent_matrix_world (None for a root).

Trait Implementations§

Source§

impl Clone for Object3D

Object3D.copy( source, recursive = false ), minus the tree: a clone gets a fresh id and no parent or children, because a Clone that shared the Rcs would give two objects the same child list. Nor does it get the listeners or the render hooks: copy() does not copy _listeners, and a boxed closure cannot be cloned.

Source§

fn clone(&self) -> Self

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 Object3D

Source§

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

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

impl Default for Object3D

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.