Add low-curvature construction
Also add infrastructure for switching between constructions.
This commit is contained in:
parent
121934c4c3
commit
3493a798d1
@ -18,14 +18,41 @@ canvas {
|
|||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.control {
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.control, .tab-pane {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
width: 600px;
|
width: 600px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type="radio"] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-pane > label {
|
||||||
|
border: 1px solid #aaa;
|
||||||
|
border-radius: 5px;
|
||||||
|
text-align: center;
|
||||||
|
padding: 5px;
|
||||||
|
margin-right: 10px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-pane > label:has(:checked) {
|
||||||
|
border-color: #fcfcfc;
|
||||||
|
background-color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-pane > label:hover:not(:has(:checked)) {
|
||||||
|
border-color: #bbb;
|
||||||
|
background-color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
label {
|
label {
|
||||||
width: 150px;
|
width: 170px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
extern crate js_sys;
|
extern crate js_sys;
|
||||||
use core::array;
|
use core::array;
|
||||||
use nalgebra::{DMatrix, DVector};
|
use nalgebra::{DMatrix, DVector};
|
||||||
|
use std::f64::consts::FRAC_1_SQRT_2;
|
||||||
use sycamore::{prelude::*, motion::create_raf, rt::{JsCast, JsValue}};
|
use sycamore::{prelude::*, motion::create_raf, rt::{JsCast, JsValue}};
|
||||||
use web_sys::{console, window, WebGl2RenderingContext, WebGlProgram, WebGlShader, WebGlUniformLocation};
|
use web_sys::{console, window, WebGl2RenderingContext, WebGlProgram, WebGlShader, WebGlUniformLocation};
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ fn bind_vertex_attrib(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_gen_test_construction(
|
fn push_gen_construction(
|
||||||
sphere_vec: &mut Vec<DVector<f64>>,
|
sphere_vec: &mut Vec<DVector<f64>>,
|
||||||
construction_to_world: &DMatrix<f64>,
|
construction_to_world: &DMatrix<f64>,
|
||||||
ctrl_x: f64,
|
ctrl_x: f64,
|
||||||
@ -99,17 +100,46 @@ fn push_gen_test_construction(
|
|||||||
sphere_vec.push(construction_to_world * engine::sphere(0.0, -0.15, -1.0, 0.25));
|
sphere_vec.push(construction_to_world * engine::sphere(0.0, -0.15, -1.0, 0.25));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn push_low_curv_construction(
|
||||||
|
sphere_vec: &mut Vec<DVector<f64>>,
|
||||||
|
construction_to_world: &DMatrix<f64>,
|
||||||
|
curv_x: f64,
|
||||||
|
curv_y: f64
|
||||||
|
) {
|
||||||
|
sphere_vec.push(construction_to_world * DVector::from_column_slice(&[0.0, -1.0, 0.0, 0.5*curv_x, 0.0]));
|
||||||
|
sphere_vec.push(construction_to_world * DVector::from_column_slice(&[-FRAC_1_SQRT_2, 0.0, -FRAC_1_SQRT_2, 0.5*curv_y, 0.0]));
|
||||||
|
sphere_vec.push(construction_to_world * engine::sphere(0.5, 0.0, 0.5, FRAC_1_SQRT_2));
|
||||||
|
sphere_vec.push(construction_to_world * engine::sphere(-0.5, 0.0, -0.5, FRAC_1_SQRT_2));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
|
enum Tab {
|
||||||
|
GenTab,
|
||||||
|
LowCurvTab
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// set up a config option that forwards panic messages to `console.error`
|
// set up a config option that forwards panic messages to `console.error`
|
||||||
#[cfg(feature = "console_error_panic_hook")]
|
#[cfg(feature = "console_error_panic_hook")]
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
sycamore::render(|| {
|
sycamore::render(|| {
|
||||||
// controls
|
// tab selection
|
||||||
|
let tab_selection = create_signal(Tab::GenTab);
|
||||||
|
|
||||||
|
// controls for general example
|
||||||
|
let gen_controls = create_node_ref();
|
||||||
let ctrl_x = create_signal(0.0);
|
let ctrl_x = create_signal(0.0);
|
||||||
let ctrl_y = create_signal(0.0);
|
let ctrl_y = create_signal(0.0);
|
||||||
let radius_x = create_signal(1.0);
|
let radius_x = create_signal(1.0);
|
||||||
let radius_y = create_signal(1.0);
|
let radius_y = create_signal(1.0);
|
||||||
|
|
||||||
|
// controls for low-curvature example
|
||||||
|
let low_curv_controls = create_node_ref();
|
||||||
|
let curv_x = create_signal(0.0);
|
||||||
|
let curv_y = create_signal(0.0);
|
||||||
|
|
||||||
|
// shared controls
|
||||||
let opacity = create_signal(0.5);
|
let opacity = create_signal(0.5);
|
||||||
let highlight = create_signal(0.2);
|
let highlight = create_signal(0.2);
|
||||||
let turntable = create_signal(false);
|
let turntable = create_signal(false);
|
||||||
@ -128,10 +158,20 @@ fn main() {
|
|||||||
// change listener
|
// change listener
|
||||||
let scene_changed = create_signal(true);
|
let scene_changed = create_signal(true);
|
||||||
create_effect(move || {
|
create_effect(move || {
|
||||||
|
// track tab selection
|
||||||
|
tab_selection.track();
|
||||||
|
|
||||||
|
// track controls for general example
|
||||||
ctrl_x.track();
|
ctrl_x.track();
|
||||||
ctrl_y.track();
|
ctrl_y.track();
|
||||||
radius_x.track();
|
radius_x.track();
|
||||||
radius_y.track();
|
radius_y.track();
|
||||||
|
|
||||||
|
// track controls for low-curvature example
|
||||||
|
curv_x.track();
|
||||||
|
curv_y.track();
|
||||||
|
|
||||||
|
// track shared controls
|
||||||
opacity.track();
|
opacity.track();
|
||||||
highlight.track();
|
highlight.track();
|
||||||
turntable.track();
|
turntable.track();
|
||||||
@ -142,6 +182,23 @@ fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
on_mount(move || {
|
on_mount(move || {
|
||||||
|
// tab listener
|
||||||
|
create_effect(move || {
|
||||||
|
// get the control panel nodes
|
||||||
|
let gen_controls_node = gen_controls.get::<DomNode>();
|
||||||
|
let low_curv_controls_node = low_curv_controls.get::<DomNode>();
|
||||||
|
|
||||||
|
// hide all the control panels
|
||||||
|
gen_controls_node.add_class("hidden");
|
||||||
|
low_curv_controls_node.add_class("hidden");
|
||||||
|
|
||||||
|
// show the selected control panel
|
||||||
|
match tab_selection.get() {
|
||||||
|
Tab::GenTab => gen_controls_node.remove_class("hidden"),
|
||||||
|
Tab::LowCurvTab => low_curv_controls_node.remove_class("hidden")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// list construction elements
|
// list construction elements
|
||||||
const SPHERE_MAX: usize = 200;
|
const SPHERE_MAX: usize = 200;
|
||||||
let mut sphere_vec = Vec::<DVector<f64>>::new();
|
let mut sphere_vec = Vec::<DVector<f64>>::new();
|
||||||
@ -308,12 +365,19 @@ fn main() {
|
|||||||
|
|
||||||
// update the construction
|
// update the construction
|
||||||
sphere_vec.clear();
|
sphere_vec.clear();
|
||||||
push_gen_test_construction(
|
match tab_selection.get() {
|
||||||
|
Tab::GenTab => push_gen_construction(
|
||||||
&mut sphere_vec,
|
&mut sphere_vec,
|
||||||
&construction_to_world,
|
&construction_to_world,
|
||||||
ctrl_x.get(), ctrl_y.get(),
|
ctrl_x.get(), ctrl_y.get(),
|
||||||
radius_x.get(), radius_y.get()
|
radius_x.get(), radius_y.get()
|
||||||
);
|
),
|
||||||
|
Tab::LowCurvTab => push_low_curv_construction(
|
||||||
|
&mut sphere_vec,
|
||||||
|
&construction_to_world,
|
||||||
|
curv_x.get(), curv_y.get()
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
// set the resolution
|
// set the resolution
|
||||||
let width = canvas.width() as f32;
|
let width = canvas.width() as f32;
|
||||||
@ -362,8 +426,29 @@ fn main() {
|
|||||||
|
|
||||||
view! {
|
view! {
|
||||||
div(id="app") {
|
div(id="app") {
|
||||||
|
div(class="tab-pane") {
|
||||||
|
label {
|
||||||
|
"General"
|
||||||
|
input(
|
||||||
|
type="radio",
|
||||||
|
name="tab",
|
||||||
|
prop:checked=tab_selection.get() == Tab::GenTab,
|
||||||
|
on:click=move |_| tab_selection.set(Tab::GenTab)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
"Low curvature"
|
||||||
|
input(
|
||||||
|
type="radio",
|
||||||
|
name="tab",
|
||||||
|
prop:checked=tab_selection.get() == Tab::LowCurvTab,
|
||||||
|
on:change=move |_| tab_selection.set(Tab::LowCurvTab)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
div { "Mean frame interval: " (mean_frame_interval.get()) " ms" }
|
div { "Mean frame interval: " (mean_frame_interval.get()) " ms" }
|
||||||
canvas(ref=display, width="600", height="600")
|
canvas(ref=display, width="600", height="600")
|
||||||
|
div(ref=gen_controls) {
|
||||||
div(class="control") {
|
div(class="control") {
|
||||||
label(for="ctrl-x") { "Sphere 0 depth" }
|
label(for="ctrl-x") { "Sphere 0 depth" }
|
||||||
input(
|
input(
|
||||||
@ -408,6 +493,31 @@ fn main() {
|
|||||||
bind:valueAsNumber=radius_y
|
bind:valueAsNumber=radius_y
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
div(ref=low_curv_controls) {
|
||||||
|
div(class="control") {
|
||||||
|
label(for="curv-x") { "Sphere 0 curvature" }
|
||||||
|
input(
|
||||||
|
type="range",
|
||||||
|
id="curv-x",
|
||||||
|
min=0.0,
|
||||||
|
max=2.0,
|
||||||
|
step=0.001,
|
||||||
|
bind:valueAsNumber=curv_x
|
||||||
|
)
|
||||||
|
}
|
||||||
|
div(class="control") {
|
||||||
|
label(for="curv-y") { "Sphere 1 curvature" }
|
||||||
|
input(
|
||||||
|
type="range",
|
||||||
|
id="curv-y",
|
||||||
|
min=0.0,
|
||||||
|
max=2.0,
|
||||||
|
step=0.001,
|
||||||
|
bind:valueAsNumber=curv_y
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
div(class="control") {
|
div(class="control") {
|
||||||
label(for="opacity") { "Opacity" }
|
label(for="opacity") { "Opacity" }
|
||||||
input(
|
input(
|
||||||
|
Loading…
Reference in New Issue
Block a user