three.js
three.js copied to clipboard
Add GLTFExporter plugin hooks for beforeWriteNode, beforeWriteMesh …
…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
and beforeWriteTexture
.
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 a newTexture
property which allows extensions to change what texture should be exported (this would make https://github.com/mrdoob/three.js/pull/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