Exemplo n.º 1
0
 def convertList_Name2Node(self, nameList):
     nodeList = []
     for nm in nameList:
         nd = rt.getNodeByName(nm)
         if rt.isValidNode(nd):
             nodeList.append(nd)
     return nodeList
Exemplo n.º 2
0
def mirrorNode(node, mirrorAxis):
    original_parent = node.GetParent()
    if MAXVERSION() < MAX2017:
        temp_mesh = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Sphere)
        temp_parent = MaxPlus.Factory.CreateNode(temp_mesh)
    else:
        temp_parent = rt.sphere()

    node.SetParent(temp_parent)

    rtNode = rt.getNodeByName(temp_parent.GetName())
    p = rt.Point3(1, 1, 1)
    if mirrorAxis == "X":
        p = rt.Point3(-1, 1, 1)
    elif mirrorAxis == "Y":
        p = rt.Point3(1, -1, 1)
    elif mirrorAxis == "Z":
        p = rt.Point3(1, 1, -1)
    else:
        print("Error axis do not match")
    rt.scale(rtNode, p)

    node.SetParent(original_parent)
    MaxPlus.INode.Delete(temp_parent) if MAXVERSION() < MAX2017 else rt.delete(
        temp_parent)
Exemplo n.º 3
0
def get_node_by_name(node_name):
    """
    Returns pymxs object of the given 3ds max node name
    :param node_name: str
    :return: pymxs object
    """

    return rt.getNodeByName(node_name)
Exemplo n.º 4
0
def getTrisCount(nodes):
    total_faces = 0
    for n in nodes:
        s = rt.getNodeByName(n.name)
        if s:
            c = rt.GetTriMeshFaceCount(s)[0]
            total_faces += c
    return total_faces
Exemplo n.º 5
0
def get_node_by_name(node_name):
    """
    Returns pymxs node object with the given name, if exists in the scene; otherwise returns None
    :param node_name: str, name of the node we want to retrieve
    :return: variant, pymxs object or None
    """

    return rt.getNodeByName(str(node_name))
Exemplo n.º 6
0
    def getBoneListFromSkinMod(self, skinMod):
        sortedBoneList = []
        boneCount = rt.skinOps.GetNumberBones(skinMod)

        # need to add one here to match the array range in max
        for i in range(1, boneCount + 1):
            n = rt.skinOps.GetBoneName(skinMod, i, 1)
            bn = rt.getNodeByName(n)
            sortedBoneList.append(bn)

        return sortedBoneList
Exemplo n.º 7
0
def createHelperBoneSystem():
    sysOption = config.SystemOption()

    regularMesh = rt.getNodeByName(sysOption.regularMeshName)
    referenceMesh = rt.getNodeByName(sysOption.referenceMeshName)

    primarySkinMod = 0

    for i in range(0, len(regularMesh.Modifiers)):
        if str(rt.classof(regularMesh.Modifiers[i])) == 'Skin':
            regularMesh.Modifiers[i].name = 'Skin_Original'
            primarySkinMod = regularMesh.Modifiers[i]
            break

    poseLearner = ln.PoseLearner(regularMesh, referenceMesh, primarySkinMod,
                                 sysOption)
    poseLearner.processStart()

    # re-select the mesh to refresh the modifiers list displaying
    rt.select(regularMesh)
Exemplo n.º 8
0
    def createHelperBoneSystem(self):
        regularMesh = rt.getNodeByName('Regular')
        referenceMesh = rt.getNodeByName('Reference')

        primarySkinMod = 0

        for i in range(0, len(regularMesh.Modifiers)):
            if str(rt.classof(regularMesh.Modifiers[i])) == 'Skin':
                regularMesh.Modifiers[i].name = "Skin_Backup"
                primarySkinMod = regularMesh.Modifiers[i]
                break

        # primaryBoneNameList = ['Bip001 L Clavicle', 'Bip001 L UpperArm', 'Bip001 L Forearm']
        primaryBoneNameList = ['Root']
        poseLearner = ln.PoseLearner(regularMesh, referenceMesh, primarySkinMod, primaryBoneNameList, self.sysOption)

        poseLearner.processStart()

        # re-select the mesh to refresh the modifiers list displaying
        rt.select(regularMesh)
Exemplo n.º 9
0
def cloneHierarchy(root, parent, func, lambda_list):
    rt_old_node = rt.getNodeByName(root.GetName())
    rt_new_node = rt.copy(rt_old_node)
    # avoid copy with default 001 prefix
    rt_new_node.name = rt_old_node.name + "_temp"
    new_node = get_node_by_name(rt_new_node.name)
    func(new_node)
    new_node.SetParent(parent)
    for l in lambda_list:
        if l is not None:
            l(new_node)

    num_children = root.GetNumChildren()
    for i in range(0, num_children):
        child = root.GetChild(i)
        cloneHierarchy(child, new_node, func, lambda_list)
Exemplo n.º 10
0
    def decodeNode(data):
        name = data["name"]
        node = rt.getNodeByName(name) if (
            MAXVERSION() >= MAX2017) else MaxPlus.INode.GetINodeByName(name)
        if not node:
            print("Node: {0} not found".format(data["name"]))
            return

        source_transform_control = sdk_utility.GetTransformControl(node)
        posController = source_transform_control.GetPositionController()
        rotController = source_transform_control.GetRotationController()
        if "positionController" in data:
            json_utility.decodePositionController(posController,
                                                  data["positionController"])
        if "rotationController" in data:
            json_utility.decodeRotationController(rotController,
                                                  data["rotationController"])
Exemplo n.º 11
0
def create_box_control(name, init_pos=None, length=10, width=10, height=10, color=None):
    """
    Creates a box control
    :param name: str
    :param init_pos:
    :param length:
    :param width:
    :param height:
    :param color:
    :return:
    """

    pos = init_pos or [0, 0, 0]
    if rt.classOf(pos) != rt.Point3:
        pos = rt.Point3(*pos)
    if color and rt.classOf(color) != rt.color:
        color = rt.color(*color)
    if not color:
        color = rt.yellow

    rt.setCommandPanelTaskMode(rt.Name('modify'))
    base_box = rt.Box(
        lengthsegs=1, widthsegs=1, heightsegs=1, length=length, width=width, height=height,
        mapcoords=True, pos=pos, isSelected=True)
    rt.select(base_box)
    rt.convertTo(base_box, rt.PolyMeshObject)
    rt.subobjectLevel = 2
    edge_bitarray = rt.BitArray()
    edge_indices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
    edge_bitarray.count = len(edge_indices)
    for i, index in enumerate(edge_indices):
        edge_bitarray[i] = index
    base_box.EditablePoly.SetSelection(rt.Name('Edge'), edge_bitarray)
    ctrl_name = rt.uniquename(name)
    base_box.EditablePoly.createShape(ctrl_name, False, base_box)
    rt.subobjectLevel = 0
    rt.delete(base_box)
    box_ctrl = rt.getNodeByName(ctrl_name)
    rt.convertTo(box_ctrl, rt.SplineShape)
    box_ctrl.wirecolor = color
    rt.CenterPivot(box_ctrl)
    transform.reset_xform_and_collapse(box_ctrl, freeze=True)

    return box_ctrl
Exemplo n.º 12
0
def load_and_verify():
    """Load and verify scene_with_app_chunk.max"""
    rt.resetMaxFile(rt.Name('noPrompt'))
    rt.loadMaxFile("scene_with_app_chunk.max")
    print("scene with AppChunk is loaded.")
    # Find the "MyTeapot123" node
    teapot_node = rt.getNodeByName("MyTeapot123")

    if teapot_node is None:
        print("Error: Incorrect saved scene.")
    else:
        print(rt.getAppData(teapot_node, 678))
        obj = teapot_node.baseObject
        print(rt.getAppData(obj, 1234))
        print(rt.getAppData(obj, 2345))
        rt.clearAllAppData(obj)
        print("No 9432 app data {}".format(rt.getAppData(obj, 9432) is None))
        print("No 7890 app data {}".format(rt.getAppData(teapot_node, 9432) is None))
        print(rt.getAppData(teapot_node.Material, 4567))
Exemplo n.º 13
0
def learnMotion():
    sysOption = config.SystemOption()

    learningBoneList = []
    referenceBoneList = []

    for nd in rt.helpers:
        pattern = re.compile(sysOption.helperBonePrefix + ".*")
        if pattern.match(nd.Name):
            learningBoneList.append(nd)

    for bnName in sysOption.tempReferenceBoneList:
        bn = rt.getNodeByName(bnName)
        referenceBoneList.append(bn)

    motionLearner = ln.MotionLearner(learningBoneList, referenceBoneList,
                                     sysOption)

    motionLearner.processStart()
