-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
254 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,73 @@ | ||
use bevy::prelude::*; | ||
use bevy::{ | ||
gltf::GltfMesh, | ||
prelude::*, | ||
reflect::{TypePath, TypeUuid}, | ||
}; | ||
use bevy_shader_mtoon::MtoonPlugin; | ||
|
||
mod extensions; | ||
pub mod loader; | ||
|
||
pub mod mtoon { | ||
pub use bevy_shader_mtoon::*; | ||
} | ||
|
||
pub struct VrmPlugin; | ||
|
||
impl Plugin for VrmPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.init_asset_loader::<loader::VrmLoader>(); | ||
app.add_plugins(MtoonPlugin) | ||
.add_asset::<MtoonReplaceMat>() | ||
.init_asset_loader::<loader::VrmLoader>() | ||
.add_systems(Update, replace_mtoon_materials); | ||
} | ||
} | ||
|
||
#[derive(TypeUuid, TypePath, Debug, Clone)] | ||
#[uuid = "e16c60c0-fa00-4ead-b76f-f97823b8404e"] | ||
pub struct MtoonReplaceMat { | ||
mesh: Handle<GltfMesh>, | ||
primitive: usize, | ||
mtoon: Handle<mtoon::MtoonMaterial>, | ||
} | ||
|
||
fn replace_mtoon_materials( | ||
mut commands: Commands, | ||
mut replacements: ResMut<Assets<MtoonReplaceMat>>, | ||
gltf_meshes: Res<Assets<GltfMesh>>, | ||
meshes: Query<(Entity, &Handle<Mesh>), Without<Handle<mtoon::MtoonMaterial>>>, | ||
) { | ||
let mut to_remove = Vec::new(); | ||
|
||
for (replacement_handle, replacement) in replacements.iter() { | ||
let target = gltf_meshes.get(&replacement.mesh).unwrap(); | ||
|
||
target | ||
.primitives | ||
.iter() | ||
.enumerate() | ||
.for_each(|(i, primitive)| { | ||
if i != replacement.primitive { | ||
return; | ||
} | ||
|
||
for (ent, ent_mesh) in meshes.iter() { | ||
if *ent_mesh != primitive.mesh { | ||
continue; | ||
} | ||
|
||
commands | ||
.entity(ent) | ||
.remove::<Handle<StandardMaterial>>() | ||
.insert(replacement.mtoon.clone()); | ||
|
||
to_remove.push(replacement_handle); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
for handle in to_remove { | ||
replacements.remove(handle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.