All stuff beside lerp and screenshot

This commit is contained in:
rewin
2024-03-15 21:37:48 +03:00
parent 98f1398b9f
commit d8c837fa1b
12 changed files with 55 additions and 56 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ fn process_skinned_meshes(
// ``` // ```
// Building this hashmap before processing each joint avoids redundancy in // Building this hashmap before processing each joint avoids redundancy in
// the common case where the same joints are bound to multiple skinned meshes // the common case where the same joints are bound to multiple skinned meshes
let mut joint_collections = EntityHashMap::<Entity, EntityHashSet<Entity>>::default(); let mut joint_collections = EntityHashMap::<EntityHashSet>::default();
for (ent, skinned_mesh) in q_skinned_meshes.iter() { for (ent, skinned_mesh) in q_skinned_meshes.iter() {
cmd.entity(ent) cmd.entity(ent)
.insert(NoFrustumCulling) .insert(NoFrustumCulling)
+1 -1
View File
@@ -129,7 +129,7 @@ pub fn animate_bvh(
} }
} }
anim.timer.percent() anim.timer.fraction()
} else { } else {
0. 0.
}; };
+6 -7
View File
@@ -8,7 +8,7 @@ use wgpu::Extent3d;
use crate::{ use crate::{
bvh::{BvhAnimCompleteEvent, TestBvh}, bvh::{BvhAnimCompleteEvent, TestBvh},
scene::SceneState, scene::{SceneState, SkyboxHolder},
screenshot::{ScreenCapture, ScreenShotPlugin}, screenshot::{ScreenCapture, ScreenShotPlugin},
BvhPlugin, CommonPlugins, LoadLibraryObjectEvent, LoadSceneEvent, MainCamera, BvhPlugin, CommonPlugins, LoadLibraryObjectEvent, LoadSceneEvent, MainCamera,
MixamoImportEvent, MixamoPlugin, SkyboxId, StudioMode, WorldGridPlugin, MixamoImportEvent, MixamoPlugin, SkyboxId, StudioMode, WorldGridPlugin,
@@ -72,12 +72,11 @@ pub fn start_headless(
HeadlessMode::Scene(scene, skybox) => { HeadlessMode::Scene(scene, skybox) => {
app.add_systems( app.add_systems(
Startup, Startup,
move |mut cmd: Commands, mut ew: EventWriter<EditorEvent>| { move |mut cmd: Commands, mut ew: EventWriter<EditorEvent>, mut asset_server: Res<AssetServer>| {
cmd.insert_resource(Skybox {
image : skybox.clone(), cmd.insert_resource(SkyboxHolder(Some(Skybox { image: asset_server.load(skybox.clone()), brightness: 1.0 })));
brightness: 1.0
}); ew.send(EditorEvent::Load(EditorPrefabPath::File(scene.clone())));
ew.send(EditorEvent::Load(EditorPrefabPath::File(scene.clone())))
}, },
); );
} }
+3 -3
View File
@@ -28,7 +28,7 @@ pub(crate) fn nearest_common_ancestor(
q_parents: &Query<Option<&Parent>>, q_parents: &Query<Option<&Parent>>,
) -> Option<Entity> { ) -> Option<Entity> {
// Find the depth of each entity in the tree // Find the depth of each entity in the tree
let mut depths: EntityHashMap<Entity, usize> = EntityHashMap::default(); let mut depths = EntityHashMap::default();
for &ent in entities { for &ent in entities {
depths.insert(ent, find_depth(ent, q_parents)); depths.insert(ent, find_depth(ent, q_parents));
} }
@@ -40,7 +40,7 @@ pub(crate) fn nearest_common_ancestor(
// Traverse up the tree from each entity until we find each one's ancestor // Traverse up the tree from each entity until we find each one's ancestor
// at the level of lowest_depth // at the level of lowest_depth
let mut equalized: EntityHashSet<Entity> = EntityHashSet::default(); let mut equalized = EntityHashSet::default();
for ent in entities { for ent in entities {
let mut depth = depths[ent]; let mut depth = depths[ent];
let mut result = *ent; let mut result = *ent;
@@ -60,7 +60,7 @@ pub(crate) fn nearest_common_ancestor(
// by adding a some kind of mode switch to this function's parameters. // by adding a some kind of mode switch to this function's parameters.
// Walk up the tree from each of those entities until we find the common ancestor // Walk up the tree from each of those entities until we find the common ancestor
let mut parents: EntityHashSet<Entity> = EntityHashSet::default(); let mut parents = EntityHashSet::default();
loop { loop {
for &ent in equalized.iter() { for &ent in equalized.iter() {
if let Some(parent) = find_parent(ent, q_parents) { if let Some(parent) = find_parent(ent, q_parents) {
+13 -13
View File
@@ -97,9 +97,9 @@ fn translate_selection_events(keyboard: Res<ButtonInput<KeyCode>>, mut input: Ev
input.send(InputAction(Lifecycle::Stop, Selection::Clear.into())); input.send(InputAction(Lifecycle::Stop, Selection::Clear.into()));
} }
if keyboard.just_pressed(KeyCode::F) { if keyboard.just_pressed(KeyCode::KeyF) {
input.send(InputAction(Lifecycle::Start, Selection::Focus.into())); input.send(InputAction(Lifecycle::Start, Selection::Focus.into()));
} else if keyboard.just_released(KeyCode::F) { } else if keyboard.just_released(KeyCode::KeyF) {
input.send(InputAction(Lifecycle::Stop, Selection::Focus.into())); input.send(InputAction(Lifecycle::Stop, Selection::Focus.into()));
} }
@@ -112,9 +112,9 @@ fn translate_selection_events(keyboard: Res<ButtonInput<KeyCode>>, mut input: Ev
fn translate_debug_toggle(keyboard: Res<ButtonInput<KeyCode>>, mut input: EventWriter<InputAction>) { fn translate_debug_toggle(keyboard: Res<ButtonInput<KeyCode>>, mut input: EventWriter<InputAction>) {
if keyboard.pressed(KeyCode::ControlLeft) || keyboard.pressed(KeyCode::ControlRight) { if keyboard.pressed(KeyCode::ControlLeft) || keyboard.pressed(KeyCode::ControlRight) {
if keyboard.just_pressed(KeyCode::Grave) { if keyboard.just_pressed(KeyCode::Backquote) {
input.send(InputAction(Lifecycle::Start, Action::ToggleDebug)); input.send(InputAction(Lifecycle::Start, Action::ToggleDebug));
} else if keyboard.just_released(KeyCode::Grave) { } else if keyboard.just_released(KeyCode::Backquote) {
input.send(InputAction(Lifecycle::Stop, Action::ToggleDebug)); input.send(InputAction(Lifecycle::Stop, Action::ToggleDebug));
} }
} }
@@ -232,7 +232,7 @@ fn translate_fps_camera_events(
) { ) {
// Camera Translation (FPS-like) // Camera Translation (FPS-like)
use KeyCode::*; use KeyCode::*;
let wasd_keys = [KeyCode::W, KeyCode::A, KeyCode::S, KeyCode::D, KeyCode::E, KeyCode::Q]; let wasd_keys = [KeyCode::KeyW, KeyCode::KeyA, KeyCode::KeyS, KeyCode::KeyD, KeyCode::KeyE, KeyCode::KeyQ];
let wasd_keys_set = wasd_keys.into_iter().collect::<HashSet<_>>(); let wasd_keys_set = wasd_keys.into_iter().collect::<HashSet<_>>();
// A little unfortunate that `get_pressed()` doesn't just return a reference // A little unfortunate that `get_pressed()` doesn't just return a reference
@@ -247,12 +247,12 @@ fn translate_fps_camera_events(
let mut mvmt = Vec3::ZERO; let mut mvmt = Vec3::ZERO;
#[rustfmt::skip] { #[rustfmt::skip] {
if wasd_keys_pressed.contains(&KeyCode::W) { mvmt.z -= 1.; } if wasd_keys_pressed.contains(&KeyCode::KeyW) { mvmt.z -= 1.; }
if wasd_keys_pressed.contains(&KeyCode::A) { mvmt.x -= 1.; } if wasd_keys_pressed.contains(&KeyCode::KeyA) { mvmt.x -= 1.; }
if wasd_keys_pressed.contains(&KeyCode::S) { mvmt.z += 1.; } if wasd_keys_pressed.contains(&KeyCode::KeyS) { mvmt.z += 1.; }
if wasd_keys_pressed.contains(&KeyCode::D) { mvmt.x += 1.; } if wasd_keys_pressed.contains(&KeyCode::KeyD) { mvmt.x += 1.; }
if wasd_keys_pressed.contains(&KeyCode::E) { mvmt.y += 1.; } if wasd_keys_pressed.contains(&KeyCode::KeyE) { mvmt.y += 1.; }
if wasd_keys_pressed.contains(&KeyCode::Q) { mvmt.y -= 1.; } if wasd_keys_pressed.contains(&KeyCode::KeyQ) { mvmt.y -= 1.; }
}; };
let mvmt = mvmt.normalize_or_zero(); let mvmt = mvmt.normalize_or_zero();
@@ -335,7 +335,7 @@ fn read_mouse_delta(
// TODO: Make it configurable // TODO: Make it configurable
fn send_undo_event(mut events: EventWriter<UndoRedo>, keyboard: Res<ButtonInput<KeyCode>>) { fn send_undo_event(mut events: EventWriter<UndoRedo>, keyboard: Res<ButtonInput<KeyCode>>) {
if keyboard.pressed(KeyCode::ControlLeft) if keyboard.pressed(KeyCode::ControlLeft)
&& keyboard.just_pressed(KeyCode::Z) && keyboard.just_pressed(KeyCode::KeyZ)
&& !keyboard.pressed(KeyCode::ShiftLeft) && !keyboard.pressed(KeyCode::ShiftLeft)
{ {
events.send(UndoRedo::Undo); events.send(UndoRedo::Undo);
@@ -343,7 +343,7 @@ fn send_undo_event(mut events: EventWriter<UndoRedo>, keyboard: Res<ButtonInput<
} }
if keyboard.pressed(KeyCode::ControlLeft) if keyboard.pressed(KeyCode::ControlLeft)
&& keyboard.just_pressed(KeyCode::Z) && keyboard.just_pressed(KeyCode::KeyZ)
&& keyboard.pressed(KeyCode::ShiftLeft) && keyboard.pressed(KeyCode::ShiftLeft)
{ {
events.send(UndoRedo::Redo); events.send(UndoRedo::Redo);
+15 -15
View File
@@ -2,7 +2,7 @@ use bevy::prelude::*;
use crate::{design_system, math::geo}; use crate::{design_system, math::geo};
use super::material::GizmoMaterial; use super::material::*;
#[derive(Resource, Reflect, Debug, Default)] #[derive(Resource, Reflect, Debug, Default)]
#[reflect(Resource)] #[reflect(Resource)]
@@ -98,25 +98,25 @@ pub(super) fn init_resources(
uniform_scale_cube, uniform_scale_cube,
}); });
let translate_x = ra_mats.add(design_system::Color::RED.into()); let translate_x = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::RED));
let translate_yz = ra_mats.add(design_system::Color::RED.into()); let translate_yz = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::RED));
let translate_y = ra_mats.add(design_system::Color::GREEN.into()); let translate_y = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::GREEN));
let translate_xz = ra_mats.add(design_system::Color::GREEN.into()); let translate_xz = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::GREEN));
let translate_z = ra_mats.add(design_system::Color::BLUE.into()); let translate_z = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::BLUE));
let translate_xy = ra_mats.add(design_system::Color::BLUE.into()); let translate_xy = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::BLUE));
let translate_ss = ra_mats.add(Color::WHITE.into()); let translate_ss = ra_mats.add(Into::<GizmoMaterial>::into(Color::WHITE));
let rotate_x = ra_mats.add(design_system::Color::RED.into()); let rotate_x = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::RED));
let rotate_y = ra_mats.add(design_system::Color::GREEN.into()); let rotate_y = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::GREEN));
let rotate_z = ra_mats.add(design_system::Color::BLUE.into()); let rotate_z = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::BLUE));
let rotate_ss = ra_mats.add(Color::WHITE.into()); let rotate_ss = ra_mats.add(Into::<GizmoMaterial>::into(Color::WHITE));
let scale_x = ra_mats.add(design_system::Color::RED.into()); let scale_x = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::RED));
let scale_y = ra_mats.add(design_system::Color::GREEN.into()); let scale_y = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::GREEN));
let scale_z = ra_mats.add(design_system::Color::BLUE.into()); let scale_z = ra_mats.add(Into::<GizmoMaterial>::into(design_system::Color::BLUE));
let rotate_trackball = ra_mats.add(GizmoMaterial { let rotate_trackball = ra_mats.add(GizmoMaterial {
color: Color::WHITE.with_a(0.0), color: Color::WHITE.with_a(0.0),
+2 -2
View File
@@ -302,7 +302,7 @@ pub(super) fn on_rotate(
} }
let view_plane_normal = (cam_xform.translation() - p1).normalize(); let view_plane_normal = (cam_xform.translation() - p1).normalize();
let hit_dist = ray.intersect_plane(p1, view_plane_normal).unwrap(); let hit_dist = ray.intersect_plane(p1, Plane3d::new(view_plane_normal)).unwrap();
let p2 = ray.origin + ray.direction * hit_dist; let p2 = ray.origin + ray.direction * hit_dist;
let drag_dist = (p2 - p1).length(); let drag_dist = (p2 - p1).length();
// TODO: Sensitivity could use some tuning // TODO: Sensitivity could use some tuning
@@ -366,7 +366,7 @@ pub(super) fn on_rotate(
}; };
// Find the world-space p2, if possible // Find the world-space p2, if possible
let Some(hit_dist) = ray.intersect_plane(p0, axis_ws) else { let Some(hit_dist) = ray.intersect_plane(p0, Plane3d::new(axis_ws)) else {
// This could fail if the axis of rotation is nearly // This could fail if the axis of rotation is nearly
// perpendicular to the view direction // perpendicular to the view direction
return; return;
+2 -2
View File
@@ -261,7 +261,7 @@ pub(super) fn on_scale(
let plane_vector = axis_ws.cross(axis_tan); let plane_vector = axis_ws.cross(axis_tan);
// Find the intersection of the camera-to-world ray against that plane // Find the intersection of the camera-to-world ray against that plane
let Some(hit_dist) = ray.intersect_plane(origin_ws, plane_vector) else { let Some(hit_dist) = ray.intersect_plane(origin_ws, Plane3d::new(plane_vector)) else {
return; return;
}; };
let hit_point = ray.origin + ray.direction * hit_dist; let hit_point = ray.origin + ray.direction * hit_dist;
@@ -299,7 +299,7 @@ pub(super) fn on_scale(
.affine() .affine()
.transform_vector3(*plane_normal) .transform_vector3(*plane_normal)
.normalize(); .normalize();
let Some(hit_dist) = ray.intersect_plane(origin_ws, normal_ws) else { let Some(hit_dist) = ray.intersect_plane(origin_ws, Plane3d::new(normal_ws)) else {
return; return;
}; };
let hit_point = ray.origin + ray.direction * hit_dist; let hit_point = ray.origin + ray.direction * hit_dist;
+2 -2
View File
@@ -257,7 +257,7 @@ pub(super) fn on_translate(
let plane_vector = axis_ws.cross(axis_tan); let plane_vector = axis_ws.cross(axis_tan);
// Find the intersection of the camera-to-world ray against that plane // Find the intersection of the camera-to-world ray against that plane
let Some(hit_dist) = ray.intersect_plane(origin_ws, plane_vector) else { let Some(hit_dist) = ray.intersect_plane(origin_ws, Plane3d::new(plane_vector)) else {
return; return;
}; };
let hit_point = ray.origin + ray.direction * hit_dist; let hit_point = ray.origin + ray.direction * hit_dist;
@@ -290,7 +290,7 @@ pub(super) fn on_translate(
}; };
// Find the intersection of the camera-to-world ray against that plane // Find the intersection of the camera-to-world ray against that plane
let Some(hit_dist) = ray.intersect_plane(origin_ws, plane_normal) else { let Some(hit_dist) = ray.intersect_plane(origin_ws, Plane3d::new(plane_normal)) else {
return; return;
}; };
let target_ws = ray.origin + ray.direction * hit_dist; let target_ws = ray.origin + ray.direction * hit_dist;
+1 -1
View File
@@ -20,7 +20,7 @@ impl Plugin for SelectionPlugin {
Update, Update,
( (
update_selection, update_selection,
process_delete_inputs.run_if(resource_exists::<Selection>()), process_delete_inputs.run_if(resource_exists::<Selection>),
), ),
) )
.add_systems( .add_systems(
+1 -1
View File
@@ -16,7 +16,7 @@ impl Plugin for RemoteAssetPlugin {
AssetSourceId::Name("remote".into()), AssetSourceId::Name("remote".into()),
AssetSource::build() AssetSource::build()
.with_reader(|| Box::new(RemoteAssetReader)) .with_reader(|| Box::new(RemoteAssetReader))
.with_writer(|| None), .with_writer(|_| None),
); );
} }
} }
+8 -8
View File
@@ -1,4 +1,4 @@
use std::{io::ErrorKind, path::Path}; use std::{io::ErrorKind, path::Path, sync::Arc};
use bevy::{ use bevy::{
asset::io::{AssetReader, AssetReaderError, PathStream, Reader, VecReader}, asset::io::{AssetReader, AssetReaderError, PathStream, Reader, VecReader},
@@ -26,10 +26,10 @@ impl AssetReader for RemoteAssetReader {
let token = path let token = path
.ext_file_prefix() .ext_file_prefix()
.ok_or_else(|| { .ok_or_else(|| {
AssetReaderError::Io(std::io::Error::new( AssetReaderError::Io(Arc::new(std::io::Error::new(
ErrorKind::Other, ErrorKind::Other,
format!("Failed to parse token from '{path:?}'"), format!("Failed to parse token from '{path:?}'"),
)) )))
})? })?
.to_str() .to_str()
.unwrap(); .unwrap();
@@ -45,10 +45,10 @@ impl AssetReader for RemoteAssetReader {
.json::<GetMediaFileSuccessResponse>() .json::<GetMediaFileSuccessResponse>()
.await .await
.map_err(IntoError::<AssetReaderError>::into), .map_err(IntoError::<AssetReaderError>::into),
other => Err(AssetReaderError::Io(std::io::Error::new( other => Err(AssetReaderError::Io(Arc::new(std::io::Error::new(
ErrorKind::Other, ErrorKind::Other,
format!("Status Code from endpoint: {other}"), format!("Status Code from endpoint: {other}"),
))), )))),
}?; }?;
let url = format!( let url = format!(
@@ -74,10 +74,10 @@ impl AssetReader for RemoteAssetReader {
.map_err(IntoError::<AssetReaderError>::into)? .map_err(IntoError::<AssetReaderError>::into)?
.into_iter() .into_iter()
.collect::<Vec<_>>()), .collect::<Vec<_>>()),
other => Err(AssetReaderError::Io(std::io::Error::new( other => Err(AssetReaderError::Io(Arc::new(std::io::Error::new(
ErrorKind::Other, ErrorKind::Other,
format!("Status Code from bucket URL: {other}"), format!("Status Code from bucket URL: {other}"),
))), )))),
}?; }?;
let reader: Box<Reader> = Box::new(VecReader::new(bytes)); let reader: Box<Reader> = Box::new(VecReader::new(bytes));
@@ -113,6 +113,6 @@ trait IntoError<Output> {
impl IntoError<AssetReaderError> for reqwest::Error { impl IntoError<AssetReaderError> for reqwest::Error {
fn into(self) -> AssetReaderError { fn into(self) -> AssetReaderError {
AssetReaderError::Io(std::io::Error::new(ErrorKind::Other, format!("{self}"))) AssetReaderError::Io(Arc::new(std::io::Error::new(ErrorKind::Other, format!("{self}"))))
} }
} }