shape.html 14 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><meta name="keywords" content="spatial, node, mesh, geometry, scenegraph"><title>Shapes</title><link rel="stylesheet" href="./asciidoctor.css">
  2. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  3. <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/advanced/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/advanced/shape.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/advanced/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>Shapes</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#3d-shapes">3D shapes</a></li><li><a href="#non-3d-shapes">Non-3D shapes</a><ul class="sectlevel2"><li><a href="#com-jme3-math-versus-com-jme3-shape">com.jme3.math versus com.jme3.shape?</a></li></ul></li><li><a href="#usage">Usage</a><ul class="sectlevel2"><li><a href="#basic-usage">Basic Usage</a></li><li><a href="#complex-shapes">Complex Shapes</a></li></ul></li><li><a href="#code-examples">Code Examples</a></li><li><a href="#see-also">See also</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p>The simplest type of Meshes are the built-in JME Shapes. You can create Shapes without using the AssetManager.</p></div></div></div>
  4. <div class="sect1"><h2 id="3d-shapes">3D shapes</h2><div class="sectionbody"><div class="openblock float-group"><div class="content"><div class="imageblock right text-left"><div class="content"><img src="../../jme3/advanced/box.png" alt="box.png" width="108" height=""></div></div>
  5. <div class="ulist"><ul><li><p>com.jme3.scene.shape.Box – A cube or cuboid. Single-sided Quad faces (outside only).</p></li><li><p>com.jme3.scene.shape.StripBox – A cube or cuboid. Solid filled faces (inside and outside).</p></li></ul></div></div></div>
  6. <div class="openblock float-group"><div class="content"><div class="imageblock right text-left"><div class="content"><img src="../../jme3/advanced/cylinder.png" alt="cylinder.png" width="108" height=""></div></div>
  7. <div class="ulist"><ul><li><p>com.jme3.scene.shape.Cylinder – A disk or pillar.</p></li></ul></div></div></div>
  8. <div class="openblock float-group"><div class="content"><div class="imageblock right text-left"><div class="content"><img src="../../jme3/advanced/sphere.png" alt="sphere.png" width="108" height=""></div></div>
  9. <div class="ulist"><ul><li><p>com.jme3.scene.shape.Sphere – A ball or elipsoid.</p></li></ul></div></div></div>
  10. <div class="openblock float-group"><div class="content"><div class="imageblock right text-left"><div class="content"><img src="../../jme3/advanced/dome.png" alt="dome.png" width="108" height=""></div></div>
  11. <div class="ulist"><ul><li><p>com.jme3.scene.shape.Dome – A semi-sphere, e.g. SkyDome.</p></li></ul></div></div></div>
  12. <div class="openblock float-group"><div class="content"><div class="imageblock right text-left"><div class="content"><img src="../../jme3/advanced/cone.png" alt="cone.png" width="108" height=""></div></div>
  13. <div class="ulist"><ul><li><p>For a cone, set the Dome&#8217;s radialSamples&gt;4 and planes=2.</p></li></ul></div></div></div>
  14. <div class="openblock float-group"><div class="content"><div class="imageblock right text-left"><div class="content"><img src="../../jme3/advanced/pyramid.png" alt="pyramid.png" width="108" height=""></div></div>
  15. <div class="ulist"><ul><li><p>For a pyramid, set the Dome&#8217;s radialSamples=4 and planes=2.</p></li></ul></div></div></div>
  16. <div class="openblock float-group"><div class="content"><div class="imageblock right text-left"><div class="content"><img src="http://i204.photobucket.com/albums/bb19/mike_ch_1/torus.png" alt="Torus" width="108" height="80"></div></div>
  17. <div class="ulist"><ul><li><p>com.jme3.scene.shape.Torus – An single-holed torus or “donut.</p></li></ul></div></div></div>
  18. <div class="openblock float-group"><div class="content"><div class="imageblock right text-left"><div class="content"><img src="../../jme3/advanced/220px-trefoil_knot_arb.png" alt="PQ torus knoz" width="108" height="80"></div></div>
  19. <div class="ulist"><ul><li><p>com.jme3.scene.shape.PQTorus – A parameterized torus. A PQ-Torus looks like a <a href="http://en.wikipedia.org/wiki/Torus_knot">donut knotted into spirals</a>.</p></li></ul></div></div></div>
  20. <div class="openblock float-group"><div class="content"><div class="imageblock right text-left"><div class="content"><img src="../../jme3/advanced/nurbs_3-d_surface.png" alt="NURBS surface" width="108" height="80"></div></div>
  21. <div class="ulist"><ul><li><p>com.jme3.scene.shape.Surface – A curved surface (called <a href="http://en.wikipedia.org/wiki/File:NURBS_3-D_surface.gif">NURBS</a>) described by knots, weights and control points. Compare with shape.Curve.</p></li></ul></div></div></div></div></div>
  22. <div class="sect2"><h3 id="non-3d-shapes">Non-3D shapes</h3><div class="ulist"><ul><li><p>com.jme3.scene.shape.Quad – A flat 2D rectangle (single-sided, center is in bottom-left corner)</p></li><li><p>com.jme3.scene.shape.Line – A straight 1D line defined by a start and end point.</p></li><li><p>com.jme3.scene.shape.Curve – A curved 1D spline. Compare with shape.Surface.</p></li></ul></div>
  23. <div class="sect2"><h3 id="com-jme3-math-versus-com-jme3-shape">com.jme3.math versus com.jme3.shape?</h3><div class="paragraph"><p>Do not mix up these visible com.jme3.shapes with similarly named classes from the com.jme3.math package. Choose the right package when letting your IDE fill in the import statements!</p></div>
  24. <div class="ulist"><ul><li><p>com.jme3.math.Line – is invisible, has a direction, goes through a point, infinite length.</p></li><li><p>com.jme3.math.Ray – is invisible, has a direction and start point, but no end.</p></li><li><p>com.jme3.math.Spline – is an invisible curve.</p></li><li><p>etc</p></li></ul></div>
  25. <div class="paragraph"><p>These maths objects are invisible and are used for collision testing (ray casting) or to describe motion paths. They cannot be wrapped into a Geometry.</p></div></div></div>
  26. <div class="sect2"><h3 id="usage">Usage</h3><div class="sect2"><h3 id="basic-usage">Basic Usage</h3><div class="paragraph"><p>To add a shape to the scene:</p></div>
  27. <div class="olist arabic"><ol class="arabic"><li><p>Create the base mesh shape.</p></li><li><p>Wrap the mesh into a Geometry.</p></li><li><p>Assign a Material to the Geometry.</p></li><li><p>Attach the Geometry to the rootNode to make it visible.</p></li></ol></div>
  28. <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>Create one static shape as mesh and use it in several geometries, or clone() the geometries.</p></div></td></tr></table></div></div>
  29. <div class="sect2"><h3 id="complex-shapes">Complex Shapes</h3><div class="paragraph"><p>You can compose more complex custom Geometries out of simple Shapes. Think of the buildings in games like Angry Birds, or the building blocks in Second Life (“prims) and in Tetris (“Tetrominos).</p></div>
  30. <div class="olist arabic"><ol class="arabic"><li><p>Create a Node. By default it is located at the origin (0/0/0) – leave the Node there for now.</p></li><li><p>Create your shapes and wrap each into a Geometry, as just described.</p></li><li><p>Attach each Geometry to the Node.</p></li><li><p>Arrange the Geometries around the Node (using <code>setLocalTranslation()</code>) so that the Node is in the center of the new constellation. The central Node is the pivot point for transformations (move/scale/rotate).</p></li><li><p>Move the pivot Node to its final location in the scene. Moving the pivot Node moves the attached constellation of Geometries with it.</p></li></ol></div>
  31. <div class="paragraph"><p>The order is important: First arrange around origin, then transform. Otherwise, transformations are applied around the wrong center (pivot). Of course, you can attach your constellation to other pivot Nodes to create even more complex shapes (a chair, a furnished room, a house, a city, …), but again, arrange them around the origin first before you transform them. Obviously, such composed Geometries are simpler than hand-sculpted meshes from a mesh editor.</p></div></div></div>
  32. <div class="sect1"><h2 id="code-examples">Code Examples</h2><div class="sectionbody"><div class="paragraph"><p>Create the Mesh shape:</p></div>
  33. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">Sphere mesh = <span class="keyword">new</span> Sphere(<span class="integer">32</span>, <span class="integer">32</span>, <span class="integer">10</span>, <span class="predefined-constant">false</span>, <span class="predefined-constant">true</span>);</code></pre></div></div>
  34. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">Dome mesh = <span class="keyword">new</span> Dome(Vector3f.ZERO, <span class="integer">2</span>, <span class="integer">4</span>, <span class="float">1f</span>,<span class="predefined-constant">false</span>); <span class="comment">// Pyramid</span></code></pre></div></div>
  35. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">Dome mesh = <span class="keyword">new</span> Dome(Vector3f.ZERO, <span class="integer">2</span>, <span class="integer">32</span>, <span class="float">1f</span>,<span class="predefined-constant">false</span>); <span class="comment">// Cone</span></code></pre></div></div>
  36. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">Dome mesh = <span class="keyword">new</span> Dome(Vector3f.ZERO, <span class="integer">32</span>, <span class="integer">32</span>, <span class="float">1f</span>,<span class="predefined-constant">false</span>); <span class="comment">// Small hemisphere</span></code></pre></div></div>
  37. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">Dome mesh = <span class="keyword">new</span> Dome(Vector3f.ZERO, <span class="integer">32</span>, <span class="integer">32</span>, <span class="float">1000f</span>,<span class="predefined-constant">true</span>); <span class="comment">// SkyDome</span></code></pre></div></div>
  38. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">PQTorus mesh = <span class="keyword">new</span> PQTorus(<span class="integer">5</span>,<span class="integer">3</span>, <span class="float">2f</span>, <span class="float">1f</span>, <span class="integer">32</span>, <span class="integer">32</span>); <span class="comment">// Spiral torus</span></code></pre></div></div>
  39. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">PQTorus mesh = <span class="keyword">new</span> PQTorus(<span class="integer">3</span>,<span class="integer">8</span>, <span class="float">2f</span>, <span class="float">1f</span>, <span class="integer">32</span>, <span class="integer">32</span>); <span class="comment">// Flower torus</span></code></pre></div></div>
  40. <div class="paragraph"><p>Use one of the above examples together with the following geometry in a scene:</p></div>
  41. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">Geometry geom = <span class="keyword">new</span> Geometry(<span class="string"><span class="delimiter">&quot;</span><span class="content">A shape</span><span class="delimiter">&quot;</span></span>, mesh); <span class="comment">// wrap shape into geometry</span>
  42. Material mat = <span class="keyword">new</span> Material(assetManager,
  43. <span class="string"><span class="delimiter">&quot;</span><span class="content">Common/MatDefs/Misc/ShowNormals.j3md</span><span class="delimiter">&quot;</span></span>); <span class="comment">// create material</span>
  44. geom.setMaterial(mat); <span class="comment">// assign material to geometry</span>
  45. <span class="comment">// if you want, transform (move, rotate, scale) the geometry.</span>
  46. rootNode.attachChild(geom); <span class="comment">// attach geometry to a node</span></code></pre></div></div></div></div>
  47. <div class="sect1"><h2 id="see-also">See also</h2><div class="sectionbody"><div class="ulist"><ul><li><p><a href="../../jme3/intermediate/optimization.html">Optimization</a> – The GeometryBatchFactory class combines several of your shapes with the same texture into one mesh with one texture.</p></li></ul></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-20 23:30:51 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
  48. apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
  49. indexName: 'jmonkeyengine',
  50. inputSelector: '#doc-search',
  51. debug: false // Set debug to true if you want to inspect the dropdown
  52. });</script></body></html>