Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nto main
  • Loading branch information
sairam4123 committed Dec 28, 2020
2 parents 50259f2 + 766b78e commit c00e266
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions addons/sairam.quadtree/QuadTree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -226,35 +226,36 @@ func _get_child(body_bounds: AABB) -> QuadTree:
return _children[3] # bottom right


func _create_rect_lines(points) -> void:
func _create_rect_lines(drawer, height) -> void:
"""
:PrivateMeth
:VersionChanged 1.0.1
Creates the lines that shows the subdivided quadtree.
"""

# recursively call _create_rect_lines to create dividing lines.
for child in _children:
if child:
child._create_rect_lines(points)
child._create_rect_lines(drawer, height)

# create the points
var p1 = Vector3(_bounds.position.x, _bounds.position.z, 1)
var p2 = Vector3(p1.x + _bounds.size.x, p1.y, 1)
var p3 = Vector3(p1.x + _bounds.size.x, p1.y + _bounds.size.z, 1)
var p4 = Vector3(p1.x, p1.y + _bounds.size.z, 1)
# append them into points array
points.append(p1)
points.append(p2)
var p1 = Vector3(_bounds.position.x, height, _bounds.position.z)
var p2 = Vector3(p1.x + _bounds.size.x, height, p1.z)
var p3 = Vector3(p1.x + _bounds.size.x, height, p1.z + _bounds.size.z)
var p4 = Vector3(p1.x, height, p1.z + _bounds.size.z)

points.append(p2)
points.append(p3)
drawer.add_vertex(p1)
drawer.add_vertex(p2)

points.append(p3)
points.append(p4)
drawer.add_vertex(p2)
drawer.add_vertex(p3)

points.append(p4)
points.append(p1)
drawer.add_vertex(p3)
drawer.add_vertex(p4)

drawer.add_vertex(p4)
drawer.add_vertex(p1)

func dump(file_name = null, indent = ""):
if file_name:
Expand Down Expand Up @@ -283,8 +284,9 @@ func _dump(file_obj: File = null, indent = ""):
if child != null:
child._dump(file_obj, indent + " ")

func draw(height: float = 1, clear_drawing: bool = true, drawer: ImmediateGeometry = null, material: Material = null) -> void:
func draw(height: float = 1, clear_drawing: bool = true, draw_outlines: bool = true, draw_tree_bounds: bool = true, drawer: ImmediateGeometry = null, material: Material = null) -> void:
"""
:VersionChanged 1.0.1
Initializes drawing stuff for you, you can use `_draw` method if you want to have special initialization.
"""
drawer = drawer if drawer else self._immediate_geo_node
Expand All @@ -293,7 +295,10 @@ func draw(height: float = 1, clear_drawing: bool = true, drawer: ImmediateGeomet
if material:
drawer.set_material_override(material)
drawer.begin(Mesh.PRIMITIVE_LINES)
_draw(drawer, height)
if draw_tree_bounds:
_create_rect_lines(drawer, height)
if draw_outlines:
_draw(drawer, height)
drawer.end()

func _draw(drawer: ImmediateGeometry, height: float) -> void:
Expand All @@ -307,13 +312,6 @@ func _draw(drawer: ImmediateGeometry, height: float) -> void:
for child in _children:
if not _is_leaf:
child._draw(drawer, height)
var points = []
# initialize the points
_create_rect_lines(points)

# draw them into the node.
for point in points:
drawer.add_vertex(Vector3(point.x, height, point.y)) # change it to x and y axis if needed.

# draw the bodies
for body in _objects:
Expand Down

0 comments on commit c00e266

Please sign in to comment.