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 option to bake a mesh from animated skeleton pose #85018

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

smix8
Copy link
Contributor

@smix8 smix8 commented Nov 17, 2023

Adds option to bake a mesh from animated skeleton pose.

Takes a snapshot of the current animated skeleton pose of the skinned mesh and bakes it to another ArrayMesh.

Implements godotengine/godot-proposals#8120 to make stuff like this:

skinned_mesh_baking

Pairs with #76725 to bake the blend shapes.

Production edit: closes godotengine/godot-roadmap#58

@smix8 smix8 requested review from a team as code owners November 17, 2023 14:31
@smix8 smix8 added this to the 4.x milestone Nov 17, 2023
@smix8 smix8 force-pushed the skinnedmeshbake branch 2 times, most recently from 6b97b25 to cd7cfb0 Compare November 17, 2023 14:45
@jcostello
Copy link
Contributor

Could be use to emit particles from a animated mesh?

@smix8
Copy link
Contributor Author

smix8 commented Nov 17, 2023

Could be use to emit particles from a animated mesh?

See godotengine/godot-proposals#8106 and godotengine/godot-proposals#5051

Particles have currently no exposed API to bake emission points from mesh at runtime.

For performance it also makes far more sense to directly bake to the texture that the particle shader uses instead of baking to an intermediate mesh.

@smix8 smix8 modified the milestones: 4.x, 4.3 Nov 20, 2023
@clayjohn
Copy link
Member

Personally I am a bit wary of exposing new APIs to users that cause GPU stalls like this. My preference would be to first add a caching system to Mesh so that users can choose to keep the data on the CPU if they want to do things like this.

@smix8
Copy link
Contributor Author

smix8 commented Nov 22, 2023

Where should such an option to (pre)cache the mesh arrays be added? On the MeshInstance3D or the Mesh or e.g. within the existing ArrayMesh Surface struct?

Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

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

I am in favour of the feature, but I don't know how to resolve the request from @clayjohn

@fire
Copy link
Member

fire commented Apr 10, 2024

I would also reuse the same approach from the blend shape bake with the inputted mesh outputting a mesh

@smix8 smix8 force-pushed the skinnedmeshbake branch from 741997f to 8bdc4b0 Compare April 11, 2024 01:21
@smix8
Copy link
Contributor Author

smix8 commented Apr 11, 2024

Applied the same changes as in the blendshape bake pr. The baked mesh is always returned, and if an optional existing mesh param is provided it updates this mesh RID instead of creating a new mesh as this helps with updating instances that already use that mesh.

@smix8 smix8 force-pushed the skinnedmeshbake branch from 8bdc4b0 to 7dd8537 Compare April 11, 2024 01:31
@akien-mga akien-mga requested a review from clayjohn April 11, 2024 08:52
@smix8 smix8 force-pushed the skinnedmeshbake branch from 7dd8537 to 896cc37 Compare April 11, 2024 10:43
@smix8 smix8 force-pushed the skinnedmeshbake branch from 946d472 to 7b19dec Compare June 13, 2024 17:48
@PiCode9560
Copy link

Is this thing done yet?

Adds option to bake a mesh from animated skeleton  pose.
@fire fire dismissed AThousandShips’s stale review September 3, 2024 22:27

All review comments are addressed.

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Sep 4, 2024
@akien-mga akien-mga merged commit db6af2e into godotengine:master Sep 4, 2024
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@RavinMaddHatter
Copy link

RavinMaddHatter commented Sep 9, 2024

Does this actually work? i have been trying to get it to work for a few days. Any example code would be nice or an example project. i tried what is in the docs but i keep getting out the orginal unblended mesh.

Aah. the 4.3 version i am running doesnt seem to have the actual code... just the stubs.... 3 days of head banging later.

@fire
Copy link
Member

fire commented Sep 11, 2024

@RavinMaddHatter are you testing on 4.4?

@RavinMaddHatter
Copy link

RavinMaddHatter commented Sep 11, 2024

image
I have tested on 4.4 Dev2 I have tried many many things. I am very likely doing something wrong, but that would mean the documentation is incomplete (happy to help fix it) or there is a bug. i can get you something for docs update if we can figure out how to get it to work on my PC.

Can chat in discord or continue here. I have several posts with no responses.

@RavinMaddHatter
Copy link

Does anyone have a test project so i can figure out the difference and why i only get the default pose?

@qualmonade
Copy link

qualmonade commented Sep 15, 2024

I'm currently encountering a problem where regardless of if it's true or not, the function does not seem to find any of the bones attached to the skeleton of my mesh of choice. I have so far tested this with inherited scenes, including imported GLB files.
image
image
image
(Excuse my less-than-stellar code. I deleted most of the rest of the other code and forgot to remove the add_child() so that I could try to zero in on what the issue was exactly.)

I am wondering if this is related to the issue that RavinMaddHatter is having?

Does this actually work? i have been trying to get it to work for a few days. Any example code would be nice or an example project. i tried what is in the docs but i keep getting out the orginal unblended mesh.

@fire
Copy link
Member

fire commented Sep 15, 2024

Please provide a test project with code.

@qualmonade
Copy link

Here you go!
I am hoping this is correct. Let me know if anything is broken in some way or other.

@TinyZilla
Copy link

So this function returns a ArrayMesh which is a resource not a node. If you add the resource to another MeshInstance3D it'll be correct. It seems to work correctly for me at least.

var a : MeshInstance3D = $ExistingMeshInstance
var b : MeshInstance3D = MeshInstance3D.new()
b.mesh = a.bake_mesh_from_current_skeleton_pose()
get_tree().root.add_child(b)

@RavinMaddHatter
Copy link

RavinMaddHatter commented Sep 16, 2024 via email

@RavinMaddHatter
Copy link

Looking at this again. This is the node i am baking. It is generated via another library so it is called Baked_Opaque.
image

In that node, there is an attached skeleton:
image
I am using this exact line of code to get the meshinstance3d baked from the skeleton
var mesh = humanizer.find_child("Baked-Opaque").bake_mesh_from_current_blend_shape_mix()
Using this version of godot
image
When i export the OBJ (i have been exporting OBJ files of the returned mesh instance 3d rather than just displaying it, because this is supposed to return the mesh snap shot, not just a copy of the skeleton attached to a similar mesh)

This is the posed input mesh rendered by the GPU
image
This is the mesh exported from the CPU
image

I am happy to be wrong here, just want to know where i am wrong.

@RavinMaddHatter
Copy link

You can see the project. it is not minimized i apologize for that, but I am not sure how to minimize it right now. I am still figuring out the 3d aspects of godot.
https://github.com/RavinMaddHatter/Madhatters-Table-Top-RPG-Mini-Maker
The baking is occuring on line 439 of new_character_menu script
The export is occurring on line 445

This is a learning project so the code hygiene is terrible. But i cannot get it to work, i am looking into other options on this topic as well.

@fire
Copy link
Member

fire commented Sep 23, 2024

I have made an issue on https://github.com/RavinMaddHatter/Madhatters-Table-Top-RPG-Mini-Maker to debug this.

@RavinMaddHatter
Copy link

From the other thread "There seems to be a missing feature to bake both blend shapes and skeleton poses."

I have not seen any updates. but i am curious if this is a bug in my implementation or in the godot implementation.

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.