Expand description
Module dealing with components in all forms, including registration, representation, and instantiation.
§High-level API
component_def!
component_struct!
component!
simple_enum!
complex_enum!
§Low-level API
A component_struct
is simply a type that implements these 2 traits:
ⓘ
pub trait Component: Display + std::fmt::Debug + std::any::Any
{
fn clone(&self) -> Box<dyn Component>;
fn eq(&self, other: &'static dyn Component) -> bool;
fn as_map(&self) -> HashMap<Cow<'static, str>, Cow<'static, str>>;
}
pub trait ConstDefault
{
const DEFAULT: Self;
}
As long as clone
provides a valid clone, eq
provides a valid equality
check, and as_map
provides a serialization of keys to values that Aframe
can understand, and a DEFAULT
value is provided that can be evaluated at
compile time, a struct is a valid component.
A ComponentReg
is slightly more complicated, but details on its low-level
API may be added here at a later date.
Macros§
- complex_
enum - A macro to define an enum in which each variant maps to an arbitrary number
of fields which will themselves be flattened into fields of the component
itself. Works similarly to the
component_struct!
macro. - component
- A macro to instantiate a component. Mimics struct creation syntax, but allows
any number of fields to be left out (in which case defaults will be used).
Note that the ability to leave out fields does not extend to struct_like
enum variants created in this macro. For example:
component!{component::Camera}
will create acamera
component with all its fields set to default values, whereascomponent!{component::Camera, active = false}
will create acamera
component with all its fields set to default values except theactive
field. - component_
def - Top-level macro to define components. Usage resembles struct creation syntax.
The
js!
macro is available for writing inline javascript, and returns a js_sys::Function object. This macro callsinto
on expressions passed into the fields expecting function, allowing thejs!
macro to be used as a catch-all. Takes the optional fields described in the table below. - component_
struct - While
component_def!
creates a component that Aframe can access from its own runtime, thecomponent_struct!
macro creates a Rust struct that mimics the internal details of that Aframe component. Component structs are already provided for Aframe’s built-in components (WIP: not all components are defined yet. Once all aframe components are defined, callingcomponent_struct!
should only be necessary for locally-defined components. Once all components from Aframe have been defined,component_def!
andcomponent_struct!
may be merged into a single macro to do the heavy-lifting of both at once). The component must be already registered in aframe before this struct may be used (although constructing it before that is safe). There are 2 variation of syntax provided, depending on the desired resultingDisplay
implementation. - geometry_
def - Top-level macro to define custom geometries. Syntax resemles but is simpler
than the
component_def!
macro. Thejs!
macro is available for writing inline javascript, and returns a js_sys::Function object. This macro callsinto
on expressions passed into the fields expecting function, allowing thejs!
macro to be used as a catch-all. Takes the optional fields described in the table below. - simple_
enum - Defines an enum in which each variant maps to a single string (via a
Display
implementation). This can be combined withcomponent_def!
to crate fields with a limited number of possiblities.
Structs§
- Animation
- animation
- Background
- background
- Camera
- camera
- Component
Reg - Component registration definition. All JsValues should be derived from
js_sys::Function
- Component
Vec - A vector containing a tuple of components along with their property name
- Cursor
- cursor
- Daydream
Controls - daydream-controls
- Device
Orientation PermissionUI - device-orientation-permission-ui
- Directional
Shadow - light#shadow
- Embedded
- embedded
- Fog
- fog
- GearVR
Controls - gearvr-controls
- Geometry
- geometry
- Geometry
Property - A property for a GeometryReg
- Geometry
Reg - Geometry registration definition. The
init
JsValue should be derived fromjs_sys::Function
- Gltf
Model - gltf-model
- Hand
Controls - hand-controls
- Hand
Tracking Controls - hand-controls
- Keyboard
Shortcuts - keyboard-shortcuts
- Laser
Controls - laser-controls
- Layer
- layer
- Light
- light
- Line
- line
- Link
- link
- List
- The type here may look daunting, but all this is just to allow you to create
a
Cow<'static, [T]>
field in a component. - Loading
Screen - loading-screen
- Local
Shadow - light#shadow
- Look
Controls - look-controls
- Magic
Leap Controls - magicleap-controls
- Material
- material
- Material
Props - Additional properties for the Material component. Contains a slice or vector of property names to property values.
- ObjModel
- obj-model
- Oculus
GoControls - oculus-go-controls
- Oculus
Touch Controls - oculus-touch-controls
- Pool
- pool
- Position
- position
- RayCaster
- raycaster
- Renderer
- renderer
- Rotation
- rotation
- Scale
- scale
- Screenshot
- screenshot
- Shadow
- shadow
- Sound
- sound
- Stats
- stats
- Text
- text
- Tracked
Controls - tracked-controls
- Visible
- visible
- Vive
Controls - vive-controls
- Vive
Focus Controls - vive-focus-controls
- VrMode
Ui - vr-mode-ui
- Wasd
Controls - wasd-controls
- WebXR
- webxr
- Windows
Motion Controls - windows-motion-controls
Enums§
- Animation
Direction - animation#dir
- Animation
Loop - animation#loop
- Antialias
- Whether to perform antialiasing. If auto, antialiasing is disabled on mobile.
- Autoplay
- animation#autoplay
- Blending
- material#blending
- Distance
Plane - raycaster#far
- Easing
- animation#easings
- FogType
- Type of fog distribution. Can be linear or exponential.
- Geometry
Primitive - geometry#built-in-geometries
- Hand
- Set hand that will be tracked (i.e., right, left).
- Hand
Model Style - Style of the hand 3D model loaded. Can be lowPoly, highPoly or toon.
- Layer
Type - quad, monocubemap or stereocubemap
- Light
Type - light-types
- Logarithmic
Depth Buffer - Whether to use a logarithmic depth buffer.
- Material
Side - material#side
- Model
Style - Mesh representing the hand or dots matching the joints
- Optional
Directional Shadow - Shadow used for directional lights
- Optional
Local Shadow - Shadow used for point and spot lights
- Precision
- Fragment shader precision : low, medium or high.
- RayOrigin
- Where the intersection ray is cast from (i.e.,entity or mouse).
- Reference
Space Type - The scene’s reference space type for camera and controllers.
- Text
Alignment - Multi-line text alignment (left, center, right).
- Text
Anchor - Horizontal positioning (left, center, right, align).
- Text
Baseline - Vertical positioning (top, center, bottom).
- Text
Side - Side to render. (front, back, double)
- Text
White Space - How whitespace should be handled (i.e., normal, pre, nowrap).
- Vertex
Colors - material#vertexcolors
- Wasd
Axis - Axis that the A and D keys act upon.
Traits§
Functions§
- cmp_
to_ attr - Convert a component to an attribute