Skip to main content

Scene

Struct Scene 

Source
pub struct Scene {
Show 13 fields pub node: ObjectRef, pub background: Option<Background>, pub background_blurriness: f64, pub background_intensity: f64, pub environment_intensity: f64, pub environment: Option<PmremHandle>, pub environment_rotation: Euler, pub environment_node: Option<EnvironmentNode>, pub fog: Option<SceneFog>, pub fog_node: Option<FogNode>, pub override_material: Option<MeshBasicNodeMaterial>, pub on_before_render: Option<SceneRenderHook>, pub on_after_render: Option<SceneRenderHook>,
}
Expand description

Scene extends Object3D.

The Object3D half is a real scene-graph ObjectRef, so the tree under a scene is the tree the renderer walks: Groups, lights and their children all nest, and Renderer::render collects drawables with crate::renderer::project_object. The fields below are what Scene adds to Object3D; they are not a Payload variant because nothing in the renderer’s traversal branches on them.

Fields§

§node: ObjectRef

The scene root. node.borrow().is_scene is true.

§background: Option<Background>

scene.background.

§background_blurriness: f64

scene.backgroundBlurriness — the roughness the background’s PMREM is read at, in [ 0, 1 ]. Three reads it through backgroundBlurriness, the render-group uniform BackgroundNode puts on getTextureLevel, so changing it is a uniform write and not a new program.

§background_intensity: f64

scene.backgroundIntensity — the factor BackgroundNode multiplies the background colour by. Like Scene::background_blurriness it is a render-group uniform, so changing it is a uniform write.

§environment_intensity: f64

scene.environmentIntensity — the factor EnvironmentNode scales the radiance and irradiance of Scene::environment (or Scene::environment_node) by, on every material that takes the scene’s environment instead of carrying its own. A material with its own pmrem_env reads envMapIntensity instead, which the port keeps at 1.

§environment: Option<PmremHandle>

scene.environment — the default environment map for every material in the scene that does not carry one of its own.

Upstream this is a plain Texture and NodeManager.updateEnvironment( scene ) turns it into a scene.environmentNode, which NodeMaterial.setupEnvironment() falls back to when neither builder.context.environment nor the material’s own envNode is set. The port carries the generated PMREM’s handle for the reason Background::Pmrem does: the maxLod uniform the read needs travels with the texture.

Assigning it after a material has drawn once needs MeshBasicNodeMaterial::set_needs_update on that material, exactly as three.js needs material.needsUpdate = true: it changes the program, not a uniform.

§environment_rotation: Euler

scene.environmentRotation — the rotation materialEnvRotation applies to Scene::environment (or Scene::environment_node) on every material that has no envMap of its own. Three’s uniform is makeRotationFromEuler( rotation ).transpose(), an object-group mat4, so changing it is a uniform write, not a new program.

§environment_node: Option<EnvironmentNode>

scene.environmentNode set by hand to a graph of pmremTexture()s. NodeManager.getEnvironmentNode() returns it ahead of the node it would make from Scene::environment, so it wins when both are set. The same rule about MeshBasicNodeMaterial::set_needs_update applies.

§fog: Option<SceneFog>

scene.fog — a classic Fog or FogExp2. The renderer turns it into a fog node whose parameters are render-group uniforms (NodeManager.updateFog()), so changing a value is a uniform write; changing the kind is a new program. Scene::fog_node wins when both are set, as in three.js.

§fog_node: Option<FogNode>

scene.fogNode. Read by NodeMaterial’s output flow on every material in the scene (rung 5).

§override_material: Option<MeshBasicNodeMaterial>

scene.overrideMaterial — used to draw every object in the scene with this material instead of its own.

§on_before_render: Option<SceneRenderHook>

scene.onBeforeRender( renderer, scene, camera, renderTarget ) — called at the start of every render of this scene, after its matrices and the camera’s are updated and before the scene is projected. Not the on_before_render of Scene::node’s Object3D: three calls an object’s hook per draw, and the scene root is not drawn, so the renderer never calls that one. See SceneRenderHook.

§on_after_render: Option<SceneRenderHook>

scene.onAfterRender( renderer, scene, camera, renderTarget ) — called at the end of every render of this scene, after its pass (and its output pass, if any) has been recorded and every object’s on_after_render has run.

Implementations§

Source§

impl Scene

Source

pub fn new() -> Self

new Scene().

Source

pub fn matrix_world(&self) -> Matrix4

Scene.matrixWorld.

Source

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

scene.onBeforeRender = function ( renderer, scene, camera, renderTarget ) { ... } — sets Scene::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 Fn(&Renderer, &Scene, &dyn RenderCamera, Option<&RenderTarget>) + 'static, )

scene.onAfterRender = function ( ... ) { ... } — sets Scene::on_after_render, as set_on_before_render does.

Source

pub fn set_background(&mut self, background: impl Into<Background>)

scene.background = value.

Source

pub fn add(&self, object: &ObjectRef) -> &Self

scene.add( object ).

Source

pub fn remove(&self, object: &ObjectRef) -> &Self

scene.remove( object ).

Source

pub fn children(&self) -> Vec<ObjectRef>

scene.children, cloned — the direct children only. The renderer does not use this; it walks the whole tree.

Source

pub fn update_matrix_world(&self)

Object3D.updateMatrixWorld() on the scene root, which is what Renderer.render() calls before projecting the scene.

Trait Implementations§

Source§

impl Default for Scene

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Scene

§

impl !Send for Scene

§

impl !Sync for Scene

§

impl !UnwindSafe for Scene

§

impl Freeze for Scene

§

impl Unpin for Scene

§

impl UnsafeUnpin for Scene

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> 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, 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.