2018-07-28 21:21:05 +02:00
|
|
|
tool
|
|
|
|
extends ViewportContainer
|
|
|
|
|
2018-08-07 09:31:41 +02:00
|
|
|
var preview_maximized = false
|
|
|
|
|
2018-07-28 21:21:05 +02:00
|
|
|
const ENVIRONMENTS = [
|
|
|
|
"experiment", "lobby", "night", "park", "schelde"
|
|
|
|
]
|
|
|
|
|
2019-10-01 08:34:08 +02:00
|
|
|
onready var objects = $MaterialPreview/Preview3d/Objects
|
2019-09-29 10:07:32 +02:00
|
|
|
onready var current_object = objects.get_child(0)
|
|
|
|
|
2019-10-13 22:06:13 +02:00
|
|
|
onready var environments = $MaterialPreview/Preview3d/Environments
|
|
|
|
onready var current_environment = environments.get_child(0)
|
|
|
|
|
2019-09-29 10:07:32 +02:00
|
|
|
signal need_update
|
2019-09-29 21:53:32 +02:00
|
|
|
signal show_background_preview
|
2019-09-29 10:07:32 +02:00
|
|
|
|
2018-07-28 21:21:05 +02:00
|
|
|
func _ready():
|
2019-09-29 10:07:32 +02:00
|
|
|
$Config/Model.clear()
|
|
|
|
for o in objects.get_children():
|
|
|
|
var m = o.get_surface_material(0)
|
|
|
|
o.set_surface_material(0, m.duplicate())
|
|
|
|
$Config/Model.add_item(o.name)
|
2019-10-13 22:06:13 +02:00
|
|
|
call_deferred("_on_Model_item_selected", 0)
|
|
|
|
$Config/Environment.clear()
|
|
|
|
for e in environments.get_children():
|
|
|
|
$Config/Environment.add_item(e.name)
|
|
|
|
call_deferred("_on_Environment_item_selected", 0)
|
2019-10-01 08:34:08 +02:00
|
|
|
$MaterialPreview/Preview3d/ObjectRotate.play("rotate")
|
2018-08-07 09:31:41 +02:00
|
|
|
$Preview2D.material = $Preview2D.material.duplicate(true)
|
|
|
|
_on_Preview_resized()
|
2019-10-01 08:34:08 +02:00
|
|
|
$MaterialPreview/Preview3d/CameraPivot/Camera/RemoteTransform.set_remote_node("../../../../../../../ProjectsPane/BackgroundPreview/Viewport/Camera")
|
2018-07-28 21:21:05 +02:00
|
|
|
|
|
|
|
func _on_Environment_item_selected(id):
|
2019-10-13 22:06:13 +02:00
|
|
|
current_environment.visible = false
|
|
|
|
current_environment = environments.get_child(id)
|
|
|
|
print(current_environment.environment)
|
|
|
|
$MaterialPreview/Preview3d/CameraPivot/Camera.set_environment(current_environment.environment)
|
|
|
|
get_node("../../ProjectsPane/BackgroundPreview/Viewport/Camera").set_environment(current_environment.environment)
|
|
|
|
current_environment.visible = true
|
2018-07-29 19:19:35 +02:00
|
|
|
|
|
|
|
func _on_Model_item_selected(id):
|
2019-09-29 10:07:32 +02:00
|
|
|
current_object.visible = false
|
|
|
|
current_object = objects.get_child(id)
|
|
|
|
current_object.visible = true
|
|
|
|
emit_signal("need_update")
|
2018-07-29 23:43:24 +02:00
|
|
|
|
|
|
|
func get_materials():
|
2019-09-29 10:07:32 +02:00
|
|
|
return [ current_object.get_surface_material(0) ]
|
2019-08-12 15:58:42 +02:00
|
|
|
|
|
|
|
func set_2d(tex: Texture):
|
|
|
|
$Preview2D.material.set_shader_param("tex", tex)
|
2018-08-07 09:31:41 +02:00
|
|
|
|
|
|
|
func _on_Preview_resized():
|
|
|
|
if preview_maximized:
|
|
|
|
var size = min(rect_size.x, rect_size.y)
|
|
|
|
$Preview2D.rect_position = 0.5*Vector2(rect_size.x-size, rect_size.y-size)
|
|
|
|
$Preview2D.rect_size = Vector2(size, size)
|
|
|
|
else:
|
|
|
|
$Preview2D.rect_position = Vector2(0, rect_size.y-64)
|
|
|
|
$Preview2D.rect_size = Vector2(64, 64)
|
|
|
|
|
2019-09-11 23:13:10 +02:00
|
|
|
func _on_Preview2D_gui_input(ev : InputEvent):
|
2019-09-13 08:07:46 +02:00
|
|
|
if ev is InputEventMouseButton and ev.button_index == 1 and ev.pressed:
|
2018-08-07 09:31:41 +02:00
|
|
|
preview_maximized = !preview_maximized
|
2019-09-29 21:53:32 +02:00
|
|
|
_on_Preview_resized()
|
|
|
|
|
|
|
|
func _on_Button_toggled(button_pressed):
|
|
|
|
emit_signal("show_background_preview", button_pressed)
|
|
|
|
|
|
|
|
func on_gui_input(event):
|
|
|
|
if event is InputEventMouseButton:
|
2019-10-01 08:34:08 +02:00
|
|
|
$MaterialPreview/Preview3d/ObjectRotate.stop()
|
2019-09-29 21:53:32 +02:00
|
|
|
elif event is InputEventMouseMotion:
|
2019-10-13 22:06:13 +02:00
|
|
|
if event.button_mask & BUTTON_MASK_LEFT:
|
2019-10-01 08:34:08 +02:00
|
|
|
$MaterialPreview/Preview3d/Objects.rotation.y += 0.01*event.relative.x
|
2019-10-13 22:06:13 +02:00
|
|
|
$MaterialPreview/Preview3d/Objects.rotation.x += 0.01*event.relative.y
|
|
|
|
elif event.button_mask & BUTTON_MASK_RIGHT:
|
|
|
|
$MaterialPreview/Preview3d/CameraPivot.rotation.y += 0.01*event.relative.x
|
2019-10-01 08:34:08 +02:00
|
|
|
$MaterialPreview/Preview3d/CameraPivot.rotation.x -= 0.01*event.relative.y
|