initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled

This commit is contained in:
2025-09-16 20:46:46 -04:00
commit 9d30169a8d
13378 changed files with 7050105 additions and 0 deletions

View File

@@ -0,0 +1,124 @@
/**************************************************************************/
/* gltf_accessor.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 DISABLE_DEPRECATED
// 32-bit versions for compatibility.
GLTFBufferViewIndex GLTFAccessor::_get_buffer_view_bind_compat_106220() {
return get_buffer_view();
}
int GLTFAccessor::_get_byte_offset_bind_compat_106220() {
return get_byte_offset();
}
int GLTFAccessor::_get_component_type_bind_compat_106220() {
return (int)get_component_type();
}
void GLTFAccessor::_set_component_type_bind_compat_106220(int p_component_type) {
set_component_type((GLTFComponentType)p_component_type);
}
bool GLTFAccessor::_get_normalized_bind_compat_106220() {
return get_normalized();
}
int GLTFAccessor::_get_count_bind_compat_106220() {
return get_count();
}
GLTFAccessor::GLTFAccessorType GLTFAccessor::_get_accessor_type_bind_compat_106220() {
return get_accessor_type();
}
int GLTFAccessor::_get_type_bind_compat_106220() {
return (int)get_accessor_type();
}
Vector<double> GLTFAccessor::_get_min_bind_compat_106220() {
return get_min();
}
Vector<double> GLTFAccessor::_get_max_bind_compat_106220() {
return get_max();
}
int GLTFAccessor::_get_sparse_count_bind_compat_106220() {
return get_sparse_count();
}
int GLTFAccessor::_get_sparse_indices_buffer_view_bind_compat_106220() {
return get_sparse_indices_buffer_view();
}
int GLTFAccessor::_get_sparse_indices_byte_offset_bind_compat_106220() {
return get_sparse_indices_byte_offset();
}
int GLTFAccessor::_get_sparse_indices_component_type_bind_compat_106220() {
return (int)get_sparse_indices_component_type();
}
void GLTFAccessor::_set_sparse_indices_component_type_bind_compat_106220(int p_sparse_indices_component_type) {
set_sparse_indices_component_type((GLTFComponentType)p_sparse_indices_component_type);
}
int GLTFAccessor::_get_sparse_values_buffer_view_bind_compat_106220() {
return get_sparse_values_buffer_view();
}
int GLTFAccessor::_get_sparse_values_byte_offset_bind_compat_106220() {
return get_sparse_values_byte_offset();
}
void GLTFAccessor::_bind_compatibility_methods() {
// 32-bit versions for compatibility.
ClassDB::bind_compatibility_method(D_METHOD("get_buffer_view"), &GLTFAccessor::_get_buffer_view_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_byte_offset"), &GLTFAccessor::_get_byte_offset_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_component_type"), &GLTFAccessor::_get_component_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("set_component_type", "component_type"), &GLTFAccessor::_set_component_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_normalized"), &GLTFAccessor::_get_normalized_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_count"), &GLTFAccessor::_get_count_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_accessor_type"), &GLTFAccessor::_get_accessor_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_type"), &GLTFAccessor::_get_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_min"), &GLTFAccessor::_get_min_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_max"), &GLTFAccessor::_get_max_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_count"), &GLTFAccessor::_get_sparse_count_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_indices_buffer_view"), &GLTFAccessor::_get_sparse_indices_buffer_view_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_indices_byte_offset"), &GLTFAccessor::_get_sparse_indices_byte_offset_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_indices_component_type"), &GLTFAccessor::_get_sparse_indices_component_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("set_sparse_indices_component_type", "sparse_indices_component_type"), &GLTFAccessor::_set_sparse_indices_component_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_values_buffer_view"), &GLTFAccessor::_get_sparse_values_buffer_view_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_values_byte_offset"), &GLTFAccessor::_get_sparse_values_byte_offset_bind_compat_106220);
}
#endif // DISABLE_DEPRECATED

View File

@@ -0,0 +1,222 @@
/**************************************************************************/
/* gltf_accessor.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_accessor.h"
#include "gltf_accessor.compat.inc"
void GLTFAccessor::_bind_methods() {
BIND_ENUM_CONSTANT(TYPE_SCALAR);
BIND_ENUM_CONSTANT(TYPE_VEC2);
BIND_ENUM_CONSTANT(TYPE_VEC3);
BIND_ENUM_CONSTANT(TYPE_VEC4);
BIND_ENUM_CONSTANT(TYPE_MAT2);
BIND_ENUM_CONSTANT(TYPE_MAT3);
BIND_ENUM_CONSTANT(TYPE_MAT4);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_NONE);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_SIGNED_BYTE);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_UNSIGNED_BYTE);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_SIGNED_SHORT);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_UNSIGNED_SHORT);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_SIGNED_INT);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_UNSIGNED_INT);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_SINGLE_FLOAT);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_DOUBLE_FLOAT);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_HALF_FLOAT);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_SIGNED_LONG);
BIND_ENUM_CONSTANT(COMPONENT_TYPE_UNSIGNED_LONG);
ClassDB::bind_method(D_METHOD("get_buffer_view"), &GLTFAccessor::get_buffer_view);
ClassDB::bind_method(D_METHOD("set_buffer_view", "buffer_view"), &GLTFAccessor::set_buffer_view);
ClassDB::bind_method(D_METHOD("get_byte_offset"), &GLTFAccessor::get_byte_offset);
ClassDB::bind_method(D_METHOD("set_byte_offset", "byte_offset"), &GLTFAccessor::set_byte_offset);
ClassDB::bind_method(D_METHOD("get_component_type"), &GLTFAccessor::get_component_type);
ClassDB::bind_method(D_METHOD("set_component_type", "component_type"), &GLTFAccessor::set_component_type);
ClassDB::bind_method(D_METHOD("get_normalized"), &GLTFAccessor::get_normalized);
ClassDB::bind_method(D_METHOD("set_normalized", "normalized"), &GLTFAccessor::set_normalized);
ClassDB::bind_method(D_METHOD("get_count"), &GLTFAccessor::get_count);
ClassDB::bind_method(D_METHOD("set_count", "count"), &GLTFAccessor::set_count);
ClassDB::bind_method(D_METHOD("get_accessor_type"), &GLTFAccessor::get_accessor_type);
ClassDB::bind_method(D_METHOD("set_accessor_type", "accessor_type"), &GLTFAccessor::set_accessor_type);
ClassDB::bind_method(D_METHOD("get_type"), &GLTFAccessor::get_type);
ClassDB::bind_method(D_METHOD("set_type", "type"), &GLTFAccessor::set_type);
ClassDB::bind_method(D_METHOD("get_min"), &GLTFAccessor::get_min);
ClassDB::bind_method(D_METHOD("set_min", "min"), &GLTFAccessor::set_min);
ClassDB::bind_method(D_METHOD("get_max"), &GLTFAccessor::get_max);
ClassDB::bind_method(D_METHOD("set_max", "max"), &GLTFAccessor::set_max);
ClassDB::bind_method(D_METHOD("get_sparse_count"), &GLTFAccessor::get_sparse_count);
ClassDB::bind_method(D_METHOD("set_sparse_count", "sparse_count"), &GLTFAccessor::set_sparse_count);
ClassDB::bind_method(D_METHOD("get_sparse_indices_buffer_view"), &GLTFAccessor::get_sparse_indices_buffer_view);
ClassDB::bind_method(D_METHOD("set_sparse_indices_buffer_view", "sparse_indices_buffer_view"), &GLTFAccessor::set_sparse_indices_buffer_view);
ClassDB::bind_method(D_METHOD("get_sparse_indices_byte_offset"), &GLTFAccessor::get_sparse_indices_byte_offset);
ClassDB::bind_method(D_METHOD("set_sparse_indices_byte_offset", "sparse_indices_byte_offset"), &GLTFAccessor::set_sparse_indices_byte_offset);
ClassDB::bind_method(D_METHOD("get_sparse_indices_component_type"), &GLTFAccessor::get_sparse_indices_component_type);
ClassDB::bind_method(D_METHOD("set_sparse_indices_component_type", "sparse_indices_component_type"), &GLTFAccessor::set_sparse_indices_component_type);
ClassDB::bind_method(D_METHOD("get_sparse_values_buffer_view"), &GLTFAccessor::get_sparse_values_buffer_view);
ClassDB::bind_method(D_METHOD("set_sparse_values_buffer_view", "sparse_values_buffer_view"), &GLTFAccessor::set_sparse_values_buffer_view);
ClassDB::bind_method(D_METHOD("get_sparse_values_byte_offset"), &GLTFAccessor::get_sparse_values_byte_offset);
ClassDB::bind_method(D_METHOD("set_sparse_values_byte_offset", "sparse_values_byte_offset"), &GLTFAccessor::set_sparse_values_byte_offset);
ADD_PROPERTY(PropertyInfo(Variant::INT, "buffer_view"), "set_buffer_view", "get_buffer_view"); // GLTFBufferViewIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_offset"), "set_byte_offset", "get_byte_offset"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "component_type"), "set_component_type", "get_component_type"); // int
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "normalized"), "set_normalized", "get_normalized"); // bool
ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "accessor_type"), "set_accessor_type", "get_accessor_type"); // GLTFAccessor::GLTFAccessorType
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_type", "get_type"); // Deprecated, int for GLTFAccessor::GLTFAccessorType
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT64_ARRAY, "min"), "set_min", "get_min"); // Vector<real_t>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT64_ARRAY, "max"), "set_max", "get_max"); // Vector<real_t>
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_count"), "set_sparse_count", "get_sparse_count"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_buffer_view"), "set_sparse_indices_buffer_view", "get_sparse_indices_buffer_view"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_byte_offset"), "set_sparse_indices_byte_offset", "get_sparse_indices_byte_offset"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_component_type"), "set_sparse_indices_component_type", "get_sparse_indices_component_type"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_values_buffer_view"), "set_sparse_values_buffer_view", "get_sparse_values_buffer_view"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_values_byte_offset"), "set_sparse_values_byte_offset", "get_sparse_values_byte_offset"); // int
}
GLTFBufferViewIndex GLTFAccessor::get_buffer_view() const {
return buffer_view;
}
void GLTFAccessor::set_buffer_view(GLTFBufferViewIndex p_buffer_view) {
buffer_view = p_buffer_view;
}
int64_t GLTFAccessor::get_byte_offset() const {
return byte_offset;
}
void GLTFAccessor::set_byte_offset(int64_t p_byte_offset) {
byte_offset = p_byte_offset;
}
GLTFAccessor::GLTFComponentType GLTFAccessor::get_component_type() const {
return component_type;
}
void GLTFAccessor::set_component_type(GLTFComponentType p_component_type) {
component_type = (GLTFComponentType)p_component_type;
}
bool GLTFAccessor::get_normalized() const {
return normalized;
}
void GLTFAccessor::set_normalized(bool p_normalized) {
normalized = p_normalized;
}
int64_t GLTFAccessor::get_count() const {
return count;
}
void GLTFAccessor::set_count(int64_t p_count) {
count = p_count;
}
GLTFAccessor::GLTFAccessorType GLTFAccessor::get_accessor_type() const {
return accessor_type;
}
void GLTFAccessor::set_accessor_type(GLTFAccessorType p_accessor_type) {
accessor_type = p_accessor_type;
}
int GLTFAccessor::get_type() const {
return (int)accessor_type;
}
void GLTFAccessor::set_type(int p_accessor_type) {
accessor_type = (GLTFAccessorType)p_accessor_type; // TODO: Register enum
}
Vector<double> GLTFAccessor::get_min() const {
return min;
}
void GLTFAccessor::set_min(Vector<double> p_min) {
min = p_min;
}
Vector<double> GLTFAccessor::get_max() const {
return max;
}
void GLTFAccessor::set_max(Vector<double> p_max) {
max = p_max;
}
int64_t GLTFAccessor::get_sparse_count() const {
return sparse_count;
}
void GLTFAccessor::set_sparse_count(int64_t p_sparse_count) {
sparse_count = p_sparse_count;
}
GLTFBufferViewIndex GLTFAccessor::get_sparse_indices_buffer_view() const {
return sparse_indices_buffer_view;
}
void GLTFAccessor::set_sparse_indices_buffer_view(GLTFBufferViewIndex p_sparse_indices_buffer_view) {
sparse_indices_buffer_view = p_sparse_indices_buffer_view;
}
int64_t GLTFAccessor::get_sparse_indices_byte_offset() const {
return sparse_indices_byte_offset;
}
void GLTFAccessor::set_sparse_indices_byte_offset(int64_t p_sparse_indices_byte_offset) {
sparse_indices_byte_offset = p_sparse_indices_byte_offset;
}
GLTFAccessor::GLTFComponentType GLTFAccessor::get_sparse_indices_component_type() const {
return sparse_indices_component_type;
}
void GLTFAccessor::set_sparse_indices_component_type(GLTFComponentType p_sparse_indices_component_type) {
sparse_indices_component_type = (GLTFComponentType)p_sparse_indices_component_type;
}
GLTFBufferViewIndex GLTFAccessor::get_sparse_values_buffer_view() const {
return sparse_values_buffer_view;
}
void GLTFAccessor::set_sparse_values_buffer_view(GLTFBufferViewIndex p_sparse_values_buffer_view) {
sparse_values_buffer_view = p_sparse_values_buffer_view;
}
int64_t GLTFAccessor::get_sparse_values_byte_offset() const {
return sparse_values_byte_offset;
}
void GLTFAccessor::set_sparse_values_byte_offset(int64_t p_sparse_values_byte_offset) {
sparse_values_byte_offset = p_sparse_values_byte_offset;
}

View File

@@ -0,0 +1,156 @@
/**************************************************************************/
/* gltf_accessor.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "../gltf_defines.h"
#include "core/io/resource.h"
struct GLTFAccessor : public Resource {
GDCLASS(GLTFAccessor, Resource);
friend class GLTFDocument;
public:
enum GLTFAccessorType {
TYPE_SCALAR,
TYPE_VEC2,
TYPE_VEC3,
TYPE_VEC4,
TYPE_MAT2,
TYPE_MAT3,
TYPE_MAT4,
};
enum GLTFComponentType {
COMPONENT_TYPE_NONE = 0,
COMPONENT_TYPE_SIGNED_BYTE = 5120,
COMPONENT_TYPE_UNSIGNED_BYTE = 5121,
COMPONENT_TYPE_SIGNED_SHORT = 5122,
COMPONENT_TYPE_UNSIGNED_SHORT = 5123,
COMPONENT_TYPE_SIGNED_INT = 5124,
COMPONENT_TYPE_UNSIGNED_INT = 5125,
COMPONENT_TYPE_SINGLE_FLOAT = 5126,
COMPONENT_TYPE_DOUBLE_FLOAT = 5130,
COMPONENT_TYPE_HALF_FLOAT = 5131,
COMPONENT_TYPE_SIGNED_LONG = 5134,
COMPONENT_TYPE_UNSIGNED_LONG = 5135,
};
private:
GLTFBufferViewIndex buffer_view = -1;
int64_t byte_offset = 0;
GLTFComponentType component_type = COMPONENT_TYPE_NONE;
bool normalized = false;
int64_t count = 0;
GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_SCALAR;
Vector<double> min;
Vector<double> max;
int64_t sparse_count = 0;
GLTFBufferViewIndex sparse_indices_buffer_view = 0;
int64_t sparse_indices_byte_offset = 0;
GLTFComponentType sparse_indices_component_type = COMPONENT_TYPE_NONE;
GLTFBufferViewIndex sparse_values_buffer_view = 0;
int64_t sparse_values_byte_offset = 0;
protected:
static void _bind_methods();
#ifndef DISABLE_DEPRECATED
// 32-bit and non-const versions for compatibility.
GLTFBufferViewIndex _get_buffer_view_bind_compat_106220();
int _get_byte_offset_bind_compat_106220();
int _get_component_type_bind_compat_106220();
void _set_component_type_bind_compat_106220(int p_component_type);
bool _get_normalized_bind_compat_106220();
int _get_count_bind_compat_106220();
GLTFAccessorType _get_accessor_type_bind_compat_106220();
int _get_type_bind_compat_106220();
Vector<double> _get_min_bind_compat_106220();
Vector<double> _get_max_bind_compat_106220();
int _get_sparse_count_bind_compat_106220();
int _get_sparse_indices_buffer_view_bind_compat_106220();
int _get_sparse_indices_byte_offset_bind_compat_106220();
int _get_sparse_indices_component_type_bind_compat_106220();
void _set_sparse_indices_component_type_bind_compat_106220(int p_sparse_indices_component_type);
int _get_sparse_values_buffer_view_bind_compat_106220();
int _get_sparse_values_byte_offset_bind_compat_106220();
static void _bind_compatibility_methods();
#endif // DISABLE_DEPRECATED
public:
GLTFBufferViewIndex get_buffer_view() const;
void set_buffer_view(GLTFBufferViewIndex p_buffer_view);
int64_t get_byte_offset() const;
void set_byte_offset(int64_t p_byte_offset);
GLTFComponentType get_component_type() const;
void set_component_type(GLTFComponentType p_component_type);
bool get_normalized() const;
void set_normalized(bool p_normalized);
int64_t get_count() const;
void set_count(int64_t p_count);
GLTFAccessorType get_accessor_type() const;
void set_accessor_type(GLTFAccessorType p_accessor_type);
int get_type() const;
void set_type(int p_accessor_type);
Vector<double> get_min() const;
void set_min(Vector<double> p_min);
Vector<double> get_max() const;
void set_max(Vector<double> p_max);
int64_t get_sparse_count() const;
void set_sparse_count(int64_t p_sparse_count);
GLTFBufferViewIndex get_sparse_indices_buffer_view() const;
void set_sparse_indices_buffer_view(GLTFBufferViewIndex p_sparse_indices_buffer_view);
int64_t get_sparse_indices_byte_offset() const;
void set_sparse_indices_byte_offset(int64_t p_sparse_indices_byte_offset);
GLTFComponentType get_sparse_indices_component_type() const;
void set_sparse_indices_component_type(GLTFComponentType p_sparse_indices_component_type);
GLTFBufferViewIndex get_sparse_values_buffer_view() const;
void set_sparse_values_buffer_view(GLTFBufferViewIndex p_sparse_values_buffer_view);
int64_t get_sparse_values_byte_offset() const;
void set_sparse_values_byte_offset(int64_t p_sparse_values_byte_offset);
};
VARIANT_ENUM_CAST(GLTFAccessor::GLTFAccessorType);
VARIANT_ENUM_CAST(GLTFAccessor::GLTFComponentType);

View File

@@ -0,0 +1,110 @@
/**************************************************************************/
/* gltf_animation.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_animation.h"
void GLTFAnimation::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_original_name"), &GLTFAnimation::get_original_name);
ClassDB::bind_method(D_METHOD("set_original_name", "original_name"), &GLTFAnimation::set_original_name);
ClassDB::bind_method(D_METHOD("get_loop"), &GLTFAnimation::get_loop);
ClassDB::bind_method(D_METHOD("set_loop", "loop"), &GLTFAnimation::set_loop);
ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFAnimation::get_additional_data);
ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFAnimation::set_additional_data);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "original_name"), "set_original_name", "get_original_name"); // String
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "get_loop"); // bool
}
GLTFAnimation::Interpolation GLTFAnimation::godot_to_gltf_interpolation(const Ref<Animation> &p_godot_animation, int32_t p_godot_anim_track_index) {
Animation::InterpolationType interpolation = p_godot_animation->track_get_interpolation_type(p_godot_anim_track_index);
switch (interpolation) {
case Animation::INTERPOLATION_LINEAR:
case Animation::INTERPOLATION_LINEAR_ANGLE:
return INTERP_LINEAR;
case Animation::INTERPOLATION_NEAREST:
return INTERP_STEP;
case Animation::INTERPOLATION_CUBIC:
case Animation::INTERPOLATION_CUBIC_ANGLE:
return INTERP_CUBIC_SPLINE;
}
return INTERP_LINEAR;
}
Animation::InterpolationType GLTFAnimation::gltf_to_godot_interpolation(Interpolation p_gltf_interpolation) {
switch (p_gltf_interpolation) {
case INTERP_LINEAR:
return Animation::INTERPOLATION_LINEAR;
case INTERP_STEP:
return Animation::INTERPOLATION_NEAREST;
case INTERP_CATMULLROMSPLINE:
case INTERP_CUBIC_SPLINE:
return Animation::INTERPOLATION_CUBIC;
}
return Animation::INTERPOLATION_LINEAR;
}
String GLTFAnimation::get_original_name() {
return original_name;
}
void GLTFAnimation::set_original_name(String p_name) {
original_name = p_name;
}
bool GLTFAnimation::get_loop() const {
return loop;
}
void GLTFAnimation::set_loop(bool p_val) {
loop = p_val;
}
HashMap<int, GLTFAnimation::NodeTrack> &GLTFAnimation::get_node_tracks() {
return node_tracks;
}
HashMap<String, GLTFAnimation::Channel<Variant>> &GLTFAnimation::get_pointer_tracks() {
return pointer_tracks;
}
bool GLTFAnimation::is_empty_of_tracks() const {
return node_tracks.is_empty() && pointer_tracks.is_empty();
}
GLTFAnimation::GLTFAnimation() {
}
Variant GLTFAnimation::get_additional_data(const StringName &p_extension_name) {
return additional_data[p_extension_name];
}
void GLTFAnimation::set_additional_data(const StringName &p_extension_name, Variant p_additional_data) {
additional_data[p_extension_name] = p_additional_data;
}

View File

@@ -0,0 +1,87 @@
/**************************************************************************/
/* gltf_animation.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "scene/resources/animation.h"
class GLTFAnimation : public Resource {
GDCLASS(GLTFAnimation, Resource);
protected:
static void _bind_methods();
public:
enum Interpolation {
INTERP_LINEAR,
INTERP_STEP,
INTERP_CATMULLROMSPLINE,
INTERP_CUBIC_SPLINE,
};
template <typename T>
struct Channel {
Interpolation interpolation = INTERP_LINEAR;
Vector<double> times;
Vector<T> values;
};
struct NodeTrack {
Channel<Vector3> position_track;
Channel<Quaternion> rotation_track;
Channel<Vector3> scale_track;
Vector<Channel<real_t>> weight_tracks;
};
String original_name;
bool loop = false;
HashMap<int, NodeTrack> node_tracks;
HashMap<String, Channel<Variant>> pointer_tracks;
Dictionary additional_data;
public:
static Interpolation godot_to_gltf_interpolation(const Ref<Animation> &p_godot_animation, int32_t p_godot_anim_track_index);
static Animation::InterpolationType gltf_to_godot_interpolation(Interpolation p_gltf_interpolation);
String get_original_name();
void set_original_name(String p_name);
bool get_loop() const;
void set_loop(bool p_val);
HashMap<int, GLTFAnimation::NodeTrack> &get_node_tracks();
HashMap<String, GLTFAnimation::Channel<Variant>> &get_pointer_tracks();
bool is_empty_of_tracks() const;
Variant get_additional_data(const StringName &p_extension_name);
void set_additional_data(const StringName &p_extension_name, Variant p_additional_data);
GLTFAnimation();
};

View File

@@ -0,0 +1,62 @@
/**************************************************************************/
/* gltf_buffer_view.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 DISABLE_DEPRECATED
GLTFBufferIndex GLTFBufferView::_get_buffer_bind_compat_86907() {
return get_buffer();
}
int GLTFBufferView::_get_byte_offset_bind_compat_86907() {
return get_byte_offset();
}
int GLTFBufferView::_get_byte_length_bind_compat_86907() {
return get_byte_length();
}
int GLTFBufferView::_get_byte_stride_bind_compat_86907() {
return get_byte_stride();
}
bool GLTFBufferView::_get_indices_bind_compat_86907() {
return get_indices();
}
void GLTFBufferView::_bind_compatibility_methods() {
// Non-const versions for compatibility.
ClassDB::bind_compatibility_method(D_METHOD("get_buffer"), &GLTFBufferView::_get_buffer_bind_compat_86907);
ClassDB::bind_compatibility_method(D_METHOD("get_byte_offset"), &GLTFBufferView::_get_byte_offset_bind_compat_86907);
ClassDB::bind_compatibility_method(D_METHOD("get_byte_length"), &GLTFBufferView::_get_byte_length_bind_compat_86907);
ClassDB::bind_compatibility_method(D_METHOD("get_byte_stride"), &GLTFBufferView::_get_byte_stride_bind_compat_86907);
ClassDB::bind_compatibility_method(D_METHOD("get_indices"), &GLTFBufferView::_get_indices_bind_compat_86907);
}
#endif // DISABLE_DEPRECATED

View File

@@ -0,0 +1,116 @@
/**************************************************************************/
/* gltf_buffer_view.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_buffer_view.h"
#include "gltf_buffer_view.compat.inc"
#include "../gltf_state.h"
void GLTFBufferView::_bind_methods() {
ClassDB::bind_method(D_METHOD("load_buffer_view_data", "state"), &GLTFBufferView::load_buffer_view_data);
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("get_byte_offset"), &GLTFBufferView::get_byte_offset);
ClassDB::bind_method(D_METHOD("set_byte_offset", "byte_offset"), &GLTFBufferView::set_byte_offset);
ClassDB::bind_method(D_METHOD("get_byte_length"), &GLTFBufferView::get_byte_length);
ClassDB::bind_method(D_METHOD("set_byte_length", "byte_length"), &GLTFBufferView::set_byte_length);
ClassDB::bind_method(D_METHOD("get_byte_stride"), &GLTFBufferView::get_byte_stride);
ClassDB::bind_method(D_METHOD("set_byte_stride", "byte_stride"), &GLTFBufferView::set_byte_stride);
ClassDB::bind_method(D_METHOD("get_indices"), &GLTFBufferView::get_indices);
ClassDB::bind_method(D_METHOD("set_indices", "indices"), &GLTFBufferView::set_indices);
ClassDB::bind_method(D_METHOD("get_vertex_attributes"), &GLTFBufferView::get_vertex_attributes);
ClassDB::bind_method(D_METHOD("set_vertex_attributes", "is_attributes"), &GLTFBufferView::set_vertex_attributes);
ADD_PROPERTY(PropertyInfo(Variant::INT, "buffer"), "set_buffer", "get_buffer"); // GLTFBufferIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_offset"), "set_byte_offset", "get_byte_offset"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_length"), "set_byte_length", "get_byte_length"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_stride"), "set_byte_stride", "get_byte_stride"); // int
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "indices"), "set_indices", "get_indices"); // bool
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vertex_attributes"), "set_vertex_attributes", "get_vertex_attributes"); // bool
}
GLTFBufferIndex GLTFBufferView::get_buffer() const {
return buffer;
}
void GLTFBufferView::set_buffer(GLTFBufferIndex p_buffer) {
buffer = p_buffer;
}
int64_t GLTFBufferView::get_byte_offset() const {
return byte_offset;
}
void GLTFBufferView::set_byte_offset(int64_t p_byte_offset) {
byte_offset = p_byte_offset;
}
int64_t GLTFBufferView::get_byte_length() const {
return byte_length;
}
void GLTFBufferView::set_byte_length(int64_t p_byte_length) {
byte_length = p_byte_length;
}
int64_t GLTFBufferView::get_byte_stride() const {
return byte_stride;
}
void GLTFBufferView::set_byte_stride(int64_t p_byte_stride) {
byte_stride = p_byte_stride;
}
bool GLTFBufferView::get_indices() const {
return indices;
}
void GLTFBufferView::set_indices(bool p_indices) {
indices = p_indices;
}
bool GLTFBufferView::get_vertex_attributes() const {
return vertex_attributes;
}
void GLTFBufferView::set_vertex_attributes(bool p_attributes) {
vertex_attributes = p_attributes;
}
Vector<uint8_t> GLTFBufferView::load_buffer_view_data(const Ref<GLTFState> p_state) const {
ERR_FAIL_COND_V(p_state.is_null(), Vector<uint8_t>());
ERR_FAIL_COND_V_MSG(byte_stride > 0, Vector<uint8_t>(), "Buffer views with byte stride are not yet supported by this method.");
const TypedArray<Vector<uint8_t>> &buffers = p_state->get_buffers();
ERR_FAIL_INDEX_V(buffer, buffers.size(), Vector<uint8_t>());
const PackedByteArray &buffer_data = buffers[buffer];
const int64_t byte_end = byte_offset + byte_length;
return buffer_data.slice(byte_offset, byte_end);
}

View File

@@ -0,0 +1,82 @@
/**************************************************************************/
/* gltf_buffer_view.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "../gltf_defines.h"
#include "core/io/resource.h"
class GLTFBufferView : public Resource {
GDCLASS(GLTFBufferView, Resource);
friend class GLTFDocument;
private:
GLTFBufferIndex buffer = -1;
int64_t byte_offset = 0;
int64_t byte_length = 0;
int64_t byte_stride = -1;
bool indices = false;
bool vertex_attributes = false;
protected:
static void _bind_methods();
#ifndef DISABLE_DEPRECATED
// Non-const versions for compatibility.
GLTFBufferIndex _get_buffer_bind_compat_86907();
int _get_byte_offset_bind_compat_86907();
int _get_byte_length_bind_compat_86907();
int _get_byte_stride_bind_compat_86907();
bool _get_indices_bind_compat_86907();
static void _bind_compatibility_methods();
#endif // DISABLE_DEPRECATED
public:
GLTFBufferIndex get_buffer() const;
void set_buffer(GLTFBufferIndex p_buffer);
int64_t get_byte_offset() const;
void set_byte_offset(int64_t p_byte_offset);
int64_t get_byte_length() const;
void set_byte_length(int64_t p_byte_length);
int64_t get_byte_stride() const;
void set_byte_stride(int64_t p_byte_stride);
bool get_indices() const;
void set_indices(bool p_indices);
bool get_vertex_attributes() const;
void set_vertex_attributes(bool p_attributes);
Vector<uint8_t> load_buffer_view_data(const Ref<GLTFState> p_state) const;
};

View File

@@ -0,0 +1,150 @@
/**************************************************************************/
/* gltf_camera.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_camera.h"
#include "gltf_object_model_property.h"
#include "scene/3d/camera_3d.h"
void GLTFCamera::_bind_methods() {
ClassDB::bind_static_method("GLTFCamera", D_METHOD("from_node", "camera_node"), &GLTFCamera::from_node);
ClassDB::bind_method(D_METHOD("to_node"), &GLTFCamera::to_node);
ClassDB::bind_static_method("GLTFCamera", D_METHOD("from_dictionary", "dictionary"), &GLTFCamera::from_dictionary);
ClassDB::bind_method(D_METHOD("to_dictionary"), &GLTFCamera::to_dictionary);
ClassDB::bind_method(D_METHOD("get_perspective"), &GLTFCamera::get_perspective);
ClassDB::bind_method(D_METHOD("set_perspective", "perspective"), &GLTFCamera::set_perspective);
ClassDB::bind_method(D_METHOD("get_fov"), &GLTFCamera::get_fov);
ClassDB::bind_method(D_METHOD("set_fov", "fov"), &GLTFCamera::set_fov);
ClassDB::bind_method(D_METHOD("get_size_mag"), &GLTFCamera::get_size_mag);
ClassDB::bind_method(D_METHOD("set_size_mag", "size_mag"), &GLTFCamera::set_size_mag);
ClassDB::bind_method(D_METHOD("get_depth_far"), &GLTFCamera::get_depth_far);
ClassDB::bind_method(D_METHOD("set_depth_far", "zdepth_far"), &GLTFCamera::set_depth_far);
ClassDB::bind_method(D_METHOD("get_depth_near"), &GLTFCamera::get_depth_near);
ClassDB::bind_method(D_METHOD("set_depth_near", "zdepth_near"), &GLTFCamera::set_depth_near);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "perspective"), "set_perspective", "get_perspective");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fov"), "set_fov", "get_fov");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_mag"), "set_size_mag", "get_size_mag");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth_far"), "set_depth_far", "get_depth_far");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth_near"), "set_depth_near", "get_depth_near");
}
void GLTFCamera::set_fov_conversion_expressions(Ref<GLTFObjectModelProperty> &r_obj_model_prop) {
// Expression to convert glTF yfov in radians to Godot fov in degrees.
Ref<Expression> gltf_to_godot_expr;
gltf_to_godot_expr.instantiate();
PackedStringArray gltf_to_godot_args = { "yfov_rad" };
gltf_to_godot_expr->parse("rad_to_deg(yfov_rad)", gltf_to_godot_args);
r_obj_model_prop->set_gltf_to_godot_expression(gltf_to_godot_expr);
// Expression to convert Godot fov in degrees to glTF yfov in radians.
Ref<Expression> godot_to_gltf_expr;
godot_to_gltf_expr.instantiate();
PackedStringArray godot_to_gltf_args = { "fov_deg" };
godot_to_gltf_expr->parse("deg_to_rad(fov_deg)", godot_to_gltf_args);
r_obj_model_prop->set_godot_to_gltf_expression(godot_to_gltf_expr);
}
Ref<GLTFCamera> GLTFCamera::from_node(const Camera3D *p_camera) {
Ref<GLTFCamera> c;
c.instantiate();
ERR_FAIL_NULL_V_MSG(p_camera, c, "Tried to create a GLTFCamera from a Camera3D node, but the given node was null.");
c->set_perspective(p_camera->get_projection() == Camera3D::ProjectionType::PROJECTION_PERSPECTIVE);
// glTF spec (yfov) is in radians, Godot's camera (fov) is in degrees.
c->set_fov(Math::deg_to_rad(p_camera->get_fov()));
// glTF spec (xmag and ymag) is a radius in meters, Godot's camera (size) is a diameter in meters.
c->set_size_mag(p_camera->get_size() * 0.5f);
c->set_depth_far(p_camera->get_far());
c->set_depth_near(p_camera->get_near());
return c;
}
Camera3D *GLTFCamera::to_node() const {
Camera3D *camera = memnew(Camera3D);
camera->set_projection(perspective ? Camera3D::PROJECTION_PERSPECTIVE : Camera3D::PROJECTION_ORTHOGONAL);
// glTF spec (yfov) is in radians, Godot's camera (fov) is in degrees.
camera->set_fov(Math::rad_to_deg(fov));
// glTF spec (xmag and ymag) is a radius in meters, Godot's camera (size) is a diameter in meters.
camera->set_size(size_mag * 2.0f);
camera->set_near(depth_near);
camera->set_far(depth_far);
return camera;
}
Ref<GLTFCamera> GLTFCamera::from_dictionary(const Dictionary p_dictionary) {
ERR_FAIL_COND_V_MSG(!p_dictionary.has("type"), Ref<GLTFCamera>(), "Failed to parse glTF camera, missing required field 'type'.");
Ref<GLTFCamera> camera;
camera.instantiate();
const String &type = p_dictionary["type"];
if (type == "perspective") {
camera->set_perspective(true);
if (p_dictionary.has("perspective")) {
const Dictionary &persp = p_dictionary["perspective"];
camera->set_fov(persp["yfov"]);
if (persp.has("zfar")) {
camera->set_depth_far(persp["zfar"]);
}
camera->set_depth_near(persp["znear"]);
}
} else if (type == "orthographic") {
camera->set_perspective(false);
if (p_dictionary.has("orthographic")) {
const Dictionary &ortho = p_dictionary["orthographic"];
camera->set_size_mag(ortho["ymag"]);
camera->set_depth_far(ortho["zfar"]);
camera->set_depth_near(ortho["znear"]);
}
} else {
ERR_PRINT("Error parsing glTF camera: Camera type '" + type + "' is unknown, should be perspective or orthographic.");
}
return camera;
}
Dictionary GLTFCamera::to_dictionary() const {
Dictionary d;
if (perspective) {
Dictionary persp;
persp["yfov"] = fov;
persp["zfar"] = depth_far;
persp["znear"] = depth_near;
d["perspective"] = persp;
d["type"] = "perspective";
} else {
Dictionary ortho;
ortho["ymag"] = size_mag;
ortho["xmag"] = size_mag;
ortho["zfar"] = depth_far;
ortho["znear"] = depth_near;
d["orthographic"] = ortho;
d["type"] = "orthographic";
}
return d;
}

View File

@@ -0,0 +1,75 @@
/**************************************************************************/
/* gltf_camera.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "core/io/resource.h"
class Camera3D;
class GLTFObjectModelProperty;
// Reference and test file:
// https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_015_SimpleCameras.md
class GLTFCamera : public Resource {
GDCLASS(GLTFCamera, Resource);
private:
// glTF has no default camera values, they should always be specified in
// the glTF file. Here we default to Godot's default camera settings.
bool perspective = true;
real_t fov = Math::deg_to_rad(75.0);
real_t size_mag = 0.5;
real_t depth_far = 4000.0;
real_t depth_near = 0.05;
protected:
static void _bind_methods();
public:
static void set_fov_conversion_expressions(Ref<GLTFObjectModelProperty> &r_obj_model_prop);
bool get_perspective() const { return perspective; }
void set_perspective(bool p_val) { perspective = p_val; }
real_t get_fov() const { return fov; }
void set_fov(real_t p_val) { fov = p_val; }
real_t get_size_mag() const { return size_mag; }
void set_size_mag(real_t p_val) { size_mag = p_val; }
real_t get_depth_far() const { return depth_far; }
void set_depth_far(real_t p_val) { depth_far = p_val; }
real_t get_depth_near() const { return depth_near; }
void set_depth_near(real_t p_val) { depth_near = p_val; }
static Ref<GLTFCamera> from_node(const Camera3D *p_camera);
Camera3D *to_node() const;
static Ref<GLTFCamera> from_dictionary(const Dictionary p_dictionary);
virtual Dictionary to_dictionary() const;
};

View File

@@ -0,0 +1,91 @@
/**************************************************************************/
/* gltf_mesh.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_mesh.h"
#include "scene/resources/3d/importer_mesh.h"
void GLTFMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_original_name"), &GLTFMesh::get_original_name);
ClassDB::bind_method(D_METHOD("set_original_name", "original_name"), &GLTFMesh::set_original_name);
ClassDB::bind_method(D_METHOD("get_mesh"), &GLTFMesh::get_mesh);
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &GLTFMesh::set_mesh);
ClassDB::bind_method(D_METHOD("get_blend_weights"), &GLTFMesh::get_blend_weights);
ClassDB::bind_method(D_METHOD("set_blend_weights", "blend_weights"), &GLTFMesh::set_blend_weights);
ClassDB::bind_method(D_METHOD("get_instance_materials"), &GLTFMesh::get_instance_materials);
ClassDB::bind_method(D_METHOD("set_instance_materials", "instance_materials"), &GLTFMesh::set_instance_materials);
ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFMesh::get_additional_data);
ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFMesh::set_additional_data);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "original_name"), "set_original_name", "get_original_name");
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::ARRAY, "instance_materials"), "set_instance_materials", "get_instance_materials");
}
String GLTFMesh::get_original_name() {
return original_name;
}
void GLTFMesh::set_original_name(String p_name) {
original_name = p_name;
}
Ref<ImporterMesh> GLTFMesh::get_mesh() {
return mesh;
}
void GLTFMesh::set_mesh(Ref<ImporterMesh> p_mesh) {
mesh = p_mesh;
}
TypedArray<Material> GLTFMesh::get_instance_materials() {
return instance_materials;
}
void GLTFMesh::set_instance_materials(TypedArray<Material> p_instance_materials) {
instance_materials = p_instance_materials;
}
Vector<float> GLTFMesh::get_blend_weights() {
return blend_weights;
}
void GLTFMesh::set_blend_weights(Vector<float> p_blend_weights) {
blend_weights = p_blend_weights;
}
Variant GLTFMesh::get_additional_data(const StringName &p_extension_name) {
return additional_data[p_extension_name];
}
void GLTFMesh::set_additional_data(const StringName &p_extension_name, Variant p_additional_data) {
additional_data[p_extension_name] = p_additional_data;
}

View File

@@ -0,0 +1,61 @@
/**************************************************************************/
/* gltf_mesh.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "../gltf_defines.h"
#include "scene/resources/3d/importer_mesh.h"
class GLTFMesh : public Resource {
GDCLASS(GLTFMesh, Resource);
private:
String original_name;
Ref<ImporterMesh> mesh;
Vector<float> blend_weights;
TypedArray<Material> instance_materials;
Dictionary additional_data;
protected:
static void _bind_methods();
public:
String get_original_name();
void set_original_name(String p_name);
Ref<ImporterMesh> get_mesh();
void set_mesh(Ref<ImporterMesh> p_mesh);
Vector<float> get_blend_weights();
void set_blend_weights(Vector<float> p_blend_weights);
TypedArray<Material> get_instance_materials();
void set_instance_materials(TypedArray<Material> p_instance_materials);
Variant get_additional_data(const StringName &p_extension_name);
void set_additional_data(const StringName &p_extension_name, Variant p_additional_data);
};

View File

@@ -0,0 +1,248 @@
/**************************************************************************/
/* gltf_node.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_node.h"
#include "../gltf_state.h"
void GLTFNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_original_name"), &GLTFNode::get_original_name);
ClassDB::bind_method(D_METHOD("set_original_name", "original_name"), &GLTFNode::set_original_name);
ClassDB::bind_method(D_METHOD("get_parent"), &GLTFNode::get_parent);
ClassDB::bind_method(D_METHOD("set_parent", "parent"), &GLTFNode::set_parent);
ClassDB::bind_method(D_METHOD("get_height"), &GLTFNode::get_height);
ClassDB::bind_method(D_METHOD("set_height", "height"), &GLTFNode::set_height);
ClassDB::bind_method(D_METHOD("get_xform"), &GLTFNode::get_xform);
ClassDB::bind_method(D_METHOD("set_xform", "xform"), &GLTFNode::set_xform);
ClassDB::bind_method(D_METHOD("get_mesh"), &GLTFNode::get_mesh);
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &GLTFNode::set_mesh);
ClassDB::bind_method(D_METHOD("get_camera"), &GLTFNode::get_camera);
ClassDB::bind_method(D_METHOD("set_camera", "camera"), &GLTFNode::set_camera);
ClassDB::bind_method(D_METHOD("get_skin"), &GLTFNode::get_skin);
ClassDB::bind_method(D_METHOD("set_skin", "skin"), &GLTFNode::set_skin);
ClassDB::bind_method(D_METHOD("get_skeleton"), &GLTFNode::get_skeleton);
ClassDB::bind_method(D_METHOD("set_skeleton", "skeleton"), &GLTFNode::set_skeleton);
ClassDB::bind_method(D_METHOD("get_position"), &GLTFNode::get_position);
ClassDB::bind_method(D_METHOD("set_position", "position"), &GLTFNode::set_position);
ClassDB::bind_method(D_METHOD("get_rotation"), &GLTFNode::get_rotation);
ClassDB::bind_method(D_METHOD("set_rotation", "rotation"), &GLTFNode::set_rotation);
ClassDB::bind_method(D_METHOD("get_scale"), &GLTFNode::get_scale);
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &GLTFNode::set_scale);
ClassDB::bind_method(D_METHOD("get_children"), &GLTFNode::get_children);
ClassDB::bind_method(D_METHOD("set_children", "children"), &GLTFNode::set_children);
ClassDB::bind_method(D_METHOD("append_child_index", "child_index"), &GLTFNode::append_child_index);
ClassDB::bind_method(D_METHOD("get_light"), &GLTFNode::get_light);
ClassDB::bind_method(D_METHOD("set_light", "light"), &GLTFNode::set_light);
ClassDB::bind_method(D_METHOD("get_visible"), &GLTFNode::get_visible);
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &GLTFNode::set_visible);
ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFNode::get_additional_data);
ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFNode::set_additional_data);
ClassDB::bind_method(D_METHOD("get_scene_node_path", "gltf_state", "handle_skeletons"), &GLTFNode::get_scene_node_path, DEFVAL(true));
ADD_PROPERTY(PropertyInfo(Variant::STRING, "original_name"), "set_original_name", "get_original_name"); // String
ADD_PROPERTY(PropertyInfo(Variant::INT, "parent"), "set_parent", "get_parent"); // GLTFNodeIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "height"), "set_height", "get_height"); // int
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "xform"), "set_xform", "get_xform"); // Transform3D
ADD_PROPERTY(PropertyInfo(Variant::INT, "mesh"), "set_mesh", "get_mesh"); // GLTFMeshIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "camera"), "set_camera", "get_camera"); // GLTFCameraIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "skin"), "set_skin", "get_skin"); // GLTFSkinIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "skeleton"), "set_skeleton", "get_skeleton"); // GLTFSkeletonIndex
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "set_position", "get_position"); // Vector3
ADD_PROPERTY(PropertyInfo(Variant::QUATERNION, "rotation"), "set_rotation", "get_rotation"); // Quaternion
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale"), "set_scale", "get_scale"); // Vector3
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "children"), "set_children", "get_children"); // Vector<int>
ADD_PROPERTY(PropertyInfo(Variant::INT, "light"), "set_light", "get_light"); // GLTFLightIndex
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "get_visible"); // bool
}
String GLTFNode::get_original_name() {
return original_name;
}
void GLTFNode::set_original_name(String p_name) {
original_name = p_name;
}
GLTFNodeIndex GLTFNode::get_parent() {
return parent;
}
void GLTFNode::set_parent(GLTFNodeIndex p_parent) {
parent = p_parent;
}
int GLTFNode::get_height() {
return height;
}
void GLTFNode::set_height(int p_height) {
height = p_height;
}
Transform3D GLTFNode::get_xform() {
return transform;
}
void GLTFNode::set_xform(Transform3D p_xform) {
transform = p_xform;
}
GLTFMeshIndex GLTFNode::get_mesh() {
return mesh;
}
void GLTFNode::set_mesh(GLTFMeshIndex p_mesh) {
mesh = p_mesh;
}
GLTFCameraIndex GLTFNode::get_camera() {
return camera;
}
void GLTFNode::set_camera(GLTFCameraIndex p_camera) {
camera = p_camera;
}
GLTFSkinIndex GLTFNode::get_skin() {
return skin;
}
void GLTFNode::set_skin(GLTFSkinIndex p_skin) {
skin = p_skin;
}
GLTFSkeletonIndex GLTFNode::get_skeleton() {
return skeleton;
}
void GLTFNode::set_skeleton(GLTFSkeletonIndex p_skeleton) {
skeleton = p_skeleton;
}
Vector3 GLTFNode::get_position() {
return transform.origin;
}
void GLTFNode::set_position(Vector3 p_position) {
transform.origin = p_position;
}
Quaternion GLTFNode::get_rotation() {
return transform.basis.get_rotation_quaternion();
}
void GLTFNode::set_rotation(Quaternion p_rotation) {
transform.basis.set_quaternion_scale(p_rotation, transform.basis.get_scale());
}
Vector3 GLTFNode::get_scale() {
return transform.basis.get_scale();
}
void GLTFNode::set_scale(Vector3 p_scale) {
transform.basis = transform.basis.orthonormalized() * Basis::from_scale(p_scale);
}
Vector<int> GLTFNode::get_children() {
return children;
}
void GLTFNode::set_children(Vector<int> p_children) {
children = p_children;
}
void GLTFNode::append_child_index(int p_child_index) {
children.append(p_child_index);
}
GLTFLightIndex GLTFNode::get_light() {
return light;
}
void GLTFNode::set_light(GLTFLightIndex p_light) {
light = p_light;
}
bool GLTFNode::get_visible() {
return visible;
}
void GLTFNode::set_visible(bool p_visible) {
visible = p_visible;
}
Variant GLTFNode::get_additional_data(const StringName &p_extension_name) {
return additional_data[p_extension_name];
}
bool GLTFNode::has_additional_data(const StringName &p_extension_name) {
return additional_data.has(p_extension_name);
}
void GLTFNode::set_additional_data(const StringName &p_extension_name, Variant p_additional_data) {
additional_data[p_extension_name] = p_additional_data;
}
NodePath GLTFNode::get_scene_node_path(Ref<GLTFState> p_state, bool p_handle_skeletons) {
Vector<StringName> path;
Vector<StringName> subpath;
Ref<GLTFNode> current_gltf_node = this;
const int gltf_node_count = p_state->nodes.size();
if (p_handle_skeletons && skeleton != -1) {
// Special case for skeleton nodes, skip all bones so that the path is to the Skeleton3D node.
// A path that would otherwise be `A/B/C/Bone1/Bone2/Bone3` becomes `A/B/C/Skeleton3D:Bone3`.
subpath.append(get_name());
// The generated Skeleton3D node will be named Skeleton3D, so add it to the path.
path.append("Skeleton3D");
do {
const int parent_index = current_gltf_node->get_parent();
ERR_FAIL_INDEX_V(parent_index, gltf_node_count, NodePath());
current_gltf_node = p_state->nodes[parent_index];
} while (current_gltf_node->skeleton != -1);
}
const bool is_godot_single_root = p_state->extensions_used.has("GODOT_single_root");
while (true) {
const int parent_index = current_gltf_node->get_parent();
if (is_godot_single_root && parent_index == -1) {
// For GODOT_single_root scenes, the root glTF node becomes the Godot scene root, so it
// should not be included in the path. Ex: A/B/C, A is single root, we want B/C only.
break;
}
path.insert(0, current_gltf_node->get_name());
if (!is_godot_single_root && parent_index == -1) {
break;
}
ERR_FAIL_INDEX_V(parent_index, gltf_node_count, NodePath());
current_gltf_node = p_state->nodes[parent_index];
}
if (unlikely(path.is_empty())) {
path.append(".");
}
return NodePath(path, subpath, false);
}

View File

@@ -0,0 +1,113 @@
/**************************************************************************/
/* gltf_node.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "../gltf_defines.h"
#include "core/io/resource.h"
class GLTFNode : public Resource {
GDCLASS(GLTFNode, Resource);
friend class GLTFDocument;
friend class SkinTool;
friend class FBXDocument;
private:
String original_name;
GLTFNodeIndex parent = -1;
int height = -1;
Transform3D transform;
GLTFMeshIndex mesh = -1;
GLTFCameraIndex camera = -1;
GLTFSkinIndex skin = -1;
GLTFSkeletonIndex skeleton = -1;
bool joint = false;
bool visible = true;
Vector<int> children;
GLTFLightIndex light = -1;
Dictionary additional_data;
protected:
static void _bind_methods();
public:
String get_original_name();
void set_original_name(String p_name);
GLTFNodeIndex get_parent();
void set_parent(GLTFNodeIndex p_parent);
int get_height();
void set_height(int p_height);
Transform3D get_xform();
void set_xform(Transform3D p_xform);
Transform3D get_rest_xform();
void set_rest_xform(Transform3D p_rest_xform);
GLTFMeshIndex get_mesh();
void set_mesh(GLTFMeshIndex p_mesh);
GLTFCameraIndex get_camera();
void set_camera(GLTFCameraIndex p_camera);
GLTFSkinIndex get_skin();
void set_skin(GLTFSkinIndex p_skin);
GLTFSkeletonIndex get_skeleton();
void set_skeleton(GLTFSkeletonIndex p_skeleton);
Vector3 get_position();
void set_position(Vector3 p_position);
Quaternion get_rotation();
void set_rotation(Quaternion p_rotation);
Vector3 get_scale();
void set_scale(Vector3 p_scale);
Vector<int> get_children();
void set_children(Vector<int> p_children);
void append_child_index(int p_child_index);
GLTFLightIndex get_light();
void set_light(GLTFLightIndex p_light);
bool get_visible();
void set_visible(bool p_visible);
Variant get_additional_data(const StringName &p_extension_name);
bool has_additional_data(const StringName &p_extension_name);
void set_additional_data(const StringName &p_extension_name, Variant p_additional_data);
NodePath get_scene_node_path(Ref<GLTFState> p_state, bool p_handle_skeletons = true);
};

View File

@@ -0,0 +1,173 @@
/**************************************************************************/
/* gltf_object_model_property.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_object_model_property.h"
#include "../gltf_template_convert.h"
void GLTFObjectModelProperty::_bind_methods() {
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_UNKNOWN);
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_BOOL);
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT);
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT_ARRAY);
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT2);
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT3);
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT4);
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT2X2);
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT3X3);
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT4X4);
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_INT);
ClassDB::bind_method(D_METHOD("append_node_path", "node_path"), &GLTFObjectModelProperty::append_node_path);
ClassDB::bind_method(D_METHOD("append_path_to_property", "node_path", "prop_name"), &GLTFObjectModelProperty::append_path_to_property);
ClassDB::bind_method(D_METHOD("get_accessor_type"), &GLTFObjectModelProperty::get_accessor_type);
ClassDB::bind_method(D_METHOD("get_gltf_to_godot_expression"), &GLTFObjectModelProperty::get_gltf_to_godot_expression);
ClassDB::bind_method(D_METHOD("set_gltf_to_godot_expression", "gltf_to_godot_expr"), &GLTFObjectModelProperty::set_gltf_to_godot_expression);
ClassDB::bind_method(D_METHOD("get_godot_to_gltf_expression"), &GLTFObjectModelProperty::get_godot_to_gltf_expression);
ClassDB::bind_method(D_METHOD("set_godot_to_gltf_expression", "godot_to_gltf_expr"), &GLTFObjectModelProperty::set_godot_to_gltf_expression);
ClassDB::bind_method(D_METHOD("get_node_paths"), &GLTFObjectModelProperty::get_node_paths);
ClassDB::bind_method(D_METHOD("has_node_paths"), &GLTFObjectModelProperty::has_node_paths);
ClassDB::bind_method(D_METHOD("set_node_paths", "node_paths"), &GLTFObjectModelProperty::set_node_paths);
ClassDB::bind_method(D_METHOD("get_object_model_type"), &GLTFObjectModelProperty::get_object_model_type);
ClassDB::bind_method(D_METHOD("set_object_model_type", "type"), &GLTFObjectModelProperty::set_object_model_type);
ClassDB::bind_method(D_METHOD("get_json_pointers"), &GLTFObjectModelProperty::get_json_pointers_bind);
ClassDB::bind_method(D_METHOD("has_json_pointers"), &GLTFObjectModelProperty::has_json_pointers);
ClassDB::bind_method(D_METHOD("set_json_pointers", "json_pointers"), &GLTFObjectModelProperty::set_json_pointers_bind);
ClassDB::bind_method(D_METHOD("get_variant_type"), &GLTFObjectModelProperty::get_variant_type);
ClassDB::bind_method(D_METHOD("set_variant_type", "variant_type"), &GLTFObjectModelProperty::set_variant_type);
ClassDB::bind_method(D_METHOD("set_types", "variant_type", "obj_model_type"), &GLTFObjectModelProperty::set_types);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gltf_to_godot_expression", PROPERTY_HINT_RESOURCE_TYPE, "Expression"), "set_gltf_to_godot_expression", "get_gltf_to_godot_expression"); // Ref<Expression>
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "godot_to_gltf_expression", PROPERTY_HINT_RESOURCE_TYPE, "Expression"), "set_godot_to_gltf_expression", "get_godot_to_gltf_expression"); // Ref<Expression>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "node_paths", PROPERTY_HINT_TYPE_STRING, "NodePath"), "set_node_paths", "get_node_paths"); // TypedArray<NodePath>
ADD_PROPERTY(PropertyInfo(Variant::INT, "object_model_type"), "set_object_model_type", "get_object_model_type"); // GLTFObjectModelType
ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "json_pointers"), "set_json_pointers", "get_json_pointers"); // TypedArray<PackedStringArray>
ADD_PROPERTY(PropertyInfo(Variant::INT, "variant_type"), "set_variant_type", "get_variant_type"); // Variant::Type
}
void GLTFObjectModelProperty::append_node_path(const NodePath &p_node_path) {
node_paths.push_back(p_node_path);
}
void GLTFObjectModelProperty::append_path_to_property(const NodePath &p_node_path, const StringName &p_prop_name) {
Vector<StringName> node_names = p_node_path.get_names();
Vector<StringName> subpath = p_node_path.get_subnames();
subpath.append(p_prop_name);
node_paths.push_back(NodePath(node_names, subpath, false));
}
GLTFAccessor::GLTFAccessorType GLTFObjectModelProperty::get_accessor_type() const {
switch (object_model_type) {
case GLTF_OBJECT_MODEL_TYPE_FLOAT2:
return GLTFAccessor::TYPE_VEC2;
case GLTF_OBJECT_MODEL_TYPE_FLOAT3:
return GLTFAccessor::TYPE_VEC3;
case GLTF_OBJECT_MODEL_TYPE_FLOAT4:
return GLTFAccessor::TYPE_VEC4;
case GLTF_OBJECT_MODEL_TYPE_FLOAT2X2:
return GLTFAccessor::TYPE_MAT2;
case GLTF_OBJECT_MODEL_TYPE_FLOAT3X3:
return GLTFAccessor::TYPE_MAT3;
case GLTF_OBJECT_MODEL_TYPE_FLOAT4X4:
return GLTFAccessor::TYPE_MAT4;
default:
return GLTFAccessor::TYPE_SCALAR;
}
}
Ref<Expression> GLTFObjectModelProperty::get_gltf_to_godot_expression() const {
return gltf_to_godot_expr;
}
void GLTFObjectModelProperty::set_gltf_to_godot_expression(Ref<Expression> p_gltf_to_godot_expr) {
gltf_to_godot_expr = p_gltf_to_godot_expr;
}
Ref<Expression> GLTFObjectModelProperty::get_godot_to_gltf_expression() const {
return godot_to_gltf_expr;
}
void GLTFObjectModelProperty::set_godot_to_gltf_expression(Ref<Expression> p_godot_to_gltf_expr) {
godot_to_gltf_expr = p_godot_to_gltf_expr;
}
TypedArray<NodePath> GLTFObjectModelProperty::get_node_paths() const {
return node_paths;
}
bool GLTFObjectModelProperty::has_node_paths() const {
return !node_paths.is_empty();
}
void GLTFObjectModelProperty::set_node_paths(TypedArray<NodePath> p_node_paths) {
node_paths = p_node_paths;
}
GLTFObjectModelProperty::GLTFObjectModelType GLTFObjectModelProperty::get_object_model_type() const {
return object_model_type;
}
void GLTFObjectModelProperty::set_object_model_type(GLTFObjectModelType p_type) {
object_model_type = p_type;
}
Vector<PackedStringArray> GLTFObjectModelProperty::get_json_pointers() const {
return json_pointers;
}
bool GLTFObjectModelProperty::has_json_pointers() const {
return !json_pointers.is_empty();
}
void GLTFObjectModelProperty::set_json_pointers(const Vector<PackedStringArray> &p_json_pointers) {
json_pointers = p_json_pointers;
}
TypedArray<PackedStringArray> GLTFObjectModelProperty::get_json_pointers_bind() const {
return GLTFTemplateConvert::to_array(json_pointers);
}
void GLTFObjectModelProperty::set_json_pointers_bind(const TypedArray<PackedStringArray> &p_json_pointers) {
GLTFTemplateConvert::set_from_array(json_pointers, p_json_pointers);
}
Variant::Type GLTFObjectModelProperty::get_variant_type() const {
return variant_type;
}
void GLTFObjectModelProperty::set_variant_type(Variant::Type p_variant_type) {
variant_type = p_variant_type;
}
void GLTFObjectModelProperty::set_types(Variant::Type p_variant_type, GLTFObjectModelType p_obj_model_type) {
variant_type = p_variant_type;
object_model_type = p_obj_model_type;
}

View File

@@ -0,0 +1,101 @@
/**************************************************************************/
/* gltf_object_model_property.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "core/math/expression.h"
#include "core/variant/typed_array.h"
#include "gltf_accessor.h"
// Object model: https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/ObjectModel.adoc
// KHR_animation_pointer: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_animation_pointer
class GLTFObjectModelProperty : public RefCounted {
GDCLASS(GLTFObjectModelProperty, RefCounted);
public:
enum GLTFObjectModelType {
GLTF_OBJECT_MODEL_TYPE_UNKNOWN,
GLTF_OBJECT_MODEL_TYPE_BOOL,
GLTF_OBJECT_MODEL_TYPE_FLOAT,
GLTF_OBJECT_MODEL_TYPE_FLOAT_ARRAY,
GLTF_OBJECT_MODEL_TYPE_FLOAT2,
GLTF_OBJECT_MODEL_TYPE_FLOAT3,
GLTF_OBJECT_MODEL_TYPE_FLOAT4,
GLTF_OBJECT_MODEL_TYPE_FLOAT2X2,
GLTF_OBJECT_MODEL_TYPE_FLOAT3X3,
GLTF_OBJECT_MODEL_TYPE_FLOAT4X4,
GLTF_OBJECT_MODEL_TYPE_INT,
};
private:
Ref<Expression> gltf_to_godot_expr;
Ref<Expression> godot_to_gltf_expr;
TypedArray<NodePath> node_paths;
GLTFObjectModelType object_model_type = GLTF_OBJECT_MODEL_TYPE_UNKNOWN;
Vector<PackedStringArray> json_pointers;
Variant::Type variant_type = Variant::NIL;
protected:
static void _bind_methods();
public:
void append_node_path(const NodePath &p_node_path);
void append_path_to_property(const NodePath &p_node_path, const StringName &p_prop_name);
GLTFAccessor::GLTFAccessorType get_accessor_type() const;
Ref<Expression> get_gltf_to_godot_expression() const;
void set_gltf_to_godot_expression(Ref<Expression> p_gltf_to_godot_expr);
Ref<Expression> get_godot_to_gltf_expression() const;
void set_godot_to_gltf_expression(Ref<Expression> p_godot_to_gltf_expr);
TypedArray<NodePath> get_node_paths() const;
bool has_node_paths() const;
void set_node_paths(TypedArray<NodePath> p_node_paths);
GLTFObjectModelType get_object_model_type() const;
void set_object_model_type(GLTFObjectModelType p_type);
Vector<PackedStringArray> get_json_pointers() const;
bool has_json_pointers() const;
void set_json_pointers(const Vector<PackedStringArray> &p_json_pointers);
TypedArray<PackedStringArray> get_json_pointers_bind() const;
void set_json_pointers_bind(const TypedArray<PackedStringArray> &p_json_pointers);
Variant::Type get_variant_type() const;
void set_variant_type(Variant::Type p_variant_type);
void set_types(Variant::Type p_variant_type, GLTFObjectModelType p_obj_model_type);
};
VARIANT_ENUM_CAST(GLTFObjectModelProperty::GLTFObjectModelType);

View File

@@ -0,0 +1,99 @@
/**************************************************************************/
/* gltf_skeleton.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_skeleton.h"
#include "../gltf_template_convert.h"
#include "scene/3d/bone_attachment_3d.h"
void GLTFSkeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_joints"), &GLTFSkeleton::get_joints);
ClassDB::bind_method(D_METHOD("set_joints", "joints"), &GLTFSkeleton::set_joints);
ClassDB::bind_method(D_METHOD("get_roots"), &GLTFSkeleton::get_roots);
ClassDB::bind_method(D_METHOD("set_roots", "roots"), &GLTFSkeleton::set_roots);
ClassDB::bind_method(D_METHOD("get_godot_skeleton"), &GLTFSkeleton::get_godot_skeleton);
ClassDB::bind_method(D_METHOD("get_unique_names"), &GLTFSkeleton::get_unique_names);
ClassDB::bind_method(D_METHOD("set_unique_names", "unique_names"), &GLTFSkeleton::set_unique_names);
ClassDB::bind_method(D_METHOD("get_godot_bone_node"), &GLTFSkeleton::get_godot_bone_node);
ClassDB::bind_method(D_METHOD("set_godot_bone_node", "godot_bone_node"), &GLTFSkeleton::set_godot_bone_node);
ClassDB::bind_method(D_METHOD("get_bone_attachment_count"), &GLTFSkeleton::get_bone_attachment_count);
ClassDB::bind_method(D_METHOD("get_bone_attachment", "idx"), &GLTFSkeleton::get_bone_attachment);
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "joints"), "set_joints", "get_joints"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_names", "get_unique_names"); // Set<String>
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "godot_bone_node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_godot_bone_node", "get_godot_bone_node"); // RBMap<int32_t,
}
Vector<GLTFNodeIndex> GLTFSkeleton::get_joints() {
return joints;
}
void GLTFSkeleton::set_joints(Vector<GLTFNodeIndex> p_joints) {
joints = p_joints;
}
Vector<GLTFNodeIndex> GLTFSkeleton::get_roots() {
return roots;
}
void GLTFSkeleton::set_roots(Vector<GLTFNodeIndex> p_roots) {
roots = p_roots;
}
Skeleton3D *GLTFSkeleton::get_godot_skeleton() {
return godot_skeleton;
}
TypedArray<String> GLTFSkeleton::get_unique_names() {
return GLTFTemplateConvert::to_array(unique_names);
}
void GLTFSkeleton::set_unique_names(TypedArray<String> p_unique_names) {
GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
}
Dictionary GLTFSkeleton::get_godot_bone_node() {
return GLTFTemplateConvert::to_dictionary(godot_bone_node);
}
void GLTFSkeleton::set_godot_bone_node(Dictionary p_indict) {
GLTFTemplateConvert::set_from_dictionary(godot_bone_node, p_indict);
}
BoneAttachment3D *GLTFSkeleton::get_bone_attachment(int idx) {
ERR_FAIL_INDEX_V(idx, bone_attachments.size(), nullptr);
return bone_attachments[idx];
}
int32_t GLTFSkeleton::get_bone_attachment_count() {
return bone_attachments.size();
}

View File

@@ -0,0 +1,104 @@
/**************************************************************************/
/* gltf_skeleton.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "../gltf_defines.h"
#include "core/io/resource.h"
#include "scene/3d/bone_attachment_3d.h"
#include "scene/3d/skeleton_3d.h"
class GLTFSkeleton : public Resource {
GDCLASS(GLTFSkeleton, Resource);
friend class GLTFDocument;
friend class SkinTool;
friend class FBXDocument;
private:
// The *synthesized* skeletons joints
Vector<GLTFNodeIndex> joints;
// The roots of the skeleton. If there are multiple, each root must have the
// same parent (ie roots are siblings)
Vector<GLTFNodeIndex> roots;
// The created Skeleton3D for the scene
Skeleton3D *godot_skeleton = nullptr;
// Set of unique bone names for the skeleton
HashSet<String> unique_names;
HashMap<int32_t, GLTFNodeIndex> godot_bone_node;
Vector<BoneAttachment3D *> bone_attachments;
protected:
static void _bind_methods();
public:
Vector<GLTFNodeIndex> get_joints();
void set_joints(Vector<GLTFNodeIndex> p_joints);
Vector<GLTFNodeIndex> get_roots();
void set_roots(Vector<GLTFNodeIndex> p_roots);
Skeleton3D *get_godot_skeleton();
// Skeleton *get_godot_skeleton() {
// return godot_skeleton;
// }
// void set_godot_skeleton(Skeleton p_*godot_skeleton) {
// godot_skeleton = p_godot_skeleton;
// }
TypedArray<String> get_unique_names();
void set_unique_names(TypedArray<String> p_unique_names);
//RBMap<int32_t, GLTFNodeIndex> get_godot_bone_node() {
// return godot_bone_node;
//}
//void set_godot_bone_node(const RBMap<int32_t, GLTFNodeIndex> &p_godot_bone_node) {
// godot_bone_node = p_godot_bone_node;
//}
Dictionary get_godot_bone_node();
void set_godot_bone_node(Dictionary p_indict);
//Dictionary get_godot_bone_node() {
// return VariantConversion::to_dict(godot_bone_node);
//}
//void set_godot_bone_node(Dictionary p_indict) {
// VariantConversion::set_from_dict(godot_bone_node, p_indict);
//}
BoneAttachment3D *get_bone_attachment(int idx);
int32_t get_bone_attachment_count();
};

View File

@@ -0,0 +1,277 @@
/**************************************************************************/
/* gltf_skin.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_skin.h"
#include "../gltf_template_convert.h"
#include "core/variant/typed_array.h"
#include "scene/resources/3d/skin.h"
void GLTFSkin::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_skin_root"), &GLTFSkin::get_skin_root);
ClassDB::bind_method(D_METHOD("set_skin_root", "skin_root"), &GLTFSkin::set_skin_root);
ClassDB::bind_method(D_METHOD("get_joints_original"), &GLTFSkin::get_joints_original);
ClassDB::bind_method(D_METHOD("set_joints_original", "joints_original"), &GLTFSkin::set_joints_original);
ClassDB::bind_method(D_METHOD("get_inverse_binds"), &GLTFSkin::get_inverse_binds);
ClassDB::bind_method(D_METHOD("set_inverse_binds", "inverse_binds"), &GLTFSkin::set_inverse_binds);
ClassDB::bind_method(D_METHOD("get_joints"), &GLTFSkin::get_joints);
ClassDB::bind_method(D_METHOD("set_joints", "joints"), &GLTFSkin::set_joints);
ClassDB::bind_method(D_METHOD("get_non_joints"), &GLTFSkin::get_non_joints);
ClassDB::bind_method(D_METHOD("set_non_joints", "non_joints"), &GLTFSkin::set_non_joints);
ClassDB::bind_method(D_METHOD("get_roots"), &GLTFSkin::get_roots);
ClassDB::bind_method(D_METHOD("set_roots", "roots"), &GLTFSkin::set_roots);
ClassDB::bind_method(D_METHOD("get_skeleton"), &GLTFSkin::get_skeleton);
ClassDB::bind_method(D_METHOD("set_skeleton", "skeleton"), &GLTFSkin::set_skeleton);
ClassDB::bind_method(D_METHOD("get_joint_i_to_bone_i"), &GLTFSkin::get_joint_i_to_bone_i);
ClassDB::bind_method(D_METHOD("set_joint_i_to_bone_i", "joint_i_to_bone_i"), &GLTFSkin::set_joint_i_to_bone_i);
ClassDB::bind_method(D_METHOD("get_joint_i_to_name"), &GLTFSkin::get_joint_i_to_name);
ClassDB::bind_method(D_METHOD("set_joint_i_to_name", "joint_i_to_name"), &GLTFSkin::set_joint_i_to_name);
ClassDB::bind_method(D_METHOD("get_godot_skin"), &GLTFSkin::get_godot_skin);
ClassDB::bind_method(D_METHOD("set_godot_skin", "godot_skin"), &GLTFSkin::set_godot_skin);
ADD_PROPERTY(PropertyInfo(Variant::INT, "skin_root"), "set_skin_root", "get_skin_root"); // GLTFNodeIndex
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "joints_original"), "set_joints_original", "get_joints_original"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "inverse_binds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_inverse_binds", "get_inverse_binds"); // Vector<Transform3D>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "joints"), "set_joints", "get_joints"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "non_joints"), "set_non_joints", "get_non_joints"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::INT, "skeleton"), "set_skeleton", "get_skeleton"); // int
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "joint_i_to_bone_i", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_joint_i_to_bone_i", "get_joint_i_to_bone_i"); // RBMap<int,
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "joint_i_to_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_joint_i_to_name", "get_joint_i_to_name"); // RBMap<int,
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "godot_skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_godot_skin", "get_godot_skin"); // Ref<Skin>
}
GLTFNodeIndex GLTFSkin::get_skin_root() {
return skin_root;
}
void GLTFSkin::set_skin_root(GLTFNodeIndex p_skin_root) {
skin_root = p_skin_root;
}
Vector<GLTFNodeIndex> GLTFSkin::get_joints_original() {
return joints_original;
}
void GLTFSkin::set_joints_original(Vector<GLTFNodeIndex> p_joints_original) {
joints_original = p_joints_original;
}
TypedArray<Transform3D> GLTFSkin::get_inverse_binds() {
return GLTFTemplateConvert::to_array(inverse_binds);
}
void GLTFSkin::set_inverse_binds(TypedArray<Transform3D> p_inverse_binds) {
GLTFTemplateConvert::set_from_array(inverse_binds, p_inverse_binds);
}
Vector<GLTFNodeIndex> GLTFSkin::get_joints() {
return joints;
}
void GLTFSkin::set_joints(Vector<GLTFNodeIndex> p_joints) {
joints = p_joints;
}
Vector<GLTFNodeIndex> GLTFSkin::get_non_joints() {
return non_joints;
}
void GLTFSkin::set_non_joints(Vector<GLTFNodeIndex> p_non_joints) {
non_joints = p_non_joints;
}
Vector<GLTFNodeIndex> GLTFSkin::get_roots() {
return roots;
}
void GLTFSkin::set_roots(Vector<GLTFNodeIndex> p_roots) {
roots = p_roots;
}
int GLTFSkin::get_skeleton() {
return skeleton;
}
void GLTFSkin::set_skeleton(int p_skeleton) {
skeleton = p_skeleton;
}
Dictionary GLTFSkin::get_joint_i_to_bone_i() {
return GLTFTemplateConvert::to_dictionary(joint_i_to_bone_i);
}
void GLTFSkin::set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i) {
GLTFTemplateConvert::set_from_dictionary(joint_i_to_bone_i, p_joint_i_to_bone_i);
}
Dictionary GLTFSkin::get_joint_i_to_name() {
Dictionary ret;
HashMap<int, StringName>::Iterator elem = joint_i_to_name.begin();
while (elem) {
ret[elem->key] = String(elem->value);
++elem;
}
return ret;
}
void GLTFSkin::set_joint_i_to_name(Dictionary p_joint_i_to_name) {
joint_i_to_name = HashMap<int, StringName>();
for (const KeyValue<Variant, Variant> &kv : p_joint_i_to_name) {
joint_i_to_name[kv.key] = kv.value;
}
}
Ref<Skin> GLTFSkin::get_godot_skin() {
return godot_skin;
}
void GLTFSkin::set_godot_skin(Ref<Skin> p_godot_skin) {
godot_skin = p_godot_skin;
}
Error GLTFSkin::from_dictionary(const Dictionary &dict) {
ERR_FAIL_COND_V(!dict.has("skin_root"), ERR_INVALID_DATA);
skin_root = dict["skin_root"];
ERR_FAIL_COND_V(!dict.has("joints_original"), ERR_INVALID_DATA);
Array joints_original_array = dict["joints_original"];
joints_original.clear();
for (int i = 0; i < joints_original_array.size(); ++i) {
joints_original.push_back(joints_original_array[i]);
}
ERR_FAIL_COND_V(!dict.has("inverse_binds"), ERR_INVALID_DATA);
Array inverse_binds_array = dict["inverse_binds"];
inverse_binds.clear();
for (int i = 0; i < inverse_binds_array.size(); ++i) {
ERR_FAIL_COND_V(inverse_binds_array[i].get_type() != Variant::TRANSFORM3D, ERR_INVALID_DATA);
inverse_binds.push_back(inverse_binds_array[i]);
}
ERR_FAIL_COND_V(!dict.has("joints"), ERR_INVALID_DATA);
Array joints_array = dict["joints"];
joints.clear();
for (int i = 0; i < joints_array.size(); ++i) {
joints.push_back(joints_array[i]);
}
ERR_FAIL_COND_V(!dict.has("non_joints"), ERR_INVALID_DATA);
Array non_joints_array = dict["non_joints"];
non_joints.clear();
for (int i = 0; i < non_joints_array.size(); ++i) {
non_joints.push_back(non_joints_array[i]);
}
ERR_FAIL_COND_V(!dict.has("roots"), ERR_INVALID_DATA);
Array roots_array = dict["roots"];
roots.clear();
for (int i = 0; i < roots_array.size(); ++i) {
roots.push_back(roots_array[i]);
}
ERR_FAIL_COND_V(!dict.has("skeleton"), ERR_INVALID_DATA);
skeleton = dict["skeleton"];
ERR_FAIL_COND_V(!dict.has("joint_i_to_bone_i"), ERR_INVALID_DATA);
Dictionary joint_i_to_bone_i_dict = dict["joint_i_to_bone_i"];
joint_i_to_bone_i.clear();
for (const KeyValue<Variant, Variant> &kv : joint_i_to_bone_i_dict) {
int key = kv.key;
int value = kv.value;
joint_i_to_bone_i[key] = value;
}
ERR_FAIL_COND_V(!dict.has("joint_i_to_name"), ERR_INVALID_DATA);
Dictionary joint_i_to_name_dict = dict["joint_i_to_name"];
joint_i_to_name.clear();
for (const KeyValue<Variant, Variant> &kv : joint_i_to_name_dict) {
int key = kv.key;
StringName value = kv.value;
joint_i_to_name[key] = value;
}
if (dict.has("godot_skin")) {
godot_skin = dict["godot_skin"];
}
return OK;
}
Dictionary GLTFSkin::to_dictionary() {
Dictionary dict;
dict["skin_root"] = skin_root;
Array joints_original_array;
for (int i = 0; i < joints_original.size(); ++i) {
joints_original_array.push_back(joints_original[i]);
}
dict["joints_original"] = joints_original_array;
Array inverse_binds_array;
for (int i = 0; i < inverse_binds.size(); ++i) {
inverse_binds_array.push_back(inverse_binds[i]);
}
dict["inverse_binds"] = inverse_binds_array;
Array joints_array;
for (int i = 0; i < joints.size(); ++i) {
joints_array.push_back(joints[i]);
}
dict["joints"] = joints_array;
Array non_joints_array;
for (int i = 0; i < non_joints.size(); ++i) {
non_joints_array.push_back(non_joints[i]);
}
dict["non_joints"] = non_joints_array;
Array roots_array;
for (int i = 0; i < roots.size(); ++i) {
roots_array.push_back(roots[i]);
}
dict["roots"] = roots_array;
dict["skeleton"] = skeleton;
Dictionary joint_i_to_bone_i_dict;
for (HashMap<int, int>::Iterator E = joint_i_to_bone_i.begin(); E; ++E) {
joint_i_to_bone_i_dict[E->key] = E->value;
}
dict["joint_i_to_bone_i"] = joint_i_to_bone_i_dict;
Dictionary joint_i_to_name_dict;
for (HashMap<int, StringName>::Iterator E = joint_i_to_name.begin(); E; ++E) {
joint_i_to_name_dict[E->key] = E->value;
}
dict["joint_i_to_name"] = joint_i_to_name_dict;
dict["godot_skin"] = godot_skin;
return dict;
}

View File

@@ -0,0 +1,117 @@
/**************************************************************************/
/* gltf_skin.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "../gltf_defines.h"
#include "core/io/resource.h"
#include "scene/resources/3d/skin.h"
template <typename T>
class TypedArray;
class GLTFSkin : public Resource {
GDCLASS(GLTFSkin, Resource);
friend class GLTFDocument;
friend class SkinTool;
friend class FBXDocument;
private:
// The "skeleton" property defined in the gltf spec. -1 = Scene Root
GLTFNodeIndex skin_root = -1;
Vector<GLTFNodeIndex> joints_original;
Vector<Transform3D> inverse_binds;
// Note: joints + non_joints should form a complete subtree, or subtrees
// with a common parent
// All nodes that are skins that are caught in-between the original joints
// (inclusive of joints_original)
Vector<GLTFNodeIndex> joints;
// All Nodes that are caught in-between skin joint nodes, and are not
// defined as joints by any skin
Vector<GLTFNodeIndex> non_joints;
// The roots of the skin. In the case of multiple roots, their parent *must*
// be the same (the roots must be siblings)
Vector<GLTFNodeIndex> roots;
// The GLTF Skeleton this Skin points to (after we determine skeletons)
GLTFSkeletonIndex skeleton = -1;
// A mapping from the joint indices (in the order of joints_original) to the
// Godot Skeleton's bone_indices
HashMap<int, int> joint_i_to_bone_i;
HashMap<int, StringName> joint_i_to_name;
// The Actual Skin that will be created as a mapping between the IBM's of
// this skin to the generated skeleton for the mesh instances.
Ref<Skin> godot_skin;
protected:
static void _bind_methods();
public:
GLTFNodeIndex get_skin_root();
void set_skin_root(GLTFNodeIndex p_skin_root);
Vector<GLTFNodeIndex> get_joints_original();
void set_joints_original(Vector<GLTFNodeIndex> p_joints_original);
TypedArray<Transform3D> get_inverse_binds();
void set_inverse_binds(TypedArray<Transform3D> p_inverse_binds);
Vector<GLTFNodeIndex> get_joints();
void set_joints(Vector<GLTFNodeIndex> p_joints);
Vector<GLTFNodeIndex> get_non_joints();
void set_non_joints(Vector<GLTFNodeIndex> p_non_joints);
Vector<GLTFNodeIndex> get_roots();
void set_roots(Vector<GLTFNodeIndex> p_roots);
int get_skeleton();
void set_skeleton(int p_skeleton);
Dictionary get_joint_i_to_bone_i();
void set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i);
Dictionary get_joint_i_to_name();
void set_joint_i_to_name(Dictionary p_joint_i_to_name);
Ref<Skin> get_godot_skin();
void set_godot_skin(Ref<Skin> p_godot_skin);
Dictionary to_dictionary();
Error from_dictionary(const Dictionary &dict);
};

View File

@@ -0,0 +1,57 @@
/**************************************************************************/
/* gltf_texture.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_texture.h"
void GLTFTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_src_image"), &GLTFTexture::get_src_image);
ClassDB::bind_method(D_METHOD("set_src_image", "src_image"), &GLTFTexture::set_src_image);
ClassDB::bind_method(D_METHOD("get_sampler"), &GLTFTexture::get_sampler);
ClassDB::bind_method(D_METHOD("set_sampler", "sampler"), &GLTFTexture::set_sampler);
ADD_PROPERTY(PropertyInfo(Variant::INT, "src_image"), "set_src_image", "get_src_image"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "sampler"), "set_sampler", "get_sampler"); // int
}
GLTFImageIndex GLTFTexture::get_src_image() const {
return src_image;
}
void GLTFTexture::set_src_image(GLTFImageIndex val) {
src_image = val;
}
GLTFTextureSamplerIndex GLTFTexture::get_sampler() const {
return sampler;
}
void GLTFTexture::set_sampler(GLTFTextureSamplerIndex val) {
sampler = val;
}

View File

@@ -0,0 +1,52 @@
/**************************************************************************/
/* gltf_texture.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "../gltf_defines.h"
#include "core/io/resource.h"
class GLTFTexture : public Resource {
GDCLASS(GLTFTexture, Resource);
private:
GLTFImageIndex src_image = -1;
GLTFTextureSamplerIndex sampler = -1;
protected:
static void _bind_methods();
public:
GLTFImageIndex get_src_image() const;
void set_src_image(GLTFImageIndex val);
GLTFTextureSamplerIndex get_sampler() const;
void set_sampler(GLTFTextureSamplerIndex val);
};

View File

@@ -0,0 +1,47 @@
/**************************************************************************/
/* gltf_texture_sampler.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 "gltf_texture_sampler.h"
void GLTFTextureSampler::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_mag_filter"), &GLTFTextureSampler::get_mag_filter);
ClassDB::bind_method(D_METHOD("set_mag_filter", "filter_mode"), &GLTFTextureSampler::set_mag_filter);
ClassDB::bind_method(D_METHOD("get_min_filter"), &GLTFTextureSampler::get_min_filter);
ClassDB::bind_method(D_METHOD("set_min_filter", "filter_mode"), &GLTFTextureSampler::set_min_filter);
ClassDB::bind_method(D_METHOD("get_wrap_s"), &GLTFTextureSampler::get_wrap_s);
ClassDB::bind_method(D_METHOD("set_wrap_s", "wrap_mode"), &GLTFTextureSampler::set_wrap_s);
ClassDB::bind_method(D_METHOD("get_wrap_t"), &GLTFTextureSampler::get_wrap_t);
ClassDB::bind_method(D_METHOD("set_wrap_t", "wrap_mode"), &GLTFTextureSampler::set_wrap_t);
ADD_PROPERTY(PropertyInfo(Variant::INT, "mag_filter"), "set_mag_filter", "get_mag_filter");
ADD_PROPERTY(PropertyInfo(Variant::INT, "min_filter"), "set_min_filter", "get_min_filter");
ADD_PROPERTY(PropertyInfo(Variant::INT, "wrap_s"), "set_wrap_s", "get_wrap_s");
ADD_PROPERTY(PropertyInfo(Variant::INT, "wrap_t"), "set_wrap_t", "get_wrap_t");
}

View File

@@ -0,0 +1,159 @@
/**************************************************************************/
/* gltf_texture_sampler.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
#pragma once
#include "scene/resources/material.h"
class GLTFTextureSampler : public Resource {
GDCLASS(GLTFTextureSampler, Resource);
public:
enum FilterMode {
NEAREST = 9728,
LINEAR = 9729,
NEAREST_MIPMAP_NEAREST = 9984,
LINEAR_MIPMAP_NEAREST = 9985,
NEAREST_MIPMAP_LINEAR = 9986,
LINEAR_MIPMAP_LINEAR = 9987
};
enum WrapMode {
CLAMP_TO_EDGE = 33071,
MIRRORED_REPEAT = 33648,
REPEAT = 10497,
DEFAULT = REPEAT
};
int get_mag_filter() const {
return mag_filter;
}
void set_mag_filter(const int filter_mode) {
mag_filter = (FilterMode)filter_mode;
}
int get_min_filter() const {
return min_filter;
}
void set_min_filter(const int filter_mode) {
min_filter = (FilterMode)filter_mode;
}
int get_wrap_s() const {
return wrap_s;
}
void set_wrap_s(const int wrap_mode) {
wrap_s = (WrapMode)wrap_mode;
}
int get_wrap_t() const {
return wrap_t;
}
void set_wrap_t(const int wrap_mode) {
wrap_s = (WrapMode)wrap_mode;
}
StandardMaterial3D::TextureFilter get_filter_mode() const {
using TextureFilter = StandardMaterial3D::TextureFilter;
switch (min_filter) {
case NEAREST:
return TextureFilter::TEXTURE_FILTER_NEAREST;
case LINEAR:
return TextureFilter::TEXTURE_FILTER_LINEAR;
case NEAREST_MIPMAP_NEAREST:
case NEAREST_MIPMAP_LINEAR:
return TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS;
case LINEAR_MIPMAP_NEAREST:
case LINEAR_MIPMAP_LINEAR:
default:
return TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS;
}
}
void set_filter_mode(StandardMaterial3D::TextureFilter mode) {
using TextureFilter = StandardMaterial3D::TextureFilter;
switch (mode) {
case TextureFilter::TEXTURE_FILTER_NEAREST:
min_filter = FilterMode::NEAREST;
mag_filter = FilterMode::NEAREST;
break;
case TextureFilter::TEXTURE_FILTER_LINEAR:
min_filter = FilterMode::LINEAR;
mag_filter = FilterMode::LINEAR;
break;
case TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS:
case TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC:
min_filter = FilterMode::NEAREST_MIPMAP_LINEAR;
mag_filter = FilterMode::NEAREST;
break;
case TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS:
case TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC:
default:
min_filter = FilterMode::LINEAR_MIPMAP_LINEAR;
mag_filter = FilterMode::LINEAR;
break;
}
}
bool get_wrap_mode() const {
// BaseMaterial3D presents wrapping as a boolean property. Either the texture is repeated
// in both dimensions, non-mirrored, or it isn't repeated at all. This will cause oddities
// when people import models having other wrapping mode combinations.
return (wrap_s == WrapMode::REPEAT) && (wrap_t == WrapMode::REPEAT);
}
void set_wrap_mode(bool mat_repeats) {
if (mat_repeats) {
wrap_s = WrapMode::REPEAT;
wrap_t = WrapMode::REPEAT;
} else {
wrap_s = WrapMode::CLAMP_TO_EDGE;
wrap_t = WrapMode::CLAMP_TO_EDGE;
}
}
protected:
static void _bind_methods();
private:
FilterMode mag_filter = FilterMode::LINEAR;
FilterMode min_filter = FilterMode::LINEAR_MIPMAP_LINEAR;
WrapMode wrap_s = WrapMode::REPEAT;
WrapMode wrap_t = WrapMode::REPEAT;
};
VARIANT_ENUM_CAST(GLTFTextureSampler::FilterMode);
VARIANT_ENUM_CAST(GLTFTextureSampler::WrapMode);