-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Meshlet GLTF processor #13431
Meshlet GLTF processor #13431
Changes from 26 commits
3fbc508
6cf0bee
b267e0c
f6e6554
cfaa541
d428c3c
ab34446
8915c32
d4e6567
6ee5f47
896eae8
bd258c2
70ea4a6
7d9b3d7
842291a
8857188
b7e684f
920bbdd
87fe640
dca38b8
21105cb
f630f1d
8ab47d3
2892523
275e3f2
baf783c
faa0b79
a7034cd
9e96e0b
0d99c8b
234a5a0
dd17657
34e08ef
9035d4d
179822a
b360a3b
cf7595d
4557879
c746a5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
( | ||
meta_format_version: "1.0", | ||
asset: Process( | ||
processor: "MeshletMeshProcessor", | ||
settings: ( | ||
loader_settings: (), | ||
saver_settings: (), | ||
), | ||
), | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,6 +283,14 @@ pub trait AssetApp { | |
fn register_asset_loader<L: AssetLoader>(&mut self, loader: L) -> &mut Self; | ||
/// Registers the given `processor` in the [`App`]'s [`AssetProcessor`]. | ||
fn register_asset_processor<P: Process>(&mut self, processor: P) -> &mut Self; | ||
/// Registers the given `processor` in the [`App`]'s [`AssetProcessor`] along with an extra alias. | ||
/// | ||
/// This alias can be used in meta files to refer to this asset processor without using the full type name. | ||
fn register_asset_processor_with_alias<P: Process>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still on vacation so this is just a quick review: I think this approach is solid, especially in the short term. I do think migrating to TypePath + supporting short names is the right long term move (this code was written in a pre-TypePath-merge world), but even in that case, it doesn't fully solve the "generic flattening / LoadAndSave erasure problem". We'd need to use that in combination with something like what @JMS55 suggested awhile back on discord (define a new short type name that shims Random musings: to support the more general "one to many asset transformations" space, we'll need to make meta serialization more type erased + dynamic than it currently is. That might also allow us to rethink how things like LoadAndSave are expressed. |
||
&mut self, | ||
processor: P, | ||
alias: &'static str, | ||
) -> &mut Self; | ||
/// Registers the given [`AssetSourceBuilder`] with the given `id`. | ||
/// | ||
/// Note that asset sources must be registered before adding [`AssetPlugin`] to your application, | ||
|
@@ -331,6 +339,17 @@ impl AssetApp for App { | |
self | ||
} | ||
|
||
fn register_asset_processor_with_alias<P: Process>( | ||
&mut self, | ||
processor: P, | ||
alias: &'static str, | ||
) -> &mut Self { | ||
if let Some(asset_processor) = self.world().get_resource::<AssetProcessor>() { | ||
asset_processor.register_processor_with_alias(processor, alias); | ||
} | ||
self | ||
} | ||
|
||
fn register_asset_source( | ||
&mut self, | ||
id: impl Into<AssetSourceId<'static>>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ use bevy_animation::AnimationClip; | |
use bevy_utils::HashMap; | ||
|
||
mod loader; | ||
#[cfg(feature = "meshlet")] | ||
mod meshlet_saver; | ||
mod vertex_attributes; | ||
pub use loader::*; | ||
|
||
|
@@ -55,26 +57,44 @@ impl GltfPlugin { | |
impl Plugin for GltfPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.register_type::<GltfExtras>() | ||
.init_asset::<RawGltf>() | ||
.init_asset::<Gltf>() | ||
.init_asset::<GltfNode>() | ||
.init_asset::<GltfPrimitive>() | ||
.init_asset::<GltfMesh>() | ||
.preregister_asset_loader::<GltfLoader>(&["gltf", "glb"]); | ||
|
||
#[cfg(feature = "meshlet")] | ||
app.register_asset_processor_with_alias::<bevy_asset::processor::LoadAndSave<RawGltfLoader, meshlet_saver::MeshletMeshGltfSaver>>( | ||
meshlet_saver::MeshletMeshGltfSaver.into(), | ||
"MeshletMeshProcessor" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be a good idea to still include Gltf & the bevy namespace here (maybe like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically bevy::asset would be inconsistent with the other auto generated processor names which use bevy_asset due to using std::any::type_name(), but I get what you're saying. |
||
); | ||
} | ||
|
||
fn finish(&self, app: &mut App) { | ||
let supported_compressed_formats = match app.world().get_resource::<RenderDevice>() { | ||
Some(render_device) => CompressedImageFormats::from_features(render_device.features()), | ||
None => CompressedImageFormats::NONE, | ||
}; | ||
|
||
app.register_asset_loader(RawGltfLoader); | ||
app.register_asset_loader(GltfLoader { | ||
supported_compressed_formats, | ||
custom_vertex_attributes: self.custom_vertex_attributes.clone(), | ||
}); | ||
} | ||
} | ||
|
||
/// Representation of a loaded glTF file. | ||
/// Underlying JSON Representation of a loaded glTF file. | ||
#[derive(Asset, Debug, TypePath)] | ||
pub struct RawGltf { | ||
/// The JSON section of a glTF file. | ||
pub gltf: gltf::Gltf, | ||
/// The buffers of a glTF file, whether from the GLB BIN section, or from external bin files. | ||
pub buffer_data: Vec<Vec<u8>>, | ||
} | ||
|
||
/// Bevy representation of a loaded glTF file. | ||
#[derive(Asset, Debug, TypePath)] | ||
pub struct Gltf { | ||
/// All scenes loaded from the glTF file. | ||
|
@@ -140,6 +160,11 @@ pub struct GltfMesh { | |
pub struct GltfPrimitive { | ||
/// Topology to be rendered. | ||
pub mesh: Handle<Mesh>, | ||
/// Meshlet topology to be rendered. | ||
/// | ||
/// If this is Some, then `mesh` is [`Handle::default()`]. | ||
#[cfg(feature = "meshlet")] | ||
pub meshlet_mesh: Option<Handle<bevy_pbr::experimental::meshlet::MeshletMesh>>, | ||
/// Material to apply to the `mesh`. | ||
pub material: Option<Handle<StandardMaterial>>, | ||
/// Additional data. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to not have an extra method here, and instead require asset processors to implement
TypePath
? (Probably not a now thing.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't think about TypePath, that might be a decent alternative.