Skip to content

Commit b177eb2

Browse files
committed
Preview3D axis snap
1 parent 3b18267 commit b177eb2

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

material_maker/panels/preview_3d/model_menu.gd

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ var custom_models : PackedStringArray = PackedStringArray()
1616
@onready var SpeedMedium := %Speed_Medium
1717
@onready var SpeedFast := %Speed_Fast
1818

19+
@onready var SnapTop := %SnapTop
20+
@onready var SnapFront := %SnapFront
21+
@onready var SnapRight := %SnapRight
22+
23+
enum SnapView {Top, Front, Right}
1924

2025
func _ready() -> void:
2126
await preview3D.ready
@@ -43,9 +48,11 @@ func _ready() -> void:
4348
2: SpeedMedium.button_pressed = true
4449
3: SpeedFast.button_pressed = true
4550

51+
4652
func _open() -> void:
4753
pass
4854

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

65+
5866
func _on_model_item_selected(index: int, custom_model_path : String = "") -> void:
5967
var objects_count : int = preview3D.objects.get_child_count()
6068
if index >= objects_count:
@@ -84,8 +92,6 @@ func _on_model_item_selected(index: int, custom_model_path : String = "") -> voi
8492
_on_model_item_selected(0)
8593

8694

87-
88-
8995
func _on_model_configurate_pressed() -> void:
9096
preview3D.configure_model()
9197

@@ -108,3 +114,36 @@ func _on_speed_medium_toggled(_toggled_on: bool) -> void:
108114
func _on_speed_fast_toggled(_toggled_on: bool) -> void:
109115
mm_globals.set_config(SETTING_3D_PREVIEW_ROTATION_SPEED, 3)
110116
preview3D.set_rotate_model_speed(0.1)
117+
118+
119+
func _process(delta: float) -> void:
120+
var shift_down : bool = Input.is_key_pressed(KEY_SHIFT)
121+
if $VBoxContainer/Model/SnapView.get_rect().has_point(get_local_mouse_position()):
122+
SnapTop.text = "Bottom" if shift_down else "Top"
123+
SnapFront.text = "Back" if shift_down else "Front"
124+
SnapRight.text = "Left" if shift_down else "Right"
125+
126+
127+
func _on_snap_pressed(id: int) -> void:
128+
var shift_down : bool = Input.is_key_pressed(KEY_SHIFT)
129+
var tween := get_tree().create_tween()
130+
var pivot := preview3D.get_node("MaterialPreview/Preview3d/ObjectsPivot/Objects")
131+
var cam_control := preview3D.get_node("MaterialPreview/Preview3d/CameraController")
132+
var camrot2 : Node3D = preview3D.camera_controller.camera_rotation2
133+
var camrot1 : Node3D = preview3D.camera_controller.camera_rotation1
134+
var rot2 := camrot2.rotation
135+
var rot1 := Vector3(camrot1.rotation.x, 0.0, camrot2.rotation.z)
136+
match id:
137+
SnapView.Top:
138+
rot2.x = -PI * (-0.5 if shift_down else 0.5)
139+
rot1.y = 0.0
140+
SnapView.Front:
141+
rot2.x = 0.0
142+
rot1.y = PI * (1.0 if shift_down else 0.0)
143+
SnapView.Right:
144+
rot2.x = 0.0
145+
rot1.y = -PI * (0.5 if shift_down else -0.5)
146+
tween.tween_property(camrot2, "rotation", rot2, 0.2).set_trans(Tween.TRANS_CUBIC)
147+
tween.parallel().tween_property(camrot1, "rotation", rot1, 0.2).set_trans(Tween.TRANS_CUBIC)
148+
tween.parallel().tween_property(pivot, "transform:origin", Vector3.ZERO, 0.2).set_trans(Tween.TRANS_CUBIC)
149+
tween.parallel().tween_property(cam_control, "transform:origin", Vector3.ZERO, 0.2).set_trans(Tween.TRANS_CUBIC)

material_maker/panels/preview_3d/preview_3d.tscn

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,37 @@ button_group = SubResource("ButtonGroup_v4mxh")
193193
icon = SubResource("AtlasTexture_xwjbu")
194194
icon_alignment = 1
195195

196+
[node name="Label" type="Label" parent="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model"]
197+
layout_mode = 2
198+
theme_type_variation = &"MM_PanelMenuSubPanelLabel"
199+
text = "View"
200+
201+
[node name="SnapView" type="HBoxContainer" parent="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model"]
202+
custom_minimum_size = Vector2(190, 0)
203+
layout_mode = 2
204+
size_flags_horizontal = 3
205+
206+
[node name="SnapTop" type="Button" parent="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView"]
207+
unique_name_in_owner = true
208+
custom_minimum_size = Vector2(48, 0)
209+
layout_mode = 2
210+
size_flags_horizontal = 3
211+
text = "Top"
212+
213+
[node name="SnapFront" type="Button" parent="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView"]
214+
unique_name_in_owner = true
215+
custom_minimum_size = Vector2(48, 0)
216+
layout_mode = 2
217+
size_flags_horizontal = 3
218+
text = "Front"
219+
220+
[node name="SnapRight" type="Button" parent="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView"]
221+
unique_name_in_owner = true
222+
custom_minimum_size = Vector2(48, 0)
223+
layout_mode = 2
224+
size_flags_horizontal = 3
225+
text = "Right"
226+
196227
[node name="EnvironmentMenu" type="Button" parent="MainMenu/HBox"]
197228
custom_minimum_size = Vector2(40, 25)
198229
layout_mode = 2
@@ -445,6 +476,9 @@ text = "Generate Map"
445476
[connection signal="toggled" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/RotationSpeeds/Speed_Slow" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_speed_slow_toggled"]
446477
[connection signal="toggled" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/RotationSpeeds/Speed_Medium" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_speed_medium_toggled"]
447478
[connection signal="toggled" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/RotationSpeeds/Speed_Fast" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_speed_fast_toggled"]
479+
[connection signal="pressed" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView/SnapTop" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_snap_pressed" binds= [0]]
480+
[connection signal="pressed" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView/SnapFront" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_snap_pressed" binds= [1]]
481+
[connection signal="pressed" from="MainMenu/HBox/ModelMenu/ModelMenuPanel/VBoxContainer/Model/SnapView/SnapRight" to="MainMenu/HBox/ModelMenu/ModelMenuPanel" method="_on_snap_pressed" binds= [2]]
448482
[connection signal="minimum_size_changed" from="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel" to="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel" method="_on_minimum_size_changed"]
449483
[connection signal="pressed" from="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel/VBoxContainer/Box/EnvironmentEditorButton" to="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel" method="_on_environment_editor_button_pressed"]
450484
[connection signal="item_selected" from="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel/VBoxContainer/ScrollContainer/EnvironmentList" to="MainMenu/HBox/EnvironmentMenu/EnvironmentMenuPanel" method="_on_environment_list_item_selected"]

0 commit comments

Comments
 (0)