def __init__(self, symbol, target, inputs, xmlnode = None): """Creates a material node :param str symbol: The symbol within a geometry this material should be bound to :param collada.material.Material target: The material object being bound to :param list inputs: A list of tuples of the form ``(semantic, input_semantic, set)`` mapping texcoords or other inputs to material input channels, e.g. ``('TEX0', 'TEXCOORD', '0')`` would map the effect parameter ``'TEX0'`` to the ``'TEXCOORD'`` semantic of the geometry, using texture coordinate set ``0``. :param xmlnode: When loaded, the xmlnode it comes from """ self.symbol = symbol """The symbol within a geometry this material should be bound to""" self.target = target """An object of type :class:`collada.material.Material` representing the material object being bound to""" self.inputs = inputs """A list of tuples of the form ``(semantic, input_semantic, set)`` mapping texcoords or other inputs to material input channels, e.g. ``('TEX0', 'TEXCOORD', '0')`` would map the effect parameter ``'TEX0'`` to the ``'TEXCOORD'`` semantic of the geometry, using texture coordinate set ``0``.""" if xmlnode is not None: self.xmlnode = xmlnode """ElementTree representation of the material node.""" else: self.xmlnode = E.instance_material( *[E.bind_vertex_input(semantic=sem, input_semantic=input_sem, input_set=set) for sem, input_sem, set in self.inputs] , **{'symbol': self.symbol, 'target':"#%s"%self.target.id} )
def save(self): """Saves the material node back to :attr:`xmlnode`""" self.xmlnode.set('symbol', self.symbol) self.xmlnode.set('target', "#%s"%self.target.id) inputs_in = [] for i in self.xmlnode.findall( tag('bind_vertex_input') ): input_tuple = ( i.get('semantic'), i.get('input_semantic'), i.get('input_set') ) if input_tuple not in self.inputs: self.xmlnode.remove(i) else: inputs_in.append(input_tuple) for i in self.inputs: if i not in inputs_in: self.xmlnode.append(E.bind_vertex_input(semantic=i[0], input_semantic=i[1], input_set=i[2]))