Skip to content

Model Importer#136

Open
erodozer wants to merge 14 commits intoMizunagiKB:mainfrom
erodozer:importer
Open

Model Importer#136
erodozer wants to merge 14 commits intoMizunagiKB:mainfrom
erodozer:importer

Conversation

@erodozer
Copy link
Copy Markdown
Contributor

@erodozer erodozer commented Mar 4, 2025

This is a large refactor PR that I've been developing and testing in my own applications as I go.

Goal is to separate out standing up Live2D models purely at runtime or dynamic settings within the editor. Instead Models can now be treated as Resources, specifically PackedScenes, that can be instantiated and cached. This improves time to create instances of models, as we no longer need the SDK to rebuild the meshes and materials at runtime.

The front facing API of the GDCubismUserModel should be largely unaffected, but a lot has been changed under the hood

Key changes

  • ResourceFormatLoader and EditorImportPlugin have been implemented, which build models as packed scenes
  • Users should not be creating GDCubismUserModel instances manually through the editor anymore, instead models should be loaded using the importer or through scripting, as they have an implicit tree requirement
    • Meshes and Masks are nested in grouping nodes
  • Parameters and Part Opacities are changed from resources to properties to allow for per-instance values
  • Builds on top of Load Motions as Animation Resources #128, moving away from using CubismSDK functions directly in favor of working towards supporting them natively through Godot's own systems

image

Opening as a draft just to highlight that this is something I'm actively working on that people can try out. It is a bit comprehensive as it also includes and depends on other open PRs. I will be squashing and rebasing commits as I go and as other PRs get merged.

User experience may not be perfect until godotengine/godot#100086 is merged, as Godot currently detects json as the extension for all Live2D files, which can cause an undesired importer match on unrelated files.

@erodozer erodozer changed the base branch from main to 0.8.1 March 6, 2025 01:53
@erodozer erodozer changed the base branch from 0.8.1 to main March 8, 2025 06:18
@erodozer erodozer changed the base branch from main to 0.9 March 25, 2025 14:00
@MizunagiKB MizunagiKB mentioned this pull request Mar 26, 2025
Merged
add missing generate mipmap step
allow mipmaps to be toggled
@erodozer erodozer changed the base branch from 0.9 to main March 28, 2025 05:35
@erodozer
Copy link
Copy Markdown
Contributor Author

Been making a few significant architectural changes, since this refactor is all about making things fit the Godot design patterns. Refactorings are still a work in progress, but this is the direction I've been going

  • Motions and Expressions have been refactored as GDCubismEffects, since they generally operated under the same pattern
    • Importer can choose to pack the scene with either a Godot AnimationPlayer or a Cubism Native MotionManager Effect
    • InternalCubismUserModel is in the process of being stripped down to only what is needed to update vertices
  • InternalCubismRenderer2D has been stripped down to just static functions that perform updates
    • Godot rendering did not actually leverage anything specific or stateful of the CubismRenderer from the SDK.
    • Removed the InternalCubismRenderer3D since it was never implemented, nor likely to be any time soon
  • Added configuration to allow Textures to generate mipmaps on load for models loaded from outside the project directory

@erodozer
Copy link
Copy Markdown
Contributor Author

erodozer commented Apr 3, 2025

More refactoring adjustments

  • InternalCubismUserModel has been removed, as its existence as a stateful object was redundant with Godot's own stateful nodes.
    • As a result, Effects Nodes now hook into GDCubismUserModel, which helps keep interfaces designed so that godot objects are talking to godot objects.
  • More Cubism systems have been moved into GDCubismEffects, allowing for a cleaner model of composition. The loader generates the effects in the scene tree so the execution of motions, poses, expressions, and physics all apply in the order according to how they did before.

Due some features having been moved into Effects, such as Motions, the properties have been removed from GDCubismUserModel. I am contemplating encouraging accessing through nodes in the scene tree with get_node, as that's more typical of Godot practices, or bubbling up the properties when the effect exists.

users are less likely to override this behavior, so it is better than taking over the virtual functions
z-indexes are a bit broken for groups, in our case it's preferred to sort within the scene tree even if that's more expensive of an operation.  Render order in most models no not extensively change from frame to frame so it should result in minimal operational overhead versus the other workaround of wrapping models in viewports.
@erodozer erodozer marked this pull request as ready for review January 22, 2026 16:20
@erodozer
Copy link
Copy Markdown
Contributor Author

Just an update on this, I've been using this branch for quite awhile in my own project, paired with #153 for improved binary distribution. I've gone and squashed other changes I had into it to overall make the performance and stability more predictable. Lots has been simplified with shaders, overall the approach has worked quite well for me allowing for dynamically loading models at runtime, as well as bundled as Godot managed importable resources.

This branch should already be in a state that's good for anyone to use.

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