Ejemplo n.º 1
0
def gear_SmoothWeightMapPoints_Execute():

    if xsi.Selection.Count < 2:
        gear.log("Select some points and a weight map", gear.sev_error)
        return

    pntSubComp = xsi.Selection(0)
    wmap = xsi.Selection(1)

    # Check  if input doesn't match
    if pntSubComp.Type not in ["pntSubComponent"] or wmap.Type not in ["wtmap"]:
        gear.log("Invalid selection", gear.sev_error)
        return

    # Get Arrays
    clsElements = wmap.Parent.Elements
    points = [clsElements.FindIndex(i) for i in pntSubComp.SubComponent.ElementArray if clsElements.FindIndex(i) != -1]

    obj = pntSubComp.SubComponent.Parent3DObject
    cls = obj.ActivePrimitive.Geometry.AddCluster(c.siVertexCluster, "gear_SmoothWeightMapPointsOp_Cls", points )

    # Apply Operator
    op = XSIFactory.CreateObject("gear_SmoothWeightMapPointsOp")

    op.AddIOPort(wmap)
    op.AddInputPort(wmap.Parent3DObject.ActivePrimitive)
    op.AddInputPort(cls)

    op.Connect(None, c.siConstructionModeModeling)

    xsi.InspectObj(op)
Ejemplo n.º 2
0
def gear_SymWeightMapPoints_Execute():

  if xsi.Selection.Count < 2:
      gear.log("Select some points and a weight map", gear.sev_error)
      return

  pntSubComp = xsi.Selection(0)
  wmap = xsi.Selection(1)

  # Check  if input doesn't match
  if pntSubComp.Type not in ["pntSubComponent"] or wmap.Type not in ["wtmap"]:
      gear.log("Invalid selection", gear.sev_error)
      return

  # Get Symmetry Map
  symMap = uti.getSymmetryMap(wmap.Parent3DObject)
  if not symMap:
      return

  # Get Arrays
  points = pntSubComp.SubComponent.ElementArray
  weights = [w for w in wmap.Elements.Array[0]]
  sym_array = symMap.Elements.Array

  # Process
  for i in points:
      weights[int(sym_array[0][i])] = weights[i]

  wmap.Elements.Array = weights
Ejemplo n.º 3
0
def gear_crvLenInfo_Execute():

    if not xsi.Selection.Count and xsi.Selection(0).Type == "crvlist":
        gear.log("No selection or first selected object not a crvlist",
        gear.sev_error)
        return

    crv = xsi.Selection(0)
    prop = xsi.gear_PSet_Apply(crv, "Length_Info", False, False )
    pLength = prop.AddParameter3( "Length", c.siDouble, 0, -1000000, 1000000 )
    pOriginalLength = prop.AddParameter3( "Original_Length", c.siDouble, 0, -1000000, 1000000, False, True )
    pLengthRatio = prop.AddParameter3( "Length Ratio", c.siDouble, 0, -1000000, 1000000 )

    layout = r"""layout.AddTab('Length_Info');\
        layout.AddGroup('Default Layout');\
        item = layout.AddItem('Length', 'Length', None);\
        item = layout.AddItem('Original_Length', 'Original_Length', None);\
        item = layout.AddItem('Length_Ratio', 'Length_Ratio', None);\
        layout.EndGroup()"""

    prop.Parameters("layout").Value = layout
    aop.sn_curvelength_op(pLength.FullName, crv)
    pOriginalLength.Value = pLength.Value
    pLengthRatio.AddExpression( pLength.FullName +  "/" + pOriginalLength.FullName)
    xsi.InspectObj(prop)
