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§
- 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. - 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. - 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. - 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. - 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. - 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§
- Component registration definition. All JsValues should be derived from
js_sys::Function
- A vector containing a tuple of components along with their property name
- A property for a GeometryReg
- Geometry registration definition. The
init
JsValue should be derived fromjs_sys::Function
- The type here may look daunting, but all this is just to allow you to create a
Cow<'static, [T]>
field in a component. - Additional properties for the Material component. Contains a slice or vector of property names to property values.
Enums§
- Whether to perform antialiasing. If auto, antialiasing is disabled on mobile.
- Type of fog distribution. Can be linear or exponential.
- Set hand that will be tracked (i.e., right, left).
- Style of the hand 3D model loaded. Can be lowPoly, highPoly or toon.
- quad, monocubemap or stereocubemap
- Whether to use a logarithmic depth buffer.
- Mesh representing the hand or dots matching the joints
- Shadow used for directional lights
- Shadow used for point and spot lights
- Fragment shader precision : low, medium or high.
- Where the intersection ray is cast from (i.e.,entity or mouse).
- The scene’s reference space type for camera and controllers.
- Multi-line text alignment (left, center, right).
- Horizontal positioning (left, center, right, align).
- Vertical positioning (top, center, bottom).
- Side to render. (front, back, double)
- How whitespace should be handled (i.e., normal, pre, nowrap).
- Axis that the A and D keys act upon.
Traits§
Functions§
- Convert a component to an attribute