2021-02-09 01:40:13 +01:00
|
|
|
tool
|
|
|
|
extends EditorSpatialGizmo
|
|
|
|
|
2021-12-29 17:10:58 +01:00
|
|
|
var MeshOutline = preload("res://addons/mesh_data_resource_editor/utilities/mesh_outline.gd")
|
2021-12-29 21:21:23 +01:00
|
|
|
var MeshDecompose = preload("res://addons/mesh_data_resource_editor/utilities/mesh_decompose.gd")
|
2022-01-14 13:17:31 +01:00
|
|
|
var MDRMeshUtils = preload("res://addons/mesh_data_resource_editor/utilities/mdred_mesh_utils.gd")
|
2021-12-29 17:10:58 +01:00
|
|
|
|
2021-03-02 21:41:24 +01:00
|
|
|
enum EditMode {
|
2021-12-29 21:38:57 +01:00
|
|
|
EDIT_MODE_NONE = 0,
|
|
|
|
EDIT_MODE_TRANSLATE = 1,
|
|
|
|
EDIT_MODE_SCALE = 2,
|
|
|
|
EDIT_MODE_ROTATE = 3
|
2021-03-02 21:41:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
enum AxisConstraint {
|
2021-03-15 15:02:25 +01:00
|
|
|
X = 1 << 0,
|
|
|
|
Y = 1 << 1,
|
|
|
|
Z = 1 << 2,
|
2021-03-02 21:41:24 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 21:21:23 +01:00
|
|
|
enum SelectionMode {
|
|
|
|
SELECTION_MODE_VERTEX = 0,
|
|
|
|
SELECTION_MODE_EDGE = 1,
|
|
|
|
SELECTION_MODE_FACE = 2,
|
|
|
|
}
|
2021-02-09 01:40:13 +01:00
|
|
|
|
2021-12-29 21:21:23 +01:00
|
|
|
var gizmo_size = 3.0
|
2021-02-28 00:18:38 +01:00
|
|
|
|
2021-12-29 23:30:08 +01:00
|
|
|
var edit_mode : int = EditMode.EDIT_MODE_TRANSLATE
|
|
|
|
var axis_constraint : int = AxisConstraint.X | AxisConstraint.Y | AxisConstraint.Z
|
|
|
|
var selection_mode : int = SelectionMode.SELECTION_MODE_VERTEX
|
2021-03-15 15:02:25 +01:00
|
|
|
var previous_point : Vector2
|
|
|
|
var is_dragging : bool = false
|
2022-01-15 13:44:14 +01:00
|
|
|
var _last_known_camera_facing : Vector3 = Vector3(0, 0, -1)
|
2021-02-28 00:18:38 +01:00
|
|
|
|
2021-12-29 21:21:23 +01:00
|
|
|
var _mdr : MeshDataResource = null
|
|
|
|
|
2021-12-29 23:30:08 +01:00
|
|
|
var _vertices : PoolVector3Array
|
2022-01-14 23:21:50 +01:00
|
|
|
var _indices : PoolIntArray
|
2021-12-29 23:30:08 +01:00
|
|
|
var _handle_points : PoolVector3Array
|
|
|
|
var _handle_to_vertex_map : Array
|
|
|
|
var _selected_points : PoolIntArray
|
|
|
|
|
|
|
|
var _mesh_outline_generator
|
2021-12-29 17:10:58 +01:00
|
|
|
|
2022-01-20 23:06:01 +01:00
|
|
|
var _handle_drag_op : bool = false
|
|
|
|
var _drag_op_orig_verices : PoolVector3Array = PoolVector3Array()
|
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
var _editor_plugin : EditorPlugin = null
|
|
|
|
var _undo_redo : UndoRedo = null
|
|
|
|
|
2021-12-29 17:10:58 +01:00
|
|
|
func _init():
|
2021-12-29 23:30:08 +01:00
|
|
|
_mesh_outline_generator = MeshOutline.new()
|
2021-12-29 21:21:23 +01:00
|
|
|
|
|
|
|
func setup() -> void:
|
|
|
|
get_spatial_node().connect("mesh_data_resource_changed", self, "on_mesh_data_resource_changed")
|
|
|
|
on_mesh_data_resource_changed(get_spatial_node().mesh_data)
|
2021-12-29 17:10:58 +01:00
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
func set_editor_plugin(editor_plugin : EditorPlugin) -> void:
|
|
|
|
_editor_plugin = editor_plugin
|
|
|
|
|
|
|
|
_undo_redo = _editor_plugin.get_undo_redo()
|
|
|
|
|
2021-02-09 01:40:13 +01:00
|
|
|
func set_handle(index: int, camera: Camera, point: Vector2):
|
2021-03-15 15:02:25 +01:00
|
|
|
var relative : Vector2 = point - previous_point
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-15 15:02:25 +01:00
|
|
|
if !is_dragging:
|
|
|
|
relative = Vector2()
|
|
|
|
is_dragging = true
|
2022-01-20 23:06:01 +01:00
|
|
|
|
|
|
|
_handle_drag_op = true
|
|
|
|
_drag_op_orig_verices = copy_mdr_verts_array()
|
2021-03-15 15:02:25 +01:00
|
|
|
|
2021-12-29 21:38:57 +01:00
|
|
|
if edit_mode == EditMode.EDIT_MODE_NONE:
|
2021-03-15 15:02:25 +01:00
|
|
|
return
|
2021-12-29 21:38:57 +01:00
|
|
|
elif edit_mode == EditMode.EDIT_MODE_TRANSLATE:
|
2021-12-29 17:48:27 +01:00
|
|
|
var ofs : Vector3 = Vector3()
|
2021-03-15 15:02:25 +01:00
|
|
|
|
2021-12-29 17:48:27 +01:00
|
|
|
if (axis_constraint & AxisConstraint.X) != 0:
|
|
|
|
ofs.x = relative.x * 0.001 * sign(camera.get_global_transform().basis.z.z)
|
2021-03-15 15:02:25 +01:00
|
|
|
|
2021-12-29 17:48:27 +01:00
|
|
|
if (axis_constraint & AxisConstraint.Y) != 0:
|
|
|
|
ofs.y = relative.y * -0.001
|
2021-03-15 15:02:25 +01:00
|
|
|
|
2021-12-29 17:48:27 +01:00
|
|
|
if (axis_constraint & AxisConstraint.Z) != 0:
|
|
|
|
ofs.z = relative.x * 0.001 * -sign(camera.get_global_transform().basis.z.x)
|
2021-03-15 15:02:25 +01:00
|
|
|
|
2021-12-29 17:48:27 +01:00
|
|
|
add_to_all_selected(ofs)
|
2021-03-15 15:02:25 +01:00
|
|
|
|
2021-12-29 22:01:52 +01:00
|
|
|
recalculate_handle_points()
|
2021-03-23 11:24:44 +01:00
|
|
|
apply()
|
2021-12-29 22:01:52 +01:00
|
|
|
redraw()
|
2021-12-29 21:38:57 +01:00
|
|
|
elif edit_mode == EditMode.EDIT_MODE_SCALE:
|
2021-03-16 12:24:24 +01:00
|
|
|
var r : float = 1.0 + ((relative.x + relative.y) * 0.05)
|
|
|
|
|
|
|
|
var vs : Vector3 = Vector3()
|
|
|
|
|
|
|
|
if (axis_constraint & AxisConstraint.X) != 0:
|
|
|
|
vs.x = r
|
|
|
|
|
|
|
|
if (axis_constraint & AxisConstraint.Y) != 0:
|
|
|
|
vs.y = r
|
|
|
|
|
|
|
|
if (axis_constraint & AxisConstraint.Z) != 0:
|
|
|
|
vs.z = r
|
|
|
|
|
|
|
|
var b : Basis = Basis().scaled(vs)
|
|
|
|
|
2021-12-29 17:48:27 +01:00
|
|
|
mul_all_selected_with_basis(b)
|
2021-03-16 12:24:24 +01:00
|
|
|
|
2021-12-29 22:01:52 +01:00
|
|
|
recalculate_handle_points()
|
2021-03-23 11:24:44 +01:00
|
|
|
apply()
|
2021-12-29 22:01:52 +01:00
|
|
|
redraw()
|
2021-12-29 21:38:57 +01:00
|
|
|
elif edit_mode == EditMode.EDIT_MODE_ROTATE:
|
2021-12-29 21:26:56 +01:00
|
|
|
print("MDR Editor: ROTATE NYI")
|
2021-03-15 15:02:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
previous_point = point
|
|
|
|
|
|
|
|
func commit_handle(index: int, restore, cancel: bool = false) -> void:
|
|
|
|
previous_point = Vector2()
|
|
|
|
|
2021-12-29 21:26:56 +01:00
|
|
|
print("MDR Editor: commit_handle test")
|
2021-02-09 01:40:13 +01:00
|
|
|
|
|
|
|
func redraw():
|
|
|
|
clear()
|
|
|
|
|
2021-12-29 21:21:23 +01:00
|
|
|
if !_mdr:
|
2021-02-09 01:40:13 +01:00
|
|
|
return
|
|
|
|
|
2021-12-29 21:21:23 +01:00
|
|
|
if _mdr.array.size() != ArrayMesh.ARRAY_MAX:
|
2021-11-17 15:31:04 +01:00
|
|
|
return
|
2021-12-29 17:10:58 +01:00
|
|
|
|
2021-12-30 01:14:05 +01:00
|
|
|
if !get_plugin():
|
|
|
|
return
|
|
|
|
|
2021-02-09 01:40:13 +01:00
|
|
|
var handles_material : SpatialMaterial = get_plugin().get_material("handles", self)
|
2021-12-29 17:10:58 +01:00
|
|
|
var material = get_plugin().get_material("main", self)
|
2022-01-18 21:11:37 +01:00
|
|
|
var seam_material = get_plugin().get_material("seam", self)
|
2021-02-09 01:40:13 +01:00
|
|
|
|
2021-12-29 23:30:08 +01:00
|
|
|
_mesh_outline_generator.setup(_mdr)
|
2021-12-31 08:41:25 +01:00
|
|
|
|
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
|
|
|
_mesh_outline_generator.generate_mark_edges()
|
2021-12-31 08:54:12 +01:00
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
|
|
|
_mesh_outline_generator.generate_mark_faces()
|
2021-12-31 08:41:25 +01:00
|
|
|
else:
|
|
|
|
_mesh_outline_generator.generate()
|
|
|
|
|
2021-12-29 23:30:08 +01:00
|
|
|
add_lines(_mesh_outline_generator.lines, material, false)
|
2022-01-18 21:11:37 +01:00
|
|
|
add_lines(_mesh_outline_generator.seam_lines, seam_material, false)
|
2021-12-31 00:52:39 +01:00
|
|
|
|
2021-12-30 01:18:03 +01:00
|
|
|
if _selected_points.size() > 0:
|
|
|
|
var vs : PoolVector3Array = PoolVector3Array()
|
|
|
|
|
|
|
|
for i in _selected_points:
|
|
|
|
vs.append(_handle_points[i])
|
|
|
|
|
|
|
|
add_handles(vs, handles_material)
|
2021-02-09 01:40:13 +01:00
|
|
|
|
2021-03-23 11:24:44 +01:00
|
|
|
func apply() -> void:
|
2021-12-29 21:21:23 +01:00
|
|
|
if !_mdr:
|
2021-03-23 11:24:44 +01:00
|
|
|
return
|
2021-12-31 00:52:39 +01:00
|
|
|
|
|
|
|
_mdr.disconnect("changed", self, "on_mdr_changed")
|
|
|
|
|
2021-12-29 21:21:23 +01:00
|
|
|
var arrs : Array = _mdr.array
|
2021-12-29 23:30:08 +01:00
|
|
|
arrs[ArrayMesh.ARRAY_VERTEX] = _vertices
|
2022-01-14 23:21:50 +01:00
|
|
|
arrs[ArrayMesh.ARRAY_INDEX] = _indices
|
2021-12-29 21:21:23 +01:00
|
|
|
_mdr.array = arrs
|
2021-12-31 00:52:39 +01:00
|
|
|
|
|
|
|
_mdr.connect("changed", self, "on_mdr_changed")
|
2021-12-29 21:21:23 +01:00
|
|
|
|
2021-02-28 00:18:38 +01:00
|
|
|
func forward_spatial_gui_input(index, camera, event):
|
2022-01-15 13:44:14 +01:00
|
|
|
_last_known_camera_facing = camera.transform.basis.xform(Vector3(0, 0, -1))
|
|
|
|
|
2021-02-28 00:18:38 +01:00
|
|
|
if event is InputEventMouseButton:
|
|
|
|
var gt : Transform = get_spatial_node().global_transform
|
|
|
|
var ray_from : Vector3 = camera.global_transform.origin
|
|
|
|
var gpoint : Vector2 = event.get_position()
|
2021-03-02 13:03:02 +01:00
|
|
|
var grab_threshold : float = 8
|
2021-02-28 00:18:38 +01:00
|
|
|
|
|
|
|
if event.get_button_index() == BUTTON_LEFT:
|
|
|
|
if event.is_pressed():
|
|
|
|
var mouse_pos = event.get_position()
|
|
|
|
|
|
|
|
# if (_gizmo_select(p_index, _edit.mouse_pos))
|
|
|
|
# return true;
|
|
|
|
|
|
|
|
# select vertex
|
|
|
|
var closest_idx : int = -1
|
|
|
|
var closest_dist : float = 1e10
|
|
|
|
|
2021-12-29 23:30:08 +01:00
|
|
|
for i in range(_handle_points.size()):
|
|
|
|
var vert_pos_3d : Vector3 = gt.xform(_handle_points[i])
|
2021-03-02 13:03:02 +01:00
|
|
|
var vert_pos_2d : Vector2 = camera.unproject_position(vert_pos_3d)
|
|
|
|
var dist_3d : float = ray_from.distance_to(vert_pos_3d)
|
|
|
|
var dist_2d : float = gpoint.distance_to(vert_pos_2d)
|
2021-02-28 00:18:38 +01:00
|
|
|
|
|
|
|
if (dist_2d < grab_threshold && dist_3d < closest_dist):
|
2021-12-29 23:34:54 +01:00
|
|
|
closest_dist = dist_3d
|
|
|
|
closest_idx = i
|
2021-02-28 00:18:38 +01:00
|
|
|
|
|
|
|
if (closest_idx >= 0):
|
2021-12-29 23:30:08 +01:00
|
|
|
for si in _selected_points:
|
2021-03-02 21:41:24 +01:00
|
|
|
if si == closest_idx:
|
|
|
|
return false
|
|
|
|
|
2021-12-29 23:30:08 +01:00
|
|
|
_selected_points.append(closest_idx)
|
2021-02-28 00:18:38 +01:00
|
|
|
|
2021-03-23 11:24:44 +01:00
|
|
|
apply()
|
2021-12-29 17:54:44 +01:00
|
|
|
redraw()
|
2021-03-02 13:03:02 +01:00
|
|
|
else:
|
2021-12-30 01:18:03 +01:00
|
|
|
if _selected_points.size() == 0:
|
|
|
|
return false
|
|
|
|
|
2021-12-29 23:30:08 +01:00
|
|
|
_selected_points.resize(0)
|
2021-12-29 23:23:50 +01:00
|
|
|
|
2021-12-29 17:54:44 +01:00
|
|
|
redraw()
|
2021-03-15 15:02:25 +01:00
|
|
|
else:
|
|
|
|
is_dragging = false
|
2022-01-20 23:06:01 +01:00
|
|
|
|
|
|
|
if _handle_drag_op && _mdr && _mdr.array.size() == ArrayMesh.ARRAY_MAX && _mdr.array[ArrayMesh.ARRAY_VERTEX] != null && _mdr.array[ArrayMesh.ARRAY_VERTEX].size() == _drag_op_orig_verices.size():
|
|
|
|
_undo_redo.create_action("Drag")
|
|
|
|
_undo_redo.add_do_method(self, "apply_vertex_array", _mdr, _mdr.array[ArrayMesh.ARRAY_VERTEX])
|
|
|
|
_undo_redo.add_undo_method(self, "apply_vertex_array", _mdr, _drag_op_orig_verices)
|
|
|
|
_undo_redo.commit_action()
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2022-01-20 23:06:01 +01:00
|
|
|
_handle_drag_op = false
|
|
|
|
|
2021-03-15 15:02:25 +01:00
|
|
|
# elif event is InputEventMouseMotion:
|
2021-12-29 21:38:57 +01:00
|
|
|
# if edit_mode == EditMode.EDIT_MODE_NONE:
|
2021-03-15 15:02:25 +01:00
|
|
|
# return false
|
2021-12-29 21:38:57 +01:00
|
|
|
# elif edit_mode == EditMode.EDIT_MODE_TRANSLATE:
|
2021-03-15 15:02:25 +01:00
|
|
|
# for i in selected_indices:
|
|
|
|
# var v : Vector3 = vertices[i]
|
|
|
|
#
|
|
|
|
# if axis_constraint == AxisConstraint.X:
|
|
|
|
# v.x += event.relative.x * -0.001
|
|
|
|
# elif axis_constraint == AxisConstraint.Y:
|
|
|
|
# v.y += event.relative.y * 0.001
|
|
|
|
# elif axis_constraint == AxisConstraint.Z:
|
|
|
|
# v.z += event.relative.x * 0.001
|
|
|
|
#
|
|
|
|
# vertices.set(i, v)
|
|
|
|
#
|
|
|
|
# redraw()
|
2021-12-29 21:38:57 +01:00
|
|
|
# elif edit_mode == EditMode.EDIT_MODE_SCALE:
|
2021-03-15 15:02:25 +01:00
|
|
|
# print("SCALE")
|
2021-12-29 21:38:57 +01:00
|
|
|
# elif edit_mode == EditMode.EDIT_MODE_ROTATE:
|
2021-03-15 15:02:25 +01:00
|
|
|
# print("ROTATE")
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-02-28 00:18:38 +01:00
|
|
|
return false
|
|
|
|
|
2021-12-29 17:48:27 +01:00
|
|
|
func add_to_all_selected(ofs : Vector3) -> void:
|
2021-12-29 23:30:08 +01:00
|
|
|
for i in _selected_points:
|
2021-12-29 23:34:54 +01:00
|
|
|
var v : Vector3 = _handle_points[i]
|
2021-12-29 17:48:27 +01:00
|
|
|
v += ofs
|
2021-12-29 23:34:54 +01:00
|
|
|
_handle_points.set(i, v)
|
2021-12-29 23:23:50 +01:00
|
|
|
|
2021-12-29 23:30:08 +01:00
|
|
|
for i in _selected_points:
|
|
|
|
var ps : PoolIntArray = _handle_to_vertex_map[i]
|
2021-12-29 23:23:50 +01:00
|
|
|
|
|
|
|
for j in ps:
|
2021-12-29 23:30:08 +01:00
|
|
|
var v : Vector3 = _vertices[j]
|
2021-12-29 23:23:50 +01:00
|
|
|
v += ofs
|
2021-12-29 23:30:08 +01:00
|
|
|
_vertices.set(j, v)
|
2021-12-29 17:48:27 +01:00
|
|
|
|
|
|
|
func mul_all_selected_with_basis(b : Basis) -> void:
|
2021-12-29 23:30:08 +01:00
|
|
|
for i in _selected_points:
|
2021-12-29 23:34:54 +01:00
|
|
|
var v : Vector3 = _handle_points[i]
|
2021-12-29 17:48:27 +01:00
|
|
|
v = b * v
|
2021-12-29 23:34:54 +01:00
|
|
|
_handle_points.set(i, v)
|
2021-12-29 23:23:50 +01:00
|
|
|
|
2021-12-29 23:30:08 +01:00
|
|
|
for i in _selected_points:
|
|
|
|
var ps : PoolIntArray = _handle_to_vertex_map[i]
|
2021-12-29 23:23:50 +01:00
|
|
|
|
|
|
|
for j in ps:
|
2021-12-29 23:30:08 +01:00
|
|
|
var v : Vector3 = _vertices[j]
|
2021-12-29 23:23:50 +01:00
|
|
|
v = b * v
|
2021-12-29 23:30:08 +01:00
|
|
|
_vertices.set(j, v)
|
2021-12-29 17:48:27 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_translate(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
if on:
|
2021-12-29 21:38:57 +01:00
|
|
|
edit_mode = EditMode.EDIT_MODE_TRANSLATE
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_scale(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
if on:
|
2021-12-29 21:38:57 +01:00
|
|
|
edit_mode = EditMode.EDIT_MODE_SCALE
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_rotate(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
if on:
|
2021-12-29 21:38:57 +01:00
|
|
|
edit_mode = EditMode.EDIT_MODE_ROTATE
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_axis_x(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
if on:
|
2021-12-31 08:07:13 +01:00
|
|
|
axis_constraint |= AxisConstraint.X
|
|
|
|
else:
|
2021-03-15 15:02:25 +01:00
|
|
|
if (axis_constraint & AxisConstraint.X) != 0:
|
|
|
|
axis_constraint ^= AxisConstraint.X
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_axis_y(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
if on:
|
2021-12-31 08:07:13 +01:00
|
|
|
axis_constraint |= AxisConstraint.Y
|
|
|
|
else:
|
2021-03-15 15:02:25 +01:00
|
|
|
if (axis_constraint & AxisConstraint.Y) != 0:
|
|
|
|
axis_constraint ^= AxisConstraint.Y
|
2021-03-02 21:41:24 +01:00
|
|
|
|
2021-03-24 19:09:02 +01:00
|
|
|
func set_axis_z(on : bool) -> void:
|
2021-03-02 21:41:24 +01:00
|
|
|
if on:
|
2021-12-31 08:07:13 +01:00
|
|
|
axis_constraint |= AxisConstraint.Z
|
|
|
|
else:
|
2021-03-15 15:02:25 +01:00
|
|
|
if (axis_constraint & AxisConstraint.Z) != 0:
|
|
|
|
axis_constraint ^= AxisConstraint.Z
|
2021-02-28 00:18:38 +01:00
|
|
|
|
2021-12-31 08:18:56 +01:00
|
|
|
func set_selection_mode_vertex() -> void:
|
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
|
|
|
return
|
|
|
|
|
|
|
|
selection_mode = SelectionMode.SELECTION_MODE_VERTEX
|
|
|
|
_selected_points.resize(0)
|
|
|
|
recalculate_handle_points()
|
|
|
|
redraw()
|
|
|
|
|
|
|
|
func set_selection_mode_edge() -> void:
|
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
|
|
|
return
|
|
|
|
|
|
|
|
selection_mode = SelectionMode.SELECTION_MODE_EDGE
|
|
|
|
_selected_points.resize(0)
|
|
|
|
recalculate_handle_points()
|
|
|
|
redraw()
|
|
|
|
|
|
|
|
func set_selection_mode_face() -> void:
|
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
|
|
|
return
|
|
|
|
|
|
|
|
selection_mode = SelectionMode.SELECTION_MODE_FACE
|
|
|
|
_selected_points.resize(0)
|
|
|
|
recalculate_handle_points()
|
|
|
|
redraw()
|
|
|
|
|
2021-02-28 00:18:38 +01:00
|
|
|
func _notification(what):
|
|
|
|
if what == NOTIFICATION_PREDELETE:
|
2021-12-30 01:23:54 +01:00
|
|
|
if self != null && get_plugin():
|
2021-12-29 21:21:23 +01:00
|
|
|
get_plugin().unregister_gizmo(self)
|
|
|
|
|
2021-12-29 22:01:52 +01:00
|
|
|
func recalculate_handle_points() -> void:
|
|
|
|
if !_mdr:
|
2021-12-29 23:30:08 +01:00
|
|
|
_handle_points.resize(0)
|
|
|
|
_handle_to_vertex_map.resize(0)
|
2021-12-31 00:53:21 +01:00
|
|
|
return
|
2021-12-31 00:52:39 +01:00
|
|
|
|
2021-12-29 23:42:19 +01:00
|
|
|
var mdr_arr : Array = _mdr.array
|
|
|
|
|
2021-12-30 01:21:38 +01:00
|
|
|
if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0:
|
|
|
|
_handle_points.resize(0)
|
|
|
|
_handle_to_vertex_map.resize(0)
|
2021-12-29 23:42:19 +01:00
|
|
|
return
|
2021-12-31 00:52:39 +01:00
|
|
|
|
2021-12-29 23:42:19 +01:00
|
|
|
var arr : Array = Array()
|
|
|
|
arr.resize(ArrayMesh.ARRAY_MAX)
|
|
|
|
arr[ArrayMesh.ARRAY_VERTEX] = mdr_arr[ArrayMesh.ARRAY_VERTEX]
|
|
|
|
arr[ArrayMesh.ARRAY_INDEX] = mdr_arr[ArrayMesh.ARRAY_INDEX]
|
|
|
|
|
2021-12-29 22:01:52 +01:00
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
2021-12-31 00:12:02 +01:00
|
|
|
var merged_arrays : Array = MeshUtils.merge_mesh_array(arr)
|
|
|
|
_handle_points = merged_arrays[ArrayMesh.ARRAY_VERTEX]
|
2021-12-31 00:54:14 +01:00
|
|
|
_handle_to_vertex_map = MeshDecompose.get_handle_vertex_to_vertex_map(mdr_arr, _handle_points)
|
2021-12-29 22:01:52 +01:00
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
2021-12-31 00:12:02 +01:00
|
|
|
var result : Array = MeshDecompose.get_handle_edge_to_vertex_map(arr)
|
|
|
|
|
|
|
|
_handle_points = result[0]
|
|
|
|
_handle_to_vertex_map = result[1]
|
2021-12-29 22:01:52 +01:00
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
2021-12-31 14:37:07 +01:00
|
|
|
var result : Array = MeshDecompose.get_handle_face_to_vertex_map(arr)
|
|
|
|
|
|
|
|
_handle_points = result[0]
|
|
|
|
_handle_to_vertex_map = result[1]
|
2021-12-29 22:01:52 +01:00
|
|
|
|
2021-12-29 21:21:23 +01:00
|
|
|
func on_mesh_data_resource_changed(mdr : MeshDataResource) -> void:
|
2021-12-31 00:52:39 +01:00
|
|
|
if _mdr:
|
|
|
|
_mdr.disconnect("changed", self, "on_mdr_changed")
|
|
|
|
|
2021-12-29 21:21:23 +01:00
|
|
|
_mdr = mdr
|
2021-12-29 21:24:27 +01:00
|
|
|
|
2021-12-31 00:52:39 +01:00
|
|
|
if _mdr && _mdr.array.size() == ArrayMesh.ARRAY_MAX && _mdr.array[ArrayMesh.ARRAY_VERTEX] != null:
|
|
|
|
_vertices = _mdr.array[ArrayMesh.ARRAY_VERTEX]
|
2022-01-14 23:21:50 +01:00
|
|
|
_indices = _mdr.array[ArrayMesh.ARRAY_INDEX]
|
2021-12-31 00:52:39 +01:00
|
|
|
else:
|
|
|
|
_vertices.resize(0)
|
2022-01-14 23:21:50 +01:00
|
|
|
_indices.resize(0)
|
2021-12-31 00:52:39 +01:00
|
|
|
|
|
|
|
if _mdr:
|
|
|
|
_mdr.connect("changed", self, "on_mdr_changed")
|
|
|
|
|
|
|
|
recalculate_handle_points()
|
|
|
|
redraw()
|
|
|
|
|
|
|
|
func on_mdr_changed() -> void:
|
2021-12-29 21:24:27 +01:00
|
|
|
if _mdr && _mdr.array.size() == ArrayMesh.ARRAY_MAX && _mdr.array[ArrayMesh.ARRAY_VERTEX] != null:
|
2021-12-29 23:30:08 +01:00
|
|
|
_vertices = _mdr.array[ArrayMesh.ARRAY_VERTEX]
|
2022-01-14 23:21:50 +01:00
|
|
|
_indices = _mdr.array[ArrayMesh.ARRAY_INDEX]
|
2021-12-29 21:24:27 +01:00
|
|
|
else:
|
2021-12-29 23:30:08 +01:00
|
|
|
_vertices.resize(0)
|
2022-01-14 23:21:50 +01:00
|
|
|
_indices.resize(0)
|
2021-12-29 21:26:56 +01:00
|
|
|
|
2021-12-29 22:01:52 +01:00
|
|
|
recalculate_handle_points()
|
2021-12-29 21:21:23 +01:00
|
|
|
redraw()
|
2022-01-03 14:45:40 +01:00
|
|
|
|
2022-01-19 01:46:33 +01:00
|
|
|
func disable_change_event() -> void:
|
|
|
|
_mdr.disconnect("changed", self, "on_mdr_changed")
|
|
|
|
|
|
|
|
func enable_change_event(update : bool = true) -> void:
|
|
|
|
_mdr.connect("changed", self, "on_mdr_changed")
|
|
|
|
|
|
|
|
if update:
|
|
|
|
on_mdr_changed()
|
|
|
|
|
2022-01-03 14:45:40 +01:00
|
|
|
func add_triangle() -> void:
|
2022-01-03 16:54:28 +01:00
|
|
|
if _mdr:
|
2022-01-20 22:31:30 +01:00
|
|
|
var orig_arr = copy_arrays(_mdr.array)
|
2022-01-14 13:17:31 +01:00
|
|
|
MDRMeshUtils.add_triangle(_mdr)
|
2022-01-20 22:31:30 +01:00
|
|
|
add_mesh_change_undo_redo(orig_arr, _mdr.array, "Add Triangle")
|
2022-01-03 16:54:28 +01:00
|
|
|
|
2022-01-03 14:45:40 +01:00
|
|
|
func add_quad() -> void:
|
2022-01-03 16:54:28 +01:00
|
|
|
if _mdr:
|
2022-01-20 22:31:30 +01:00
|
|
|
var orig_arr = copy_arrays(_mdr.array)
|
2022-01-14 13:17:31 +01:00
|
|
|
MDRMeshUtils.add_quad(_mdr)
|
2022-01-20 22:31:30 +01:00
|
|
|
add_mesh_change_undo_redo(orig_arr, _mdr.array, "Add Quad")
|
2022-01-03 16:54:28 +01:00
|
|
|
|
2022-01-14 16:22:40 +01:00
|
|
|
func is_verts_equal(v0 : Vector3, v1 : Vector3) -> bool:
|
|
|
|
return is_equal_approx(v0.x, v1.x) && is_equal_approx(v0.y, v1.y) && is_equal_approx(v0.z, v1.z)
|
|
|
|
|
2022-01-14 23:21:50 +01:00
|
|
|
func find_other_vertex_for_edge(edge : int, v0 : Vector3) -> Vector3:
|
|
|
|
var ps : PoolIntArray = _handle_to_vertex_map[edge]
|
|
|
|
|
|
|
|
var vert : Vector3 = Vector3()
|
|
|
|
|
|
|
|
for i in range(ps.size()):
|
|
|
|
vert = _vertices[ps[i]]
|
|
|
|
|
|
|
|
if !is_verts_equal(v0, vert):
|
|
|
|
return vert
|
|
|
|
|
|
|
|
return v0
|
|
|
|
|
|
|
|
func split_edge_indices(edge : int) -> Array:
|
|
|
|
var ps : PoolIntArray = _handle_to_vertex_map[edge]
|
|
|
|
|
|
|
|
if ps.size() == 0:
|
|
|
|
return [ ]
|
|
|
|
|
|
|
|
var v0 : Vector3 = _vertices[ps[0]]
|
|
|
|
|
|
|
|
var v0ei : PoolIntArray = PoolIntArray()
|
|
|
|
v0ei.append(ps[0])
|
|
|
|
var v1ei : 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:
|
|
|
|
v1ei.append(ps[i])
|
|
|
|
|
|
|
|
return [ v0ei, v1ei ]
|
|
|
|
|
|
|
|
func pool_int_arr_contains(arr : PoolIntArray, val : int) -> bool:
|
|
|
|
for a in arr:
|
|
|
|
if a == val:
|
|
|
|
return true
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
func find_triangles_for_edge(edge : int) -> PoolIntArray:
|
|
|
|
var eisarr : Array = split_edge_indices(edge)
|
|
|
|
|
|
|
|
if eisarr.size() == 0:
|
|
|
|
return PoolIntArray()
|
2022-01-14 16:22:40 +01:00
|
|
|
|
2022-01-14 23:21:50 +01:00
|
|
|
# these should have the same size
|
|
|
|
var v0ei : PoolIntArray = eisarr[0]
|
|
|
|
var v1ei : PoolIntArray = eisarr[1]
|
2022-01-14 16:22:40 +01:00
|
|
|
|
2022-01-14 23:21:50 +01:00
|
|
|
var res : PoolIntArray = PoolIntArray()
|
|
|
|
|
|
|
|
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):
|
|
|
|
res.append(i / 3)
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
func find_first_triangle_for_edge(edge : int) -> int:
|
|
|
|
var eisarr : Array = split_edge_indices(edge)
|
|
|
|
|
|
|
|
if eisarr.size() == 0:
|
|
|
|
return -1
|
|
|
|
|
|
|
|
# these should have the same size
|
|
|
|
var v0ei : PoolIntArray = eisarr[0]
|
|
|
|
var v1ei : PoolIntArray = eisarr[1]
|
|
|
|
|
|
|
|
var res : PoolIntArray = PoolIntArray()
|
|
|
|
|
|
|
|
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):
|
|
|
|
return i / 3
|
|
|
|
|
|
|
|
return -1
|
2022-01-14 16:22:40 +01:00
|
|
|
|
2022-01-14 23:21:50 +01:00
|
|
|
func add_triangle_to_edge(edge : int) -> void:
|
|
|
|
var triangle_index : int = find_first_triangle_for_edge(edge)
|
|
|
|
|
|
|
|
var inds : int = triangle_index * 3
|
|
|
|
|
|
|
|
var ti0 : int = _indices[inds]
|
|
|
|
var ti1 : int = _indices[inds + 1]
|
|
|
|
var ti2 : int = _indices[inds + 2]
|
|
|
|
|
|
|
|
var ps : PoolIntArray = _handle_to_vertex_map[edge]
|
|
|
|
|
|
|
|
if ps.size() == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
var ei0 : int = 0
|
|
|
|
var ei1 : int = 0
|
|
|
|
var erefind : int = 0
|
|
|
|
|
|
|
|
if !pool_int_arr_contains(ps, ti0):
|
|
|
|
ei0 = ti1
|
|
|
|
ei1 = ti2
|
|
|
|
erefind = ti0
|
|
|
|
elif !pool_int_arr_contains(ps, ti1):
|
|
|
|
ei0 = ti0
|
|
|
|
ei1 = ti2
|
|
|
|
erefind = ti1
|
|
|
|
elif !pool_int_arr_contains(ps, ti2):
|
|
|
|
ei0 = ti0
|
|
|
|
ei1 = ti1
|
|
|
|
erefind = ti2
|
2022-01-15 01:01:40 +01:00
|
|
|
|
|
|
|
var fo : Vector3 = MDRMeshUtils.get_face_normal(_vertices[ti0], _vertices[ti1], _vertices[ti2])
|
|
|
|
var fn : Vector3 = MDRMeshUtils.get_face_normal(_vertices[ei0], _vertices[ei1], _vertices[erefind])
|
|
|
|
|
|
|
|
if fo.dot(fn) < 0:
|
|
|
|
var t : int = ei0
|
|
|
|
ei0 = ei1
|
|
|
|
ei1 = t
|
2022-01-14 23:21:50 +01:00
|
|
|
|
|
|
|
MDRMeshUtils.append_triangle_to_tri_edge(_mdr, _vertices[ei0], _vertices[ei1], _vertices[erefind])
|
2022-01-15 01:29:09 +01:00
|
|
|
|
|
|
|
func add_quad_to_edge(edge : int) -> void:
|
|
|
|
var triangle_index : int = find_first_triangle_for_edge(edge)
|
|
|
|
|
|
|
|
var inds : int = triangle_index * 3
|
|
|
|
|
|
|
|
var ti0 : int = _indices[inds]
|
|
|
|
var ti1 : int = _indices[inds + 1]
|
|
|
|
var ti2 : int = _indices[inds + 2]
|
|
|
|
|
|
|
|
var ps : PoolIntArray = _handle_to_vertex_map[edge]
|
|
|
|
|
|
|
|
if ps.size() == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
var ei0 : int = 0
|
|
|
|
var ei1 : int = 0
|
|
|
|
var erefind : int = 0
|
2022-01-14 23:21:50 +01:00
|
|
|
|
2022-01-15 01:29:09 +01:00
|
|
|
if !pool_int_arr_contains(ps, ti0):
|
|
|
|
ei0 = ti1
|
|
|
|
ei1 = ti2
|
|
|
|
erefind = ti0
|
|
|
|
elif !pool_int_arr_contains(ps, ti1):
|
|
|
|
ei0 = ti0
|
|
|
|
ei1 = ti2
|
|
|
|
erefind = ti1
|
|
|
|
elif !pool_int_arr_contains(ps, ti2):
|
|
|
|
ei0 = ti0
|
|
|
|
ei1 = ti1
|
|
|
|
erefind = ti2
|
|
|
|
|
|
|
|
var fo : Vector3 = MDRMeshUtils.get_face_normal(_vertices[ti0], _vertices[ti1], _vertices[ti2])
|
|
|
|
var fn : Vector3 = MDRMeshUtils.get_face_normal(_vertices[ei0], _vertices[ei1], _vertices[erefind])
|
|
|
|
|
|
|
|
if fo.dot(fn) < 0:
|
|
|
|
var t : int = ei0
|
|
|
|
ei0 = ei1
|
|
|
|
ei1 = t
|
|
|
|
|
|
|
|
MDRMeshUtils.append_quad_to_tri_edge(_mdr, _vertices[ei0], _vertices[ei1], _vertices[erefind])
|
|
|
|
|
2022-01-14 15:24:59 +01:00
|
|
|
func add_triangle_at() -> void:
|
2022-01-14 23:21:50 +01:00
|
|
|
if !_mdr:
|
|
|
|
return
|
|
|
|
|
2022-01-14 15:50:54 +01:00
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
|
|
|
#todo
|
|
|
|
pass
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
2022-01-20 22:31:30 +01:00
|
|
|
disable_change_event()
|
|
|
|
var orig_arr = copy_arrays(_mdr.array)
|
2022-01-15 17:12:01 +01:00
|
|
|
|
2022-01-14 23:21:50 +01:00
|
|
|
for sp in _selected_points:
|
|
|
|
add_triangle_to_edge(sp)
|
2022-01-20 22:31:30 +01:00
|
|
|
|
2022-01-15 17:12:01 +01:00
|
|
|
_selected_points.resize(0)
|
2022-01-20 22:31:30 +01:00
|
|
|
add_mesh_change_undo_redo(orig_arr, _mdr.array, "Add Triangle At")
|
|
|
|
enable_change_event()
|
2022-01-14 15:50:54 +01:00
|
|
|
else:
|
|
|
|
add_triangle()
|
2022-01-14 15:24:59 +01:00
|
|
|
|
|
|
|
func add_quad_at() -> void:
|
2022-01-15 01:29:09 +01:00
|
|
|
if !_mdr:
|
|
|
|
return
|
|
|
|
|
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
|
|
|
#todo
|
|
|
|
pass
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
2022-01-20 22:31:30 +01:00
|
|
|
disable_change_event()
|
|
|
|
var orig_arr = copy_arrays(_mdr.array)
|
2022-01-15 17:12:01 +01:00
|
|
|
|
2022-01-15 01:29:09 +01:00
|
|
|
for sp in _selected_points:
|
|
|
|
add_quad_to_edge(sp)
|
2022-01-15 17:12:01 +01:00
|
|
|
|
|
|
|
_selected_points.resize(0)
|
2022-01-20 22:31:30 +01:00
|
|
|
add_mesh_change_undo_redo(orig_arr, _mdr.array, "Add Quad At")
|
|
|
|
enable_change_event()
|
2022-01-15 01:29:09 +01:00
|
|
|
else:
|
|
|
|
add_triangle()
|
2022-01-14 15:24:59 +01:00
|
|
|
|
2022-01-03 16:54:28 +01:00
|
|
|
func add_box() -> void:
|
|
|
|
if _mdr:
|
2022-01-20 22:31:30 +01:00
|
|
|
var orig_arr = copy_arrays(_mdr.array)
|
2022-01-14 13:17:31 +01:00
|
|
|
MDRMeshUtils.add_box(_mdr)
|
2022-01-20 22:31:30 +01:00
|
|
|
add_mesh_change_undo_redo(orig_arr, _mdr.array, "Add Box")
|
|
|
|
|
2022-01-03 17:33:34 +01:00
|
|
|
func split():
|
|
|
|
pass
|
|
|
|
|
|
|
|
func disconnect_action():
|
|
|
|
pass
|
2022-01-15 13:44:14 +01:00
|
|
|
|
|
|
|
func create_face():
|
|
|
|
if !_mdr:
|
|
|
|
return
|
|
|
|
|
|
|
|
if _selected_points.size() <= 2:
|
|
|
|
return
|
2022-01-15 15:18:14 +01:00
|
|
|
|
2022-01-15 13:44:14 +01:00
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
2022-01-20 23:06:01 +01:00
|
|
|
disable_change_event()
|
2022-01-15 13:44:14 +01:00
|
|
|
|
|
|
|
var points : PoolVector3Array = PoolVector3Array()
|
|
|
|
|
|
|
|
for sp in _selected_points:
|
|
|
|
points.push_back(_handle_points[sp])
|
|
|
|
|
|
|
|
MDRMeshUtils.add_triangulated_mesh_from_points(_mdr, points, _last_known_camera_facing)
|
2022-01-15 17:12:01 +01:00
|
|
|
|
2022-01-20 23:06:01 +01:00
|
|
|
|
|
|
|
|
2022-01-15 17:12:01 +01:00
|
|
|
_selected_points.resize(0)
|
2022-01-20 23:06:01 +01:00
|
|
|
enable_change_event()
|
2022-01-15 13:44:14 +01:00
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
|
|
|
pass
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
|
|
|
pass
|
2022-01-15 15:18:14 +01:00
|
|
|
|
|
|
|
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:
|
2022-01-19 01:46:33 +01:00
|
|
|
disable_change_event()
|
2022-01-15 15:18:14 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-01-19 01:46:33 +01:00
|
|
|
enable_change_event()
|
|
|
|
|
2022-01-15 15:53:08 +01:00
|
|
|
func generate_normals():
|
|
|
|
if !_mdr:
|
|
|
|
return
|
2022-01-19 01:46:33 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
disable_change_event()
|
|
|
|
var seam_points : PoolVector3Array = MDRMeshUtils.seams_to_points(_mdr)
|
2022-01-15 15:53:08 +01:00
|
|
|
MDRMeshUtils.generate_normals(_mdr)
|
2022-01-19 01:46:33 +01:00
|
|
|
MDRMeshUtils.points_to_seams(_mdr, seam_points)
|
|
|
|
enable_change_event()
|
2022-01-15 15:53:08 +01:00
|
|
|
|
|
|
|
func generate_tangents():
|
|
|
|
if !_mdr:
|
|
|
|
return
|
|
|
|
|
2022-01-19 01:46:33 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
disable_change_event()
|
|
|
|
var seam_points : PoolVector3Array = MDRMeshUtils.seams_to_points(_mdr)
|
2022-01-15 15:53:08 +01:00
|
|
|
MDRMeshUtils.generate_tangents(_mdr)
|
2022-01-19 01:46:33 +01:00
|
|
|
MDRMeshUtils.points_to_seams(_mdr, seam_points)
|
|
|
|
enable_change_event()
|
2022-01-15 15:53:08 +01:00
|
|
|
|
|
|
|
func remove_doubles():
|
|
|
|
if !_mdr:
|
|
|
|
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
|
|
|
|
|
2022-01-19 01:46:33 +01:00
|
|
|
disable_change_event()
|
|
|
|
|
2022-01-18 22:21:50 +01:00
|
|
|
var seam_points : PoolVector3Array = MDRMeshUtils.seams_to_points(_mdr)
|
2022-01-15 15:53:08 +01:00
|
|
|
|
2022-01-18 22:21:50 +01:00
|
|
|
var merged_arrays : Array = MeshUtils.remove_doubles(mdr_arr)
|
2022-01-15 15:53:08 +01:00
|
|
|
_mdr.array = merged_arrays
|
2022-01-18 22:21:50 +01:00
|
|
|
|
|
|
|
MDRMeshUtils.points_to_seams(_mdr, seam_points)
|
|
|
|
|
2022-01-19 01:46:33 +01:00
|
|
|
enable_change_event()
|
2022-01-15 15:53:08 +01:00
|
|
|
|
|
|
|
func merge_optimize():
|
|
|
|
if !_mdr:
|
|
|
|
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
|
|
|
|
|
2022-01-19 01:46:33 +01:00
|
|
|
disable_change_event()
|
|
|
|
|
2022-01-18 22:21:50 +01:00
|
|
|
var seam_points : PoolVector3Array = MDRMeshUtils.seams_to_points(_mdr)
|
2022-01-15 15:53:08 +01:00
|
|
|
|
2022-01-18 22:21:50 +01:00
|
|
|
var merged_arrays : Array = MeshUtils.merge_mesh_array(mdr_arr)
|
2022-01-15 15:53:08 +01:00
|
|
|
_mdr.array = merged_arrays
|
2022-01-18 22:21:50 +01:00
|
|
|
|
|
|
|
MDRMeshUtils.points_to_seams(_mdr, seam_points)
|
|
|
|
|
2022-01-19 01:46:33 +01:00
|
|
|
enable_change_event()
|
2022-01-18 22:21:50 +01:00
|
|
|
|
2022-01-15 16:13:09 +01:00
|
|
|
func onnect_to_first_selected():
|
|
|
|
if !_mdr:
|
|
|
|
return
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
var vertices : PoolVector3Array = mdr_arr[ArrayMesh.ARRAY_VERTEX]
|
|
|
|
|
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
|
|
|
var mpos : Vector3 = _handle_points[_selected_points[0]]
|
|
|
|
|
|
|
|
for i in range(1, _selected_points.size()):
|
|
|
|
var ps : PoolIntArray = _handle_to_vertex_map[_selected_points[i]]
|
|
|
|
|
|
|
|
for indx in ps:
|
|
|
|
vertices[indx] = mpos
|
|
|
|
|
|
|
|
_selected_points.resize(0)
|
|
|
|
|
|
|
|
mdr_arr[ArrayMesh.ARRAY_VERTEX] = vertices
|
|
|
|
_mdr.array = mdr_arr
|
|
|
|
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
|
|
|
pass
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
|
|
|
pass
|
2022-01-15 15:53:08 +01:00
|
|
|
|
2022-01-15 16:13:09 +01:00
|
|
|
func connect_to_avg():
|
|
|
|
if !_mdr:
|
|
|
|
return
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
var vertices : PoolVector3Array = mdr_arr[ArrayMesh.ARRAY_VERTEX]
|
|
|
|
|
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
|
|
|
var mpos : Vector3 = Vector3()
|
|
|
|
|
|
|
|
for sp in _selected_points:
|
|
|
|
mpos += _handle_points[sp]
|
|
|
|
|
|
|
|
mpos /= _selected_points.size()
|
|
|
|
|
|
|
|
for i in range(_selected_points.size()):
|
|
|
|
var ps : PoolIntArray = _handle_to_vertex_map[_selected_points[i]]
|
|
|
|
|
|
|
|
for indx in ps:
|
|
|
|
vertices[indx] = mpos
|
|
|
|
|
|
|
|
_selected_points.resize(0)
|
|
|
|
|
|
|
|
mdr_arr[ArrayMesh.ARRAY_VERTEX] = vertices
|
|
|
|
_mdr.array = mdr_arr
|
|
|
|
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
|
|
|
pass
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
|
|
|
pass
|
|
|
|
|
|
|
|
func connect_to_last_selected():
|
|
|
|
if !_mdr:
|
|
|
|
return
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
var vertices : PoolVector3Array = mdr_arr[ArrayMesh.ARRAY_VERTEX]
|
|
|
|
|
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
|
|
|
var mpos : Vector3 = _handle_points[_selected_points[_selected_points.size() - 1]]
|
|
|
|
|
|
|
|
for i in range(0, _selected_points.size() - 1):
|
|
|
|
var ps : PoolIntArray = _handle_to_vertex_map[_selected_points[i]]
|
|
|
|
|
|
|
|
for indx in ps:
|
|
|
|
vertices[indx] = mpos
|
|
|
|
|
|
|
|
_selected_points.resize(0)
|
|
|
|
|
|
|
|
mdr_arr[ArrayMesh.ARRAY_VERTEX] = vertices
|
|
|
|
_mdr.array = mdr_arr
|
|
|
|
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
|
|
|
pass
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
|
|
|
pass
|
2022-01-15 16:24:34 +01:00
|
|
|
|
2022-01-18 20:51:05 +01:00
|
|
|
func get_first_index_pair_for_edge(edge : int) -> PoolIntArray:
|
|
|
|
var ret : PoolIntArray = PoolIntArray()
|
|
|
|
|
|
|
|
var eisarr : Array = split_edge_indices(edge)
|
|
|
|
|
|
|
|
if eisarr.size() == 0:
|
|
|
|
return ret
|
|
|
|
|
|
|
|
# these should have the same size
|
|
|
|
var v0ei : PoolIntArray = eisarr[0]
|
|
|
|
var v1ei : PoolIntArray = eisarr[1]
|
|
|
|
|
|
|
|
var res : PoolIntArray = PoolIntArray()
|
|
|
|
|
|
|
|
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(v0ei, i0):
|
|
|
|
ret.push_back(i0)
|
|
|
|
elif pool_int_arr_contains(v0ei, i1):
|
|
|
|
ret.push_back(i1)
|
|
|
|
elif pool_int_arr_contains(v0ei, i2):
|
|
|
|
ret.push_back(i2)
|
|
|
|
|
|
|
|
if pool_int_arr_contains(v1ei, i0):
|
|
|
|
ret.push_back(i0)
|
|
|
|
elif pool_int_arr_contains(v1ei, i1):
|
|
|
|
ret.push_back(i1)
|
|
|
|
elif pool_int_arr_contains(v1ei, i2):
|
|
|
|
ret.push_back(i2)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
func get_all_index_pairs_for_edge(edge : int) -> PoolIntArray:
|
|
|
|
var ret : PoolIntArray = PoolIntArray()
|
|
|
|
|
|
|
|
var eisarr : Array = split_edge_indices(edge)
|
|
|
|
|
|
|
|
if eisarr.size() == 0:
|
|
|
|
return ret
|
|
|
|
|
|
|
|
# these should have the same size
|
|
|
|
var v0ei : PoolIntArray = eisarr[0]
|
|
|
|
var v1ei : PoolIntArray = eisarr[1]
|
|
|
|
|
|
|
|
var res : PoolIntArray = PoolIntArray()
|
|
|
|
|
|
|
|
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(v0ei, i0):
|
|
|
|
ret.push_back(i0)
|
|
|
|
elif pool_int_arr_contains(v0ei, i1):
|
|
|
|
ret.push_back(i1)
|
|
|
|
elif pool_int_arr_contains(v0ei, i2):
|
|
|
|
ret.push_back(i2)
|
|
|
|
|
|
|
|
if pool_int_arr_contains(v1ei, i0):
|
|
|
|
ret.push_back(i0)
|
|
|
|
elif pool_int_arr_contains(v1ei, i1):
|
|
|
|
ret.push_back(i1)
|
|
|
|
elif pool_int_arr_contains(v1ei, i2):
|
|
|
|
ret.push_back(i2)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
2022-01-15 16:24:34 +01:00
|
|
|
func mark_seam():
|
2022-01-18 20:51:05 +01:00
|
|
|
if !_mdr:
|
|
|
|
return
|
|
|
|
|
|
|
|
if _selected_points.size() == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
|
|
|
pass
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
2022-01-19 01:46:33 +01:00
|
|
|
disable_change_event()
|
2022-01-18 20:51:05 +01:00
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
var prev_seams : PoolIntArray = copy_pool_int_array(_mdr.seams)
|
|
|
|
|
2022-01-18 20:51:05 +01:00
|
|
|
for se in _selected_points:
|
2022-01-18 21:41:39 +01:00
|
|
|
var eis : PoolIntArray = MDRMeshUtils.order_seam_indices(get_first_index_pair_for_edge(se))
|
2022-01-18 20:51:05 +01:00
|
|
|
|
|
|
|
if eis.size() == 0:
|
|
|
|
continue
|
|
|
|
|
2022-01-18 21:41:39 +01:00
|
|
|
MDRMeshUtils.add_seam(_mdr, eis[0], eis[1])
|
2022-01-18 20:51:05 +01:00
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
_undo_redo.create_action("mark_seam")
|
|
|
|
_undo_redo.add_do_method(self, "set_seam", _mdr, copy_pool_int_array(_mdr.seams))
|
|
|
|
_undo_redo.add_undo_method(self, "set_seam", _mdr, prev_seams)
|
|
|
|
_undo_redo.commit_action()
|
|
|
|
|
2022-01-19 01:46:33 +01:00
|
|
|
enable_change_event()
|
2022-01-18 20:51:05 +01:00
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
|
|
|
pass
|
2022-01-20 21:48:21 +01:00
|
|
|
|
2022-01-15 16:24:34 +01:00
|
|
|
func unmark_seam():
|
2022-01-18 20:51:05 +01:00
|
|
|
if !_mdr:
|
|
|
|
return
|
|
|
|
|
|
|
|
if _selected_points.size() == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
if selection_mode == SelectionMode.SELECTION_MODE_VERTEX:
|
|
|
|
pass
|
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_EDGE:
|
2022-01-19 01:46:33 +01:00
|
|
|
disable_change_event()
|
2022-01-18 20:51:05 +01:00
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
var prev_seams : PoolIntArray = copy_pool_int_array(_mdr.seams)
|
|
|
|
|
2022-01-18 20:51:05 +01:00
|
|
|
for se in _selected_points:
|
2022-01-18 21:41:39 +01:00
|
|
|
var eis : PoolIntArray = MDRMeshUtils.order_seam_indices(get_all_index_pairs_for_edge(se))
|
2022-01-18 20:51:05 +01:00
|
|
|
|
|
|
|
if eis.size() == 0:
|
|
|
|
continue
|
|
|
|
|
2022-01-18 21:41:39 +01:00
|
|
|
MDRMeshUtils.remove_seam(_mdr, eis[0], eis[1])
|
2022-01-18 20:51:05 +01:00
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
_undo_redo.create_action("mark_seam")
|
|
|
|
_undo_redo.add_do_method(self, "set_seam", _mdr, copy_pool_int_array(_mdr.seams))
|
|
|
|
_undo_redo.add_undo_method(self, "set_seam", _mdr, prev_seams)
|
|
|
|
_undo_redo.commit_action()
|
|
|
|
|
2022-01-19 01:46:33 +01:00
|
|
|
enable_change_event()
|
2022-01-18 20:51:05 +01:00
|
|
|
elif selection_mode == SelectionMode.SELECTION_MODE_FACE:
|
|
|
|
pass
|
2022-01-18 22:24:22 +01:00
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
func set_seam(mdr : MeshDataResource, arr : PoolIntArray) -> void:
|
|
|
|
mdr.seams = arr
|
|
|
|
|
2022-01-18 22:24:22 +01:00
|
|
|
func apply_seam():
|
2022-01-18 23:02:26 +01:00
|
|
|
if !_mdr:
|
|
|
|
return
|
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
disable_change_event()
|
2022-01-18 23:02:26 +01:00
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
var orig_arr : Array = copy_arrays(_mdr.array)
|
2022-01-18 23:02:26 +01:00
|
|
|
MDRMeshUtils.apply_seam(_mdr)
|
2022-01-20 21:48:21 +01:00
|
|
|
add_mesh_change_undo_redo(orig_arr, _mdr.array, "apply_seam")
|
2022-01-18 23:02:26 +01:00
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
enable_change_event()
|
2022-01-19 00:17:39 +01:00
|
|
|
|
|
|
|
func uv_unwrap() -> void:
|
|
|
|
if !_mdr:
|
|
|
|
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
|
2022-01-20 21:48:21 +01:00
|
|
|
|
|
|
|
disable_change_event()
|
2022-01-19 00:17:39 +01:00
|
|
|
|
2022-01-19 01:01:32 +01:00
|
|
|
var uvs : PoolVector2Array = MeshUtils.uv_unwrap(mdr_arr)
|
2022-01-19 00:17:39 +01:00
|
|
|
|
2022-01-19 01:01:32 +01:00
|
|
|
if uvs.size() != mdr_arr[ArrayMesh.ARRAY_VERTEX].size():
|
2022-01-19 00:17:39 +01:00
|
|
|
print("Error: Could not unwrap mesh!")
|
|
|
|
return
|
2022-01-20 21:48:21 +01:00
|
|
|
|
|
|
|
var orig_arr : Array = copy_arrays(mdr_arr)
|
2022-01-19 00:17:39 +01:00
|
|
|
|
2022-01-19 01:01:32 +01:00
|
|
|
mdr_arr[ArrayMesh.ARRAY_TEX_UV] = uvs
|
2022-01-20 21:48:21 +01:00
|
|
|
|
|
|
|
add_mesh_change_undo_redo(orig_arr, mdr_arr, "uv_unwrap")
|
|
|
|
enable_change_event()
|
|
|
|
|
|
|
|
func add_mesh_change_undo_redo(orig_arr : Array, new_arr : Array, action_name : String) -> void:
|
|
|
|
_undo_redo.create_action(action_name)
|
|
|
|
var nac : Array = copy_arrays(new_arr)
|
|
|
|
_undo_redo.add_do_method(self, "apply_mesh_change", _mdr, nac)
|
|
|
|
_undo_redo.add_undo_method(self, "apply_mesh_change", _mdr, orig_arr)
|
|
|
|
_undo_redo.commit_action()
|
|
|
|
|
|
|
|
func apply_mesh_change(mdr : MeshDataResource, arr : Array) -> void:
|
|
|
|
if !mdr:
|
|
|
|
return
|
|
|
|
|
|
|
|
mdr.array = copy_arrays(arr)
|
|
|
|
|
2022-01-20 23:06:01 +01:00
|
|
|
func apply_vertex_array(mdr : MeshDataResource, verts : PoolVector3Array) -> void:
|
|
|
|
if !mdr:
|
|
|
|
return
|
|
|
|
|
|
|
|
var mdr_arr : Array = mdr.array
|
|
|
|
|
|
|
|
if mdr_arr.size() != ArrayMesh.ARRAY_MAX:
|
|
|
|
return
|
|
|
|
|
|
|
|
mdr_arr[ArrayMesh.ARRAY_VERTEX] = verts
|
|
|
|
mdr.array = mdr_arr
|
|
|
|
|
2022-01-20 21:48:21 +01:00
|
|
|
func copy_arrays(arr : Array) -> Array:
|
|
|
|
return arr.duplicate(true)
|
|
|
|
|
|
|
|
func copy_pool_int_array(pia : PoolIntArray) -> PoolIntArray:
|
|
|
|
var ret : PoolIntArray = PoolIntArray()
|
|
|
|
ret.resize(pia.size())
|
|
|
|
|
|
|
|
for i in range(pia.size()):
|
|
|
|
ret[i] = pia[i]
|
|
|
|
|
|
|
|
return ret
|
2022-01-20 23:06:01 +01:00
|
|
|
|
|
|
|
func copy_mdr_verts_array() -> PoolVector3Array:
|
|
|
|
var ret : PoolVector3Array = PoolVector3Array()
|
|
|
|
|
|
|
|
if !_mdr:
|
|
|
|
return ret
|
|
|
|
|
|
|
|
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 ret
|
|
|
|
|
|
|
|
var vertices : PoolVector3Array = mdr_arr[ArrayMesh.ARRAY_VERTEX]
|
|
|
|
ret.append_array(vertices)
|
|
|
|
|
|
|
|
return ret
|