3d models/materials/animations tweaks

Likely cannot update these in real time...
main
Elijah Voigt 2 years ago
parent d7d89d71da
commit 4040d55372

@ -29,9 +29,9 @@ put_down = "/SFX/3D/3DPutDownPiece"
idle = "/SFX/3D/3DPickup-Idle-PutdownWhirr" idle = "/SFX/3D/3DPickup-Idle-PutdownWhirr"
invalid = "/sfx/3D/3DInvalidMove" invalid = "/sfx/3D/3DInvalidMove"
######################################################################### ####################
# Display3d settings # Display3d settings
######################################################################### ####################
[display3d] [display3d]
### ###
# Multi-sample Anti-Aliasing # Multi-sample Anti-Aliasing
@ -41,6 +41,36 @@ invalid = "/sfx/3D/3DInvalidMove"
### ###
msaa = "Off" msaa = "Off"
[display3d.models]
assets_file = "models/Martian Chess.glb"
skybox_file = "images/skybox.png"
[display3d.models.scenes]
queen = "Queen"
drone = "Drone"
pawn = "Pawn"
board = "Gameboard"
valid_move = "Valid Move Spot"
[display3d.models.animations]
intro_a = "GameCamIntro1"
intro_b = "GameCamIntro2"
turn_a = "GameCamSide2>1"
turn_b = "GameCamSide1>2"
pick_up = "PiecePickup"
put_down = "PiecePutDown"
idle = "PieceIdle"
[display3d.models.materials]
queen_red = "Queen"
queen_blue = "QueenBlue"
drone_red = "Drone"
drone_blue = "DroneBlue"
pawn_red = "Pawn"
pawn_blue = "DroneBlue"
dots_red = "Dots"
dots_blue = "DotsBlue"
### ###
# Fog # Fog
# Only seems to affect objects and not skyboxes # Only seems to affect objects and not skyboxes
@ -93,9 +123,9 @@ post_saturation = 1.0
# Options: Off, Low, Medium, High, Ultra # Options: Off, Low, Medium, High, Ultra
quality_level = "Off" quality_level = "Off"
### ####################
# Display 2D tweaks # Display2d settings
### ####################
[display2d.sprites] [display2d.sprites]
# Sprite file path inside the `assets` folder # Sprite file path inside the `assets` folder
file = "images/sprites.png" file = "images/sprites.png"

