shape.adoc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. = Shapes
  2. :revnumber: 2.1
  3. :revdate: 2020/07/23
  4. :keywords: spatial, node, mesh, geometry, scenegraph
  5. The simplest type of Meshes are the built-in JME Shapes. You can create Shapes without using the AssetManager.
  6. == 3D shapes
  7. [.float-group]
  8. --
  9. [.right.text-left]
  10. image::scene/shape/box.png[box.png,width="108",height=""]
  11. * com.jme3.scene.shape.Box – A cube or cuboid. Single-sided Quad faces (outside only).
  12. * com.jme3.scene.shape.StripBox – A cube or cuboid. Solid filled faces (inside and outside).
  13. --
  14. [.float-group]
  15. --
  16. [.right.text-left]
  17. image::scene/shape/cylinder.png[cylinder.png,width="108",height=""]
  18. * com.jme3.scene.shape.Cylinder – A disk or pillar.
  19. --
  20. [.float-group]
  21. --
  22. [.right.text-left]
  23. image::scene/shape/sphere.png[sphere.png,width="108",height=""]
  24. * com.jme3.scene.shape.Sphere – A ball or ellipsoid.
  25. --
  26. [.float-group]
  27. --
  28. [.right.text-left]
  29. image::scene/shape/dome.png[dome.png,width="108",height=""]
  30. * com.jme3.scene.shape.Dome – A semi-sphere, e.g. SkyDome.
  31. --
  32. [.float-group]
  33. --
  34. [.right.text-left]
  35. image::scene/shape/cone.png[cone.png,width="108",height=""]
  36. * For a cone, set the Dome's radialSamples>4 and planes=2.
  37. --
  38. [.float-group]
  39. --
  40. [.right.text-left]
  41. image::scene/shape/pyramid.png[pyramid.png,width="108",height=""]
  42. * For a pyramid, set the Dome's radialSamples=4 and planes=2.
  43. --
  44. [.float-group]
  45. --
  46. [.right.text-left]
  47. image::http://i204.photobucket.com/albums/bb19/mike_ch_1/torus.png[Torus,width="108",height="80"]
  48. * com.jme3.scene.shape.Torus – An single-holed torus or "`donut`".
  49. --
  50. [.float-group]
  51. --
  52. [.right.text-left]
  53. image::scene/shape/220px-trefoil_knot_arb.png[PQ torus knoz,width="108",height="80"]
  54. * com.jme3.scene.shape.PQTorus – A parameterized torus. A PQ-Torus looks like a link:http://en.wikipedia.org/wiki/Torus_knot[donut knotted into spirals].
  55. --
  56. [.float-group]
  57. --
  58. [.right.text-left]
  59. image::scene/shape/nurbs_3-d_surface.png[NURBS surface,width="108",height="80"]
  60. * com.jme3.scene.shape.Surface – A curved surface (called link:http://en.wikipedia.org/wiki/File:NURBS_3-D_surface.gif[NURBS]) described by knots, weights and control points. Compare with shape.Curve.
  61. --
  62. == Non-3D shapes
  63. * com.jme3.scene.shape.Quad – A flat 2D rectangle (single-sided, center is in bottom-left corner)
  64. * com.jme3.scene.shape.Line – A straight 1D line defined by a start and end point.
  65. * com.jme3.scene.shape.Curve – A curved 1D spline. Compare with shape.Surface.
  66. === com.jme3.math versus com.jme3.shape?
  67. 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!
  68. * com.jme3.math.Line – is invisible, has a direction, goes through a point, infinite length.
  69. * com.jme3.math.Ray – is invisible, has a direction and start point, but no end.
  70. * com.jme3.math.Spline – is an invisible curve.
  71. * etc
  72. 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.
  73. == Usage
  74. === Basic Usage
  75. To add a shape to the scene:
  76. . Create the base mesh shape.
  77. . Wrap the mesh into a Geometry.
  78. . Assign a Material to the Geometry.
  79. . Attach the Geometry to the rootNode to make it visible.
  80. [TIP]
  81. ====
  82. Create one static shape as mesh and use it in several geometries, or clone() the geometries.
  83. ====
  84. === Complex Shapes
  85. 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).
  86. . Create a Node. By default it is located at the origin (0/0/0) – leave the Node there for now.
  87. . Create your shapes and wrap each into a Geometry, as just described.
  88. . Attach each Geometry to the Node.
  89. . Arrange the Geometries around the Node (using `setLocalTranslation()`) so that the Node is in the center of the new constellation. The central Node is the pivot point for transformations (move/scale/rotate).
  90. . Move the pivot Node to its final location in the scene. Moving the pivot Node moves the attached constellation of Geometries with it.
  91. 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.
  92. == Code Examples
  93. Create the Mesh shape:
  94. [source,java]
  95. ----
  96. Sphere mesh = new Sphere(32, 32, 10, false, true);
  97. ----
  98. [source,java]
  99. ----
  100. Dome mesh = new Dome(Vector3f.ZERO, 2, 4, 1f,false); // Pyramid
  101. ----
  102. [source,java]
  103. ----
  104. Dome mesh = new Dome(Vector3f.ZERO, 2, 32, 1f,false); // Cone
  105. ----
  106. [source,java]
  107. ----
  108. Dome mesh = new Dome(Vector3f.ZERO, 32, 32, 1f,false); // Small hemisphere
  109. ----
  110. [source,java]
  111. ----
  112. Dome mesh = new Dome(Vector3f.ZERO, 32, 32, 1000f,true); // SkyDome
  113. ----
  114. [source,java]
  115. ----
  116. PQTorus mesh = new PQTorus(5,3, 2f, 1f, 32, 32); // Spiral torus
  117. ----
  118. [source,java]
  119. ----
  120. PQTorus mesh = new PQTorus(3,8, 2f, 1f, 32, 32); // Flower torus
  121. ----
  122. Use one of the above examples together with the following geometry in a scene:
  123. [source,java]
  124. ----
  125. Geometry geom = new Geometry("A shape", mesh); // wrap shape into geometry
  126. Material mat = new Material(assetManager,
  127. "Common/MatDefs/Misc/ShowNormals.j3md"); // create material
  128. geom.setMaterial(mat); // assign material to geometry
  129. // if you want, transform (move, rotate, scale) the geometry.
  130. rootNode.attachChild(geom); // attach geometry to a node
  131. ----
  132. == See also
  133. * xref:tutorials:concepts/optimization.adoc[Optimization] – The GeometryBatchFactory class combines several of your shapes with the same texture into one mesh with one texture.