Ejemplo n.º 4
0
def gear_ApplyZipperOp_Execute():

    if xsi.Selection.Count < 2:
        gear.log("Select 2 curve", gear.sev_error)
        return

    crv_A = xsi.Selection(0)
    crv_B = xsi.Selection(1)

    if crv_A.Type not in ["crvlist"] or crv_B.Type not in ["crvlist"]:
        gear.log("Select 2 curve", gear.sev_error)
        return

    # Apply Operator ----------------------
    op = XSIFactory.CreateObject("gear_ZipperOp")

    op.AddIOPort(crv_A.ActivePrimitive)
    op.AddIOPort(crv_B.ActivePrimitive)

    pStart_fcv = op.Parameters("Start_FCurve").Value
    fcv.drawFCurve(pStart_fcv, [[0, 0], [1, 1]], c.siLinearKeyInterpolation)

    pSpeed_fcv = op.Parameters("Speed_FCurve").Value
    fcv.drawFCurve(pStart_fcv, [[0, 0], [1, 1]], c.siLinearKeyInterpolation)

    op.Connect()

    xsi.InspectObj(op)

    return op
Ejemplo n.º 5
0
def gear_ResetWeightMapPoints_Execute():

    if xsi.Selection.Count < 2:
        gear.log("Select some points and a weight map", gear.sev_error)
        return

    pntSubComp = xsi.Selection(0)
    wmap = xsi.Selection(1)

    # Check  if input doesn't match
    if pntSubComp.Type not in ["pntSubComponent"] or wmap.Type not in ["wtmap"]:
        gear.log("Invalid selection", gear.sev_error)
        return

    wei.resetWeightMapPoints(wmap, pntSubComp.SubComponent.ElementArray)
Ejemplo n.º 6
0
def gear_NormalizeWeights_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    sel = xsi.Selection(0)

    if sel.Type in ["polymsh", "surfmsh", "crvlist"]:
        mesh = sel
        points = range(mesh.ActivePrimitive.Geometry.Points.Count)
    elif sel.Type == "pntSubComponent":
        mesh = sel.SubComponent.Parent3DObject
        points = sel.SubComponent.ElementArray
    else:
        gear.log("Invalid selection", gear.sev_error)
        return

    # Get Envelope from object
    envelope_op = ope.getOperatorFromStack(mesh, "envelopop")
    if not envelope_op:
        gear.log("There is no envelope on selected mesh", gear.sev_error)
        return

    # Process
    points = env.getUnnormalizedPoints(envelope_op, points)
    if not env.normalizeWeights(envelope_op, points):
        return

    env.freezeEnvelope(envelope_op)
    env.rebuiltEnvelope(envelope_op)
Ejemplo n.º 7
0
def gear_ExportObject_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    # -----------------------------------------------------
    # Getting the file path
    path = uit.fileBrowser("Export Object", xsi.ActiveProject2.OriginPath,
                           xsi.Selection(0).Name + "_skin.xml", ["xml"], True)
    if not path:
        return

    xsixmldom.resetOptions()
    xObject = xsixmldom.getObject(xsi.Selection(0))
    xObject.save(path)
Ejemplo n.º 8
0
def gear_GuideToolsUI_import_OnClicked():

    if not os.path.exists(PPG.templateList.Value):
        return

    parent = xsi.Selection(0)
    if parent is not None and not parent.IsClassOf(c.siX3DObjectID):
        gear.log("Invalid Parent Selected", gear.sev_error)
        return

    if parent is not None:
        if parent.Type == "#model":
            target_model = parent
        else:
            target_model = parent.Model

        if not target_model.Properties("options"):
            gear.log("Invalid Parent Selected", gear.sev_error)
            return

    # import guide
    rg = RigGuide()
    model = rg.importFromXml(PPG.templateList.Value)

    if parent is not None:
        for child in model.children:
            if child.Name not in ["controlers_org"]:
                parent.AddChild(child)

        for group in model.Groups:
            if target_model.Groups(group.Name):
                target_model.Groups(group.Name).AddMember(group.Members)

        xsi.DeleteObj(model)
