Skip to content

Commit

Permalink
Further updates to maya set data logic
Browse files Browse the repository at this point in the history
Now handles data with varying influence size, order and values
  • Loading branch information
munkybutt committed Sep 16, 2023
1 parent c3624ad commit 82cdd79
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 37 deletions.
2 changes: 0 additions & 2 deletions PYProjects/skin_plus_plus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ def import_skin_data(
tuple(data["positions"])
)

print(f"skin_data.bone_ids: {skin_data.bone_ids}")

return set_skin_weights(mesh_name, skin_data)

# if import_type == ImportType.nearest:
Expand Down
35 changes: 17 additions & 18 deletions PYProjects/skin_plus_plus_test/skin_plus_plus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,9 @@ def add_bones():
print(mobject)
fnInfluence = oman.MFnIkJoint(mobject);


if __name__ == "__main__":
pass
# skin_plus_plus.io.max_to_maya(file_type=skin_plus_plus.FileType.json)
skin_plus_plus.io.max_to_maya(file_type=skin_plus_plus.FileType.json)
# skin_plus_plus
# bones = ["one", "two"]
# ids = np.array([[0, 1], [1, 0]], dtype=np.float64)
Expand All @@ -689,26 +688,26 @@ def add_bones():
# print(sd.bone_ids)
# skin_plus_plus.io.save(file_type=skin_plus_plus.FileType.json)
# skin_plus_plus.io.load(file_type=skin_plus_plus.FileType.json)
import json
# import json
# import pickle

path = r"C:\Users\Sheaky\Documents\3ds Max 2023\scenes\_Data\Sphere001_GEO.skpp-json"
# path = r"C:\Users\Sheaky\Documents\3ds Max 2023\scenes\_Data\Sphere001_GEO.skpp-json"

with open(path, "r") as file:
data = json.load(file)
skin_data = skin_plus_plus.SkinData(
tuple(data["bone_names"]),
tuple(data["bone_ids"]),
tuple(data["weights"]),
tuple(data["positions"])
)
# # with open(path, "rb") as file:
# # skin_data = pickle.load(file)
# with open(path, "r") as file:
# data = json.load(file)
# skin_data = skin_plus_plus.SkinData(
# tuple(data["bone_names"]),
# tuple(data["bone_ids"]),
# tuple(data["weights"]),
# tuple(data["positions"])
# )
# with open(path, "rb") as file:
# skin_data = pickle.load(file)

# print(skin_data)
# # for ids in skin_data.bone_ids:
# # print(ids)
skin_plus_plus.set_skin_weights("Sphere001", skin_data)
# # print(skin_data)
# # # for ids in skin_data.bone_ids:
# # # print(ids)
# skin_plus_plus.set_skin_weights("Sphere001", skin_data)
# sd = skin_plus_plus.get_skin_data("Sphere001")
# print(sd.weights)
# for index, weights in enumerate(sd.weights):
Expand Down
19 changes: 19 additions & 0 deletions PYProjects/source/skin_plus_plus_py/headers/skin_plus_plus_py.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ struct PySkinData final
this->boneIDs = boneIDs;
this->weights = weights;
this->positions = positions;
//for (eg::Index i = 0; i < this->boneIDs.rows(); i++)
//{
// auto message = fmt::format("Vertex: {} - ", i);
// for (UINT j = 0; j < this->boneIDs.cols(); j++)
// {
// if (j == 0)
// {
// message += "[";
// }
// auto value = this->boneIDs(i, j);
// message += fmt::format("{}", value);
// if (j < this->boneIDs.cols() - 1)
// {
// message += ", ";
// }
// }
// message += "]";
// py::print(message);
//}
}

