summaryrefslogtreecommitdiff
path: root/modules/gltf/gltf_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gltf/gltf_state.cpp')
-rw-r--r--modules/gltf/gltf_state.cpp236
1 files changed, 141 insertions, 95 deletions
diff --git a/modules/gltf/gltf_state.cpp b/modules/gltf/gltf_state.cpp
index 989fa476c2..252453dfc2 100644
--- a/modules/gltf/gltf_state.cpp
+++ b/modules/gltf/gltf_state.cpp
@@ -1,36 +1,39 @@
-/*************************************************************************/
-/* gltf_state.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* 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. */
-/*************************************************************************/
+/**************************************************************************/
+/* gltf_state.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_state.h"
+#include "gltf_template_convert.h"
+
void GLTFState::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("add_used_extension", "extension_name", "required"), &GLTFState::add_used_extension);
ClassDB::bind_method(D_METHOD("get_json"), &GLTFState::get_json);
ClassDB::bind_method(D_METHOD("set_json", "json"), &GLTFState::set_json);
ClassDB::bind_method(D_METHOD("get_major_version"), &GLTFState::get_major_version);
@@ -63,6 +66,8 @@ void GLTFState::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_root_nodes", "root_nodes"), &GLTFState::set_root_nodes);
ClassDB::bind_method(D_METHOD("get_textures"), &GLTFState::get_textures);
ClassDB::bind_method(D_METHOD("set_textures", "textures"), &GLTFState::set_textures);
+ ClassDB::bind_method(D_METHOD("get_texture_samplers"), &GLTFState::get_texture_samplers);
+ ClassDB::bind_method(D_METHOD("set_texture_samplers", "texture_samplers"), &GLTFState::set_texture_samplers);
ClassDB::bind_method(D_METHOD("get_images"), &GLTFState::get_images);
ClassDB::bind_method(D_METHOD("set_images", "images"), &GLTFState::set_images);
ClassDB::bind_method(D_METHOD("get_skins"), &GLTFState::get_skins);
@@ -79,9 +84,13 @@ void GLTFState::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_skeletons", "skeletons"), &GLTFState::set_skeletons);
ClassDB::bind_method(D_METHOD("get_skeleton_to_node"), &GLTFState::get_skeleton_to_node);
ClassDB::bind_method(D_METHOD("set_skeleton_to_node", "skeleton_to_node"), &GLTFState::set_skeleton_to_node);
+ ClassDB::bind_method(D_METHOD("get_create_animations"), &GLTFState::get_create_animations);
+ ClassDB::bind_method(D_METHOD("set_create_animations", "create_animations"), &GLTFState::set_create_animations);
ClassDB::bind_method(D_METHOD("get_animations"), &GLTFState::get_animations);
ClassDB::bind_method(D_METHOD("set_animations", "animations"), &GLTFState::set_animations);
ClassDB::bind_method(D_METHOD("get_scene_node", "idx"), &GLTFState::get_scene_node);
+ ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFState::get_additional_data);
+ ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFState::set_additional_data);
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "json"), "set_json", "get_json"); // Dictionary
ADD_PROPERTY(PropertyInfo(Variant::INT, "major_version"), "set_major_version", "get_major_version"); // int
@@ -98,6 +107,7 @@ void GLTFState::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_path"), "set_base_path", "get_base_path"); // String
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "root_nodes"), "set_root_nodes", "get_root_nodes"); // Vector<int>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "textures", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_textures", "get_textures"); // Vector<Ref<GLTFTexture>>
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "texture_samplers", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_texture_samplers", "get_texture_samplers"); //Vector<Ref<GLTFTextureSampler>>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "images", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_images", "get_images"); // Vector<Ref<Texture>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skins", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skins", "get_skins"); // Vector<Ref<GLTFSkin>>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "cameras", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_cameras", "get_cameras"); // Vector<Ref<GLTFCamera>>
@@ -106,9 +116,21 @@ void GLTFState::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_animation_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_animation_names", "get_unique_animation_names"); // Set<String>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skeletons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skeletons", "get_skeletons"); // Vector<Ref<GLTFSkeleton>>
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "skeleton_to_node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skeleton_to_node", "get_skeleton_to_node"); // RBMap<GLTFSkeletonIndex,
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "create_animations"), "set_create_animations", "get_create_animations"); // bool
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animations", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_animations", "get_animations"); // Vector<Ref<GLTFAnimation>>
}
+void GLTFState::add_used_extension(const String &p_extension_name, bool p_required) {
+ if (!extensions_used.has(p_extension_name)) {
+ extensions_used.push_back(p_extension_name);
+ }
+ if (p_required) {
+ if (!extensions_required.has(p_extension_name)) {
+ extensions_required.push_back(p_extension_name);
+ }
+ }
+}
+
Dictionary GLTFState::get_json() {
return json;
}
@@ -149,52 +171,52 @@ void GLTFState::set_use_named_skin_binds(bool p_use_named_skin_binds) {
use_named_skin_binds = p_use_named_skin_binds;
}
-Array GLTFState::get_nodes() {
- return GLTFDocument::to_array(nodes);
+TypedArray<GLTFNode> GLTFState::get_nodes() {
+ return GLTFTemplateConvert::to_array(nodes);
}
-void GLTFState::set_nodes(Array p_nodes) {
- GLTFDocument::set_from_array(nodes, p_nodes);
+void GLTFState::set_nodes(TypedArray<GLTFNode> p_nodes) {
+ GLTFTemplateConvert::set_from_array(nodes, p_nodes);
}
-Array GLTFState::get_buffers() {
- return GLTFDocument::to_array(buffers);
+TypedArray<PackedByteArray> GLTFState::get_buffers() {
+ return GLTFTemplateConvert::to_array(buffers);
}
-void GLTFState::set_buffers(Array p_buffers) {
- GLTFDocument::set_from_array(buffers, p_buffers);
+void GLTFState::set_buffers(TypedArray<PackedByteArray> p_buffers) {
+ GLTFTemplateConvert::set_from_array(buffers, p_buffers);
}
-Array GLTFState::get_buffer_views() {
- return GLTFDocument::to_array(buffer_views);
+TypedArray<GLTFBufferView> GLTFState::get_buffer_views() {
+ return GLTFTemplateConvert::to_array(buffer_views);
}
-void GLTFState::set_buffer_views(Array p_buffer_views) {
- GLTFDocument::set_from_array(buffer_views, p_buffer_views);
+void GLTFState::set_buffer_views(TypedArray<GLTFBufferView> p_buffer_views) {
+ GLTFTemplateConvert::set_from_array(buffer_views, p_buffer_views);
}
-Array GLTFState::get_accessors() {
- return GLTFDocument::to_array(accessors);
+TypedArray<GLTFAccessor> GLTFState::get_accessors() {
+ return GLTFTemplateConvert::to_array(accessors);
}
-void GLTFState::set_accessors(Array p_accessors) {
- GLTFDocument::set_from_array(accessors, p_accessors);
+void GLTFState::set_accessors(TypedArray<GLTFAccessor> p_accessors) {
+ GLTFTemplateConvert::set_from_array(accessors, p_accessors);
}
-Array GLTFState::get_meshes() {
- return GLTFDocument::to_array(meshes);
+TypedArray<GLTFMesh> GLTFState::get_meshes() {
+ return GLTFTemplateConvert::to_array(meshes);
}
-void GLTFState::set_meshes(Array p_meshes) {
- GLTFDocument::set_from_array(meshes, p_meshes);
+void GLTFState::set_meshes(TypedArray<GLTFMesh> p_meshes) {
+ GLTFTemplateConvert::set_from_array(meshes, p_meshes);
}
-Array GLTFState::get_materials() {
- return GLTFDocument::to_array(materials);
+TypedArray<Material> GLTFState::get_materials() {
+ return GLTFTemplateConvert::to_array(materials);
}
-void GLTFState::set_materials(Array p_materials) {
- GLTFDocument::set_from_array(materials, p_materials);
+void GLTFState::set_materials(TypedArray<Material> p_materials) {
+ GLTFTemplateConvert::set_from_array(materials, p_materials);
}
String GLTFState::get_scene_name() {
@@ -205,92 +227,108 @@ void GLTFState::set_scene_name(String p_scene_name) {
scene_name = p_scene_name;
}
-Array GLTFState::get_root_nodes() {
- return GLTFDocument::to_array(root_nodes);
+PackedInt32Array GLTFState::get_root_nodes() {
+ return root_nodes;
+}
+
+void GLTFState::set_root_nodes(PackedInt32Array p_root_nodes) {
+ root_nodes = p_root_nodes;
+}
+
+TypedArray<GLTFTexture> GLTFState::get_textures() {
+ return GLTFTemplateConvert::to_array(textures);
}
-void GLTFState::set_root_nodes(Array p_root_nodes) {
- GLTFDocument::set_from_array(root_nodes, p_root_nodes);
+void GLTFState::set_textures(TypedArray<GLTFTexture> p_textures) {
+ GLTFTemplateConvert::set_from_array(textures, p_textures);
}
-Array GLTFState::get_textures() {
- return GLTFDocument::to_array(textures);
+TypedArray<GLTFTextureSampler> GLTFState::get_texture_samplers() {
+ return GLTFTemplateConvert::to_array(texture_samplers);
}
-void GLTFState::set_textures(Array p_textures) {
- GLTFDocument::set_from_array(textures, p_textures);
+void GLTFState::set_texture_samplers(TypedArray<GLTFTextureSampler> p_texture_samplers) {
+ GLTFTemplateConvert::set_from_array(texture_samplers, p_texture_samplers);
}
-Array GLTFState::get_images() {
- return GLTFDocument::to_array(images);
+TypedArray<Texture2D> GLTFState::get_images() {
+ return GLTFTemplateConvert::to_array(images);
}
-void GLTFState::set_images(Array p_images) {
- GLTFDocument::set_from_array(images, p_images);
+void GLTFState::set_images(TypedArray<Texture2D> p_images) {
+ GLTFTemplateConvert::set_from_array(images, p_images);
}
-Array GLTFState::get_skins() {
- return GLTFDocument::to_array(skins);
+TypedArray<GLTFSkin> GLTFState::get_skins() {
+ return GLTFTemplateConvert::to_array(skins);
}
-void GLTFState::set_skins(Array p_skins) {
- GLTFDocument::set_from_array(skins, p_skins);
+void GLTFState::set_skins(TypedArray<GLTFSkin> p_skins) {
+ GLTFTemplateConvert::set_from_array(skins, p_skins);
}
-Array GLTFState::get_cameras() {
- return GLTFDocument::to_array(cameras);
+TypedArray<GLTFCamera> GLTFState::get_cameras() {
+ return GLTFTemplateConvert::to_array(cameras);
}
-void GLTFState::set_cameras(Array p_cameras) {
- GLTFDocument::set_from_array(cameras, p_cameras);
+void GLTFState::set_cameras(TypedArray<GLTFCamera> p_cameras) {
+ GLTFTemplateConvert::set_from_array(cameras, p_cameras);
}
-Array GLTFState::get_lights() {
- return GLTFDocument::to_array(lights);
+TypedArray<GLTFLight> GLTFState::get_lights() {
+ return GLTFTemplateConvert::to_array(lights);
}
-void GLTFState::set_lights(Array p_lights) {
- GLTFDocument::set_from_array(lights, p_lights);
+void GLTFState::set_lights(TypedArray<GLTFLight> p_lights) {
+ GLTFTemplateConvert::set_from_array(lights, p_lights);
}
-Array GLTFState::get_unique_names() {
- return GLTFDocument::to_array(unique_names);
+TypedArray<String> GLTFState::get_unique_names() {
+ return GLTFTemplateConvert::to_array(unique_names);
}
-void GLTFState::set_unique_names(Array p_unique_names) {
- GLTFDocument::set_from_array(unique_names, p_unique_names);
+void GLTFState::set_unique_names(TypedArray<String> p_unique_names) {
+ GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
}
-Array GLTFState::get_unique_animation_names() {
- return GLTFDocument::to_array(unique_animation_names);
+TypedArray<String> GLTFState::get_unique_animation_names() {
+ return GLTFTemplateConvert::to_array(unique_animation_names);
}
-void GLTFState::set_unique_animation_names(Array p_unique_animation_names) {
- GLTFDocument::set_from_array(unique_animation_names, p_unique_animation_names);
+void GLTFState::set_unique_animation_names(TypedArray<String> p_unique_animation_names) {
+ GLTFTemplateConvert::set_from_array(unique_animation_names, p_unique_animation_names);
}
-Array GLTFState::get_skeletons() {
- return GLTFDocument::to_array(skeletons);
+TypedArray<GLTFSkeleton> GLTFState::get_skeletons() {
+ return GLTFTemplateConvert::to_array(skeletons);
}
-void GLTFState::set_skeletons(Array p_skeletons) {
- GLTFDocument::set_from_array(skeletons, p_skeletons);
+void GLTFState::set_skeletons(TypedArray<GLTFSkeleton> p_skeletons) {
+ GLTFTemplateConvert::set_from_array(skeletons, p_skeletons);
}
Dictionary GLTFState::get_skeleton_to_node() {
- return GLTFDocument::to_dict(skeleton_to_node);
+ return GLTFTemplateConvert::to_dict(skeleton_to_node);
}
void GLTFState::set_skeleton_to_node(Dictionary p_skeleton_to_node) {
- GLTFDocument::set_from_dict(skeleton_to_node, p_skeleton_to_node);
+ GLTFTemplateConvert::set_from_dict(skeleton_to_node, p_skeleton_to_node);
}
-Array GLTFState::get_animations() {
- return GLTFDocument::to_array(animations);
+bool GLTFState::get_create_animations() {
+ return create_animations;
}
-void GLTFState::set_animations(Array p_animations) {
- GLTFDocument::set_from_array(animations, p_animations);
+void GLTFState::set_create_animations(bool p_create_animations) {
+ create_animations = p_create_animations;
+}
+
+TypedArray<GLTFAnimation> GLTFState::get_animations() {
+ return GLTFTemplateConvert::to_array(animations);
+}
+
+void GLTFState::set_animations(TypedArray<GLTFAnimation> p_animations) {
+ GLTFTemplateConvert::set_from_array(animations, p_animations);
}
Node *GLTFState::get_scene_node(GLTFNodeIndex idx) {
@@ -324,3 +362,11 @@ String GLTFState::get_base_path() {
void GLTFState::set_base_path(String p_base_path) {
base_path = p_base_path;
}
+
+Variant GLTFState::get_additional_data(const StringName &p_extension_name) {
+ return additional_data[p_extension_name];
+}
+
+void GLTFState::set_additional_data(const StringName &p_extension_name, Variant p_additional_data) {
+ additional_data[p_extension_name] = p_additional_data;
+}