Module component

Source
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 a camera component with all its fields set to default values, whereas component!{component::Camera, active = false} will create a camera component with all its fields set to default values except the active 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 calls into on expressions passed into the fields expecting function, allowing the js! 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, the component_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, calling component_struct! should only be necessary for locally-defined components. Once all components from Aframe have been defined, component_def! and component_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 resulting Display implementation.
geometry_def
Top-level macro to define custom geometries. Syntax resemles but is simpler than the component_def! macro. The js! macro is available for writing inline javascript, and returns a js_sys::Function object. This macro calls into on expressions passed into the fields expecting function, allowing the js! 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 with component_def! to crate fields with a limited number of possiblities.

Structs§

Animation
animation
Background
background
Camera
camera
ComponentReg
Component registration definition. All JsValues should be derived from js_sys::Function
ComponentVec
A vector containing a tuple of components along with their property name
Cursor
cursor
DaydreamControls
daydream-controls
DeviceOrientationPermissionUI
device-orientation-permission-ui
DirectionalShadow
light#shadow
Embedded
embedded
Fog
fog
GearVRControls
gearvr-controls
Geometry
geometry
GeometryProperty
A property for a GeometryReg
GeometryReg
Geometry registration definition. The init JsValue should be derived from js_sys::Function
GltfModel
gltf-model
HandControls
hand-controls
HandTrackingControls
hand-controls
KeyboardShortcuts
keyboard-shortcuts
LaserControls
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.
LoadingScreen
loading-screen
LocalShadow
light#shadow
LookControls
look-controls
MagicLeapControls
magicleap-controls
Material
material
MaterialProps
Additional properties for the Material component. Contains a slice or vector of property names to property values.
ObjModel
obj-model
OculusGoControls
oculus-go-controls
OculusTouchControls
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
TrackedControls
tracked-controls
Visible
visible
ViveControls
vive-controls
ViveFocusControls
vive-focus-controls
VrModeUi
vr-mode-ui
WasdControls
wasd-controls
WebXR
webxr
WindowsMotionControls
windows-motion-controls

Enums§

AnimationDirection
animation#dir
AnimationLoop
animation#loop
Antialias
Whether to perform antialiasing. If auto, antialiasing is disabled on mobile.
Autoplay
animation#autoplay
Blending
material#blending
DistancePlane
raycaster#far
Easing
animation#easings
FogType
Type of fog distribution. Can be linear or exponential.
GeometryPrimitive
geometry#built-in-geometries
Hand
Set hand that will be tracked (i.e., right, left).
HandModelStyle
Style of the hand 3D model loaded. Can be lowPoly, highPoly or toon.
LayerType
quad, monocubemap or stereocubemap
LightType
light-types
LogarithmicDepthBuffer
Whether to use a logarithmic depth buffer.
MaterialSide
material#side
ModelStyle
Mesh representing the hand or dots matching the joints
OptionalDirectionalShadow
Shadow used for directional lights
OptionalLocalShadow
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).
ReferenceSpaceType
The scene’s reference space type for camera and controllers.
TextAlignment
Multi-line text alignment (left, center, right).
TextAnchor
Horizontal positioning (left, center, right, align).
TextBaseline
Vertical positioning (top, center, bottom).
TextSide
Side to render. (front, back, double)
TextWhiteSpace
How whitespace should be handled (i.e., normal, pre, nowrap).
VertexColors
material#vertexcolors
WasdAxis
Axis that the A and D keys act upon.

Traits§

Component

Functions§

cmp_to_attr
Convert a component to an attribute