Ejemplo n.º 9
0
def gear_ApplyZipperOp_Execute():

    if xsi.Selection.Count < 2:
        gear.log("Select 2 curve", gear.sev_error)
        return

    crv_A = xsi.Selection(0)
    crv_B = xsi.Selection(1)

    if crv_A.Type not in ["crvlist"] or crv_B.Type not in ["crvlist"]:
        gear.log("Select 2 curve", gear.sev_error)
        return
    else:
        op =  aop.gear_zipper_op( crv_A, crv_B)

    xsi.InspectObj(op)
Ejemplo n.º 10
0
    def buildFromSelection(self):

        # Cet the option first otherwise the change wight might do won't be taken
        sel = xsi.Selection(0)
        if sel.Type == "#model":
            guide_model = sel
        else:
            guide_model = sel.Model
        guide_options = guide_model.Properties("options")
        if not guide_options:
            gear.log("Can't generate rig, invalid model selected",
                     gear.sev_error)
            return

        rtn = xsi.InspectObj(guide_options, "", "Options", c.siModal, False)
        if rtn:
            return False

        # Check guide is valid
        self.guide.setFromSelection()
        if not self.guide.valid:
            return

        # Build
        self.build()
Ejemplo n.º 11
0
def gear_Renamer_Apply_OnClicked():

    grid_data = PPG.PreviewGrid.Value

    if grid_data.RowCount:
        for i in range(grid_data.RowCount):

            row_values = grid_data.GetRowValues(i)

            obj = xsi.Dictionary.GetObject(row_values[0] + "." + row_values[1])
            obj.Name = row_values[2]

            if PPG.EditMode.Value == 3:
                if obj.Type == "root":
                    obj.primary_icon.Value = PPG.rootIcon.Value
                if obj.Type == "eff":
                    obj.primary_icon.Value = PPG.effIcon.Value

                obj.size.Value = PPG.size.Value

    else:
        for i in range(xsi.Selection.Count):

            sel = xsi.Selection(i)
            sel.Name = rename(PPG, sel.Name, i)

    grid_data.RowCount = 0

    PPG.Refresh()
Ejemplo n.º 12
0
def gear_SymmetrizePoints_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    pntSubComp = xsi.Selection(0)
    if pntSubComp.Type not in ["pntSubComponent"]:
        gear.log("Invalid Selection, need a pntSubComponent", gear.sev_error)
        return

    obj = pntSubComp.SubComponent.Parent3DObject

    # Get Symmetry Map -------------------
    sym_map = uti.getSymmetryMap(obj)
    if not sym_map:
        gear.log("There is no symmetry map on selected object", gear.sev_error)
        return

    cls = obj.ActivePrimitive.Geometry.AddCluster(
        c.siVertexCluster, "gear_SymmetrizePointsOp_cls",
        pntSubComp.SubComponent.ElementArray)

    # Apply Operator ----------------------
    op = XSIFactory.CreateObject("gear_SymmetrizePointsOp")

    op.AddIOPort(obj.ActivePrimitive)
    op.AddInputPort(sym_map)
    op.AddInputPort(cls)

    op.Connect()

    xsi.InspectObj(op)

    return op
Ejemplo n.º 13
0
def gear_SymmetrizeSelection_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    subComp = xsi.Selection(0)
    if subComp.Type not in [
            "pntSubComponent", "edgeSubComponent", "polySubComponent"
    ]:
        gear.log("Invalid Selection", gear.sev_error)
        return

    elements = subComp.SubComponent.ElementArray
    mesh = subComp.SubComponent.Parent3DObject

    mirror_elements = geo.getSymSubComponent(elements, subComp.Type, mesh)
    if not mirror_elements:
        return

    points = []
    points.extend(elements)
    points.extend(mirror_elements)

    sub_type = subComp.Type.replace("SubComponent", "")
    xsi.SelectGeometryComponents(mesh.FullName + "." + sub_type + str(points))
