From c9c5b5d7c2a238310ce7bde336f76d2d1b6f9f29 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Sat, 15 Jan 2022 16:29:02 +0100 Subject: moved shapes to loading area & fixed asset paths --- addons/voxel-core/engine/importers/meshes.gd | 108 ++++++++++++++++++++ .../voxel-core/engine/importers/voxel_objects.gd | 112 +++++++++++++++++++++ addons/voxel-core/engine/importers/voxel_sets.gd | 66 ++++++++++++ 3 files changed, 286 insertions(+) create mode 100644 addons/voxel-core/engine/importers/meshes.gd create mode 100644 addons/voxel-core/engine/importers/voxel_objects.gd create mode 100644 addons/voxel-core/engine/importers/voxel_sets.gd (limited to 'addons/voxel-core/engine/importers') diff --git a/addons/voxel-core/engine/importers/meshes.gd b/addons/voxel-core/engine/importers/meshes.gd new file mode 100644 index 0000000..8b2dbbd --- /dev/null +++ b/addons/voxel-core/engine/importers/meshes.gd @@ -0,0 +1,108 @@ +tool +extends EditorImportPlugin +# Import files as static Mesh Resource, not to be confused with VoxelObjects + + + +## Enums +enum Presets { DEFAULT } + + + +## Built-In Virtual Methods +func get_visible_name() -> String: + return "MeshOfVoxels" + + +func get_importer_name() -> String: + return "VoxelCore.MeshOfVoxels" + + +func get_recognized_extensions() -> Array: + return [ + "png", "jpg", + "vox", + #"qb", + #"qbt", + #"vxm", + ] + + +func get_resource_type() -> String: + return "Mesh" + + +func get_save_extension() -> String: + return "mesh" + + +func get_preset_count() -> int: + return Presets.size() + + +func get_preset_name(preset : int) -> String: + match preset: + Presets.DEFAULT: + return "Default" + _: + return "Unknown" + + +func get_import_options(preset : int) -> Array: + var preset_options = [ + { + "name": "mesh_mode", + "default_value": VoxelMesh.MeshModes.GREEDY, + "property_hint": PROPERTY_HINT_ENUM, + "hint_string": PoolStringArray(VoxelMesh.MeshModes.keys()).join(","), + "usage": PROPERTY_USAGE_EDITOR, + }, + { + "name": "center", + "default_value": 0, + "property_hint": PROPERTY_HINT_ENUM, + "hint_string": "NONE,CENTER,CENTER_ABOVE_AXIS", + "usage": PROPERTY_USAGE_EDITOR, + }, + ] + + match preset: + Presets.DEFAULT: + pass + + return preset_options + + +func get_option_visibility(option : String, options : Dictionary) -> bool: + return true + + +func import(source_file : String, save_path : String, options : Dictionary, r_platform_variants : Array, r_gen_files : Array) -> int: + var read := Reader.read_file(source_file) + var error = read.get("error", FAILED) + if error == OK: + var voxel_mesh = VoxelMesh.new() + voxel_mesh.voxel_set = VoxelSet.new() + + voxel_mesh.set_mesh_mode(options.get("mesh_mode", VoxelMesh.MeshModes.GREEDY)) + voxel_mesh.voxel_set.set_voxels(read["palette"]) + for voxel_position in read["voxels"]: + voxel_mesh.set_voxel(voxel_position, read["voxels"][voxel_position]) + + var center = options.get("center", 0) + if center > 0: + match center: + 1: + center = Vector3(0.5, 0.5, 0.5) + 2: + center = Vector3(0.5, 1.0, 0.5) + voxel_mesh.center(center) + + voxel_mesh.update_mesh() + + error = ResourceSaver.save( + '%s.%s' % [save_path, get_save_extension()], + voxel_mesh.mesh) + + voxel_mesh.free() + return error diff --git a/addons/voxel-core/engine/importers/voxel_objects.gd b/addons/voxel-core/engine/importers/voxel_objects.gd new file mode 100644 index 0000000..e1f2f48 --- /dev/null +++ b/addons/voxel-core/engine/importers/voxel_objects.gd @@ -0,0 +1,112 @@ +tool +extends EditorImportPlugin +# Import files as VoxelObjects + + +## Enums +enum Presets { DEFAULT } + + + +## Built-In Virtual Methods +func get_visible_name() -> String: + return "VoxelObject" + + +func get_importer_name() -> String: + return "VoxelCore.VoxelObject" + + +func get_recognized_extensions() -> Array: + return [ + "png", "jpg", + "vox", + #"qb", + #"qbt", + #"vxm", + ] + + +func get_resource_type() -> String: + return "PackedScene" + + +func get_save_extension() -> String: + return "tscn" + + +func get_preset_count() -> int: + return Presets.size() + + +func get_preset_name(preset : int) -> String: + match preset: + Presets.DEFAULT: + return "Default" + _: + return "Unknown" + + +func get_import_options(preset : int) -> Array: + var preset_options = [ + { + "name": "name", + "default_value": "", + "usage": PROPERTY_USAGE_EDITOR, + }, + { + "name": "voxel_object", + "default_value": 0, + "property_hint": PROPERTY_HINT_ENUM, + "hint_string": "DETECT,VOXEL_MESH", + "usage": PROPERTY_USAGE_EDITOR, + }, + { + "name": "mesh_mode", + "default_value": VoxelMesh.MeshModes.NAIVE, + "property_hint": PROPERTY_HINT_ENUM, + "hint_string": PoolStringArray(VoxelMesh.MeshModes.keys()).join(","), + "usage": PROPERTY_USAGE_EDITOR, + }, + { + "name": "center", + "default_value": 0, + "property_hint": PROPERTY_HINT_ENUM, + "hint_string": "NONE,CENTER,CENTER_ABOVE_AXIS", + "usage": PROPERTY_USAGE_EDITOR, + }, + ] + + return preset_options + + +func get_option_visibility(option : String, options : Dictionary) -> bool: + return true + + +func import(source_file : String, save_path : String, options : Dictionary, r_platform_variants : Array, r_gen_files : Array) -> int: + var voxel_object + match options.get("voxel_object", 0): + _: voxel_object = VoxelMesh.new() + var error = voxel_object.load_file(source_file) + if error == OK: + voxel_object.set_name(source_file.get_file().replace("." + source_file.get_extension(), "") if options["name"].empty() else options["name"]) + voxel_object.set_mesh_mode(options.get("mesh_mode", VoxelMesh.MeshModes.NAIVE)) + + var center = options.get("center", 0) + if center > 0: + match center: + 1: + center = Vector3(0.5, 0.5, 0.5) + 2: + center = Vector3(0.5, 1.0, 0.5) + voxel_object.center(center) + + voxel_object.update_mesh() + + var scene = PackedScene.new() + error = scene.pack(voxel_object) + if error == OK: + error = ResourceSaver.save("%s.%s" % [save_path, get_save_extension()], scene) + voxel_object.free() + return error diff --git a/addons/voxel-core/engine/importers/voxel_sets.gd b/addons/voxel-core/engine/importers/voxel_sets.gd new file mode 100644 index 0000000..fc560b4 --- /dev/null +++ b/addons/voxel-core/engine/importers/voxel_sets.gd @@ -0,0 +1,66 @@ +tool +extends EditorImportPlugin + + + +## Enums +enum Presets { DEFAULT } + + + +## Built-In Virtual Methods +func get_visible_name() -> String: + return "VoxelSet" + + +func get_importer_name() -> String: + return "VoxelCore.VoxelSet" + + +func get_recognized_extensions() -> Array: + return [ + "png", "jpg", + "vox", + "gpl", + ] + + +func get_resource_type() -> String: + return "Resource" + + +func get_save_extension() -> String: + return "tres" + + +func get_preset_count() -> int: + return Presets.size() + + +func get_preset_name(preset : int) -> String: + match preset: + Presets.DEFAULT: + return "Default" + _: + return "Unknown" + + +func get_import_options(preset : int) -> Array: + var preset_options = [ + + ] + + return preset_options + + +func get_option_visibility(option : String, options : Dictionary) -> bool: + return true + + +func import(source_file : String, save_path : String, options : Dictionary, r_platform_variants : Array, r_gen_files : Array) -> int: + var voxel_set := VoxelSet.new() + var error = voxel_set.load_file(source_file) + if error == OK: + voxel_set.request_refresh() + error = ResourceSaver.save("%s.%s" % [save_path, get_save_extension()], voxel_set) + return error -- cgit v1.2.3-54-g00ecf