From 6eef77702fbd0d2ff0cc857f0f7314aa97cd2b63 Mon Sep 17 00:00:00 2001 From: Masterchef365 Date: Tue, 2 May 2023 03:27:13 -0700 Subject: [PATCH 1/2] Add methods for render and upload to meshhandle --- common/src/render.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/src/render.rs b/common/src/render.rs index 2a5b6d6..f85ae25 100644 --- a/common/src/render.rs +++ b/common/src/render.rs @@ -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 { @@ -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 } + } +} From c3e9ac6bb10a0644e318960ea228f52ee16fc798 Mon Sep 17 00:00:00 2001 From: Masterchef365 Date: Tue, 2 May 2023 03:33:04 -0700 Subject: [PATCH 2/2] Update cube plugin to match --- example_plugins/cube/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/example_plugins/cube/src/lib.rs b/example_plugins/cube/src/lib.rs index 491edec..10bca27 100644 --- a/example_plugins/cube/src/lib.rs +++ b/example_plugins/cube/src/lib.rs @@ -19,10 +19,7 @@ impl UserState for ClientState { fn new(io: &mut EngineIo, _sched: &mut EngineSchedule) -> 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 } @@ -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