mirror of
https://github.com/Relintai/broken_seals.git
synced 2025-03-05 03:43:10 +01:00
In mesh data editor now the selected vertices are draggable with the handles, instead of blender like commands. Also now axis constraints are togglable per axis.
This commit is contained in:
parent
0aad743afe
commit
5d9651253c
@ -12,15 +12,15 @@ func _unhandled_key_input(event : InputEventKey) -> void:
|
||||
|
||||
#translate
|
||||
if plugin:
|
||||
plugin.translate_request(event.pressed)
|
||||
plugin.translate_key_pressed(event.pressed)
|
||||
elif event.scancode == KEY_S:
|
||||
#scale? probably needs a differrent key
|
||||
if plugin:
|
||||
plugin.scale_request(event.pressed)
|
||||
plugin.scale_key_pressed(event.pressed)
|
||||
elif event.scancode == KEY_R:
|
||||
#rotate
|
||||
if plugin:
|
||||
plugin.rotate_request(event.pressed)
|
||||
plugin.rotate_key_pressed(event.pressed)
|
||||
elif event.scancode == KEY_X:
|
||||
if plugin:
|
||||
plugin.axis_key_x(event.pressed)
|
||||
|
@ -6,7 +6,9 @@ enum EditMode {
|
||||
}
|
||||
|
||||
enum AxisConstraint {
|
||||
X, Y, Z
|
||||
X = 1 << 0,
|
||||
Y = 1 << 1,
|
||||
Z = 1 << 2,
|
||||
}
|
||||
|
||||
var gizmo_size = 3.0
|
||||
@ -19,13 +21,48 @@ var selected_indices : PoolIntArray
|
||||
var selected_vertices : PoolVector3Array
|
||||
var selected_vertices_original : PoolVector3Array
|
||||
|
||||
var edit_mode = EditMode.NONE
|
||||
var axis_constraint = AxisConstraint.NONE
|
||||
var edit_mode = EditMode.TRANSLATE
|
||||
var axis_constraint = AxisConstraint.X | AxisConstraint.Y | AxisConstraint.Z
|
||||
var previous_point : Vector2
|
||||
var is_dragging : bool = false
|
||||
|
||||
func set_handle(index: int, camera: Camera, point: Vector2):
|
||||
print("set_handle")
|
||||
var relative : Vector2 = point - previous_point
|
||||
|
||||
edit_mode = EditMode.NONE
|
||||
if !is_dragging:
|
||||
relative = Vector2()
|
||||
is_dragging = true
|
||||
|
||||
if edit_mode == EditMode.NONE:
|
||||
return
|
||||
elif edit_mode == EditMode.TRANSLATE:
|
||||
for i in selected_indices:
|
||||
var v : Vector3 = vertices[i]
|
||||
|
||||
if (axis_constraint & AxisConstraint.X) != 0:
|
||||
v.x += relative.x * -0.001
|
||||
|
||||
if (axis_constraint & AxisConstraint.Y) != 0:
|
||||
v.y += relative.y * 0.001
|
||||
|
||||
if (axis_constraint & AxisConstraint.Z) != 0:
|
||||
v.z += relative.x * 0.001
|
||||
|
||||
vertices.set(i, v)
|
||||
|
||||
redraw()
|
||||
elif edit_mode == EditMode.SCALE:
|
||||
print("SCALE")
|
||||
elif edit_mode == EditMode.ROTATE:
|
||||
print("ROTATE")
|
||||
|
||||
|
||||
previous_point = point
|
||||
|
||||
func commit_handle(index: int, restore, cancel: bool = false) -> void:
|
||||
previous_point = Vector2()
|
||||
|
||||
print("commit")
|
||||
|
||||
func redraw():
|
||||
clear()
|
||||
@ -44,7 +81,6 @@ func redraw():
|
||||
|
||||
if vertices.size() == 0:
|
||||
vertices = mdr.array[ArrayMesh.ARRAY_VERTEX]
|
||||
#add_handles(vertices, handles_material)
|
||||
|
||||
var material = get_plugin().get_material("main", self)
|
||||
var indices : PoolIntArray = mdr.array[ArrayMesh.ARRAY_INDEX]
|
||||
@ -64,7 +100,12 @@ func redraw():
|
||||
|
||||
add_lines(lines, material, false)
|
||||
|
||||
add_handles(selected_vertices, handles_material)
|
||||
var vs : PoolVector3Array = PoolVector3Array()
|
||||
|
||||
for i in selected_indices:
|
||||
vs.append(vertices[i])
|
||||
|
||||
add_handles(vs, handles_material)
|
||||
|
||||
func forward_spatial_gui_input(index, camera, event):
|
||||
if event is InputEventMouseButton:
|
||||
@ -76,7 +117,6 @@ func forward_spatial_gui_input(index, camera, event):
|
||||
|
||||
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))
|
||||
@ -127,54 +167,65 @@ func forward_spatial_gui_input(index, camera, event):
|
||||
selected_vertices_original.resize(0)
|
||||
|
||||
redraw()
|
||||
else:
|
||||
is_dragging = false
|
||||
|
||||
elif event is InputEventMouseMotion:
|
||||
if edit_mode == EditMode.NONE:
|
||||
return false
|
||||
elif edit_mode == EditMode.TRANSLATE:
|
||||
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()
|
||||
elif edit_mode == EditMode.SCALE:
|
||||
print("SCALE")
|
||||
elif edit_mode == EditMode.ROTATE:
|
||||
print("ROTATE")
|
||||
# elif event is InputEventMouseMotion:
|
||||
# if edit_mode == EditMode.NONE:
|
||||
# return false
|
||||
# elif edit_mode == EditMode.TRANSLATE:
|
||||
# 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()
|
||||
# elif edit_mode == EditMode.SCALE:
|
||||
# print("SCALE")
|
||||
# elif edit_mode == EditMode.ROTATE:
|
||||
# print("ROTATE")
|
||||
|
||||
return false
|
||||
|
||||
func translate_request(on : bool) -> void:
|
||||
func translate_key_pressed(on : bool) -> void:
|
||||
if on:
|
||||
edit_mode = EditMode.TRANSLATE
|
||||
|
||||
func scale_request(on : bool) -> void:
|
||||
func scale_key_pressed(on : bool) -> void:
|
||||
if on:
|
||||
edit_mode = EditMode.SCALE
|
||||
|
||||
func rotate_request(on : bool) -> void:
|
||||
func rotate_key_pressed(on : bool) -> void:
|
||||
if on:
|
||||
edit_mode = EditMode.ROTATE
|
||||
|
||||
func axis_key_x(on : bool) -> void:
|
||||
if on:
|
||||
axis_constraint = AxisConstraint.X
|
||||
if (axis_constraint & AxisConstraint.X) != 0:
|
||||
axis_constraint ^= AxisConstraint.X
|
||||
else:
|
||||
axis_constraint |= AxisConstraint.X
|
||||
|
||||
func axis_key_y(on : bool) -> void:
|
||||
if on:
|
||||
axis_constraint = AxisConstraint.Y
|
||||
if (axis_constraint & AxisConstraint.Y) != 0:
|
||||
axis_constraint ^= AxisConstraint.Y
|
||||
else:
|
||||
axis_constraint |= AxisConstraint.Y
|
||||
|
||||
func axis_key_z(on : bool) -> void:
|
||||
if on:
|
||||
axis_constraint = AxisConstraint.Z
|
||||
if (axis_constraint & AxisConstraint.Z) != 0:
|
||||
axis_constraint ^= AxisConstraint.Z
|
||||
else:
|
||||
axis_constraint |= AxisConstraint.Z
|
||||
|
||||
func _notification(what):
|
||||
if what == NOTIFICATION_PREDELETE:
|
||||
|
@ -77,17 +77,17 @@ func unregister_gizmo(gizmo):
|
||||
active_gizmos.remove(i)
|
||||
return
|
||||
|
||||
func translate_request(on : bool) -> void:
|
||||
func translate_key_pressed(on : bool) -> void:
|
||||
for g in active_gizmos:
|
||||
g.translate_request(on)
|
||||
g.translate_key_pressed(on)
|
||||
|
||||
func scale_request(on : bool) -> void:
|
||||
func scale_key_pressed(on : bool) -> void:
|
||||
for g in active_gizmos:
|
||||
g.scale_request(on)
|
||||
g.scale_key_pressed(on)
|
||||
|
||||
func rotate_request(on : bool) -> void:
|
||||
func rotate_key_pressed(on : bool) -> void:
|
||||
for g in active_gizmos:
|
||||
g.rotate_request(on)
|
||||
g.rotate_key_pressed(on)
|
||||
|
||||
func axis_key_x(on : bool) -> void:
|
||||
for g in active_gizmos:
|
||||
|
Loading…
Reference in New Issue
Block a user