mirror of
https://github.com/Relintai/mesh_data_resource.git
synced 2024-11-12 10:15:21 +01:00
Added mesh_utils optional dependency. If present you get mesh simplification/optimization - remove doubles + remove doubles interpolate normals for now - options.
This commit is contained in:
parent
d42024d928
commit
02c6802286
@ -7,6 +7,7 @@ The module also comes with importers (gltf, and collada for now), you can import
|
||||
## Optional Dependencies
|
||||
|
||||
`https://github.com/Relintai/props`: If present, you also get a prop importer for MeshDataInstances.
|
||||
`https://github.com/Relintai/mesh_utils`: If present, you get mesh simplification/optimization options at import.
|
||||
|
||||
## Pre-built binaries
|
||||
|
||||
|
3
SCsub
3
SCsub
@ -10,6 +10,9 @@ if os.path.isdir('../texture_packer'):
|
||||
if os.path.isdir('../props'):
|
||||
module_env.Append(CPPDEFINES=['PROPS_PRESENT'])
|
||||
|
||||
if os.path.isdir('../mesh_utils'):
|
||||
module_env.Append(CPPDEFINES=['MESH_UTILS_PRESENT'])
|
||||
|
||||
module_env.add_source_files(env.modules_sources,"register_types.cpp")
|
||||
|
||||
module_env.add_source_files(env.modules_sources,"mesh_data_resource.cpp")
|
||||
|
@ -69,10 +69,27 @@ using PoolVector = Vector<N>;
|
||||
|
||||
#endif
|
||||
|
||||
#if MESH_UTILS_PRESENT
|
||||
#include "../../mesh_utils/mesh_utils.h"
|
||||
#endif
|
||||
|
||||
const String MDRImportPluginBase::BINDING_MDR_IMPORT_TYPE = "Single,Multiple";
|
||||
const String MDRImportPluginBase::BINDING_MDR_OPTIMIZATION_TYPE = "Off"
|
||||
#if MESH_UTILS_PRESENT
|
||||
",Remove Doubles,Remove Doubles Interpolate Normals"
|
||||
#endif
|
||||
;
|
||||
|
||||
void MDRImportPluginBase::get_import_options(List<ImportOption> *r_options, int p_preset) const {
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "import_type", PROPERTY_HINT_ENUM, BINDING_MDR_IMPORT_TYPE), MDRImportPluginBase::MDR_IMPORT_TIME_SINGLE));
|
||||
|
||||
#if MESH_UTILS_PRESENT
|
||||
//Normal remove doubles should be the default if mesh utils present as it shouldn't visibly change the mesh
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "optimization_type", PROPERTY_HINT_ENUM, BINDING_MDR_OPTIMIZATION_TYPE), MDRImportPluginBase::MDR_OPTIMIZATION_REMOVE_DOUBLES));
|
||||
#else
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "optimization_type", PROPERTY_HINT_ENUM, BINDING_MDR_OPTIMIZATION_TYPE), MDRImportPluginBase::MDR_OPTIMIZATION_OFF));
|
||||
#endif
|
||||
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "collider_type", PROPERTY_HINT_ENUM, MeshDataResource::BINDING_STRING_COLLIDER_TYPE), MeshDataResource::COLLIDER_TYPE_NONE));
|
||||
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "offset"), Vector3(0, 0, 0)));
|
||||
@ -127,6 +144,10 @@ int MDRImportPluginBase::get_mesh_count(Node *n) {
|
||||
}
|
||||
|
||||
Error MDRImportPluginBase::process_node_single(Node *n, const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
|
||||
#if MESH_UTILS_PRESENT
|
||||
MDRImportPluginBase::MDROptimizationType optimization_type = static_cast<MDRImportPluginBase::MDROptimizationType>(static_cast<int>(p_options["optimization_type"]));
|
||||
#endif
|
||||
|
||||
MeshDataResource::ColliderType collider_type = static_cast<MeshDataResource::ColliderType>(static_cast<int>(p_options["collider_type"]));
|
||||
|
||||
Vector3 scale = p_options["scale"];
|
||||
@ -141,6 +162,19 @@ Error MDRImportPluginBase::process_node_single(Node *n, const String &p_source_f
|
||||
|
||||
Ref<MeshDataResource> mdr = get_mesh(mi, p_options, collider_type, scale);
|
||||
|
||||
#if MESH_UTILS_PRESENT
|
||||
switch (optimization_type) {
|
||||
case MDR_OPTIMIZATION_OFF:
|
||||
break;
|
||||
case MDR_OPTIMIZATION_REMOVE_DOUBLES:
|
||||
mdr->set_array(MeshUtils::get_singleton()->remove_doubles(mdr->get_array()));
|
||||
break;
|
||||
case MDR_OPTIMIZATION_REMOVE_DOUBLES_INTERPOLATE_NORMALS:
|
||||
mdr->set_array(MeshUtils::get_singleton()->remove_doubles_interpolate_normals(mdr->get_array()));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
ERR_FAIL_COND_V(!mdr.is_valid(), Error::ERR_PARSE_ERROR);
|
||||
|
||||
return ResourceSaver::save(p_save_path + "." + get_save_extension(), mdr);
|
||||
@ -155,6 +189,10 @@ Error MDRImportPluginBase::process_node_single(Node *n, const String &p_source_f
|
||||
}
|
||||
|
||||
Error MDRImportPluginBase::process_node_single_separated_bones(Node *n, const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
|
||||
#if MESH_UTILS_PRESENT
|
||||
MDRImportPluginBase::MDROptimizationType optimization_type = static_cast<MDRImportPluginBase::MDROptimizationType>(static_cast<int>(p_options["optimization_type"]));
|
||||
#endif
|
||||
|
||||
MeshDataResource::ColliderType collider_type = static_cast<MeshDataResource::ColliderType>(static_cast<int>(p_options["collider_type"]));
|
||||
|
||||
Vector3 scale = p_options["scale"];
|
||||
@ -185,6 +223,19 @@ Error MDRImportPluginBase::process_node_single_separated_bones(Node *n, const St
|
||||
if (!mdr.is_valid())
|
||||
continue;
|
||||
|
||||
#if MESH_UTILS_PRESENT
|
||||
switch (optimization_type) {
|
||||
case MDR_OPTIMIZATION_OFF:
|
||||
break;
|
||||
case MDR_OPTIMIZATION_REMOVE_DOUBLES:
|
||||
mdr->set_array(MeshUtils::get_singleton()->remove_doubles(mdr->get_array()));
|
||||
break;
|
||||
case MDR_OPTIMIZATION_REMOVE_DOUBLES_INTERPOLATE_NORMALS:
|
||||
mdr->set_array(MeshUtils::get_singleton()->remove_doubles_interpolate_normals(mdr->get_array()));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
String node_name = c->get_name();
|
||||
node_name = node_name.to_lower();
|
||||
String filename = p_source_file.get_basename() + "_" + node_name + "_" + String::num(j) + "." + get_save_extension();
|
||||
@ -210,6 +261,10 @@ Error MDRImportPluginBase::process_node_single_separated_bones(Node *n, const St
|
||||
}
|
||||
|
||||
Error MDRImportPluginBase::process_node_multi(Node *n, const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata, Ref<MeshDataResourceCollection> coll) {
|
||||
#if MESH_UTILS_PRESENT
|
||||
MDRImportPluginBase::MDROptimizationType optimization_type = static_cast<MDRImportPluginBase::MDROptimizationType>(static_cast<int>(p_options["optimization_type"]));
|
||||
#endif
|
||||
|
||||
MeshDataResource::ColliderType collider_type = static_cast<MeshDataResource::ColliderType>(static_cast<int>(p_options["collider_type"]));
|
||||
|
||||
Vector3 scale = p_options["scale"];
|
||||
@ -224,6 +279,19 @@ Error MDRImportPluginBase::process_node_multi(Node *n, const String &p_source_fi
|
||||
|
||||
Ref<MeshDataResource> mdr = get_mesh(mi, p_options, collider_type, scale);
|
||||
|
||||
#if MESH_UTILS_PRESENT
|
||||
switch (optimization_type) {
|
||||
case MDR_OPTIMIZATION_OFF:
|
||||
break;
|
||||
case MDR_OPTIMIZATION_REMOVE_DOUBLES:
|
||||
mdr->set_array(MeshUtils::get_singleton()->remove_doubles(mdr->get_array()));
|
||||
break;
|
||||
case MDR_OPTIMIZATION_REMOVE_DOUBLES_INTERPOLATE_NORMALS:
|
||||
mdr->set_array(MeshUtils::get_singleton()->remove_doubles_interpolate_normals(mdr->get_array()));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
String node_name = c->get_name();
|
||||
node_name = node_name.to_lower();
|
||||
String filename = p_source_file.get_basename() + "_" + node_name + "." + get_save_extension();
|
||||
|
@ -29,8 +29,8 @@ SOFTWARE.
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/array.h"
|
||||
#else
|
||||
#include "core/ustring.h"
|
||||
#include "core/array.h"
|
||||
#include "core/ustring.h"
|
||||
#endif
|
||||
|
||||
#include "../mesh_data_resource_collection.h"
|
||||
@ -43,7 +43,6 @@ SOFTWARE.
|
||||
|
||||
#include "../mesh_data_resource.h"
|
||||
|
||||
|
||||
#include "core/math/transform.h"
|
||||
|
||||
#include "core/version.h"
|
||||
@ -51,17 +50,15 @@ SOFTWARE.
|
||||
#if VERSION_MAJOR < 4
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
|
||||
|
||||
#if VERSION_MINOR < 4
|
||||
#include "editor/import/editor_scene_importer_gltf.h"
|
||||
#else
|
||||
#include "../../gltf/editor_scene_importer_gltf.h"
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
#include "../../gltf/editor_scene_importer_gltf.h"
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
|
||||
#define MeshInstance MeshInstance3D
|
||||
#endif
|
||||
@ -71,6 +68,7 @@ class MDRImportPluginBase : public EditorImportPlugin {
|
||||
|
||||
public:
|
||||
static const String BINDING_MDR_IMPORT_TYPE;
|
||||
static const String BINDING_MDR_OPTIMIZATION_TYPE;
|
||||
|
||||
enum MDRImportType {
|
||||
MDR_IMPORT_TIME_SINGLE = 0,
|
||||
@ -79,6 +77,14 @@ public:
|
||||
//MDR_IMPORT_TIME_SINGLE_WITH_SEPARATED_BONES,
|
||||
};
|
||||
|
||||
enum MDROptimizationType {
|
||||
MDR_OPTIMIZATION_OFF = 0,
|
||||
#if MESH_UTILS_PRESENT
|
||||
MDR_OPTIMIZATION_REMOVE_DOUBLES,
|
||||
MDR_OPTIMIZATION_REMOVE_DOUBLES_INTERPOLATE_NORMALS,
|
||||
#endif
|
||||
};
|
||||
|
||||
public:
|
||||
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
|
||||
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
|
||||
|
Loading…
Reference in New Issue
Block a user