diff --git a/addons/material_maker/main_window.gd b/addons/material_maker/main_window.gd index 1d9855a..d85ee66 100644 --- a/addons/material_maker/main_window.gd +++ b/addons/material_maker/main_window.gd @@ -14,6 +14,9 @@ var need_update : bool = false onready var projects = $VBoxContainer/HBoxContainer/ProjectsPane/Projects onready var library = $VBoxContainer/HBoxContainer/VBoxContainer/Library +onready var preview_2d = $VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview2D +onready var preview_3d = $VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D + const RECENT_FILES_COUNT = 15 const MENU = [ @@ -473,7 +476,6 @@ func update_preview() -> void: func update_preview_2d(node = null) -> void: var graph_edit : MMGraphEdit = get_current_graph_edit() if graph_edit != null: - var preview = $VBoxContainer/HBoxContainer/VBoxContainer/Preview if node == null: for n in graph_edit.get_children(): if n is GraphNode and n.selected: @@ -486,7 +488,7 @@ func update_preview_2d(node = null) -> void: var tex = ImageTexture.new() result.copy_to_texture(tex) result.release() - preview.set_2d(tex) + preview_2d.set_preview_texture(tex) func update_preview_3d() -> void: var graph_edit : MMGraphEdit = get_current_graph_edit() @@ -495,7 +497,7 @@ func update_preview_3d() -> void: var status = gen_material.render_textures() while status is GDScriptFunctionState: status = yield(status, "completed") - gen_material.update_materials($VBoxContainer/HBoxContainer/VBoxContainer/Preview.get_materials()) + gen_material.update_materials(preview_3d.get_materials()) func _on_Projects_tab_changed(tab) -> void: var new_tab = projects.get_current_tab_control() @@ -510,7 +512,7 @@ func _on_Projects_tab_changed(tab) -> void: update_preview() func _on_Preview_show_background_preview(v) -> void: - var pv = $VBoxContainer/HBoxContainer/VBoxContainer/Preview/MaterialPreview + var pv = preview_3d.get_node("MaterialPreview") var bgpv = $VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview/Viewport bgpv.world = pv.find_world() $VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview.visible = v diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index 4e72a8b..b531dd8 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -1,19 +1,32 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=12 format=2] [ext_resource path="res://addons/material_maker/main_window.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/library.tscn" type="PackedScene" id=2] -[ext_resource path="res://addons/material_maker/preview/preview.tscn" type="PackedScene" id=3] -[ext_resource path="res://addons/material_maker/preview/panoramas/epping_forest_01.hdr" type="Texture" id=4] -[ext_resource path="res://addons/material_maker/widgets/tabs.gd" type="Script" id=5] -[ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=6] +[ext_resource path="res://addons/material_maker/preview/preview_2d.tscn" type="PackedScene" id=3] +[ext_resource path="res://addons/material_maker/preview/preview_3d.tscn" type="PackedScene" id=4] +[ext_resource path="res://addons/material_maker/preview/panoramas/epping_forest_01.hdr" type="Texture" id=5] +[ext_resource path="res://addons/material_maker/widgets/tabs.gd" type="Script" id=6] +[ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=7] -[sub_resource type="PanoramaSky" id=1] +[sub_resource type="Shader" id=1] +code = "shader_type canvas_item; + +uniform sampler2D tex; + +void fragment() { + COLOR = texture(tex, UV); +}" + +[sub_resource type="ShaderMaterial" id=2] +shader = SubResource( 1 ) + +[sub_resource type="PanoramaSky" id=3] resource_local_to_scene = true -panorama = ExtResource( 4 ) +panorama = ExtResource( 5 ) -[sub_resource type="Environment" id=2] +[sub_resource type="Environment" id=4] background_mode = 2 -background_sky = SubResource( 1 ) +background_sky = SubResource( 3 ) background_energy = 1.5 ambient_light_color = Color( 1, 1, 1, 1 ) ambient_light_energy = 0.32 @@ -66,7 +79,7 @@ margin_left = 125.0 margin_right = 171.0 margin_bottom = 20.0 text = "Tools" -items = [ "Create", null, 0, false, false, -1, 0, null, "PopupMenu", false, "Create group", null, 0, false, false, 19, 268435527, null, "", false, "Make selected nodes editable", null, 0, false, false, 20, 268435543, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Add selected node to user library", null, 0, false, false, 22, 0, null, "", false, "Export the nodes library", null, 0, false, false, 23, 0, null, "", false ] +items = [ "Create", null, 0, false, false, 0, 0, null, "PopupMenu", false, "Create group", null, 0, false, false, 19, 268435527, null, "", false, "Make selected nodes editable", null, 0, false, false, 20, 268435543, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Add selected node to user library", null, 0, false, false, 22, 0, null, "", false, "Export the nodes library", null, 0, false, false, 23, 0, null, "", false ] [node name="Help" type="MenuButton" parent="VBoxContainer/Menu"] margin_left = 175.0 @@ -89,18 +102,22 @@ size_flags_vertical = 3 [node name="Library" parent="VBoxContainer/HBoxContainer/VBoxContainer" instance=ExtResource( 2 )] margin_right = 311.0 -margin_bottom = 404.0 +margin_bottom = 386.0 size_flags_vertical = 3 size_flags_stretch_ratio = 1.5 -[node name="Preview" parent="VBoxContainer/HBoxContainer/VBoxContainer" instance=ExtResource( 3 )] -anchor_left = 0.0 -anchor_right = 0.0 -margin_left = 0.0 -margin_top = 416.0 +[node name="Preview" type="TabContainer" parent="VBoxContainer/HBoxContainer/VBoxContainer"] +margin_top = 398.0 margin_right = 311.0 margin_bottom = 684.0 -rect_min_size = Vector2( 300, 200 ) +tab_align = 0 + +[node name="Preview2D" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview" instance=ExtResource( 3 )] +material = SubResource( 2 ) +rect_min_size = Vector2( 250, 250 ) + +[node name="Preview3D" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview" instance=ExtResource( 4 )] +rect_min_size = Vector2( 250, 250 ) [node name="ProjectsPane" type="Control" parent="VBoxContainer/HBoxContainer"] margin_left = 323.0 @@ -124,7 +141,7 @@ render_target_update_mode = 0 [node name="Camera" type="Camera" parent="VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview/Viewport"] transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 2.24976, 2.68115 ) -environment = SubResource( 2 ) +environment = SubResource( 4 ) current = true [node name="Projects" type="Panel" parent="VBoxContainer/HBoxContainer/ProjectsPane"] @@ -135,7 +152,7 @@ margin_right = 5.0 margin_bottom = 5.0 size_flags_horizontal = 3 size_flags_vertical = 3 -script = ExtResource( 5 ) +script = ExtResource( 6 ) [node name="Tabs" type="Tabs" parent="VBoxContainer/HBoxContainer/ProjectsPane/Projects"] margin_right = 950.0 @@ -144,9 +161,9 @@ tab_align = 0 tab_close_display_policy = 1 [node name="NodeFactory" type="Node" parent="."] -script = ExtResource( 6 ) -[connection signal="need_update" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="." method="update_preview_3d"] -[connection signal="show_background_preview" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="." method="_on_Preview_show_background_preview"] +script = ExtResource( 7 ) +[connection signal="need_update" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" to="." method="update_preview_3d"] +[connection signal="show_background_preview" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" to="." method="_on_Preview_show_background_preview"] [connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="." method="new_material"] [connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects" method="_on_Projects_resized"] [connection signal="tab_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="." method="_on_Projects_tab_changed"] diff --git a/addons/material_maker/preview/preview.tscn b/addons/material_maker/preview/preview.tscn deleted file mode 100644 index 932920e..0000000 --- a/addons/material_maker/preview/preview.tscn +++ /dev/null @@ -1,108 +0,0 @@ -[gd_scene load_steps=6 format=2] - -[ext_resource path="res://addons/material_maker/preview/preview.gd" type="Script" id=1] -[ext_resource path="res://addons/material_maker/preview/preview_3d.tscn" type="PackedScene" id=2] - - -[sub_resource type="World" id=1] - -[sub_resource type="Shader" id=2] -code = "shader_type canvas_item; - -uniform sampler2D tex; - -void fragment() { - COLOR = texture(tex, UV); -}" - -[sub_resource type="ShaderMaterial" id=3] -shader = SubResource( 2 ) - -[node name="Preview" type="ViewportContainer"] -anchor_left = 1.0 -anchor_right = 1.0 -margin_left = -398.0 -margin_top = 3.0 -margin_right = -3.0 -margin_bottom = 373.0 -rect_min_size = Vector2( 200, 200 ) -mouse_filter = 1 -size_flags_horizontal = 3 -size_flags_vertical = 3 -stretch = true -script = ExtResource( 1 ) - -[node name="MaterialPreview" type="Viewport" parent="."] -size = Vector2( 395, 370 ) -own_world = true -world = SubResource( 1 ) -handle_input_locally = false -msaa = 2 -render_target_clear_mode = 1 -render_target_update_mode = 3 -physics_object_picking = true - -[node name="Preview3d" parent="MaterialPreview" instance=ExtResource( 2 )] - -[node name="Config" type="HBoxContainer" parent="."] -anchor_right = 1.0 -margin_bottom = 20.0 -size_flags_horizontal = 3 - -[node name="Model" type="OptionButton" parent="Config"] -margin_right = 100.0 -margin_bottom = 20.0 -rect_min_size = Vector2( 100, 0 ) -text = "Cube" -items = [ "Cube", null, false, -1, null, "Cylinder", null, false, -1, null, "Sphere", null, false, -1, null, "Sphere2", null, false, -1, null, "Quad", null, false, -1, null, "Plane", null, false, -1, null ] -selected = 0 - -[node name="Environment" type="OptionButton" parent="Config"] -margin_left = 104.0 -margin_right = 231.0 -margin_bottom = 20.0 -rect_min_size = Vector2( 100, 0 ) -text = "Epping Forest" -items = [ "Epping Forest", null, false, -1, null, "Moonless Golf", null, false, -1, null ] -selected = 0 - -[node name="Rotate" type="Button" parent="Config"] -margin_left = 235.0 -margin_right = 255.0 -margin_bottom = 20.0 -rect_pivot_offset = Vector2( -4, 7 ) -hint_tooltip = "Rotate object" -size_flags_horizontal = 2 -toggle_mode = true -pressed = true -text = "R" - -[node name="Background" type="Button" parent="Config"] -margin_left = 372.0 -margin_right = 395.0 -margin_bottom = 20.0 -grow_horizontal = 2 -grow_vertical = 2 -rect_pivot_offset = Vector2( -4, 7 ) -hint_tooltip = "Show in main view" -size_flags_horizontal = 8 -toggle_mode = true -text = "O" - -[node name="Preview2D" type="ColorRect" parent="."] -material = SubResource( 3 ) -anchor_top = 1.0 -anchor_bottom = 1.0 -margin_top = -64.0 -margin_right = 64.0 -rect_min_size = Vector2( 64, 64 ) -mouse_filter = 1 -size_flags_horizontal = 0 -size_flags_vertical = 8 -[connection signal="gui_input" from="." to="." method="on_gui_input"] -[connection signal="resized" from="." to="." method="_on_Preview_resized"] -[connection signal="item_selected" from="Config/Model" to="." method="_on_Model_item_selected"] -[connection signal="item_selected" from="Config/Environment" to="." method="_on_Environment_item_selected"] -[connection signal="toggled" from="Config/Rotate" to="." method="_on_Rotate_toggled"] -[connection signal="toggled" from="Config/Background" to="." method="_on_Background_toggled"] -[connection signal="gui_input" from="Preview2D" to="." method="_on_Preview2D_gui_input"] diff --git a/addons/material_maker/preview/preview_2d.gd b/addons/material_maker/preview/preview_2d.gd new file mode 100644 index 0000000..1cba73f --- /dev/null +++ b/addons/material_maker/preview/preview_2d.gd @@ -0,0 +1,7 @@ +extends ColorRect + +func _ready() -> void: + material = material.duplicate(true) + +func set_preview_texture(tex: Texture) -> void: + material.set_shader_param("tex", tex) diff --git a/addons/material_maker/preview/preview_2d.tscn b/addons/material_maker/preview/preview_2d.tscn new file mode 100644 index 0000000..3073c0f --- /dev/null +++ b/addons/material_maker/preview/preview_2d.tscn @@ -0,0 +1,29 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://addons/material_maker/preview/preview_2d.gd" type="Script" id=1] + +[sub_resource type="Shader" id=1] +code = "shader_type canvas_item; + +uniform sampler2D tex; + +void fragment() { + COLOR = texture(tex, UV); +}" + +[sub_resource type="ShaderMaterial" id=2] +shader = SubResource( 1 ) + +[node name="Preview2D" type="ColorRect"] +material = SubResource( 2 ) +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 4.0 +margin_top = 32.0 +margin_right = -4.0 +margin_bottom = -4.0 +rect_min_size = Vector2( 64, 64 ) +mouse_filter = 1 +size_flags_horizontal = 0 +size_flags_vertical = 8 +script = ExtResource( 1 ) diff --git a/addons/material_maker/preview/preview.gd b/addons/material_maker/preview/preview_3d.gd similarity index 71% rename from addons/material_maker/preview/preview.gd rename to addons/material_maker/preview/preview_3d.gd index a62aed4..1e51c61 100644 --- a/addons/material_maker/preview/preview.gd +++ b/addons/material_maker/preview/preview_3d.gd @@ -1,8 +1,6 @@ tool extends ViewportContainer -var preview_maximized = false - const ENVIRONMENTS = [ "experiment", "lobby", "night", "park", "schelde" ] @@ -23,27 +21,18 @@ signal need_update signal show_background_preview func _ready() -> void: - $Config/Model.clear() + var model_list : Array = [] 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) - call_deferred("_on_Model_item_selected", 0) - $Config/Environment.clear() + model_list.push_back(o.name) + $Preview3DUI.set_models(model_list) + var environment_list : Array = [] for e in environments.get_children(): - $Config/Environment.add_item(e.name) - call_deferred("_on_Environment_item_selected", 0) + environment_list.push_back(e.name) + $Preview3DUI.set_environments(environment_list) $MaterialPreview/Preview3d/ObjectRotate.play("rotate") - $Preview2D.material = $Preview2D.material.duplicate(true) - _on_Preview_resized() - $MaterialPreview/Preview3d/CameraPivot/Camera/RemoteTransform.set_remote_node("../../../../../../../ProjectsPane/BackgroundPreview/Viewport/Camera") - -func _on_Environment_item_selected(id) -> void: - current_environment.visible = false - current_environment = environments.get_child(id) - $MaterialPreview/Preview3d/CameraPivot/Camera.set_environment(current_environment.environment) - get_node("../../ProjectsPane/BackgroundPreview/Viewport/Camera").set_environment(current_environment.environment) - current_environment.visible = true + $MaterialPreview/Preview3d/CameraPivot/Camera/RemoteTransform.set_remote_node("../../../../../../../../ProjectsPane/BackgroundPreview/Viewport/Camera") func _on_Model_item_selected(id) -> void: current_object.visible = false @@ -51,33 +40,29 @@ func _on_Model_item_selected(id) -> void: current_object.visible = true emit_signal("need_update") -func get_materials() -> Array: - return [ current_object.get_surface_material(0) ] +func _on_Environment_item_selected(id) -> void: + current_environment.visible = false + current_environment = environments.get_child(id) + $MaterialPreview/Preview3d/CameraPivot/Camera.set_environment(current_environment.environment) + get_node("../../../ProjectsPane/BackgroundPreview/Viewport/Camera").set_environment(current_environment.environment) + current_environment.visible = true -func set_2d(tex: Texture) -> void: - $Preview2D.material.set_shader_param("tex", tex) - -func _on_Preview_resized() -> void: - 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) +func _on_Rotate_toggled(button_pressed) -> void: + if button_pressed: + $MaterialPreview/Preview3d/ObjectRotate.play("rotate") else: - $Preview2D.rect_position = Vector2(0, rect_size.y-64) - $Preview2D.rect_size = Vector2(64, 64) - -func _on_Preview2D_gui_input(ev : InputEvent) -> void: - if ev is InputEventMouseButton and ev.button_index == 1 and ev.pressed: - preview_maximized = !preview_maximized - _on_Preview_resized() + $MaterialPreview/Preview3d/ObjectRotate.stop(false) func _on_Background_toggled(button_pressed) -> void: emit_signal("show_background_preview", button_pressed) +func get_materials() -> Array: + return [ current_object.get_surface_material(0) ] + func on_gui_input(event) -> void: if event is InputEventMouseButton: $MaterialPreview/Preview3d/ObjectRotate.stop(false) - $Config/Rotate.pressed = false + $Preview3DUI.rotation_cancelled() match event.button_index: BUTTON_WHEEL_UP: camera.translation.z = clamp( @@ -106,9 +91,3 @@ func on_gui_input(event) -> void: camera_stand.rotate(camera_basis.y.normalized(), -motion.x) elif event.button_mask & BUTTON_MASK_RIGHT: camera_stand.rotate(camera_basis.z.normalized(), -motion.x) - -func _on_Rotate_toggled(button_pressed) -> void: - if button_pressed: - $MaterialPreview/Preview3d/ObjectRotate.play("rotate") - else: - $MaterialPreview/Preview3d/ObjectRotate.stop(false) diff --git a/addons/material_maker/preview/preview_3d.tscn b/addons/material_maker/preview/preview_3d.tscn index ac443bb..3dab17f 100644 --- a/addons/material_maker/preview/preview_3d.tscn +++ b/addons/material_maker/preview/preview_3d.tscn @@ -1,121 +1,42 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=5 format=2] -[ext_resource path="res://addons/material_maker/preview/preview_objects.tscn" type="PackedScene" id=1] -[ext_resource path="res://addons/material_maker/preview/panoramas/moonless_golf.hdr" type="Texture" id=2] -[ext_resource path="res://addons/material_maker/environment.gd" type="Script" id=3] -[ext_resource path="res://addons/material_maker/preview/panoramas/epping_forest_01.hdr" type="Texture" id=4] -[ext_resource path="res://addons/material_maker/preview/panoramas/studio_sky.tres" type="Environment" id=5] +[ext_resource path="res://addons/material_maker/preview/preview_3d.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/preview/preview_3d_scene.tscn" type="PackedScene" id=2] +[ext_resource path="res://addons/material_maker/preview/preview_3d_ui.tscn" type="PackedScene" id=3] -[sub_resource type="PanoramaSky" id=3] -resource_local_to_scene = true -panorama = ExtResource( 2 ) +[sub_resource type="World" id=1] -[sub_resource type="Environment" id=4] -resource_local_to_scene = true -background_mode = 2 -background_sky = SubResource( 3 ) - -[sub_resource type="Animation" id=5] -loop = true -tracks/0/type = "value" -tracks/0/path = NodePath("Objects:rotation_degrees") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/keys = { -"times": PoolRealArray( 0, 1 ), -"transitions": PoolRealArray( 1, 1 ), -"update": 0, -"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ] -} - -[sub_resource type="PanoramaSky" id=1] -resource_local_to_scene = true -panorama = ExtResource( 4 ) - -[sub_resource type="Environment" id=2] -background_mode = 2 -background_sky = SubResource( 1 ) -background_energy = 1.5 -ambient_light_color = Color( 1, 1, 1, 1 ) -ambient_light_energy = 0.32 -tonemap_mode = 2 -tonemap_white = 16.0 - -[sub_resource type="CylinderMesh" id=6] -top_radius = 5.0 -bottom_radius = 5.0 -height = 0.5 - -[sub_resource type="SpatialMaterial" id=7] - -[sub_resource type="PlaneMesh" id=8] -size = Vector2( 1000, 1000 ) -subdivide_width = 10 -subdivide_depth = 10 - -[node name="Preview3d" type="Spatial"] - -[node name="Objects" parent="." instance=ExtResource( 1 )] -transform = Transform( -0.799512, 0, 0.60065, 0, 1, 0, -0.60065, 0, -0.799512, 0, 0, 0 ) - -[node name="CameraPivot" type="Spatial" parent="."] -transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 0, 0 ) - -[node name="Camera" type="Camera" parent="CameraPivot"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.5 ) -environment = SubResource( 4 ) -current = true - -[node name="RemoteTransform" type="RemoteTransform" parent="CameraPivot/Camera"] -remote_path = NodePath("../../../../../../ProjectsPane/BackgroundPreview/Viewport/Camera") - -[node name="ObjectRotate" type="AnimationPlayer" parent="."] -autoplay = "rotate" -playback_speed = 0.1 -anims/rotate = SubResource( 5 ) - -[node name="Environments" type="Spatial" parent="."] - -[node name="Epping Forest" type="Spatial" parent="Environments"] -editor/display_folded = true +[node name="Preview3D" type="ViewportContainer"] visible = false -script = ExtResource( 3 ) -environment = SubResource( 2 ) +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 4.0 +margin_top = 32.0 +margin_right = -4.0 +margin_bottom = -4.0 +rect_min_size = Vector2( 200, 200 ) +mouse_filter = 1 +size_flags_horizontal = 3 +size_flags_vertical = 3 +stretch = true +script = ExtResource( 1 ) -[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Epping Forest"] -transform = Transform( 0.976272, -0.0494319, -0.21083, 0.216548, 0.222856, 0.950496, -8.69534e-009, -0.973597, 0.228272, -5.08826, 21.6274, 5.3744 ) -light_energy = 0.5 -shadow_enabled = true +[node name="MaterialPreview" type="Viewport" parent="."] +size = Vector2( 1272, 684 ) +own_world = true +world = SubResource( 1 ) +handle_input_locally = false +msaa = 2 +render_target_clear_mode = 1 +render_target_update_mode = 0 +physics_object_picking = true -[node name="MeshInstance" type="MeshInstance" parent="Environments/Epping Forest"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -3.3343, 0 ) -visible = false -mesh = SubResource( 6 ) -material/0 = SubResource( 7 ) +[node name="Preview3d" parent="MaterialPreview" instance=ExtResource( 2 )] -[node name="Moonless Golf" type="Spatial" parent="Environments"] -editor/display_folded = true -visible = false -script = ExtResource( 3 ) -environment = SubResource( 4 ) - -[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Moonless Golf"] -transform = Transform( 0.569388, 0.170928, 0.804103, 0.171359, -0.981336, 0.087263, 0.804011, 0.088104, -0.588051, 91.9658, 9.62053, -85.1176 ) -light_energy = 0.2 -shadow_enabled = true - -[node name="Studio" type="Spatial" parent="Environments"] -visible = false -script = ExtResource( 3 ) -environment = ExtResource( 5 ) - -[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Studio"] -transform = Transform( 0.707107, -0.40558, 0.579228, 0, 0.819152, 0.573577, -0.707107, -0.40558, 0.579228, 10, 10, 0 ) -shadow_enabled = true - -[node name="GroundPlane" type="MeshInstance" parent="Environments/Studio"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.05186, 0 ) -mesh = SubResource( 8 ) -material/0 = null +[node name="Preview3DUI" parent="." instance=ExtResource( 3 )] +[connection signal="gui_input" from="." to="." method="on_gui_input"] +[connection signal="resized" from="." to="." method="_on_Preview_resized"] +[connection signal="background_toggled" from="Preview3DUI" to="." method="_on_Background_toggled"] +[connection signal="environment_selected" from="Preview3DUI" to="." method="_on_Environment_item_selected"] +[connection signal="model_selected" from="Preview3DUI" to="." method="_on_Model_item_selected"] +[connection signal="rotate_toggled" from="Preview3DUI" to="." method="_on_Rotate_toggled"] diff --git a/addons/material_maker/preview/preview_3d_scene.tscn b/addons/material_maker/preview/preview_3d_scene.tscn new file mode 100644 index 0000000..05b5692 --- /dev/null +++ b/addons/material_maker/preview/preview_3d_scene.tscn @@ -0,0 +1,121 @@ +[gd_scene load_steps=14 format=2] + +[ext_resource path="res://addons/material_maker/preview/preview_objects.tscn" type="PackedScene" id=1] +[ext_resource path="res://addons/material_maker/preview/panoramas/moonless_golf.hdr" type="Texture" id=2] +[ext_resource path="res://addons/material_maker/environment.gd" type="Script" id=3] +[ext_resource path="res://addons/material_maker/preview/panoramas/epping_forest_01.hdr" type="Texture" id=4] +[ext_resource path="res://addons/material_maker/preview/panoramas/studio_sky.tres" type="Environment" id=5] + +[sub_resource type="PanoramaSky" id=1] +resource_local_to_scene = true +panorama = ExtResource( 2 ) + +[sub_resource type="Environment" id=2] +resource_local_to_scene = true +background_mode = 2 +background_sky = SubResource( 1 ) + +[sub_resource type="Animation" id=3] +loop = true +tracks/0/type = "value" +tracks/0/path = NodePath("Objects:rotation_degrees") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 1 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 0, +"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ] +} + +[sub_resource type="PanoramaSky" id=4] +resource_local_to_scene = true +panorama = ExtResource( 4 ) + +[sub_resource type="Environment" id=5] +background_mode = 2 +background_sky = SubResource( 4 ) +background_energy = 1.5 +ambient_light_color = Color( 1, 1, 1, 1 ) +ambient_light_energy = 0.32 +tonemap_mode = 2 +tonemap_white = 16.0 + +[sub_resource type="CylinderMesh" id=6] +top_radius = 5.0 +bottom_radius = 5.0 +height = 0.5 + +[sub_resource type="SpatialMaterial" id=7] + +[sub_resource type="PlaneMesh" id=8] +size = Vector2( 1000, 1000 ) +subdivide_width = 10 +subdivide_depth = 10 + +[node name="Preview3dScene" type="Spatial"] + +[node name="Objects" parent="." instance=ExtResource( 1 )] +transform = Transform( -0.799512, 0, 0.60065, 0, 1, 0, -0.60065, 0, -0.799512, 0, 0, 0 ) + +[node name="CameraPivot" type="Spatial" parent="."] +transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 0, 0 ) + +[node name="Camera" type="Camera" parent="CameraPivot"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.5 ) +environment = SubResource( 2 ) +current = true + +[node name="RemoteTransform" type="RemoteTransform" parent="CameraPivot/Camera"] +remote_path = NodePath("../../../../../../ProjectsPane/BackgroundPreview/Viewport/Camera") + +[node name="ObjectRotate" type="AnimationPlayer" parent="."] +autoplay = "rotate" +playback_speed = 0.1 +anims/rotate = SubResource( 3 ) + +[node name="Environments" type="Spatial" parent="."] + +[node name="Epping Forest" type="Spatial" parent="Environments"] +editor/display_folded = true +visible = false +script = ExtResource( 3 ) +environment = SubResource( 5 ) + +[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Epping Forest"] +transform = Transform( 0.976272, -0.0494319, -0.21083, 0.216548, 0.222856, 0.950496, -8.69534e-009, -0.973597, 0.228272, -5.08826, 21.6274, 5.3744 ) +light_energy = 0.5 +shadow_enabled = true + +[node name="MeshInstance" type="MeshInstance" parent="Environments/Epping Forest"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -3.3343, 0 ) +visible = false +mesh = SubResource( 6 ) +material/0 = SubResource( 7 ) + +[node name="Moonless Golf" type="Spatial" parent="Environments"] +editor/display_folded = true +visible = false +script = ExtResource( 3 ) +environment = SubResource( 2 ) + +[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Moonless Golf"] +transform = Transform( 0.569388, 0.170928, 0.804103, 0.171359, -0.981336, 0.087263, 0.804011, 0.088104, -0.588051, 91.9658, 9.62053, -85.1176 ) +light_energy = 0.2 +shadow_enabled = true + +[node name="Studio" type="Spatial" parent="Environments"] +visible = false +script = ExtResource( 3 ) +environment = ExtResource( 5 ) + +[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Studio"] +transform = Transform( 0.707107, -0.40558, 0.579228, 0, 0.819152, 0.573577, -0.707107, -0.40558, 0.579228, 10, 10, 0 ) +shadow_enabled = true + +[node name="GroundPlane" type="MeshInstance" parent="Environments/Studio"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.05186, 0 ) +mesh = SubResource( 8 ) +material/0 = null diff --git a/addons/material_maker/preview/preview_3d_ui.gd b/addons/material_maker/preview/preview_3d_ui.gd new file mode 100644 index 0000000..78718e5 --- /dev/null +++ b/addons/material_maker/preview/preview_3d_ui.gd @@ -0,0 +1,34 @@ +tool +extends HBoxContainer + +signal model_selected(id) +signal environment_selected(id) +signal rotate_toggled(b) +signal background_toggled(b) + +func set_models(model_list : Array) -> void: + $Model.clear() + for m in model_list: + $Model.add_item(m) + call_deferred("_on_Model_item_selected", 0) + +func set_environments(environment_list : Array) -> void: + $Environment.clear() + for e in environment_list: + $Environment.add_item(e) + call_deferred("_on_Environment_item_selected", 0) + +func rotation_cancelled() -> void: + $Rotate.pressed = false + +func _on_Model_item_selected(ID) -> void: + emit_signal("model_selected", ID) + +func _on_Environment_item_selected(ID) -> void: + emit_signal("environment_selected", ID) + +func _on_Rotate_toggled(button_pressed) -> void: + emit_signal("rotate_toggled", button_pressed) + +func _on_Background_toggled(button_pressed) -> void: + emit_signal("background_toggled", button_pressed) diff --git a/addons/material_maker/preview/preview_3d_ui.tscn b/addons/material_maker/preview/preview_3d_ui.tscn new file mode 100644 index 0000000..1e7ab55 --- /dev/null +++ b/addons/material_maker/preview/preview_3d_ui.tscn @@ -0,0 +1,53 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/material_maker/preview/preview_3d_ui.gd" type="Script" id=1] + +[node name="Preview3DUI" type="HBoxContainer"] +anchor_right = 1.0 +margin_bottom = 20.0 +size_flags_horizontal = 3 +script = ExtResource( 1 ) + +[node name="Model" type="OptionButton" parent="."] +margin_right = 100.0 +margin_bottom = 20.0 +rect_min_size = Vector2( 100, 0 ) +text = "Cube" +items = [ "Cube", null, false, 0, null, "Cylinder", null, false, 1, null, "Sphere", null, false, 2, null, "Sphere2", null, false, 3, null, "Prism", null, false, 4, null, "Quad", null, false, 5, null, "Plane", null, false, 6, null, "SphereTess", null, false, 7, null ] +selected = 0 + +[node name="Environment" type="OptionButton" parent="."] +margin_left = 104.0 +margin_right = 231.0 +margin_bottom = 20.0 +rect_min_size = Vector2( 100, 0 ) +text = "Epping Forest" +items = [ "Epping Forest", null, false, 0, null, "Moonless Golf", null, false, 1, null, "Studio", null, false, 2, null ] +selected = 0 + +[node name="Rotate" type="Button" parent="."] +margin_left = 235.0 +margin_right = 255.0 +margin_bottom = 20.0 +rect_pivot_offset = Vector2( -4, 7 ) +hint_tooltip = "Rotate object" +size_flags_horizontal = 2 +toggle_mode = true +pressed = true +text = "R" + +[node name="Background" type="Button" parent="."] +margin_left = 1257.0 +margin_right = 1280.0 +margin_bottom = 20.0 +grow_horizontal = 2 +grow_vertical = 2 +rect_pivot_offset = Vector2( -4, 7 ) +hint_tooltip = "Show in main view" +size_flags_horizontal = 8 +toggle_mode = true +text = "O" +[connection signal="item_selected" from="Model" to="." method="_on_Model_item_selected"] +[connection signal="item_selected" from="Environment" to="." method="_on_Environment_item_selected"] +[connection signal="toggled" from="Rotate" to="." method="_on_Rotate_toggled"] +[connection signal="toggled" from="Background" to="." method="_on_Background_toggled"]