Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gltf/structures/gltf_object_model_property.cpp
10278 views
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
void GLTFObjectModelProperty::_bind_methods() {
36
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_UNKNOWN);
37
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_BOOL);
38
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT);
39
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT_ARRAY);
40
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT2);
41
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT3);
42
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT4);
43
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT2X2);
44
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT3X3);
45
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT4X4);
46
BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_INT);
47
48
ClassDB::bind_method(D_METHOD("append_node_path", "node_path"), &GLTFObjectModelProperty::append_node_path);
49
ClassDB::bind_method(D_METHOD("append_path_to_property", "node_path", "prop_name"), &GLTFObjectModelProperty::append_path_to_property);
50
51
ClassDB::bind_method(D_METHOD("get_accessor_type"), &GLTFObjectModelProperty::get_accessor_type);
52
ClassDB::bind_method(D_METHOD("get_gltf_to_godot_expression"), &GLTFObjectModelProperty::get_gltf_to_godot_expression);
53
ClassDB::bind_method(D_METHOD("set_gltf_to_godot_expression", "gltf_to_godot_expr"), &GLTFObjectModelProperty::set_gltf_to_godot_expression);
54
ClassDB::bind_method(D_METHOD("get_godot_to_gltf_expression"), &GLTFObjectModelProperty::get_godot_to_gltf_expression);
55
ClassDB::bind_method(D_METHOD("set_godot_to_gltf_expression", "godot_to_gltf_expr"), &GLTFObjectModelProperty::set_godot_to_gltf_expression);
56
ClassDB::bind_method(D_METHOD("get_node_paths"), &GLTFObjectModelProperty::get_node_paths);
57
ClassDB::bind_method(D_METHOD("has_node_paths"), &GLTFObjectModelProperty::has_node_paths);
58
ClassDB::bind_method(D_METHOD("set_node_paths", "node_paths"), &GLTFObjectModelProperty::set_node_paths);
59
ClassDB::bind_method(D_METHOD("get_object_model_type"), &GLTFObjectModelProperty::get_object_model_type);
60
ClassDB::bind_method(D_METHOD("set_object_model_type", "type"), &GLTFObjectModelProperty::set_object_model_type);
61
ClassDB::bind_method(D_METHOD("get_json_pointers"), &GLTFObjectModelProperty::get_json_pointers_bind);
62
ClassDB::bind_method(D_METHOD("has_json_pointers"), &GLTFObjectModelProperty::has_json_pointers);
63
ClassDB::bind_method(D_METHOD("set_json_pointers", "json_pointers"), &GLTFObjectModelProperty::set_json_pointers_bind);
64
ClassDB::bind_method(D_METHOD("get_variant_type"), &GLTFObjectModelProperty::get_variant_type);
65
ClassDB::bind_method(D_METHOD("set_variant_type", "variant_type"), &GLTFObjectModelProperty::set_variant_type);
66
ClassDB::bind_method(D_METHOD("set_types", "variant_type", "obj_model_type"), &GLTFObjectModelProperty::set_types);
67
68
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>
69
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>
70
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "node_paths", PROPERTY_HINT_TYPE_STRING, "NodePath"), "set_node_paths", "get_node_paths"); // TypedArray<NodePath>
71
ADD_PROPERTY(PropertyInfo(Variant::INT, "object_model_type"), "set_object_model_type", "get_object_model_type"); // GLTFObjectModelType
72
ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "json_pointers"), "set_json_pointers", "get_json_pointers"); // TypedArray<PackedStringArray>
73
ADD_PROPERTY(PropertyInfo(Variant::INT, "variant_type"), "set_variant_type", "get_variant_type"); // Variant::Type
74
}
75
76
void GLTFObjectModelProperty::append_node_path(const NodePath &p_node_path) {
77
node_paths.push_back(p_node_path);
78
}
79
80
void GLTFObjectModelProperty::append_path_to_property(const NodePath &p_node_path, const StringName &p_prop_name) {
81
Vector<StringName> node_names = p_node_path.get_names();
82
Vector<StringName> subpath = p_node_path.get_subnames();
83
subpath.append(p_prop_name);
84
node_paths.push_back(NodePath(node_names, subpath, false));
85
}
86
87
GLTFAccessor::GLTFAccessorType GLTFObjectModelProperty::get_accessor_type() const {
88
switch (object_model_type) {
89
case GLTF_OBJECT_MODEL_TYPE_FLOAT2:
90
return GLTFAccessor::TYPE_VEC2;
91
case GLTF_OBJECT_MODEL_TYPE_FLOAT3:
92
return GLTFAccessor::TYPE_VEC3;
93
case GLTF_OBJECT_MODEL_TYPE_FLOAT4:
94
return GLTFAccessor::TYPE_VEC4;
95
case GLTF_OBJECT_MODEL_TYPE_FLOAT2X2:
96
return GLTFAccessor::TYPE_MAT2;
97
case GLTF_OBJECT_MODEL_TYPE_FLOAT3X3:
98
return GLTFAccessor::TYPE_MAT3;
99
case GLTF_OBJECT_MODEL_TYPE_FLOAT4X4:
100
return GLTFAccessor::TYPE_MAT4;
101
default:
102
return GLTFAccessor::TYPE_SCALAR;
103
}
104
}
105
106
Ref<Expression> GLTFObjectModelProperty::get_gltf_to_godot_expression() const {
107
return gltf_to_godot_expr;
108
}
109
110
void GLTFObjectModelProperty::set_gltf_to_godot_expression(Ref<Expression> p_gltf_to_godot_expr) {
111
gltf_to_godot_expr = p_gltf_to_godot_expr;
112
}
113
114
Ref<Expression> GLTFObjectModelProperty::get_godot_to_gltf_expression() const {
115
return godot_to_gltf_expr;
116
}
117
118
void GLTFObjectModelProperty::set_godot_to_gltf_expression(Ref<Expression> p_godot_to_gltf_expr) {
119
godot_to_gltf_expr = p_godot_to_gltf_expr;
120
}
121
122
TypedArray<NodePath> GLTFObjectModelProperty::get_node_paths() const {
123
return node_paths;
124
}
125
126
bool GLTFObjectModelProperty::has_node_paths() const {
127
return !node_paths.is_empty();
128
}
129
130
void GLTFObjectModelProperty::set_node_paths(TypedArray<NodePath> p_node_paths) {
131
node_paths = p_node_paths;
132
}
133
134
GLTFObjectModelProperty::GLTFObjectModelType GLTFObjectModelProperty::get_object_model_type() const {
135
return object_model_type;
136
}
137
138
void GLTFObjectModelProperty::set_object_model_type(GLTFObjectModelType p_type) {
139
object_model_type = p_type;
140
}
141
142
Vector<PackedStringArray> GLTFObjectModelProperty::get_json_pointers() const {
143
return json_pointers;
144
}
145
146
bool GLTFObjectModelProperty::has_json_pointers() const {
147
return !json_pointers.is_empty();
148
}
149
150
void GLTFObjectModelProperty::set_json_pointers(const Vector<PackedStringArray> &p_json_pointers) {
151
json_pointers = p_json_pointers;
152
}
153
154
TypedArray<PackedStringArray> GLTFObjectModelProperty::get_json_pointers_bind() const {
155
return GLTFTemplateConvert::to_array(json_pointers);
156
}
157
158
void GLTFObjectModelProperty::set_json_pointers_bind(const TypedArray<PackedStringArray> &p_json_pointers) {
159
GLTFTemplateConvert::set_from_array(json_pointers, p_json_pointers);
160
}
161
162
Variant::Type GLTFObjectModelProperty::get_variant_type() const {
163
return variant_type;
164
}
165
166
void GLTFObjectModelProperty::set_variant_type(Variant::Type p_variant_type) {
167
variant_type = p_variant_type;
168
}
169
170
void GLTFObjectModelProperty::set_types(Variant::Type p_variant_type, GLTFObjectModelType p_obj_model_type) {
171
variant_type = p_variant_type;
172
object_model_type = p_obj_model_type;
173
}
174
175