0.2.0-dev Download ZIP
194 lines ·9.7 KB Raw
| 1 | /**************************************************************************/ |
| 2 | /* gltf_object_model_property.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "gltf_object_model_property.h" |
| 32 | |
| 33 | #include "../gltf_template_convert.h" |
| 34 | |
| 35 | #include "core/object/class_db.h" |
| 36 | |
| 37 | void GLTFObjectModelProperty::_bind_methods() { |
| 38 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_UNKNOWN); |
| 39 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_BOOL); |
| 40 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT); |
| 41 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT_ARRAY); |
| 42 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT2); |
| 43 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT3); |
| 44 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT4); |
| 45 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT2X2); |
| 46 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT3X3); |
| 47 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT4X4); |
| 48 | BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_INT); |
| 49 | |
| 50 | ClassDB::bind_method(D_METHOD("append_node_path", "node_path"), &GLTFObjectModelProperty::append_node_path); |
| 51 | ClassDB::bind_method(D_METHOD("append_path_to_property", "node_path", "prop_name"), &GLTFObjectModelProperty::append_path_to_property); |
| 52 | |
| 53 | ClassDB::bind_method(D_METHOD("get_accessor_type"), &GLTFObjectModelProperty::get_accessor_type); |
| 54 | ClassDB::bind_method(D_METHOD("get_gltf_to_godot_expression"), &GLTFObjectModelProperty::get_gltf_to_godot_expression); |
| 55 | ClassDB::bind_method(D_METHOD("set_gltf_to_godot_expression", "gltf_to_godot_expr"), &GLTFObjectModelProperty::set_gltf_to_godot_expression); |
| 56 | ClassDB::bind_method(D_METHOD("get_godot_to_gltf_expression"), &GLTFObjectModelProperty::get_godot_to_gltf_expression); |
| 57 | ClassDB::bind_method(D_METHOD("set_godot_to_gltf_expression", "godot_to_gltf_expr"), &GLTFObjectModelProperty::set_godot_to_gltf_expression); |
| 58 | ClassDB::bind_method(D_METHOD("get_node_paths"), &GLTFObjectModelProperty::get_node_paths); |
| 59 | ClassDB::bind_method(D_METHOD("has_node_paths"), &GLTFObjectModelProperty::has_node_paths); |
| 60 | ClassDB::bind_method(D_METHOD("set_node_paths", "node_paths"), &GLTFObjectModelProperty::set_node_paths); |
| 61 | ClassDB::bind_method(D_METHOD("get_object_model_type"), &GLTFObjectModelProperty::get_object_model_type); |
| 62 | ClassDB::bind_method(D_METHOD("set_object_model_type", "type"), &GLTFObjectModelProperty::set_object_model_type); |
| 63 | ClassDB::bind_method(D_METHOD("get_json_pointers"), &GLTFObjectModelProperty::get_json_pointers_bind); |
| 64 | ClassDB::bind_method(D_METHOD("has_json_pointers"), &GLTFObjectModelProperty::has_json_pointers); |
| 65 | ClassDB::bind_method(D_METHOD("set_json_pointers", "json_pointers"), &GLTFObjectModelProperty::set_json_pointers_bind); |
| 66 | ClassDB::bind_method(D_METHOD("get_variant_type"), &GLTFObjectModelProperty::get_variant_type); |
| 67 | ClassDB::bind_method(D_METHOD("set_variant_type", "variant_type"), &GLTFObjectModelProperty::set_variant_type); |
| 68 | ClassDB::bind_method(D_METHOD("set_types", "variant_type", "obj_model_type"), &GLTFObjectModelProperty::set_types); |
| 69 | |
| 70 | ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gltf_to_godot_expression", PROPERTY_HINT_RESOURCE_TYPE, Expression::get_class_static()), "set_gltf_to_godot_expression", "get_gltf_to_godot_expression"); // Ref<Expression> |
| 71 | ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "godot_to_gltf_expression", PROPERTY_HINT_RESOURCE_TYPE, Expression::get_class_static()), "set_godot_to_gltf_expression", "get_godot_to_gltf_expression"); // Ref<Expression> |
| 72 | ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "node_paths", PROPERTY_HINT_TYPE_STRING, "NodePath"), "set_node_paths", "get_node_paths"); // TypedArray<NodePath> |
| 73 | ADD_PROPERTY(PropertyInfo(Variant::INT, "object_model_type"), "set_object_model_type", "get_object_model_type"); // GLTFObjectModelType |
| 74 | ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "json_pointers"), "set_json_pointers", "get_json_pointers"); // TypedArray<PackedStringArray> |
| 75 | ADD_PROPERTY(PropertyInfo(Variant::INT, "variant_type"), "set_variant_type", "get_variant_type"); // Variant::Type |
| 76 | } |
| 77 | |
| 78 | void GLTFObjectModelProperty::append_node_path(const NodePath &p_node_path) { |
| 79 | node_paths.push_back(p_node_path); |
| 80 | } |
| 81 | |
| 82 | void GLTFObjectModelProperty::append_path_to_property(const NodePath &p_node_path, const StringName &p_prop_name) { |
| 83 | Vector<StringName> node_names = p_node_path.get_names(); |
| 84 | Vector<StringName> subpath = p_node_path.get_subnames(); |
| 85 | subpath.append(p_prop_name); |
| 86 | node_paths.push_back(NodePath(node_names, subpath, false)); |
| 87 | } |
| 88 | |
| 89 | GLTFAccessor::GLTFAccessorType GLTFObjectModelProperty::get_accessor_type() const { |
| 90 | switch (object_model_type) { |
| 91 | case GLTF_OBJECT_MODEL_TYPE_FLOAT2: |
| 92 | return GLTFAccessor::TYPE_VEC2; |
| 93 | case GLTF_OBJECT_MODEL_TYPE_FLOAT3: |
| 94 | return GLTFAccessor::TYPE_VEC3; |
| 95 | case GLTF_OBJECT_MODEL_TYPE_FLOAT4: |
| 96 | return GLTFAccessor::TYPE_VEC4; |
| 97 | case GLTF_OBJECT_MODEL_TYPE_FLOAT2X2: |
| 98 | return GLTFAccessor::TYPE_MAT2; |
| 99 | case GLTF_OBJECT_MODEL_TYPE_FLOAT3X3: |
| 100 | return GLTFAccessor::TYPE_MAT3; |
| 101 | case GLTF_OBJECT_MODEL_TYPE_FLOAT4X4: |
| 102 | return GLTFAccessor::TYPE_MAT4; |
| 103 | default: |
| 104 | return GLTFAccessor::TYPE_SCALAR; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | GLTFAccessor::GLTFComponentType GLTFObjectModelProperty::get_component_type(const Vector<Variant> &p_values) const { |
| 109 | switch (object_model_type) { |
| 110 | case GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_BOOL: { |
| 111 | return GLTFAccessor::COMPONENT_TYPE_UNSIGNED_BYTE; |
| 112 | } break; |
| 113 | case GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_INT: { |
| 114 | PackedInt64Array int_values; |
| 115 | for (int i = 0; i < p_values.size(); i++) { |
| 116 | int_values.append(p_values[i]); |
| 117 | } |
| 118 | return GLTFAccessor::get_minimal_integer_component_type_from_ints(int_values); |
| 119 | } break; |
| 120 | default: { |
| 121 | // The base glTF specification only supports 32-bit float accessors for floating point data. |
| 122 | return GLTFAccessor::COMPONENT_TYPE_SINGLE_FLOAT; |
| 123 | } break; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | Ref<Expression> GLTFObjectModelProperty::get_gltf_to_godot_expression() const { |
| 128 | return gltf_to_godot_expr; |
| 129 | } |
| 130 | |
| 131 | void GLTFObjectModelProperty::set_gltf_to_godot_expression(const Ref<Expression> &p_gltf_to_godot_expr) { |
| 132 | gltf_to_godot_expr = p_gltf_to_godot_expr; |
| 133 | } |
| 134 | |
| 135 | Ref<Expression> GLTFObjectModelProperty::get_godot_to_gltf_expression() const { |
| 136 | return godot_to_gltf_expr; |
| 137 | } |
| 138 | |
| 139 | void GLTFObjectModelProperty::set_godot_to_gltf_expression(const Ref<Expression> &p_godot_to_gltf_expr) { |
| 140 | godot_to_gltf_expr = p_godot_to_gltf_expr; |
| 141 | } |
| 142 | |
| 143 | TypedArray<NodePath> GLTFObjectModelProperty::get_node_paths() const { |
| 144 | return TypedArray<NodePath>(node_paths); |
| 145 | } |
| 146 | |
| 147 | bool GLTFObjectModelProperty::has_node_paths() const { |
| 148 | return !node_paths.is_empty(); |
| 149 | } |
| 150 | |
| 151 | void GLTFObjectModelProperty::set_node_paths(const TypedArray<NodePath> &p_node_paths) { |
| 152 | node_paths = TypedArray<NodePath>(p_node_paths); |
| 153 | } |
| 154 | |
| 155 | GLTFObjectModelProperty::GLTFObjectModelType GLTFObjectModelProperty::get_object_model_type() const { |
| 156 | return object_model_type; |
| 157 | } |
| 158 | |
| 159 | void GLTFObjectModelProperty::set_object_model_type(GLTFObjectModelType p_type) { |
| 160 | object_model_type = p_type; |
| 161 | } |
| 162 | |
| 163 | Vector<PackedStringArray> GLTFObjectModelProperty::get_json_pointers() const { |
| 164 | return json_pointers; |
| 165 | } |
| 166 | |
| 167 | bool GLTFObjectModelProperty::has_json_pointers() const { |
| 168 | return !json_pointers.is_empty(); |
| 169 | } |
| 170 | |
| 171 | void GLTFObjectModelProperty::set_json_pointers(const Vector<PackedStringArray> &p_json_pointers) { |
| 172 | json_pointers = p_json_pointers; |
| 173 | } |
| 174 | |
| 175 | TypedArray<PackedStringArray> GLTFObjectModelProperty::get_json_pointers_bind() const { |
| 176 | return GLTFTemplateConvert::to_array(json_pointers); |
| 177 | } |
| 178 | |
| 179 | void GLTFObjectModelProperty::set_json_pointers_bind(const TypedArray<PackedStringArray> &p_json_pointers) { |
| 180 | GLTFTemplateConvert::set_from_array(json_pointers, p_json_pointers); |
| 181 | } |
| 182 | |
| 183 | Variant::Type GLTFObjectModelProperty::get_variant_type() const { |
| 184 | return variant_type; |
| 185 | } |
| 186 | |
| 187 | void GLTFObjectModelProperty::set_variant_type(Variant::Type p_variant_type) { |
| 188 | variant_type = p_variant_type; |
| 189 | } |
| 190 | |
| 191 | void GLTFObjectModelProperty::set_types(Variant::Type p_variant_type, GLTFObjectModelType p_obj_model_type) { |
| 192 | variant_type = p_variant_type; |
| 193 | object_model_type = p_obj_model_type; |
| 194 | } |