Skip to content

Commit

Permalink
add 3d model mode
Browse files Browse the repository at this point in the history
Signed-off-by: Yukihito Saito <[email protected]>
  • Loading branch information
yukkysaito committed Apr 17, 2024
1 parent fae3fa4 commit 51e51c3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
59 changes: 29 additions & 30 deletions godot-project/DynamicObjectMesh.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends MeshInstance3D

var dynamic_objects = DynamicObjects.new()
var only_known_object = true
var object_3d_model_mode = false

var pool_size = 100
var model_types = {
Expand Down Expand Up @@ -29,11 +30,33 @@ func initialize_model_pools():
func _process(_delta):
if not dynamic_objects.has_new():
return
var object_list = dynamic_objects.get_dynamic_object_list(only_known_object)
reset_visibility()
update_models(object_list)

if object_3d_model_mode:
var object_list = dynamic_objects.get_dynamic_object_list(only_known_object)
reset_visibility()
update_models(object_list)
else:
var arr = []
arr.resize(Mesh.ARRAY_MAX)
var verts = PackedVector3Array()
var normals = PackedVector3Array()

var triangle_list = dynamic_objects.get_triangle_list(only_known_object)

for point in triangle_list:
verts.append(point["position"])
normals.append(point["normal"])

arr[Mesh.ARRAY_VERTEX] = verts
arr[Mesh.ARRAY_NORMAL] = normals

if !verts.is_empty():
reset_visibility()
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
dynamic_objects.set_old()

func reset_visibility():
mesh.clear_surfaces()
for model_type in model_types:
for node in model_types[model_type]["pool"]:
node.visible = false
Expand All @@ -53,33 +76,9 @@ func update_models(object_list):
node.set_position(Vector3(object["position"].x, object["position"].y - object["size"].y * 0.5, object["position"].z))
node.set_rotation(object["rotation"])
model_indices[model_type] += 1




#-------------------------------
#var arr = []
#arr.resize(Mesh.ARRAY_MAX)
#var verts = PackedVector3Array()
## var uvs = PoolVector2Array()
#var normals = PackedVector3Array()
## var indices = PoolIntArray()
#
#var triangle_list = dynamic_objects.get_triangle_list(only_known_object)
#
#for point in triangle_list:
#verts.append(point["position"])
#normals.append(point["normal"])
#
#arr[Mesh.ARRAY_VERTEX] = verts
#arr[Mesh.ARRAY_NORMAL] = normals
## arr[Mesh.ARRAY_INDEX] = indices
## arr[Mesh.ARRAY_TEX_UV] = uvs
#
#if !verts.is_empty():
#mesh.clear_surfaces()
#mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
#dynamic_objects.set_old()

func _on_OnlyKnownObjectCheckButton_toggled(button_pressed):
only_known_object = button_pressed

func _on_d_model_object_toggled(toggled_on):
object_3d_model_mode = toggled_on
12 changes: 10 additions & 2 deletions godot-project/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5527,12 +5527,19 @@ focus_mode = 0
button_pressed = true
text = "Only Known Objects"

[node name="Object3DModel" type="CheckButton" parent="Menu"]
offset_top = 121.0
offset_right = 224.0
offset_bottom = 152.0
focus_mode = 0
text = "3D Model Mode"

[node name="RenderingQuality" type="HBoxContainer" parent="Menu"]
layout_mode = 0
offset_left = 6.0
offset_top = 130.0
offset_top = 165.0
offset_right = 356.0
offset_bottom = 153.0
offset_bottom = 188.0

[node name="Label" type="Label" parent="Menu/RenderingQuality"]
layout_mode = 2
Expand Down Expand Up @@ -5586,4 +5593,5 @@ texture = ExtResource("23")
[connection signal="toggled" from="Menu/NightModeCheckButton" to="BackGround" method="_on_night_mode_check_button_toggled"]
[connection signal="toggled" from="Menu/NightModeCheckButton" to="EgoVehicle" method="_on_night_mode_check_button_toggled"]
[connection signal="toggled" from="Menu/OnlyKnownObjectCheckButton" to="DynamicObjectMesh" method="_on_OnlyKnownObjectCheckButton_toggled"]
[connection signal="toggled" from="Menu/Object3DModel" to="DynamicObjectMesh" method="_on_d_model_object_toggled"]
[connection signal="value_changed" from="Menu/RenderingQuality/MSAASlider" to="." method="_on_MSAASlider_value_changed"]

0 comments on commit 51e51c3

Please sign in to comment.