本文整理汇总了Python中collada.common.E类的典型用法代码示例。如果您正苦于以下问题:Python E类的具体用法?Python E怎么用?Python E使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了E类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
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)
示例2: __init__
def __init__(self, id, color, xmlnode = None):
"""Create a new ambient light.
:param str id:
A unique string identifier for the light
:param tuple color:
Either a tuple of size 3 containing the RGB color value
of the light or a tuple of size 4 containing the RGBA
color value of the light
:param xmlnode:
If loaded from xml, the xml node
"""
self.id = id
"""The unique string identifier for the light"""
self.color = color
"""Either a tuple of size 3 containing the RGB color value
of the light or a tuple of size 4 containing the RGBA
color value of the light"""
if xmlnode != None:
self.xmlnode = xmlnode
"""ElementTree representation of the light."""
else:
self.xmlnode = E.light(
E.technique_common(
E.ambient(
E.color(' '.join(map(str, self.color)))
)
)
, id=self.id, name=self.id)
示例3: __init__
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]
)
))
示例4: _create_anim_src_elem
def _create_anim_src_elem(anim_name, src_data, src_suffix, src_type, param_name, param_type):
""""""
idName = anim_name + "-" + src_suffix
src_elem = E.source(id=idName)
idName += "-array"
count = len(src_data) / 16 if param_type == "float4x4" else len(src_data)
if src_type == "float":
str_src_data = " ".join([str(round(val, precision)) for val in src_data]) + " "
str_src_data = str_src_data.replace(".0 ", " ")
else:
str_src_data = " ".join(map(str, src_data))
src_elem.append(E(src_type + "_array", str_src_data, id=idName, count=str(count)))
src_elem.append(
E.technique_common(
E.accessor(
E.param(name=param_name, type=param_type), # accessor child
source="#" + idName,
count=str(count), # accessor attribs
)
)
)
if param_type == "float4x4":
src_elem.find(tag("technique_common")).find(tag("accessor")).set("stride", str(16))
return src_elem
示例5: __init__
def __init__(self, id, surface, minfilter=None, magfilter=None, xmlnode=None):
"""Create a Sampler2D object.
:param str id:
A string identifier for the sampler within the local scope of the material
:param collada.material.Surface surface:
Surface instance that this object samples from
:param str minfilter:
Minification filter string id, see collada spec for details
:param str magfilter:
Maximization filter string id, see collada spec for details
:param xmlnode:
If loaded from xml, the xml node
"""
self.id = id
"""The string identifier for the sampler within the local scope of the material"""
self.surface = surface
"""Surface instance that this object samples from"""
self.minfilter = minfilter
"""Minification filter string id, see collada spec for details"""
self.magfilter = magfilter
"""Maximization filter string id, see collada spec for details"""
if xmlnode != None:
self.xmlnode = xmlnode
"""ElementTree representation of the sampler."""
else:
sampler_node = E.sampler2D(E.source(self.surface.id))
if minfilter:
sampler_node.append(E.minfilter(self.minfilter))
if magfilter:
sampler_node.append(E.magfilter(self.magfilter))
self.xmlnode = E.newparam(sampler_node, sid=self.id)
示例6: getPropNode
def getPropNode(prop, value):
propnode = E(prop)
if type(value) is Map:
propnode.append(copy.deepcopy(value.xmlnode))
elif type(value) is float:
propnode.append(E.float(str(value)))
else:
propnode.append(E.color(' '.join(map(str, value) )))
return propnode
示例7: getPropNode
def getPropNode(prop, value):
propnode = E(prop)
if prop == 'transparent' and self.opaque_mode == OPAQUE_MODE.RGB_ZERO:
propnode.set('opaque', OPAQUE_MODE.RGB_ZERO)
if type(value) is Map:
propnode.append(copy.deepcopy(value.xmlnode))
elif type(value) is float:
propnode.append(E.float(str(value)))
else:
propnode.append(E.color(' '.join(map(str, value) )))
return propnode
示例8: _add_osg_description
def _add_osg_description(self, node, description):
"""
"""
extra = E.extra(
E.technique(
E.Descriptions( E.Description(description) ),
profile="OpenSceneGraph",
),
type="Node",
)
extra_node = collada.scene.ExtraNode(extra)
node.children.append(extra_node)
示例9: __init__
def __init__(self, filename, scale=1.0, options=None):
"""
"""
DrawerDriver.__init__(self, scale)
self.filename = filename
self.dae = collada.Collada()
self.shapes_dae = collada.Collada(os.path.join(os.path.dirname(os.path.abspath(__file__)), "simple_shapes.dae"))
# create library_physics_models
self.physics_model = E.physics_model(id="world")
self.dae.xmlnode.getroot().insert(1, E.library_physics_models(self.physics_model)) # insert just after asset
self.ground_node = None
self.scene = None
self._materials = {}
self._names = []
示例10: save
def save(self):
"""Saves the collada document back to :attr:`xmlnode`"""
libraries = [(self.geometries, 'library_geometries'),
(self.controllers, 'library_controllers'),
(self.lights, 'library_lights'),
(self.cameras, 'library_cameras'),
(self.images, 'library_images'),
(self.effects, 'library_effects'),
(self.materials, 'library_materials'),
(self.nodes, 'library_nodes'),
(self.scenes, 'library_visual_scenes')]
self.assetInfo.save()
assetnode = self.xmlnode.getroot().find(tag('asset'))
if assetnode is not None:
self.xmlnode.getroot().replace(assetnode, self.assetInfo.xmlnode)
else:
self.xmlnode.getroot().insert(0, self.assetInfo.xmlnode)
library_loc = 0
for i, node in enumerate(self.xmlnode.getroot()):
if node.tag == tag('asset'):
library_loc = i+1
for arr, name in libraries:
node = self.xmlnode.find( tag(name) )
if node is None:
if len(arr) == 0:
continue
self.xmlnode.getroot().insert(library_loc, E(name))
node = self.xmlnode.find( tag(name) )
elif node is not None and len(arr) == 0:
self.xmlnode.getroot().remove(node)
continue
for o in arr:
o.save()
if o.xmlnode not in node:
node.append(o.xmlnode)
xmlnodes = [o.xmlnode for o in arr]
for n in node:
if n not in xmlnodes:
node.remove(n)
scenenode = self.xmlnode.find(tag('scene'))
scenenode.clear()
if self.scene is not None:
sceneid = self.scene.id
if sceneid not in self.scenes:
raise DaeBrokenRefError('Default scene %s not found' % sceneid)
scenenode.append(E.instance_visual_scene(url="#%s" % sceneid))
if self.validator is not None:
if not self.validator.validate(self.xmlnode):
raise DaeSaveValidationError("Validation error when saving: " +
schema.COLLADA_SCHEMA_1_4_1_INSTANCE.error_log.last_error.message)
示例11: _recreateXmlNode
def _recreateXmlNode(self):
perspective_node = E.perspective()
if self.xfov is not None:
perspective_node.append(E.xfov(str(self.xfov)))
if self.yfov is not None:
perspective_node.append(E.yfov(str(self.yfov)))
if self.aspect_ratio is not None:
perspective_node.append(E.aspect_ratio(str(self.aspect_ratio)))
perspective_node.append(E.znear(str(self.znear)))
perspective_node.append(E.zfar(str(self.zfar)))
self.xmlnode = E.camera(
E.optics(
E.technique_common(perspective_node)
)
, id=self.id, name=self.id)
示例12: __init__
def __init__(self, id, data, components, xmlnode=None):
"""Create a name source instance.
:param str id:
A unique string identifier for the source
:param numpy.array data:
Numpy array (unshaped) with the source values
:param tuple components:
Tuple of strings describing the semantic of the data,
e.g. ``('JOINT')`` would cause :attr:`data` to be
reshaped as ``(-1, 1)``
:param xmlnode:
When loaded, the xmlnode it comes from.
"""
self.id = id
"""The unique string identifier for the source"""
self.data = data
"""Numpy array with the source values. This will be shaped as ``(-1,N)`` where ``N = len(self.components)``"""
self.data.shape = (-1, len(components) )
self.components = components
"""Tuple of strings describing the semantic of the data, e.g. ``('JOINT')``"""
if xmlnode != None:
self.xmlnode = xmlnode
"""ElementTree representation of the source."""
else:
self.data.shape = (-1,)
txtdata = ' '.join(map(str, self.data.tolist() ))
rawlen = len( self.data )
self.data.shape = (-1, len(self.components) )
acclen = len( self.data )
stridelen = len(self.components)
sourcename = "%s-array"%self.id
self.xmlnode = E.source(
E.Name_array(txtdata, count=str(rawlen), id=sourcename),
E.technique_common(
E.accessor(
*[E.param(type='Name', name=c) for c in self.components]
, **{'count':str(acclen), 'stride':str(stridelen), 'source':sourcename})
)
, id=self.id )
示例13: _recreateXmlNode
def _recreateXmlNode(self):
self.index.shape = -1
acclen = len(self.index)
txtindices = " ".join(map(str, self.index.tolist()))
self.index.shape = (-1, 3, self.nindices)
self.xmlnode = E.triangles(count=str(self.ntriangles))
if self.material is not None:
self.xmlnode.set("material", self.material)
all_inputs = []
for semantic_list in self.sources.values():
all_inputs.extend(semantic_list)
for offset, semantic, sourceid, set, src in all_inputs:
inpnode = E.input(offset=str(offset), semantic=semantic, source=sourceid)
if set is not None:
inpnode.set("set", str(set))
self.xmlnode.append(inpnode)
self.xmlnode.append(E.p(txtindices))
示例14: _recreateXmlNode
def _recreateXmlNode(self):
self.xmlnode = E.asset()
for contributor in self.contributors:
self.xmlnode.append(contributor.xmlnode)
self.xmlnode.append(E.created(self.created.isoformat()))
if self.keywords is not None:
self.xmlnode.append(E.keywords(self.keywords))
self.xmlnode.append(E.modified(self.modified.isoformat()))
if self.revision is not None:
self.xmlnode.append(E.revision(self.revision))
if self.subject is not None:
self.xmlnode.append(E.subject(self.subject))
if self.title is not None:
self.xmlnode.append(E.title(self.title))
if self.unitmeter is not None and self.unitname is not None:
self.xmlnode.append(E.unit(name=self.unitname, meter=str(self.unitmeter)))
self.xmlnode.append(E.up_axis(self.upaxis))
示例15: save
def save(self):
"""Saves the surface data back to :attr:`xmlnode`"""
surfacenode = self.xmlnode.find( tag('surface') )
initnode = surfacenode.find( tag('init_from') )
if self.format:
formatnode = surfacenode.find( tag('format') )
if formatnode is None:
surfacenode.append(E.format(self.format))
else:
formatnode.text = self.format
initnode.text = self.image.id
self.xmlnode.set('sid', self.id)