|
|
|
@ -70,7 +70,7 @@ impl Plugin for Display3dPlugin {
|
|
|
|
.or_else(any_component_added::<PointLight>)
|
|
|
|
.or_else(any_component_added::<PointLight>)
|
|
|
|
.or_else(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
.or_else(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
setup_capture_piece.run_if(any_component_added::<Piece>),
|
|
|
|
setup_capture_piece.run_if(any_component_changed::<Handle<StandardMaterial>>),
|
|
|
|
capture_piece.run_if(any_with_component::<game::Captured>()),
|
|
|
|
capture_piece.run_if(any_with_component::<game::Captured>()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -579,9 +579,10 @@ fn set_piece_texture(
|
|
|
|
.get_handle::<Gltf>("display3d_models_assets_file")
|
|
|
|
.get_handle::<Gltf>("display3d_models_assets_file")
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
if let Some(gltf) = gltfs.get(assets_handle) {
|
|
|
|
if let Some(gltf) = gltfs.get(assets_handle) {
|
|
|
|
children.iter_descendants(entity).for_each(|child| {
|
|
|
|
// Why can't we just models.iter_many_mut(...).for_each(...)??
|
|
|
|
if let Ok((n, mut m)) = models.get_mut(child) {
|
|
|
|
let mut stuff = models.iter_many_mut(children.iter_descendants(entity));
|
|
|
|
debug!("Setting piece texture for {:?}", child);
|
|
|
|
while let Some((n, mut m)) = stuff.fetch_next() {
|
|
|
|
|
|
|
|
debug!("Setting piece texture for {:?}", n);
|
|
|
|
match (*piece, side, n.as_str()) {
|
|
|
|
match (*piece, side, n.as_str()) {
|
|
|
|
(Piece::Queen, Side::A, "Queen.0") => {
|
|
|
|
(Piece::Queen, Side::A, "Queen.0") => {
|
|
|
|
*m = gltf
|
|
|
|
*m = gltf
|
|
|
|
@ -730,9 +731,8 @@ fn set_piece_texture(
|
|
|
|
_ => warn!("???"),
|
|
|
|
_ => warn!("???"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Select tiles and pieces in 3d
|
|
|
|
/// Select tiles and pieces in 3d
|
|
|
|
@ -1281,12 +1281,12 @@ struct Backup<T: Component>(T);
|
|
|
|
|
|
|
|
|
|
|
|
/// Sets up all pieces to have an associated "dissolve" material ready for capture
|
|
|
|
/// Sets up all pieces to have an associated "dissolve" material ready for capture
|
|
|
|
fn setup_capture_piece(
|
|
|
|
fn setup_capture_piece(
|
|
|
|
|
|
|
|
// All entities with materials are candidates for this procedure
|
|
|
|
|
|
|
|
events: Query<(Entity, &Handle<StandardMaterial>), (Added<Handle<StandardMaterial>>, Changed<Handle<StandardMaterial>>)>,
|
|
|
|
// Only process newly created pieces (we do not delete pieces at runtime)
|
|
|
|
// Only process newly created pieces (we do not delete pieces at runtime)
|
|
|
|
events: Query<Entity, Added<Piece>>,
|
|
|
|
query: Query<Entity, (With<Piece>, Added<Children>)>,
|
|
|
|
// Children of pieces are the actual meshes that need materials
|
|
|
|
// Children of pieces are the actual meshes that need materials
|
|
|
|
children: Query<&Children>,
|
|
|
|
parents: Query<&Parent>,
|
|
|
|
// All entities with materials are candidates for this procedure
|
|
|
|
|
|
|
|
query: Query<(Entity, &Handle<StandardMaterial>)>,
|
|
|
|
|
|
|
|
// Used to create DissovleMaterial
|
|
|
|
// Used to create DissovleMaterial
|
|
|
|
standard_materials: Res<Assets<StandardMaterial>>,
|
|
|
|
standard_materials: Res<Assets<StandardMaterial>>,
|
|
|
|
// Used to create Handle<DissolveMaterial>
|
|
|
|
// Used to create Handle<DissolveMaterial>
|
|
|
|
@ -1296,9 +1296,13 @@ fn setup_capture_piece(
|
|
|
|
// Cache dissolve textures that have already been created
|
|
|
|
// Cache dissolve textures that have already been created
|
|
|
|
mut cache: Local<HashMap<Handle<StandardMaterial>, Handle<DissolveMaterial>>>,
|
|
|
|
mut cache: Local<HashMap<Handle<StandardMaterial>, Handle<DissolveMaterial>>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
events.iter().for_each(|entity| {
|
|
|
|
events
|
|
|
|
query
|
|
|
|
.iter()
|
|
|
|
.iter_many(children.iter_descendants(entity))
|
|
|
|
// Only process if this is a child of a piece
|
|
|
|
|
|
|
|
.filter(|(child, _)| {
|
|
|
|
|
|
|
|
query.iter_many(parents.iter_ancestors(*child)).count() > 0
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
// Handle this entity (mesh)
|
|
|
|
.for_each(|(child, std_handle)| {
|
|
|
|
.for_each(|(child, std_handle)| {
|
|
|
|
let dis_handle = match cache.get(std_handle) {
|
|
|
|
let dis_handle = match cache.get(std_handle) {
|
|
|
|
// We have not seen this material, so create a new dissolve material
|
|
|
|
// We have not seen this material, so create a new dissolve material
|
|
|
|
@ -1319,16 +1323,14 @@ fn setup_capture_piece(
|
|
|
|
Some(dis_handle) => dis_handle.clone(),
|
|
|
|
Some(dis_handle) => dis_handle.clone(),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Insert this handle into the cache (may be redundant)
|
|
|
|
cache.insert(std_handle.clone(), dis_handle.clone());
|
|
|
|
cache.insert(std_handle.clone(), dis_handle.clone());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the dissolve handle as a Backup(T)
|
|
|
|
commands
|
|
|
|
commands
|
|
|
|
.entity(child)
|
|
|
|
.entity(child)
|
|
|
|
.insert(dis_handle.clone())
|
|
|
|
.insert(Backup(dis_handle.clone()));
|
|
|
|
.insert(Backup(std_handle.clone()))
|
|
|
|
});
|
|
|
|
.remove::<Handle<StandardMaterial>>();
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// When a piece is captured...
|
|
|
|
/// When a piece is captured...
|
|
|
|
@ -1363,9 +1365,8 @@ fn capture_piece(
|
|
|
|
*prog = 1.0;
|
|
|
|
*prog = 1.0;
|
|
|
|
|
|
|
|
|
|
|
|
// store the kids we want to process
|
|
|
|
// store the kids we want to process
|
|
|
|
*kids = children
|
|
|
|
*kids = object_standard_materials
|
|
|
|
.iter_descendants(entity)
|
|
|
|
.iter_many(children.iter_descendants(entity))
|
|
|
|
.filter_map(|e| object_standard_materials.get(e).ok())
|
|
|
|
|
|
|
|
.map(|(child, std_handle, Backup(dis_handle))| {
|
|
|
|
.map(|(child, std_handle, Backup(dis_handle))| {
|
|
|
|
// Swap standard and dissolve material
|
|
|
|
// Swap standard and dissolve material
|
|
|
|
commands
|
|
|
|
commands
|
|
|
|
@ -1418,6 +1419,10 @@ fn capture_piece(
|
|
|
|
"Play fade out animation {:?} {:?}",
|
|
|
|
"Play fade out animation {:?} {:?}",
|
|
|
|
delta, dissolve_material.extension.percentage
|
|
|
|
delta, dissolve_material.extension.percentage
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commands
|
|
|
|
|
|
|
|
.entity(_child)
|
|
|
|
|
|
|
|
.log_components();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|