Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Reflect for Mesh #9779

Merged
merged 2 commits into from
Sep 12, 2023
Merged
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
8 changes: 5 additions & 3 deletions crates/bevy_render/src/mesh/mesh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bevy_derive::EnumVariantMeta;
use bevy_ecs::system::{lifetimeless::SRes, SystemParamItem};
use bevy_log::warn;
use bevy_math::*;
use bevy_reflect::TypePath;
use bevy_reflect::Reflect;
use bevy_utils::{tracing::error, Hashed};
use std::{collections::BTreeMap, hash::Hash, iter::FusedIterator};
use thiserror::Error;
Expand Down Expand Up @@ -110,13 +110,15 @@ pub const VERTEX_ATTRIBUTE_BUFFER_ID: u64 = 10;
/// is the side of the triangle from where the vertices appear in a *counter-clockwise* order.
///
// TODO: allow values to be unloaded after been submitting to the GPU to conserve memory
#[derive(Asset, Debug, TypePath, Clone)]
#[derive(Asset, Debug, Clone, Reflect)]
pub struct Mesh {
#[reflect(ignore)]
primitive_topology: PrimitiveTopology,
/// `std::collections::BTreeMap` with all defined vertex attributes (Positions, Normals, ...)
/// for this mesh. Attribute ids to attribute values.
/// Uses a BTreeMap because, unlike HashMap, it has a defined iteration order,
/// which allows easy stable VertexBuffers (i.e. same buffer order)
#[reflect(ignore)]
attributes: BTreeMap<MeshVertexAttributeId, MeshAttributeData>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you feel like it I don't see anything preventing anyone from implementing Reflect on PrimitiveTopology and MeshAttributeData.

indices: Option<Indices>,
morph_targets: Option<Handle<Image>>,
Expand Down Expand Up @@ -834,7 +836,7 @@ impl From<&VertexAttributeValues> for VertexFormat {
/// An array of indices into the [`VertexAttributeValues`] for a mesh.
///
/// It describes the order in which the vertex attributes should be joined into faces.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Reflect)]
pub enum Indices {
U16(Vec<u16>),
U32(Vec<u32>),
Expand Down
7 changes: 6 additions & 1 deletion crates/bevy_render/src/mesh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use mesh::*;

use crate::{prelude::Image, render_asset::RenderAssetPlugin};
use bevy_app::{App, Plugin};
use bevy_asset::AssetApp;
use bevy_asset::{AssetApp, Handle};
use bevy_ecs::entity::Entity;

/// Adds the [`Mesh`] as an asset and makes sure that they are extracted and prepared for the GPU.
Expand All @@ -18,6 +18,11 @@ impl Plugin for MeshPlugin {
fn build(&self, app: &mut App) {
app.init_asset::<Mesh>()
.init_asset::<skinning::SkinnedMeshInverseBindposes>()
.register_asset_reflect::<Mesh>()
SludgePhD marked this conversation as resolved.
Show resolved Hide resolved
.register_type::<Option<Handle<Image>>>()
.register_type::<Option<Vec<String>>>()
.register_type::<Option<Indices>>()
.register_type::<Indices>()
.register_type::<skinning::SkinnedMesh>()
.register_type::<Vec<Entity>>()
// 'Mesh' must be prepared after 'Image' as meshes rely on the morph target image being ready
Expand Down