Exemplo n.º 14
0
    def getOneVertBoneAndWeight(self, vertexIndex, originalSkinMod):
        outBonesList = []
        outWeightList = []

        vertexBoneCount = rt.skinOps.GetVertexWeightCount(originalSkinMod, vertexIndex+1)

        # if original bones is in the list, then it takes the priority to be added
        for b in range(0, vertexBoneCount):
            vertexWeightBoneID = rt.skinOps.GetVertexWeightBoneID(originalSkinMod, vertexIndex + 1, b + 1)
            boneName = rt.skinOps.GetBoneName(originalSkinMod, vertexWeightBoneID, 0)
            weight = rt.skinOps.GetVertexWeight(originalSkinMod, vertexIndex + 1, b + 1)

            boneNode = rt.getNodeByName(boneName)

            outBonesList.append(boneNode)
            outWeightList.append(weight)

        outBonesList, outWeightList = self.sortBonesByWeight(outBonesList, outWeightList, isReversed=True)

        return outBonesList, outWeightList
Exemplo n.º 15
0
    def startTransfer(self):
        mxs.execute("max create mode")

        with pymxs.undo(True):

            for i in self.skinMeshes:
                skinSource = mxs.skinUtils.ExtractSkinData(i[0])
                skinSource = mxs.getNodeByName("SkinData_{}".format(i[0].name))

                count = mxs.skinOps.GetNumberBones(i[1])
                newBones = []

                for item in range(count):
                    # print(item +1, i[0].name, mxs.skinOps.GetBoneNode(i[1], item + 1))
                    try:
                        newBones.append(self.dict[mxs.skinOps.GetBoneNode(
                            i[1], item + 1)])
                    except:
                        pass

                oldSkin = i[1]
                oldSkin.enabled = False

                skinMod = mxs.Skin()
                skinMod.name = "Transfered Skin"

                mxs.addModifier(i[0], skinMod, before=i[2] - 1)

                for bone in newBones:
                    mxs.skinOps.addbone(skinMod, bone, 0)

                mxs.select(i[0])
                mxs.selectmore(skinSource)
                mxs.skinUtils.ImportSkinDataNoDialog(True, False, False, False,
                                                     False, 1.0, 0)

                mxs.delete(skinSource)
                mxs.clearSelection()

        mxs.execute("max modify mode")
Exemplo n.º 16
0
    def __init__(self):
        return

    def assignPositionScriptConstraint(self, obj, constantNameList, constantValueList, targetNodeList, scripts):
        posScriptConstraint = mp.Factory.CreatePositionController(mp.ClassIds.position_script)
        print posScriptConstraint.Script
        objINode = mp.INode.GetINodeByHandle(obj.handle)

        for nd in targetNodeList:
            targetINode = mp.INode.GetINodeByHandle(nd.handle)
            posScriptConstraint.SetTarget (targetINode)

        objTMController = objINode.GetTMController()
        print (type(objTMController))
        objTMController.SetPositionController(posScriptConstraint)

        sourceINodeList = []
        # for srcNode in targetNodeList:
        #     newSrcINode = mp.INode.GetINodeByHandle(srcNode.handle)
        #     sourceINodeList.append(newSrcINode)
        #     objTMController.AddObject (srcNode.name, newSrcINode)



constraintSetter = ConstraintSetter()
obj = rt.getNodeByName('Point001')
constantNameList = ['a','b']
constantValueList = [1,2]
sourceNodeList = [rt.getNodeByName('target')]
script = ''
constraintSetter.assignPositionScriptConstraint(obj, constantNameList, constantValueList, sourceNodeList, script)
Exemplo n.º 17
0
def collapseAllModifiers(node):
    """Collapses modifier stack.
    """
    rtNode = rt.getNodeByName(node.GetName())
    rt.collapseStack(rtNode)
Exemplo n.º 18
0
 def mxNode(self):
     obj = rt.getNodeByName(self._name)
     return obj
Exemplo n.º 19
0
def get_node_by_name(name):
    if MAXVERSION() < MAX2017:
        return MaxPlus.INode.GetINodeByName(name)
    else:
        return rt.getNodeByName(name)