Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GLTFExporter plugin hooks for beforeWriteNode, beforeWriteMesh … #28658

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

marwie
Copy link
Contributor

@marwie marwie commented Jun 14, 2024

…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 #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

@@ -1627,6 +1639,20 @@
*/
processMesh( mesh ) {

const beforeWriteArgs = { keep: true }

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (98% of all statements in
the enclosing function
have an explicit semicolon).
@@ -2226,6 +2252,20 @@
*/
processNode( object ) {

const beforeWriteArgs = { keep: true }

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (96% of all statements in
the enclosing function
have an explicit semicolon).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant