Combine color and opacity on push to scene
All checks were successful
/ test (pull_request) Successful in 2m27s
All checks were successful
/ test (pull_request) Successful in 2m27s
This commit is contained in:
parent
592f327e62
commit
2aa1adcd07
1 changed files with 15 additions and 18 deletions
|
@ -20,15 +20,23 @@ use crate::{
|
|||
assembly::{Element, ElementColor, ElementMotion, Point, Sphere}
|
||||
};
|
||||
|
||||
// --- scene data ---
|
||||
// --- color ---
|
||||
|
||||
const COLOR_SIZE: usize = 3;
|
||||
type ColorWithOpacity = [f32; COLOR_SIZE + 1];
|
||||
|
||||
fn combine_channels(color: ElementColor, opacity: f32) -> ColorWithOpacity {
|
||||
let mut color_with_opacity = [0.0; COLOR_SIZE + 1];
|
||||
color_with_opacity[..COLOR_SIZE].copy_from_slice(&color);
|
||||
color_with_opacity[COLOR_SIZE] = opacity;
|
||||
color_with_opacity
|
||||
}
|
||||
|
||||
// --- scene data ---
|
||||
|
||||
struct SceneSpheres {
|
||||
representations: Vec<DVector<f64>>,
|
||||
colors: Vec<ElementColor>,
|
||||
opacities: Vec<f32>,
|
||||
colors_with_opacity: Vec<ColorWithOpacity>,
|
||||
highlights: Vec<f32>
|
||||
}
|
||||
|
||||
|
@ -36,8 +44,7 @@ impl SceneSpheres {
|
|||
fn new() -> SceneSpheres{
|
||||
SceneSpheres {
|
||||
representations: Vec::new(),
|
||||
colors: Vec::new(),
|
||||
opacities: Vec::new(),
|
||||
colors_with_opacity: Vec::new(),
|
||||
highlights: Vec::new()
|
||||
}
|
||||
}
|
||||
|
@ -48,8 +55,7 @@ impl SceneSpheres {
|
|||
|
||||
fn push(&mut self, representation: DVector<f64>, color: ElementColor, opacity: f32, highlight: f32) {
|
||||
self.representations.push(representation);
|
||||
self.colors.push(color);
|
||||
self.opacities.push(opacity);
|
||||
self.colors_with_opacity.push(combine_channels(color, opacity));
|
||||
self.highlights.push(highlight);
|
||||
}
|
||||
}
|
||||
|
@ -72,12 +78,8 @@ impl ScenePoints {
|
|||
}
|
||||
|
||||
fn push(&mut self, representation: DVector<f64>, color: ElementColor, opacity: f32, highlight: f32, selected: bool) {
|
||||
let mut color_with_opacity = [0.0; COLOR_SIZE + 1];
|
||||
color_with_opacity[..COLOR_SIZE].copy_from_slice(&color);
|
||||
color_with_opacity[COLOR_SIZE] = opacity;
|
||||
|
||||
self.representations.push(representation);
|
||||
self.colors_with_opacity.push(color_with_opacity);
|
||||
self.colors_with_opacity.push(combine_channels(color, opacity));
|
||||
self.highlights.push(highlight);
|
||||
self.selections.push(if selected { 1.0 } else { 0.0 });
|
||||
}
|
||||
|
@ -664,11 +666,6 @@ pub fn Display() -> View {
|
|||
ctx.uniform1i(sphere_cnt_loc.as_ref(), sphere_cnt);
|
||||
for n in 0..sphere_reps_world.len() {
|
||||
let v = &sphere_reps_world[n];
|
||||
|
||||
let sphere_color = &mut [0.0; 4];
|
||||
sphere_color[..3].copy_from_slice(&scene.spheres.colors[n]);
|
||||
sphere_color[3] = scene.spheres.opacities[n];
|
||||
|
||||
ctx.uniform3fv_with_f32_array(
|
||||
sphere_sp_locs[n].as_ref(),
|
||||
v.rows(0, 3).as_slice()
|
||||
|
@ -679,7 +676,7 @@ pub fn Display() -> View {
|
|||
);
|
||||
ctx.uniform4fv_with_f32_array(
|
||||
sphere_color_locs[n].as_ref(),
|
||||
sphere_color
|
||||
&scene.spheres.colors_with_opacity[n]
|
||||
);
|
||||
ctx.uniform1f(
|
||||
sphere_highlight_locs[n].as_ref(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue