Skip to content

Commit

Permalink
Implement Request #47 Add .res to open mesh dialog (and also .obj and…
Browse files Browse the repository at this point in the history
… .scn/.gltf to scene open dialog)
  • Loading branch information
dreadpon committed May 3, 2024
1 parent 729b413 commit 28af3e4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,22 @@ func _cleanup():
# Wish we could automatically infer extensions :/
func add_file_dialog_filter():
for accepted_class in accepted_classes:
var extension := "tres"
match accepted_class:
"ArrayMesh":
extension = "mesh"
"PackedScene":
extension = "tscn"
file_dialog.add_filter("*.*%s ; %s" % [extension, accepted_class])
var extensions := ""
var ext_name := ""
var inst = accepted_class.new()

if is_instance_of(inst, Mesh):
extensions = "*.tres, *.res, *.mesh, .*obj"
ext_name = "Mesh"
elif is_instance_of(inst, PackedScene):
extensions = "*.tscn, *.scn, *.gltf"
ext_name = "PackedScene"
elif is_instance_of(inst, Resource):
extensions = "*.tres, *.res"
ext_name = "Resource"

if extensions != "":
file_dialog.add_filter("%s ; %s" % [extensions, ext_name])



Expand Down Expand Up @@ -222,8 +231,8 @@ func on_file_selected(path, thumb):
var res = load(path)

var found_example = false
for accepted_classe in accepted_classes:
if FunLib.obj_is_class_string(res, accepted_classe):
for accepted_class in accepted_classes:
if is_instance_of(res, accepted_class):
found_example = true
break

Expand Down
2 changes: 1 addition & 1 deletion addons/dreadpon.spatial_gardener/greenhouse/greenhouse.gd
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func _create_input_field(_base_control:Control, _resource_previewer, prop:String
"plant_types/greenhouse_plant_states":
var settings := {
"add_create_inst_button": true,
"accepted_classes": ["Greenhouse_PlantState"],
"accepted_classes": [Greenhouse_PlantState],
"element_display_size": 100 * FunLib.get_setting_safe("dreadpons_spatial_gardener/input_and_ui/greenhouse_thumbnail_scale", 1.0),
"element_interaction_flags": UI_IF_ThumbnailArray.PRESET_PLANT_STATE,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ func _create_input_field(_base_control:Control, _resource_previewer, prop:String
match prop:
"mesh":
var settings := {
# Godot really needs a proper class check
"accepted_classes": Globals.MESH_CLASSES,
"accepted_classes": [Mesh],
"element_display_size": 75 * FunLib.get_setting_safe("dreadpons_spatial_gardener/input_and_ui/greenhouse_thumbnail_scale", 1.0),
"element_interaction_flags": UI_IF_ThumbnailArray.PRESET_RESOURCE,
}
input_field = UI_IF_ThumbnailObject.new(mesh, "Mesh", prop, settings)
"spawned_spatial":
var settings := {
"accepted_classes": ["PackedScene"],
"accepted_classes": [PackedScene],
"element_display_size": 75 * FunLib.get_setting_safe("dreadpons_spatial_gardener/input_and_ui/greenhouse_thumbnail_scale", 1.0),
"element_interaction_flags": UI_IF_ThumbnailArray.PRESET_RESOURCE,
}
Expand Down
15 changes: 8 additions & 7 deletions addons/dreadpon.spatial_gardener/greenhouse/greenhouse_plant.gd
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ func _create_input_field(_base_control:Control, _resource_previewer, prop:String
var input_field:UI_InputField = null
match prop:
"mesh/mesh_LOD_variants":
var accepted_classes := ["Greenhouse_LODVariant", "PackedScene"]
accepted_classes.append_array(Globals.MESH_CLASSES)
var accepted_classes := [Greenhouse_LODVariant, PackedScene, Mesh]
var settings := {
"add_create_inst_button": true,
"accepted_classes": accepted_classes,
Expand Down Expand Up @@ -429,11 +428,13 @@ func request_prop_action(prop_action:PropAction):
var new_prop_action = null
if is_instance_of(prop_action.val, PackedScene):
new_prop_action = PA_PropSet.new("spawned_spatial", prop_action.val)
else:
for mesh_class in Globals.MESH_CLASSES:
if FunLib.obj_is_class_string(prop_action.val, mesh_class):
new_prop_action = PA_PropSet.new("mesh", prop_action.val)
break
elif is_instance_of(prop_action.val, Mesh):
new_prop_action = PA_PropSet.new("mesh", prop_action.val)
# else:
# for mesh_class in Globals.MESH_CLASSES:
# if FunLib.obj_is_class_string(prop_action.val, mesh_class):
# new_prop_action = PA_PropSet.new("mesh", prop_action.val)
# break

if new_prop_action != null:
mesh_LOD_variants[prop_action.index].request_prop_action(new_prop_action)
Expand Down
3 changes: 0 additions & 3 deletions addons/dreadpon.spatial_gardener/utility/globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ static func get_err_message(err_code):



# All accepted mesh classes in string format
const MESH_CLASSES:Array = ["ArrayMesh", "CapsuleMesh", "BoxMesh", "CylinderMesh", "PlaneMesh", "PointMesh", "PrismMesh", "QuadMesh", "SphereMesh"]

# Controls per how many units is density calculated
const PLANT_DENSITY_UNITS:int = 100

Expand Down

0 comments on commit 28af3e4

Please sign in to comment.