Skip to content

Commit

Permalink
Merge pull request #316 from klingbolt/update_waypoints
Browse files Browse the repository at this point in the history
Waypoint data the source of truth for position of icons and trails
  • Loading branch information
AsherGlick authored Jun 17, 2024
2 parents 5c702d0 + 7ea2173 commit 00752d0
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 137 deletions.
4 changes: 4 additions & 0 deletions Category3D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ func clear_all():
self.subcategories = []
for child in self.get_children():
child.queue_free()

func remove_icon(icon):
self.icons.remove(icon)
icon.queue_free()
3 changes: 0 additions & 3 deletions Icon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,3 @@ func set_icon_image(texture_path: String):

func set_position(position: Vector3):
self.translation = position

func remove_icon():
self.queue_free()
48 changes: 4 additions & 44 deletions Route.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ var color = Color(0.9, 0.1, 0.1)
var waypoint: Waypoint.Trail
var category: TreeItem

var point_list := PoolVector3Array()

func create_mesh(point_list: PoolVector3Array):
self.point_list = point_list
refresh_mesh()

func refresh_mesh():
var tmpMesh = Mesh.new()
var i = 0
var last_uv: float = 0.0
for point_index in range(len(point_list)-1):
var point:Vector3 = point_list[point_index]
var next_point:Vector3 = point_list[point_index+1]
var trail_data = self.waypoint.get_trail_data()
for point_index in range(trail_data.get_points_x().size()-1):
var point:Vector3 = Vector3(trail_data.get_points_x()[point_index], trail_data.get_points_y()[point_index], -trail_data.get_points_z()[point_index])
var next_point:Vector3 = Vector3(trail_data.get_points_x()[point_index+1], trail_data.get_points_y()[point_index+1], -trail_data.get_points_z()[point_index+1])
# If the line starts or ends at map coordinates (0,0,0), don't draw the line.
if point == Vector3(0,0,0) or next_point == Vector3(0,0,0):
continue
Expand Down Expand Up @@ -65,41 +60,6 @@ func refresh_mesh():
$MeshInstance.mesh = tmpMesh


func update_point_vertical(index, y_value):
pass

func reverse():
self.point_list.invert()
refresh_mesh()

func get_point_count():
return len(self.point_list)

func get_point_position(index: int):
return self.point_list[index]

func set_point_position(position: Vector3, index: int):
self.point_list[index] = position
refresh_mesh()

func add_point(position: Vector3, index: int = -1):
if index == -1:
self.point_list.append(position)
else:
self.point_list.insert(index, position)
refresh_mesh()

func remove_point(index: int):
self.point_list.remove(index)
refresh_mesh()

func new_point_after(midpoint: Vector3, index: int):
var start: Vector3 = self.get_point_position(index)
if self.get_point_count() > index+1:
var end: Vector3 = self.get_point_position(index+1)
midpoint = ((start-end)/2) + end
add_point(midpoint, index+1)

func set_texture(texture):
$MeshInstance.material_override.set_shader_param("texture_albedo", texture)

21 changes: 8 additions & 13 deletions Route2D.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
extends Line2D

func new_point_after(midpoint: Vector3, index: int):
var midpoint2d: Vector2 = Vector2(midpoint.x, midpoint.z)
var start: Vector2 = self.get_point_position(index)

if self.get_point_count() > index+1:
var end: Vector2 = self.get_point_position(index+1)
midpoint2d = ((start-end)/2) + end
add_point(midpoint2d, index+1)
const Waypoint = preload("res://waypoint.gd")
var waypoint: Waypoint.Trail

func remove_point(index: int):
self.remove_point(index)

func reverse():
self.points.invert()
func refresh_points():
var path_points := PoolVector2Array()
var trail_data = self.waypoint.get_trail_data()
for index in range(0, trail_data.get_points_z().size()):
path_points.append(Vector2(trail_data.get_points_x()[index], -trail_data.get_points_z()[index]))
self.points = path_points
Loading

0 comments on commit 00752d0

Please sign in to comment.