Skip to main content

Scene

Struct Scene 

Source
pub struct Scene { /* private fields */ }
Expand description

A 3D scene. Renders one <div data-three="scene"> element.

use autumn_plugin_three::{Camera, Color, Controls, Light, Mesh, Scene};
use autumn_web::html;

let scene = Scene::new()
    .label("A spinning orange torus knot")
    .camera(Camera::perspective().position([0.0, 0.0, 4.0]))
    .controls(Controls::OrbitNoZoom)
    .add(Mesh::torus_knot(0.8, 0.25).color(Color::hex(0xff7a18)).spin([0.0, 45.0, 0.0]))
    .add(Light::directional().position([3.0, 5.0, 2.0]))
    .fallback(html! { p { "3D preview needs WebGL." } });

let html = html! { (scene) }.into_string();
assert!(html.starts_with(r#"<div role="img""#), "{html}");
assert!(html.contains(r#"data-three="scene""#));
assert!(html.contains(r#"data-three-mesh="torus-knot""#));

Implementations§

Source§

impl Scene

Source

pub fn new() -> Self

Makes an empty scene with the defaults.

Source

pub fn id(self, id: impl Into<String>) -> Self

Sets the element id.

Source

pub fn class(self, class: impl Into<String>) -> Self

Sets the element class, for your own size or layout CSS.

Source

pub fn label(self, label: impl Into<String>) -> Self

Sets an accessible label. The element gets role="img" and aria-label.

Source

pub const fn aspect(self, aspect: Aspect) -> Self

Sets the aspect ratio. Default: Aspect::Wide (16 / 9).

Source

pub const fn background(self, color: Color) -> Self

Sets a solid background color. Default: transparent.

Source

pub const fn camera(self, camera: Camera) -> Self

Sets the camera.

Source

pub const fn controls(self, controls: Controls) -> Self

Sets the camera controls. Default: Controls::None.

Source

pub const fn environment(self, environment: Environment) -> Self

Sets the image-based light.

Source

pub const fn turntable(self, degrees_per_second: f32) -> Self

Turns the whole scene around the Y axis, in degrees per second. Negative values turn clockwise (seen from above).

Source

pub const fn animate_reduced_motion(self) -> Self

Keeps automatic motion (spin, turntable, clips) when the user prefers reduced motion. Default: automatic motion stops.

Source

pub fn add(self, object: impl Into<SceneObject>) -> Self

Adds a mesh, model, or light.

Source

pub fn fallback(self, markup: Markup) -> Self

Sets fallback content. It shows without JavaScript, without WebGL, and when a model fails to load.

Trait Implementations§

Source§

impl Clone for Scene

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 Scene

Source§

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

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

impl Default for Scene

Source§

fn default() -> Self

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

impl Render for Scene

Source§

fn render(&self) -> Markup

Renders self as a block of Markup.
Source§

fn render_to(&self, buffer: &mut String)

Appends a representation of self to the given buffer. Read more

Auto Trait Implementations§

§

impl Forget for Scene

§

impl Freeze for Scene

§

impl RefUnwindSafe for Scene

§

impl Send for Scene

§

impl Sync for Scene

§

impl Unpin for Scene

§

impl UnsafeUnpin for Scene

§

impl UnwindSafe 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> 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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scoped for T
where T: Send + Sync + 'static,

Source§

fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>

Open a deferred ScopeQuery for this type. Resolves the registered scope at .load() time, not here.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more