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 an extension system for the GLTFDocument class #3305

Closed
4 tasks done
fire opened this issue Sep 16, 2021 · 1 comment · Fixed by godotengine/godot#68981
Closed
4 tasks done

Add an extension system for the GLTFDocument class #3305

fire opened this issue Sep 16, 2021 · 1 comment · Fixed by godotengine/godot#68981

Comments

@fire
Copy link
Member

fire commented Sep 16, 2021

Describe the project you are working on

Godot Engine and a 3D VR game

Describe the problem or limitation you are having in your project

The GLTFDocument is starting to get large and it's difficult to add functionality.

See also moving GLTFDocument to core #3273

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I propose adding a Ref<GLTFExtension> system so we can start moving code from Ref<GLTFDocument> to extensions.

  • Camera extension (decided not to implement)
  • Light Extension (decided not to implement)
  • SpecGloss Extension (decided not to implement)
  • Editor Mesh Node3D and Editor Mesh extension (What generates EditorMeshInstanceImport stuff can be an extension)

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Worked with @humbletim and @lyuma.

Reference https://github.com/KhronosGroup/glTF-Blender-IO/blob/b8767c9b122cc504c6828edc3f84130469e89392/example-addons/example_gltf_extension/readme.md

GLTFDocumentExtensions

  1. One sample extension is to check the glTF requirements. For example, less than N triangles; no textures > 2048. We can implement this extension so that it returns a null node if failing. Error data is stored in the extension.

Add hook functions.

virtual Error import_preflight(Ref<GLTFState> p_state);
virtual Error import_post_parse(Ref<GLTFState> p_state);
virtual Error export_post(Ref<GLTFState> p_state);
virtual Error import_post(Ref<GLTFState> p_state, Node *p_node);
virtual Error export_preflight(Node *p_state);
virtual Error import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node);
virtual Error export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node);
// Error import_animation(gltf2_animation, Ref<Animation>, Node *,Dictionary p_export_settings) { return OK; }
// Error import_animation_channel(gltf2_animation_channel, channels, Node *, bake_bone, bake_channel, bake_range_start, import_bake_range_end, action_name,Dictionary p_export_settings) {}
// Error import_animation_channel_target(gltf2_animation_channel_target, channels, Node *, bake_bone, bake_channel,Dictionary p_export_settings) {}
// Error import_animation_sampler(gltf2_sampler, Node *, channels, bake_bone, bake_channel, bake_range_start, bake_range_end, action_name,Dictionary p_export_settings) {}
// Error import_asset(gltf2_asset, p_export_settings) {}
// Error import_camera(gltf2_camera, Camera3D *, p_export_settings) {}
// Error import_gltf(gltf2_plan, p_export_settings) {}
// Error import_image(gltf2_image, p_export_settings) {}
// Error import_joint(gltf2_node, Skeleton3D *, BoneId, p_export_settings) {}
// Error import_material(gltf2_material, Ref<Material>, p_export_settings) {}
// Error import_material_pbr_metallic_roughness(gltf2_material, Ref<BaseMaterial3D>, orm_texture, p_export_settings) {}
// Error import_material_unlit(gltf2_material, Ref<Material>, p_export_settings) {}
// Error import_mesh(gltf2_mesh,Ref<ArrayMesh>, vertex_groups, modifiers, skip_filter, material_names, p_export_settings) {}
// Error import_sampler(self, gltf2_sampler, Ref<Material>, p_export_settings) {}
// Error import_node(gltf2_node, Node *, p_export_settings) {}
// Error import_scene(gltf2_scene, Node *, p_export_settings) {}
// Error import_skin(gltf2_skin,  Ref<Skin>, p_export_settings) {}
// Error import_texture(gltf2_texture, p_export_settings) {}
// Error import_texture_info(gltf2_texture_info, p_export_settings) {}

If this enhancement will not be used often, can it be worked around with a few lines of script?

GLTF2 support can be difficult and making hooks can help others. GLTF Extensions is not a few lines.

Is there a reason why this should be core and not an add-on in the asset library?

GLTFDocument is in core so it can't be easily modified by an addon.

@fire
Copy link
Member Author

fire commented Nov 22, 2022

@aaronfranke I think your pr implements this fully godotengine/godot#68981. Thoughts?

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

Successfully merging a pull request may close this issue.

4 participants