Ejemplo n.º 14
0
def gear_SelectUnnormalizedPoints_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    mesh = xsi.Selection(0)

    # Check input
    if mesh.Type not in ["polymsh", "crvlist", "surfmsh"]:
        gear.log("Invalid selection", gear.sev_error)
        return

    # Get Envelope
    envelope_op = ope.getOperatorFromStack(mesh, "envelopop")
    if not envelope_op:
        gear.log("There's no envelope on " + mesh.Fullname, gear.sev_error)
        return

    unNormPntId = env.getUnnormalizedPoints(envelope_op)

    # Select Pnt
    if unNormPntId:
        gear.log("There is " + str(len(unNormPntId)) +
                 " unnormalized point(s)")
        gear.log(mesh.FullName + ".pnt" + str(unNormPntId))
        xsi.SelectGeometryComponents(mesh.FullName + ".pnt" + str(unNormPntId))
    else:
        gear.log("There is no unnormalized point", gear.sev_warning)
Ejemplo n.º 15
0
def gear_CopyWeightsAverage_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    sel = xsi.Selection(0)

    # Check input
    if sel.Type not in ["pntSubComponent"]:
        gear.log("Invalid selection", gear.sev_error)
        return

    target_point = sel.SubComponent.ElementArray

    obj = sel.SubComponent.Parent3DObject
    envelope_op = ope.getOperatorFromStack(obj, "envelopop")
    if not envelope_op:
        gear.log("There is no envelope on selected mesh", gear.sev_error)
        return

    # Pick Session
    source_points = []
    while True:
        source_pnt = uit.pickSession(c.siPointFilter, "Pick Source Point",
                                     False)
        if not source_pnt:
            break

        source_points.extend(source_pnt.SubComponent.ElementArray)

    if not source_points:
        gear.log("No Points Selected", gear.sev_error)
        return

    # Get Weights
    weights_tuple = envelope_op.Weights.Array
    weights = [
        weights_tuple[j][i] for i in range(len(weights_tuple[0]))
        for j in range(len(weights_tuple))
    ]
    deformer_count = envelope_op.Deformers.Count

    # Array of average value of weights
    avr_weights = [0] * deformer_count
    for point_index in source_points:
        for deformer_index in range(deformer_count):
            avr_weights[deformer_index] += weights_tuple[deformer_index][
                point_index] / len(source_points)

    # Replace Weights in Weight Array
    for point_index in target_point:
        for deformer_index in range(deformer_count):
            weights[point_index * deformer_count +
                    deformer_index] = avr_weights[deformer_index]

    envelope_op.Weights.Array = weights

    return
Ejemplo n.º 16
0
def gear_MatchSR_Execute():

    source_object = xsi.Selection(0)
    target_object = uit.pickSession()
    if not target_object:
        return

    tra.matchGlobalTransform(source_object, target_object, False, True, True)
Ejemplo n.º 17
0
def gear_SymShapePoints_Execute():

    if xsi.Selection.Count < 2:
        gear.log("Select first the point and then the shape", gear.sev_error)
        return

    pntSubComp = xsi.Selection(0)
    shape = xsi.Selection(1)

    # Check  if input doesn't match
    if pntSubComp.Type not in ["pntSubComponent"
                               ] or shape.Type not in ["clskey"]:
        gear.log("Invalid selection", gear.sev_error)
        return

    points = pntSubComp.SubComponent.ElementArray

    sha.symmetrizeShapePoints(shape, points)
Ejemplo n.º 18
0
def gear_CurveSlide2Op_Execute():

    if not xsi.Selection.Count or xsi.Selection(0).Type not in ["crvlist"]:
        gear.log("No selection or invalid Selection", gear.sev_error)
        return

    out_crv = xsi.Selection(0)

    if out_crv.ActivePrimitive.Geometry.Curves.Count > 1:
        gear.log("Curve Resampler works only with single curve", gear.sev_error)
        return

    in_crv = uit.pickSession(c.siCurveFilter, "Pick Reference Curve", True)
    if not in_crv:
        return

    op = aop.sn_curveslide2_op(out_crv, in_crv)

    xsi.InspectObj(op)
