Implemented generating handle points.

This commit is contained in:
Relintai 2021-12-29 22:01:52 +01:00
parent e7110b5314
commit ec0b477291
3 changed files with 48 additions and 13 deletions

View File

@ -21,8 +21,6 @@ func create_gizmo(spatial):
gizmo.set_spatial_node(spatial)
gizmo.setup()
#gizmo.plugin = plugin
plugin.register_gizmo(gizmo)
return gizmo

View File

@ -26,7 +26,6 @@ enum SelectionMode {
var gizmo_size = 3.0
var vertices : PoolVector3Array
var indices : PoolIntArray
var handle_points : PoolVector3Array
var handle_to_vertex_map : Array
@ -75,8 +74,9 @@ func set_handle(index: int, camera: Camera, point: Vector2):
add_to_all_selected(ofs)
redraw()
recalculate_handle_points()
apply()
redraw()
elif edit_mode == EditMode.EDIT_MODE_SCALE:
var r : float = 1.0 + ((relative.x + relative.y) * 0.05)
@ -95,8 +95,9 @@ func set_handle(index: int, camera: Camera, point: Vector2):
mul_all_selected_with_basis(b)
redraw()
recalculate_handle_points()
apply()
redraw()
elif edit_mode == EditMode.EDIT_MODE_ROTATE:
print("MDR Editor: ROTATE NYI")
@ -141,7 +142,6 @@ func apply() -> void:
arrs[ArrayMesh.ARRAY_VERTEX] = vertices
_mdr.array = arrs
func forward_spatial_gui_input(index, camera, event):
if event is InputEventMouseButton:
var gt : Transform = get_spatial_node().global_transform
@ -281,6 +281,25 @@ func _notification(what):
if get_plugin():
get_plugin().unregister_gizmo(self)
#todo if selection type changed recalc handles aswell
#add method recalc handles -> check for type
func recalculate_handle_points() -> void:
if !_mdr:
handle_points.resize(0)
handle_to_vertex_map.resize(0)
var merged_arrays : Array = MeshUtils.merge_mesh_array(_mdr.array)
handle_points = merged_arrays[ArrayMesh.ARRAY_VERTEX]
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
handle_to_vertex_map = MeshDecompose.get_handle_vertex_to_vertex_map(_mdr.array, handle_points)
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
#todo
handle_to_vertex_map = MeshDecompose.get_handle_vertex_to_vertex_map(_mdr.array, handle_points)
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
#todo
handle_to_vertex_map = MeshDecompose.get_handle_vertex_to_vertex_map(_mdr.array, handle_points)
func on_mesh_data_resource_changed(mdr : MeshDataResource) -> void:
_mdr = mdr
@ -289,9 +308,5 @@ func on_mesh_data_resource_changed(mdr : MeshDataResource) -> void:
else:
vertices.resize(0)
#recalc handle points
#if selection type changed recalc handles aswell
#add method recalc handles -> check for type
recalculate_handle_points()
redraw()

View File

@ -5,9 +5,31 @@ extends Object
static func get_handle_vertex_to_vertex_map(arrays : Array, handle_points : PoolVector3Array) -> Array:
var handle_to_vertex_map : Array
handle_to_vertex_map.resize(handle_points.size())
#foreach handle points
#get all equal approx vertex and put it into the map
if handle_points.size() == 0:
return handle_to_vertex_map
if arrays.size() != ArrayMesh.ARRAY_MAX || arrays[ArrayMesh.ARRAY_INDEX] == null:
return handle_to_vertex_map
var vertices : PoolVector3Array = arrays[ArrayMesh.ARRAY_VERTEX]
if vertices.size() == 0:
return handle_to_vertex_map
for i in range(handle_points.size()):
var hv : Vector3 = handle_points[i]
var iarr : PoolIntArray = PoolIntArray()
#find all verts that have the same position as the handle
for j in range(vertices.size()):
var vn : Vector3 = vertices[j]
if is_equal_approx(hv.x, vn.x) && is_equal_approx(hv.y, vn.y) && is_equal_approx(hv.z, vn.z):
iarr.append(j)
handle_to_vertex_map[i] = iarr
return handle_to_vertex_map