aboutsummaryrefslogtreecommitdiff
path: root/client/system/gltf_apply_visibility.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/system/gltf_apply_visibility.gd')
-rw-r--r--client/system/gltf_apply_visibility.gd35
1 files changed, 35 insertions, 0 deletions
diff --git a/client/system/gltf_apply_visibility.gd b/client/system/gltf_apply_visibility.gd
new file mode 100644
index 00000000..5635bf6e
--- /dev/null
+++ b/client/system/gltf_apply_visibility.gd
@@ -0,0 +1,35 @@
+# Hurry Curry! - a game about cooking
+# Copyright (C) 2025 Hurry Curry! contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, version 3 of the License only.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+extends GLTFDocumentExtension
+class_name GLTFApplyNodeVisibility
+
+# Since Godot 4.5 the KHR_node_visibility extension is
+# required which is not yet supported in Blender, so we
+# pre-apply them by removing meshes from hidden nodes.
+func _export_post(state: GLTFState) -> Error:
+ state.json["extensionsRequired"].erase("KHR_node_visibility")
+ var nodes = state.json["nodes"]
+ for node in nodes:
+ var visible = node.get("extensions", {}).get("KHR_node_visibility", {}).get("visible", true)
+ if not visible: hide_node(nodes, node)
+ return Error.OK
+
+func hide_node(nodes: Array, node: Dictionary):
+ if node.has("mesh"): print("clear mesh")
+ node.erase("mesh")
+ for child_index in node.get("children", []):
+ print("clear child child_index")
+ hide_node(nodes, nodes[child_index])