def setFromXml(self, xml_guide): # Options xml_options = xml_guide.find("options") if not xml_options: self.valid = False else: self.setParamDefValuesFromXml(xml_options) # Controlers xml_controlers = xml_guide.find("controlers") if xml_controlers: for xml_obj in xml_controlers.findall("x3dobject"): name = xml_obj.get("name") type = xml_obj.get("type") if type in ["null", "crvlist"]: self.controlers[name] = pri.getPrimitive(xml_obj) else: gear.log("Invalid controler type : " + name + " - " + type, gear.sev_warning) # Component Guide for xml_comp in xml_guide.findall("component"): comp_name = xml_comp.get("name") comp_type = xml_comp.get("type") comp_guide = self.getComponentGuide(comp_type) if not comp_guide: continue comp_guide.setFromXml(xml_comp) self.componentsIndex.append(comp_name) self.components[comp_name] = comp_guide # Parenting for xml_comp in xml_guide.findall("component"): name = xml_comp.get("name") parent = xml_comp.get("parent") if parent is None: continue parent = parent.split(".") if parent[0] != "None": self.components[name].parentComponent = self.components[ parent[0]] self.components[name].parentLocalName = parent[1] # More option values self.addOptionsValues()
def setFromXml(self, xml_guide): # Options xml_options = xml_guide.find("options") if not xml_options: self.valid = False else: self.setParamDefValuesFromXml(xml_options) # Controlers xml_controlers = xml_guide.find("controlers") if xml_controlers: for xml_obj in xml_controlers.findall("x3dobject"): name = xml_obj.get("name") type = xml_obj.get("type") if type in ["null", "crvlist"]: self.controlers[name] = pri.getPrimitive(xml_obj) else: gear.log("Invalid controler type : " + name + " - " + type, gear.sev_warning) # Component Guide for xml_comp in xml_guide.findall("component"): comp_name = xml_comp.get("name") comp_type = xml_comp.get("type") comp_guide = self.getComponentGuide(comp_type) if not comp_guide: continue comp_guide.setFromXml(xml_comp) self.componentsIndex.append(comp_name) self.components[comp_name] = comp_guide # Parenting for xml_comp in xml_guide.findall("component"): name = xml_comp.get("name") parent = xml_comp.get("parent") if parent is None: continue parent = parent.split(".") if parent[0] != "None": self.components[name].parentComponent = self.components[parent[0]] self.components[name].parentLocalName = parent[1] # More option values self.addOptionsValues()
def setFromXml(self, xml_comp): # --------------------------------------------------- # Settings xml_settings = xml_comp.find("settings") self.setParamDefValuesFromXml(xml_settings) # --------------------------------------------------- # First get all the object available in the xml (it's faster that way) xml_objects = xml_comp.find("objects") for xml_obj in xml_objects.findall("x3dobject"): localName = xml_obj.get("localName") xObj = xsixmldom.xmlToObject(xml_obj) xml_kine = xml_obj.find("kinematics") if xml_kine and len(xml_kine): t = xObj.getGlobalTransform() self.tra[localName] = t self.pos[localName] = t.Translation xml_prim = xml_obj.find("primitive") if xml_prim and len(xml_prim): self.prim[localName] = pri.getPrimitive(xml_obj) if localName in self.save_blade: self.blades[localName] = vec.Blade(self.tra[localName]) # --------------------------------------------------- # Then check what is missing for name in self.save_transform: if "#" in name: i = 0 while not self.minmax[name].max > 0 or i < self.minmax[ name].max: localName = string.replaceSharpWithPadding(name, i) if localName not in self.tra.keys(): break self.atra.append(self.tra[localName]) self.apos.append(self.pos[localName]) i += 1 if i < self.minmax[name].min: gear.log( "Minimum of object requiered for " + name + " hasn't been reached", gear.sev_warning) self.valid = False continue else: if name not in self.tra.keys(): gear.log("Object missing : %s" % name, gear.sev_warning) self.valid = False continue self.atra.append(self.tra[name]) self.apos.append(self.pos[name]) for name in self.save_primitive: if name not in self.prim.keys(): gear.log("Object missing : %s" % name, gear.sev_warning) self.valid = False continue for name in self.save_blade: if name not in self.blades.keys(): gear.log("Object missing : %s" % name, gear.sev_warning) self.valid = False continue self.size = self.getSize() self.root_size = float(xml_comp.get("root_size"))
def setFromHierarchy(self, root): self.root = root self.model = self.root.Model # --------------------------------------------------- # First check and set the settings self.settings = self.root.Properties("settings") if not self.settings: gear.log( "Can't find the 'setting' property. %s is not a proper guide." % self.root.Name, gear.sev_error) self.valid = False return self.setParamDefValuesFromProperty(self.settings) # --------------------------------------------------- # Then get the objects for name in self.save_transform: if "#" in name: i = 0 while not self.minmax[name].max > 0 or i < self.minmax[ name].max: localName = string.replaceSharpWithPadding(name, i) obj = self.model.FindChild(self.getName(localName)) if not obj: break self.tra[localName] = obj.Kinematics.Global.Transform self.atra.append(obj.Kinematics.Global.Transform) self.pos[ localName] = obj.Kinematics.Global.Transform.Translation self.apos.append( obj.Kinematics.Global.Transform.Translation) i += 1 if i < self.minmax[name].min: gear.log( "Minimum of object requiered for " + name + " hasn't been reached", gear.sev_warning) self.valid = False continue else: obj = self.model.FindChild(self.getName(name)) if not obj: gear.log("Object missing : %s" % name, gear.sev_warning) self.valid = False continue self.tra[name] = obj.Kinematics.Global.Transform self.atra.append(obj.Kinematics.Global.Transform) self.pos[name] = obj.Kinematics.Global.Transform.Translation self.apos.append(obj.Kinematics.Global.Transform.Translation) for name in self.save_primitive: obj = self.model.FindChild(self.getName(name)) if not obj: gear.log("Object missing : %s" % name, gear.sev_warning) self.valid = False continue self.prim[name] = pri.getPrimitive(obj) for name in self.save_blade: obj = self.model.FindChild(self.getName(name)) if not obj: gear.log("Object missing : %s" % name, gear.sev_warning) self.valid = False continue self.blades[name] = vec.Blade(obj.Kinematics.Global.Transform) self.size = self.getSize() self.root_size = self.root.size.Value
def setFromXml(self, xml_comp): # --------------------------------------------------- # Settings xml_settings = xml_comp.find("settings") self.setParamDefValuesFromXml(xml_settings) # --------------------------------------------------- # First get all the object available in the xml (it's faster that way) xml_objects = xml_comp.find("objects") for xml_obj in xml_objects.findall("x3dobject"): localName = xml_obj.get("localName") xObj = xsixmldom.xmlToObject(xml_obj) xml_kine = xml_obj.find("kinematics") if xml_kine and len(xml_kine): t = xObj.getGlobalTransform() self.tra[localName] = t self.pos[localName] = t.Translation xml_prim = xml_obj.find("primitive") if xml_prim and len(xml_prim): self.prim[localName] = pri.getPrimitive(xml_obj) if localName in self.save_blade: self.blades[localName] = vec.Blade(self.tra[localName]) # --------------------------------------------------- # Then check what is missing for name in self.save_transform: if "#" in name: i = 0 while not self.minmax[name].max > 0 or i < self.minmax[name].max: localName = string.replaceSharpWithPadding(name, i) if localName not in self.tra.keys(): break self.atra.append(self.tra[localName]) self.apos.append(self.pos[localName]) i += 1 if i < self.minmax[name].min: gear.log("Minimum of object requiered for "+name+" hasn't been reached", gear.sev_warning) self.valid = False continue else: if name not in self.tra.keys(): gear.log("Object missing : %s"%name, gear.sev_warning) self.valid = False continue self.atra.append(self.tra[name]) self.apos.append(self.pos[name]) for name in self.save_primitive: if name not in self.prim.keys(): gear.log("Object missing : %s"%name, gear.sev_warning) self.valid = False continue for name in self.save_blade: if name not in self.blades.keys(): gear.log("Object missing : %s"%name, gear.sev_warning) self.valid = False continue self.size = self.getSize() self.root_size = float(xml_comp.get("root_size"))
def setFromHierarchy(self, root): self.root = root self.model = self.root.Model # --------------------------------------------------- # First check and set the settings self.settings = self.root.Properties("settings") if not self.settings: gear.log("Can't find the 'setting' property. %s is not a proper guide."%self.root.Name, gear.sev_error) self.valid = False return self.setParamDefValuesFromProperty(self.settings) # --------------------------------------------------- # Then get the objects for name in self.save_transform: if "#" in name: i = 0 while not self.minmax[name].max > 0 or i < self.minmax[name].max: localName = string.replaceSharpWithPadding(name, i) obj = self.model.FindChild(self.getName(localName)) if not obj: break self.tra[localName] = obj.Kinematics.Global.Transform self.atra.append(obj.Kinematics.Global.Transform) self.pos[localName] = obj.Kinematics.Global.Transform.Translation self.apos.append(obj.Kinematics.Global.Transform.Translation) i += 1 if i < self.minmax[name].min: gear.log("Minimum of object requiered for "+name+" hasn't been reached", gear.sev_warning) self.valid = False continue else: obj = self.model.FindChild(self.getName(name)) if not obj: gear.log("Object missing : %s"%name, gear.sev_warning) self.valid = False continue self.tra[name] = obj.Kinematics.Global.Transform self.atra.append(obj.Kinematics.Global.Transform) self.pos[name] = obj.Kinematics.Global.Transform.Translation self.apos.append(obj.Kinematics.Global.Transform.Translation) for name in self.save_primitive: obj = self.model.FindChild(self.getName(name)) if not obj: gear.log("Object missing : %s"%name, gear.sev_warning) self.valid = False continue self.prim[name] = pri.getPrimitive(obj) for name in self.save_blade: obj = self.model.FindChild(self.getName(name)) if not obj: gear.log("Object missing : %s"%name, gear.sev_warning) self.valid = False continue self.blades[name] = vec.Blade(obj.Kinematics.Global.Transform) self.size = self.getSize() self.root_size = self.root.size.Value
def setFromHierarchy(self, root, branch=True): if not root.IsClassOf(c.siX3DObjectID): root = root.Parent3DObject # Start self.plog.start("Checking guide") if root.Type == "#model": self.model = root else: self.model = root.Model while True: if root.Properties("settings") or root.IsEqualTo(self.model): break root = root.Parent3DObject # --------------------------------------------------- # First check and set the options self.plog.log(None, "Get options") self.options = self.model.Properties("options") if not self.options: gear.log( "Can't find the 'options' property. %s is not a proper rig guide." % self.model.Name, gear.sev_error ) self.valid = False return self.setParamDefValuesFromProperty(self.options) # --------------------------------------------------- # Get the controlers self.plog.log(None, "Get controlers") self.controlers_org = self.model.FindChild("controlers_org") if self.controlers_org: for child in self.controlers_org.Children: if child.Type in ["null", "crvlist"]: self.controlers[child.Name] = pri.getPrimitive(child) else: gear.log("Invalid controler type : " + child.Name + " - " + child.Type, gear.sev_warning) # --------------------------------------------------- # Components self.plog.log(None, "Get components") self.findComponentRecursive(root, branch) # Parenting self.plog.log(None, "Get parenting") for name in self.componentsIndex: compChild = self.components[name] for name in self.componentsIndex: compParent = self.components[name] for name, element in compParent.getObjects(self.model).items(): if element is not None and element.IsEqualTo(compChild.root.Parent): compChild.parentComponent = compParent compChild.parentLocalName = name break # More option values self.addOptionsValues() # End if not self.valid: gear.log( "The guide doesn't seem to be up to date. Check logged messages and update the guide.", gear.sev_warning ) gear.log("Guide loaded from hierarchy in [ " + self.plog.getTime() + " ]") self.plog.hideBar()
def setFromHierarchy(self, root, branch=True): if not root.IsClassOf(c.siX3DObjectID): root = root.Parent3DObject # Start self.plog.start("Checking guide") if root.Type == "#model": self.model = root else: self.model = root.Model while True: if root.Properties("settings") or root.IsEqualTo(self.model): break root = root.Parent3DObject # --------------------------------------------------- # First check and set the options self.plog.log(None, "Get options") self.options = self.model.Properties("options") if not self.options: gear.log( "Can't find the 'options' property. %s is not a proper rig guide." % self.model.Name, gear.sev_error) self.valid = False return self.setParamDefValuesFromProperty(self.options) # --------------------------------------------------- # Get the controlers self.plog.log(None, "Get controlers") self.controlers_org = self.model.FindChild("controlers_org") if self.controlers_org: for child in self.controlers_org.Children: if child.Type in ["null", "crvlist"]: self.controlers[child.Name] = pri.getPrimitive(child) else: gear.log( "Invalid controler type : " + child.Name + " - " + child.Type, gear.sev_warning) # --------------------------------------------------- # Components self.plog.log(None, "Get components") self.findComponentRecursive(root, branch) # Parenting self.plog.log(None, "Get parenting") for name in self.componentsIndex: compChild = self.components[name] for name in self.componentsIndex: compParent = self.components[name] for name, element in compParent.getObjects(self.model).items(): if element is not None and element.IsEqualTo( compChild.root.Parent): compChild.parentComponent = compParent compChild.parentLocalName = name break # More option values self.addOptionsValues() # End if not self.valid: gear.log( "The guide doesn't seem to be up to date. Check logged messages and update the guide.", gear.sev_warning) gear.log("Guide loaded from hierarchy in [ " + self.plog.getTime() + " ]") self.plog.hideBar()