|
|
|
@ -38,31 +38,19 @@ function geometry_prepare_stroke(state) {
@@ -38,31 +38,19 @@ function geometry_prepare_stroke(state) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function geometry_write_instances(state, context) { |
|
|
|
|
if (state.segments_from.cap < context.clipped_indices.count + 1) { |
|
|
|
|
state.segments_from.cap = round_to_pow2(context.clipped_indices.count + 1, 4096); |
|
|
|
|
state.segments_from.data = new Uint32Array(state.segments_from.cap); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (state.segments.cap < state.coordinates.size / 2) { |
|
|
|
|
state.segments.cap = round_to_pow2(state.coordinates.size, 4096); |
|
|
|
|
state.segments.data = new Uint32Array(state.segments.cap); |
|
|
|
|
} |
|
|
|
|
tv_ensure(state.segments_from, round_to_pow2(context.clipped_indices.size + 1, 4096)); |
|
|
|
|
tv_ensure(state.segments, round_to_pow2(state.coordinates.size / 2, 4096)); |
|
|
|
|
|
|
|
|
|
state.segments_from.count = 0; |
|
|
|
|
state.segments.count = 0; |
|
|
|
|
tv_clear(state.segments_from); |
|
|
|
|
tv_clear(state.segments); |
|
|
|
|
|
|
|
|
|
state.stats.rdp_max_count = 0; |
|
|
|
|
state.stats.rdp_segments = 0; |
|
|
|
|
|
|
|
|
|
const segment_count = do_lod(state, context); |
|
|
|
|
|
|
|
|
|
state.segments.count = segment_count; |
|
|
|
|
state.segments_from.data[context.clipped_indices.count] = state.segments.count; |
|
|
|
|
state.segments_from.count = context.clipped_indices.count + 1; |
|
|
|
|
|
|
|
|
|
context.instance_data_points = tv_ensure(context.instance_data_points, state.segments.count * 2); |
|
|
|
|
context.instance_data_ids = tv_ensure(context.instance_data_ids, state.segments.count); |
|
|
|
|
|
|
|
|
|
tv_ensure(context.instance_data_points, state.segments.size * 2); |
|
|
|
|
tv_ensure(context.instance_data_ids, state.segments.size); |
|
|
|
|
|
|
|
|
|
tv_clear(context.instance_data_points); |
|
|
|
|
tv_clear(context.instance_data_ids); |
|
|
|
@ -72,10 +60,11 @@ function geometry_write_instances(state, context) {
@@ -72,10 +60,11 @@ function geometry_write_instances(state, context) {
|
|
|
|
|
const segments = state.segments.data; |
|
|
|
|
const coords = state.coordinates.data; |
|
|
|
|
const events = state.events; |
|
|
|
|
|
|
|
|
|
for (let i = 0; i < state.segments_from.count - 1; ++i) { |
|
|
|
|
|
|
|
|
|
// TODO: move this loop to WASM
|
|
|
|
|
for (let i = 0; i < state.segments_from.size - 1; ++i) { |
|
|
|
|
const stroke_index = clipped[i]; |
|
|
|
|
const coords_from = events[stroke_index].coords_from; |
|
|
|
|
const coords_from = state.events[stroke_index].coords_from; |
|
|
|
|
const from = segments_from[i]; |
|
|
|
|
const to = segments_from[i + 1]; |
|
|
|
|
|
|
|
|
@ -100,7 +89,7 @@ function geometry_write_instances(state, context) {
@@ -100,7 +89,7 @@ function geometry_write_instances(state, context) {
|
|
|
|
|
|
|
|
|
|
if (config.debug_print) console.debug('instances:', state.segments.count, 'rdp max:', state.stats.rdp_max_count, 'rdp segments:', state.stats.rdp_segments); |
|
|
|
|
|
|
|
|
|
return state.segments.count; |
|
|
|
|
return state.segments.size; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function geometry_add_stroke(state, context, stroke, stroke_index, skip_bvh = false) { |
|
|
|
@ -111,7 +100,7 @@ function geometry_add_stroke(state, context, stroke, stroke_index, skip_bvh = fa
@@ -111,7 +100,7 @@ function geometry_add_stroke(state, context, stroke, stroke_index, skip_bvh = fa
|
|
|
|
|
|
|
|
|
|
context.stroke_data = ser_ensure_by(context.stroke_data, config.bytes_per_stroke); |
|
|
|
|
|
|
|
|
|
state.line_threshold = tv_ensure(state.line_threshold, round_to_pow2(state.stroke_count, 4096)); |
|
|
|
|
tv_ensure(state.line_threshold, round_to_pow2(state.stroke_count, 4096)); |
|
|
|
|
tv_add(state.line_threshold, -1); |
|
|
|
|
|
|
|
|
|
const color_u32 = stroke.color; |
|
|
|
@ -159,8 +148,8 @@ function recompute_dynamic_data(state, context) {
@@ -159,8 +148,8 @@ function recompute_dynamic_data(state, context) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
context.dynamic_instance_data = tv_ensure(context.dynamic_instance_points, round_to_pow2(total_points * 2, 4096)); |
|
|
|
|
context.dynamic_instance_ids = tv_ensure(context.dynamic_instance_ids, round_to_pow2(total_points, 4096)); |
|
|
|
|
tv_ensure(context.dynamic_instance_points, round_to_pow2(total_points * 2, 4096)); |
|
|
|
|
tv_ensure(context.dynamic_instance_ids, round_to_pow2(total_points, 4096)); |
|
|
|
|
|
|
|
|
|
tv_clear(context.dynamic_instance_points); |
|
|
|
|
tv_clear(context.dynamic_instance_ids); |
|
|
|
|