PySkinData(py::tuple data)
Expand Down
39 changes: 22 additions & 17 deletions PYProjects/source/skin_plus_plus_pymaya/skin_plus_plus_pymaya.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ void sortBoneIDs(BoneIDsMatrix& boneIDs, std::vector<UINT> newIDOrder, const eg:
/// <param name="vertexCount"></param>
/// <param name="influenceCount"></param>
/// <returns></returns>
MDoubleArray getWeightsAsMDoubleArray(BoneIDsMatrix boneIDs, WeightsMatrix weights, const eg::Index vertexCount, const eg::Index influenceCount)
MDoubleArray getWeightsAsMDoubleArray(BoneIDsMatrix boneIDs, WeightsMatrix weights, const eg::Index vertexCount, const eg::Index influenceCount, const eg::Index maxInfluenceCount)
{
const UINT arraySize = vertexCount * influenceCount;
MDoubleArray mWeights(arraySize);
const UINT arraySize = vertexCount * maxInfluenceCount;
MDoubleArray mWeights(arraySize, 0.0);
for (eg::Index vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++)
{
const UINT baseIndex = vertexIndex * influenceCount;
const UINT baseIndex = vertexIndex * maxInfluenceCount;
for (eg::Index influenceIndex = 0; influenceIndex < influenceCount; influenceIndex++)
{
const int boneID = boneIDs(vertexIndex, influenceIndex);
Expand All @@ -303,14 +303,15 @@ MDoubleArray getWeightsAsMDoubleArray(BoneIDsMatrix boneIDs, WeightsMatrix weigh
}
//for (eg::Index i = 0; i < vertexCount; i++)
//{
// auto message = fmt::format("Vertex: {}", i);
// auto message = fmt::format("Vertex: {} - ", i);
// for (UINT j = 0; j < influenceCount; j++)
// {
// if (j == 0)
// {
// message += "[";
// }
// message += fmt::format("{}", mWeights[j]);
// auto mIndex = i * influenceCount + j;
// message += fmt::format("{}: {}", mIndex, mWeights[mIndex]);
// if (j < influenceCount - 1)
// {
// message += ", ";
Expand All @@ -319,6 +320,10 @@ MDoubleArray getWeightsAsMDoubleArray(BoneIDsMatrix boneIDs, WeightsMatrix weigh
// message += "]";
// py::print(message);
//}
//for (size_t i = 0; i < mWeights.length(); i++)
//{
// py::print(mWeights[i]);
//}
return mWeights;
}

Expand Down Expand Up @@ -386,20 +391,20 @@ bool SkinManagerMaya::setSkinWeights(PySkinData& skinData)
MIntArray mBoneIDs(sortedBoneSize);

//auto message = fmt::format("Influences: [");
//for (size_t index = 0; index < sortedBoneSize; index++)
//{
// mBoneIDs[index] = sortedBoneIDs.sortedBoneIDs[index];
// message += fmt::format("{}", mBoneIDs[index]);
// if (index < sortedBoneSize - 1)
// {
// message += ", ";
// }
//}
for (size_t index = 0; index < sortedBoneSize; index++)
{
mBoneIDs[index] = sortedBoneIDs.sortedBoneIDs[index];
//message += fmt::format("{}", mBoneIDs[index]);
//if (index < sortedBoneSize - 1)
//{
// message += ", ";
//}
}
//message += "]";
//py::print(message);

sortBoneIDs(skinData.boneIDs, sortedBoneIDs.sortedBoneIDs, vertexCount, influenceCount);
MDoubleArray mWeights = getWeightsAsMDoubleArray(skinData.boneIDs, skinData.weights, vertexCount, influenceCount);
//sortBoneIDs(skinData.boneIDs, sortedBoneIDs.sortedBoneIDs, vertexCount, influenceCount);
MDoubleArray mWeights = getWeightsAsMDoubleArray(skinData.boneIDs, skinData.weights, vertexCount, influenceCount, sortedBoneSize);
status = this->fnSkinCluster.setWeights(
this->dagPath,
this->component,
Expand Down

0 comments on commit 82cdd79

Please sign in to comment.