Skip to content

Add BSGeometry bone weight loading from mesh data#61

Merged
ousnius merged 5 commits into
ousnius:mainfrom
DJLegends1011:fix/starfield-bsgeometry-overrides
May 17, 2026
Merged

Add BSGeometry bone weight loading from mesh data#61
ousnius merged 5 commits into
ousnius:mainfrom
DJLegends1011:fix/starfield-bsgeometry-overrides

Conversation

@DJLegends1011
Copy link
Copy Markdown
Contributor

@DJLegends1011 DJLegends1011 commented May 17, 2026

Summary

  • Add a BSGeometry case to GetShapeBoneWeights that reads per-vertex bone weights from BSGeometryMeshData::skinWeights (packed uint16 values where 65535 = 1.0)
  • Fixes Starfield mesh vertices appearing unweighted in Outfit Studio

Context

Follow-up to PR #60 (merged). This commit was on the same branch but not included in that PR.

🤖 Generated with the help of Claude Code
@

GetShapeBoneWeights had no path for BSGeometry shapes. Starfield
meshes store per-vertex bone weights in BSGeometryMeshData::skinWeights
as packed uint16 values (65535 = 1.0). Add a BSGeometry case that reads
these weights, bridging the gap that caused all SF mesh vertices to
appear unweighted in Outfit Studio.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends Starfield BSGeometry skinning support by teaching NifFile::GetShapeBoneWeights how to read per-vertex bone weights from BSGeometryMeshData::skinWeights, addressing cases where Starfield meshes previously appeared unweighted.

Changes:

  • Add a BSGeometry code path in GetShapeBoneWeights that extracts weights from BSGeometryMeshData::skinWeights and normalizes uint16 weights to floats.
  • Preserve existing behavior for BSTriShape and NiSkinInstance-backed shapes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/NifFile.cpp Outdated
Comment thread src/NifFile.cpp
Address Copilot review notes on the BSGeometry GetShapeBoneWeights path:
- The vertex loop counter was uint16_t while skinWeights.size() is 32-bit,
  causing an infinite loop on meshes with more than 65535 vertices. Iterate
  with a size_t index capped at the uint16_t-keyed output map's range.
- Add a Starfield regression test that loads the external mesh data and
  verifies GetShapeBoneWeights returns normalized weights in [0, 1].

https://claude.ai/code/session_01M73z1PscSn8M97dpyPYUW5
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread tests/TestNifFile.cpp
Comment thread tests/TestNifFile.cpp
Comment thread src/NifFile.cpp Outdated
ousnius and others added 2 commits May 17, 2026 09:48
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
In tests/TestNifFile.cpp (BSGeometry bone weights test) replace structured bindings that returned full file tuples with std::get<0>() to only retrieve the input path (fileInput / meshFileInput). Add REQUIRE checks to ensure external mesh path lists and mesh path strings are not empty before attempting to open streams. These changes remove unused tuple elements and add safer assertions to avoid opening invalid paths during the test.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/NifFile.cpp
Comment thread src/NifFile.cpp
Replace hardcoded magic values (0x10000 and 65535) with constexpr derived from std::numeric_limits<uint16_t>::max(). Cap vertCount via std::min to avoid overflow on meshes with >65535 vertices and normalize bone weights by a named maxWeightValue. Improves clarity and avoids magic numbers.
@ousnius ousnius added the enhancement New feature or request label May 17, 2026
@ousnius ousnius self-assigned this May 17, 2026
@ousnius ousnius merged commit aeee637 into ousnius:main May 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants