mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-02-20 17:14:44 +01:00
Moved MeshDataResource to it's own module. This module will now detect it's presence.
This commit is contained in:
parent
897c051982
commit
e9a7a92fb2
5
SCsub
5
SCsub
@ -1,8 +1,13 @@
|
||||
import os
|
||||
|
||||
Import('env')
|
||||
|
||||
if ARGUMENTS.get('entities_2d', 'no') == 'yes':
|
||||
env.Append(CPPDEFINES=['ENTITIES_2D'])
|
||||
|
||||
if os.path.isdir('../mesh_data_resource'):
|
||||
env.Append(CPPDEFINES=['MESH_DATA_RESOURCE_PRESENT'])
|
||||
|
||||
module_env = env.Clone()
|
||||
|
||||
module_env.add_source_files(env.modules_sources,"register_types.cpp")
|
||||
|
@ -7,12 +7,14 @@ void ItemVisualEntry::set_override_layer(ItemEnums::EntityTextureLayers layer) {
|
||||
_override_layer = layer;
|
||||
}
|
||||
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
Ref<MeshDataResource> ItemVisualEntry::get_mesh(int index) {
|
||||
return _mesh[index];
|
||||
}
|
||||
void ItemVisualEntry::set_mesh(int index, Ref<MeshDataResource> mesh) {
|
||||
_mesh[index] = mesh;
|
||||
}
|
||||
#endif
|
||||
|
||||
Ref<Texture> ItemVisualEntry::get_texture(int index) {
|
||||
return _texture[index];
|
||||
@ -50,7 +52,10 @@ ItemVisualEntry::ItemVisualEntry() {
|
||||
|
||||
ItemVisualEntry::~ItemVisualEntry() {
|
||||
for (int i = 0; i < EntityEnums::GENDER_COUNT; ++i) {
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
_mesh[i].unref();
|
||||
#endif
|
||||
|
||||
_texture[i].unref();
|
||||
}
|
||||
|
||||
@ -62,10 +67,12 @@ void ItemVisualEntry::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_override_layer", "value"), &ItemVisualEntry::set_override_layer);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "override_layer", PROPERTY_HINT_ENUM, ItemEnums::BINDING_STRING_ENTITY_TEXTURE_LAYERS), "set_override_layer", "get_override_layer");
|
||||
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
ClassDB::bind_method(D_METHOD("get_mesh", "index"), &ItemVisualEntry::get_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_mesh", "index", "value"), &ItemVisualEntry::set_mesh);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "mesh_male", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"), "set_mesh", "get_mesh", EntityEnums::GENDER_MALE);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "mesh_female", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"), "set_mesh", "get_mesh", EntityEnums::GENDER_FEMALE);
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_texture", "index"), &ItemVisualEntry::get_texture);
|
||||
ClassDB::bind_method(D_METHOD("set_texture", "index", "value"), &ItemVisualEntry::set_texture);
|
||||
@ -85,4 +92,4 @@ void ItemVisualEntry::_bind_methods() {
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::VECTOR3, "effect_offset_male"), "set_effect_offset", "get_effect_offset", EntityEnums::GENDER_MALE);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::VECTOR3, "effect_offset_female"), "set_effect_offset", "get_effect_offset", EntityEnums::GENDER_FEMALE);
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -11,7 +11,10 @@
|
||||
|
||||
#include "scene/resources/packed_scene.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "../meshes/mesh_data_resource.h"
|
||||
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
#include "../../mesh_data_resource/mesh_data_resource.h"
|
||||
#endif
|
||||
|
||||
class ItemVisualEntry : public Resource {
|
||||
GDCLASS(ItemVisualEntry, Resource);
|
||||
@ -20,8 +23,10 @@ public:
|
||||
ItemEnums::EntityTextureLayers get_override_layer();
|
||||
void set_override_layer(ItemEnums::EntityTextureLayers layer);
|
||||
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
Ref<MeshDataResource> get_mesh(int index);
|
||||
void set_mesh(int index, Ref<MeshDataResource> mesh);
|
||||
#endif
|
||||
|
||||
Ref<Texture> get_texture(int index);
|
||||
void set_texture(int index, Ref<Texture> texture);
|
||||
@ -44,7 +49,9 @@ protected:
|
||||
private:
|
||||
ItemEnums::EntityTextureLayers _override_layer;
|
||||
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
Ref<MeshDataResource> _mesh[EntityEnums::GENDER_COUNT];
|
||||
#endif
|
||||
|
||||
Ref<Texture> _texture[EntityEnums::GENDER_COUNT];
|
||||
Color _color;
|
||||
|
@ -1,142 +0,0 @@
|
||||
#include "editor_import_collada_mdr.h"
|
||||
|
||||
String EditorImportColladaMdr::get_importer_name() const {
|
||||
return "collada_mdr";
|
||||
}
|
||||
|
||||
String EditorImportColladaMdr::get_visible_name() const {
|
||||
return "Collada MDR";
|
||||
}
|
||||
|
||||
void EditorImportColladaMdr::get_recognized_extensions(List<String> *p_extensions) const {
|
||||
p_extensions->push_back("dae");
|
||||
}
|
||||
|
||||
String EditorImportColladaMdr::get_save_extension() const {
|
||||
return "res";
|
||||
}
|
||||
|
||||
String EditorImportColladaMdr::get_resource_type() const {
|
||||
return "MeshDataResource";
|
||||
}
|
||||
|
||||
float EditorImportColladaMdr::get_priority() const {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
int EditorImportColladaMdr::get_preset_count() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String EditorImportColladaMdr::get_preset_name(int p_idx) const {
|
||||
return "";
|
||||
}
|
||||
|
||||
void EditorImportColladaMdr::get_import_options(List<ImportOption> *r_options, int p_preset) const {
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "offset"), Vector3(0, 0, 0)));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "rotation"), Vector3(0, 0, -(3.141592 / 2.0))));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "scale"), Vector3(0.011, 0.011, 0.011)));
|
||||
}
|
||||
|
||||
bool EditorImportColladaMdr::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
Error EditorImportColladaMdr::import(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) {
|
||||
Node *n = _importer->import_scene(p_source_file, 0, 15);
|
||||
|
||||
if (n == NULL) {
|
||||
n->queue_delete();
|
||||
return Error::ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n->get_child_count(); ++i) {
|
||||
Node *c = n->get_child(i);
|
||||
print_error(String::num(i));
|
||||
|
||||
if (c == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Object::cast_to<MeshInstance>(c)) {
|
||||
MeshInstance *mi = Object::cast_to<MeshInstance>(c);
|
||||
|
||||
Ref<ArrayMesh> mesh = mi->get_mesh();
|
||||
|
||||
if (mesh.is_valid()) {
|
||||
Ref<MeshDataResource> mdr;
|
||||
mdr.instance();
|
||||
|
||||
Array arrays = mesh->surface_get_arrays(0);
|
||||
|
||||
mdr->set_array(apply_transforms(arrays, p_options));
|
||||
|
||||
n->queue_delete();
|
||||
|
||||
return ResourceSaver::save(p_save_path + "." + get_save_extension(), mdr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
n->queue_delete();
|
||||
return Error::ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
Array EditorImportColladaMdr::apply_transforms(Array &array, const Map<StringName, Variant> &p_options) {
|
||||
Vector3 offset = p_options["offset"];
|
||||
Vector3 rotation = p_options["rotation"];
|
||||
Vector3 scale = p_options["scale"];
|
||||
|
||||
Transform transform = Transform(Basis(rotation).scaled(scale), offset);
|
||||
|
||||
Array verts = array.get(Mesh::ARRAY_VERTEX);
|
||||
|
||||
for (int i = 0; i < verts.size(); ++i) {
|
||||
Vector3 vert = verts[i];
|
||||
|
||||
vert = transform.xform(vert);
|
||||
|
||||
verts.set(i, (vert));
|
||||
}
|
||||
|
||||
Array normals = array.get(Mesh::ARRAY_NORMAL);
|
||||
|
||||
for (int i = 0; i < normals.size(); ++i) {
|
||||
Vector3 normal = normals[i];
|
||||
|
||||
normal = transform.basis.xform(normal);
|
||||
|
||||
normals.set(i, normal);
|
||||
}
|
||||
|
||||
Array tangents = array.get(Mesh::ARRAY_TANGENT);
|
||||
|
||||
if (tangents.size() == verts.size() * 4) {
|
||||
|
||||
for (int i = 0; i < verts.size(); ++i) {
|
||||
|
||||
Plane p(tangents[i * 4 + 0], tangents[i * 4 + 1], tangents[i * 4 + 2], tangents[i * 4 + 3]);
|
||||
|
||||
Vector3 tangent = p.normal;
|
||||
|
||||
tangent = transform.basis.xform(tangent);
|
||||
|
||||
tangents.set(i, tangent);
|
||||
}
|
||||
}
|
||||
|
||||
array.set(Mesh::ARRAY_VERTEX, verts);
|
||||
array.set(Mesh::ARRAY_NORMAL, normals);
|
||||
array.set(Mesh::ARRAY_TANGENT, tangents);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
EditorImportColladaMdr::EditorImportColladaMdr() {
|
||||
_importer.instance();
|
||||
}
|
||||
|
||||
EditorImportColladaMdr::~EditorImportColladaMdr() {
|
||||
_importer.unref();
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
|
||||
#ifndef EDITOR_IMPORT_COLLADA_MDR
|
||||
#define EDITOR_IMPORT_COLLADA_MDR
|
||||
|
||||
#include "editor/import/editor_import_plugin.h"
|
||||
#include "core/ustring.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
#include "core/io/resource_saver.h"
|
||||
#include "core/array.h"
|
||||
#include "core/math/basis.h"
|
||||
#include "core/math/transform.h"
|
||||
|
||||
#include "mesh_data_resource.h"
|
||||
#include "editor/import/editor_import_collada.h"
|
||||
|
||||
class EditorImportColladaMdr : public EditorImportPlugin {
|
||||
|
||||
GDCLASS(EditorImportColladaMdr, EditorImportPlugin);
|
||||
|
||||
public:
|
||||
virtual String get_importer_name() const;
|
||||
virtual String get_visible_name() const;
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
||||
virtual String get_save_extension() const;
|
||||
virtual String get_resource_type() const;
|
||||
virtual float get_priority() const;
|
||||
|
||||
virtual int get_preset_count() const;
|
||||
virtual String get_preset_name(int p_idx) 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 Error import(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);
|
||||
|
||||
Array apply_transforms(Array &array, const Map<StringName, Variant> &p_options);
|
||||
|
||||
EditorImportColladaMdr();
|
||||
~EditorImportColladaMdr();
|
||||
|
||||
private:
|
||||
Ref<EditorSceneImporterCollada> _importer;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
#include "editor_plugin_collada_mdr.h"
|
||||
|
||||
void EditorPluginColladaMdr::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
_importer.instance();
|
||||
|
||||
add_import_plugin(_importer);
|
||||
|
||||
break;
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
remove_import_plugin(_importer);
|
||||
|
||||
_importer.unref();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EditorPluginColladaMdr::EditorPluginColladaMdr(EditorNode *node) {
|
||||
_node = node;
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
|
||||
#ifndef EDITOR_PLUGIN_COLLADA_MDR
|
||||
#define EDITOR_PLUGIN_COLLADA_MDR
|
||||
|
||||
#include "editor/editor_plugin.h"
|
||||
#include "core/ustring.h"
|
||||
|
||||
#include "editor_import_collada_mdr.h"
|
||||
|
||||
class EditorPluginColladaMdr : public EditorPlugin {
|
||||
|
||||
GDCLASS(EditorPluginColladaMdr, EditorPlugin);
|
||||
|
||||
public:
|
||||
EditorPluginColladaMdr(EditorNode *node);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
private:
|
||||
EditorNode *_node;
|
||||
Ref<EditorImportColladaMdr> _importer;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,20 +0,0 @@
|
||||
#include "mesh_data_resource.h"
|
||||
|
||||
Array MeshDataResource::get_array() {
|
||||
return _arrays;
|
||||
}
|
||||
void MeshDataResource::set_array(const Array &p_arrays) {
|
||||
_arrays.clear();
|
||||
|
||||
_arrays = p_arrays.duplicate(true);
|
||||
}
|
||||
|
||||
MeshDataResource::MeshDataResource() {
|
||||
|
||||
}
|
||||
|
||||
void MeshDataResource::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_array"), &MeshDataResource::get_array);
|
||||
ClassDB::bind_method(D_METHOD("set_array", "array"), &MeshDataResource::set_array);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "array"), "set_array", "get_array");
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
#ifndef MESH_DATA_REOURCE_H
|
||||
#define MESH_DATA_REOURCE_H
|
||||
|
||||
#include "core/resource.h"
|
||||
#include "core/array.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
|
||||
class MeshDataResource : public Resource {
|
||||
|
||||
GDCLASS(MeshDataResource, Resource);
|
||||
RES_BASE_EXTENSION("mdres");
|
||||
|
||||
public:
|
||||
Array get_array();
|
||||
void set_array(const Array &p_arrays);
|
||||
|
||||
MeshDataResource();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Array _arrays;
|
||||
};
|
||||
|
||||
#endif
|
@ -88,8 +88,6 @@
|
||||
#include "utility/cooldown.h"
|
||||
#include "utility/category_cooldown.h"
|
||||
|
||||
#include "meshes/mesh_data_resource.h"
|
||||
|
||||
#include "loot/loot_data_base.h"
|
||||
#include "loot/loot_data_item.h"
|
||||
#include "loot/loot_data_container.h"
|
||||
@ -115,13 +113,6 @@
|
||||
#include "profile_manager/class_profile.h"
|
||||
#include "profile_manager/profile_manager.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "editor/editor_plugin.h"
|
||||
|
||||
#include "meshes/editor_plugin_collada_mdr.h"
|
||||
#endif
|
||||
|
||||
|
||||
void register_entity_spell_system_types() {
|
||||
ClassDB::register_class<SpellEnums>();
|
||||
|
||||
@ -235,9 +226,6 @@ void register_entity_spell_system_types() {
|
||||
|
||||
ClassDB::register_class<AIFormation>();
|
||||
|
||||
//meshes
|
||||
ClassDB::register_class<MeshDataResource>();
|
||||
|
||||
//ProfileManager
|
||||
ClassDB::register_class<InputProfileModifier>();
|
||||
ClassDB::register_class<InputProfileModifierEntry>();
|
||||
@ -249,10 +237,6 @@ void register_entity_spell_system_types() {
|
||||
|
||||
ClassDB::register_class<ClassProfile>();
|
||||
ClassDB::register_class<ProfileManager>();
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
EditorPlugins::add_by_type<EditorPluginColladaMdr>();
|
||||
#endif
|
||||
}
|
||||
|
||||
void unregister_entity_spell_system_types() {
|
||||
|
Loading…
Reference in New Issue
Block a user