Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions common/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct CameraComponent {
}

/// All information required to define a renderable mesh
#[must_use]
#[derive(Message, Serialize, Deserialize, Debug, Clone)]
#[locality("Local")]
pub struct UploadMesh {
Expand Down Expand Up @@ -193,3 +194,15 @@ impl Default for CameraComponent {
}
}
}

impl MeshHandle {
/// Returns an appropriate Render component.
pub fn render(self) -> Render {
Render::new(self)
}

/// Returns an appropriate UploadMesh message.
pub fn upload(self, mesh: Mesh) -> UploadMesh {
UploadMesh { mesh, id: self }
}
}
7 changes: 2 additions & 5 deletions example_plugins/cube/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ impl UserState for ClientState {
fn new(io: &mut EngineIo, _sched: &mut EngineSchedule<Self>) -> Self {
// Make the cube mesh available to the rendering engine
// This defines the CUBE_HANDLE id to refer to the mesh we get from cube()
io.send(&UploadMesh {
mesh: cube(),
id: CUBE_HANDLE,
});
io.send(&CUBE_HANDLE.upload(cube()));

Self
}
Expand All @@ -37,7 +34,7 @@ impl UserState for ServerState {
.add_component(Transform::default())
// Attach the Render component, which details how the object should be drawn
// Note that we use CUBE_HANDLE here, to tell the rendering engine to draw the cube
.add_component(Render::new(CUBE_HANDLE).primitive(Primitive::Triangles))
.add_component(CUBE_HANDLE.render().primitive(Primitive::Triangles))
// Attach the Synchronized component, which will copy the object to clients
.add_component(Synchronized)
// And get the entity ID
Expand Down