Add GLTFExporter plugin hooks for beforeWriteNode, beforeWriteMesh … #28658
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…and beforeWriteTexture
Description
Currently it's not easily possible to modify or omit parts of the exported scene using GLTFExporter.
The only way to do that is to traverse the whole scene before export and then reverting changes after.
Besides being wasteful for large and complex scenes it's also error prone since the export process can take a few frames or seconds to complete during which the exported objects could again be modified by unrelated code (e.g. an object might have been moved or added to the hierarchy that was not there before export. One example of this are debug gizmos that might be added to the renderstack every frame).
This change adds callback hooks for
beforeWriteNode
,beforeWriteMesh
andbeforeWriteTexture
.Each callback receives the object that should be exported as well as an options argument which contains a bool to allow extensions to skip objects ( by setting
{ keep: false }
).Additionally
beforeWriteTexture
contains anewTexture
property which allows extensions to change what texture should be exported (this would make #28653 obsolete)Generally a better approach for the whole exporter would be to first parse the whole scene and collect the data that will get exported - then adding once callback that allows extensions to filter parts of the hierarchy - and then actually writing any data. That would be similar to how the GLTFExporter in Blender works (or the USDZExporter in Needle Engine)
This contribution is funded by Needle