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: ObjectRefThe scene root. node.borrow().is_scene is true.
background: Option<Background>scene.background.
background_blurriness: f64scene.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: f64scene.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: f64scene.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: Eulerscene.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
impl Scene
Sourcepub fn matrix_world(&self) -> Matrix4
pub fn matrix_world(&self) -> Matrix4
Scene.matrixWorld.
Sourcepub fn set_on_before_render(
&mut self,
hook: impl Fn(&Renderer, &Scene, &dyn RenderCamera, Option<&RenderTarget>) + 'static,
)
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.
Sourcepub fn set_on_after_render(
&mut self,
hook: impl Fn(&Renderer, &Scene, &dyn RenderCamera, Option<&RenderTarget>) + 'static,
)
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.
Sourcepub fn set_background(&mut self, background: impl Into<Background>)
pub fn set_background(&mut self, background: impl Into<Background>)
scene.background = value.
Sourcepub fn children(&self) -> Vec<ObjectRef>
pub fn children(&self) -> Vec<ObjectRef>
scene.children, cloned — the direct children only. The renderer does
not use this; it walks the whole tree.
Sourcepub fn update_matrix_world(&self)
pub fn update_matrix_world(&self)
Object3D.updateMatrixWorld() on the scene root, which is what
Renderer.render() calls before projecting the scene.