/usr/share/doc/python-collada/html/structure.html is in python-collada 0.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Collada Object Structure — pycollada 0.4 documentation</title>
<link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.4',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="pycollada 0.4 documentation" href="index.html" />
<link rel="next" title="Creating A Collada Object" href="creating.html" />
<link rel="prev" title="Loading A Collada Document" href="loading.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="creating.html" title="Creating A Collada Object"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="loading.html" title="Loading A Collada Document"
accesskey="P">previous</a> |</li>
<li><a href="index.html">pycollada 0.4 documentation</a> »</li>
</ul>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="loading.html"
title="previous chapter">Loading A Collada Document</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="creating.html"
title="next chapter">Creating A Collada Object</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/structure.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="collada-object-structure">
<span id="structure"></span><h1>Collada Object Structure<a class="headerlink" href="#collada-object-structure" title="Permalink to this headline">ΒΆ</a></h1>
<p>After loading a collada document, all of the information about the
file is stored within the Collada object. For example, consider the
following code:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">collada</span> <span class="kn">import</span> <span class="o">*</span>
<span class="gp">>>> </span><span class="n">mesh</span> <span class="o">=</span> <span class="n">Collada</span><span class="p">(</span><span class="s">'duck_triangles.dae'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">mesh</span>
<span class="go"><Collada geometries=1></span>
</pre></div>
</div>
<p>This sample file is located in <cite>collada/tests/data</cite> of the pycollada
distribution. We can now explore the attributes of the <a class="reference internal" href="reference/generated/collada.Collada.html#collada.Collada" title="collada.Collada"><tt class="xref py py-class docutils literal"><span class="pre">Collada</span></tt></a>
class.</p>
<p>Let’s see what <a class="reference internal" href="reference/generated/collada.Collada.html#collada.Collada.geometries" title="collada.Collada.geometries"><tt class="xref py py-attr docutils literal"><span class="pre">Collada.geometries</span></tt></a> it has:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">mesh</span><span class="o">.</span><span class="n">geometries</span>
<span class="go">[<Geometry id=LOD3spShape-lib, 1 primitives>]</span>
</pre></div>
</div>
<p>Each geometry has a number of <a class="reference internal" href="reference/generated/collada.source.Source.html#collada.source.Source" title="collada.source.Source"><tt class="xref py py-class docutils literal"><span class="pre">Source</span></tt></a> objects that contain raw
source data like an array of floats. It then has a number of <a class="reference internal" href="reference/generated/collada.primitive.Primitive.html#collada.primitive.Primitive" title="collada.primitive.Primitive"><tt class="xref py py-class docutils literal"><span class="pre">Primitive</span></tt></a>
objects contained. Let’s inspect them:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">geom</span> <span class="o">=</span> <span class="n">mesh</span><span class="o">.</span><span class="n">geometries</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">geom</span><span class="o">.</span><span class="n">primitives</span>
<span class="go">[<TriangleSet length=4212>]</span>
</pre></div>
</div>
<p>In this case, there is only a single primitive contained in the geometry and it’s
a set of triangles. The <a class="reference internal" href="reference/generated/collada.triangleset.TriangleSet.html#collada.triangleset.TriangleSet" title="collada.triangleset.TriangleSet"><tt class="xref py py-class docutils literal"><span class="pre">TriangleSet</span></tt></a> object lets us get at the vertex,
normal, and texture coordinate information. There are index properties that index
into the source arrays, and the sources are also automatically mapped for you.
You can iterate over the triangle set to yield individual <a class="reference internal" href="reference/generated/collada.triangleset.Triangle.html#collada.triangleset.Triangle" title="collada.triangleset.Triangle"><tt class="xref py py-class docutils literal"><span class="pre">Triangle</span></tt></a>
objects:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">triset</span> <span class="o">=</span> <span class="n">geom</span><span class="o">.</span><span class="n">primitives</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">trilist</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">triset</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">trilist</span><span class="p">)</span>
<span class="go">4212</span>
<span class="gp">>>> </span><span class="n">trilist</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go"><Triangle ([-23.93639946 11.53530025 30.61249924], [-18.72640038 10.1079998 26.6814003 ], [-15.69919968 11.42780018 34.23210144], "blinn3SG")></span>
</pre></div>
</div>
<p>The triangle object has the vertex, normal, and texture coordinate data associated
with the triangle, as well as the material it references. Iterating over the triangle
set is convenient, but it can be slow for large meshes. Instead, you can access the
numpy arrays in the set. For example, to get the vertex, normal, and texture coordinate
for the first triangle in the set:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">triset</span><span class="o">.</span><span class="n">vertex</span><span class="p">[</span><span class="n">triset</span><span class="o">.</span><span class="n">vertex_index</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
<span class="go">array([[-23.93639946, 11.53530025, 30.61249924],</span>
<span class="go"> [-18.72640038, 10.1079998 , 26.6814003 ],</span>
<span class="go"> [-15.69919968, 11.42780018, 34.23210144]], dtype=float32)</span>
<span class="gp">>>> </span><span class="n">triset</span><span class="o">.</span><span class="n">normal</span><span class="p">[</span><span class="n">triset</span><span class="o">.</span><span class="n">normal_index</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
<span class="go">array([[-0.192109 , -0.934569 , 0.299458 ],</span>
<span class="go"> [-0.06315 , -0.99362302, 0.093407 ],</span>
<span class="go"> [-0.11695 , -0.92131299, 0.37081599]], dtype=float32)</span>
<span class="gp">>>> </span><span class="n">triset</span><span class="o">.</span><span class="n">texcoordset</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">triset</span><span class="o">.</span><span class="n">texcoord_indexset</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="mi">0</span><span class="p">]</span>
<span class="go">array([[ 0.866606 , 0.39892399],</span>
<span class="go"> [ 0.87138402, 0.39761901],</span>
<span class="go"> [ 0.87415999, 0.398826 ]], dtype=float32)</span>
</pre></div>
</div>
<p>These are numpy arrays which allows for fast retrieval and computations.</p>
<p>The collada object also has arrays for accessing <a class="reference internal" href="reference/generated/collada.camera.Camera.html#collada.camera.Camera" title="collada.camera.Camera"><tt class="xref py py-class docutils literal"><span class="pre">Camera</span></tt></a>, <a class="reference internal" href="reference/generated/collada.light.Light.html#collada.light.Light" title="collada.light.Light"><tt class="xref py py-class docutils literal"><span class="pre">Light</span></tt></a>,
<a class="reference internal" href="reference/generated/collada.material.Effect.html#collada.material.Effect" title="collada.material.Effect"><tt class="xref py py-class docutils literal"><span class="pre">Effect</span></tt></a>, <a class="reference internal" href="reference/generated/collada.material.Material.html#collada.material.Material" title="collada.material.Material"><tt class="xref py py-class docutils literal"><span class="pre">Material</span></tt></a>, and <a class="reference internal" href="reference/generated/collada.scene.Scene.html#collada.scene.Scene" title="collada.scene.Scene"><tt class="xref py py-class docutils literal"><span class="pre">Scene</span></tt></a> objects:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">mesh</span><span class="o">.</span><span class="n">cameras</span>
<span class="go">[<Camera id=cameraShape1>]</span>
<span class="gp">>>> </span><span class="n">mesh</span><span class="o">.</span><span class="n">lights</span>
<span class="go">[<DirectionalLight id=directionalLightShape1-lib>]</span>
<span class="gp">>>> </span><span class="n">mesh</span><span class="o">.</span><span class="n">effects</span>
<span class="go">[<Effect id=blinn3-fx type=blinn>]</span>
<span class="gp">>>> </span><span class="n">mesh</span><span class="o">.</span><span class="n">materials</span>
<span class="go">[<Material id=blinn3 effect=blinn3-fx>]</span>
<span class="gp">>>> </span><span class="n">mesh</span><span class="o">.</span><span class="n">scenes</span>
<span class="go">[<Scene id=VisualSceneNode nodes=3>]</span>
</pre></div>
</div>
<p>A collada scene is a graph that contains nodes. Each node can have transformations
and a list of child nodes. A child node can be another node or an instance of a geometry,
light, camera, etc. The default scene is contained in the <a class="reference internal" href="reference/generated/collada.Collada.html#collada.Collada.scene" title="collada.Collada.scene"><tt class="xref py py-attr docutils literal"><span class="pre">Collada.scene</span></tt></a> attribute.
Let’s take a look:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">mesh</span><span class="o">.</span><span class="n">scene</span>
<span class="go"><Scene id=VisualSceneNode nodes=3></span>
<span class="gp">>>> </span><span class="n">mesh</span><span class="o">.</span><span class="n">scene</span><span class="o">.</span><span class="n">nodes</span>
<span class="go">[<Node transforms=3, children=1>, <Node transforms=4, children=1>, <Node transforms=4, children=1>]</span>
</pre></div>
</div>
<p>We could write code to iterate through the scene, applying transformations on bound objects,
but the Scene object already does this for you via its <a class="reference internal" href="reference/generated/collada.scene.Scene.html#collada.scene.Scene.objects" title="collada.scene.Scene.objects"><tt class="xref py py-meth docutils literal"><span class="pre">Scene.objects()</span></tt></a> method. For
example, to find all of the instantiated geometries in a scene and have them bound to a
material and transformation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">boundgeoms</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">mesh</span><span class="o">.</span><span class="n">scene</span><span class="o">.</span><span class="n">objects</span><span class="p">(</span><span class="s">'geometry'</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">boundgeoms</span>
<span class="go">[<BoundGeometry id=LOD3spShape-lib, 1 primitives>]</span>
</pre></div>
</div>
<p>Notice that we get a <a class="reference internal" href="reference/generated/collada.geometry.BoundGeometry.html#collada.geometry.BoundGeometry" title="collada.geometry.BoundGeometry"><tt class="xref py py-class docutils literal"><span class="pre">BoundGeometry</span></tt></a> here. We can also pass in <cite>light</cite>, <cite>camera</cite>, or
<cite>controller</cite> to get back a <a class="reference internal" href="reference/generated/collada.light.BoundLight.html#collada.light.BoundLight" title="collada.light.BoundLight"><tt class="xref py py-class docutils literal"><span class="pre">BoundLight</span></tt></a>, <a class="reference internal" href="reference/generated/collada.camera.BoundCamera.html#collada.camera.BoundCamera" title="collada.camera.BoundCamera"><tt class="xref py py-class docutils literal"><span class="pre">BoundCamera</span></tt></a>, or <a class="reference internal" href="reference/generated/collada.controller.BoundController.html#collada.controller.BoundController" title="collada.controller.BoundController"><tt class="xref py py-class docutils literal"><span class="pre">BoundController</span></tt></a>,
respectively. The bound geometry is very similar to the geometry we looked through above. We can use
the iterative method:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">boundprims</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">boundgeoms</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">primitives</span><span class="p">())</span>
<span class="gp">>>> </span><span class="n">boundprims</span>
<span class="go">[<BoundTriangleSet length=4212>]</span>
<span class="gp">>>> </span><span class="n">boundtrilist</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">boundprims</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">boundtrilist</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go"><Triangle ([-23.93639946 -30.61249924 11.53530025], [-18.72640038 -26.6814003 10.1079998 ], [-15.69919968 -34.23210144 11.42780018], "<Material id=blinn3 effect=blinn3-fx>")></span>
</pre></div>
</div>
<p>or by accessing the numpy arrays directly:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">boundprims</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">vertex</span><span class="p">[</span><span class="n">boundprims</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">vertex_index</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
<span class="go">array([[-23.93639946, -30.61249924, 11.53530025],</span>
<span class="go"> [-18.72640038, -26.6814003 , 10.1079998 ],</span>
<span class="go"> [-15.69919968, -34.23210144, 11.42780018]], dtype=float32)</span>
</pre></div>
</div>
<p>In this case, the triangle is identical to above. This is because the collada duck example only has
identity transformations. We can inspect these in the scene:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">mesh</span><span class="o">.</span><span class="n">scene</span><span class="o">.</span><span class="n">nodes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">transforms</span>
<span class="go">[<RotateTransform (0.0, 0.0, 1.0) angle=0.0>, <RotateTransform (0.0, 1.0, 0.0) angle=0.0>, <RotateTransform (1.0, 0.0, 0.0) angle=0.0>]</span>
<span class="gp">>>> </span><span class="n">mesh</span><span class="o">.</span><span class="n">scene</span><span class="o">.</span><span class="n">nodes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">children</span>
<span class="go">[<GeometryNode geometry=LOD3spShape-lib>]</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="creating.html" title="Creating A Collada Object"
>next</a> |</li>
<li class="right" >
<a href="loading.html" title="Loading A Collada Document"
>previous</a> |</li>
<li><a href="index.html">pycollada 0.4 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2011, Jeff Terrace and contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.
</div>
</body>
</html>
|