def gear_ApplySpinePointAtOp_Execute(): start_obj = uit.pickSession(c.siGenericObjectFilter, "Pick Start Reference", True) if not start_obj: return end_obj = uit.pickSession(c.siGenericObjectFilter, "Pick End Reference", True) if not end_obj: return count = xsi.Selection.Count+0.0 operators = [] for i, sel in enumerate(Application.Selection): path_cns = False for cns in sel.Kinematics.Constraints: if cns.Type in ["crvcns", "pathcns"]: path_cns = cns break if not path_cns: gear.log("There is no path or curve constraint on this object : %s"%sel.Name, gear.sev_warning) continue blend = i/count op = aop.spinePointAtOp(cns, start_obj, end_obj, blend) operators.append(op) xsi.InspectObj(operators)
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()
def inspect(prop, width=None, height=None, posx=None, posy=None): # If no size define we just do a simple inspect obj if width is None or height is None: xsi.InspectObj(prop) return # Get the screen resolution to position the window screen_width, screen_height = scr.getResolution() if posx is None: posx = int((screen_width / 2.0) - (width / 2.0)) elif posx < 0: posx = int(screen_width + posx) if posy is None: posy = int((screen_height / 2.0) - (height / 2.0)) elif posy < 0: posy = int(screen_height + posy) view = xsi.Desktop.ActiveLayout.CreateView("Property Panel", prop.Name) view.BeginEdit() view.Move(posx, posy) view.Resize(width, height) view.SetAttributeValue("targetcontent", prop.FullName) view.EndEdit()
def getObjectDefinitions(path, inputs, ui=False): items, xml_objs = getObjectItems(path) objects = [] for obj in inputs: if obj.Type in ["pntSubComponent"]: objects.append(obj.SubComponent.Parent3DObject) else: objects.append(obj) # ----------------------------------------------------- # Check if we need the UI defs = {} if ui: if not [False for obj in objects if obj.Name not in items]: ui = False else: prop = xsi.ActiveSceneRoot.AddProperty("CustomProperty", False, "ImportEnvelope") layout = prop.PPGLayout layout.AddGroup("Select Object Reference") params = {} for obj in objects: if obj.Name in items: param = prop.AddParameter3("def_%s" % obj.Name, c.siString, obj.Name) else: param = prop.AddParameter3("def_%s" % obj.Name, c.siString, "0") params[obj.name] = param layout.AddEnumControl(param.ScriptName, items, obj.Name, c.siControlCombo) layout.EndGroup() rtn = xsi.InspectObj(prop, "", "Import Envelope", c.siModal, False) for obj in objects: if params[obj.Name].Value != "0": defs[obj.Name] = xml_objs[params[obj.Name].Value] xsi.DeleteObj(prop) if rtn: return False if not ui: for obj in objects: if obj.Name in xml_objs.keys(): defs[obj.Name] = xml_objs[obj.Name] else: gear.log("No defintion found for %s" % obj.Name, gear.sev_warning) return defs
def gear_CreateSplineKine_Execute(): if xsi.Selection.Count < 2: gear.log("Select at least two objects", gear.sev_error) return controlers = [obj for obj in xsi.Selection] # ----------------------------------------------------- # UI prop = xsi.ActiveSceneRoot.AddProperty("CustomProperty", False, "SplineKineOptions") pDivision = prop.AddParameter3("division", c.siInt4, 10, 1, None, False, False) rtn = xsi.InspectObj(prop, "", "Spline Kine Options", c.siModal, False) div_count = pDivision.Value xsi.DeleteObj(prop) if rtn: return # ----------------------------------------------------- # Create Parent property to connect the multiple operators parameters prop = controlers[0].Properties("gear_splinekine_options") if not prop: prop = controlers[0].AddProperty("CustomProperty", False, "gear_splinekine_options") prop.AddParameter3("resample", c.siBool, True, None, None, True, False) prop.AddParameter3("subdiv", c.siInt4, 10, 3, 50, True, False) prop.AddParameter3("absolute", c.siBool, False, None, None, True, False) # ----------------------------------------------------- for i in range(div_count): div = controlers[0].AddNull("div_%s" % i) pri.setNullDisplay(div, 4, .5) op = aop.sn_splinekine_op(div, controlers, i / (div_count - 1.0)) for s in ["resample", "subdiv", "absolute"]: op.Parameters(s).AddExpression(prop.Parameters(s)) xsi.InspectObj(prop)
def gear_InspectSolvers_Execute(): if xsi.Selection.Count: try: xsi.InspectObj(".Kine.Global.sn_*") except: lm("Any of the selected objects have GEAR,s 'sn_solver' solvers", 2)
def gear_MirrorAnimation_Execute(): # controlers if not xsi.Selection.Count: gear.log("No selection", gear.sev_error) return ## Miquel Shed added: else: controlers = XSIFactory.CreateActiveXObject("XSI.Collection") controlers.AddItems(xsi.Selection) ##end of the addition # Get First and Last Frame frames = fcv.getFirstAndLastKey(controlers) if not frames: gear.log("No Key on selection, cannot perform mirror animation", gear.sev_error) return # UI ui_prop = xsi.ActiveSceneRoot.AddProperty("CustomProperty", False, "Mirror Animation") pOffset = ui_prop.AddParameter3("offset", c.siInt4, 0, None, None, False, False) pConsiderTime = ui_prop.AddParameter3("considerTime", c.siBool, False, None, None, False, False) pFrameIn = ui_prop.AddParameter3("frameIn", c.siInt4, frames[0], None, None, False, False) pFrameOut = ui_prop.AddParameter3("frameOut", c.siInt4, frames[1], None, None, False, False) layout = ui_prop.PPGLayout layout.AddGroup("Options") layout.AddItem(pOffset.ScriptName, "Offset") layout.AddItem(pConsiderTime.ScriptName, "Consider Time") layout.AddRow() layout.AddItem(pFrameIn.ScriptName, "Frame In") layout.AddItem(pFrameOut.ScriptName, "Frame Out") layout.EndRow() layout.EndGroup() rtn = xsi.InspectObj(ui_prop, "", "Mirror Animation", c.siModal, False) frame_offset = pOffset.Value considerTime = pConsiderTime.Value frame_in = pFrameIn.Value frame_out = pFrameOut.Value xsi.DeleteObj(ui_prop) if rtn: return # Mirror ani.mirror(controlers, True, frame_offset, considerTime, frame_in, frame_out) return
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)
def plotSpringToControler(comp_name, prop): # Get objects model = prop.Model refs = [] ctls = [] i = 0 while True: ctl = model.FindChild(comp_name + "_fk%s_ctl" % i) ref = model.FindChild(comp_name + "_%s_ref" % i) if not ctl or not ref: break ctls.append(ctl) refs.append(ref) i += 1 # UI pc = ani.PlayControl() ui_prop = xsi.ActiveSceneRoot.AddProperty("CustomProperty", False, "Plot") pStartFrame = ui_prop.AddParameter3("start_frame", c.siInt4, pc.localIn.Value, None, None) pEndFrame = ui_prop.AddParameter3("end_frame", c.siInt4, pc.localOut.Value, None, None) rtn = xsi.InspectObj(ui_prop, "", "Plot", c.siModal, False) start_frame = pStartFrame.Value end_frame = pEndFrame.Value xsi.DeleteObj(ui_prop) if rtn: return # Plot params = [ ref.Kinematics.Local.Parameters("rot" + s).FullName for ref in refs for s in "xyz" ] action = xsi.PlotAndApplyActions(",".join(params), "plot", start_frame, end_frame, 1, 20, 3, False, .01, True, False, False, False)(0) # Edit the stored Action for item in action.SourceItems: item.Target = item.Target.replace(comp_name + "_", comp_name + "_fk") item.Target = item.Target.replace("_ref", "_ctl") prop.Parameters(comp_name + "_main_blend").Value = 0 xsi.ApplyAction(action) xsi.DeleteObj(action)
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)
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
def gear_MergeWithClusters_Execute(): if not xsi.Selection.Count: gear.log("No selection", gear.sev_error) return objects = [obj for obj in xsi.Selection if obj.Type in ["polymsh"]] if len(objects) < 2: gear.log("Not enough object to perform action. Make sure you have selected enough polymesh", gear.sev_error) return op = geo.mergeWithClusters(objects) xsi.InspectObj(op)
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)
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)
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)
def gear_MatchGeometry_Execute(): if not xsi.Selection.Count: gear.log("No selection", gear.sev_error) return target = xsi.Selection(0) if target.Type not in ["pntSubComponent", "polymsh", "surfmsh", "crvlist"]: gear.log("Invalid Selection, select a geometry or a point selection", gear.sev_error) return # Get reference source = uit.pickSession(c.siGenericObjectFilter, "Pick Source Geometry") if not source: return # Get cluster if target.Type == "pntSubComponent": obj = target.SubComponent.Parent3DObject cls = obj.ActivePrimitive.Geometry.AddCluster( c.siVertexCluster, "gear_MatchGeometryOp_cls", target.SubComponent.ElementArray) else: obj = target cls = obj.ActivePrimitive.Geometry.AddCluster( c.siVertexCluster, "gear_MatchGeometryOp_cls") if source.Type != obj.Type: gear.log("Invalid Selection", gear.sev_error) xsi.DeleteObj(cls) return # Apply Operator op = XSIFactory.CreateObject("gear_MatchGeometryOp") op.AddIOPort(obj.ActivePrimitive) op.AddInputPort(source.ActivePrimitive) op.AddInputPort(cls) op.AddInputPort(obj.Kinematics.Global) op.AddInputPort(source.Kinematics.Global) op.Connect() xsi.InspectObj(op) return op
def drawNewComponent(self, parent, comp_type): comp_guide = self.getComponentGuide(comp_type) if not comp_guide: return if parent is None: self.initialHierarchy() parent = self.model elif not parent.IsClassOf(c.siX3DObjectID): gear.log("Invalid Parent Selected", gear.sev_error) return else: parent_root = parent while True: if parent_root.Type == "#model": break # Setting some default value according to the parent (side, connector and uihost) if parent_root.Properties("settings"): parent_type = parent_root.Properties( "settings").Parameters("comp_type").Value parent_side = parent_root.Properties( "settings").Parameters("comp_side").Value parent_uihost = parent_root.Properties( "settings").Parameters("uiHost").Value if parent_type in comp_guide.connectors: comp_guide.setParamDefValue("connector", parent_type) comp_guide.setParamDefValue("comp_side", parent_side) comp_guide.setParamDefValue("uiHost", parent_uihost) break parent_root = parent_root.Parent3DObject if not self.isValidModel(parent.Model): return if comp_guide.drawFromUI(parent): xsi.SelectObj(comp_guide.root) xsi.InspectObj(comp_guide.settings)
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)
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)
def gear_Interpose_Execute(): if not xsi.Selection.Count: gear.log("No selection", gear.sev_error) return out = xsi.Selection(0) ref_A = uit.pickSession(c.siGenericObjectFilter, "Pick Reference A", True) if not ref_A: return ref_B = uit.pickSession(c.siGenericObjectFilter, "Pick Reference B", True) if not ref_B: return op = aop.sn_interpose_op(out, ref_A, ref_B) xsi.InspectObj(op)
def gear_CurveResampler_Execute(): if not xsi.Selection.Count: gear.log("No selection", gear.sev_error) return for curve in xsi.Selection: if curve.Type not in ["crvlist"]: gear.log("Invalid selection", gear.sev_warning) continue if curve.ActivePrimitive.Geometry.Curves.Count > 1: gear.log("Curve Resampler works only with single curve", gear.sev_warning) continue # Apply Operator op = cur.applyCurveResamplerOp(curve) xsi.InspectObj(op)
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)
def drawFromUI(self, parent): if not self.pickPositions(): gear.log("aborded", gear.sev_warning) return self.parent = parent self.setIndex(self.parent.Model) self.addObjects() # Set the size of the controlers if self.root_size is None: self.root_size = 1 if self.type != "control_01": for child in self.root.FindChildren(): self.root_size = max(self.root_size, vec.getDistance2(self.root, child)) self.root_size = min(1, max(.1, self.root_size*.15)) self.root.size = self.root_size xsi.InspectObj(self.settings)
def drawCubicHermiteSpline(cInputs, bCreateTangentCtrl = True): # Create Curve and tangent controler ---------------------------- oCurve = xsi.ActiveSceneRoot.AddNurbsCurve() oCurve.Name = "CatmullRom_crv" if bCreateTangentCtrl: oStartTangent = prm.addNull(oCurve, "StartTangent", cInputs(0).Kinematics.Global.Transform, 1) oEndTangent = prm.addNull(oCurve, "EndTangent", cInputs(cInputs.Count-1).Kinematics.Global.Transform, 1) else: oStartTangent = cInputs(0) oEndTangent = cInputs(cInputs.Count-1) # Apply Operator ------------------------------------------------ oOp = XSIFactory.CreateObject("gCubicHermiteSplineOp") # Output oOp.AddOutputPort(oCurve.ActivePrimitive) oOp.AddInputPort(oCurve.Kinematics.Global) oOp.AddInputPort(oStartTangent.Kinematics.Global) oOp.AddInputPort(oEndTangent.Kinematics.Global) # PortGroup oInputGroup = oOp.AddPortGroup("InputGroup", 0, 1000) # PortGroup class ID oOp.AddInputPortByClassID(c.siKinematicsID, "InputKine", oInputGroup.Index) for oInput in cInputs: oOp.ConnectToGroup(oInputGroup.Index,oInput.Kinematics.Global) oOp.Connect() xsi.InspectObj(oOp) return oOp
def gear_SplitShapeKey_Execute(): if not xsi.Selection.Count: gear.log("Select shape keys", gear.sev_error) return shapes = [shape for shape in xsi.Selection if shape.Type in ["clskey"]] if not shapes: return cls = shapes[0].Parent mesh = cls.Parent3DObject geo = mesh.ActivePrimitive.Geometry clusters = geo.Clusters # UI prop = xsi.ActiveSceneRoot.AddProperty("Custom_parameter_list", False, "gear_SplitShapeKey") pLPrefix = prop.AddParameter3("LPrefix", c.siString, "L_", None, None, False, False) pRPrefix = prop.AddParameter3("RPrefix", c.siString, "R_", None, None, False, False) pRCluster = prop.AddParameter3("RCluster", c.siInt4, -1, -1, clusters.Count - 1, False, False) pLCluster = prop.AddParameter3("LCluster", c.siInt4, -1, -1, clusters.Count - 1, False, False) pCCluster = prop.AddParameter3("CCluster", c.siInt4, -1, -1, clusters.Count - 1, False, False) clusters_items = ["Auto Detect Points", -1] for i, cls in enumerate(clusters): clusters_items.append(cls.Name) clusters_items.append(i) # Layout layout = prop.PPGLayout layout.Clear() layout.AddTab("General") layout.AddGroup("Prefix") layout.AddRow() layout.AddItem(pRPrefix.ScriptName, "Right") layout.AddItem(pLPrefix.ScriptName, "Left") layout.EndRow() layout.EndGroup() layout.AddGroup("Clusters") layout.AddEnumControl(pRCluster.ScriptName, clusters_items, "Right Points", c.siControlCombo) layout.AddEnumControl(pLCluster.ScriptName, clusters_items, "Left Points", c.siControlCombo) layout.AddEnumControl(pCCluster.ScriptName, clusters_items, "Center Points", c.siControlCombo) layout.EndGroup() # Inspect rtn = xsi.InspectObj(prop, "", "Split Shape Key", c.siModal, False) # Return Values if pRCluster.Value == -1: r_points = sha.getPoints(geo, "R") else: r_points = clusters(pRCluster.value - 1).Elements.Array if pLCluster.Value == -1: l_points = sha.getPoints(geo, "L") else: l_points = clusters(pLCluster.value - 1).Elements.Array if pCCluster.Value == -1: c_points = sha.getPoints(geo, "C") else: c_points = clusters(pCCluster.value - 1).Elements.Array r_prefix = pRPrefix.Value l_prefix = pLPrefix.Value xsi.DeleteObj(prop) if rtn: return # Process for shape in shapes: sha.createHalfShape(shape, c_points, l_prefix, r_points) sha.createHalfShape(shape, c_points, r_prefix, l_points)
def gear_groupManagerOpen_Execute(): ppg = XSIFactory.CreateObject("gear_groupManager") xsi.InspectObj(ppg) return 1
def finalize(self): # Properties -------------------------------------- self.plog.log("Filling layout and logic") self.ui.fillLayoutAndLogic() # Groups ------------------------------------------ self.plog.log("Creating groups") # Retrieve group content from components for name in self.componentsIndex: component = self.components[name] for name, objects in component.groups.items(): self.addToGroup(objects, name) # Creating all groups for name, objects in self.groups.items(): collection = XSIFactory.CreateObject("XSI.Collection") collection.AddItems(objects) self.groups[name] = self.model.AddGroup(collection, name + "_grp") # Hidden if self.options["setHidden"]: self.groups["hidden"].Parameters("viewvis").Value = 0 self.groups["hidden"].Parameters("rendvis").Value = 0 # Unselectable if self.options["setUnselectable"]: self.groups["unselectable"].Parameters("selectability").Value = 0 # Deformers if self.options["setDeformers"]: self.groups["deformers"].Parameters("viewvis").Value = 0 self.groups["deformers"].Parameters("rendvis").Value = 0 # Geometries if self.options["setGeometries"]: self.groups["geometries"].Parameters("selectability").Value = 0 prop = self.groups["geometries"].AddProperty("GeomApprox") par.addExpression(prop.Parameters("gapproxmosl"), self.pOGLLevel) # Skin -------------------------------------------- if self.options["addGeometry"]: self.plog.log("Applying skin") # Import geometry if self.options["geo_path"] and os.path.exists( self.options["geo_path"]): geo_model = xsi.ImportModel(self.options["geo_path"], xsi.ActiveSceneRoot, False, None)(1) geo_objects = geo_model.FindChildren() self.model.AddChild(geo_model.children) for group in geo_model.Groups: target_group = pri.createOrReturnGroup( self.model, group.Name) target_group.AddMember(group.Members) xsi.DeleteObj(geo_model) # Apply skin if self.options["skin_path"] and os.path.exists( self.options["skin_path"]): xml_objs = io.getObjectDefinitions( self.options["skin_path"], geo_objects, False) for obj in geo_objects: if obj.Name not in xml_objs.keys(): continue io.importSkin(xml_objs[obj.Name], obj) # Symmetry Mapping Template ----------------------- if self.options["mode"] == 1: env.createSymmetryMappingTemplate(self.groups["deformers"].Members) for geo in self.groups["geometries"].Members: if geo.Type == "polymsh": xsi.CreateSymmetryMap("SymmetryMap", geo, "Symmetry Map") # Mirror Animation Template ----------------------- if self.options["mode"] == 0: cnx_prop = ani.createMirrorCnxTemplate(self.model) for count, compName in enumerate(self.componentsIndex): component = self.components[compName] inversed_params = component.inv_params.GetAsText().split(",") for ctl in component.controlers: ani.addMirroringRule(ctl, cnx_prop, inversed_params, True) # Reset Pose -------------------------------------- self.plog.log("Creating rest pose") controlers = XSIFactory.CreateObject("XSI.Collection") for group in self.model.Groups: if group.Name.startswith("controlers"): controlers.AddItems(group.Members) keyableParams = controlers.FindObjectsByMarkingAndCapabilities( None, c.siKeyable) xsi.StoreAction(self.model, keyableParams, 1, "reset", False) # Isolate and popup ------------------------------- if self.options["isolateResult"]: xsi.SelectObj(self.model, "BRANCH") xsi.IsolateSelected(False, -1) xsi.DeselectAll() if self.options["popUpControls"]: xsi.InspectObj(self.ui.anim_prop)
def gear_MoveShapeKey_Execute(): if not xsi.Selection.Count: gear.log("Select shape keys", gear.sev_error) return shapes = [shape for shape in xsi.Selection if shape.Type in ["clskey"]] if not shapes: return cls = shapes[0].Parent geo = cls.Parent clusters = geo.Clusters # UI prop = xsi.ActiveSceneRoot.AddProperty("Custom_parameter_list", False, "gear_MoveShapeKey") pDuplicate = prop.AddParameter3("duplicate", c.siBool, True, None, None, False, False) pClusters = prop.AddParameter3("clusters", c.siInt4, -1, 0, clusters.Count - 1, False, False) clustersItems = ["New Cluster", -1] for i, cls in enumerate(clusters): clustersItems.append(cls.Name) clustersItems.append(i) layout = prop.PPGLayout layout.Clear() layout.AddTab("General") layout.AddGroup("Move Shape Key Option") item = layout.AddItem(pDuplicate.ScriptName, "Duplicate") item = layout.AddEnumControl(pClusters.ScriptName, clustersItems, "Move to", c.siControlCombo) layout.EndGroup() # Inspect rtn = xsi.InspectObj(prop, "", "Move Shape Key", c.siModal, False) # Return values duplicate = pDuplicate.Value cluster_index = pClusters.Value xsi.DeleteObj(prop) if rtn: return # Create or get target cluster if cluster_index == -1: target_cluster = geo.AddCluster(c.siVertexCluster, cls.Name + "_Copy", cls.Elements.Array) else: target_cluster = clusters(cluster_index) # Duplicate Shape key for shape in shapes: sha.duplicateShapeKey(shape, target_cluster) # Delete original if not duplicate: xsi.DeleteObj(shapes)