Cleaned up and added GLTF helper methods to the build.

This commit is contained in:
Relintai 2022-08-08 00:20:08 +02:00
parent 4090cb34d7
commit 435a59947a
10 changed files with 63 additions and 41 deletions

View File

@ -6,9 +6,11 @@ Import("env_modules")
env_gltf = env_modules.Clone() env_gltf = env_modules.Clone()
# Godot source files # Godot source files
env_gltf.add_source_files(env.modules_sources, "*.cpp") env_gltf.add_source_files(env.modules_sources, "register_types.cpp")
#env_gltf.add_source_files(env.modules_sources, "*.cpp")
env_gltf.add_source_files(env.modules_sources, "extensions/*.cpp") env_gltf.add_source_files(env.modules_sources, "extensions/*.cpp")
env_gltf.add_source_files(env.modules_sources, "structures/*.cpp") env_gltf.add_source_files(env.modules_sources, "structures/*.cpp")
if env["tools"]: #if env["tools"]:
env_gltf.add_source_files(env.modules_sources, "editor/*.cpp") # env_gltf.add_source_files(env.modules_sources, "editor/*.cpp")

View File

@ -45,11 +45,11 @@ void GLTFLight::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_outer_cone_angle", "outer_cone_angle"), &GLTFLight::set_outer_cone_angle); ClassDB::bind_method(D_METHOD("set_outer_cone_angle", "outer_cone_angle"), &GLTFLight::set_outer_cone_angle);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); // Color ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); // Color
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "intensity"), "set_intensity", "get_intensity"); // float ADD_PROPERTY(PropertyInfo(Variant::REAL, "intensity"), "set_intensity", "get_intensity"); // float
ADD_PROPERTY(PropertyInfo(Variant::STRING, "light_type"), "set_light_type", "get_light_type"); // String ADD_PROPERTY(PropertyInfo(Variant::STRING, "light_type"), "set_light_type", "get_light_type"); // String
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "range"), "set_range", "get_range"); // float ADD_PROPERTY(PropertyInfo(Variant::REAL, "range"), "set_range", "get_range"); // float
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inner_cone_angle"), "set_inner_cone_angle", "get_inner_cone_angle"); // float ADD_PROPERTY(PropertyInfo(Variant::REAL, "inner_cone_angle"), "set_inner_cone_angle", "get_inner_cone_angle"); // float
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "outer_cone_angle"), "set_outer_cone_angle", "get_outer_cone_angle"); // float ADD_PROPERTY(PropertyInfo(Variant::REAL, "outer_cone_angle"), "set_outer_cone_angle", "get_outer_cone_angle"); // float
} }
Color GLTFLight::get_color() { Color GLTFLight::get_color() {

View File

@ -31,9 +31,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "core/hash_set.h"
#include "core/array.h" #include "core/array.h"
#include "core/dictionary.h" #include "core/dictionary.h"
#include "core/hash_set.h"
namespace GLTFTemplateConvert { namespace GLTFTemplateConvert {
template <class T> template <class T>
@ -75,8 +75,9 @@ static void set_from_array(HashSet<T> &r_out, const Array &p_inp) {
template <class K, class V> template <class K, class V>
static Dictionary to_dict(const HashMap<K, V> &p_inp) { static Dictionary to_dict(const HashMap<K, V> &p_inp) {
Dictionary ret; Dictionary ret;
for (const KeyValue<K, V> &E : p_inp) { const K *key = NULL;
ret[E.key] = E.value; while ((key = p_inp.next(key))) {
ret[*key] = p_inp[*key];
} }
return ret; return ret;
} }

View File

@ -32,20 +32,6 @@
#ifndef _3D_DISABLED #ifndef _3D_DISABLED
void register_gltf_types() {
}
void unregister_gltf_types() {
}
/*
#include "extensions/gltf_light.h"
#include "extensions/gltf_spec_gloss.h"
#include "gltf_document.h"
#include "gltf_document_extension.h"
#include "gltf_document_extension_convert_importer_mesh.h"
#include "gltf_state.h"
#include "structures/gltf_accessor.h" #include "structures/gltf_accessor.h"
#include "structures/gltf_animation.h" #include "structures/gltf_animation.h"
#include "structures/gltf_buffer_view.h" #include "structures/gltf_buffer_view.h"
@ -56,6 +42,40 @@ void unregister_gltf_types() {
#include "structures/gltf_skin.h" #include "structures/gltf_skin.h"
#include "structures/gltf_texture.h" #include "structures/gltf_texture.h"
#include "extensions/gltf_light.h"
#include "extensions/gltf_spec_gloss.h"
void register_gltf_types() {
ClassDB::register_class<GLTFAccessor>();
ClassDB::register_class<GLTFAnimation>();
ClassDB::register_class<GLTFBufferView>();
ClassDB::register_class<GLTFCamera>();
ClassDB::register_class<GLTFMesh>();
ClassDB::register_class<GLTFNode>();
ClassDB::register_class<GLTFSkeleton>();
ClassDB::register_class<GLTFSkin>();
ClassDB::register_class<GLTFTexture>();
ClassDB::register_class<GLTFSpecGloss>();
ClassDB::register_class<GLTFLight>();
//ClassDB::register_class<GLTFDocument>();
//ClassDB::register_class<GLTFDocumentExtension>();
//ClassDB::register_class<GLTFDocumentExtensionConvertImporterMesh>();
//ClassDB::register_class<GLTFState>();
}
void unregister_gltf_types() {
}
/*
#include "gltf_document.h"
#include "gltf_document_extension.h"
#include "gltf_document_extension_convert_importer_mesh.h"
#include "gltf_state.h"
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
#include "core/project_settings.h" #include "core/project_settings.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"

View File

@ -124,19 +124,19 @@ void GLTFAccessor::set_type(int p_type) {
type = (GLTFType)p_type; // TODO: Register enum type = (GLTFType)p_type; // TODO: Register enum
} }
Vector<double> GLTFAccessor::get_min() { PoolRealArray GLTFAccessor::get_min() {
return min; return min;
} }
void GLTFAccessor::set_min(Vector<double> p_min) { void GLTFAccessor::set_min(const PoolRealArray &p_min) {
min = p_min; min = p_min;
} }
Vector<double> GLTFAccessor::get_max() { PoolRealArray GLTFAccessor::get_max() {
return max; return max;
} }
void GLTFAccessor::set_max(Vector<double> p_max) { void GLTFAccessor::set_max(const PoolRealArray &p_max) {
max = p_max; max = p_max;
} }

View File

@ -46,8 +46,8 @@ private:
bool normalized = false; bool normalized = false;
int count = 0; int count = 0;
GLTFType type = GLTFType::TYPE_SCALAR; GLTFType type = GLTFType::TYPE_SCALAR;
Vector<double> min; PoolRealArray min;
Vector<double> max; PoolRealArray max;
int sparse_count = 0; int sparse_count = 0;
int sparse_indices_buffer_view = 0; int sparse_indices_buffer_view = 0;
int sparse_indices_byte_offset = 0; int sparse_indices_byte_offset = 0;
@ -77,11 +77,11 @@ public:
int get_type(); int get_type();
void set_type(int p_type); void set_type(int p_type);
Vector<double> get_min(); PoolRealArray get_min();
void set_min(Vector<double> p_min); void set_min(const PoolRealArray &p_min);
Vector<double> get_max(); PoolRealArray get_max();
void set_max(Vector<double> p_max); void set_max(const PoolRealArray &p_max);
int get_sparse_count(); int get_sparse_count();
void set_sparse_count(int p_sparse_count); void set_sparse_count(int p_sparse_count);

View File

@ -30,8 +30,6 @@
#include "gltf_buffer_view.h" #include "gltf_buffer_view.h"
#include "../gltf_document_extension.h"
void GLTFBufferView::_bind_methods() { void GLTFBufferView::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_buffer"), &GLTFBufferView::get_buffer); ClassDB::bind_method(D_METHOD("get_buffer"), &GLTFBufferView::get_buffer);
ClassDB::bind_method(D_METHOD("set_buffer", "buffer"), &GLTFBufferView::set_buffer); ClassDB::bind_method(D_METHOD("set_buffer", "buffer"), &GLTFBufferView::set_buffer);

View File

@ -41,7 +41,7 @@ void GLTFMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_instance_materials", "instance_materials"), &GLTFMesh::set_instance_materials); ClassDB::bind_method(D_METHOD("set_instance_materials", "instance_materials"), &GLTFMesh::set_instance_materials);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh"), "set_mesh", "get_mesh"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh"), "set_mesh", "get_mesh");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT32_ARRAY, "blend_weights"), "set_blend_weights", "get_blend_weights"); // Vector<float> ADD_PROPERTY(PropertyInfo(Variant::POOL_REAL_ARRAY, "blend_weights"), "set_blend_weights", "get_blend_weights"); // Vector<float>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "instance_materials"), "set_instance_materials", "get_instance_materials"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "instance_materials"), "set_instance_materials", "get_instance_materials");
} }

View File

@ -33,6 +33,7 @@
#include "../gltf_defines.h" #include "../gltf_defines.h"
#include "core/resource.h" #include "core/resource.h"
#include "core/hash_set.h"
class GLTFSkeleton : public Resource { class GLTFSkeleton : public Resource {
GDCLASS(GLTFSkeleton, Resource); GDCLASS(GLTFSkeleton, Resource);

View File

@ -133,10 +133,10 @@ void GLTFSkin::set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i) {
Dictionary GLTFSkin::get_joint_i_to_name() { Dictionary GLTFSkin::get_joint_i_to_name() {
Dictionary ret; Dictionary ret;
HashMap<int, StringName>::Iterator elem = joint_i_to_name.begin();
while (elem) { const int *key = NULL;
ret[elem->key] = String(elem->value); while ((key = joint_i_to_name.next(key))) {
++elem; ret[*key] = String(joint_i_to_name[*key]);
} }
return ret; return ret;
} }