From 8c13c982b9d3c5a50c8bcd0e85e8a467d73b0b60 Mon Sep 17 00:00:00 2001 From: Guillaume Babin <36015647+guibab@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:32:19 -0800 Subject: [PATCH] fix retrieve xml, added vertices count to find match in name mismatch (#8) Co-authored-by: Guillaume Babin --- scripts/blurdeform/blurdeform.py | 8 ++++++-- scripts/blurdeform/storeXml.py | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/scripts/blurdeform/blurdeform.py b/scripts/blurdeform/blurdeform.py index 58e94a2..595dbfa 100644 --- a/scripts/blurdeform/blurdeform.py +++ b/scripts/blurdeform/blurdeform.py @@ -643,9 +643,11 @@ def addNewFrame(self): self.refresh(selectTime=True, selTime=cmds.currentTime(q=True)) def doAddNewFrame(self, blurNode, currentGeom, targetMesh): - # print(blurNode, currentGeom, targetMesh) + print(blurNode, currentGeom, targetMesh) prt ,= cmds.listRelatives(targetMesh, parent=True, path=True) or [None] - cmds.parent(targetMesh, currentGeom) + [cmds.setAttr(targetMesh+"."+att+axis, l=False) for att in "trs" for axis in " xyz"] + if prt != currentGeom: + cmds.parent(targetMesh, currentGeom) cmds.makeIdentity(targetMesh, apply=True, translate=False, rotate=True, scale=False, normal=0, preserveNormals=True) if prt is not None: cmds.parent(targetMesh, prt) @@ -1633,6 +1635,8 @@ def storeInfoBlurSculpt(self, doc, blurNode, inputPoseFramesIndices=None): geomIndices = " - ".join(map(str, geoIndices)) blurNode_tag.setAttribute("geom", geom) blurNode_tag.setAttribute("geomIndices", geomIndices) + nbVertices = cmds.polyEvaluate(geom, v=True) + blurNode_tag.setAttribute("nbVertices", nbVertices) listPoses = cmds.blurSculpt(blurNode, query=True, listPoses=True) if not listPoses: diff --git a/scripts/blurdeform/storeXml.py b/scripts/blurdeform/storeXml.py index 731d226..fc3c6f8 100644 --- a/scripts/blurdeform/storeXml.py +++ b/scripts/blurdeform/storeXml.py @@ -211,11 +211,23 @@ def retrieveblurXml(self, dicFrames, listPoses, theBlurNode=None): dicVal = {"blurNode": theBlurNode} blurNodeMeshToIndex, geomSorted = self.blurInfo[theBlurNode] - fileIndexToMesh = self.blurFileInfo[geomSorted] + if geomSorted not in self.blurFileInfo: + # try the first element + currentNbVerts = cmds.polyEvaluate(geomSorted, v=True) + if currentNbVerts in self.vertsToName: + storedName = self.vertsToName[currentNbVerts] + fileIndexToMesh = self.blurFileInfo[storedName] + print("matching vertices found {}".format(currentNbVerts)) + else: + storedName, fileIndexToMesh = next(iter(self.blurFileInfo.items())) + + else: + fileIndexToMesh = self.blurFileInfo[geomSorted] + storedName = geomSorted dicIndexFileToIndexNode = {} for indexGeo, meshName in six.iteritems(blurNodeMeshToIndex): - indexFile = fileIndexToMesh[meshName] + indexFile = fileIndexToMesh[meshName if meshName in fileIndexToMesh else storedName] dicIndexFileToIndexNode[indexFile] = indexGeo pses = cmds.getAttr(theBlurNode + ".poses", mi=True) @@ -438,6 +450,7 @@ def readXmlFile(self): self.blurDic = {} self.blurInfo = {} self.blurFileInfo = {} + self.vertsToName = {} for blurNode in selectedItems: geos, geoIndices = self.parentWindow.getGeom(blurNode, transform=True) geomSorted = " - ".join(sorted(geos)) @@ -489,6 +502,10 @@ def refreshTreeFromRoot(self, root): self.blurFileInfo[geomSorted] = blurNodeIndexToMesh # multi deal - with name END + if "nbVertices" in blurNode_tag.attrib: + nbVertices = blurNode_tag.get("nbVertices") + self.vertsToName[int(nbVertices)] = geomSorted + isGeomSelected = geomSorted in geomsSelected for pose_tag in list(iter(blurNode_tag)): poseName = pose_tag.get("poseName")