mirror of
https://github.com/Relintai/mesh_data_resource.git
synced 2024-11-12 10:15:21 +01:00
Add a prop processor for PropDataMeshInstances. Also moved PropDataMesh into this module.
This commit is contained in:
parent
eb3c654998
commit
601cabc63f
7
SCsub
7
SCsub
@ -4,10 +4,12 @@ Import('env')
|
|||||||
|
|
||||||
module_env = env.Clone()
|
module_env = env.Clone()
|
||||||
|
|
||||||
|
|
||||||
if os.path.isdir('../texture_packer'):
|
if os.path.isdir('../texture_packer'):
|
||||||
module_env.Append(CPPDEFINES=['TEXTURE_PACKER_PRESENT'])
|
module_env.Append(CPPDEFINES=['TEXTURE_PACKER_PRESENT'])
|
||||||
|
|
||||||
|
if os.path.isdir('../props'):
|
||||||
|
module_env.Append(CPPDEFINES=['PROPS_PRESENT'])
|
||||||
|
|
||||||
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")
|
||||||
@ -19,3 +21,6 @@ module_env.add_source_files(env.modules_sources,"plugin_gltf/editor_import_gltf_
|
|||||||
module_env.add_source_files(env.modules_sources,"plugin_gltf/editor_plugin_gltf_mdr.cpp")
|
module_env.add_source_files(env.modules_sources,"plugin_gltf/editor_plugin_gltf_mdr.cpp")
|
||||||
|
|
||||||
module_env.add_source_files(env.modules_sources,"nodes/mesh_data_instance.cpp")
|
module_env.add_source_files(env.modules_sources,"nodes/mesh_data_instance.cpp")
|
||||||
|
|
||||||
|
module_env.add_source_files(env.modules_sources,"props/mesh_data_instance_processor.cpp")
|
||||||
|
module_env.add_source_files(env.modules_sources,"props/prop_data_mesh.cpp")
|
||||||
|
@ -12,6 +12,9 @@ def get_doc_classes():
|
|||||||
return [
|
return [
|
||||||
"MeshDataResource",
|
"MeshDataResource",
|
||||||
"MeshDataInstance",
|
"MeshDataInstance",
|
||||||
|
|
||||||
|
"MeshDataInstanceProcessor",
|
||||||
|
"PropDataMesh",
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_doc_path():
|
def get_doc_path():
|
||||||
|
35
props/mesh_data_instance_processor.cpp
Normal file
35
props/mesh_data_instance_processor.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include "mesh_data_instance_processor.h"
|
||||||
|
|
||||||
|
#if PROPS_PRESENT
|
||||||
|
|
||||||
|
#include "../nodes/mesh_data_instance.h"
|
||||||
|
#include "prop_data_mesh.h"
|
||||||
|
|
||||||
|
bool MeshDataInstanceProcessor::_handles(Node *node) {
|
||||||
|
MeshDataInstance *i = Object::cast_to<MeshDataInstance>(node);
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeshDataInstanceProcessor::_process(Ref<PropData> prop_data, Node *node, const Transform &transform) {
|
||||||
|
MeshDataInstance *i = Object::cast_to<MeshDataInstance>(node);
|
||||||
|
|
||||||
|
ERR_FAIL_COND(!i);
|
||||||
|
|
||||||
|
Ref<PropDataMesh> m;
|
||||||
|
m.instance();
|
||||||
|
m->set_mesh(i->get_mesh_data());
|
||||||
|
m->set_texture(i->get_texture());
|
||||||
|
m->set_transform(transform * i->get_transform());
|
||||||
|
prop_data->add_prop(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
MeshDataInstanceProcessor::MeshDataInstanceProcessor() {
|
||||||
|
}
|
||||||
|
MeshDataInstanceProcessor::~MeshDataInstanceProcessor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeshDataInstanceProcessor::_bind_methods() {
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
57
props/mesh_data_instance_processor.h
Normal file
57
props/mesh_data_instance_processor.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
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 PROP_MESH_DATA_INSTANCE_PROCESSOR_H
|
||||||
|
#define PROP_MESH_DATA_INSTANCE_PROCESSOR_H
|
||||||
|
|
||||||
|
#if PROPS_PRESENT
|
||||||
|
|
||||||
|
#include "../../props/processor/prop_data_processor.h"
|
||||||
|
|
||||||
|
#include "core/version.h"
|
||||||
|
#include "scene/resources/texture.h"
|
||||||
|
|
||||||
|
#include "core/math/vector3.h"
|
||||||
|
|
||||||
|
#include "../mesh_data_resource.h"
|
||||||
|
|
||||||
|
class PropInstance;
|
||||||
|
|
||||||
|
class MeshDataInstanceProcessor : public PropDataProcessor {
|
||||||
|
GDCLASS(MeshDataInstanceProcessor, PropDataProcessor);
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool _handles(Node *node);
|
||||||
|
void _process(Ref<PropData> prop_data, Node *node, const Transform &transform);
|
||||||
|
|
||||||
|
MeshDataInstanceProcessor();
|
||||||
|
~MeshDataInstanceProcessor();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void _bind_methods();
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
82
props/prop_data_mesh.cpp
Normal file
82
props/prop_data_mesh.cpp
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
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 "prop_data_mesh.h"
|
||||||
|
|
||||||
|
#if PROPS_PRESENT
|
||||||
|
|
||||||
|
Ref<MeshDataResource> PropDataMesh::get_mesh() const {
|
||||||
|
return _mesh;
|
||||||
|
}
|
||||||
|
void PropDataMesh::set_mesh(const Ref<MeshDataResource> mesh) {
|
||||||
|
_mesh = mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Texture> PropDataMesh::get_texture() const {
|
||||||
|
return _texture;
|
||||||
|
}
|
||||||
|
void PropDataMesh::set_texture(const Ref<Texture> texture) {
|
||||||
|
_texture = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PropDataMesh::get_snap_to_mesh() {
|
||||||
|
return _snap_to_mesh;
|
||||||
|
}
|
||||||
|
void PropDataMesh::set_snap_to_mesh(bool value) {
|
||||||
|
_snap_to_mesh = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 PropDataMesh::get_snap_axis() {
|
||||||
|
return _snap_axis;
|
||||||
|
}
|
||||||
|
void PropDataMesh::set_snap_axis(Vector3 value) {
|
||||||
|
_snap_axis = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PropDataMesh::PropDataMesh() {
|
||||||
|
_snap_to_mesh = false;
|
||||||
|
_snap_axis = Vector3(0, 1, 0);
|
||||||
|
}
|
||||||
|
PropDataMesh::~PropDataMesh() {
|
||||||
|
if (_mesh.is_valid())
|
||||||
|
_mesh.unref();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropDataMesh::_bind_methods() {
|
||||||
|
ClassDB::bind_method(D_METHOD("get_mesh"), &PropDataMesh::get_mesh);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_mesh", "value"), &PropDataMesh::set_mesh);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"), "set_mesh", "get_mesh");
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_texture"), &PropDataMesh::get_texture);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_texture", "value"), &PropDataMesh::set_texture);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropDataMesh::get_snap_to_mesh);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropDataMesh::set_snap_to_mesh);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_snap_axis"), &PropDataMesh::get_snap_axis);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &PropDataMesh::set_snap_axis);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
66
props/prop_data_mesh.h
Normal file
66
props/prop_data_mesh.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
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 PROP_DATA_MESH_H
|
||||||
|
#define PROP_DATA_MESH_H
|
||||||
|
|
||||||
|
#if PROPS_PRESENT
|
||||||
|
|
||||||
|
#include "../../props/props/prop_data_entry.h"
|
||||||
|
#include "core/math/vector3.h"
|
||||||
|
|
||||||
|
#include "scene/resources/texture.h"
|
||||||
|
|
||||||
|
#include "../mesh_data_resource.h"
|
||||||
|
|
||||||
|
class PropDataMesh : public PropDataEntry {
|
||||||
|
GDCLASS(PropDataMesh, PropDataEntry);
|
||||||
|
|
||||||
|
public:
|
||||||
|
Ref<MeshDataResource> get_mesh() const;
|
||||||
|
void set_mesh(const Ref<MeshDataResource> mesh);
|
||||||
|
|
||||||
|
Ref<Texture> get_texture() const;
|
||||||
|
void set_texture(const Ref<Texture> texture);
|
||||||
|
|
||||||
|
bool get_snap_to_mesh();
|
||||||
|
void set_snap_to_mesh(bool value);
|
||||||
|
|
||||||
|
Vector3 get_snap_axis();
|
||||||
|
void set_snap_axis(Vector3 value);
|
||||||
|
|
||||||
|
PropDataMesh();
|
||||||
|
~PropDataMesh();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void _bind_methods();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _snap_to_mesh;
|
||||||
|
Vector3 _snap_axis;
|
||||||
|
Ref<MeshDataResource> _mesh;
|
||||||
|
Ref<Texture> _texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -33,11 +33,24 @@ SOFTWARE.
|
|||||||
#include "plugin_gltf/editor_plugin_gltf_mdr.h"
|
#include "plugin_gltf/editor_plugin_gltf_mdr.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if PROPS_PRESENT
|
||||||
|
#include "../props/singleton/prop_utils.h"
|
||||||
|
#include "props/mesh_data_instance_processor.h"
|
||||||
|
#include "props/prop_data_mesh.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
void register_mesh_data_resource_types() {
|
void register_mesh_data_resource_types() {
|
||||||
ClassDB::register_class<MeshDataResource>();
|
ClassDB::register_class<MeshDataResource>();
|
||||||
|
|
||||||
ClassDB::register_class<MeshDataInstance>();
|
ClassDB::register_class<MeshDataInstance>();
|
||||||
|
|
||||||
|
#if PROPS_PRESENT
|
||||||
|
ClassDB::register_class<PropDataMesh>();
|
||||||
|
ClassDB::register_class<MeshDataInstanceProcessor>();
|
||||||
|
Ref<PropDataProcessor> processor = memnew(MeshDataInstanceProcessor);
|
||||||
|
PropUtils::add_processor(processor);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
EditorPlugins::add_by_type<EditorPluginColladaMdr>();
|
EditorPlugins::add_by_type<EditorPluginColladaMdr>();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user