diff --git a/modifiers/trail/trail.wren b/modifiers/trail/trail.wren index 1a1f988..582d75e 100644 --- a/modifiers/trail/trail.wren +++ b/modifiers/trail/trail.wren @@ -200,15 +200,13 @@ class TrailSystem is ModifierSystem { } tick(delta) { - //System.print("positions") record_positions(delta) //System.print("buffers") update_buffers() //System.print("debug") - debug_draw() + //debug_draw() //System.print("end") - } //tick record_positions(delta: Num){ @@ -218,7 +216,7 @@ class TrailSystem is ModifierSystem { var instance_data: TrailData = _instance_data[entity] var pos = Transform.get_pos_world(entity) - var up = Transform.local_dir_to_world(entity, 0, 1, 0) + var up = Transform.local_dir_to_world(entity, 0, data.edge_length * 0.5, 0) var prev_pos = instance_data.previous_pos || pos var prev_up = instance_data.previous_up || up @@ -252,8 +250,6 @@ class TrailSystem is ModifierSystem { dist = dist + diff var step = data.length / data.subdivisions_length while(dist > step){ - //interpolate between points - //todo: extrapolate curve instead of linear dist = dist - step var t = 1 - dist / diff var point = Point.new([ @@ -266,7 +262,6 @@ class TrailSystem is ModifierSystem { Math.lerp(prev_up.z, up.z, t) ]) Math.normalize(point.up) - //System.print(point.up) if(instance_data.points.count >= data.subdivisions_length - 1) instance_data.points.dequeue() instance_data.points.enqueue(point) } @@ -307,55 +302,20 @@ class TrailSystem is ModifierSystem { var step = data.length / data.subdivisions_length var point_index = -1 - System.print("------------") while(true){ point_index = point_index + 1 if(point_index >= instance_data.points.count) break i = i + 1 var p:Point = instance_data.points[point_index] - - var from: Vec - var from_up: Vec - if(point_index == 0){ - from = Transform.get_pos_world(entity) - from_up = Transform.local_dir_to_world(entity, 0, 1, 0) - } else { - var prev: Point = instance_data.points[point_index-1] - from = prev.pos - from_up = prev.up - } - - System.print(from_up) - - var to = p.pos - var to_up = p.up - - var t = instance_data.progress_since_last_point / step - var pos_x = Math.lerp(from.x, to.x, t) - var pos_y = Math.lerp(from.y, to.y, t) - var pos_z = Math.lerp(from.z, to.z, t) - - var up_x = Math.lerp(from_up.x, to_up.x, t) - var up_y = Math.lerp(from_up.y, to_up.y, t) - var up_z = Math.lerp(from_up.z, to_up.z, t) - - pos_x = to.x - pos_y = to.y - pos_z = to.z - - up_x = to_up.x - up_y = to_up.y - up_z = to_up.z - var x = instance_data.points.count + 1 - i for(y in 0...data.subdivisions_width){ - var t = 1 - y / (data.subdivisions_width-1) + var t = y / (data.subdivisions_width-1) var offset_x = Math.lerp(-p.up.x, p.up.x, t) var offset_y = Math.lerp(-p.up.y, p.up.y, t) var offset_z = Math.lerp(-p.up.z, p.up.z, t) - positions[x*4*data.subdivisions_width + y*4 + 0] = pos_x + offset_x * data.edge_length * 0.5 - positions[x*4*data.subdivisions_width + y*4 + 1] = pos_y + offset_y * data.edge_length * 0.5 - positions[x*4*data.subdivisions_width + y*4 + 2] = pos_z + offset_z * data.edge_length * 0.5 + positions[x*4*data.subdivisions_width + y*4 + 0] = p.pos.x + offset_x * data.edge_length * 0.5 + positions[x*4*data.subdivisions_width + y*4 + 1] = p.pos.y + offset_y * data.edge_length * 0.5 + positions[x*4*data.subdivisions_width + y*4 + 2] = p.pos.z + offset_z * data.edge_length * 0.5 } }