forked from StudioInfinity/dyna3
Pause realization while loading assemblies
This avoids redundant realizations as we set an assembly's regulators during loading. Adding some regulators to the low-curvature assembly confirms that the feature is working as intended.
This commit is contained in:
parent
5864017e6f
commit
40d665d8ac
2 changed files with 90 additions and 9 deletions
|
@ -6,7 +6,8 @@ use crate::{
|
|||
AppState,
|
||||
engine,
|
||||
engine::DescentHistory,
|
||||
assembly::{Assembly, InversiveDistanceRegulator, Point, Sphere}
|
||||
assembly::{Assembly, InversiveDistanceRegulator, Point, Sphere},
|
||||
specified::SpecifiedValue
|
||||
};
|
||||
|
||||
/* DEBUG */
|
||||
|
@ -67,6 +68,7 @@ fn load_gen_assemb(assembly: &Assembly) {
|
|||
// load an example assembly for testing. this code will be removed once we've
|
||||
// built a more formal test assembly system
|
||||
fn load_low_curv_assemb(assembly: &Assembly) {
|
||||
// create the spheres
|
||||
let a = 0.75_f64.sqrt();
|
||||
let _ = assembly.try_insert_element(
|
||||
Sphere::new(
|
||||
|
@ -132,6 +134,56 @@ fn load_low_curv_assemb(assembly: &Assembly) {
|
|||
engine::sphere(2.0/3.0, 4.0/3.0 * a, 0.0, 1.0/3.0)
|
||||
)
|
||||
);
|
||||
|
||||
// impose the desired tangencies and make the sides planar
|
||||
let index_range = 1..=3;
|
||||
let [central, assemb_plane] = ["central", "assemb_plane"].map(
|
||||
|id| assembly.elements_by_id.with_untracked(
|
||||
|elts_by_id| elts_by_id[id].clone()
|
||||
)
|
||||
);
|
||||
let sides = index_range.clone().map(
|
||||
|k| assembly.elements_by_id.with_untracked(
|
||||
|elts_by_id| elts_by_id[&format!("side{k}")].clone()
|
||||
)
|
||||
);
|
||||
let corners = index_range.map(
|
||||
|k| assembly.elements_by_id.with_untracked(
|
||||
|elts_by_id| elts_by_id[&format!("corner{k}")].clone()
|
||||
)
|
||||
);
|
||||
for plane in [assemb_plane.clone()].into_iter().chain(sides.clone()) {
|
||||
// fix the curvature of each plane
|
||||
let curvature = plane.regulators().with_untracked(
|
||||
|regs| regs.first().unwrap().clone()
|
||||
);
|
||||
curvature.set_point().set(SpecifiedValue::try_from("0".to_string()).unwrap());
|
||||
}
|
||||
let all_perpendicular = [central.clone()].into_iter()
|
||||
.chain(sides.clone())
|
||||
.chain(corners.clone());
|
||||
for sphere in all_perpendicular {
|
||||
// make each side and packed sphere perpendicular to the assembly plane
|
||||
let right_angle = InversiveDistanceRegulator::new([sphere, assemb_plane.clone()]);
|
||||
right_angle.set_point.set(SpecifiedValue::try_from("0".to_string()).unwrap());
|
||||
assembly.insert_regulator(Rc::new(right_angle));
|
||||
}
|
||||
for sphere in sides.clone().chain(corners.clone()) {
|
||||
// make each side and corner sphere tangent to the central sphere
|
||||
let tangency = InversiveDistanceRegulator::new([sphere.clone(), central.clone()]);
|
||||
tangency.set_point.set(SpecifiedValue::try_from("-1".to_string()).unwrap());
|
||||
assembly.insert_regulator(Rc::new(tangency));
|
||||
}
|
||||
for (side_index, side) in sides.enumerate() {
|
||||
// make each side tangent to the two adjacent corner spheres
|
||||
for (corner_index, corner) in corners.clone().enumerate() {
|
||||
if side_index != corner_index {
|
||||
let tangency = InversiveDistanceRegulator::new([side.clone(), corner]);
|
||||
tangency.set_point.set(SpecifiedValue::try_from("-1".to_string()).unwrap());
|
||||
assembly.insert_regulator(Rc::new(tangency));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load_pointed_assemb(assembly: &Assembly) {
|
||||
|
@ -192,6 +244,9 @@ pub fn AddRemove() -> View {
|
|||
let state = use_context::<AppState>();
|
||||
let assembly = &state.assembly;
|
||||
|
||||
// pause realization
|
||||
assembly.keep_realized.set(false);
|
||||
|
||||
// clear state
|
||||
assembly.regulators.update(|regs| regs.clear());
|
||||
assembly.elements.update(|elts| elts.clear());
|
||||
|
@ -206,6 +261,9 @@ pub fn AddRemove() -> View {
|
|||
"pointed" => load_pointed_assemb(assembly),
|
||||
_ => ()
|
||||
};
|
||||
|
||||
// resume realization
|
||||
assembly.keep_realized.set(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue