-
Notifications
You must be signed in to change notification settings - Fork 10
Expose magica voxel scene info #10
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
Open
zzhgithub
wants to merge
7
commits into
Game4all:master
Choose a base branch
from
zzhgithub:more-info
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
af620a2
dev-read more info of vox.like many models and transform
zzhgithub 8047122
doc
zzhgithub b6c7a40
dev-add defualt hidden in layer define and toggle face in example boy
zzhgithub 1cdbb2d
dev-change named
zzhgithub 4c6e1e2
dev-change source label
zzhgithub 4700b82
fix
zzhgithub a7937a7
Update src/vox_scene_info.rs
zzhgithub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,174 @@ | ||
use bevy::prelude::*; | ||
use bevy_egui::EguiPlugin; | ||
use bevy_inspector_egui::quick::WorldInspectorPlugin; | ||
use bevy_vox_mesh::{vox_scene_info::VoxSceneInfo, VoxMeshPlugin}; | ||
use std::f32::consts::PI; | ||
|
||
fn main() { | ||
App::default() | ||
.add_plugins(DefaultPlugins) | ||
.add_plugins(EguiPlugin) | ||
.add_plugins(WorldInspectorPlugin::new()) | ||
.add_plugins(VoxMeshPlugin::default()) | ||
.register_type::<Entity>() | ||
.insert_resource(BoyMate { | ||
handle: None, | ||
mate: None, | ||
}) | ||
.insert_resource(BoyEntity { boy_entity: None }) | ||
.insert_resource(FaceNow::default()) | ||
.add_systems(Startup, setup) | ||
.add_systems(Update, (load_mate, load_boy, toggle_faces)) | ||
.run(); | ||
} | ||
|
||
#[derive(Debug, Resource)] | ||
pub struct BoyEntity { | ||
pub boy_entity: Option<Entity>, | ||
} | ||
|
||
#[derive(Debug, Resource, Clone)] | ||
pub struct BoyMate { | ||
pub handle: Option<Handle<VoxSceneInfo>>, | ||
pub mate: Option<VoxSceneInfo>, | ||
} | ||
|
||
#[derive(Debug, Resource, Clone)] | ||
pub struct FaceNow { | ||
pub now_face: &'static str, | ||
} | ||
|
||
impl Default for FaceNow { | ||
fn default() -> Self { | ||
Self { now_face: "face0" } | ||
} | ||
} | ||
|
||
fn toggle_faces( | ||
keyboard_input: Res<Input<KeyCode>>, | ||
mut query: Query<(Entity, &Name, &mut Visibility)>, | ||
mut face_now: ResMut<FaceNow>, | ||
) { | ||
let faces = vec!["face0", "face1", "face2", "face3"]; | ||
if keyboard_input.just_pressed(KeyCode::Tab) { | ||
if let Some(index) = faces.iter().position(|&x| x == face_now.now_face) { | ||
let next_index = if index == faces.len() - 1 { | ||
0 | ||
} else { | ||
index + 1 | ||
}; | ||
let next_face = faces[next_index]; | ||
for (_, name, mut visibility) in query.iter_mut() { | ||
if faces.contains(&name.as_str()) { | ||
if name.as_str() == next_face { | ||
*visibility.as_mut() = Visibility::Inherited; | ||
} else { | ||
*visibility.as_mut() = Visibility::Hidden; | ||
} | ||
} | ||
} | ||
face_now.now_face = next_face; | ||
} | ||
} | ||
} | ||
|
||
fn load_boy( | ||
mut commands: Commands, | ||
boy_mate: Res<BoyMate>, | ||
mut boy_entity: ResMut<BoyEntity>, | ||
assets: Res<AssetServer>, | ||
mut stdmats: ResMut<Assets<StandardMaterial>>, | ||
mut mesh_assets: ResMut<Assets<Mesh>>, | ||
) { | ||
if let Some(_entity) = boy_entity.boy_entity { | ||
// 这里可以进行其他的处理? | ||
} else { | ||
if let Some(mate_data) = boy_mate.mate.clone() { | ||
if mate_data.all_loaded("boy.vox", mesh_assets.as_ref(), assets.as_ref()) { | ||
// println!("这里生成模型的详情"); | ||
let boy = mate_data.to_entity( | ||
"boy.vox", | ||
&mut commands, | ||
assets.as_ref(), | ||
stdmats.add(Color::rgb(1., 1., 1.).into()), | ||
&mut mesh_assets, | ||
); | ||
commands.entity(boy).insert(( | ||
Visibility::Inherited, | ||
ComputedVisibility::HIDDEN, | ||
GlobalTransform::IDENTITY, | ||
Transform { | ||
translation: Vec3 { | ||
x: 0.0, | ||
y: 1.0 / 40. * 40., // height is 80 so the button is scale*80/2 | ||
z: 0.0, | ||
}, | ||
scale: Vec3 { | ||
x: 1.0 / 40., | ||
y: 1.0 / 40., | ||
z: 1.0 / 40., | ||
}, | ||
..Default::default() | ||
} * Transform::from_rotation(Quat::from_axis_angle(Vec3::Y, PI)), | ||
)); | ||
boy_entity.boy_entity = Some(boy); | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn load_mate(mate_assets: Res<Assets<VoxSceneInfo>>, mut boy_mate: ResMut<BoyMate>) { | ||
if let Some(handle) = boy_mate.handle.clone() { | ||
match boy_mate.mate { | ||
Some(_) => {} | ||
None => { | ||
if let Some(mate) = mate_assets.get(&handle) { | ||
boy_mate.mate = Some(mate.clone()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn setup( | ||
mut commands: Commands, | ||
mut meshes: ResMut<Assets<Mesh>>, | ||
mut stdmats: ResMut<Assets<StandardMaterial>>, | ||
mut boy_mate: ResMut<BoyMate>, | ||
assets: Res<AssetServer>, | ||
) { | ||
let mate_data_handle: Handle<VoxSceneInfo> = assets.load("boy.vox#scene"); | ||
boy_mate.handle = Some(mate_data_handle); | ||
|
||
commands.spawn(Camera3dBundle { | ||
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), | ||
..Default::default() | ||
}); | ||
|
||
commands.spawn(PointLightBundle { | ||
point_light: PointLight { | ||
intensity: 1500.0, | ||
shadows_enabled: true, | ||
..default() | ||
}, | ||
transform: Transform::from_xyz(4.0, 8.0, 4.0), | ||
..default() | ||
}); | ||
|
||
commands.spawn(PbrBundle { | ||
mesh: meshes.add(Mesh::from(shape::Plane { | ||
subdivisions: 2, | ||
size: 5.0, | ||
})), | ||
material: stdmats.add(Color::rgb(0.3, 0.5, 0.3).into()), | ||
..Default::default() | ||
}); | ||
|
||
// commands.spawn(PbrBundle { | ||
// transform: Transform::from_scale((0.01, 0.01, 0.01).into()) | ||
// * Transform::from_rotation(Quat::from_axis_angle(Vec3::Y, PI)), | ||
// mesh: assets.load("boy.vox#model5"), | ||
// material: stdmats.add(Color::rgb(1., 1., 1.).into()), | ||
// ..Default::default() | ||
// }); | ||
} |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just in case to not get into any legal trouble, what's the usage license for this ?