From b1f355702eadfbd3bea4a7f0eb11668c71c93189 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Tue, 18 Apr 2023 21:04:13 +0300 Subject: [PATCH] Add camera FOV and size to the 3D layers Orthogonal projection is now more usable --- src/Classes/Cel3D.gd | 6 ++++ src/Tools/3DShapeEdit.gd | 19 +++++++++-- src/Tools/3DShapeEdit.tscn | 64 ++++++++++++++++++++++++++++++++++---- 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/src/Classes/Cel3D.gd b/src/Classes/Cel3D.gd index 273cb017d..23efb7ced 100644 --- a/src/Classes/Cel3D.gd +++ b/src/Classes/Cel3D.gd @@ -26,6 +26,8 @@ func _init(_size: Vector2, from_pxo := false, _object_prop := {}, _scene_prop := scene_properties = { "camera_transform": camera_transform, "camera_projection": Camera.PROJECTION_PERSPECTIVE, + "camera_fov": 70.0, + "camera_size": 1.0, "ambient_light_color": Color.black, "ambient_light_energy": 1, } @@ -76,6 +78,8 @@ func serialize_scene_properties() -> Dictionary: return { "camera_transform": camera.transform, "camera_projection": camera.projection, + "camera_fov": camera.fov, + "camera_size": camera.size, "ambient_light_color": viewport.world.environment.ambient_light_color, "ambient_light_energy": viewport.world.environment.ambient_light_energy } @@ -84,6 +88,8 @@ func serialize_scene_properties() -> Dictionary: func deserialize_scene_properties() -> void: camera.transform = scene_properties["camera_transform"] camera.projection = scene_properties["camera_projection"] + camera.fov = scene_properties["camera_fov"] + camera.size = scene_properties["camera_size"] viewport.world.environment.ambient_light_color = scene_properties["ambient_light_color"] viewport.world.environment.ambient_light_energy = scene_properties["ambient_light_energy"] diff --git a/src/Tools/3DShapeEdit.gd b/src/Tools/3DShapeEdit.gd index 86c3298b0..221d0be72 100644 --- a/src/Tools/3DShapeEdit.gd +++ b/src/Tools/3DShapeEdit.gd @@ -34,6 +34,8 @@ onready var load_model_dialog := $LoadModelDialog as FileDialog onready var cel_properties := { "camera:projection": $"%ProjectionOptionButton", "camera:rotation_degrees": $"%CameraRotation", + "camera:fov": $"%CameraFOV", + "camera:size": $"%CameraSize", "viewport:world:environment:ambient_light_color": $"%AmbientColorPickerButton", "viewport:world:environment:ambient_light_energy": $"%AmbientEnergy", } @@ -284,8 +286,7 @@ func _selected_object(object: Cel3DObject) -> void: elif node is ValueSliderV2 and typeof(property) != TYPE_VECTOR2: property_exists = false if node.get_index() > 0: - var prev_node: Control = node.get_parent().get_child(node.get_index() - 1) - prev_node.visible = property_exists + _get_previous_node(node).visible = property_exists node.visible = property_exists mesh_options.visible = object.node3d_type is MeshInstance light_options.visible = object.node3d_type is Light @@ -301,6 +302,16 @@ func _selected_object(object: Cel3DObject) -> void: func _set_cel_node_values() -> void: + if _cel.camera.projection == Camera.PROJECTION_PERSPECTIVE: + _get_previous_node(cel_properties["camera:fov"]).visible = true + _get_previous_node(cel_properties["camera:size"]).visible = false + cel_properties["camera:fov"].visible = true + cel_properties["camera:size"].visible = false + else: + _get_previous_node(cel_properties["camera:size"]).visible = true + _get_previous_node(cel_properties["camera:fov"]).visible = false + cel_properties["camera:size"].visible = true + cel_properties["camera:fov"].visible = false _can_start_timer = false _set_node_values(_cel, cel_properties) _can_start_timer = true @@ -340,6 +351,10 @@ func _set_node_values(to_edit: Object, properties: Dictionary) -> void: node.text = value +func _get_previous_node(node: Node) -> Node: + return node.get_parent().get_child(node.get_index() - 1) + + func _set_value_from_node(to_edit: Object, value, prop: String) -> void: if not is_instance_valid(to_edit): return diff --git a/src/Tools/3DShapeEdit.tscn b/src/Tools/3DShapeEdit.tscn index 2607d5a86..404293c25 100644 --- a/src/Tools/3DShapeEdit.tscn +++ b/src/Tools/3DShapeEdit.tscn @@ -74,12 +74,12 @@ text = "Remove object" unique_name_in_owner = true margin_top = 74.0 margin_right = 223.0 -margin_bottom = 226.0 +margin_bottom = 244.0 size_flags_vertical = 3 [node name="CameraOptions" type="VBoxContainer" parent="CelOptions" index="0"] margin_right = 223.0 -margin_bottom = 128.0 +margin_bottom = 146.0 theme_type_variation = "CollapsibleContainer" script = ExtResource( 6 ) text = "Camera" @@ -88,7 +88,7 @@ visible_content = true [node name="GridContainer" type="GridContainer" parent="CelOptions/CameraOptions" index="1"] margin_top = 24.0 margin_right = 223.0 -margin_bottom = 128.0 +margin_bottom = 146.0 columns = 2 [node name="ProjectionLabel" type="Label" parent="CelOptions/CameraOptions/GridContainer" index="0"] @@ -131,10 +131,62 @@ suffix_x = "°" suffix_y = "°" suffix_z = "°" -[node name="EnvironmentOptions" type="VBoxContainer" parent="CelOptions" index="1"] -margin_top = 132.0 +[node name="CameraFOVLabel" type="Label" parent="CelOptions/CameraOptions/GridContainer" index="4"] +margin_top = 108.0 +margin_right = 110.0 +margin_bottom = 122.0 +text = "FOV:" + +[node name="CameraFOV" type="TextureProgress" parent="CelOptions/CameraOptions/GridContainer" index="5"] +unique_name_in_owner = true +margin_left = 114.0 +margin_top = 108.0 margin_right = 223.0 -margin_bottom = 152.0 +margin_bottom = 122.0 +mouse_default_cursor_shape = 2 +theme_type_variation = "ValueSlider" +min_value = 1.0 +max_value = 179.0 +value = 70.0 +nine_patch_stretch = true +stretch_margin_left = 3 +stretch_margin_top = 3 +stretch_margin_right = 3 +stretch_margin_bottom = 3 +script = ExtResource( 5 ) +suffix = "°" + +[node name="CameraSizeLabel" type="Label" parent="CelOptions/CameraOptions/GridContainer" index="6"] +visible = false +margin_top = 126.0 +margin_right = 110.0 +margin_bottom = 140.0 +text = "Size:" + +[node name="CameraSize" type="TextureProgress" parent="CelOptions/CameraOptions/GridContainer" index="7"] +unique_name_in_owner = true +visible = false +margin_top = 126.0 +margin_right = 110.0 +margin_bottom = 132.0 +mouse_default_cursor_shape = 2 +theme_type_variation = "ValueSlider" +min_value = 0.001 +max_value = 32.0 +step = 0.001 +value = 1.0 +allow_greater = true +nine_patch_stretch = true +stretch_margin_left = 3 +stretch_margin_top = 3 +stretch_margin_right = 3 +stretch_margin_bottom = 3 +script = ExtResource( 5 ) + +[node name="EnvironmentOptions" type="VBoxContainer" parent="CelOptions" index="1"] +margin_top = 150.0 +margin_right = 223.0 +margin_bottom = 170.0 theme_type_variation = "CollapsibleContainer" script = ExtResource( 6 ) text = "Environment"