Stop computing B-vertex normals, which are no longer used.
6x improvement in partitioning time (because atan2 is dog slow).
This commit is contained in:
parent
7a2ad35d7e
commit
d8c590867d
|
@ -29,7 +29,6 @@ pub struct MeshLibrary {
|
||||||
pub b_quad_vertex_interior_indices: Vec<u32>,
|
pub b_quad_vertex_interior_indices: Vec<u32>,
|
||||||
pub b_vertex_positions: Vec<Point2D<f32>>,
|
pub b_vertex_positions: Vec<Point2D<f32>>,
|
||||||
pub b_vertex_loop_blinn_data: Vec<BVertexLoopBlinnData>,
|
pub b_vertex_loop_blinn_data: Vec<BVertexLoopBlinnData>,
|
||||||
pub b_vertex_normals: Vec<f32>,
|
|
||||||
pub segments: MeshLibrarySegments,
|
pub segments: MeshLibrarySegments,
|
||||||
pub segment_normals: MeshLibrarySegmentNormals,
|
pub segment_normals: MeshLibrarySegmentNormals,
|
||||||
}
|
}
|
||||||
|
@ -44,7 +43,6 @@ impl MeshLibrary {
|
||||||
b_quad_vertex_interior_indices: vec![],
|
b_quad_vertex_interior_indices: vec![],
|
||||||
b_vertex_positions: vec![],
|
b_vertex_positions: vec![],
|
||||||
b_vertex_loop_blinn_data: vec![],
|
b_vertex_loop_blinn_data: vec![],
|
||||||
b_vertex_normals: vec![],
|
|
||||||
segments: MeshLibrarySegments::new(),
|
segments: MeshLibrarySegments::new(),
|
||||||
segment_normals: MeshLibrarySegmentNormals::new(),
|
segment_normals: MeshLibrarySegmentNormals::new(),
|
||||||
}
|
}
|
||||||
|
@ -57,7 +55,6 @@ impl MeshLibrary {
|
||||||
self.b_quad_vertex_interior_indices.clear();
|
self.b_quad_vertex_interior_indices.clear();
|
||||||
self.b_vertex_positions.clear();
|
self.b_vertex_positions.clear();
|
||||||
self.b_vertex_loop_blinn_data.clear();
|
self.b_vertex_loop_blinn_data.clear();
|
||||||
self.b_vertex_normals.clear();
|
|
||||||
self.segments.clear();
|
self.segments.clear();
|
||||||
self.segment_normals.clear();
|
self.segment_normals.clear();
|
||||||
}
|
}
|
||||||
|
@ -72,11 +69,9 @@ impl MeshLibrary {
|
||||||
|
|
||||||
pub(crate) fn add_b_vertex(&mut self,
|
pub(crate) fn add_b_vertex(&mut self,
|
||||||
position: &Point2D<f32>,
|
position: &Point2D<f32>,
|
||||||
loop_blinn_data: &BVertexLoopBlinnData,
|
loop_blinn_data: &BVertexLoopBlinnData) {
|
||||||
normal: f32) {
|
|
||||||
self.b_vertex_positions.push(*position);
|
self.b_vertex_positions.push(*position);
|
||||||
self.b_vertex_loop_blinn_data.push(*loop_blinn_data);
|
self.b_vertex_loop_blinn_data.push(*loop_blinn_data);
|
||||||
self.b_vertex_normals.push(normal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_b_quad(&mut self, b_quad: &BQuad) {
|
pub(crate) fn add_b_quad(&mut self, b_quad: &BQuad) {
|
||||||
|
|
|
@ -23,7 +23,6 @@ use std::ops::{Add, AddAssign};
|
||||||
use std::u32;
|
use std::u32;
|
||||||
|
|
||||||
use mesh_library::MeshLibrary;
|
use mesh_library::MeshLibrary;
|
||||||
use normal;
|
|
||||||
use {BQuad, BVertexLoopBlinnData, BVertexKind, Endpoint, FillRule, Subpath};
|
use {BQuad, BVertexLoopBlinnData, BVertexKind, Endpoint, FillRule, Subpath};
|
||||||
|
|
||||||
const MAX_B_QUAD_SUBDIVISIONS: u8 = 8;
|
const MAX_B_QUAD_SUBDIVISIONS: u8 = 8;
|
||||||
|
@ -115,12 +114,8 @@ impl<'a> Partitioner<'a> {
|
||||||
|
|
||||||
while self.process_next_point() {}
|
while self.process_next_point() {}
|
||||||
|
|
||||||
self.write_normals_to_library();
|
|
||||||
|
|
||||||
debug_assert_eq!(self.library.b_vertex_loop_blinn_data.len(),
|
debug_assert_eq!(self.library.b_vertex_loop_blinn_data.len(),
|
||||||
self.library.b_vertex_positions.len());
|
self.library.b_vertex_positions.len());
|
||||||
debug_assert_eq!(self.library.b_vertex_loop_blinn_data.len(),
|
|
||||||
self.library.b_vertex_normals.len());
|
|
||||||
|
|
||||||
let end_lengths = self.library.snapshot_lengths();
|
let end_lengths = self.library.snapshot_lengths();
|
||||||
|
|
||||||
|
@ -218,8 +213,7 @@ impl<'a> Partitioner<'a> {
|
||||||
|
|
||||||
// FIXME(pcwalton): Normal
|
// FIXME(pcwalton): Normal
|
||||||
self.library.add_b_vertex(&endpoint_position,
|
self.library.add_b_vertex(&endpoint_position,
|
||||||
&BVertexLoopBlinnData::new(active_edge.endpoint_kind()),
|
&BVertexLoopBlinnData::new(active_edge.endpoint_kind()));
|
||||||
0.0);
|
|
||||||
|
|
||||||
active_edge.toggle_parity();
|
active_edge.toggle_parity();
|
||||||
}
|
}
|
||||||
|
@ -261,8 +255,7 @@ impl<'a> Partitioner<'a> {
|
||||||
|
|
||||||
// FIXME(pcwalton): Normal
|
// FIXME(pcwalton): Normal
|
||||||
self.library.add_b_vertex(control_point_position,
|
self.library.add_b_vertex(control_point_position,
|
||||||
&control_point_b_vertex_loop_blinn_data,
|
&control_point_b_vertex_loop_blinn_data);
|
||||||
0.0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,26 +319,6 @@ impl<'a> Partitioner<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_normals_to_library(&mut self) {
|
|
||||||
// Write B-vertex normals.
|
|
||||||
for (b_vertex_index, vertex_normal) in self.vertex_normals.iter().enumerate() {
|
|
||||||
debug_assert!(b_vertex_index <= self.library.b_vertex_normals.len());
|
|
||||||
|
|
||||||
let angle = vertex_normal.angle();
|
|
||||||
if b_vertex_index == self.library.b_vertex_normals.len() {
|
|
||||||
self.library.b_vertex_normals.push(angle)
|
|
||||||
} else {
|
|
||||||
self.library.b_vertex_normals[b_vertex_index as usize] = angle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let remaining_b_vertex_count = self.library.b_vertex_positions.len() -
|
|
||||||
self.library.b_vertex_normals.len();
|
|
||||||
if remaining_b_vertex_count > 0 {
|
|
||||||
self.library.b_vertex_normals.extend(iter::repeat(0.0).take(remaining_b_vertex_count))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_new_edges_for_min_point(&mut self, endpoint_index: u32, next_active_edge_index: u32) {
|
fn add_new_edges_for_min_point(&mut self, endpoint_index: u32, next_active_edge_index: u32) {
|
||||||
// FIXME(pcwalton): This is twice as slow as it needs to be.
|
// FIXME(pcwalton): This is twice as slow as it needs to be.
|
||||||
self.active_edges.insert(next_active_edge_index as usize, ActiveEdge::default());
|
self.active_edges.insert(next_active_edge_index as usize, ActiveEdge::default());
|
||||||
|
@ -364,8 +337,7 @@ impl<'a> Partitioner<'a> {
|
||||||
// FIXME(pcwalton): Normal
|
// FIXME(pcwalton): Normal
|
||||||
let position = self.endpoints[endpoint_index as usize].position;
|
let position = self.endpoints[endpoint_index as usize].position;
|
||||||
self.library.add_b_vertex(&position,
|
self.library.add_b_vertex(&position,
|
||||||
&BVertexLoopBlinnData::new(BVertexKind::Endpoint0),
|
&BVertexLoopBlinnData::new(BVertexKind::Endpoint0));
|
||||||
0.0);
|
|
||||||
|
|
||||||
new_active_edges[0].toggle_parity();
|
new_active_edges[0].toggle_parity();
|
||||||
new_active_edges[1].toggle_parity();
|
new_active_edges[1].toggle_parity();
|
||||||
|
@ -416,8 +388,7 @@ impl<'a> Partitioner<'a> {
|
||||||
|
|
||||||
// FIXME(pcwalton): Normal
|
// FIXME(pcwalton): Normal
|
||||||
self.library.add_b_vertex(&control_point_position,
|
self.library.add_b_vertex(&control_point_position,
|
||||||
&control_point_b_vertex_loop_blinn_data,
|
&control_point_b_vertex_loop_blinn_data)
|
||||||
0.0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,8 +410,7 @@ impl<'a> Partitioner<'a> {
|
||||||
|
|
||||||
// FIXME(pcwalton): Normal
|
// FIXME(pcwalton): Normal
|
||||||
self.library.add_b_vertex(&control_point_position,
|
self.library.add_b_vertex(&control_point_position,
|
||||||
&control_point_b_vertex_loop_blinn_data,
|
&control_point_b_vertex_loop_blinn_data)
|
||||||
0.0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -936,8 +906,7 @@ impl<'a> Partitioner<'a> {
|
||||||
// FIXME(pcwalton): Normal
|
// FIXME(pcwalton): Normal
|
||||||
active_edge.left_vertex_index = self.library.b_vertex_loop_blinn_data.len() as u32;
|
active_edge.left_vertex_index = self.library.b_vertex_loop_blinn_data.len() as u32;
|
||||||
self.library.add_b_vertex(&middle_point.to_point(),
|
self.library.add_b_vertex(&middle_point.to_point(),
|
||||||
&BVertexLoopBlinnData::new(active_edge.endpoint_kind()),
|
&BVertexLoopBlinnData::new(active_edge.endpoint_kind()));
|
||||||
0.0);
|
|
||||||
|
|
||||||
left_curve_control_point_vertex_index = u32::MAX;
|
left_curve_control_point_vertex_index = u32::MAX;
|
||||||
}
|
}
|
||||||
|
@ -965,18 +934,15 @@ impl<'a> Partitioner<'a> {
|
||||||
&BVertexLoopBlinnData::control_point(&left_curve.endpoints[0],
|
&BVertexLoopBlinnData::control_point(&left_curve.endpoints[0],
|
||||||
&left_curve.control_point,
|
&left_curve.control_point,
|
||||||
&left_curve.endpoints[1],
|
&left_curve.endpoints[1],
|
||||||
bottom),
|
bottom));
|
||||||
0.0);
|
|
||||||
self.library.add_b_vertex(&left_curve.endpoints[1],
|
self.library.add_b_vertex(&left_curve.endpoints[1],
|
||||||
&BVertexLoopBlinnData::new(active_edge.endpoint_kind()),
|
&BVertexLoopBlinnData::new(active_edge.endpoint_kind()));
|
||||||
0.0);
|
|
||||||
self.library
|
self.library
|
||||||
.add_b_vertex(&right_curve.control_point,
|
.add_b_vertex(&right_curve.control_point,
|
||||||
&BVertexLoopBlinnData::control_point(&right_curve.endpoints[0],
|
&BVertexLoopBlinnData::control_point(&right_curve.endpoints[0],
|
||||||
&right_curve.control_point,
|
&right_curve.control_point,
|
||||||
&right_curve.endpoints[1],
|
&right_curve.endpoints[1],
|
||||||
bottom),
|
bottom));
|
||||||
0.0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1260,10 +1226,6 @@ impl VertexNormal {
|
||||||
sum: Vector2D::zero(),
|
sum: Vector2D::zero(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn angle(&self) -> f32 {
|
|
||||||
normal::calculate_normal_angle(&self.sum)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add<VertexNormal> for VertexNormal {
|
impl Add<VertexNormal> for VertexNormal {
|
||||||
|
|
Loading…
Reference in New Issue