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

Make GLTF Scene Importer populate node metadata with GLTF extras #39024

Closed
wants to merge 1 commit into from

Conversation

fghibellini
Copy link

Introduction

This PR adds the boolean import option nodes/meta to the Scene Importer.

When enabled the imported nodes' metadata is populated from annotation data of the specific file format (currently limited to GLTF "extras").

This PR currently only generates metadata for Meshes, Cameras and
Spatials. Other nodes can be added in later PRs.

The change was discussed with @fire on the engine room of the Godot discord.

Motivation

I would like to be able to write custom import scripts that modify the imported scene based on metadata on objects. e.g. generating physics objects for meshes that are somehow tagged in Blender.

The metadata can also be read at runtime, which makes it very easy to specify values in the 3d model (at modeling time i.e. in Blender) that are then used by the game e.g. physical properties of objects.

@fire expressed the desire to include GDscripts in GLTF files.

Example

Screen Shot 2020-05-24 at 20 51 08

Notice the custom property "is_floor" on the box mesh specified in Blender.

Screen Shot 2020-05-24 at 20 52 18

We export the model with the GLTF exporter while making sure to have the "Custom properties" option enabled.

Screen Shot 2020-05-24 at 20 53 36

We can see that the .gltf file encodes the custom property in the "extras" field.

Screen Shot 2020-05-24 at 21 00 04

Importing the .gltf file into Godot results in a MeshInstance with the metadata set to the values specified in Blender.

(the metadata panel is displayed by this plugin)

Breaking behavior

The option is disabled by default so it should not introduce unexpected behavior to anyone.

Disclaimer

I have no prior experience with 3D model formats or game development.

@fghibellini fghibellini force-pushed the scene-importer-meta branch from 0a7d4fb to aaeebc1 Compare May 25, 2020 00:49
@Calinou Calinou added this to the 3.2 milestone May 25, 2020
@akien-mga akien-mga requested a review from reduz May 25, 2020 09:37
@@ -1161,6 +1162,7 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in
bool animations_out = p_preset == PRESET_SEPARATE_ANIMATIONS || p_preset == PRESET_SEPARATE_MESHES_AND_ANIMATIONS || p_preset == PRESET_SEPARATE_MATERIALS_AND_ANIMATIONS || p_preset == PRESET_SEPARATE_MESHES_MATERIALS_AND_ANIMATIONS;

r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "nodes/root_scale", PROPERTY_HINT_RANGE, "0.001,1000,0.001"), 1.0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "nodes/meta"), false));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added metadata doesn't seem particularly compat breaking, so I guess it could be on by default?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with many 3D modeling tools but I can imagine some tools abusing custom properties to store a lot of data (maybe editor plugins?) - so I'm just concerned the user might unknowingly end up with a lot of data in his scene that they never use (and currently not even immediately see as the metadata can be displayed only through a plugin or needs to be inspected by code).

Also if someone already used metadata assuming (performance-wise) there's going to be only their keys/values it might significantly slow down their code if they use some 3D tool that fills the object metadata with a lot of stuff.

But as already stated - I don't really know how things usually work in gamedev/3Dmodeling.

@akien-mga
Copy link
Member

Changes seem OK, but it needs a check by @reduz to confirm that it's wanted.

A PR should be made for the master branch too, as it doesn't make sense to merge a new feature in 3.2 to then lose it in 4.0.

This PR currently only generates metadata for Meshes, Cameras and
Spatials. Other nodes can be added later.
This feature can be enabled by a Scene Importer import option called "Meta".
@fghibellini fghibellini force-pushed the scene-importer-meta branch from aaeebc1 to a703e44 Compare May 25, 2020 09:53
@fghibellini
Copy link
Author

@akien-mga
Thanks for the review!

Unfortunately master does not work on my machine, so I guess someone else will have to port the changes.

@fire
Copy link
Member

fire commented May 25, 2020

If you want, I can spend significant time with helping you get Godot Engine 4.0 to run on your computer.

@fghibellini
Copy link
Author

fghibellini commented May 25, 2020

@fire
I really appreciate the offer. But at the moment I'm really just trying to develop a small game for the first time as free-time (i.e. relax) project. Maybe later on.

NOTE
Given that it was brought up, this is what the project manager window looks like on master right after start (macOS Mojave Version 10.14.6 (18G4032))
Screen Shot 2020-05-25 at 20 22 41

@fire
Copy link
Member

fire commented Jul 15, 2020

I really want this, so I'll see if I can find time the next available period to work on it for master.

@fire
Copy link
Member

fire commented Oct 17, 2020

This pr is outdated by #40474.

@akien-mga
Copy link
Member

Superseded by #40474. Thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants