def GetCaptBoneNamesSet(node): resultSet = set() #print 'deal:',node boneDeformNodes = BasicFunc.get_nodes_in_children(node, 'bonedeform') for bdn in boneDeformNodes: for upNode in bdn.inputs(): tempNode_unpack = node.createNode('captureattribunpack') BasicFunc.connect_node(upNode, tempNode_unpack) captPathAttr = tempNode_unpack.geometry().findGlobalAttrib( 'boneCapture_pCaptPath') if captPathAttr: #print 'attrib exist:',captPathAttr.dataType(),' ',captPathAttr.name() capPathStrArr = tempNode_unpack.geometry( ).stringListAttribValue('boneCapture_pCaptPath') #print capPathStrArr resultSet = resultSet.union(set(capPathStrArr)) #print 'union len:', len(resultSet) tempNode_unpack.destroy() #print 'deal ok:',node,' \tcount:',len(resultSet) return resultSet
def DealBoneLines(rootBones): if not rootBones: return worldStage = rootBones[0].parent() curveObjNode = worldStage.createNode('geo') curveObjNode.setName('curve', True) curveNode = curveObjNode.createNode('null') curveNode.setHardLocked(True) curveGeo = curveNode.geometry().freeze() percentAttrName = 'percentOnCurve' curveGeo.addAttrib(hou.attribType.Point, percentAttrName, float(0)) lineList = [] #curvePosList = [] ptCount = 0 indexList = [] for rootBone in rootBones: line = HairControl.GetBoneLine(rootBone) lineList.append(line) #curve = [] boneCount = len(line) oneLineIndex = [] for i in range(boneCount): bone = line[i] newPoint = HairControl.CreatePointInGeo( BasicFunc.getWorldPos(bone), curveGeo) pPercent = float(i) / boneCount newPoint.setAttribValue(percentAttrName, pPercent) #curve.append(newPoint) oneLineIndex.append(ptCount) ptCount = ptCount + 1 #print 'end bone:', line[boneCount-1] lastPoint = HairControl.CreatePointInGeo( BoneQuery.GetBoneEndPos(line[boneCount - 1]), curveGeo) #curve.append() lastPoint.setAttribValue(percentAttrName, float(1)) oneLineIndex.append(ptCount) ptCount = ptCount + 1 #curvePosList.append(curve) indexList.append(oneLineIndex) #print curvePosList #for curveLine in curvePosList: #curveGeo.createPoints(curveLine) polygons = curveGeo.createPolygons(indexList) for poly in polygons: poly.setIsClosed(False)
def SubMeshesSplitToGeos(submeshNode): submeshNode.setHardLocked(True) nodeName = submeshNode.name() currentHomeNode = submeshNode.parent() outWorld = currentHomeNode.parent() newHomeNode = outWorld.createNode('geo') newHomeNode.setName(nodeName,True) currentHomeInputs = currentHomeNode.inputs() if currentHomeInputs and len(currentHomeInputs) > 0: BasicFunc.connect_node(currentHomeInputs[0], newHomeNode) BasicFunc.alignWorldPos(newHomeNode, currentHomeNode) BasicFunc.adjustLayout(newHomeNode) cpNode = hou.copyNodesTo((submeshNode,), newHomeNode)[0] submeshNode.setColor(hou.Color(1, 0, 0))
def AddFKControl(boneNode): # x to next, y to world up, that's all! boneTransformMatrix = boneNode.worldTransform() #print '111' ctl = BasicFunc.create_null_at_obj(boneNode) #print '222' ctl.parm('controltype').set(1) boneLen = boneNode.parm('length').eval() ctl.parm('geoscale').set(boneLen) # lookAtNode = None # nodeOutputs = boneNode.outputs() # if nodeOutputs is not None and len(nodeOutputs) > 0: # lookAtNode = nodeOutputs[0] selfPos = BasicFunc.getWorldPos(boneNode) # if lookAtNode is None: # targetPos = hou.Vector3(0,0,-1) * boneTransformMatrix # temp = boneNode.parent().createNode('null') # BasicFunc.setWorldPos(temp,targetPos[0],targetPos[1],targetPos[2]) # else: # targetPos = BasicFunc.getWorldPos(lookAtNode) targetPos = hou.Vector3(0, 0, -1) * boneTransformMatrix # this kind of way is really stupid.... direction = targetPos - selfPos sideDirection = direction.cross(hou.Vector3(0, 1, 0)) sidePos = selfPos - sideDirection sideEye = boneNode.parent().createNode('null') BasicFunc.setWorldPos(sideEye, sidePos[0], sidePos[1], sidePos[2]) upVec = sideDirection.cross(direction) matrix = ctl.buildLookatRotation(sideEye, upVec) ctl.setWorldTransform(matrix) sideEye.destroy() BasicFunc.set_transform_keeppos(ctl) BasicFunc.set_transform_keeppos(boneNode) nodeInputs = boneNode.inputs() if nodeInputs is not None and len(nodeInputs) > 0: BasicFunc.connect_node(nodeInputs[0], ctl) BasicFunc.connect_node(ctl, boneNode) BasicFunc.adjustLayout(ctl)
def ConvertJointsToBones(fbxNode): #print 'begin convert fbxNode', fbxNode.name() newNodes = [] parentNullNodes = [] destroyList = [] geoList = [] for child in fbxNode.children(): childTypeName = child.type().name() if childTypeName == 'bone': childInputs = child.inputs() if childInputs is not None and len(childInputs) > 0: jointParentNode = child.inputs()[0] parentNullNodes.append(jointParentNode) jointParentNode.parm('keeppos').set(True) #jointParentName = jointParentNode.name() #jointRealName = jointParentName.split('_')[-1] #print child.name(), '->' , child.inputs() realBoneNode = fbxNode.createNode('bone')#,'bone_'+jointRealName) realBoneNode.parm('length').set(child.parm('length').eval()) realBoneNode.setColor(hou.Color(1,0,0)) #realBoneNode.setInput(0,None,0) newNodes.append(realBoneNode) BasicFunc.connect_node(child, realBoneNode) BasicFunc.alignWorldPos(realBoneNode, jointParentNode) realBoneNode.parm('keeppos').set(True) BasicFunc.adjustLayout(realBoneNode) child.setDisplayFlag(False) destroyList.append(child) elif childTypeName == 'geo': geoList.append(child) elif childTypeName == 'null': if len(child.outputs()) == 0: childInputs = child.inputs() if childInputs is not None and len(childInputs)>0: if JointsToBones.IsNodeJoint(childInputs[0]): # this is the end joint child.parm('keeppos').set(True) endBone = fbxNode.createNode('bone') endBone.parm('length').set(0) BasicFunc.connect_node(child, endBone) endBone.parm('keeppos').set(True) BasicFunc.adjustLayout(endBone) newNodes.append(endBone) parentNullNodes.append(child) #BasicFunc.layoutChildren(fbxNode, newNodes, 0, 1) for i in range(len(newNodes)): mother = parentNullNodes[i] motherInputs = mother.inputs() if motherInputs is not None and len(motherInputs)>0: grandma = motherInputs[0] if grandma in parentNullNodes: father = newNodes[parentNullNodes.index(grandma)] BasicFunc.connect_node(father, newNodes[i]) else: newNodes[i].setInput(0,None,0) targetNames = [] for i in range(len(newNodes)): try: targetName = parentNullNodes[i].name() #parentNullNodes[i].destroy() if not parentNullNodes[i] in destroyList: destroyList.append(parentNullNodes[i]) targetNames.append(targetName) # newNodes[i].setName(targetName) except: print 'exception on:', newNodes[i] for dn in destroyList: dn.destroy() for i in range(len(newNodes)): newNodes[i].setName(targetNames[i],True) for geoNode in geoList: # find bone capture node currentRenderNode = geoNode.renderNode() captureNode = None for insideNode in geoNode.children(): # print insideNode if insideNode.type().name() == 'capture': captureNode = insideNode break if captureNode: print 'capture node:', captureNode cpNode = hou.copyNodesTo((captureNode,), geoNode)[0] cpNode.setHardLocked(False) attrCopyNode = geoNode.createNode('attribcopy') BasicFunc.connect_node(cpNode, attrCopyNode,0,0) BasicFunc.connect_node(captureNode, attrCopyNode,0,1) attrCopyNode.parm('attribname').set('*') BasicFunc.connect_node(attrCopyNode, currentRenderNode)
def ConvertJointsToBones_Hierachy(rootNode): #print 'parent:', rootNode.parent() #rootNode.parent().createNode('null','testnull') destroyList = [] stack = [] realBoneList = [] newNames = [] firstAuthority = [] subnet = rootNode.parent() stack.append(rootNode) BasicFunc.set_transform_keeppos(rootNode) while len(stack) > 0: nullNode = stack.pop() # print nullNode nodeInputs = nullNode.inputs() hierachyParent = None if nodeInputs is not None and len(nodeInputs) > 0: hierachyParent = nodeInputs[0] destroyList.append(nullNode) firstFlag = True nullNodeOutputs = nullNode.outputs() if nullNodeOutputs is not None and len(nullNodeOutputs) > 0: for child in nullNode.outputs(): BasicFunc.set_transform_keeppos(child) childTypeName = child.type().name() # print childTypeName if childTypeName == 'null': #print 'append', child stack.append(child) elif childTypeName == 'bone': #child 是替代骨骼 nodeLookAt = child.node(child.parm('lookatpath').eval()) BasicFunc.set_transform_keeppos(nodeLookAt) # create bone node and parent to origin parent realBoneNode = subnet.createNode('bone') realBoneList.append(realBoneNode) #append !!!!! newNames.append(nullNode.name()) if firstFlag: firstFlag = False firstAuthority.append(True) else: firstAuthority.append(False) realBoneNode.parm('length').set(child.parm('length').eval()) realBoneNode.setColor(hou.Color(1, 0, 0)) BasicFunc.connect_node(child, realBoneNode) BasicFunc.alignWorldPos(realBoneNode, nullNode) realBoneNode.parm('keeppos').set(True) BasicFunc.adjustLayout(realBoneNode) if hierachyParent: BasicFunc.connect_node(hierachyParent, realBoneNode) else: realBoneNode.setInput(0, None, 0) BasicFunc.connect_node(realBoneNode,nodeLookAt) destroyList.append(child) else: endBoneNode = subnet.createNode('bone') BasicFunc.connect_node(nullNode, endBoneNode) endBoneNode.parm('length').set(0) BasicFunc.adjustLayout(endBoneNode) BasicFunc.alignWorldPos(endBoneNode, nullNode) endBoneNode.parm('keeppos').set(True) realBoneList.append(endBoneNode) newNames.append(nullNode.name()) firstAuthority.append(True) for deadNode in destroyList: deadNode.destroy() for i in range(len(realBoneList)): if firstAuthority[i]: realBoneList[i].setName(newNames[i],True) else: realBoneList[i].setName(newNames[i]+'_00', True) for geoNode in subnet.children(): if geoNode.type().name() == 'geo': # find bone capture node currentRenderNode = geoNode.renderNode() captureNode = None for insideNode in geoNode.children(): # print insideNode if insideNode.type().name() == 'capture': captureNode = insideNode break if captureNode: print 'capture node:', captureNode cpNode = hou.copyNodesTo((captureNode,), geoNode)[0] cpNode.setHardLocked(False) attrCopyNode = geoNode.createNode('attribcopy') BasicFunc.connect_node(cpNode, attrCopyNode,0,0) BasicFunc.connect_node(captureNode, attrCopyNode,0,1) attrCopyNode.parm('attribname').set('*') BasicFunc.connect_node(attrCopyNode, currentRenderNode)
def DeleteBoneButKeepChildren(boneNode): BasicFunc.set_children_transform_keeppos(boneNode) boneNode.destroy()