Skip to content

Commit

Permalink
Fix a skin bug (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrinktofit authored Nov 3, 2020
1 parent d521acc commit 846c6b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Core/Source/bee/Convert/SceneConverter.Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ SceneConverter::_typeVertices(const FbxMeshVertexLayout &vertex_layout_) {
? channelCount / setCapacity
: (channelCount / setCapacity + 1);
for (std::remove_const_t<decltype(set)> iSet = 0; iSet < set; ++iSet) {
const auto setElement =
(iSet == set - 1) ? channelCount % setCapacity : setCapacity;
const auto nSetElements =
(iSet == set - 1) ? (channelCount - iSet * setCapacity) : setCapacity;
defaultBulk.addChannel(
"JOINTS_" + std::to_string(iSet), // name
glTFType, // type
Expand All @@ -604,7 +604,7 @@ SceneConverter::_typeVertices(const FbxMeshVertexLayout &vertex_layout_) {
makeUntypedVertexCopyN<
GLTFComponentTypeStorage<
fx::gltf::Accessor::ComponentType::UnsignedShort>,
NeutralVertexJointComponent>(setElement) // writer
NeutralVertexJointComponent>(nSetElements) // writer
);
defaultBulk.addChannel(
"WEIGHTS_" + std::to_string(iSet), // name
Expand All @@ -615,7 +615,7 @@ SceneConverter::_typeVertices(const FbxMeshVertexLayout &vertex_layout_) {
makeUntypedVertexCopyN<GLTFComponentTypeStorage<
fx::gltf::Accessor::ComponentType::Float>,
NeutralVertexWeightComponent>(
setElement) // writer
nSetElements) // writer
);
}
}
Expand Down
9 changes: 7 additions & 2 deletions Core/Source/bee/Convert/SceneConverter.Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ SceneConverter::_extractSkinData(const fbxsdk::FbxMesh &fbx_mesh_) {
for (std::remove_const_t<decltype(nControlPointIndices)>
iControlPointIndex = 0;
iControlPointIndex < nControlPointIndices; ++iControlPointIndex) {
const auto weight = static_cast<NeutralVertexWeightComponent>(
controlPointWeights[iControlPointIndex]);
if (!weight) {
continue;
}
const auto controlPointIndex = controlPointIndices[iControlPointIndex];
auto &nChannels = channelsCount[controlPointIndex];
assert(nChannels <= skinData.channels.size());
Expand All @@ -219,8 +224,7 @@ SceneConverter::_extractSkinData(const fbxsdk::FbxMesh &fbx_mesh_) {
}
auto &[joints, weights] = skinData.channels[nChannels];
joints[controlPointIndex] = jointId;
weights[controlPointIndex] = static_cast<NeutralVertexWeightComponent>(
controlPointWeights[iControlPointIndex]);
weights[controlPointIndex] = weight;
++nChannels;
}
}
Expand Down Expand Up @@ -255,6 +259,7 @@ SceneConverter::_extractSkinData(const fbxsdk::FbxMesh &fbx_mesh_) {
std::uint32_t
SceneConverter::_createGLTFSkin(const NodeMeshesSkinData &skin_data_) {
fx::gltf::Skin glTFSkin;
glTFSkin.name = skin_data_.name;
glTFSkin.joints.resize(skin_data_.bones.size());
std::transform(
skin_data_.bones.begin(), skin_data_.bones.end(), glTFSkin.joints.begin(),
Expand Down

0 comments on commit 846c6b3

Please sign in to comment.