Rendering
The rendering interface in ChatImproVR works as follows:
- Plugins define a
MeshHandle
, which is just a name for the mesh we will upload. This name will be used in theRender
component.
#![allow(unused)] fn main() { const CUBE_HANDLE: MeshHandle = MeshHandle::new(pkg_namespace!("Cube")); }
- Plugins send an
UploadMesh
message containing theMeshHandle
and the desired mesh data. This tells the rendering engine about the mesh data, so that we may later reference it by itsMeshHandle
.
#![allow(unused)] fn main() { io.send(&UploadMesh { mesh: cube(), id: CUBE_HANDLE, }); }
- To render a mesh, create an entity with the
Transform
andRender
components. TheTransform
component specifies the position and orientation of the rendered mesh. This is available in shaders via themat4 view
uniform. TheRender
component specifies how the mesh is to be displayed; e.g. which primitive to use, indexing limites, etc. Note how we specify whichMeshHandle
to render!
#![allow(unused)] fn main() { io.create_entity() .add_component(Transform::identity()); .add_component(Render::new(CUBE_HANDLE)) .build(); }
NOTE: All rendering data is processed client-side; e.g. UploadMesh should be sent in ClientState.
See the cube example!
Defining meshes
Meshes are defined using vertices and indices. The default shader uses Vertex
's uvw
field to represent vertex color.