| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  gltf_skin.cpp                                                        */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							|  |  |  | /*                      https://godotengine.org                          */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2022-01-03 21:27:34 +01:00
										 |  |  | /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* 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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-24 14:20:50 -05:00
										 |  |  | #include "../gltf_template_convert.h"
 | 
					
						
							| 
									
										
										
										
											2022-08-08 00:52:20 +02:00
										 |  |  | #include "core/variant/typed_array.h"
 | 
					
						
							| 
									
										
										
										
											2022-07-24 12:06:38 -05:00
										 |  |  | #include "scene/resources/skin.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | 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>
 | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "inverse_binds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_inverse_binds", "get_inverse_binds"); // Vector<Transform3D>
 | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | 	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
 | 
					
						
							| 
									
										
										
										
											2022-05-13 15:04:37 +02:00
										 |  |  | 	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,
 | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "godot_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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 00:52:20 +02:00
										 |  |  | TypedArray<Transform3D> GLTFSkin::get_inverse_binds() { | 
					
						
							| 
									
										
										
										
											2022-07-24 12:06:38 -05:00
										 |  |  | 	return GLTFTemplateConvert::to_array(inverse_binds); | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 00:52:20 +02:00
										 |  |  | void GLTFSkin::set_inverse_binds(TypedArray<Transform3D> p_inverse_binds) { | 
					
						
							| 
									
										
										
										
											2022-07-24 12:06:38 -05:00
										 |  |  | 	GLTFTemplateConvert::set_from_array(inverse_binds, p_inverse_binds); | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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() { | 
					
						
							| 
									
										
										
										
											2022-07-24 12:06:38 -05:00
										 |  |  | 	return GLTFTemplateConvert::to_dict(joint_i_to_bone_i); | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GLTFSkin::set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i) { | 
					
						
							| 
									
										
										
										
											2022-07-24 12:06:38 -05:00
										 |  |  | 	GLTFTemplateConvert::set_from_dict(joint_i_to_bone_i, p_joint_i_to_bone_i); | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Dictionary GLTFSkin::get_joint_i_to_name() { | 
					
						
							|  |  |  | 	Dictionary ret; | 
					
						
							| 
									
										
										
										
											2022-05-13 15:04:37 +02:00
										 |  |  | 	HashMap<int, StringName>::Iterator elem = joint_i_to_name.begin(); | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | 	while (elem) { | 
					
						
							| 
									
										
										
										
											2022-05-13 15:04:37 +02:00
										 |  |  | 		ret[elem->key] = String(elem->value); | 
					
						
							|  |  |  | 		++elem; | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GLTFSkin::set_joint_i_to_name(Dictionary p_joint_i_to_name) { | 
					
						
							| 
									
										
										
										
											2022-05-13 15:04:37 +02:00
										 |  |  | 	joint_i_to_name = HashMap<int, StringName>(); | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | 	Array keys = p_joint_i_to_name.keys(); | 
					
						
							|  |  |  | 	for (int i = 0; i < keys.size(); i++) { | 
					
						
							| 
									
										
										
										
											2021-02-13 01:24:43 +05:30
										 |  |  | 		joint_i_to_name[keys[i]] = p_joint_i_to_name[keys[i]]; | 
					
						
							| 
									
										
										
										
											2020-12-21 07:39:32 -08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Ref<Skin> GLTFSkin::get_godot_skin() { | 
					
						
							|  |  |  | 	return godot_skin; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GLTFSkin::set_godot_skin(Ref<Skin> p_godot_skin) { | 
					
						
							|  |  |  | 	godot_skin = p_godot_skin; | 
					
						
							|  |  |  | } |