mesh.adoc 4.2 KB

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