WIP: Manipulate the assembly #29

Draft
Vectornaut wants to merge 8 commits from tangent-space into main
Showing only changes of commit 64da1ba577 - Show all commits

View File

@ -126,6 +126,10 @@ pub fn Display() -> View {
// manipulation // manipulation
let translate_neg_x = create_signal(0.0); let translate_neg_x = create_signal(0.0);
let translate_pos_x = create_signal(0.0); let translate_pos_x = create_signal(0.0);
let translate_neg_y = create_signal(0.0);
let translate_pos_y = create_signal(0.0);
let translate_neg_z = create_signal(0.0);
let translate_pos_z = create_signal(0.0);
// change listener // change listener
let scene_changed = create_signal(true); let scene_changed = create_signal(true);
@ -284,6 +288,10 @@ pub fn Display() -> View {
// get the manipulation state // get the manipulation state
let translate_neg_x_val = translate_neg_x.get(); let translate_neg_x_val = translate_neg_x.get();
let translate_pos_x_val = translate_pos_x.get(); let translate_pos_x_val = translate_pos_x.get();
let translate_neg_y_val = translate_neg_y.get();
let translate_pos_y_val = translate_pos_y.get();
let translate_neg_z_val = translate_neg_z.get();
let translate_pos_z_val = translate_pos_z.get();
// update the assembly's orientation // update the assembly's orientation
let ang_vel = { let ang_vel = {
@ -318,17 +326,21 @@ pub fn Display() -> View {
let rep = state.assembly.elements.with_untracked( let rep = state.assembly.elements.with_untracked(
|elts| elts[sel].representation.get_clone_untracked() |elts| elts[sel].representation.get_clone_untracked()
); );
let vel_field_x = DMatrix::from_column_slice(5, 5, &[
0.0, 0.0, 0.0, 0.0, 1.0,
0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0,
2.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0
]);
let translate_x = translate_pos_x_val - translate_neg_x_val; let translate_x = translate_pos_x_val - translate_neg_x_val;
if translate_x != 0.0 { let translate_y = translate_pos_y_val - translate_neg_y_val;
let vel = translate_x * vel_field_x * rep; let translate_z = translate_pos_z_val - translate_neg_z_val;
let elt_motion: DVector<f64> = time_step * TRANSLATION_SPEED * vel; if translate_x != 0.0 || translate_y != 0.0 || translate_z != 0.0 {
let vel_field = {
let u = Vector3::new(translate_x, translate_y, translate_z).normalize();
DMatrix::from_column_slice(5, 5, &[
0.0, 0.0, 0.0, 0.0, u[0],
0.0, 0.0, 0.0, 0.0, u[1],
0.0, 0.0, 0.0, 0.0, u[2],
2.0*u[0], 2.0*u[1], 2.0*u[2], 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0
])
};
let elt_motion: DVector<f64> = time_step * TRANSLATION_SPEED * vel_field * rep;
assembly_for_raf.deform(vec![(sel, elt_motion.as_view())]); assembly_for_raf.deform(vec![(sel, elt_motion.as_view())]);
scene_changed.set(true); scene_changed.set(true);
} }
@ -474,9 +486,14 @@ pub fn Display() -> View {
let set_manip_signal = move |event: &KeyboardEvent, value: f64| { let set_manip_signal = move |event: &KeyboardEvent, value: f64| {
let mut manipulating = true; let mut manipulating = true;
let shift = event.shift_key();
match event.key().as_str() { match event.key().as_str() {
"d" => translate_pos_x.set(value), "d" | "D" => translate_pos_x.set(value),
"a" => translate_neg_x.set(value), "a" | "A" => translate_neg_x.set(value),
"w" | "W" if shift => translate_neg_z.set(value),
"s" | "S" if shift => translate_pos_z.set(value),
"w" | "W" => translate_pos_y.set(value),
"s" | "S" => translate_neg_y.set(value),
_ => manipulating = false _ => manipulating = false
}; };
if manipulating { if manipulating {
@ -495,6 +512,7 @@ pub fn Display() -> View {
tabindex="0", tabindex="0",
on:keydown=move |event: KeyboardEvent| { on:keydown=move |event: KeyboardEvent| {
if event.key() == "Shift" { if event.key() == "Shift" {
// swap navigation inputs
roll_cw.set(yaw_right.get()); roll_cw.set(yaw_right.get());
roll_ccw.set(yaw_left.get()); roll_ccw.set(yaw_left.get());
zoom_in.set(pitch_up.get()); zoom_in.set(pitch_up.get());
@ -503,6 +521,12 @@ pub fn Display() -> View {
yaw_left.set(0.0); yaw_left.set(0.0);
pitch_up.set(0.0); pitch_up.set(0.0);
pitch_down.set(0.0); pitch_down.set(0.0);
// swap manipulation inputs
translate_pos_z.set(translate_neg_y.get());
translate_neg_z.set(translate_pos_y.get());
translate_pos_y.set(0.0);
translate_neg_y.set(0.0);
} else { } else {
if event.key() == "Enter" { /* BENCHMARKING */ if event.key() == "Enter" { /* BENCHMARKING */
turntable.set_fn(|turn| !turn); turntable.set_fn(|turn| !turn);
@ -514,6 +538,7 @@ pub fn Display() -> View {
}, },
on:keyup=move |event: KeyboardEvent| { on:keyup=move |event: KeyboardEvent| {
if event.key() == "Shift" { if event.key() == "Shift" {
// swap navigation inputs
yaw_right.set(roll_cw.get()); yaw_right.set(roll_cw.get());
yaw_left.set(roll_ccw.get()); yaw_left.set(roll_ccw.get());
pitch_up.set(zoom_in.get()); pitch_up.set(zoom_in.get());
@ -522,6 +547,12 @@ pub fn Display() -> View {
roll_ccw.set(0.0); roll_ccw.set(0.0);
zoom_in.set(0.0); zoom_in.set(0.0);
zoom_out.set(0.0); zoom_out.set(0.0);
// swap manipulation inputs
translate_pos_y.set(translate_neg_z.get());
translate_neg_y.set(translate_pos_z.get());
translate_pos_z.set(0.0);
translate_neg_z.set(0.0);
} else { } else {
set_nav_signal(&event, 0.0); set_nav_signal(&event, 0.0);
set_manip_signal(&event, 0.0); set_manip_signal(&event, 0.0);