mesh.adoc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. = Polygon Meshes
  2. :revnumber: 2.0
  3. :revdate: 2020/07/22
  4. :keywords: spatial, node, mesh, geometry, scenegraph
  5. image::scene/dolphin-mesh.png[dolphin-mesh.png,width="",height="",align="right"]
  6. All visible game elements in a scene, whether it is a Model or a Shape, are made up of polygon meshes. JME3 has a link:{link-javadoc}/com/jme3/scene/Mesh.html[com.jme3.scene.Mesh] class that represents all meshes.
  7. * Meshes are made up of triangles: `getTriangleCount(…)` and `getTriangle(…)`
  8. * Each mesh has a unique ID: `getId()`
  9. * Meshes have transformations: Location (local translation), rotation, scale.
  10. * Meshes have a bounding volume. jME3 can detect intersections (that is, non-physical collisions) between meshes, or between meshes and 2D elements such as rays: `collideWith()`.
  11. * Meshes are locked with `setStatic()` and unlocked with `setDynamic()`.
  12. ** Static Meshes cannot be modified, but are more optimized and faster (they can be precalculated).
  13. ** Dynamic Meshes can be modified live, but are not optimized and slower.
  14. You have several options when xref:scene/spatial.adoc[creating Geometries from meshes]:
  15. * Use built-in xref:scene/shape/shape.adoc[Shape]s as meshes;
  16. * Load xref:scene/3d_models.adoc[3D models] (that is, meshes created in external applications); or
  17. * Create free-form xref:scene/custom_meshes.adoc[custom meshes] programmatically.
  18. == Vertex Buffer
  19. The VertexBuffer contains a particular type of geometry data used by Meshes. Every VertexBuffer set on a Mesh is sent as an attribute to the vertex shader to be processed.
  20. === Mesh Vertex Buffers
  21. Here is the list of link:{link-javadoc}/com/jme3/scene/VertexBuffer.Type.html[VertexBuffer] types.
  22. [cols="2", options="header"]
  23. |===
  24. a|Vertex Buffer Type
  25. a|Description
  26. a|Type.Position
  27. a|Position of the vertex (3 floats)
  28. a|Type.Index
  29. a| Specifies the index buffer, must contain integer data.
  30. a|Type.TexCoord
  31. a| Texture coordinate
  32. a|Type.TexCoord2
  33. a| Texture coordinate #2
  34. a|Type.Normal
  35. a| Normal vector, normalized.
  36. a|Type.Tangent
  37. a| Tangent vector, normalized.
  38. a|Type.Binormal
  39. a| Binormal vector, normalized.
  40. a|Type.Color
  41. a| Color and Alpha (4 floats)
  42. a|Type.Size
  43. a|The size of the point when using point buffers.
  44. a|Type.InterleavedData
  45. a| Specifies the source data for various vertex buffers when interleaving is used.
  46. a|Type.BindPosePosition
  47. a| Initial vertex position, used with animation.
  48. a|Type.BindPoseNormal
  49. a| Initial vertex normals, used with animation
  50. a|Type.BoneWeight
  51. a| Bone weights, used with animation
  52. a|Type.BoneIndex
  53. a| Bone indices, used with animation
  54. |===
  55. === Mesh Properties
  56. Some Mesh properties from the link:{link-javadoc}/com/jme3/scene/Mesh.html[Mesh] class.
  57. [cols="2", options="header"]
  58. |===
  59. a|Mesh method
  60. a|Description
  61. a|setBound(boundingVolume)
  62. a|if you need to specify a custom optimized bounding volume
  63. a|setStatic()
  64. a|Locks the mesh so you cannot modify it anymore, thus optimizing its data (faster).
  65. a|setDynamic()
  66. a|Unlocks the mesh so you can modified it, but this will un-optimize the data (slower).
  67. a|setMode(Mesh.Mode.Points)
  68. a|Used to set mesh rendering modes, see below.
  69. a|getId()
  70. a|returns the Mesh ID, default value is -1
  71. a|getTriangle(int,tri)
  72. a|returns data of triangle number `int` into variable `tri`
  73. a|scaleTextureCoordinates(Vector2f)
  74. a|How the texture will be stretched over the whole mesh.
  75. |===
  76. === Mesh Rendering Modes
  77. Here is the list of link:{link-javadoc}/com/jme3/scene/Mesh.Mode.html[Mesh rendering modes].
  78. [cols="2", options="header"]
  79. |===
  80. a|Mesh Mode
  81. a|Description
  82. a|Mesh.Mode.Points
  83. a|Show only corner points (vertices) of mesh
  84. a|Mesh.Mode.Lines
  85. a|Show lines (edges) of mesh
  86. a|Mesh.Mode.LineLoop
  87. a|?
  88. a|Mesh.Mode.LineStrip
  89. a|?
  90. a|Mesh.Mode.Triangles
  91. a|?
  92. a|Mesh.Mode.TriangleStrip
  93. a|?
  94. a|Mesh.Mode.TriangleFan
  95. a|?
  96. a|Mesh.Mode.Hybrid
  97. a|?
  98. |===
  99. === Level of Detail
  100. Optionally, custom meshes can have a LOD (level of detail optimization) that renders more or less detail, depending on the distance of the mesh from the camera. You have to specify several vertex buffers, one for each level of detail you want (very far away with few details, close up with all details, and something in the middle). Use `setLodLevels(VertexBuffer[] lodLevels)`.