summaryrefslogtreecommitdiffstats
path: root/modules/gltf
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-08-03 18:33:49 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-08-03 18:33:49 +0200
commit1d42504b309832627d32fd632f14dbb74fce66ad (patch)
tree454032354687e5f005f03a0fd4e8b2b873b22bf7 /modules/gltf
parent2e59878201cc96f6299e5f6816ffd65013cac6f8 (diff)
parente8906b5b80312dd03599813c1c99fc834d747699 (diff)
downloadredot-engine-1d42504b309832627d32fd632f14dbb74fce66ad.tar.gz
Merge pull request #79623 from aaronfranke/gltf-export-preserialize
Add `export_preserialize` to the GLTF export process
Diffstat (limited to 'modules/gltf')
-rw-r--r--modules/gltf/doc_classes/GLTFDocumentExtension.xml12
-rw-r--r--modules/gltf/extensions/gltf_document_extension.cpp8
-rw-r--r--modules/gltf/extensions/gltf_document_extension.h2
-rw-r--r--modules/gltf/gltf_document.cpp6
4 files changed, 26 insertions, 2 deletions
diff --git a/modules/gltf/doc_classes/GLTFDocumentExtension.xml b/modules/gltf/doc_classes/GLTFDocumentExtension.xml
index 95e6763579..bae980fb56 100644
--- a/modules/gltf/doc_classes/GLTFDocumentExtension.xml
+++ b/modules/gltf/doc_classes/GLTFDocumentExtension.xml
@@ -17,7 +17,7 @@
<param index="1" name="gltf_node" type="GLTFNode" />
<param index="2" name="scene_node" type="Node" />
<description>
- Part of the export process. This method is run after [method _export_preflight] and before [method _export_node].
+ Part of the export process. This method is run after [method _export_preflight] and before [method _export_preserialize].
Runs when converting the data from a Godot scene node. This method can be used to process the Godot scene node data into a format that can be used by [method _export_node].
</description>
</method>
@@ -28,7 +28,7 @@
<param index="2" name="json" type="Dictionary" />
<param index="3" name="node" type="Node" />
<description>
- Part of the export process. This method is run after [method _convert_scene_node] and before [method _export_post].
+ Part of the export process. This method is run after [method _export_preserialize] and before [method _export_post].
This method can be used to modify the final JSON of each node.
</description>
</method>
@@ -49,6 +49,14 @@
The return value is used to determine if this [GLTFDocumentExtension] instance should be used for exporting a given GLTF file. If [constant OK], the export will use this [GLTFDocumentExtension] instance. If not overridden, [constant OK] is returned.
</description>
</method>
+ <method name="_export_preserialize" qualifiers="virtual">
+ <return type="int" enum="Error" />
+ <param index="0" name="state" type="GLTFState" />
+ <description>
+ Part of the export process. This method is run after [method _convert_scene_node] and before [method _export_node].
+ This method can be used to alter the state before performing serialization. It runs every time when generating a buffer with [method GLTFDocument.generate_buffer] or writing to the file system with [method GLTFDocument.write_to_filesystem].
+ </description>
+ </method>
<method name="_generate_scene_node" qualifiers="virtual">
<return type="Node3D" />
<param index="0" name="state" type="GLTFState" />
diff --git a/modules/gltf/extensions/gltf_document_extension.cpp b/modules/gltf/extensions/gltf_document_extension.cpp
index ce1a0176f5..11718ba78a 100644
--- a/modules/gltf/extensions/gltf_document_extension.cpp
+++ b/modules/gltf/extensions/gltf_document_extension.cpp
@@ -45,6 +45,7 @@ void GLTFDocumentExtension::_bind_methods() {
// Export process.
GDVIRTUAL_BIND(_export_preflight, "state", "root");
GDVIRTUAL_BIND(_convert_scene_node, "state", "gltf_node", "scene_node");
+ GDVIRTUAL_BIND(_export_preserialize, "state");
GDVIRTUAL_BIND(_export_node, "state", "gltf_node", "json", "node");
GDVIRTUAL_BIND(_export_post, "state");
}
@@ -141,6 +142,13 @@ void GLTFDocumentExtension::convert_scene_node(Ref<GLTFState> p_state, Ref<GLTFN
GDVIRTUAL_CALL(_convert_scene_node, p_state, p_gltf_node, p_scene_node);
}
+Error GLTFDocumentExtension::export_preserialize(Ref<GLTFState> p_state) {
+ ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
+ Error err = OK;
+ GDVIRTUAL_CALL(_export_preserialize, p_state, err);
+ return err;
+}
+
Error GLTFDocumentExtension::export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_dict, Node *p_node) {
ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
ERR_FAIL_NULL_V(p_gltf_node, ERR_INVALID_PARAMETER);
diff --git a/modules/gltf/extensions/gltf_document_extension.h b/modules/gltf/extensions/gltf_document_extension.h
index 14735704b7..0a631bb6c5 100644
--- a/modules/gltf/extensions/gltf_document_extension.h
+++ b/modules/gltf/extensions/gltf_document_extension.h
@@ -54,6 +54,7 @@ public:
// Export process.
virtual Error export_preflight(Ref<GLTFState> p_state, Node *p_root);
virtual void convert_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_node);
+ virtual Error export_preserialize(Ref<GLTFState> p_state);
virtual Error export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node);
virtual Error export_post(Ref<GLTFState> p_state);
@@ -71,6 +72,7 @@ public:
// Export process.
GDVIRTUAL2R(Error, _export_preflight, Ref<GLTFState>, Node *);
GDVIRTUAL3(_convert_scene_node, Ref<GLTFState>, Ref<GLTFNode>, Node *);
+ GDVIRTUAL1R(Error, _export_preserialize, Ref<GLTFState>);
GDVIRTUAL4R(Error, _export_node, Ref<GLTFState>, Ref<GLTFNode>, Dictionary, Node *);
GDVIRTUAL1R(Error, _export_post, Ref<GLTFState>);
};
diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp
index 493eb00991..d23b22049b 100644
--- a/modules/gltf/gltf_document.cpp
+++ b/modules/gltf/gltf_document.cpp
@@ -115,6 +115,12 @@ Error GLTFDocument::_serialize(Ref<GLTFState> p_state, const String &p_path) {
p_state->buffers.push_back(Vector<uint8_t>());
}
+ for (Ref<GLTFDocumentExtension> ext : document_extensions) {
+ ERR_CONTINUE(ext.is_null());
+ Error err = ext->export_preserialize(p_state);
+ ERR_CONTINUE(err != OK);
+ }
+
/* STEP CONVERT MESH INSTANCES */
_convert_mesh_instances(p_state);