mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-27 19:39:19 +01:00
Initial skeleton conversion of mdr_ed_mesh_utils.
This commit is contained in:
parent
200b4b0405
commit
d3118e1d4b
@ -1,18 +0,0 @@
|
|||||||
tool
|
|
||||||
extends PanelContainer
|
|
||||||
|
|
||||||
func set_plugin(plugin : EditorPlugin) -> void:
|
|
||||||
$ScrollContainer/MarginContainer/RectView.set_plugin(plugin)
|
|
||||||
|
|
||||||
func set_mesh_data_resource(a : MeshDataResource) -> void:
|
|
||||||
$ScrollContainer/MarginContainer/RectView.set_mesh_data_resource(a)
|
|
||||||
|
|
||||||
func set_mesh_data_instance(a : MeshDataInstance) -> void:
|
|
||||||
$ScrollContainer/MarginContainer/RectView.set_mesh_data_instance(a)
|
|
||||||
|
|
||||||
func ok_pressed() -> void:
|
|
||||||
$ScrollContainer/MarginContainer/RectView.ok_pressed()
|
|
||||||
|
|
||||||
func cancel_pressed() -> void:
|
|
||||||
$ScrollContainer/MarginContainer/RectView.cancel_pressed()
|
|
||||||
|
|
@ -1,250 +0,0 @@
|
|||||||
tool
|
|
||||||
extends Control
|
|
||||||
|
|
||||||
var MeshDecompose = preload("res://addons/mesh_data_resource_editor/utilities/mesh_decompose.gd")
|
|
||||||
|
|
||||||
var rect_editor_node_scene : PackedScene = preload("res://addons/mesh_data_resource_editor/uv_editor/RectViewNode.tscn")
|
|
||||||
|
|
||||||
export(NodePath) var zoom_widget_path : NodePath = ""
|
|
||||||
|
|
||||||
export(NodePath) var mirror_horizontal_button_path : NodePath = ""
|
|
||||||
export(NodePath) var mirror_vertical_button_path : NodePath = ""
|
|
||||||
|
|
||||||
export(NodePath) var rotate_left_button_path : NodePath = ""
|
|
||||||
export(NodePath) var rotate_amount_spinbox_path : NodePath = ""
|
|
||||||
export(NodePath) var rotate_right_button_path : NodePath = ""
|
|
||||||
|
|
||||||
var _rect_scale : float = 1
|
|
||||||
|
|
||||||
var _mdr : MeshDataResource = null
|
|
||||||
var _background_texture : Texture = null
|
|
||||||
|
|
||||||
var base_rect : Rect2 = Rect2(0, 0, 600, 600)
|
|
||||||
var edited_resource_current_size : Vector2 = Vector2()
|
|
||||||
|
|
||||||
var _stored_uvs : PoolVector2Array = PoolVector2Array()
|
|
||||||
|
|
||||||
var _plugin : EditorPlugin = null
|
|
||||||
var _undo_redo : UndoRedo = null
|
|
||||||
|
|
||||||
var selected_rect : Control = null
|
|
||||||
|
|
||||||
var rotation_amount : float = 45
|
|
||||||
|
|
||||||
func _enter_tree():
|
|
||||||
var zoom_widget : Node = get_node_or_null(zoom_widget_path)
|
|
||||||
|
|
||||||
if zoom_widget && !zoom_widget.is_connected("zoom_changed", self, "on_zoom_changed"):
|
|
||||||
zoom_widget.connect("zoom_changed", self, "on_zoom_changed")
|
|
||||||
|
|
||||||
var mirror_horizontal_button : Button = get_node_or_null(mirror_horizontal_button_path)
|
|
||||||
if mirror_horizontal_button && !mirror_horizontal_button.is_connected("pressed", self, "on_mirror_horizontal_button_pressed"):
|
|
||||||
mirror_horizontal_button.connect("pressed", self, "on_mirror_horizontal_button_pressed")
|
|
||||||
|
|
||||||
var mirror_vertical_button : Button = get_node_or_null(mirror_vertical_button_path)
|
|
||||||
if mirror_vertical_button && !mirror_vertical_button.is_connected("pressed", self, "on_mirror_vertical_button_pressed"):
|
|
||||||
mirror_vertical_button.connect("pressed", self, "on_mirror_vertical_button_pressed")
|
|
||||||
|
|
||||||
var rotate_left_button : Button = get_node_or_null(rotate_left_button_path)
|
|
||||||
if rotate_left_button && !rotate_left_button.is_connected("pressed", self, "on_rotate_left_button_button_pressed"):
|
|
||||||
rotate_left_button.connect("pressed", self, "on_rotate_left_button_button_pressed")
|
|
||||||
|
|
||||||
var rotate_amount_spinbox : SpinBox = get_node_or_null(rotate_amount_spinbox_path)
|
|
||||||
if rotate_amount_spinbox:
|
|
||||||
rotation_amount = rotate_amount_spinbox.value
|
|
||||||
if !rotate_amount_spinbox.is_connected("value_changed", self, "on_rotate_amount_spinbox_changed"):
|
|
||||||
rotate_amount_spinbox.connect("value_changed", self, "on_rotate_amount_spinbox_changed")
|
|
||||||
|
|
||||||
var rotate_right_button : Button = get_node_or_null(rotate_right_button_path)
|
|
||||||
if rotate_right_button && !rotate_right_button.is_connected("pressed", self, "on_rotate_right_button_button_pressed"):
|
|
||||||
rotate_right_button.connect("pressed", self, "on_rotate_right_button_button_pressed")
|
|
||||||
|
|
||||||
if !is_connected("visibility_changed", self, "on_visibility_changed"):
|
|
||||||
connect("visibility_changed", self, "on_visibility_changed")
|
|
||||||
|
|
||||||
func on_mirror_horizontal_button_pressed() -> void:
|
|
||||||
if selected_rect && is_instance_valid(selected_rect):
|
|
||||||
selected_rect.mirror_horizontal()
|
|
||||||
|
|
||||||
func on_mirror_vertical_button_pressed() -> void:
|
|
||||||
if selected_rect && is_instance_valid(selected_rect):
|
|
||||||
selected_rect.mirror_vertical()
|
|
||||||
|
|
||||||
func on_rotate_left_button_button_pressed() -> void:
|
|
||||||
if selected_rect && is_instance_valid(selected_rect):
|
|
||||||
selected_rect.rotate_uvs(-rotation_amount)
|
|
||||||
|
|
||||||
func on_rotate_amount_spinbox_changed(val : float) -> void:
|
|
||||||
rotation_amount = val
|
|
||||||
|
|
||||||
func on_rotate_right_button_button_pressed() -> void:
|
|
||||||
if selected_rect && is_instance_valid(selected_rect):
|
|
||||||
selected_rect.rotate_uvs(rotation_amount)
|
|
||||||
|
|
||||||
func set_plugin(plugin : EditorPlugin) -> void:
|
|
||||||
_plugin = plugin
|
|
||||||
|
|
||||||
_undo_redo = _plugin.get_undo_redo()
|
|
||||||
|
|
||||||
func on_visibility_changed() -> void:
|
|
||||||
if is_visible_in_tree():
|
|
||||||
store_uvs()
|
|
||||||
call_deferred("refresh")
|
|
||||||
|
|
||||||
func apply_zoom() -> void:
|
|
||||||
var rect : Rect2 = base_rect
|
|
||||||
edited_resource_current_size = rect.size
|
|
||||||
rect.position = rect.position * _rect_scale
|
|
||||||
rect.size = rect.size * _rect_scale
|
|
||||||
set_custom_minimum_size(rect.size)
|
|
||||||
|
|
||||||
var p : MarginContainer = get_parent() as MarginContainer
|
|
||||||
|
|
||||||
p.add_constant_override("margin_left", min(rect.size.x / 4.0, 50 * _rect_scale))
|
|
||||||
p.add_constant_override("margin_right", min(rect.size.x / 4.0, 50 * _rect_scale))
|
|
||||||
p.add_constant_override("margin_top", min(rect.size.y / 4.0, 50 * _rect_scale))
|
|
||||||
p.add_constant_override("margin_bottom", min(rect.size.y / 4.0, 50 * _rect_scale))
|
|
||||||
|
|
||||||
for c in get_children():
|
|
||||||
c.set_editor_rect_scale(_rect_scale)
|
|
||||||
|
|
||||||
func on_zoom_changed(zoom : float) -> void:
|
|
||||||
_rect_scale = zoom
|
|
||||||
apply_zoom()
|
|
||||||
|
|
||||||
func _draw():
|
|
||||||
draw_rect(Rect2(Vector2(), get_size()), Color(0.2, 0.2, 0.2, 1))
|
|
||||||
|
|
||||||
if _background_texture:
|
|
||||||
draw_texture_rect_region(_background_texture, Rect2(Vector2(), get_size()), Rect2(Vector2(), _background_texture.get_size()))
|
|
||||||
|
|
||||||
func refresh() -> void:
|
|
||||||
clear()
|
|
||||||
|
|
||||||
var rect : Rect2 = base_rect
|
|
||||||
edited_resource_current_size = rect.size
|
|
||||||
rect.position = rect.position * _rect_scale
|
|
||||||
rect.size = rect.size * _rect_scale
|
|
||||||
set_custom_minimum_size(rect.size)
|
|
||||||
|
|
||||||
apply_zoom()
|
|
||||||
|
|
||||||
refresh_rects()
|
|
||||||
|
|
||||||
func clear() -> void:
|
|
||||||
pass
|
|
||||||
|
|
||||||
func refresh_rects() -> void:
|
|
||||||
clear_rects()
|
|
||||||
|
|
||||||
if !_mdr:
|
|
||||||
return
|
|
||||||
|
|
||||||
var partitions : Array = MeshDecompose.partition_mesh(_mdr)
|
|
||||||
|
|
||||||
for p in partitions:
|
|
||||||
var s : Node = rect_editor_node_scene.instance()
|
|
||||||
|
|
||||||
add_child(s)
|
|
||||||
s.set_editor_rect_scale(_rect_scale)
|
|
||||||
s.edited_resource_parent_size = edited_resource_current_size
|
|
||||||
s.set_edited_resource(_mdr, p)
|
|
||||||
|
|
||||||
func clear_rects():
|
|
||||||
for c in get_children():
|
|
||||||
c.queue_free()
|
|
||||||
remove_child(c)
|
|
||||||
|
|
||||||
func set_mesh_data_resource(a : MeshDataResource) -> void:
|
|
||||||
_mdr = a
|
|
||||||
|
|
||||||
func set_mesh_data_instance(a : MeshDataInstance) -> void:
|
|
||||||
_background_texture = null
|
|
||||||
|
|
||||||
if a:
|
|
||||||
_background_texture = a.texture
|
|
||||||
|
|
||||||
func on_edited_resource_changed() -> void:
|
|
||||||
call_deferred("refresh")
|
|
||||||
|
|
||||||
func get_uvs(mdr : MeshDataResource) -> PoolVector2Array:
|
|
||||||
if !_mdr:
|
|
||||||
return PoolVector2Array()
|
|
||||||
|
|
||||||
var arrays : Array = _mdr.get_array()
|
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
|
||||||
return PoolVector2Array()
|
|
||||||
|
|
||||||
if arrays[ArrayMesh.ARRAY_TEX_UV] == null:
|
|
||||||
return PoolVector2Array()
|
|
||||||
|
|
||||||
return arrays[ArrayMesh.ARRAY_TEX_UV]
|
|
||||||
|
|
||||||
func store_uvs() -> void:
|
|
||||||
_stored_uvs.resize(0)
|
|
||||||
|
|
||||||
if !_mdr:
|
|
||||||
return
|
|
||||||
|
|
||||||
var arrays : Array = _mdr.get_array()
|
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
|
||||||
return
|
|
||||||
|
|
||||||
if arrays[ArrayMesh.ARRAY_TEX_UV] == null:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Make sure it gets copied
|
|
||||||
_stored_uvs.append_array(arrays[ArrayMesh.ARRAY_TEX_UV])
|
|
||||||
|
|
||||||
func apply_uvs(mdr : MeshDataResource, stored_uvs : PoolVector2Array) -> void:
|
|
||||||
if !_mdr:
|
|
||||||
return
|
|
||||||
|
|
||||||
var arrays : Array = _mdr.get_array()
|
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
|
||||||
return
|
|
||||||
|
|
||||||
if arrays[ArrayMesh.ARRAY_TEX_UV] == null:
|
|
||||||
return
|
|
||||||
|
|
||||||
arrays[ArrayMesh.ARRAY_TEX_UV] = stored_uvs
|
|
||||||
|
|
||||||
_mdr.array = arrays
|
|
||||||
|
|
||||||
func ok_pressed() -> void:
|
|
||||||
_undo_redo.create_action("UV Editor Accept")
|
|
||||||
_undo_redo.add_do_method(self, "apply_uvs", _mdr, get_uvs(_mdr))
|
|
||||||
_undo_redo.add_undo_method(self, "apply_uvs", _mdr, _stored_uvs)
|
|
||||||
_undo_redo.commit_action()
|
|
||||||
|
|
||||||
func cancel_pressed() -> void:
|
|
||||||
if !_mdr:
|
|
||||||
return
|
|
||||||
|
|
||||||
var arrays : Array = _mdr.get_array()
|
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Make sure it gets copied
|
|
||||||
var uvs : PoolVector2Array = PoolVector2Array()
|
|
||||||
uvs.append_array(_stored_uvs)
|
|
||||||
|
|
||||||
_undo_redo.create_action("UV Editor Cancel")
|
|
||||||
_undo_redo.add_do_method(self, "apply_uvs", _mdr, uvs)
|
|
||||||
_undo_redo.add_undo_method(self, "apply_uvs", _mdr, get_uvs(_mdr))
|
|
||||||
_undo_redo.commit_action()
|
|
||||||
|
|
||||||
_stored_uvs.resize(0)
|
|
||||||
|
|
||||||
func set_selected(node : Control) -> void:
|
|
||||||
if selected_rect && is_instance_valid(selected_rect):
|
|
||||||
selected_rect.set_selected(false)
|
|
||||||
|
|
||||||
selected_rect = node
|
|
||||||
|
|
||||||
if selected_rect:
|
|
||||||
selected_rect.set_selected(true)
|
|
@ -1,418 +0,0 @@
|
|||||||
tool
|
|
||||||
extends MarginContainer
|
|
||||||
|
|
||||||
enum DragType {
|
|
||||||
DRAG_NONE = 0,
|
|
||||||
DRAG_MOVE = 1,
|
|
||||||
DRAG_RESIZE_TOP = 1 << 1,
|
|
||||||
DRAG_RESIZE_RIGHT = 1 << 2,
|
|
||||||
DRAG_RESIZE_BOTTOM = 1 << 3,
|
|
||||||
DRAG_RESIZE_LEFT = 1 << 4
|
|
||||||
};
|
|
||||||
|
|
||||||
var selected : bool = false
|
|
||||||
|
|
||||||
var _mdr : MeshDataResource = null
|
|
||||||
var _indices : PoolIntArray = PoolIntArray()
|
|
||||||
var _uvs : PoolVector2Array = PoolVector2Array()
|
|
||||||
var _base_rect : Rect2 = Rect2(0, 0, 100, 100)
|
|
||||||
var _uv_min : Vector2 = Vector2()
|
|
||||||
var _uv_max : Vector2 = Vector2()
|
|
||||||
|
|
||||||
var edited_resource_parent_size : Vector2 = Vector2()
|
|
||||||
|
|
||||||
var _edited_resource_rect_border_color : Color = Color(0.8, 0.8, 0.8, 0.5)
|
|
||||||
var _edited_resource_rect_color : Color = Color(0.5, 0.5, 0.5, 0.2)
|
|
||||||
var _edited_resource_rect_selected_border_color : Color = Color(0.9, 0.9, 0.9, 0.8)
|
|
||||||
var _edited_resource_rect_selected_color : Color = Color(0.5, 0.5, 0.5, 0.4)
|
|
||||||
var _edited_resource_uv_mesh_color : Color = Color(1, 1, 1, 1)
|
|
||||||
var _editor_rect_border_size : int = 2
|
|
||||||
var _edited_resource_font_color : Color = Color(0, 0, 0, 1)
|
|
||||||
var _editor_additional_text : String = ""
|
|
||||||
|
|
||||||
var drag_type : int
|
|
||||||
var drag_offset : Vector2
|
|
||||||
var drag_offset_far : Vector2
|
|
||||||
|
|
||||||
var _rect_scale : float = 1
|
|
||||||
|
|
||||||
func _draw():
|
|
||||||
if selected:
|
|
||||||
draw_rect(Rect2(Vector2(), get_size()), _edited_resource_rect_selected_color)
|
|
||||||
draw_rect(Rect2(Vector2(), get_size()), _edited_resource_rect_selected_border_color, false, _editor_rect_border_size)
|
|
||||||
else:
|
|
||||||
draw_rect(Rect2(Vector2(), get_size()), _edited_resource_rect_color)
|
|
||||||
draw_rect(Rect2(Vector2(), get_size()), _edited_resource_rect_border_color, false, _editor_rect_border_size)
|
|
||||||
|
|
||||||
if _mdr && _uvs.size() > 0:
|
|
||||||
var c : Color = _edited_resource_uv_mesh_color
|
|
||||||
|
|
||||||
for i in range(0, len(_indices), 3):
|
|
||||||
draw_line(_uvs[_indices[i]] * get_size(), _uvs[_indices[i + 1]] * get_size(), c, 1, false)
|
|
||||||
draw_line(_uvs[_indices[i + 1]] * get_size(), _uvs[_indices[i + 2]] * get_size(), c, 1, false)
|
|
||||||
draw_line(_uvs[_indices[i + 2]] * get_size(), _uvs[_indices[i]] * get_size(), c, 1, false)
|
|
||||||
|
|
||||||
func mirror_horizontal() -> void:
|
|
||||||
var pia : PoolIntArray = PoolIntArray()
|
|
||||||
for index in _indices:
|
|
||||||
var found : bool = false
|
|
||||||
|
|
||||||
for i in pia:
|
|
||||||
if i == index:
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
|
|
||||||
if found:
|
|
||||||
continue
|
|
||||||
|
|
||||||
pia.append(index)
|
|
||||||
|
|
||||||
var uv : Vector2 = _uvs[index]
|
|
||||||
uv.x = 1.0 - uv.x
|
|
||||||
_uvs.set(index, uv)
|
|
||||||
|
|
||||||
apply_uv()
|
|
||||||
update()
|
|
||||||
|
|
||||||
func mirror_vertical() -> void:
|
|
||||||
var pia : PoolIntArray = PoolIntArray()
|
|
||||||
for index in _indices:
|
|
||||||
var found : bool = false
|
|
||||||
|
|
||||||
for i in pia:
|
|
||||||
if i == index:
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
|
|
||||||
if found:
|
|
||||||
continue
|
|
||||||
|
|
||||||
pia.append(index)
|
|
||||||
|
|
||||||
var uv : Vector2 = _uvs[index]
|
|
||||||
uv.y = 1.0 - uv.y
|
|
||||||
_uvs.set(index, uv)
|
|
||||||
|
|
||||||
apply_uv()
|
|
||||||
update()
|
|
||||||
|
|
||||||
func rotate_uvs(amount : float) -> void:
|
|
||||||
var t : Transform2D = Transform2D(deg2rad(amount), Vector2())
|
|
||||||
|
|
||||||
var pia : PoolIntArray = PoolIntArray()
|
|
||||||
for index in _indices:
|
|
||||||
var found : bool = false
|
|
||||||
|
|
||||||
for i in pia:
|
|
||||||
if i == index:
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
|
|
||||||
if found:
|
|
||||||
continue
|
|
||||||
|
|
||||||
pia.append(index)
|
|
||||||
|
|
||||||
var uv : Vector2 = _uvs[index]
|
|
||||||
uv = t.xform(uv)
|
|
||||||
_uvs.set(index, uv)
|
|
||||||
|
|
||||||
|
|
||||||
re_normalize_uvs()
|
|
||||||
apply_uv()
|
|
||||||
update()
|
|
||||||
|
|
||||||
func refresh() -> void:
|
|
||||||
if !_mdr:
|
|
||||||
return
|
|
||||||
|
|
||||||
var rect : Rect2 = _base_rect
|
|
||||||
rect.position *= _rect_scale
|
|
||||||
rect.size *= _rect_scale
|
|
||||||
|
|
||||||
rect_position = rect.position
|
|
||||||
rect_size = rect.size
|
|
||||||
|
|
||||||
update()
|
|
||||||
|
|
||||||
func set_editor_rect_scale(rect_scale) -> void:
|
|
||||||
_rect_scale = rect_scale
|
|
||||||
|
|
||||||
refresh()
|
|
||||||
|
|
||||||
func set_edited_resource(mdr : MeshDataResource, indices : PoolIntArray):
|
|
||||||
_mdr = mdr
|
|
||||||
_indices = indices
|
|
||||||
_uvs.resize(0)
|
|
||||||
|
|
||||||
var arrays : Array = _mdr.get_array()
|
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
|
||||||
return
|
|
||||||
|
|
||||||
if arrays[ArrayMesh.ARRAY_TEX_UV] == null:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Make sure it gets copied
|
|
||||||
_uvs.append_array(arrays[ArrayMesh.ARRAY_TEX_UV])
|
|
||||||
|
|
||||||
set_up_base_rect()
|
|
||||||
|
|
||||||
refresh()
|
|
||||||
|
|
||||||
func set_up_base_rect() -> void:
|
|
||||||
_base_rect = Rect2()
|
|
||||||
|
|
||||||
if !_mdr:
|
|
||||||
return
|
|
||||||
|
|
||||||
if _uvs.size() == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
var vmin : Vector2 = _uvs[_indices[0]]
|
|
||||||
var vmax : Vector2 = vmin
|
|
||||||
for i in range(1, _indices.size()):
|
|
||||||
var uv : Vector2 = _uvs[_indices[i]]
|
|
||||||
|
|
||||||
if uv.x < vmin.x:
|
|
||||||
vmin.x = uv.x
|
|
||||||
|
|
||||||
if uv.x > vmax.x:
|
|
||||||
vmax.x = uv.x
|
|
||||||
|
|
||||||
if uv.y < vmin.y:
|
|
||||||
vmin.y = uv.y
|
|
||||||
|
|
||||||
if uv.y > vmax.y:
|
|
||||||
vmax.y = uv.y
|
|
||||||
|
|
||||||
_base_rect = Rect2(vmin.x, vmin.y, vmax.x - vmin.x, vmax.y - vmin.y)
|
|
||||||
_base_rect.position *= edited_resource_parent_size
|
|
||||||
_base_rect.size *= edited_resource_parent_size
|
|
||||||
|
|
||||||
_uv_min = vmin
|
|
||||||
_uv_max = vmax
|
|
||||||
|
|
||||||
normalize_uvs()
|
|
||||||
|
|
||||||
func re_normalize_uvs() -> void:
|
|
||||||
if _uvs.size() == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
var vmin : Vector2 = _uvs[_indices[0]]
|
|
||||||
var vmax : Vector2 = vmin
|
|
||||||
for i in range(1, _indices.size()):
|
|
||||||
var uv : Vector2 = _uvs[_indices[i]]
|
|
||||||
|
|
||||||
if uv.x < vmin.x:
|
|
||||||
vmin.x = uv.x
|
|
||||||
|
|
||||||
if uv.x > vmax.x:
|
|
||||||
vmax.x = uv.x
|
|
||||||
|
|
||||||
if uv.y < vmin.y:
|
|
||||||
vmin.y = uv.y
|
|
||||||
|
|
||||||
if uv.y > vmax.y:
|
|
||||||
vmax.y = uv.y
|
|
||||||
|
|
||||||
var xmm : float = vmax.x - vmin.x
|
|
||||||
var ymm : float = vmax.y - vmin.y
|
|
||||||
|
|
||||||
if xmm == 0:
|
|
||||||
xmm = 0.0000001
|
|
||||||
|
|
||||||
if ymm == 0:
|
|
||||||
ymm = 0.0000001
|
|
||||||
|
|
||||||
for i in range(_uvs.size()):
|
|
||||||
var uv : Vector2 = _uvs[i]
|
|
||||||
|
|
||||||
uv.x -= vmin.x
|
|
||||||
uv.x /= xmm
|
|
||||||
|
|
||||||
uv.y -= vmin.y
|
|
||||||
uv.y /= ymm
|
|
||||||
|
|
||||||
_uvs[i] = uv
|
|
||||||
|
|
||||||
func normalize_uvs() -> void:
|
|
||||||
var xmm : float = _uv_max.x - _uv_min.x
|
|
||||||
var ymm : float = _uv_max.y - _uv_min.y
|
|
||||||
|
|
||||||
if xmm == 0:
|
|
||||||
xmm = 0.0000001
|
|
||||||
|
|
||||||
if ymm == 0:
|
|
||||||
ymm = 0.0000001
|
|
||||||
|
|
||||||
for i in range(_uvs.size()):
|
|
||||||
var uv : Vector2 = _uvs[i]
|
|
||||||
|
|
||||||
uv.x -= _uv_min.x
|
|
||||||
uv.x /= xmm
|
|
||||||
|
|
||||||
uv.y -= _uv_min.y
|
|
||||||
uv.y /= ymm
|
|
||||||
|
|
||||||
_uvs[i] = uv
|
|
||||||
|
|
||||||
func apply_uv() -> void:
|
|
||||||
if !_mdr:
|
|
||||||
return
|
|
||||||
|
|
||||||
var rect : Rect2 = get_rect()
|
|
||||||
|
|
||||||
#rect needs to be converted back
|
|
||||||
rect.position /= _rect_scale
|
|
||||||
rect.size /= _rect_scale
|
|
||||||
rect.position /= edited_resource_parent_size
|
|
||||||
rect.size /= edited_resource_parent_size
|
|
||||||
|
|
||||||
var arrays : Array = _mdr.get_array()
|
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
|
||||||
return
|
|
||||||
|
|
||||||
if arrays[ArrayMesh.ARRAY_TEX_UV] == null:
|
|
||||||
return
|
|
||||||
|
|
||||||
var uvs : PoolVector2Array = arrays[ArrayMesh.ARRAY_TEX_UV]
|
|
||||||
|
|
||||||
for index in _indices:
|
|
||||||
var uv : Vector2 = _uvs[index]
|
|
||||||
|
|
||||||
uv = uv * rect.size + rect.position
|
|
||||||
|
|
||||||
uvs[index] = uv
|
|
||||||
|
|
||||||
_uv_min = rect.position
|
|
||||||
_uv_max = rect.position + rect.size
|
|
||||||
|
|
||||||
_base_rect = get_rect()
|
|
||||||
|
|
||||||
arrays[ArrayMesh.ARRAY_TEX_UV] = uvs
|
|
||||||
_mdr.array = arrays
|
|
||||||
|
|
||||||
|
|
||||||
#based on / ported from engine/scene/gui/dialogs.h and .cpp
|
|
||||||
func _notification(p_what : int) -> void:
|
|
||||||
if (p_what == NOTIFICATION_MOUSE_EXIT):
|
|
||||||
# Reset the mouse cursor when leaving the resizable window border.
|
|
||||||
if (_mdr && !drag_type):
|
|
||||||
if (get_default_cursor_shape() != CURSOR_ARROW):
|
|
||||||
set_default_cursor_shape(CURSOR_ARROW)
|
|
||||||
|
|
||||||
#based on / ported from engine/scene/gui/dialogs.h and .cpp
|
|
||||||
func _gui_input(p_event : InputEvent) -> void:
|
|
||||||
if (p_event is InputEventMouseButton) && (p_event.get_button_index() == BUTTON_LEFT):
|
|
||||||
var mb : InputEventMouseButton = p_event as InputEventMouseButton
|
|
||||||
|
|
||||||
if (mb.is_pressed()):
|
|
||||||
get_parent().set_selected(self)
|
|
||||||
|
|
||||||
# Begin a possible dragging operation.
|
|
||||||
drag_type = _drag_hit_test(Vector2(mb.get_position().x, mb.get_position().y))
|
|
||||||
|
|
||||||
if (drag_type != DragType.DRAG_NONE):
|
|
||||||
drag_offset = get_global_mouse_position() - get_position()
|
|
||||||
|
|
||||||
drag_offset_far = get_position() + get_size() - get_global_mouse_position()
|
|
||||||
|
|
||||||
elif (drag_type != DragType.DRAG_NONE && !mb.is_pressed()):
|
|
||||||
# End a dragging operation.
|
|
||||||
|
|
||||||
apply_uv()
|
|
||||||
|
|
||||||
drag_type = DragType.DRAG_NONE
|
|
||||||
|
|
||||||
if p_event is InputEventMouseMotion:
|
|
||||||
var mm : InputEventMouseMotion = p_event as InputEventMouseMotion
|
|
||||||
|
|
||||||
if (drag_type == DragType.DRAG_NONE):
|
|
||||||
# Update the cursor while moving along the borders.
|
|
||||||
var cursor = CURSOR_ARROW
|
|
||||||
|
|
||||||
var preview_drag_type : int = _drag_hit_test(Vector2(mm.get_position().x, mm.get_position().y))
|
|
||||||
|
|
||||||
var top_left : int = DragType.DRAG_RESIZE_TOP + DragType.DRAG_RESIZE_LEFT
|
|
||||||
var bottom_right : int = DragType.DRAG_RESIZE_BOTTOM + DragType.DRAG_RESIZE_RIGHT
|
|
||||||
var top_right : int = DragType.DRAG_RESIZE_TOP + DragType.DRAG_RESIZE_RIGHT
|
|
||||||
var bottom_left : int = DragType.DRAG_RESIZE_BOTTOM + DragType.DRAG_RESIZE_LEFT
|
|
||||||
|
|
||||||
match (preview_drag_type):
|
|
||||||
DragType.DRAG_RESIZE_TOP:
|
|
||||||
cursor = CURSOR_VSIZE
|
|
||||||
DragType.DRAG_RESIZE_BOTTOM:
|
|
||||||
cursor = CURSOR_VSIZE
|
|
||||||
DragType.DRAG_RESIZE_LEFT:
|
|
||||||
cursor = CURSOR_HSIZE
|
|
||||||
DragType.DRAG_RESIZE_RIGHT:
|
|
||||||
cursor = CURSOR_HSIZE
|
|
||||||
top_left:
|
|
||||||
cursor = CURSOR_FDIAGSIZE
|
|
||||||
bottom_right:
|
|
||||||
cursor = CURSOR_FDIAGSIZE
|
|
||||||
top_right:
|
|
||||||
cursor = CURSOR_BDIAGSIZE
|
|
||||||
bottom_left:
|
|
||||||
cursor = CURSOR_BDIAGSIZE
|
|
||||||
|
|
||||||
if (get_cursor_shape() != cursor):
|
|
||||||
set_default_cursor_shape(cursor);
|
|
||||||
|
|
||||||
else:
|
|
||||||
# Update while in a dragging operation.
|
|
||||||
var global_pos : Vector2 = get_global_mouse_position()
|
|
||||||
|
|
||||||
var rect : Rect2 = get_rect()
|
|
||||||
var min_size : Vector2 = get_combined_minimum_size()
|
|
||||||
|
|
||||||
if (drag_type == DragType.DRAG_MOVE):
|
|
||||||
rect.position = global_pos - drag_offset
|
|
||||||
else:
|
|
||||||
if (drag_type & DragType.DRAG_RESIZE_TOP):
|
|
||||||
var bottom : int = rect.position.y + rect.size.y
|
|
||||||
var max_y : int = bottom - min_size.y
|
|
||||||
rect.position.y = min(global_pos.y - drag_offset.y, max_y)
|
|
||||||
rect.size.y = bottom - rect.position.y
|
|
||||||
elif (drag_type & DragType.DRAG_RESIZE_BOTTOM):
|
|
||||||
rect.size.y = global_pos.y - rect.position.y + drag_offset_far.y
|
|
||||||
|
|
||||||
if (drag_type & DragType.DRAG_RESIZE_LEFT):
|
|
||||||
var right : int = rect.position.x + rect.size.x
|
|
||||||
var max_x : int = right - min_size.x
|
|
||||||
rect.position.x = min(global_pos.x - drag_offset.x, max_x)
|
|
||||||
rect.size.x = right - rect.position.x
|
|
||||||
elif (drag_type & DragType.DRAG_RESIZE_RIGHT):
|
|
||||||
rect.size.x = global_pos.x - rect.position.x + drag_offset_far.x
|
|
||||||
|
|
||||||
set_size(rect.size)
|
|
||||||
set_position(rect.position)
|
|
||||||
|
|
||||||
#based on / ported from engine/scene/gui/dialogs.h and .cpp
|
|
||||||
func _drag_hit_test(pos : Vector2) -> int:
|
|
||||||
var drag_type : int = DragType.DRAG_NONE
|
|
||||||
|
|
||||||
var scaleborder_size : int = 5 #get_constant("scaleborder_size", "WindowDialog")
|
|
||||||
|
|
||||||
var rect : Rect2 = get_rect()
|
|
||||||
|
|
||||||
if (pos.y < (scaleborder_size)):
|
|
||||||
drag_type = DragType.DRAG_RESIZE_TOP
|
|
||||||
elif (pos.y >= (rect.size.y - scaleborder_size)):
|
|
||||||
drag_type = DragType.DRAG_RESIZE_BOTTOM
|
|
||||||
|
|
||||||
if (pos.x < scaleborder_size):
|
|
||||||
drag_type |= DragType.DRAG_RESIZE_LEFT
|
|
||||||
elif (pos.x >= (rect.size.x - scaleborder_size)):
|
|
||||||
drag_type |= DragType.DRAG_RESIZE_RIGHT
|
|
||||||
|
|
||||||
if (drag_type == DragType.DRAG_NONE):
|
|
||||||
drag_type = DragType.DRAG_MOVE
|
|
||||||
|
|
||||||
return drag_type
|
|
||||||
|
|
||||||
func set_selected(val : bool) -> void:
|
|
||||||
selected = val
|
|
||||||
update()
|
|
@ -1,11 +0,0 @@
|
|||||||
[gd_scene load_steps=2 format=2]
|
|
||||||
|
|
||||||
[ext_resource path="res://addons/mesh_data_resource_editor/uv_editor/RectViewNode.gd" type="Script" id=1]
|
|
||||||
|
|
||||||
[node name="RectViewNode" type="MarginContainer"]
|
|
||||||
margin_right = 1024.0
|
|
||||||
margin_bottom = 600.0
|
|
||||||
script = ExtResource( 1 )
|
|
||||||
__meta__ = {
|
|
||||||
"_edit_use_anchors_": false
|
|
||||||
}
|
|
@ -1,121 +0,0 @@
|
|||||||
[gd_scene load_steps=8 format=2]
|
|
||||||
|
|
||||||
[ext_resource path="res://addons/mesh_data_resource_editor/uv_editor/RectEditor.gd" type="Script" id=1]
|
|
||||||
[ext_resource path="res://addons/mesh_data_resource_editor/widgets/EditorZoomWidget.tscn" type="PackedScene" id=2]
|
|
||||||
[ext_resource path="res://addons/mesh_data_resource_editor/uv_editor/RectView.gd" type="Script" id=3]
|
|
||||||
[ext_resource path="res://addons/mesh_data_resource_editor/icons/icon_v_mirror.png" type="Texture" id=4]
|
|
||||||
[ext_resource path="res://addons/mesh_data_resource_editor/icons/icon_h_mirror.png" type="Texture" id=5]
|
|
||||||
[ext_resource path="res://addons/mesh_data_resource_editor/icons/icon_rot_right.png" type="Texture" id=6]
|
|
||||||
[ext_resource path="res://addons/mesh_data_resource_editor/icons/icon_rot_left.png" type="Texture" id=7]
|
|
||||||
|
|
||||||
[node name="UVEditor" type="PanelContainer"]
|
|
||||||
anchor_right = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
script = ExtResource( 1 )
|
|
||||||
__meta__ = {
|
|
||||||
"_edit_use_anchors_": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[node name="ScrollContainer" type="ScrollContainer" parent="."]
|
|
||||||
margin_left = 7.0
|
|
||||||
margin_top = 7.0
|
|
||||||
margin_right = 1017.0
|
|
||||||
margin_bottom = 593.0
|
|
||||||
|
|
||||||
[node name="MarginContainer" type="MarginContainer" parent="ScrollContainer"]
|
|
||||||
margin_right = 700.0
|
|
||||||
margin_bottom = 700.0
|
|
||||||
custom_constants/margin_right = 50
|
|
||||||
custom_constants/margin_top = 50
|
|
||||||
custom_constants/margin_left = 50
|
|
||||||
custom_constants/margin_bottom = 50
|
|
||||||
|
|
||||||
[node name="RectView" type="Control" parent="ScrollContainer/MarginContainer"]
|
|
||||||
margin_left = 50.0
|
|
||||||
margin_top = 50.0
|
|
||||||
margin_right = 650.0
|
|
||||||
margin_bottom = 650.0
|
|
||||||
rect_min_size = Vector2( 600, 600 )
|
|
||||||
script = ExtResource( 3 )
|
|
||||||
zoom_widget_path = NodePath("../../../Control/HBoxContainer/EditorZoomWidget")
|
|
||||||
mirror_horizontal_button_path = NodePath("../../../Control/HBoxContainer/HorizontalMirror")
|
|
||||||
mirror_vertical_button_path = NodePath("../../../Control/HBoxContainer/VerticalMirror")
|
|
||||||
rotate_left_button_path = NodePath("../../../Control/HBoxContainer/RotLeft")
|
|
||||||
rotate_amount_spinbox_path = NodePath("../../../Control/HBoxContainer/SpinBox")
|
|
||||||
rotate_right_button_path = NodePath("../../../Control/HBoxContainer/RotRight")
|
|
||||||
|
|
||||||
[node name="Control" type="VBoxContainer" parent="."]
|
|
||||||
margin_left = 7.0
|
|
||||||
margin_top = 7.0
|
|
||||||
margin_right = 1017.0
|
|
||||||
margin_bottom = 593.0
|
|
||||||
mouse_filter = 2
|
|
||||||
size_flags_horizontal = 3
|
|
||||||
size_flags_vertical = 3
|
|
||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="Control"]
|
|
||||||
margin_right = 1010.0
|
|
||||||
margin_bottom = 24.0
|
|
||||||
mouse_filter = 2
|
|
||||||
size_flags_horizontal = 3
|
|
||||||
__meta__ = {
|
|
||||||
"_edit_use_anchors_": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[node name="EditorZoomWidget" parent="Control/HBoxContainer" instance=ExtResource( 2 )]
|
|
||||||
anchor_right = 0.0
|
|
||||||
anchor_bottom = 0.0
|
|
||||||
margin_right = 115.0
|
|
||||||
margin_bottom = 24.0
|
|
||||||
custom_constants/separation = -8
|
|
||||||
__meta__ = {
|
|
||||||
"_edit_use_anchors_": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[node name="VSeparator2" type="VSeparator" parent="Control/HBoxContainer"]
|
|
||||||
margin_left = 119.0
|
|
||||||
margin_right = 123.0
|
|
||||||
margin_bottom = 24.0
|
|
||||||
|
|
||||||
[node name="HorizontalMirror" type="Button" parent="Control/HBoxContainer"]
|
|
||||||
margin_left = 127.0
|
|
||||||
margin_right = 155.0
|
|
||||||
margin_bottom = 24.0
|
|
||||||
hint_tooltip = "Mirror the selected island horizontally.."
|
|
||||||
icon = ExtResource( 5 )
|
|
||||||
|
|
||||||
[node name="VerticalMirror" type="Button" parent="Control/HBoxContainer"]
|
|
||||||
margin_left = 159.0
|
|
||||||
margin_right = 187.0
|
|
||||||
margin_bottom = 24.0
|
|
||||||
hint_tooltip = "Mirror the selected island vertically."
|
|
||||||
icon = ExtResource( 4 )
|
|
||||||
|
|
||||||
[node name="VSeparator" type="VSeparator" parent="Control/HBoxContainer"]
|
|
||||||
margin_left = 191.0
|
|
||||||
margin_right = 195.0
|
|
||||||
margin_bottom = 24.0
|
|
||||||
|
|
||||||
[node name="RotLeft" type="Button" parent="Control/HBoxContainer"]
|
|
||||||
margin_left = 199.0
|
|
||||||
margin_right = 227.0
|
|
||||||
margin_bottom = 24.0
|
|
||||||
hint_tooltip = "Rotate left."
|
|
||||||
icon = ExtResource( 7 )
|
|
||||||
|
|
||||||
[node name="SpinBox" type="SpinBox" parent="Control/HBoxContainer"]
|
|
||||||
margin_left = 231.0
|
|
||||||
margin_right = 305.0
|
|
||||||
margin_bottom = 24.0
|
|
||||||
hint_tooltip = "Rotate amount in degrees."
|
|
||||||
max_value = 360.0
|
|
||||||
value = 45.0
|
|
||||||
allow_greater = true
|
|
||||||
allow_lesser = true
|
|
||||||
|
|
||||||
[node name="RotRight" type="Button" parent="Control/HBoxContainer"]
|
|
||||||
margin_left = 309.0
|
|
||||||
margin_right = 337.0
|
|
||||||
margin_bottom = 24.0
|
|
||||||
hint_tooltip = "Rotate right."
|
|
||||||
icon = ExtResource( 6 )
|
|
@ -1,15 +0,0 @@
|
|||||||
tool
|
|
||||||
extends ConfirmationDialog
|
|
||||||
|
|
||||||
func _enter_tree():
|
|
||||||
if !is_connected("confirmed", self, "on_ok_pressed"):
|
|
||||||
connect("confirmed", self, "on_ok_pressed")
|
|
||||||
|
|
||||||
if !get_cancel().is_connected("pressed", self, "on_cancel_pressed"):
|
|
||||||
get_cancel().connect("pressed", self, "on_cancel_pressed")
|
|
||||||
|
|
||||||
func on_ok_pressed() -> void:
|
|
||||||
$UVEditor.ok_pressed()
|
|
||||||
|
|
||||||
func on_cancel_pressed() -> void:
|
|
||||||
$UVEditor.cancel_pressed()
|
|
@ -1,7 +1,193 @@
|
|||||||
tool
|
/*
|
||||||
extends Object
|
Copyright (c) 2019-2022 Péter Magyar
|
||||||
|
|
||||||
static func remove_triangle(mdr : MeshDataResource, triangle_index : int) -> void:
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mdr_ed_mesh_utils.h"
|
||||||
|
|
||||||
|
int MDREDMeshUtils::SeamTriangleHelper::get_other_side_index(int index) {
|
||||||
|
/*
|
||||||
|
if side_index_1 == index:
|
||||||
|
return side_index_2
|
||||||
|
else:
|
||||||
|
return side_index_1
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
int MDREDMeshUtils::SeamTriangleHelper::get_side_index(int i) {
|
||||||
|
/*
|
||||||
|
if i == 1:
|
||||||
|
return side_index_1
|
||||||
|
else:
|
||||||
|
return side_index_2
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
int MDREDMeshUtils::SeamTriangleHelper::get_side_index_cut() {
|
||||||
|
/*
|
||||||
|
if side_index_1_cut && side_index_2_cut:
|
||||||
|
return 3
|
||||||
|
elif side_index_1_cut:
|
||||||
|
return 1
|
||||||
|
elif side_index_2_cut:
|
||||||
|
return 2
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
int MDREDMeshUtils::SeamTriangleHelper::get_opposite_side_index_cut() {
|
||||||
|
/*
|
||||||
|
if side_index_1_cut && side_index_2_cut:
|
||||||
|
return 3
|
||||||
|
elif side_index_1_cut:
|
||||||
|
return 2
|
||||||
|
elif side_index_2_cut:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
bool MDREDMeshUtils::SeamTriangleHelper::is_side_index_cut(int i) {
|
||||||
|
/*
|
||||||
|
if i == 1:
|
||||||
|
return side_index_1_cut
|
||||||
|
else:
|
||||||
|
return side_index_2_cut
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MDREDMeshUtils::SeamTriangleHelper::is_the_same(SeamTriangleHelper h) {
|
||||||
|
/*
|
||||||
|
return is_triangle(h.i0, h.i1, h.i2)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MDREDMeshUtils::SeamTriangleHelper::is_triangle(int pi0, int pi1, int pi2) {
|
||||||
|
/*
|
||||||
|
if pi0 == i0 || pi0 == i1 || pi0 == i2:
|
||||||
|
if pi1 == i0 || pi1 == i1 || pi1 == i2:
|
||||||
|
if pi2 == i0 || pi2 == i1 || pi2 == i2:
|
||||||
|
return true
|
||||||
|
|
||||||
|
return false
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
bool MDREDMeshUtils::SeamTriangleHelper::is_neighbour_to(int index) {
|
||||||
|
/*
|
||||||
|
return (side_index_1 == index) || (side_index_2 == index)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MDREDMeshUtils::SeamTriangleHelper::needs_to_be_cut_near(int index) {
|
||||||
|
/*
|
||||||
|
if (side_index_1 == index):
|
||||||
|
return side_index_1_cut
|
||||||
|
|
||||||
|
if (side_index_2 == index):
|
||||||
|
return side_index_2_cut
|
||||||
|
|
||||||
|
return false
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
bool MDREDMeshUtils::SeamTriangleHelper::has_cut() {
|
||||||
|
/*
|
||||||
|
return side_index_1_cut || side_index_2_cut
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
bool MDREDMeshUtils::SeamTriangleHelper::both_sides_need_cut() {
|
||||||
|
/*
|
||||||
|
return side_index_1_cut && side_index_2_cut
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void MDREDMeshUtils::SeamTriangleHelper::setup(int pi0, int pi1, int pi2, int porig_ind, int pindex_index, PoolIntArray seams) {
|
||||||
|
/*
|
||||||
|
processed = false
|
||||||
|
i0 = pi0
|
||||||
|
i1 = pi1
|
||||||
|
i2 = pi2
|
||||||
|
orig_index = porig_ind
|
||||||
|
index_index = pindex_index
|
||||||
|
|
||||||
|
if porig_ind == pi0:
|
||||||
|
side_index_1 = pi1
|
||||||
|
side_index_2 = pi2
|
||||||
|
elif porig_ind == pi1:
|
||||||
|
side_index_1 = pi0
|
||||||
|
side_index_2 = pi2
|
||||||
|
elif porig_ind == pi2:
|
||||||
|
side_index_1 = pi1
|
||||||
|
side_index_2 = pi0
|
||||||
|
|
||||||
|
determine_cuts(seams)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void MDREDMeshUtils::SeamTriangleHelper::determine_cuts(PoolIntArray seams) {
|
||||||
|
/*
|
||||||
|
if orig_index < side_index_1:
|
||||||
|
side_index_1_cut = check_cut(orig_index, side_index_1, seams)
|
||||||
|
else:
|
||||||
|
side_index_1_cut = check_cut(side_index_1, orig_index, seams)
|
||||||
|
|
||||||
|
if orig_index < side_index_2:
|
||||||
|
side_index_2_cut = check_cut(orig_index, side_index_2, seams)
|
||||||
|
else:
|
||||||
|
side_index_2_cut = check_cut(side_index_2, orig_index, seams)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
bool MDREDMeshUtils::SeamTriangleHelper::check_cut(int ind0, int ind1, PoolIntArray seams) {
|
||||||
|
/*
|
||||||
|
for stind in range(0, seams.size(), 2):
|
||||||
|
var si0 : int = seams[stind]
|
||||||
|
var si1 : int = seams[stind + 1]
|
||||||
|
|
||||||
|
if (si0 == ind0) && (si1 == ind1):
|
||||||
|
return true
|
||||||
|
|
||||||
|
return false
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
String MDREDMeshUtils::SeamTriangleHelper::_to_string() {
|
||||||
|
/*
|
||||||
|
return "[ TRI: " + str(i0) + ", " + str(i1) + ", " + str(i2) + " ]"
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
MDREDMeshUtils::SeamTriangleHelper::SeamTriangleHelper() {
|
||||||
|
i0 = 0;
|
||||||
|
i1 = 0;
|
||||||
|
i2 = 0;
|
||||||
|
orig_index = 0;
|
||||||
|
index_index = 0;
|
||||||
|
|
||||||
|
side_index_1 = 0;
|
||||||
|
side_index_2 = 0;
|
||||||
|
side_index_1_cut = false;
|
||||||
|
side_index_2_cut = false;
|
||||||
|
|
||||||
|
processed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MDREDMeshUtils::remove_triangle(Ref<MeshDataResource> mdr, int triangle_index) {
|
||||||
|
/*
|
||||||
if triangle_index < 0:
|
if triangle_index < 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -33,8 +219,10 @@ static func remove_triangle(mdr : MeshDataResource, triangle_index : int) -> voi
|
|||||||
arrays[ArrayMesh.ARRAY_INDEX] = indices
|
arrays[ArrayMesh.ARRAY_INDEX] = indices
|
||||||
|
|
||||||
mdr.set_array(arrays)
|
mdr.set_array(arrays)
|
||||||
|
*/
|
||||||
static func add_triangulated_mesh_from_points_delaunay(mdr : MeshDataResource, selected_points : PoolVector3Array, last_known_camera_facing : Vector3) -> bool:
|
}
|
||||||
|
bool MDREDMeshUtils::add_triangulated_mesh_from_points_delaunay(Ref<MeshDataResource> mdr, PoolVector3Array selected_points, Vector3 last_known_camera_facing) {
|
||||||
|
/*
|
||||||
if selected_points.size() < 3:
|
if selected_points.size() < 3:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
@ -108,8 +296,10 @@ static func add_triangulated_mesh_from_points_delaunay(mdr : MeshDataResource, s
|
|||||||
merge_in_surface_tool(mdr, st)
|
merge_in_surface_tool(mdr, st)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
*/
|
||||||
static func add_triangulated_mesh_from_points(mdr : MeshDataResource, selected_points : PoolVector3Array, last_known_camera_facing : Vector3) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::add_triangulated_mesh_from_points(Ref<MeshDataResource> mdr, PoolVector3Array selected_points, Vector3 last_known_camera_facing) {
|
||||||
|
/*
|
||||||
if selected_points.size() < 3:
|
if selected_points.size() < 3:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -149,14 +339,20 @@ static func add_triangulated_mesh_from_points(mdr : MeshDataResource, selected_p
|
|||||||
st.add_index(im3)
|
st.add_index(im3)
|
||||||
|
|
||||||
merge_in_surface_tool(mdr, st)
|
merge_in_surface_tool(mdr, st)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
# Appends a triangle to the mesh. It's created from miroring v2 to the ev0, and ev1 edge
|
// Appends a triangle to the mesh. It's created from miroring v2 to the ev0, and ev1 edge
|
||||||
static func append_triangle_to_tri_edge(mdr : MeshDataResource, ev0 : Vector3, ev1 : Vector3, v2 : Vector3) -> void:
|
void MDREDMeshUtils::append_triangle_to_tri_edge(Ref<MeshDataResource> mdr, Vector3 ev0, Vector3 ev1, Vector3 v2) {
|
||||||
|
/*
|
||||||
var vref : Vector3 = reflect_vertex(ev0, ev1, v2)
|
var vref : Vector3 = reflect_vertex(ev0, ev1, v2)
|
||||||
|
|
||||||
add_triangle_at(mdr, ev1, ev0, vref, false)
|
add_triangle_at(mdr, ev1, ev0, vref, false)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func add_triangle_at(mdr : MeshDataResource, v0 : Vector3, v1 : Vector3, v2 : Vector3, flip : bool = false) -> void:
|
void MDREDMeshUtils::add_triangle_at(Ref<MeshDataResource> mdr, Vector3 v0, Vector3 v1, Vector3 v2, bool flip = false) {
|
||||||
|
/*
|
||||||
var st : SurfaceTool = SurfaceTool.new()
|
var st : SurfaceTool = SurfaceTool.new()
|
||||||
|
|
||||||
st.begin(Mesh.PRIMITIVE_TRIANGLES)
|
st.begin(Mesh.PRIMITIVE_TRIANGLES)
|
||||||
@ -184,7 +380,11 @@ static func add_triangle_at(mdr : MeshDataResource, v0 : Vector3, v1 : Vector3,
|
|||||||
|
|
||||||
merge_in_surface_tool(mdr, st)
|
merge_in_surface_tool(mdr, st)
|
||||||
|
|
||||||
static func add_triangle(mdr : MeshDataResource) -> void:
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void MDREDMeshUtils::add_triangle(Ref<MeshDataResource> mdr) {
|
||||||
|
/*
|
||||||
var st : SurfaceTool = SurfaceTool.new()
|
var st : SurfaceTool = SurfaceTool.new()
|
||||||
|
|
||||||
st.begin(Mesh.PRIMITIVE_TRIANGLES)
|
st.begin(Mesh.PRIMITIVE_TRIANGLES)
|
||||||
@ -206,9 +406,12 @@ static func add_triangle(mdr : MeshDataResource) -> void:
|
|||||||
st.add_index(2)
|
st.add_index(2)
|
||||||
|
|
||||||
merge_in_surface_tool(mdr, st)
|
merge_in_surface_tool(mdr, st)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
# Appends a quad to the mesh. It's created to the opposite side of v2 to the ev0, and ev1 edge
|
// Appends a quad to the mesh. It's created to the opposite side of v2 to the ev0, and ev1 edge
|
||||||
static func append_quad_to_tri_edge(mdr : MeshDataResource, ev0 : Vector3, ev1 : Vector3, v2 : Vector3) -> void:
|
void MDREDMeshUtils::append_quad_to_tri_edge(Ref<MeshDataResource> mdr, Vector3 ev0, Vector3 ev1, Vector3 v2) {
|
||||||
|
/*
|
||||||
var vref : Vector3 = reflect_vertex(ev0, ev1, v2)
|
var vref : Vector3 = reflect_vertex(ev0, ev1, v2)
|
||||||
var vproj : Vector3 = (vref - ev0).project(ev1 - ev0)
|
var vproj : Vector3 = (vref - ev0).project(ev1 - ev0)
|
||||||
var eoffs : Vector3 = (vref - ev0) - vproj
|
var eoffs : Vector3 = (vref - ev0) - vproj
|
||||||
@ -219,8 +422,10 @@ static func append_quad_to_tri_edge(mdr : MeshDataResource, ev0 : Vector3, ev1 :
|
|||||||
var qv3 : Vector3 = ev1
|
var qv3 : Vector3 = ev1
|
||||||
|
|
||||||
add_quad_at(mdr, qv0, qv1, qv2, qv3, false)
|
add_quad_at(mdr, qv0, qv1, qv2, qv3, false)
|
||||||
|
*/
|
||||||
static func add_quad_at(mdr : MeshDataResource, v0 : Vector3, v1 : Vector3, v2 : Vector3, v3 : Vector3, flip : bool = false) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::add_quad_at(Ref<MeshDataResource> mdr, Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3, bool flip = false) {
|
||||||
|
/*
|
||||||
var st : SurfaceTool = SurfaceTool.new()
|
var st : SurfaceTool = SurfaceTool.new()
|
||||||
|
|
||||||
st.begin(Mesh.PRIMITIVE_TRIANGLES)
|
st.begin(Mesh.PRIMITIVE_TRIANGLES)
|
||||||
@ -260,7 +465,10 @@ static func add_quad_at(mdr : MeshDataResource, v0 : Vector3, v1 : Vector3, v2 :
|
|||||||
|
|
||||||
merge_in_surface_tool(mdr, st)
|
merge_in_surface_tool(mdr, st)
|
||||||
|
|
||||||
static func add_quad(mdr : MeshDataResource) -> void:
|
*/
|
||||||
|
}
|
||||||
|
void MDREDMeshUtils::add_quad(Ref<MeshDataResource> mdr) {
|
||||||
|
/*
|
||||||
var st : SurfaceTool = SurfaceTool.new()
|
var st : SurfaceTool = SurfaceTool.new()
|
||||||
|
|
||||||
var normal : Vector3 = get_face_normal(Vector3(-0.5, -0.5, 0), Vector3(-0.5, 0.5, 0), Vector3(0.5, 0.5, 0))
|
var normal : Vector3 = get_face_normal(Vector3(-0.5, -0.5, 0), Vector3(-0.5, 0.5, 0), Vector3(0.5, 0.5, 0))
|
||||||
@ -288,8 +496,10 @@ static func add_quad(mdr : MeshDataResource) -> void:
|
|||||||
st.add_index(0)
|
st.add_index(0)
|
||||||
|
|
||||||
merge_in_surface_tool(mdr, st)
|
merge_in_surface_tool(mdr, st)
|
||||||
|
*/
|
||||||
static func add_box(mdr : MeshDataResource) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::add_box(Ref<MeshDataResource> mdr) {
|
||||||
|
/*
|
||||||
var st : SurfaceTool = SurfaceTool.new()
|
var st : SurfaceTool = SurfaceTool.new()
|
||||||
|
|
||||||
var normal : Vector3 = Vector3()
|
var normal : Vector3 = Vector3()
|
||||||
@ -378,8 +588,10 @@ static func add_box(mdr : MeshDataResource) -> void:
|
|||||||
ind += 4
|
ind += 4
|
||||||
|
|
||||||
merge_in_surface_tool(mdr, st)
|
merge_in_surface_tool(mdr, st)
|
||||||
|
*/
|
||||||
static func merge_in_surface_tool(mdr : MeshDataResource, st : SurfaceTool, generate_normals_if_needed : bool = true, generate_tangents_if_needed : bool = true) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::merge_in_surface_tool(Ref<MeshDataResource> mdr, Ref<SurfaceTool> st, bool generate_normals_if_needed = true, bool generate_tangents_if_needed = true) {
|
||||||
|
/*
|
||||||
var arrays : Array = get_arrays_prepared(mdr)
|
var arrays : Array = get_arrays_prepared(mdr)
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
@ -393,8 +605,10 @@ static func merge_in_surface_tool(mdr : MeshDataResource, st : SurfaceTool, gene
|
|||||||
st.generate_tangents()
|
st.generate_tangents()
|
||||||
|
|
||||||
merge_in_arrays(mdr, st.commit_to_arrays())
|
merge_in_arrays(mdr, st.commit_to_arrays())
|
||||||
|
*/
|
||||||
static func merge_in_arrays(mdr : MeshDataResource, merge : Array) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::merge_in_arrays(Ref<MeshDataResource> mdr, Array merge) {
|
||||||
|
/*
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
@ -569,8 +783,10 @@ static func merge_in_arrays(mdr : MeshDataResource, merge : Array) -> void:
|
|||||||
arrays[ArrayMesh.ARRAY_INDEX] = indices
|
arrays[ArrayMesh.ARRAY_INDEX] = indices
|
||||||
|
|
||||||
mdr.set_array(arrays)
|
mdr.set_array(arrays)
|
||||||
|
*/
|
||||||
static func get_arrays_prepared(mdr : MeshDataResource) -> Array:
|
}
|
||||||
|
Array MDREDMeshUtils::get_arrays_prepared(Ref<MeshDataResource> mdr) {
|
||||||
|
/*
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
@ -582,55 +798,80 @@ static func get_arrays_prepared(mdr : MeshDataResource) -> Array:
|
|||||||
arrays[ArrayMesh.ARRAY_INDEX] = PoolIntArray()
|
arrays[ArrayMesh.ARRAY_INDEX] = PoolIntArray()
|
||||||
|
|
||||||
return arrays
|
return arrays
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
# There are probably better ways to do this
|
// There are probably better ways to do this
|
||||||
static func should_flip_reflected_triangle(v0 : Vector3, v1 : Vector3, v2 : Vector3) -> bool:
|
bool MDREDMeshUtils::should_flip_reflected_triangle(Vector3 v0, Vector3 v1, Vector3 v2) {
|
||||||
|
/*
|
||||||
var reflected : Vector3 = reflect_vertex(v0, v1, v2)
|
var reflected : Vector3 = reflect_vertex(v0, v1, v2)
|
||||||
var nn : Vector3 = get_face_normal(v0, v1, v2)
|
var nn : Vector3 = get_face_normal(v0, v1, v2)
|
||||||
|
|
||||||
return should_triangle_flip(v0, v1, reflected, nn)
|
return should_triangle_flip(v0, v1, reflected, nn)
|
||||||
|
*/
|
||||||
static func reflect_vertex(v0 : Vector3, v1 : Vector3, v2 : Vector3) -> Vector3:
|
}
|
||||||
|
Vector3 MDREDMeshUtils::reflect_vertex(Vector3 v0, Vector3 v1, Vector3 v2) {
|
||||||
|
/*
|
||||||
return (v2 - v0).reflect((v1 - v0).normalized()) + v0
|
return (v2 - v0).reflect((v1 - v0).normalized()) + v0
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func get_face_normal_arr_ti(verts : PoolVector3Array, indices : PoolIntArray, triangle_index : int, flipped : bool = false) -> Vector3:
|
Vector3 MDREDMeshUtils::get_face_normal_arr_ti(PoolVector3Array verts, PoolIntArray indices, int triangle_index, bool flipped = false) {
|
||||||
|
/*
|
||||||
return get_face_normal_arr(verts, indices, triangle_index * 3, flipped)
|
return get_face_normal_arr(verts, indices, triangle_index * 3, flipped)
|
||||||
|
*/
|
||||||
static func get_face_normal_arr(verts : PoolVector3Array, indices : PoolIntArray, index : int, flipped : bool = false) -> Vector3:
|
}
|
||||||
|
Vector3 MDREDMeshUtils::get_face_normal_arr(PoolVector3Array verts, PoolIntArray indices, int index, bool flipped = false) {
|
||||||
|
/*
|
||||||
var v0 : Vector3 = verts[indices[index]]
|
var v0 : Vector3 = verts[indices[index]]
|
||||||
var v1 : Vector3 = verts[indices[index + 1]]
|
var v1 : Vector3 = verts[indices[index + 1]]
|
||||||
var v2 : Vector3 = verts[indices[index + 2]]
|
var v2 : Vector3 = verts[indices[index + 2]]
|
||||||
|
|
||||||
return get_face_normal(v0, v1, v2, flipped)
|
return get_face_normal(v0, v1, v2, flipped)
|
||||||
|
*/
|
||||||
static func get_face_normal(v0 : Vector3, v1 : Vector3, v2 : Vector3, flipped : bool = false) -> Vector3:
|
}
|
||||||
|
Vector3 MDREDMeshUtils::get_face_normal(Vector3 v0, Vector3 v1, Vector3 v2, bool flipped = false) {
|
||||||
|
/*
|
||||||
if !flipped:
|
if !flipped:
|
||||||
return Plane(v0, v1, v2).normal
|
return Plane(v0, v1, v2).normal
|
||||||
else:
|
else:
|
||||||
return Plane(v2, v1, v0).normal
|
return Plane(v2, v1, v0).normal
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func should_triangle_flip(v0 : Vector3, v1 : Vector3, v2 : Vector3, similar_dir_normal : Vector3) -> bool:
|
bool MDREDMeshUtils::should_triangle_flip(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 similar_dir_normal) {
|
||||||
|
/*
|
||||||
var normal : Vector3 = get_face_normal(v0, v1, v2)
|
var normal : Vector3 = get_face_normal(v0, v1, v2)
|
||||||
|
|
||||||
var ndns : float = normal.dot(similar_dir_normal)
|
var ndns : float = normal.dot(similar_dir_normal)
|
||||||
|
|
||||||
return ndns < 0
|
return ndns < 0
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func is_normal_similar(v0 : Vector3, v1 : Vector3, v2 : Vector3, similar_dir_normal : Vector3) -> bool:
|
bool MDREDMeshUtils::is_normal_similar(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 similar_dir_normal) {
|
||||||
|
/*
|
||||||
var normal : Vector3 = get_face_normal(v0, v1, v2)
|
var normal : Vector3 = get_face_normal(v0, v1, v2)
|
||||||
|
|
||||||
var ndns : float = normal.dot(similar_dir_normal)
|
var ndns : float = normal.dot(similar_dir_normal)
|
||||||
|
|
||||||
return ndns >= 0
|
return ndns >= 0
|
||||||
|
*/
|
||||||
static func is_direction_similar(d0 : Vector3, d1 : Vector3) -> bool:
|
}
|
||||||
|
bool MDREDMeshUtils::is_direction_similar(Vector3 d0, Vector3 d1) {
|
||||||
|
/*
|
||||||
var ndns : float = d0.dot(d1)
|
var ndns : float = d0.dot(d1)
|
||||||
return ndns >= 0
|
return ndns >= 0
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func flip_triangle_ti(mdr : MeshDataResource, triangle_index : int) -> void:
|
void MDREDMeshUtils::flip_triangle_ti(Ref<MeshDataResource> mdr, int triangle_index) {
|
||||||
|
/*
|
||||||
flip_triangle(mdr, triangle_index * 3)
|
flip_triangle(mdr, triangle_index * 3)
|
||||||
|
*/
|
||||||
static func flip_triangle(mdr : MeshDataResource, index : int) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::flip_triangle(Ref<MeshDataResource> mdr, int index) {
|
||||||
|
/*
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
@ -650,8 +891,10 @@ static func flip_triangle(mdr : MeshDataResource, index : int) -> void:
|
|||||||
arrays[ArrayMesh.ARRAY_INDEX] = indices
|
arrays[ArrayMesh.ARRAY_INDEX] = indices
|
||||||
|
|
||||||
mdr.set_array(arrays)
|
mdr.set_array(arrays)
|
||||||
|
*/
|
||||||
static func add_into_surface_tool(mdr : MeshDataResource, st : SurfaceTool) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::add_into_surface_tool(Ref<MeshDataResource> mdr, Ref<SurfaceTool> st) {
|
||||||
|
/*
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
@ -739,8 +982,11 @@ static func add_into_surface_tool(mdr : MeshDataResource, st : SurfaceTool) -> v
|
|||||||
|
|
||||||
for ind in indices:
|
for ind in indices:
|
||||||
st.add_index(ind)
|
st.add_index(ind)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func generate_normals_arrs(arrays : Array) -> Array:
|
Array MDREDMeshUtils::generate_normals_arrs(Array arrays) {
|
||||||
|
/*
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
arrays.resize(ArrayMesh.ARRAY_MAX)
|
arrays.resize(ArrayMesh.ARRAY_MAX)
|
||||||
|
|
||||||
@ -797,9 +1043,10 @@ static func generate_normals_arrs(arrays : Array) -> Array:
|
|||||||
arrays[ArrayMesh.ARRAY_NORMAL] = normals
|
arrays[ArrayMesh.ARRAY_NORMAL] = normals
|
||||||
|
|
||||||
return arrays
|
return arrays
|
||||||
|
*/
|
||||||
|
}
|
||||||
static func generate_normals_mdr(mdr : MeshDataResource) -> void:
|
void MDREDMeshUtils::generate_normals_mdr(Ref<MeshDataResource> mdr) {
|
||||||
|
/*
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
@ -857,9 +1104,13 @@ static func generate_normals_mdr(mdr : MeshDataResource) -> void:
|
|||||||
arrays[ArrayMesh.ARRAY_NORMAL] = normals
|
arrays[ArrayMesh.ARRAY_NORMAL] = normals
|
||||||
mdr.array = arrays
|
mdr.array = arrays
|
||||||
|
|
||||||
# Apparently surfacetool adds more verts during normal generation
|
*/
|
||||||
# Keeping this here for now
|
}
|
||||||
static func generate_normals_surface_tool(mdr : MeshDataResource) -> void:
|
|
||||||
|
// Apparently surfacetool adds more verts during normal generation
|
||||||
|
// Keeping this here for now
|
||||||
|
void MDREDMeshUtils::generate_normals_surface_tool(Ref<MeshDataResource> mdr) {
|
||||||
|
/*
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
@ -876,8 +1127,10 @@ static func generate_normals_surface_tool(mdr : MeshDataResource) -> void:
|
|||||||
st.generate_normals()
|
st.generate_normals()
|
||||||
|
|
||||||
mdr.array = st.commit_to_arrays()
|
mdr.array = st.commit_to_arrays()
|
||||||
|
*/
|
||||||
static func generate_tangents(mdr : MeshDataResource) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::generate_tangents(Ref<MeshDataResource> mdr) {
|
||||||
|
/*
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
@ -894,8 +1147,11 @@ static func generate_tangents(mdr : MeshDataResource) -> void:
|
|||||||
st.generate_tangents()
|
st.generate_tangents()
|
||||||
|
|
||||||
mdr.array = st.commit_to_arrays()
|
mdr.array = st.commit_to_arrays()
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func remove_used_vertices(arrays : Array) -> Array:
|
Array MDREDMeshUtils::remove_used_vertices(Array arrays) {
|
||||||
|
/*
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
return arrays
|
return arrays
|
||||||
|
|
||||||
@ -913,9 +1169,11 @@ static func remove_used_vertices(arrays : Array) -> Array:
|
|||||||
remove_vertices(arrays, unused_indices)
|
remove_vertices(arrays, unused_indices)
|
||||||
|
|
||||||
return arrays
|
return arrays
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
Array MDREDMeshUtils::remove_vertices(Array arrays, PoolIntArray indices) {
|
||||||
static func remove_vertices(arrays : Array, indices : PoolIntArray) -> Array:
|
/*
|
||||||
if indices.size() == 0:
|
if indices.size() == 0:
|
||||||
return arrays
|
return arrays
|
||||||
|
|
||||||
@ -1029,8 +1287,11 @@ static func remove_vertices(arrays : Array, indices : PoolIntArray) -> Array:
|
|||||||
arrays[ArrayMesh.ARRAY_INDEX] = arr_indices
|
arrays[ArrayMesh.ARRAY_INDEX] = arr_indices
|
||||||
|
|
||||||
return arrays
|
return arrays
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func find_max(arr : PoolIntArray) -> int:
|
int MDREDMeshUtils::find_max(PoolIntArray arr) {
|
||||||
|
/*
|
||||||
var m : int = arr[0]
|
var m : int = arr[0]
|
||||||
|
|
||||||
for v in arr:
|
for v in arr:
|
||||||
@ -1038,8 +1299,10 @@ static func find_max(arr : PoolIntArray) -> int:
|
|||||||
m = v
|
m = v
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
*/
|
||||||
static func find_max_capped(arr : PoolIntArray, last : int) -> int:
|
}
|
||||||
|
int MDREDMeshUtils::find_max_capped(PoolIntArray arr, int last) {
|
||||||
|
/*
|
||||||
var m : int = 0
|
var m : int = 0
|
||||||
|
|
||||||
for v in arr:
|
for v in arr:
|
||||||
@ -1052,8 +1315,11 @@ static func find_max_capped(arr : PoolIntArray, last : int) -> int:
|
|||||||
m = v
|
m = v
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func order_seam_indices(arr : PoolIntArray) -> PoolIntArray:
|
PoolIntArray MDREDMeshUtils::order_seam_indices(PoolIntArray arr) {
|
||||||
|
/*
|
||||||
var ret : PoolIntArray = PoolIntArray()
|
var ret : PoolIntArray = PoolIntArray()
|
||||||
|
|
||||||
if arr.size() == 0:
|
if arr.size() == 0:
|
||||||
@ -1072,20 +1338,28 @@ static func order_seam_indices(arr : PoolIntArray) -> PoolIntArray:
|
|||||||
ret.push_back(index1)
|
ret.push_back(index1)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func add_seam_not_ordered(mdr : MeshDataResource, index0 : int, index1 : int) -> void:
|
void MDREDMeshUtils::add_seam_not_ordered(Ref<MeshDataResource> mdr, int index0, int index1) {
|
||||||
|
/*
|
||||||
if index0 > index1:
|
if index0 > index1:
|
||||||
add_seam(mdr, index1, index0)
|
add_seam(mdr, index1, index0)
|
||||||
else:
|
else:
|
||||||
add_seam(mdr, index0, index1)
|
add_seam(mdr, index0, index1)
|
||||||
|
*/
|
||||||
static func remove_seam_not_ordered(mdr : MeshDataResource, index0 : int, index1 : int) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::remove_seam_not_ordered(Ref<MeshDataResource> mdr, int index0, int index1) {
|
||||||
|
/*
|
||||||
if index0 > index1:
|
if index0 > index1:
|
||||||
remove_seam(mdr, index1, index0)
|
remove_seam(mdr, index1, index0)
|
||||||
else:
|
else:
|
||||||
remove_seam(mdr, index0, index1)
|
remove_seam(mdr, index0, index1)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func has_seam(mdr : MeshDataResource, index0 : int, index1 : int) -> bool:
|
bool MDREDMeshUtils::has_seam(Ref<MeshDataResource> mdr, int index0, int index1) {
|
||||||
|
/*
|
||||||
var seams : PoolIntArray = mdr.seams
|
var seams : PoolIntArray = mdr.seams
|
||||||
|
|
||||||
for i in range(0, seams.size(), 2):
|
for i in range(0, seams.size(), 2):
|
||||||
@ -1093,8 +1367,10 @@ static func has_seam(mdr : MeshDataResource, index0 : int, index1 : int) -> bool
|
|||||||
return true
|
return true
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
*/
|
||||||
static func add_seam(mdr : MeshDataResource, index0 : int, index1 : int) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::add_seam(Ref<MeshDataResource> mdr, int index0, int index1) {
|
||||||
|
/*
|
||||||
if has_seam(mdr, index0, index1):
|
if has_seam(mdr, index0, index1):
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1102,8 +1378,10 @@ static func add_seam(mdr : MeshDataResource, index0 : int, index1 : int) -> void
|
|||||||
seams.push_back(index0)
|
seams.push_back(index0)
|
||||||
seams.push_back(index1)
|
seams.push_back(index1)
|
||||||
mdr.seams = seams
|
mdr.seams = seams
|
||||||
|
*/
|
||||||
static func remove_seam(mdr : MeshDataResource, index0 : int, index1 : int) -> void:
|
}
|
||||||
|
void MDREDMeshUtils::remove_seam(Ref<MeshDataResource> mdr, int index0, int index1) {
|
||||||
|
/*
|
||||||
if !has_seam(mdr, index0, index1):
|
if !has_seam(mdr, index0, index1):
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1115,12 +1393,17 @@ static func remove_seam(mdr : MeshDataResource, index0 : int, index1 : int) -> v
|
|||||||
seams.remove(i)
|
seams.remove(i)
|
||||||
mdr.seams = seams
|
mdr.seams = seams
|
||||||
return
|
return
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func is_verts_equal(v0 : Vector3, v1 : Vector3) -> bool:
|
bool MDREDMeshUtils::is_verts_equal(Vector3 v0, Vector3 v1) {
|
||||||
|
/*
|
||||||
return is_equal_approx(v0.x, v1.x) && is_equal_approx(v0.y, v1.y) && is_equal_approx(v0.z, v1.z)
|
return is_equal_approx(v0.x, v1.x) && is_equal_approx(v0.y, v1.y) && is_equal_approx(v0.z, v1.z)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void MDREDMeshUtils::points_to_seams(Ref<MeshDataResource> mdr, PoolVector3Array points) {
|
||||||
static func points_to_seams(mdr : MeshDataResource, points : PoolVector3Array) -> void:
|
/*
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
|
|
||||||
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
if arrays.size() != ArrayMesh.ARRAY_MAX:
|
||||||
@ -1179,8 +1462,10 @@ static func points_to_seams(mdr : MeshDataResource, points : PoolVector3Array) -
|
|||||||
break
|
break
|
||||||
|
|
||||||
mdr.seams = seams
|
mdr.seams = seams
|
||||||
|
*/
|
||||||
static func seams_to_points(mdr : MeshDataResource) -> PoolVector3Array:
|
}
|
||||||
|
PoolVector3Array MDREDMeshUtils::seams_to_points(Ref<MeshDataResource> mdr) {
|
||||||
|
/*
|
||||||
var points : PoolVector3Array = PoolVector3Array()
|
var points : PoolVector3Array = PoolVector3Array()
|
||||||
|
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
@ -1198,149 +1483,31 @@ static func seams_to_points(mdr : MeshDataResource) -> PoolVector3Array:
|
|||||||
points.push_back(vertices[s])
|
points.push_back(vertices[s])
|
||||||
|
|
||||||
return points
|
return points
|
||||||
|
*/
|
||||||
static func is_matching_seam(i0 : int, i1: int, si0 : int, si1: int) -> bool:
|
}
|
||||||
|
bool MDREDMeshUtils::is_matching_seam(int i0, int i1, int si0, int si1) {
|
||||||
|
/*
|
||||||
if i0 > i1:
|
if i0 > i1:
|
||||||
var t : int = i0
|
var t : int = i0
|
||||||
i0 = i1
|
i0 = i1
|
||||||
i1 = t
|
i1 = t
|
||||||
|
|
||||||
return (i0 == si0) && (i1 == si1)
|
return (i0 == si0) && (i1 == si1)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
static func pool_int_arr_contains(arr : PoolIntArray, val : int) -> bool:
|
bool MDREDMeshUtils::pool_int_arr_contains(PoolIntArray arr, int val) {
|
||||||
|
/*
|
||||||
for a in arr:
|
for a in arr:
|
||||||
if a == val:
|
if a == val:
|
||||||
return true
|
return true
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void MDREDMeshUtils::apply_seam(Ref<MeshDataResource> mdr) {
|
||||||
class SeamTriangleHelper:
|
/*
|
||||||
var i0 : int = 0
|
|
||||||
var i1 : int = 0
|
|
||||||
var i2 : int = 0
|
|
||||||
var orig_index : int = 0
|
|
||||||
var index_index : int = 0
|
|
||||||
|
|
||||||
var side_index_1 : int = 0
|
|
||||||
var side_index_2 : int = 0
|
|
||||||
var side_index_1_cut : bool = false
|
|
||||||
var side_index_2_cut : bool = false
|
|
||||||
|
|
||||||
var processed : bool = false
|
|
||||||
|
|
||||||
func get_other_side_index(index : int) -> int:
|
|
||||||
if side_index_1 == index:
|
|
||||||
return side_index_2
|
|
||||||
else:
|
|
||||||
return side_index_1
|
|
||||||
|
|
||||||
func get_side_index(i : int) -> int:
|
|
||||||
if i == 1:
|
|
||||||
return side_index_1
|
|
||||||
else:
|
|
||||||
return side_index_2
|
|
||||||
|
|
||||||
func get_side_index_cut() -> int:
|
|
||||||
if side_index_1_cut && side_index_2_cut:
|
|
||||||
return 3
|
|
||||||
elif side_index_1_cut:
|
|
||||||
return 1
|
|
||||||
elif side_index_2_cut:
|
|
||||||
return 2
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
func get_opposite_side_index_cut() -> int:
|
|
||||||
if side_index_1_cut && side_index_2_cut:
|
|
||||||
return 3
|
|
||||||
elif side_index_1_cut:
|
|
||||||
return 2
|
|
||||||
elif side_index_2_cut:
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
func is_side_index_cut(i : int) -> bool:
|
|
||||||
if i == 1:
|
|
||||||
return side_index_1_cut
|
|
||||||
else:
|
|
||||||
return side_index_2_cut
|
|
||||||
|
|
||||||
func is_the_same(h : SeamTriangleHelper) -> bool:
|
|
||||||
return is_triangle(h.i0, h.i1, h.i2)
|
|
||||||
|
|
||||||
func is_triangle(pi0 : int, pi1 : int, pi2 : int) -> bool:
|
|
||||||
if pi0 == i0 || pi0 == i1 || pi0 == i2:
|
|
||||||
if pi1 == i0 || pi1 == i1 || pi1 == i2:
|
|
||||||
if pi2 == i0 || pi2 == i1 || pi2 == i2:
|
|
||||||
return true
|
|
||||||
|
|
||||||
return false
|
|
||||||
|
|
||||||
func is_neighbour_to(index : int) -> bool:
|
|
||||||
return (side_index_1 == index) || (side_index_2 == index)
|
|
||||||
|
|
||||||
func needs_to_be_cut_near(index : int) -> bool:
|
|
||||||
if (side_index_1 == index):
|
|
||||||
return side_index_1_cut
|
|
||||||
|
|
||||||
if (side_index_2 == index):
|
|
||||||
return side_index_2_cut
|
|
||||||
|
|
||||||
return false
|
|
||||||
|
|
||||||
func has_cut() -> bool:
|
|
||||||
return side_index_1_cut || side_index_2_cut
|
|
||||||
|
|
||||||
func both_sides_need_cut() -> bool:
|
|
||||||
return side_index_1_cut && side_index_2_cut
|
|
||||||
|
|
||||||
func setup(pi0 : int, pi1 : int, pi2 : int, porig_ind : int, pindex_index : int, seams : PoolIntArray) -> void:
|
|
||||||
processed = false
|
|
||||||
i0 = pi0
|
|
||||||
i1 = pi1
|
|
||||||
i2 = pi2
|
|
||||||
orig_index = porig_ind
|
|
||||||
index_index = pindex_index
|
|
||||||
|
|
||||||
if porig_ind == pi0:
|
|
||||||
side_index_1 = pi1
|
|
||||||
side_index_2 = pi2
|
|
||||||
elif porig_ind == pi1:
|
|
||||||
side_index_1 = pi0
|
|
||||||
side_index_2 = pi2
|
|
||||||
elif porig_ind == pi2:
|
|
||||||
side_index_1 = pi1
|
|
||||||
side_index_2 = pi0
|
|
||||||
|
|
||||||
determine_cuts(seams)
|
|
||||||
|
|
||||||
func determine_cuts(seams : PoolIntArray) -> void:
|
|
||||||
if orig_index < side_index_1:
|
|
||||||
side_index_1_cut = check_cut(orig_index, side_index_1, seams)
|
|
||||||
else:
|
|
||||||
side_index_1_cut = check_cut(side_index_1, orig_index, seams)
|
|
||||||
|
|
||||||
if orig_index < side_index_2:
|
|
||||||
side_index_2_cut = check_cut(orig_index, side_index_2, seams)
|
|
||||||
else:
|
|
||||||
side_index_2_cut = check_cut(side_index_2, orig_index, seams)
|
|
||||||
|
|
||||||
func check_cut(ind0 : int, ind1 : int, seams : PoolIntArray) -> bool:
|
|
||||||
for stind in range(0, seams.size(), 2):
|
|
||||||
var si0 : int = seams[stind]
|
|
||||||
var si1 : int = seams[stind + 1]
|
|
||||||
|
|
||||||
if (si0 == ind0) && (si1 == ind1):
|
|
||||||
return true
|
|
||||||
|
|
||||||
return false
|
|
||||||
|
|
||||||
func _to_string():
|
|
||||||
return "[ TRI: " + str(i0) + ", " + str(i1) + ", " + str(i2) + " ]"
|
|
||||||
|
|
||||||
static func apply_seam(mdr : MeshDataResource) -> void:
|
|
||||||
var points : PoolVector3Array = PoolVector3Array()
|
var points : PoolVector3Array = PoolVector3Array()
|
||||||
|
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
@ -1465,9 +1632,10 @@ static func apply_seam(mdr : MeshDataResource) -> void:
|
|||||||
arrays[ArrayMesh.ARRAY_INDEX] = new_indices
|
arrays[ArrayMesh.ARRAY_INDEX] = new_indices
|
||||||
|
|
||||||
mdr.array = seam_apply_duplicate_vertices(arrays, duplicate_verts_indices)
|
mdr.array = seam_apply_duplicate_vertices(arrays, duplicate_verts_indices)
|
||||||
|
*/
|
||||||
|
}
|
||||||
static func apply_seam_old(mdr : MeshDataResource) -> void:
|
void MDREDMeshUtils::apply_seam_old(Ref<MeshDataResource> mdr) {
|
||||||
|
/*
|
||||||
var points : PoolVector3Array = PoolVector3Array()
|
var points : PoolVector3Array = PoolVector3Array()
|
||||||
|
|
||||||
var arrays : Array = mdr.get_array()
|
var arrays : Array = mdr.get_array()
|
||||||
@ -1547,9 +1715,12 @@ static func apply_seam_old(mdr : MeshDataResource) -> void:
|
|||||||
#mdr.array = arrays
|
#mdr.array = arrays
|
||||||
|
|
||||||
mdr.array = seam_apply_duplicate_vertices(arrays, duplicate_verts_indices)
|
mdr.array = seam_apply_duplicate_vertices(arrays, duplicate_verts_indices)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
# This will not touch the indices!
|
// This will not touch the indices!
|
||||||
static func seam_apply_duplicate_vertices(arrays : Array, duplicate_verts_indices : PoolIntArray) -> Array:
|
Array MDREDMeshUtils::seam_apply_duplicate_vertices(Array arrays, PoolIntArray duplicate_verts_indices) {
|
||||||
|
/*
|
||||||
var vertices : PoolVector3Array = arrays[ArrayMesh.ARRAY_VERTEX]
|
var vertices : PoolVector3Array = arrays[ArrayMesh.ARRAY_VERTEX]
|
||||||
|
|
||||||
var normals : PoolVector3Array
|
var normals : PoolVector3Array
|
||||||
@ -1641,3 +1812,5 @@ static func seam_apply_duplicate_vertices(arrays : Array, duplicate_verts_indice
|
|||||||
arrays[ArrayMesh.ARRAY_WEIGHTS] = weights
|
arrays[ArrayMesh.ARRAY_WEIGHTS] = weights
|
||||||
|
|
||||||
return arrays
|
return arrays
|
||||||
|
*/
|
||||||
|
}
|
153
modules/mesh_data_resource/editor/utilities/mdr_ed_mesh_utils.h
Normal file
153
modules/mesh_data_resource/editor/utilities/mdr_ed_mesh_utils.h
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
#ifndef MDR_ED_MESH_UTILS_H
|
||||||
|
#define MDR_ED_MESH_UTILS_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Péter Magyar
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "core/ustring.h"
|
||||||
|
#include "core/pool_vector.h"
|
||||||
|
#include "core/math/vector3.h"
|
||||||
|
#include "core/reference.h"
|
||||||
|
#include "core/array.h"
|
||||||
|
|
||||||
|
class MeshDataResource;
|
||||||
|
class SurfaceTool;
|
||||||
|
|
||||||
|
class MDREDMeshUtils {
|
||||||
|
public:
|
||||||
|
struct SeamTriangleHelper {
|
||||||
|
int i0;
|
||||||
|
int i1;
|
||||||
|
int i2;
|
||||||
|
int orig_index;
|
||||||
|
int index_index;
|
||||||
|
|
||||||
|
int side_index_1;
|
||||||
|
int side_index_2;
|
||||||
|
bool side_index_1_cut;
|
||||||
|
bool side_index_2_cut;
|
||||||
|
|
||||||
|
bool processed;
|
||||||
|
|
||||||
|
int get_other_side_index(int index);
|
||||||
|
|
||||||
|
int get_side_index(int i);
|
||||||
|
int get_side_index_cut();
|
||||||
|
int get_opposite_side_index_cut();
|
||||||
|
bool is_side_index_cut(int i);
|
||||||
|
|
||||||
|
bool is_the_same(SeamTriangleHelper h);
|
||||||
|
|
||||||
|
bool is_triangle(int pi0, int pi1, int pi2);
|
||||||
|
bool is_neighbour_to(int index);
|
||||||
|
|
||||||
|
bool needs_to_be_cut_near(int index);
|
||||||
|
bool has_cut();
|
||||||
|
bool both_sides_need_cut();
|
||||||
|
|
||||||
|
void setup(int pi0, int pi1, int pi2, int porig_ind, int pindex_index, PoolIntArray seams);
|
||||||
|
|
||||||
|
void determine_cuts(PoolIntArray seams);
|
||||||
|
bool check_cut(int ind0, int ind1, PoolIntArray seams);
|
||||||
|
|
||||||
|
String _to_string();
|
||||||
|
|
||||||
|
SeamTriangleHelper();
|
||||||
|
};
|
||||||
|
|
||||||
|
static void remove_triangle(Ref<MeshDataResource> mdr, int triangle_index);
|
||||||
|
static bool add_triangulated_mesh_from_points_delaunay(Ref<MeshDataResource> mdr, PoolVector3Array selected_points, Vector3 last_known_camera_facing);
|
||||||
|
static void add_triangulated_mesh_from_points(Ref<MeshDataResource> mdr, PoolVector3Array selected_points, Vector3 last_known_camera_facing);
|
||||||
|
|
||||||
|
// Appends a triangle to the mesh. It's created from miroring v2 to the ev0, and ev1 edge
|
||||||
|
static void append_triangle_to_tri_edge(Ref<MeshDataResource> mdr, Vector3 ev0, Vector3 ev1, Vector3 v2);
|
||||||
|
|
||||||
|
static void add_triangle_at(Ref<MeshDataResource> mdr, Vector3 v0, Vector3 v1, Vector3 v2, bool flip = false);
|
||||||
|
|
||||||
|
static void add_triangle(Ref<MeshDataResource> mdr);
|
||||||
|
|
||||||
|
// Appends a quad to the mesh. It's created to the opposite side of v2 to the ev0, and ev1 edge
|
||||||
|
static void append_quad_to_tri_edge(Ref<MeshDataResource> mdr, Vector3 ev0, Vector3 ev1, Vector3 v2);
|
||||||
|
static void add_quad_at(Ref<MeshDataResource> mdr, Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3, bool flip = false);
|
||||||
|
static void add_quad(Ref<MeshDataResource> mdr);
|
||||||
|
static void add_box(Ref<MeshDataResource> mdr);
|
||||||
|
static void merge_in_surface_tool(Ref<MeshDataResource> mdr, Ref<SurfaceTool> st, bool generate_normals_if_needed = true, bool generate_tangents_if_needed = true);
|
||||||
|
static void merge_in_arrays(Ref<MeshDataResource> mdr, Array merge);
|
||||||
|
static Array get_arrays_prepared(Ref<MeshDataResource> mdr);
|
||||||
|
|
||||||
|
// There are probably better ways to do this
|
||||||
|
static bool should_flip_reflected_triangle(Vector3 v0, Vector3 v1, Vector3 v2);
|
||||||
|
static Vector3 reflect_vertex(Vector3 v0, Vector3 v1, Vector3 v2);
|
||||||
|
|
||||||
|
static Vector3 get_face_normal_arr_ti(PoolVector3Array verts, PoolIntArray indices, int triangle_index, bool flipped = false);
|
||||||
|
static Vector3 get_face_normal_arr(PoolVector3Array verts, PoolIntArray indices, int index, bool flipped = false);
|
||||||
|
static Vector3 get_face_normal(Vector3 v0, Vector3 v1, Vector3 v2, bool flipped = false);
|
||||||
|
|
||||||
|
static bool should_triangle_flip(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 similar_dir_normal);
|
||||||
|
|
||||||
|
static bool is_normal_similar(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 similar_dir_normal);
|
||||||
|
static bool is_direction_similar(Vector3 d0, Vector3 d1);
|
||||||
|
|
||||||
|
static void flip_triangle_ti(Ref<MeshDataResource> mdr, int triangle_index);
|
||||||
|
static void flip_triangle(Ref<MeshDataResource> mdr, int index);
|
||||||
|
static void add_into_surface_tool(Ref<MeshDataResource> mdr, Ref<SurfaceTool> st);
|
||||||
|
|
||||||
|
static Array generate_normals_arrs(Array arrays);
|
||||||
|
static void generate_normals_mdr(Ref<MeshDataResource> mdr);
|
||||||
|
|
||||||
|
// Apparently surfacetool adds more verts during normal generation
|
||||||
|
// Keeping this here for now
|
||||||
|
static void generate_normals_surface_tool(Ref<MeshDataResource> mdr);
|
||||||
|
static void generate_tangents(Ref<MeshDataResource> mdr);
|
||||||
|
|
||||||
|
static Array remove_used_vertices(Array arrays);
|
||||||
|
|
||||||
|
static Array remove_vertices(Array arrays, PoolIntArray indices);
|
||||||
|
|
||||||
|
static int find_max(PoolIntArray arr);
|
||||||
|
static int find_max_capped(PoolIntArray arr, int last);
|
||||||
|
|
||||||
|
static PoolIntArray order_seam_indices(PoolIntArray arr);
|
||||||
|
|
||||||
|
static void add_seam_not_ordered(Ref<MeshDataResource> mdr, int index0, int index1);
|
||||||
|
static void remove_seam_not_ordered(Ref<MeshDataResource> mdr, int index0, int index1);
|
||||||
|
|
||||||
|
static bool has_seam(Ref<MeshDataResource> mdr, int index0, int index1);
|
||||||
|
static void add_seam(Ref<MeshDataResource> mdr, int index0, int index1);
|
||||||
|
static void remove_seam(Ref<MeshDataResource> mdr, int index0, int index1);
|
||||||
|
|
||||||
|
static bool is_verts_equal(Vector3 v0, Vector3 v1);
|
||||||
|
|
||||||
|
static void points_to_seams(Ref<MeshDataResource> mdr, PoolVector3Array points);
|
||||||
|
static PoolVector3Array seams_to_points(Ref<MeshDataResource> mdr);
|
||||||
|
static bool is_matching_seam(int i0, int i1, int si0, int si1);
|
||||||
|
|
||||||
|
static bool pool_int_arr_contains(PoolIntArray arr, int val);
|
||||||
|
|
||||||
|
static void apply_seam(Ref<MeshDataResource> mdr);
|
||||||
|
static void apply_seam_old(Ref<MeshDataResource> mdr);
|
||||||
|
|
||||||
|
// This will not touch the indices!
|
||||||
|
static Array seam_apply_duplicate_vertices(Array arrays, PoolIntArray duplicate_verts_indices);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user