Implemented face deletion.

This commit is contained in:
Relintai 2022-01-15 15:18:14 +01:00
parent 18583e66f9
commit 76d5818c34
5 changed files with 124 additions and 7 deletions

View File

@ -159,3 +159,6 @@ func _on_add_auad_at_pressed():
func _oncreate_face_pressed():
plugin.create_face()
func _on_delete_pressed():
plugin.delete_selected()

View File

@ -289,6 +289,11 @@ margin_top = 18.0
margin_right = 1010.0
margin_bottom = 110.0
[node name="Delete" type="Button" parent="VBoxContainer/FaceOps/Operations"]
margin_right = 1010.0
margin_bottom = 20.0
text = "Delete"
[node name="Merge" type="Button" parent="VBoxContainer/FaceOps/Operations"]
margin_right = 1010.0
margin_bottom = 20.0
@ -472,6 +477,7 @@ script = ExtResource( 3 )
[connection signal="pressed" from="VBoxContainer/EdgeOps/Operations/Split" to="." method="_on_split_pressed"]
[connection signal="pressed" from="VBoxContainer/EdgeOps/Operations/Connect" to="." method="_on_connect_pressed"]
[connection signal="pressed" from="VBoxContainer/EdgeOps/Operations/Disconnect" to="." method="_on_disconnect_pressed"]
[connection signal="pressed" from="VBoxContainer/FaceOps/Operations/Delete" to="." method="_on_delete_pressed"]
[connection signal="pressed" from="VBoxContainer/FaceOps/Operations/Merge" to="." method="_on_merge_pressed"]
[connection signal="pressed" from="VBoxContainer/FaceOps/Operations/Split" to="." method="_on_split_pressed"]
[connection signal="pressed" from="VBoxContainer/FaceOps/Operations/Connect" to="." method="_on_connect_pressed"]

View File

@ -646,11 +646,6 @@ func create_face():
if _selected_points.size() <= 2:
return
var mdr_arr : Array = _mdr.array
if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0:
return
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
var points : PoolVector3Array = PoolVector3Array()
@ -664,3 +659,89 @@ func create_face():
pass
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
pass
func split_face_indices(face : int) -> Array:
var ps : PoolIntArray = _handle_to_vertex_map[face]
if ps.size() == 0:
return [ ]
var v0 : Vector3 = _vertices[ps[0]]
var v1 : Vector3 = Vector3()
var v1found : bool = false
var v0ei : PoolIntArray = PoolIntArray()
v0ei.append(ps[0])
var v1ei : PoolIntArray = PoolIntArray()
var v2ei : PoolIntArray = PoolIntArray()
for i in range(1, ps.size()):
var vert : Vector3 = _vertices[ps[i]]
if is_verts_equal(v0, vert):
v0ei.append(ps[i])
else:
if v1found:
if is_verts_equal(v1, vert):
v1ei.append(ps[i])
else:
v2ei.append(ps[i])
else:
v1found = true
v1 = _vertices[ps[i]]
v1ei.append(ps[i])
return [ v0ei, v1ei, v2ei ]
func find_first_triangle_index_for_face(face : int) -> int:
var split_indices_arr : Array = split_face_indices(face)
if split_indices_arr.size() == 0:
return -1
var v0ei : PoolIntArray = split_indices_arr[0]
var v1ei : PoolIntArray = split_indices_arr[1]
var v2ei : PoolIntArray = split_indices_arr[2]
var tri_index : int = -1
for i in range(0, _indices.size(), 3):
var i0 : int = _indices[i]
var i1 : int = _indices[i + 1]
var i2 : int = _indices[i + 2]
if pool_int_arr_contains(v0ei, i0) || pool_int_arr_contains(v0ei, i1) || pool_int_arr_contains(v0ei, i2):
if pool_int_arr_contains(v1ei, i0) || pool_int_arr_contains(v1ei, i1) || pool_int_arr_contains(v1ei, i2):
if pool_int_arr_contains(v2ei, i0) || pool_int_arr_contains(v2ei, i1) || pool_int_arr_contains(v2ei, i2):
return i / 3
return -1
func delete_selected() -> void:
if !_mdr:
return
if _selected_points.size() == 0:
return
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
#todo
pass
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
#todo
pass
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
if _mdr:
_mdr.disconnect("changed", self, "on_mdr_changed")
for sp in _selected_points:
var triangle_index : int = find_first_triangle_index_for_face(sp)
MDRMeshUtils.remove_triangle(_mdr, triangle_index)
_selected_points.resize(0)
if _mdr:
_mdr.connect("changed", self, "on_mdr_changed")
on_mdr_changed()

View File

@ -209,3 +209,7 @@ func disconnect_action():
func create_face():
for g in active_gizmos:
g.create_face()
func delete_selected():
for g in active_gizmos:
g.delete_selected()

View File

@ -1,8 +1,31 @@
tool
extends Object
static func add_triangulated_mesh_from_points(mdr : MeshDataResource, selected_points : PoolVector3Array, last_known_camera_facing : Vector3) -> void:
static func remove_triangle(mdr : MeshDataResource, triangle_index : int) -> void:
if triangle_index < 0:
return
var arrays : Array = mdr.get_array()
if arrays.size() != ArrayMesh.ARRAY_MAX:
arrays.resize(ArrayMesh.ARRAY_MAX)
if arrays[ArrayMesh.ARRAY_INDEX] == null:
return
var indices : PoolIntArray = arrays[ArrayMesh.ARRAY_INDEX]
# Just remove that triangle
var i : int = triangle_index * 3
indices.remove(i)
indices.remove(i)
indices.remove(i)
arrays[ArrayMesh.ARRAY_INDEX] = indices
mdr.set_array(arrays)
static func add_triangulated_mesh_from_points(mdr : MeshDataResource, selected_points : PoolVector3Array, last_known_camera_facing : Vector3) -> void:
if selected_points.size() < 3:
return