Ejemplo n.º 19
0
def gear_CurveResampler_Execute():

    if not xsi.Selection.Count or xsi.Selection(0).Type not in ["crvlist"]:
        gear.log("No selection or invalid Selection", gear.sev_error)
        return

    curve = xsi.Selection(0)
    if curve.ActivePrimitive.Geometry.Curves.Count > 1:
        gear.log("Curve Resampler works only with single curve",
                 gear.sev_error)
        return

    ref_crv = uit.pickSession(c.siCurveFilter, "Pick Reference Curve", False)
    if not ref_crv:
        ref_crv = curve

    op = aop.gear_resampler_op(curve, ref_crv, 0, 1)

    xsi.InspectObj(op)
Ejemplo n.º 20
0
def gear_GuideToolsUI_draw_OnClicked():

    if not PPG.componentList.Value:
        gear.log("There is no component selected in the list", gear.sev_error)
        return

    compType = PPG.componentList.Value

    rg = RigGuide()
    g = rg.drawNewComponent(xsi.Selection(0), compType)
Ejemplo n.º 21
0
def gear_PSet_Debug_Execute():

    prop = xsi.Selection(0)

    if not prop or not prop.Parameters("debug"):
        gear.log("Select a gear_PSet", gear.sev_error)
        return

    # Set the debug mode
    prop.Parameters("debug").Value = True
Ejemplo n.º 22
0
def gear_CreateMirrorTemplate_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    model = xsi.Selection(0).Model
    cnx_prop = ani.createMirrorCnxTemplate(model, xsi.Selection)

    xsi.InspectObj(cnx_prop)
Ejemplo n.º 23
0
def gear_SmoothShapePoints_Execute():

    if xsi.Selection.Count < 2:
        gear.log("Select first the point and then the shape", gear.sev_error)
        return

    pntSubComp = xsi.Selection(0)
    shape = xsi.Selection(1)

    # Check  if input doesn't match
    if pntSubComp.Type not in ["pntSubComponent"
                               ] or shape.Type not in ["clskey"]:
        gear.log("Invalid selection", gear.sev_error)
        return

    points = pntSubComp.SubComponent.ElementArray

    op = sha.applySmoothShapeOp(shape, points)

    xsi.InspectObj(op)
Ejemplo n.º 24
0
def gear_XformSpring_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    out = xsi.Selection(0)

    op = aop.sn_xfspring_op(out, mode=2)

    xsi.InspectObj(op)
Ejemplo n.º 25
0
def gear_MatchT_Execute():

    if not xsi.Selection.Count:
        gear.log("No Selection", gear.sev_error)
        return

    source_object = xsi.Selection(0)
    target_object = uit.pickSession()
    if not target_object:
        return

    tra.matchGlobalTransform(source_object, target_object, True, False, False)
Ejemplo n.º 26
0
def gear_CopyWeights_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    sel = xsi.Selection(0)

    # Check input
    if sel.Type not in ["pntSubComponent"]:
        gear.log("Invalid selection", gear.sev_error)
        return

    obj = sel.SubComponent.Parent3DObject
    envelope_op = ope.getOperatorFromStack(obj, "envelopop")
    if not envelope_op:
        gear.log("There is no envelope on selected mesh", gear.sev_error)
        return

    cls = obj.ActivePrimitive.Geometry.AddCluster(
        c.siVertexCluster, "gear_CopyWeightsOp_Cls",
        sel.SubComponent.ElementArray)

    # Pick Session
    source_pnt = uit.pickSession(c.siPointFilter, "Pick Source Point", True)
    if not source_pnt:
        return

    points = source_pnt.SubComponent.ElementArray
    if len(points) != 1:
        gear.log("Please Select Only One Point", gear.sev_error)
        return

    # Need to find the cluster
    for port in envelope_op.InputPorts:
        if port.Target2.Type == "envweights":
            env_cls = port.Target2

    if not env_cls:
        gear.log("Invalid Envelop, no cluster was found", gear.sev_error)
        return

    # Apply Operator ----------------------
    op = XSIFactory.CreateObject("gear_CopyWeightsOp")

    op.AddIOPort(env_cls)
    op.AddInputPort(cls)
    op.Index = points[0]
    op.Connect()

    xsi.InspectObj(op)

    return op
