Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions material_maker/panels/preview_3d/model_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ var custom_models : PackedStringArray = PackedStringArray()
@onready var SpeedMedium := %Speed_Medium
@onready var SpeedFast := %Speed_Fast

@onready var SnapTop := %SnapTop
@onready var SnapFront := %SnapFront
@onready var SnapRight := %SnapRight

enum SnapView {Top, Front, Right}

func _ready() -> void:
await preview3D.ready
Expand Down Expand Up @@ -43,9 +48,11 @@ func _ready() -> void:
2: SpeedMedium.button_pressed = true
3: SpeedFast.button_pressed = true


func _open() -> void:
pass


func update_model_selector() -> void:
var objects_count : int = preview3D.objects.get_child_count()
Model.clear()
Expand All @@ -55,6 +62,7 @@ func update_model_selector() -> void:
for i in min(custom_models.size(), MAX_CUSTOM_MODELS):
Model.add_item(custom_models[i].get_file(), i+objects_count)


func _on_model_item_selected(index: int, custom_model_path : String = "") -> void:
var objects_count : int = preview3D.objects.get_child_count()
if index >= objects_count:
Expand Down Expand Up @@ -84,8 +92,6 @@ func _on_model_item_selected(index: int, custom_model_path : String = "") -> voi
_on_model_item_selected(0)




func _on_model_configurate_pressed() -> void:
preview3D.configure_model()

Expand All @@ -108,3 +114,36 @@ func _on_speed_medium_toggled(_toggled_on: bool) -> void:
func _on_speed_fast_toggled(_toggled_on: bool) -> void:
mm_globals.set_config(SETTING_3D_PREVIEW_ROTATION_SPEED, 3)
preview3D.set_rotate_model_speed(0.1)


func _process(delta: float) -> void:
var shift_down : bool = Input.is_key_pressed(KEY_SHIFT)
SnapTop.text = "Bottom" if shift_down else "Top"
SnapFront.text = "Back" if shift_down else "Front"
SnapRight.text = "Left" if shift_down else "Right"


func _on_snap_pressed(id: int) -> void:
var tween := get_tree().create_tween()
var pivot := preview3D.get_node("MaterialPreview/Preview3d/ObjectsPivot/Objects")
var cam_control := preview3D.get_node("MaterialPreview/Preview3d/CameraController")
var camrot2 : Node3D = preview3D.camera_controller.camera_rotation2
var camrot1 : Node3D = preview3D.camera_controller.camera_rotation1
var rot2 := camrot2.rotation
var rot1 := Vector3(camrot1.rotation.x, 0.0, camrot2.rotation.z)
match id:
SnapView.Top:
rot2.x = -PI * (-0.5 if Input.is_key_pressed(KEY_SHIFT) else 0.5)
rot1.y = 0.0
SnapView.Front:
rot2.x = 0.0
rot1.y = PI * (1.0 if Input.is_key_pressed(KEY_SHIFT) else 0.0)
SnapView.Right:
rot2.x = 0.0
rot1.y = -PI * (0.5 if Input.is_key_pressed(KEY_SHIFT) else -0.5)
# Snap view
tween.tween_property(camrot2, "rotation", rot2, 0.2).set_trans(Tween.TRANS_CUBIC)
tween.parallel().tween_property(camrot1, "rotation", rot1, 0.2).set_trans(Tween.TRANS_CUBIC)
# Reset center
tween.parallel().tween_property(pivot, "transform:origin", Vector3.ZERO, 0.2).set_trans(Tween.TRANS_CUBIC)
tween.parallel().tween_property(cam_control, "transform:origin", Vector3.ZERO, 0.2).set_trans(Tween.TRANS_CUBIC)
34 changes: 34 additions & 0 deletions material_maker/panels/preview_3d/preview_3d.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,37 @@ button_group = SubResource("ButtonGroup_v4mxh")
icon = SubResource("AtlasTexture_xwjbu")
icon_alignment = 1

[node name="Label" type="Label" parent="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model"]
layout_mode = 2
theme_type_variation = &"MM_PanelMenuSubPanelLabel"
text = "View"

[node name="SnapView" type="HBoxContainer" parent="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model"]
custom_minimum_size = Vector2(190, 0)
layout_mode = 2
size_flags_horizontal = 3

[node name="SnapTop" type="Button" parent="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView"]
unique_name_in_owner = true
custom_minimum_size = Vector2(48, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "Top"

[node name="SnapFront" type="Button" parent="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView"]
unique_name_in_owner = true
custom_minimum_size = Vector2(48, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "Front"

[node name="SnapRight" type="Button" parent="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView"]
unique_name_in_owner = true
custom_minimum_size = Vector2(48, 0)
layout_mode = 2
size_flags_horizontal = 3
text = "Right"

[node name="EnvironmentMenu" type="Button" parent="MainMenu/HBox"]
custom_minimum_size = Vector2(40, 25)
layout_mode = 2
Expand Down Expand Up @@ -445,6 +476,9 @@ text = "Generate Map"
[connection signal="toggled" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/RotationSpeeds/Speed_Slow" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_speed_slow_toggled"]
[connection signal="toggled" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/RotationSpeeds/Speed_Medium" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_speed_medium_toggled"]
[connection signal="toggled" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/RotationSpeeds/Speed_Fast" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_speed_fast_toggled"]
[connection signal="pressed" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView/SnapTop" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_snap_pressed" binds= [0]]
[connection signal="pressed" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView/SnapFront" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_snap_pressed" binds= [1]]
[connection signal="pressed" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView/SnapRight" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_snap_pressed" binds= [2]]
[connection signal="minimum_size_changed" from="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel" to="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel" method="_on_minimum_size_changed"]
[connection signal="pressed" from="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel/VBoxContainer/Box/EnvironmentEditorButton" to="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel" method="_on_environment_editor_button_pressed"]
[connection signal="item_selected" from="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel/VBoxContainer/ScrollContainer/EnvironmentList" to="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel" method="_on_environment_list_item_selected"]
Expand Down
Loading