def addMirroringRule(ctl, cnx_grid, inversed_params=[], delUnused=False): model = ctl.Model # I want to get all the keyable parameters for this object and the easiest way # is to use the FindObjectsByMarkingAndCapabilities() method # but it only applies on collection controlers = XSIFactory.CreateObject("XSI.Collection") controlers.Add(ctl) key_params = controlers.FindObjectsByMarkingAndCapabilities(None, 2048) # try to find the mirror object mirror_ctl = model.FindChild(uti.convertRLName(ctl.Name)) connections = par.getDictFromGridData(cnx_grid) for param in key_params: # Skip marking set to avoid having all the params twice if param.Parent.Name == "MarkingSet" or param.Parent.Name.startswith( "DisplayInfo"): continue fullName = param.FullName[param.FullName.find(".") + 1:] # If the object mirror on itself, try to find R and L parameters if not mirror_ctl or mirror_ctl.IsEqualTo(ctl): mirror_param = param.Parent.Parameters( uti.convertRLName(param.Name)) if mirror_param: mirror_fullName = mirror_param.FullName[mirror_param.FullName. find(".") + 1:] else: mirror_fullName = fullName else: mirror_fullName = fullName.replace(ctl.Name, mirror_ctl.Name) if delUnused and (fullName == mirror_fullName and not param.FullName in inversed_params): continue connections[fullName] = [ mirror_fullName, param.FullName in inversed_params ] par.setDataGridFromDict(cnx_grid, connections) return connections
def averageMirrorWeights(envelope_op, points): 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)) ] deformers = envelope_op.Deformers deformer_count = deformers.Count # Get Mirror Deformer Index mirror_deformers = [0] * deformer_count for deformer_index, deformer in enumerate(deformers): mirror_deformer = deformer.Model.FindChild( uti.convertRLName(deformer.Name)) if mirror_deformer and isDeformer(envelope_op, mirror_deformer): mirror_deformers[deformer_index] = getDeformerIndex( envelope_op, mirror_deformer) else: mirror_deformers[deformer_index] = deformer_index # Replace weights in weight array for point_index in points: for deformer_index in range(deformer_count): weights[point_index * deformer_count + deformer_index] = ( weights_tuple[deformer_index][point_index] + weights_tuple[mirror_deformers[deformer_index]][point_index] ) * .5 envelope_op.Weights.Array = weights
def createSymmetryMappingTemplate(in_deformers): deformers = XSIFactory.CreateObject("XSI.Collection") deformers.AddItems(in_deformers) temp_mesh = deformers(0).Model.AddGeometry("Sphere", "MeshSurface", "TempMesh") temp_mesh.ApplyEnvelope(deformers, False, False) # Create Mapping Template mapTemplate = xsi.CreateSymmetryMappingTemplate(temp_mesh, False, 0, False) for deformer in deformers: # Skip effectors if deformer.Type == "eff": continue sym_deformers = deformer.Model.FindChild( uti.convertRLName(deformer.Name)) if not sym_deformers or sym_deformers.IsEqualTo(deformer): continue xsi.AddMappingRule(mapTemplate, deformer.Name, sym_deformers.Name, xsi.GetNumMappingRules(mapTemplate)) xsi.DeleteObj(temp_mesh) return mapTemplate
def createSymmetryMappingTemplate(in_deformers): deformers = XSIFactory.CreateObject("XSI.Collection") deformers.AddItems(in_deformers) temp_mesh = deformers(0).Model.AddGeometry("Sphere", "MeshSurface", "TempMesh") temp_mesh.ApplyEnvelope(deformers, False, False) # Create Mapping Template mapTemplate = xsi.CreateSymmetryMappingTemplate(temp_mesh, False, 0, False) for deformer in deformers: # Skip effectors if deformer.Type == "eff": continue sym_deformers = deformer.Model.FindChild(uti.convertRLName(deformer.Name)) if not sym_deformers or sym_deformers.IsEqualTo(deformer): continue xsi.AddMappingRule(mapTemplate, deformer.Name, sym_deformers.Name, xsi.GetNumMappingRules(mapTemplate)) xsi.DeleteObj(temp_mesh) return mapTemplate
def mirrorCluster(cls): mesh = cls.Parent3DObject mirror_component = getSymSubComponent(cls.Elements, cls.Type+"SubComponent", mesh) mirror_cls = mesh.ActivePrimitive.Geometry.AddCluster(cls.Type, uti.convertRLName(cls.Name), mirror_component) return mirror_cls
def addMirroringRule(ctl, cnx_grid, inversed_params=[], delUnused=False): model = ctl.Model # I want to get all the keyable parameters for this object and the easiest way # is to use the FindObjectsByMarkingAndCapabilities() method # but it only applies on collection controlers = XSIFactory.CreateObject("XSI.Collection") controlers.Add(ctl) key_params = controlers.FindObjectsByMarkingAndCapabilities(None, 2048) # try to find the mirror object mirror_ctl = model.FindChild(uti.convertRLName(ctl.Name)) connections = par.getDictFromGridData(cnx_grid) for param in key_params: # Skip marking set to avoid having all the params twice if param.Parent.Name == "MarkingSet" or param.Parent.Name.startswith("DisplayInfo"): continue fullName = param.FullName[param.FullName.find(".")+1:] # If the object mirror on itself, try to find R and L parameters if not mirror_ctl or mirror_ctl.IsEqualTo(ctl): mirror_param = param.Parent.Parameters(uti.convertRLName(param.Name)) if mirror_param: mirror_fullName = mirror_param.FullName[mirror_param.FullName.find(".")+1:] else: mirror_fullName = fullName else: mirror_fullName = fullName.replace(ctl.Name, mirror_ctl.Name) if delUnused and (fullName == mirror_fullName and not param.FullName in inversed_params): continue connections[fullName] = [mirror_fullName, param.FullName in inversed_params] par.setDataGridFromDict(cnx_grid, connections) return connections
def copyMirrorEnvelope(source_mesh, target_mesh): sourceEnv_op = ope.getOperatorFromStack(source_mesh, "envelopop") if not sourceEnv_op: gear.log("There is no envelope on source mesh", gear.sev_error) return target_deformers = XSIFactory.CreateObject("XSI.Collection") for deformer in sourceEnv_op.Deformers: model = deformer.Model target_deformer = model.FindChild(uti.convertRLName(deformer.Name)) if not target_deformer: gear.log("Deformer missing : " +uti.convertRLName(deformer.Name), c.siWarning) target_deformer = deformer target_deformers.Add(target_deformer) targetEnv_op = target_mesh.ApplyEnvelope(target_deformers) # Apply Weights targetEnv_op.Weights.Array = sourceEnv_op.Weights.Array
def copyMirrorEnvelope(source_mesh, target_mesh): sourceEnv_op = ope.getOperatorFromStack(source_mesh, "envelopop") if not sourceEnv_op: gear.log("There is no envelope on source mesh", gear.sev_error) return target_deformers = XSIFactory.CreateObject("XSI.Collection") for deformer in sourceEnv_op.Deformers: model = deformer.Model target_deformer = model.FindChild(uti.convertRLName(deformer.Name)) if not target_deformer: gear.log("Deformer missing : " + uti.convertRLName(deformer.Name), c.siWarning) target_deformer = deformer target_deformers.Add(target_deformer) targetEnv_op = target_mesh.ApplyEnvelope(target_deformers) # Apply Weights targetEnv_op.Weights.Array = sourceEnv_op.Weights.Array
def symmetrize(self): if self.values["comp_side"] not in ["R", "L"]: gear.log("Can't symmetrize central component", gear.sev_error) return False self.setParamDefValue("comp_side", uti.convertRLName(self.values["comp_side"])) for name, t in self.tra.items(): self.tra[name] = tra.getSymmetricalTransform2(t) for name, blade in self.blades.items(): self.blades[name] = vec.Blade(tra.getSymmetricalTransform2(blade.transform)) return True
def duplicate(self, root, symmetrize=False): if not root or (root.Type != "#model" and not root.Properties("settings")): gear.log("Select a root to duplicate", gear.sev_error) return self.setFromHierarchy(root) for name in self.componentsIndex: comp_guide = self.components[name] if symmetrize: if not comp_guide.symmetrize(): return # Draw if root.Type == "#model": self.draw() else: for name in self.componentsIndex: comp_guide = self.components[name] if comp_guide.parentComponent is None: if symmetrize: parent = self.model.FindChild(uti.convertRLName(comp_guide.root.Name)) if parent is None: parent = comp_guide.root.Parent else: parent = comp_guide.root.Parent else: parent = self.model.FindChild(comp_guide.parentComponent.getName(comp_guide.parentLocalName)) if not parent: gear.log( "Unable to find parent (%s.%s) for guide %s" % ( comp_guide.parentComponent.getFullName, comp_guide.parentLocalName, comp_guide.getFullName, ) ) parent = self.model comp_guide.root = None # Reset the root so we force the draw to duplicate comp_guide.setIndex(self.model) comp_guide.draw(parent) xsi.SelectObj(self.components[self.componentsIndex[0]].root)
def duplicate(self, root, symmetrize=False): if not root or (root.Type != "#model" and not root.Properties("settings")): gear.log("Select a root to duplicate", gear.sev_error) return self.setFromHierarchy(root) for name in self.componentsIndex: comp_guide = self.components[name] if symmetrize: if not comp_guide.symmetrize(): return # Draw if root.Type == "#model": self.draw() else: for name in self.componentsIndex: comp_guide = self.components[name] if comp_guide.parentComponent is None: if symmetrize: parent = self.model.FindChild( uti.convertRLName(comp_guide.root.Name)) if parent is None: parent = comp_guide.root.Parent else: parent = comp_guide.root.Parent else: parent = self.model.FindChild( comp_guide.parentComponent.getName( comp_guide.parentLocalName)) if not parent: gear.log("Unable to find parent (%s.%s) for guide %s" % (comp_guide.parentComponent.getFullName, comp_guide.parentLocalName, comp_guide.getFullName)) parent = self.model comp_guide.root = None # Reset the root so we force the draw to duplicate comp_guide.setIndex(self.model) comp_guide.draw(parent) xsi.SelectObj(self.components[self.componentsIndex[0]].root)
def symmetrize(self): if self.values["comp_side"] not in ["R", "L"]: gear.log("Can't symmetrize central component", gear.sev_error) return False #self.setParamDefValue("comp_side", uti.convertRLName(self.values["comp_side"])) for name, paramDef in self.paramDefs.items(): if paramDef.valueType == c.siString: self.setParamDefValue(name, uti.convertRLName(self.values[name])) for name, t in self.tra.items(): self.tra[name] = tra.getSymmetricalTransform2(t) for name, blade in self.blades.items(): self.blades[name] = vec.Blade(tra.getSymmetricalTransform2(blade.transform)) return True
def averageMirrorWeights(envelope_op, points): 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))] deformers = envelope_op.Deformers deformer_count = deformers.Count # Get Mirror Deformer Index mirror_deformers = [0] * deformer_count for deformer_index, deformer in enumerate(deformers): mirror_deformer = deformer.Model.FindChild(uti.convertRLName(deformer.Name)) if mirror_deformer and isDeformer(envelope_op, mirror_deformer): mirror_deformers[deformer_index] = getDeformerIndex(envelope_op, mirror_deformer) else: mirror_deformers[deformer_index] = deformer_index # Replace weights in weight array for point_index in points: for deformer_index in range(deformer_count): weights[point_index*deformer_count + deformer_index] = (weights_tuple[deformer_index][point_index] + weights_tuple[mirror_deformers[deformer_index]][point_index]) * .5 envelope_op.Weights.Array = weights