diff --git a/PYProjects/skin_plus_plus/core.py b/PYProjects/skin_plus_plus/core.py index 75502ab..bd156a8 100644 --- a/PYProjects/skin_plus_plus/core.py +++ b/PYProjects/skin_plus_plus/core.py @@ -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: diff --git a/PYProjects/skin_plus_plus_test/skin_plus_plus_test.py b/PYProjects/skin_plus_plus_test/skin_plus_plus_test.py index 24bf62b..8b1410b 100644 --- a/PYProjects/skin_plus_plus_test/skin_plus_plus_test.py +++ b/PYProjects/skin_plus_plus_test/skin_plus_plus_test.py @@ -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) @@ -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): diff --git a/PYProjects/source/skin_plus_plus_py/headers/skin_plus_plus_py.h b/PYProjects/source/skin_plus_plus_py/headers/skin_plus_plus_py.h index 96fe83b..09d1761 100644 --- a/PYProjects/source/skin_plus_plus_py/headers/skin_plus_plus_py.h +++ b/PYProjects/source/skin_plus_plus_py/headers/skin_plus_plus_py.h @@ -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) diff --git a/PYProjects/source/skin_plus_plus_pymaya/skin_plus_plus_pymaya.cpp b/PYProjects/source/skin_plus_plus_pymaya/skin_plus_plus_pymaya.cpp index 6c69033..e37c6db 100644 --- a/PYProjects/source/skin_plus_plus_pymaya/skin_plus_plus_pymaya.cpp +++ b/PYProjects/source/skin_plus_plus_pymaya/skin_plus_plus_pymaya.cpp @@ -282,13 +282,13 @@ void sortBoneIDs(BoneIDsMatrix& boneIDs, std::vector newIDOrder, const eg: /// /// /// -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); @@ -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 += ", "; @@ -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; } @@ -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,