Skip to content

Commit 68410ac

Browse files
committed
Merge pull request #111613 from aaronfranke/gltf-obj-model-components
GLTF: Determine the component type when encoding object model properties
2 parents 94b3e10 + e9bfc5a commit 68410ac

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

modules/gltf/gltf_document.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3768,9 +3768,10 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> p_state) {
37683768
Dictionary sampler;
37693769
sampler["input"] = GLTFAccessor::encode_new_accessor_from_float64s(p_state, pointer_track.times);
37703770
sampler["interpolation"] = interpolation_to_string(pointer_track.interpolation);
3771+
GLTFAccessor::GLTFComponentType component_type = obj_model_prop->get_component_type(pointer_track.values);
37713772
// TODO: This can be made faster after this pull request is merged: https://github.com/godotengine/godot/pull/109003
37723773
Array values_arr = GLTFTemplateConvert::to_array(pointer_track.values);
3773-
sampler["output"] = GLTFAccessor::encode_new_accessor_from_variants(p_state, values_arr, obj_model_prop->get_variant_type(), obj_model_prop->get_accessor_type());
3774+
sampler["output"] = GLTFAccessor::encode_new_accessor_from_variants(p_state, values_arr, obj_model_prop->get_variant_type(), obj_model_prop->get_accessor_type(), component_type);
37743775
samplers.push_back(sampler);
37753776
}
37763777
}

modules/gltf/structures/gltf_object_model_property.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ GLTFAccessor::GLTFAccessorType GLTFObjectModelProperty::get_accessor_type() cons
103103
}
104104
}
105105

106+
GLTFAccessor::GLTFComponentType GLTFObjectModelProperty::get_component_type(const Vector<Variant> &p_values) const {
107+
switch (object_model_type) {
108+
case GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_BOOL: {
109+
return GLTFAccessor::COMPONENT_TYPE_UNSIGNED_BYTE;
110+
} break;
111+
case GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_INT: {
112+
PackedInt64Array int_values;
113+
for (int i = 0; i < p_values.size(); i++) {
114+
int_values.append(p_values[i]);
115+
}
116+
return GLTFAccessor::get_minimal_integer_component_type_from_ints(int_values);
117+
} break;
118+
default: {
119+
// The base glTF specification only supports 32-bit float accessors for floating point data.
120+
return GLTFAccessor::COMPONENT_TYPE_SINGLE_FLOAT;
121+
} break;
122+
}
123+
}
124+
106125
Ref<Expression> GLTFObjectModelProperty::get_gltf_to_godot_expression() const {
107126
return gltf_to_godot_expr;
108127
}

modules/gltf/structures/gltf_object_model_property.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class GLTFObjectModelProperty : public RefCounted {
7171
void append_path_to_property(const NodePath &p_node_path, const StringName &p_prop_name);
7272

7373
GLTFAccessor::GLTFAccessorType get_accessor_type() const;
74+
GLTFAccessor::GLTFComponentType get_component_type(const Vector<Variant> &p_values) const;
7475

7576
Ref<Expression> get_gltf_to_godot_expression() const;
7677
void set_gltf_to_godot_expression(const Ref<Expression> &p_gltf_to_godot_expr);

0 commit comments

Comments
 (0)