Started refactoring mesh data resource editor's gizmo.

This commit is contained in:
Relintai 2021-12-29 17:10:58 +01:00
parent eea2e76702
commit ef7ed3848b
4 changed files with 79 additions and 20 deletions

View File

@ -1,6 +1,8 @@
tool
extends EditorSpatialGizmo
var MeshOutline = preload("res://addons/mesh_data_resource_editor/utilities/mesh_outline.gd")
enum EditMode {
NONE, TRANSLATE, SCALE, ROTATE
}
@ -13,10 +15,11 @@ enum AxisConstraint {
var gizmo_size = 3.0
var plugin
var plugin : EditorPlugin
var vertices : PoolVector3Array
var indices : PoolIntArray
var selected_indices : PoolIntArray
var selected_vertices : PoolVector3Array
var selected_vertices_original : PoolVector3Array
@ -26,6 +29,11 @@ var axis_constraint = AxisConstraint.X | AxisConstraint.Y | AxisConstraint.Z
var previous_point : Vector2
var is_dragging : bool = false
var _mesh_outline
func _init():
_mesh_outline = MeshOutline.new()
func set_handle(index: int, camera: Camera, point: Vector2):
var relative : Vector2 = point - previous_point
@ -103,29 +111,15 @@ func redraw():
if mdr.array.size() != ArrayMesh.ARRAY_MAX:
return
var handles_material : SpatialMaterial = get_plugin().get_material("handles", self)
var material = get_plugin().get_material("main", self)
_mesh_outline.setup(mdr)
add_lines(_mesh_outline.lines, material, false)
if vertices.size() == 0:
vertices = mdr.array[ArrayMesh.ARRAY_VERTEX]
var material = get_plugin().get_material("main", self)
var indices : PoolIntArray = mdr.array[ArrayMesh.ARRAY_INDEX]
var lines : PoolVector3Array = PoolVector3Array()
if indices.size() % 3 == 0:
for i in range(0, len(indices), 3):
lines.append(vertices[indices[i]])
lines.append(vertices[indices[i + 1]])
lines.append(vertices[indices[i + 1]])
lines.append(vertices[indices[i + 2]])
lines.append(vertices[indices[i + 2]])
lines.append(vertices[indices[i]])
add_lines(lines, material, false)
var vs : PoolVector3Array = PoolVector3Array()

View File

@ -1,3 +1,4 @@
tool
extends Object
static func add_box(mdr : MeshDataResource) -> void:

View File

@ -0,0 +1,14 @@
tool
extends Object
static func get_vertex_to_vertex_map() -> Array:
return Array()
static func get_edge_to_vertex_map() -> Array:
return Array()
static func get_face_to_vertex_map() -> Array:
return Array()
static func calculate_map_midpoints(mesh : Array, vertex_map : Array) -> PoolVector3Array:
return PoolVector3Array()

View File

@ -0,0 +1,50 @@
tool
extends Reference
var _mdr : MeshDataResource
var lines : PoolVector3Array
func setup(mdr : MeshDataResource) -> void:
if _mdr != null && _mdr == mdr:
return
if _mdr:
_mdr.disconnect("changed", self, "refresh")
_mdr = mdr
if _mdr:
_mdr.connect("changed", self, "refresh")
refresh()
func refresh():
lines.resize(0)
if !_mdr:
return
if _mdr.array.size() != ArrayMesh.ARRAY_MAX:
return
if _mdr.array[ArrayMesh.ARRAY_VERTEX] == null || _mdr.array[ArrayMesh.ARRAY_INDEX] == null:
return
var vertices : PoolVector3Array = _mdr.array[ArrayMesh.ARRAY_VERTEX]
var indices : PoolIntArray = _mdr.array[ArrayMesh.ARRAY_INDEX]
if vertices.size() == 0:
vertices = _mdr.array[ArrayMesh.ARRAY_VERTEX]
if indices.size() % 3 == 0:
for i in range(0, len(indices), 3):
lines.append(vertices[indices[i]])
lines.append(vertices[indices[i + 1]])
lines.append(vertices[indices[i + 1]])
lines.append(vertices[indices[i + 2]])
lines.append(vertices[indices[i + 2]])
lines.append(vertices[indices[i]])