mirror of
https://github.com/Relintai/mesh_data_resource.git
synced 2025-02-20 17:14:31 +01:00
Now the importer can handle files with multiple meshes in them.
This commit is contained in:
parent
515a3b250f
commit
2c1508e616
1
SCsub
1
SCsub
@ -13,6 +13,7 @@ if os.path.isdir('../props'):
|
|||||||
module_env.add_source_files(env.modules_sources,"register_types.cpp")
|
module_env.add_source_files(env.modules_sources,"register_types.cpp")
|
||||||
|
|
||||||
module_env.add_source_files(env.modules_sources,"mesh_data_resource.cpp")
|
module_env.add_source_files(env.modules_sources,"mesh_data_resource.cpp")
|
||||||
|
module_env.add_source_files(env.modules_sources,"mesh_data_resource_collection.cpp")
|
||||||
|
|
||||||
module_env.add_source_files(env.modules_sources,"plugin/mdr_import_plugin_base.cpp")
|
module_env.add_source_files(env.modules_sources,"plugin/mdr_import_plugin_base.cpp")
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ SOFTWARE.
|
|||||||
#include "scene/resources/shape.h"
|
#include "scene/resources/shape.h"
|
||||||
|
|
||||||
class MeshDataResource : public Resource {
|
class MeshDataResource : public Resource {
|
||||||
|
|
||||||
GDCLASS(MeshDataResource, Resource);
|
GDCLASS(MeshDataResource, Resource);
|
||||||
RES_BASE_EXTENSION("mdres");
|
RES_BASE_EXTENSION("mdres");
|
||||||
|
|
||||||
|
65
mesh_data_resource_collection.cpp
Normal file
65
mesh_data_resource_collection.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2020 Péter Magyar
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mesh_data_resource_collection.h"
|
||||||
|
|
||||||
|
#include "core/version.h"
|
||||||
|
|
||||||
|
void MeshDataResourceCollection::add_mdr(Ref<MeshDataResource> mdr) {
|
||||||
|
_mdrs.push_back(mdr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<Variant> MeshDataResourceCollection::get_mdrs() {
|
||||||
|
Vector<Variant> r;
|
||||||
|
for (int i = 0; i < _mdrs.size(); i++) {
|
||||||
|
#if VERSION_MAJOR < 4
|
||||||
|
r.push_back(_mdrs[i].get_ref_ptr());
|
||||||
|
#else
|
||||||
|
r.push_back(_mdrs[i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
void MeshDataResourceCollection::set_mdrs(const Vector<Variant> &p_arrays) {
|
||||||
|
_mdrs.clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < p_arrays.size(); ++i) {
|
||||||
|
Ref<MeshDataResource> e = Ref<MeshDataResource>(p_arrays[i]);
|
||||||
|
|
||||||
|
_mdrs.push_back(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MeshDataResourceCollection::MeshDataResourceCollection() {
|
||||||
|
}
|
||||||
|
|
||||||
|
MeshDataResourceCollection::~MeshDataResourceCollection() {
|
||||||
|
_mdrs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeshDataResourceCollection::_bind_methods() {
|
||||||
|
ClassDB::bind_method(D_METHOD("add_mdr", "mdr"), &MeshDataResourceCollection::add_mdr);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_mdrs"), &MeshDataResourceCollection::get_mdrs);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_mdrs", "array"), &MeshDataResourceCollection::set_mdrs);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "mdrs"), "set_mdrs", "get_mdrs");
|
||||||
|
}
|
51
mesh_data_resource_collection.h
Normal file
51
mesh_data_resource_collection.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2020 Péter Magyar
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MESH_DATA_REOURCE_COLLECTION_H
|
||||||
|
#define MESH_DATA_REOURCE_COLLECTION_H
|
||||||
|
|
||||||
|
#include "core/resource.h"
|
||||||
|
|
||||||
|
#include "core/vector.h"
|
||||||
|
|
||||||
|
#include "mesh_data_resource.h"
|
||||||
|
|
||||||
|
class MeshDataResourceCollection : public Resource {
|
||||||
|
GDCLASS(MeshDataResourceCollection, Resource);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void add_mdr(Ref<MeshDataResource> mdr);
|
||||||
|
|
||||||
|
Vector<Variant> get_mdrs();
|
||||||
|
void set_mdrs(const Vector<Variant> &p_arrays);
|
||||||
|
|
||||||
|
MeshDataResourceCollection();
|
||||||
|
~MeshDataResourceCollection();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void _bind_methods();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Vector<Ref<MeshDataResource> > _mdrs;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -30,7 +30,10 @@ SOFTWARE.
|
|||||||
#include "scene/resources/shape.h"
|
#include "scene/resources/shape.h"
|
||||||
#include "scene/resources/sphere_shape.h"
|
#include "scene/resources/sphere_shape.h"
|
||||||
|
|
||||||
|
const String MDRImportPluginBase::BINDING_MDR_IMPORT_TYPE = "Single,Single Merged,Multiple";
|
||||||
|
|
||||||
void MDRImportPluginBase::get_import_options(List<ImportOption> *r_options, int p_preset) const {
|
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));
|
||||||
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::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)));
|
r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "offset"), Vector3(0, 0, 0)));
|
||||||
@ -44,6 +47,29 @@ bool MDRImportPluginBase::get_option_visibility(const String &p_option, const Ma
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Error MDRImportPluginBase::process_node(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) {
|
||||||
|
MDRImportPluginBase::MDRImportType type = static_cast<MDRImportPluginBase::MDRImportType>(static_cast<int>(p_options["import_type"]));
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case MDR_IMPORT_TIME_SINGLE: {
|
||||||
|
return process_node_single(n, p_source_file, p_save_path, p_options, r_platform_variants, r_gen_files, r_metadata);
|
||||||
|
}
|
||||||
|
case MDR_IMPORT_TIME_SINGLE_MERGED: {
|
||||||
|
ERR_FAIL_V_MSG(Error::ERR_UNAVAILABLE, "import type Single Merged is not yet implemented! " + p_source_file);
|
||||||
|
}
|
||||||
|
case MDR_IMPORT_TIME_MULTIPLE: {
|
||||||
|
Ref<MeshDataResourceCollection> coll;
|
||||||
|
coll.instance();
|
||||||
|
|
||||||
|
process_node_multi(n, p_source_file, p_save_path, p_options, r_platform_variants, r_gen_files, r_metadata, coll);
|
||||||
|
|
||||||
|
return ResourceSaver::save(p_save_path + "." + get_save_extension(), coll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error::ERR_PARSE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
int MDRImportPluginBase::get_mesh_count(Node *n) {
|
int MDRImportPluginBase::get_mesh_count(Node *n) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
@ -79,12 +105,16 @@ Error MDRImportPluginBase::process_node_single(Node *n, const String &p_source_f
|
|||||||
|
|
||||||
return ResourceSaver::save(p_save_path + "." + get_save_extension(), mdr);
|
return ResourceSaver::save(p_save_path + "." + get_save_extension(), mdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process_node_single(c, p_source_file, p_save_path, p_options, r_platform_variants, r_gen_files, r_metadata) == Error::OK) {
|
||||||
|
return Error::OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Error::ERR_PARSE_ERROR;
|
return Error::ERR_PARSE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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) {
|
||||||
MeshDataResource::ColliderType collider_type = static_cast<MeshDataResource::ColliderType>(static_cast<int>(p_options["collider_type"]));
|
MeshDataResource::ColliderType collider_type = static_cast<MeshDataResource::ColliderType>(static_cast<int>(p_options["collider_type"]));
|
||||||
|
|
||||||
Vector3 scale = p_options["scale"];
|
Vector3 scale = p_options["scale"];
|
||||||
@ -103,14 +133,20 @@ Error MDRImportPluginBase::process_node_multi(Node *n, const String &p_source_fi
|
|||||||
|
|
||||||
node_name = node_name.to_lower();
|
node_name = node_name.to_lower();
|
||||||
|
|
||||||
Error err = ResourceSaver::save(p_save_path + "_" + node_name + "." + get_save_extension(), mdr);
|
String filename = p_source_file.get_basename() + "_" + node_name + "." + get_save_extension();
|
||||||
|
|
||||||
|
Error err = ResourceSaver::save(filename, mdr);
|
||||||
|
|
||||||
|
Ref<MeshDataResource> mdrl = ResourceLoader::load(filename);
|
||||||
|
|
||||||
|
coll->add_mdr(mdrl);
|
||||||
|
|
||||||
if (err != Error::OK) {
|
if (err != Error::OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process_node_multi(c, p_source_file, p_save_path, p_options, r_platform_variants, r_gen_files, r_metadata);
|
process_node_multi(c, p_source_file, p_save_path, p_options, r_platform_variants, r_gen_files, r_metadata, coll);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Error::OK;
|
return Error::OK;
|
||||||
|
@ -23,6 +23,7 @@ SOFTWARE.
|
|||||||
#ifndef MDR_IMPORT_PLUGIN_BASE
|
#ifndef MDR_IMPORT_PLUGIN_BASE
|
||||||
#define MDR_IMPORT_PLUGIN_BASE
|
#define MDR_IMPORT_PLUGIN_BASE
|
||||||
|
|
||||||
|
#include "../mesh_data_resource_collection.h"
|
||||||
#include "core/array.h"
|
#include "core/array.h"
|
||||||
#include "core/io/resource_saver.h"
|
#include "core/io/resource_saver.h"
|
||||||
#include "core/math/basis.h"
|
#include "core/math/basis.h"
|
||||||
@ -48,16 +49,26 @@ SOFTWARE.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
class MDRImportPluginBase : public EditorImportPlugin {
|
class MDRImportPluginBase : public EditorImportPlugin {
|
||||||
|
|
||||||
GDCLASS(MDRImportPluginBase, EditorImportPlugin);
|
GDCLASS(MDRImportPluginBase, EditorImportPlugin);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static const String BINDING_MDR_IMPORT_TYPE;
|
||||||
|
|
||||||
|
enum MDRImportType {
|
||||||
|
MDR_IMPORT_TIME_SINGLE = 0,
|
||||||
|
MDR_IMPORT_TIME_SINGLE_MERGED,
|
||||||
|
MDR_IMPORT_TIME_MULTIPLE,
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
|
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;
|
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
|
||||||
|
|
||||||
|
Error process_node(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 = NULL, Variant *r_metadata = NULL);
|
||||||
|
|
||||||
int get_mesh_count(Node *n);
|
int get_mesh_count(Node *n);
|
||||||
Error 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 = NULL, Variant *r_metadata = NULL);
|
Error 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);
|
||||||
Error 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 = NULL, Variant *r_metadata = NULL);
|
Error 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);
|
||||||
Ref<MeshDataResource> get_mesh(MeshInstance *mi, const Map<StringName, Variant> &p_options, MeshDataResource::ColliderType collider_type, Vector3 scale);
|
Ref<MeshDataResource> get_mesh(MeshInstance *mi, const Map<StringName, Variant> &p_options, MeshDataResource::ColliderType collider_type, Vector3 scale);
|
||||||
|
|
||||||
Array apply_transforms(Array &array, const Map<StringName, Variant> &p_options);
|
Array apply_transforms(Array &array, const Map<StringName, Variant> &p_options);
|
||||||
|
@ -70,7 +70,7 @@ Error EditorImportGLTFMdr::import(const String &p_source_file, const String &p_s
|
|||||||
|
|
||||||
ERR_FAIL_COND_V(!n, Error::ERR_PARSE_ERROR);
|
ERR_FAIL_COND_V(!n, Error::ERR_PARSE_ERROR);
|
||||||
|
|
||||||
Error err = process_node_single(n, p_source_file, p_save_path, p_options, r_platform_variants, r_gen_files, r_metadata);
|
Error err = process_node(n, p_source_file, p_save_path, p_options, r_platform_variants, r_gen_files, r_metadata);
|
||||||
|
|
||||||
n->queue_delete();
|
n->queue_delete();
|
||||||
return err;
|
return err;
|
||||||
|
@ -23,6 +23,7 @@ SOFTWARE.
|
|||||||
#include "register_types.h"
|
#include "register_types.h"
|
||||||
|
|
||||||
#include "mesh_data_resource.h"
|
#include "mesh_data_resource.h"
|
||||||
|
#include "mesh_data_resource_collection.h"
|
||||||
#include "nodes/mesh_data_instance.h"
|
#include "nodes/mesh_data_instance.h"
|
||||||
|
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
@ -40,6 +41,7 @@ SOFTWARE.
|
|||||||
|
|
||||||
void register_mesh_data_resource_types() {
|
void register_mesh_data_resource_types() {
|
||||||
ClassDB::register_class<MeshDataResource>();
|
ClassDB::register_class<MeshDataResource>();
|
||||||
|
ClassDB::register_class<MeshDataResourceCollection>();
|
||||||
|
|
||||||
ClassDB::register_class<MeshDataInstance>();
|
ClassDB::register_class<MeshDataInstance>();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user