|
|
|
@ -17,39 +17,33 @@ impl Plugin for Display3dPlugin {
|
|
|
|
OnExit(GameState::Loading),
|
|
|
|
OnExit(GameState::Loading),
|
|
|
|
(initialize, fix_skybox.before(initialize)),
|
|
|
|
(initialize, fix_skybox.before(initialize)),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(
|
|
|
|
|
|
|
|
Update,
|
|
|
|
|
|
|
|
menu::exit_to_menu.run_if(in_state(GameState::Display3d)),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
Update,
|
|
|
|
Update,
|
|
|
|
(
|
|
|
|
(
|
|
|
|
set_piece_position.run_if(any_component_changed::<BoardIndex>),
|
|
|
|
menu::exit_to_menu.run_if(in_state(GameState::Display3d)),
|
|
|
|
set_piece_model.run_if(any_component_changed::<Side>),
|
|
|
|
set_piece_model.run_if(any_component_added::<Piece3d>),
|
|
|
|
set_board_model.run_if(any_component_added::<Board3d>),
|
|
|
|
set_board_model.run_if(any_component_added::<Board3d>),
|
|
|
|
|
|
|
|
set_piece_position.run_if(any_component_changed::<BoardIndex>),
|
|
|
|
|
|
|
|
set_piece_texture.run_if(any_component_changed::<Side>),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
Update,
|
|
|
|
Update,
|
|
|
|
gizmo_system
|
|
|
|
(
|
|
|
|
.run_if(in_state(GameState::Display3d))
|
|
|
|
move_camera
|
|
|
|
.run_if(resource_exists::<debug::DebugEnabled>()),
|
|
|
|
.run_if(in_state(GameState::Display3d))
|
|
|
|
)
|
|
|
|
.run_if(on_event::<MouseMotion>()),
|
|
|
|
.add_systems(
|
|
|
|
gizmo_system.run_if(in_state(GameState::Display3d)),
|
|
|
|
Update,
|
|
|
|
mouse_zoom
|
|
|
|
move_camera
|
|
|
|
.run_if(in_state(GameState::Display3d))
|
|
|
|
.run_if(in_state(GameState::Display3d))
|
|
|
|
.run_if(on_event::<MouseWheel>()),
|
|
|
|
.run_if(on_event::<MouseMotion>())
|
|
|
|
)
|
|
|
|
.run_if(resource_exists::<debug::DebugEnabled>()),
|
|
|
|
.run_if(resource_exists::<debug::DebugEnabled>()),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
Update,
|
|
|
|
OnEnter(GameState::Display3d),
|
|
|
|
mouse_zoom
|
|
|
|
(activate::<Display3d>, set_piece_texture),
|
|
|
|
.run_if(in_state(GameState::Display3d))
|
|
|
|
|
|
|
|
.run_if(on_event::<MouseWheel>())
|
|
|
|
|
|
|
|
.run_if(resource_exists::<debug::DebugEnabled>()),
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(OnEnter(GameState::Display3d), activate::<Display3d>)
|
|
|
|
|
|
|
|
.add_systems(OnExit(GameState::Display3d), deactivate::<Display3d>);
|
|
|
|
.add_systems(OnExit(GameState::Display3d), deactivate::<Display3d>);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -80,7 +74,7 @@ fn load_assets(server: Res<AssetServer>, mut commands: Commands) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Initialize the 3d board
|
|
|
|
/// Initialize the 3d board
|
|
|
|
fn initialize(mut commands: Commands, board: Option<Res<game::Board>>, assets: Res<AssetsMap>) {
|
|
|
|
fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<AssetsMap>) {
|
|
|
|
info!("Initialize 3d camera");
|
|
|
|
info!("Initialize 3d camera");
|
|
|
|
// let handle = server.load("images/mars.hdr");
|
|
|
|
// let handle = server.load("images/mars.hdr");
|
|
|
|
commands.spawn((
|
|
|
|
commands.spawn((
|
|
|
|
@ -130,7 +124,7 @@ fn initialize(mut commands: Commands, board: Option<Res<game::Board>>, assets: R
|
|
|
|
parent
|
|
|
|
parent
|
|
|
|
.spawn((Display3d, Board3d, SceneBundle { ..default() }))
|
|
|
|
.spawn((Display3d, Board3d, SceneBundle { ..default() }))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
board.unwrap().pieces().iter().for_each(|(index, piece)| {
|
|
|
|
board.pieces().iter().for_each(|(index, piece)| {
|
|
|
|
let side = Board::side(index).expect("Spawn valid side");
|
|
|
|
let side = Board::side(index).expect("Spawn valid side");
|
|
|
|
|
|
|
|
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((
|
|
|
|
@ -161,14 +155,14 @@ fn fix_skybox(mut images: ResMut<Assets<Image>>, assets: Res<AssetsMap>) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Set the model for each piece based on the game::Piece::* marker
|
|
|
|
fn set_piece_model(
|
|
|
|
fn set_piece_model(
|
|
|
|
mut events: Query<(&mut Handle<Scene>, &Piece), (With<Piece3d>, Changed<Side>)>,
|
|
|
|
mut events: Query<(&mut Handle<Scene>, &Piece), Added<Piece3d>>,
|
|
|
|
assets_map: Option<Res<AssetsMap>>,
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let mf = assets_map.expect("Models file");
|
|
|
|
|
|
|
|
events.iter_mut().for_each(|(mut handle, piece)| {
|
|
|
|
events.iter_mut().for_each(|(mut handle, piece)| {
|
|
|
|
let gltf = gltfs.get(&mf.models).expect("Load GLTF content");
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
*handle = match piece {
|
|
|
|
*handle = match piece {
|
|
|
|
game::Piece::Pawn => gltf.named_scenes.get("Pawn"),
|
|
|
|
game::Piece::Pawn => gltf.named_scenes.get("Pawn"),
|
|
|
|
game::Piece::Drone => gltf.named_scenes.get("Drone"),
|
|
|
|
game::Piece::Drone => gltf.named_scenes.get("Drone"),
|
|
|
|
@ -181,12 +175,11 @@ fn set_piece_model(
|
|
|
|
|
|
|
|
|
|
|
|
fn set_board_model(
|
|
|
|
fn set_board_model(
|
|
|
|
mut events: Query<&mut Handle<Scene>, With<Board3d>>,
|
|
|
|
mut events: Query<&mut Handle<Scene>, With<Board3d>>,
|
|
|
|
assets_map: Option<Res<AssetsMap>>,
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let mf = assets_map.expect("Models file");
|
|
|
|
|
|
|
|
events.iter_mut().for_each(|mut handle| {
|
|
|
|
events.iter_mut().for_each(|mut handle| {
|
|
|
|
let gltf = gltfs.get(&mf.models).expect("Load GLTF content");
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
*handle = gltf
|
|
|
|
*handle = gltf
|
|
|
|
.named_scenes
|
|
|
|
.named_scenes
|
|
|
|
.get("Gameboard")
|
|
|
|
.get("Gameboard")
|
|
|
|
@ -259,3 +252,118 @@ fn mouse_zoom(
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Set the Texture for a piece given it's position (left or right) on the bord.
|
|
|
|
|
|
|
|
/// Executed when Side is changed or upon entry to Display3d state
|
|
|
|
|
|
|
|
/// Getting this to run _after_ GLTF is loaded is a pain.
|
|
|
|
|
|
|
|
/// PERF: We are saving what to work on in a Vector which is bad.
|
|
|
|
|
|
|
|
/// CAVEAT: We are only exeucting this when a piece changes or state is changed.
|
|
|
|
|
|
|
|
fn set_piece_texture(
|
|
|
|
|
|
|
|
events: Query<(Entity, &Piece, &Side), (With<Piece3d>, Changed<Side>)>,
|
|
|
|
|
|
|
|
all: Query<(Entity, &Piece, &Side), With<Piece3d>>,
|
|
|
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
|
|
|
|
children: Query<&Children>,
|
|
|
|
|
|
|
|
mut models: Query<(&Name, &mut Handle<StandardMaterial>)>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
let pieces = if events.is_empty() {
|
|
|
|
|
|
|
|
all.iter().collect::<Vec<(Entity, &Piece, &Side)>>()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
events.iter().collect::<Vec<(Entity, &Piece, &Side)>>()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
pieces.iter().for_each(|(entity, piece, side)| {
|
|
|
|
|
|
|
|
if let Some(gltf) = gltfs.get(&assets_map.models) {
|
|
|
|
|
|
|
|
children.iter_descendants(*entity).for_each(|child| {
|
|
|
|
|
|
|
|
if let Ok((n, mut m)) = models.get_mut(child) {
|
|
|
|
|
|
|
|
match (*piece, *side, n.as_str()) {
|
|
|
|
|
|
|
|
(Piece::Queen, Side::A, "Queen.0") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("Queen")
|
|
|
|
|
|
|
|
.expect("Load Red Queen texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Queen, Side::A, "Queen.1") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("Dots")
|
|
|
|
|
|
|
|
.expect("Load Red Dots texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Queen, Side::B, "Queen.0") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("QueenBlue")
|
|
|
|
|
|
|
|
.expect("Load Blue Queen texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Queen, Side::B, "Queen.1") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("DotsBlue")
|
|
|
|
|
|
|
|
.expect("Load Red Dots texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Drone, Side::A, "Drone.0") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("Drone")
|
|
|
|
|
|
|
|
.expect("Load Red Drone texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Drone, Side::A, "Drone.1") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("Dots")
|
|
|
|
|
|
|
|
.expect("Load Red Dots texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Drone, Side::B, "Drone.0") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("DroneBlue")
|
|
|
|
|
|
|
|
.expect("Load Blue Drone texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Drone, Side::B, "Drone.1") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("DotsBlue")
|
|
|
|
|
|
|
|
.expect("Load Blue Dots texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Pawn, Side::A, "Pawn.0") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("Pawn")
|
|
|
|
|
|
|
|
.expect("Load Red Pawn texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Pawn, Side::A, "Pawn.1") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("Dots")
|
|
|
|
|
|
|
|
.expect("Load Red Dots texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Pawn, Side::B, "Pawn.0") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("DroneBlue") // TODO: FIX
|
|
|
|
|
|
|
|
.expect("Load Blue Pawn texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(Piece::Pawn, Side::B, "Pawn.1") => {
|
|
|
|
|
|
|
|
*m = gltf
|
|
|
|
|
|
|
|
.named_materials
|
|
|
|
|
|
|
|
.get("DotsBlue")
|
|
|
|
|
|
|
|
.expect("Load Blue Dots texture")
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => warn!("???"),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|