Ejemplo n.º 27
0
def gear_ExportGuide_Execute():

    if not xsi.Selection.Count:
        xsi.LogMessage("Select an object from the guide to export", c.siError)
        return

    if xsi.Selection(0).Type == "#model":
        model = xsi.Selection(0)
    else:
        model = xsi.Selection(0).Model

    options = model.Properties("options")
    if not options:
        gear.log("Invalid selection", gear.sev_error)
        return

    path = uit.fileBrowser("Export Guide", xsi.ActiveProject2.OriginPath, model.Name, ["xml"], True)
    if not path:
        return

    rg = RigGuide()
    rg.exportToXml(xsi.Selection(0), path)
Ejemplo n.º 28
0
def gear_PruneWeights_Execute():

    if not xsi.Selection.Count:
        gear.log("No selection", gear.sev_error)
        return

    sel = xsi.Selection(0)

    if sel.Type in ["polymsh", "surfmsh", "crvlist"]:
        mesh = sel
        points = range(mesh.ActivePrimitive.Geometry.Points.Count)
#    elif sel.Type == "pntSubComponent":
#        mesh = sel.SubComponent.Parent3DObject
#        points = sel.SubComponent.ElementArray
    else:
        gear.log("Invalid selection", gear.sev_error)
        return

    # Get Envelope from object
    envelope_op = ope.getOperatorFromStack(mesh, "envelopop")
    if not envelope_op:
        gear.log("There is no envelope on selected mesh", gear.sev_error)
        return

    # PPG for Options
    prop = xsi.ActiveSceneRoot.AddProperty("CustomProperty", False,
                                           "gear_PruneWeights")
    pThreshold = prop.AddParameter3("Threshold", c.siDouble, .1, 0, None,
                                    False, False)
    pRemove = prop.AddParameter3("RemoveDeformers", c.siBool, True, None, None,
                                 False, False)

    layout = prop.PPGLayout
    layout.AddGroup("Prune")
    layout.AddItem(pThreshold.ScriptName, "Weights Threshold")
    layout.AddItem(pRemove.ScriptName, "Remove Unused Deformers")
    layout.EndGroup()

    rtn = xsi.InspectObj(prop, "", "Prune Weights", c.siModal, False)

    threshold = pThreshold.Value
    remove = pRemove.Value

    xsi.DeleteObj(prop)

    if rtn:
        return

    # Process
    env.pruneWeights(envelope_op, points, threshold, remove, True)
Ejemplo n.º 29
0
def gear_poseLibManager_removePose_OnClicked():
    oSel = xsi.Selection(0)
    if oSel and oSel.Type == "customparamset":
        oParam = oSel.Parameters("poseEditList")
        if oParam:
            currPose = oSel.Parameters("poseEditList").Value.split(";")
            setName = oSel.Name
            xsi.DeleteObj(oSel)
            gear_poseLibManager_createPoseSet_OnClicked(currPose , setName, True)

        else:
            lm("The custom paramenter set selected is not a Pose Set", 4)
    else:
        lm("Select a custom paramenter set", 4)
Ejemplo n.º 30
0
def gear_InspectGuideSettings_Execute():
    if xsi.Selection.Count:
        oSel = xsi.Selection(0)
        settings = False
        while not settings :
            if oSel.Properties("settings"):
                settings = oSel.Properties("settings")
                xsi.InspectObj(settings)
            else:
                oSel = oSel.Parent
                if oSel.Type == "#model":
                    settings = True
                    lm("The selected object is not part of a guide, or the guide do not have settings", 4)
    else:
        lm("Nothing selected. Please select an object from a GEAR guide", 4)