Skip to content

Commit 218c343

Browse files
committedNov 11, 2023
fixes #48 in generating trail meshes and some clippy lints
1 parent 2c7a36a commit 218c343

File tree

3 files changed

+56
-51
lines changed

3 files changed

+56
-51
lines changed
 

‎crates/joko_marker_format/src/manager/live_pack.rs

+54-48
Original file line numberDiff line numberDiff line change
@@ -726,56 +726,62 @@ impl ActiveTrail {
726726
// scale it trail scale
727727
let horizontal_offset = horizontal_offset * attrs.get_trail_scale().copied().unwrap_or(1.0);
728728
let height = horizontal_offset * 2.0;
729-
let mut y_offset = 1.0;
729+
730730
let mut vertices = vec![];
731-
for two_positions in positions.windows(2) {
732-
let first = two_positions[0];
733-
let second = two_positions[1];
734-
// right side of the vector from first to second
735-
let right_side = (second - first).normalize().cross(Vec3::Y).normalize();
731+
// trail mesh is split by separating different parts with a [0, 0, 0]
732+
// we will call each separate trail mesh as a "strip" of trail.
733+
// each strip should *almost* act as an independent trail, but they all are drawn at the same time with the same parameters.
734+
for strip in positions.split(|&v| v == Vec3::ZERO) {
735+
let mut y_offset = 1.0;
736+
for two_positions in strip.windows(2) {
737+
let first = two_positions[0];
738+
let second = two_positions[1];
739+
// right side of the vector from first to second
740+
let right_side = (second - first).normalize().cross(Vec3::Y).normalize();
736741

737-
let new_offset = (-1.0 * (first.distance(second) / height)) + y_offset;
738-
let first_left = MarkerVertex {
739-
position: first - (right_side * horizontal_offset),
740-
texture_coordinates: vec2(0.0, y_offset),
741-
alpha,
742-
color,
743-
fade_near_far,
744-
};
745-
let first_right = MarkerVertex {
746-
position: first + (right_side * horizontal_offset),
747-
texture_coordinates: vec2(1.0, y_offset),
748-
alpha,
749-
color,
750-
fade_near_far,
751-
};
752-
let second_left = MarkerVertex {
753-
position: second - (right_side * horizontal_offset),
754-
texture_coordinates: vec2(0.0, new_offset),
755-
alpha,
756-
color,
757-
fade_near_far,
758-
};
759-
let second_right = MarkerVertex {
760-
position: second + (right_side * horizontal_offset),
761-
texture_coordinates: vec2(1.0, new_offset),
762-
alpha,
763-
color,
764-
fade_near_far,
765-
};
766-
y_offset = if new_offset.is_sign_positive() {
767-
new_offset
768-
} else {
769-
1.0 - new_offset.fract().abs()
770-
};
771-
vertices.extend([
772-
second_left,
773-
first_left,
774-
first_right,
775-
first_right,
776-
second_right,
777-
second_left,
778-
]);
742+
let new_offset = (-1.0 * (first.distance(second) / height)) + y_offset;
743+
let first_left = MarkerVertex {
744+
position: first - (right_side * horizontal_offset),
745+
texture_coordinates: vec2(0.0, y_offset),
746+
alpha,
747+
color,
748+
fade_near_far,
749+
};
750+
let first_right = MarkerVertex {
751+
position: first + (right_side * horizontal_offset),
752+
texture_coordinates: vec2(1.0, y_offset),
753+
alpha,
754+
color,
755+
fade_near_far,
756+
};
757+
let second_left = MarkerVertex {
758+
position: second - (right_side * horizontal_offset),
759+
texture_coordinates: vec2(0.0, new_offset),
760+
alpha,
761+
color,
762+
fade_near_far,
763+
};
764+
let second_right = MarkerVertex {
765+
position: second + (right_side * horizontal_offset),
766+
texture_coordinates: vec2(1.0, new_offset),
767+
alpha,
768+
color,
769+
fade_near_far,
770+
};
771+
y_offset = if new_offset.is_sign_positive() {
772+
new_offset
773+
} else {
774+
1.0 - new_offset.fract().abs()
775+
};
776+
vertices.extend([
777+
second_left,
778+
first_left,
779+
first_right,
780+
first_right,
781+
second_right,
782+
second_left,
783+
]);
784+
}
779785
}
780786

781787
Some(ActiveTrail {

‎crates/joko_render/src/billboard.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub fn new_program(
245245
gl.delete_shader(frag_shader);
246246
gl_error!(gl);
247247
let active_attribute_count = gl.get_active_attributes(program);
248-
let mut shader_info = format!("Shader Info:\nvertex attributes: 5");
248+
let mut shader_info = format!("Shader Info:\nvertex attributes: {active_attribute_count}");
249249
for index in 0..active_attribute_count {
250250
if let Some(attr) = gl.get_active_attribute(program, index) {
251251
let location = gl.get_attrib_location(program, &attr.name);

‎crates/joko_render/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ use three_d::prelude::*;
2222
#[macro_export]
2323
macro_rules! gl_error {
2424
($gl:expr) => {{
25-
use crate::three_d::context::NO_ERROR;
2625
let e = $gl.get_error();
27-
if e != NO_ERROR {
26+
if e != egui_render_three_d::three_d::context::NO_ERROR {
2827
tracing::error!("glerror {} at {} {} {}", e, file!(), line!(), column!());
2928
}
3029
}};

0 commit comments

Comments
 (0)
Please sign in to comment.