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 theRendercomponent.
#![allow(unused)] fn main() { const CUBE_HANDLE: MeshHandle = MeshHandle::new(pkg_namespace!("Cube")); }
- Plugins send an
UploadMeshmessage containing theMeshHandleand 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
TransformandRendercomponents. TheTransformcomponent specifies the position and orientation of the rendered mesh. This is available in shaders via themat4 viewuniform. TheRendercomponent specifies how the mesh is to be displayed; e.g. which primitive to use, indexing limites, etc. Note how we specify whichMeshHandleto 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.