-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Refactor skinned mesh weight data structure #16655
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
Merged
+581
−620
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
91e8dea
Refactor skinned mesh weight data structure
appgurueu 61c77cb
Eat your vegetables
appgurueu 295f8e2
Weights -> weights
appgurueu ceda6a2
SkinnedMeshBuilder: Inheritance -> composition + friend
appgurueu 2f4d353
Avoid unnecessary reallocations
appgurueu cd05a1f
Transpose: Use vector of structs
appgurueu e88f907
.
appgurueu b7c659e
Remove IAnimatedMesh::[gs]etAnimationSpeed
appgurueu 02e52f7
Irrlicht license
appgurueu c010ebd
Various small things
appgurueu 473d68c
Do bounds check in WeightBuffer
appgurueu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Luanti | ||
| // SPDX-License-Identifier: LGPL-2.1-or-later | ||
| // Copyright (C) 2025 Lars Müller | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "vector3d.h" | ||
| #include "matrix4.h" | ||
| #include "IVertexBuffer.h" | ||
|
|
||
| #include <cassert> | ||
| #include <memory> | ||
| #include <optional> | ||
|
|
||
| namespace scene | ||
| { | ||
|
|
||
| struct WeightBuffer | ||
| { | ||
| constexpr static u16 MAX_WEIGHTS_PER_VERTEX = 4; | ||
| size_t n_verts; | ||
| std::unique_ptr<u16[]> joint_idxs; | ||
| std::unique_ptr<f32[]> weights; | ||
|
|
||
| std::optional<std::vector<u32>> animated_vertices; | ||
|
|
||
| // A bit of a hack for now: Store static positions here so we can use them for skinning. | ||
| // Ideally we might want a design where we do not mutate the original vertex buffer at all. | ||
| std::unique_ptr<core::vector3df[]> static_positions; | ||
| std::unique_ptr<core::vector3df[]> static_normals; | ||
|
|
||
| WeightBuffer(size_t n_verts); | ||
|
|
||
| u16 *getJointIndices(u32 vertex_id) | ||
| { return &joint_idxs[vertex_id * MAX_WEIGHTS_PER_VERTEX]; } | ||
| const u16 *getJointIndices(u32 vertex_id) const | ||
| { return &joint_idxs[vertex_id * MAX_WEIGHTS_PER_VERTEX]; } | ||
|
|
||
| f32 *getWeights(u32 vertex_id) | ||
| { return &weights[vertex_id * MAX_WEIGHTS_PER_VERTEX]; } | ||
| const f32 *getWeights(u32 vertex_id) const | ||
| { return &weights[vertex_id * MAX_WEIGHTS_PER_VERTEX]; } | ||
|
|
||
| void addWeight(u32 vertex_id, u16 joint_id, f32 weight); | ||
|
|
||
| void skinVertex(u32 vertex_id, core::vector3df &pos, core::vector3df &normal, | ||
| const std::vector<core::matrix4> &joint_transforms) const; | ||
appgurueu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// @note src and dst can be the same buffer | ||
| void skin(IVertexBuffer *dst, | ||
| const std::vector<core::matrix4> &joint_transforms) const; | ||
|
|
||
| /// Normalizes weights so that they sum to 1.0 per vertex, | ||
| /// stores which vertices are animated. | ||
| void finalize(); | ||
|
|
||
| void updateStaticPose(const IVertexBuffer *vbuf); | ||
|
|
||
| void resetToStatic(IVertexBuffer *vbuf) const; | ||
| }; | ||
|
|
||
| } // end namespace scene | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.