def save(self): """Saves the geometry node back to :attr:`xmlnode`""" self.xmlnode.set('url', "#%s" % self.geometry.id) for m in self.materials: m.save() matparent = self.xmlnode.find('%s/%s'%( tag('bind_material'), tag('technique_common') ) ) if matparent is None and len(self.materials)==0: return elif matparent is None: matparent = E.technique_common() self.xmlnode.append(E.bind_material(matparent)) elif len(self.materials) == 0 and matparent is not None: bindnode = self.xmlnode.find('%s' % tag('bind_material')) self.xmlnode.remove(bindnode) return for m in self.materials: if m.xmlnode not in matparent: matparent.append(m.xmlnode) xmlnodes = [m.xmlnode for m in self.materials] for n in matparent: if n not in xmlnodes: matparent.remove(n)
def __init__(self, geometry, materials=None, xmlnode=None): """Creates a geometry node :param collada.geometry.Geometry geometry: A geometry to instantiate in the scene :param list materials: A list containing items of type :class:`collada.scene.MaterialNode`. Each of these represents a material that the geometry should be bound to. :param xmlnode: When loaded, the xmlnode it comes from """ self.geometry = geometry """An object of type :class:`collada.geometry.Geometry` representing the geometry to bind in the scene""" self.materials = [] """A list containing items of type :class:`collada.scene.MaterialNode`. Each of these represents a material that the geometry is bound to.""" if materials is not None: self.materials = materials if xmlnode != None: self.xmlnode = xmlnode """ElementTree representation of the geometry node.""" else: self.xmlnode = E.instance_geometry(url="#%s" % self.geometry.id) if len(self.materials) > 0: self.xmlnode.append(E.bind_material( E.technique_common( *[mat.xmlnode for mat in self.materials] ) ))