@ -28,7 +28,6 @@ pub(crate) struct Display3dPlugin;
impl Plugin for Display3dPlugin { impl Plugin for Display3dPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_plugins(TemporalAntiAliasPlugin) app.add_plugins(TemporalAntiAliasPlugin)
.add_systems(OnEnter(GameState::Loading), load_assets)
.insert_resource(Msaa::Off) .insert_resource(Msaa::Off)
.add_systems( .add_systems(
OnExit(GameState::Loading), OnExit(GameState::Loading),
@ -37,6 +36,9 @@ impl Plugin for Display3dPlugin {
.add_systems( .add_systems(
Update, Update,
( (
load_assets
.run_if(in_state(GameState::Loading))
.run_if(on_event::<AssetEvent<Tweakfile>>()),
hydrate_camera.run_if(any_component_added::<Camera3d>), hydrate_camera.run_if(any_component_added::<Camera3d>),
set_piece_model.run_if(any_component_added::<Piece>), set_piece_model.run_if(any_component_added::<Piece>),
set_board_model.run_if(any_component_added::<game::BoardComponent>), set_board_model.run_if(any_component_added::<game::BoardComponent>),
@ -119,7 +121,11 @@ fn load_assets(
mut commands: Commands, mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
tweaks: Res<Assets<Tweakfile>>,
) { ) {
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
let tweak = tweaks.get(&handle).expect("Load tweakfile");
let hitbox_shape = meshes.add(shape::Box::new(1.0, 0.1, 1.0).into()); let hitbox_shape = meshes.add(shape::Box::new(1.0, 0.1, 1.0).into());
let hitbox_material = materials.add(StandardMaterial { let hitbox_material = materials.add(StandardMaterial {
base_color: Color::NONE, base_color: Color::NONE,
@ -129,8 +135,8 @@ fn load_assets(
..default() ..default()
}); });
commands.insert_resource(AssetsMap { commands.insert_resource(AssetsMap {
models: server.load("models/Martian Chess.glb"), models: server.load(tweak.display3d.models.assets_file.as_str()),
skybox: server.load("images/skybox.png"), skybox: server.load(tweak.display3d.models.skybox_file.as_str()),
hitbox_shape, hitbox_shape,
hitbox_material, hitbox_material,
}); });
@ -196,7 +202,11 @@ fn hydrate_camera(
state: Res<State<game::TurnState>>, state: Res<State<game::TurnState>>,
mut players: Query<&mut AnimationPlayer>, mut players: Query<&mut AnimationPlayer>,
mut commands: Commands, mut commands: Commands,
tweaks: Res<Assets<Tweakfile>>,
server: Res<AssetServer>,
) { ) {
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
let tweak = tweaks.get(&handle).expect("Load tweakfile");
events events
.iter() .iter()
.filter(|(name, _)| name.as_str() == "GameCam") .filter(|(name, _)| name.as_str() == "GameCam")
@ -209,7 +219,7 @@ fn hydrate_camera(
Camera3dBundle { Camera3dBundle {
camera: Camera { camera: Camera {
is_active: false, is_active: false,
hdr: true, hdr: tweak.display3d.hdr,
..default() ..default()
}, },
dither: DebandDither::Enabled, dither: DebandDither::Enabled,
@ -235,8 +245,12 @@ fn hydrate_camera(
debug!("Animations: {:?}", gltf.named_animations.keys()); debug!("Animations: {:?}", gltf.named_animations.keys());
// GameCamIntro1, GameCamIntro2, GameCamSide1>2, GameCamSide2>1 // GameCamIntro1, GameCamIntro2, GameCamSide1>2, GameCamSide2>1
let animation = match state.get() { let animation = match state.get() {
game::TurnState::SideA => gltf.named_animations.get("GameCamIntro1"), game::TurnState::SideA => gltf
game::TurnState::SideB => gltf.named_animations.get("GameCamIntro2"), .named_animations
.get(tweak.display3d.models.animations.intro_a.as_str()),
game::TurnState::SideB => gltf
.named_animations
.get(tweak.display3d.models.animations.intro_b.as_str()),
}; };
player player
.play(animation.expect("Camera Startup").clone()) .play(animation.expect("Camera Startup").clone())
@ -312,13 +326,23 @@ fn set_piece_model(
mut events: Query<(&mut Handle<Scene>, &Piece), (Added<game::Piece>, With<Display3d>)>, mut events: Query<(&mut Handle<Scene>, &Piece), (Added<game::Piece>, With<Display3d>)>,
assets_map: Res<AssetsMap>, assets_map: Res<AssetsMap>,
gltfs: Res<Assets<Gltf>>, gltfs: Res<Assets<Gltf>>,
tweaks: Res<Assets<Tweakfile>>,
server: Res<AssetServer>,
) { ) {
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
let tweak = tweaks.get(&handle).expect("Load tweakfile");
events.iter_mut().for_each(|(mut handle, piece)| { events.iter_mut().for_each(|(mut handle, piece)| {
let gltf = gltfs.get(&assets_map.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
game::Piece::Drone => gltf.named_scenes.get("Drone"), .named_scenes
game::Piece::Queen => gltf.named_scenes.get("Queen"), .get(tweak.display3d.models.scenes.pawn.as_str()),
game::Piece::Drone => gltf
.named_scenes
.get(tweak.display3d.models.scenes.drone.as_str()),
game::Piece::Queen => gltf
.named_scenes
.get(tweak.display3d.models.scenes.queen.as_str()),
} }
.expect("Game board model") .expect("Game board model")
.clone(); .clone();
@ -344,15 +368,20 @@ fn set_board_model(
>, >,
assets_map: Res<AssetsMap>, assets_map: Res<AssetsMap>,
gltfs: Res<Assets<Gltf>>, gltfs: Res<Assets<Gltf>>,
tweaks: Res<Assets<Tweakfile>>,
server: Res<AssetServer>,
) { ) {
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
let tweak = tweaks.get(&handle).expect("Load tweakfile");
boards.iter_mut().for_each(|mut handle| { boards.iter_mut().for_each(|mut handle| {
let gltf = gltfs.get(&assets_map.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(tweak.display3d.models.scenes.board.as_str())
.expect("Game board model") .expect("Game board model")
.clone(); .clone();
}); });
// TODO: Get rid of this -- upstream asset has merged tiles back into gameboard scene
tiles.iter_mut().for_each(|mut handle| { tiles.iter_mut().for_each(|mut handle| {
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content"); let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
*handle = gltf *handle = gltf
@ -459,7 +488,11 @@ fn set_piece_texture(
assets_map: Res<AssetsMap>, assets_map: Res<AssetsMap>,
children: Query<&Children>, children: Query<&Children>,
mut models: Query<(&Name, &mut Handle<StandardMaterial>)>, mut models: Query<(&Name, &mut Handle<StandardMaterial>)>,
tweaks: Res<Assets<Tweakfile>>,
server: Res<AssetServer>,
) { ) {
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
let tweak = tweaks.get(&handle).expect("Load tweakfile");
events.iter().for_each(|(entity, piece, side)| { events.iter().for_each(|(entity, piece, side)| {
debug!("Checking piece texture for {:?}", entity); debug!("Checking piece texture for {:?}", entity);
if let Some(gltf) = gltfs.get(&assets_map.models) { if let Some(gltf) = gltfs.get(&assets_map.models) {
@ -470,84 +503,84 @@ fn set_piece_texture(
(Piece::Queen, Side::A, "Queen.0") => { (Piece::Queen, Side::A, "Queen.0") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("Queen") .get(tweak.display3d.models.materials.queen_red.as_str())
.expect("Load Red Queen texture") .expect("Load Red Queen texture")
.clone() .clone()
} }
(Piece::Queen, Side::A, "Queen.1") => { (Piece::Queen, Side::A, "Queen.1") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("Dots") .get(tweak.display3d.models.materials.dots_red.as_str())
.expect("Load Red Dots texture") .expect("Load Red Dots texture")
.clone() .clone()
} }
(Piece::Queen, Side::B, "Queen.0") => { (Piece::Queen, Side::B, "Queen.0") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("QueenBlue") .get(tweak.display3d.models.materials.queen_blue.as_str())
.expect("Load Blue Queen texture") .expect("Load Blue Queen texture")
.clone() .clone()
} }
(Piece::Queen, Side::B, "Queen.1") => { (Piece::Queen, Side::B, "Queen.1") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("DotsBlue") .get(tweak.display3d.models.materials.dots_blue.as_str())
.expect("Load Red Dots texture") .expect("Load Red Dots texture")
.clone() .clone()
} }
(Piece::Drone, Side::A, "Drone.0") => { (Piece::Drone, Side::A, "Drone.0") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("Drone") .get(tweak.display3d.models.materials.drone_red.as_str())
.expect("Load Red Drone texture") .expect("Load Red Drone texture")
.clone() .clone()
} }
(Piece::Drone, Side::A, "Drone.1") => { (Piece::Drone, Side::A, "Drone.1") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("Dots") .get(tweak.display3d.models.materials.dots_red.as_str())
.expect("Load Red Dots texture") .expect("Load Red Dots texture")
.clone() .clone()
} }
(Piece::Drone, Side::B, "Drone.0") => { (Piece::Drone, Side::B, "Drone.0") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("DroneBlue") .get(tweak.display3d.models.materials.drone_blue.as_str())
.expect("Load Blue Drone texture") .expect("Load Blue Drone texture")
.clone() .clone()
} }
(Piece::Drone, Side::B, "Drone.1") => { (Piece::Drone, Side::B, "Drone.1") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("DotsBlue") .get(tweak.display3d.models.materials.dots_blue.as_str())
.expect("Load Blue Dots texture") .expect("Load Blue Dots texture")
.clone() .clone()
} }
(Piece::Pawn, Side::A, "Pawn.0") => { (Piece::Pawn, Side::A, "Pawn.0") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("Pawn") .get(tweak.display3d.models.materials.pawn_red.as_str())
.expect("Load Red Pawn texture") .expect("Load Red Pawn texture")
.clone() .clone()
} }
(Piece::Pawn, Side::A, "Pawn.1") => { (Piece::Pawn, Side::A, "Pawn.1") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("Dots") .get(tweak.display3d.models.materials.dots_red.as_str())
.expect("Load Red Dots texture") .expect("Load Red Dots texture")
.clone() .clone()
} }
(Piece::Pawn, Side::B, "Pawn.0") => { (Piece::Pawn, Side::B, "Pawn.0") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("DroneBlue") // TODO: FIX .get(tweak.display3d.models.materials.pawn_blue.as_str())
.expect("Load Blue Pawn texture") .expect("Load Blue Pawn texture")
.clone() .clone()
} }
(Piece::Pawn, Side::B, "Pawn.1") => { (Piece::Pawn, Side::B, "Pawn.1") => {
*m = gltf *m = gltf
.named_materials .named_materials
.get("DotsBlue") .get(tweak.display3d.models.materials.dots_blue.as_str())
.expect("Load Blue Dots texture") .expect("Load Blue Dots texture")
.clone() .clone()
} }
@ -668,10 +701,18 @@ fn set_valid_move_model(
mut events: Query<&mut Handle<Scene>, (With<Display3d>, Added<game::ValidMove>)>, mut events: Query<&mut Handle<Scene>, (With<Display3d>, Added<game::ValidMove>)>,
gltfs: Res<Assets<Gltf>>, gltfs: Res<Assets<Gltf>>,
assets_map: Res<AssetsMap>, assets_map: Res<AssetsMap>,
tweaks: Res<Assets<Tweakfile>>,
server: Res<AssetServer>,
) { ) {
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
let tweak = tweaks.get(&handle).expect("Load tweakfile");
if let Some(gltf) = gltfs.get(&assets_map.models) { if let Some(gltf) = gltfs.get(&assets_map.models) {
events.iter_mut().for_each(|mut handle| { events.iter_mut().for_each(|mut handle| {
*handle = gltf.named_scenes.get("Valid Move Spot").unwrap().clone() *handle = gltf
.named_scenes
.get(tweak.display3d.models.scenes.valid_move.as_str())
.unwrap()
.clone()
}) })
} }
} }
@ -703,14 +744,22 @@ fn pick_up(
gltfs: Res<Assets<Gltf>>, gltfs: Res<Assets<Gltf>>,
children: Query<&Children>, children: Query<&Children>,
mut players: Query<&mut AnimationPlayer>, mut players: Query<&mut AnimationPlayer>,
tweaks: Res<Assets<Tweakfile>>,
server: Res<AssetServer>,
) { ) {
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
let tweak = tweaks.get(&handle).expect("Load tweakfile");
events.iter_mut().for_each(|(entity, piece)| { events.iter_mut().for_each(|(entity, piece)| {
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content"); let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
children.iter_descendants(entity).for_each(|child| { children.iter_descendants(entity).for_each(|child| {
if let Ok(mut player) = players.get_mut(child) { if let Ok(mut player) = players.get_mut(child) {
info!("Picking up {:?} {:?}", entity, piece); info!("Picking up {:?} {:?}", entity, piece);
let animation = gltf.named_animations.get("PiecePickup"); let animation = gltf
let idle = gltf.named_animations.get("PieceIdle"); .named_animations
.get(tweak.display3d.models.animations.pick_up.as_str());
let idle = gltf
.named_animations
.get(tweak.display3d.models.animations.idle.as_str());
player player
.start_with_transition( .start_with_transition(
animation.expect("Pickup Animation").clone(), animation.expect("Pickup Animation").clone(),
@ -733,14 +782,20 @@ fn put_down(
gltfs: Res<Assets<Gltf>>, gltfs: Res<Assets<Gltf>>,
children: Query<&Children>, children: Query<&Children>,
mut players: Query<&mut AnimationPlayer>, mut players: Query<&mut AnimationPlayer>,
tweaks: Res<Assets<Tweakfile>>,
server: Res<AssetServer>,
) { ) {
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
let tweak = tweaks.get(&handle).expect("Load tweakfile");
events.iter().for_each(|entity| { events.iter().for_each(|entity| {
if let Ok(_piece) = query.get_mut(entity) { if let Ok(_piece) = query.get_mut(entity) {
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content"); let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
children.iter_descendants(entity).for_each(|child| { children.iter_descendants(entity).for_each(|child| {
if let Ok(mut player) = players.get_mut(child) { if let Ok(mut player) = players.get_mut(child) {
info!("Putting down {:?}", entity); info!("Putting down {:?}", entity);
let animation = gltf.named_animations.get("PiecePutDown"); let animation = gltf
.named_animations
.get(tweak.display3d.models.animations.put_down.as_str());
player player
.start_with_transition( .start_with_transition(
animation.expect("PutDown Animation").clone(), animation.expect("PutDown Animation").clone(),
@ -773,12 +828,20 @@ fn switch_sides(
assets_map: Res<AssetsMap>, assets_map: Res<AssetsMap>,
gltfs: Res<Assets<Gltf>>, gltfs: Res<Assets<Gltf>>,
state: Res<State<game::TurnState>>, state: Res<State<game::TurnState>>,
tweaks: Res<Assets<Tweakfile>>,
server: Res<AssetServer>,
) { ) {
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
let tweak = tweaks.get(&handle).expect("Load tweakfile");
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content"); let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
players.iter_mut().for_each(|mut player| { players.iter_mut().for_each(|mut player| {
let animation = match state.get() { let animation = match state.get() {
game::TurnState::SideA => gltf.named_animations.get("GameCamSide2>1"), game::TurnState::SideA => gltf
game::TurnState::SideB => gltf.named_animations.get("GameCamSide1>2"), .named_animations
.get(tweak.display3d.models.animations.turn_a.as_str()),
game::TurnState::SideB => gltf
.named_animations
.get(tweak.display3d.models.animations.turn_b.as_str()),
}; };
player.start_with_transition( player.start_with_transition(
animation.expect("Camera Transition Animation").clone(), animation.expect("Camera Transition Animation").clone(),
@ -796,6 +859,8 @@ pub(crate) mod tweaks {
#[derive(Debug, Deserialize, Default)] #[derive(Debug, Deserialize, Default)]
pub(crate) struct Display3dTweaks { pub(crate) struct Display3dTweaks {
#[serde(default)]
pub hdr: bool,
#[serde(default)] #[serde(default)]
pub fog: FogTweaks, pub fog: FogTweaks,
#[serde(default)] #[serde(default)]
@ -804,6 +869,8 @@ pub(crate) mod tweaks {
pub ssao: SsaoTweaks, pub ssao: SsaoTweaks,
#[serde(default)] #[serde(default)]
pub msaa: MsaaTweaks, pub msaa: MsaaTweaks,
#[serde(default)]
pub models: ModelTweaks,
} }
#[derive(Debug, Deserialize, Default)] #[derive(Debug, Deserialize, Default)]
@ -1002,4 +1069,45 @@ pub(crate) mod tweaks {
} }
} }
} }
#[derive(Debug, Deserialize, Default, Clone)]
pub(crate) struct ModelTweaks {
pub assets_file: String,
pub skybox_file: String,
pub scenes: SceneTweaks,
pub animations: AnimationTweaks,
pub materials: MaterialTweaks,
}
#[derive(Debug, Deserialize, Default, Clone)]
pub(crate) struct SceneTweaks {
pub queen: String,
pub drone: String,
pub pawn: String,
pub board: String,
pub valid_move: String,
}
#[derive(Debug, Deserialize, Default, Clone)]
pub(crate) struct AnimationTweaks {
pub intro_a: String,
pub intro_b: String,
pub turn_a: String,
pub turn_b: String,
pub pick_up: String,
pub put_down: String,
pub idle: String,
}
#[derive(Debug, Deserialize, Default, Clone)]
pub(crate) struct MaterialTweaks {
pub queen_red: String,
pub queen_blue: String,
pub drone_red: String,
pub drone_blue: String,
pub pawn_red: String,
pub pawn_blue: String,
pub dots_red: String,
pub dots_blue: String,
}
} }

Loading…
Cancel
Save