Skip to content

Commit 596a192

Browse files
committed
GLTF: Support animating node visibility
1 parent c01c7b8 commit 596a192

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

modules/gltf/gltf_document.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6890,6 +6890,14 @@ Ref<GLTFObjectModelProperty> GLTFDocument::import_object_model_property(Ref<GLTF
68906890
}
68916891
// Else, Godot's MeshInstance3D does not expose the blend shape weights as one property.
68926892
// But that's fine, we handle this case in _parse_animation_pointer instead.
6893+
} else if (node_prop == "extensions") {
6894+
ERR_FAIL_COND_V(split.size() < 5, ret);
6895+
const String &ext_name = split[3];
6896+
const String &ext_prop = split[4];
6897+
if (ext_name == "KHR_node_visibility" && ext_prop == "visible") {
6898+
ret->append_path_to_property(node_path, "visible");
6899+
ret->set_types(Variant::BOOL, GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_BOOL);
6900+
}
68936901
}
68946902
} else if (split[0] == "cameras") {
68956903
const String &camera_prop = split[2];
@@ -7196,7 +7204,7 @@ Ref<GLTFObjectModelProperty> GLTFDocument::export_object_model_property(Ref<GLTF
71967204
split_json_pointer.append("weights");
71977205
split_json_pointer.append(weight_index_string);
71987206
}
7199-
// Transform properties. Check for all 3D nodes if we haven't resolved the JSON pointer yet.
7207+
// Transform and visibility properties. Check for all 3D nodes if we haven't resolved the JSON pointer yet.
72007208
// Note: Do not put this in an `else`, because otherwise this will not be reached.
72017209
if (split_json_pointer.is_empty() && Object::cast_to<Node3D>(target_object)) {
72027210
split_json_pointer.append("nodes");
@@ -7218,6 +7226,11 @@ Ref<GLTFObjectModelProperty> GLTFDocument::export_object_model_property(Ref<GLTF
72187226
} else if (target_prop == "global_transform") {
72197227
split_json_pointer.append("globalMatrix");
72207228
ret->set_types(Variant::TRANSFORM3D, GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_FLOAT4X4);
7229+
} else if (target_prop == "visible") {
7230+
split_json_pointer.append("extensions");
7231+
split_json_pointer.append("KHR_node_visibility");
7232+
split_json_pointer.append("visible");
7233+
ret->set_types(Variant::BOOL, GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_BOOL);
72217234
} else {
72227235
split_json_pointer.clear();
72237236
}

0 commit comments

Comments
 (0)