InstancedMesh.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Mesh] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. A special version of [page:Mesh] with instanced rendering support. Use [name] if you have to render a large number of
  14. objects with the same geometry and material but with different world transformations. The usage of [name] will help you
  15. to reduce the number of draw calls and thus improve the overall rendering performance in your application.
  16. </p>
  17. <p>
  18. The current implementation requires that materials are not shared between [name] and other 3D objects.
  19. </p>
  20. <h2>Examples</h2>
  21. <p>
  22. [example:webgl_instancing_dynamic WebGL / instancing / dynamic]<br />
  23. [example:webgl_instancing_modified WebGL / instancing / modified]<br />
  24. [example:webgl_instancing_performance WebGL / instancing / performance]<br />
  25. [example:webgl_instancing_scatter WebGL / instancing / scatter]<br />
  26. [example:webgl_instancing_raycast WebGL / instancing / raycast]
  27. </p>
  28. <h2>Constructor</h2>
  29. <h3>[name]( [param:BufferGeometry geometry], [param:Material material], [param:Integer count] )</h3>
  30. <p>
  31. [page:BufferGeometry geometry] - an instance of [page:BufferGeometry].<br />
  32. [page:Material material] - an instance of [page:Material]. Default is a new [page:MeshBasicMaterial].<br />
  33. [page:Integer count] - the number of instances.<br />
  34. </p>
  35. <h2>Properties</h2>
  36. <p>See the base [page:Mesh] class for common properties.</p>
  37. <h3>[property:Integer count]</h3>
  38. <p>
  39. The number of instances. The *count* value passed into the constructor represents the maximum number of
  40. instances of this mesh. You can change the number of instances at runtime to an integer value
  41. in the range [0, count].
  42. </p>
  43. <p>
  44. If you need more instances than the original count value, you have to create a new [name].
  45. </p>
  46. <h3>[property:BufferAttribute instanceColor]</h3>
  47. <p>
  48. Represents the colors of all instances. *null* by default.
  49. You have to set its [page:BufferAttribute.needsUpdate needsUpdate] flag to true if you modify instanced data via [page:.setColorAt]().
  50. </p>
  51. <h3>[property:BufferAttribute instanceMatrix]</h3>
  52. <p>
  53. Represents the local transformation of all instances.
  54. You have to set its [page:BufferAttribute.needsUpdate needsUpdate] flag to true if you modify instanced data via [page:.setMatrixAt]().
  55. </p>
  56. <h2>Methods</h2>
  57. <p>See the base [page:Mesh] class for common methods.</p>
  58. <h3>[method:null dispose]()</h3>
  59. <p>
  60. Frees the internal resources of this instance.
  61. </p>
  62. <h3>[method:null getColorAt]( [param:Integer index], [param:Color color] )</h3>
  63. <p>
  64. [page:Integer index]: The index of an instance. Values have to be in the range [0, count].
  65. </p>
  66. <p>
  67. [page:Color color]: This color object will be set to the color of the defined instance.
  68. </p>
  69. <p>
  70. Get the color of the defined instance.
  71. </p>
  72. <h3>[method:null getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
  73. <p>
  74. [page:Integer index]: The index of an instance. Values have to be in the range [0, count].
  75. </p>
  76. <p>
  77. [page:Matrix4 matrix]: This 4x4 matrix will be set to the local transformation matrix of the defined instance.
  78. </p>
  79. <p>
  80. Get the local transformation matrix of the defined instance.
  81. </p>
  82. <h3>[method:null setColorAt]( [param:Integer index], [param:Color color] )</h3>
  83. <p>
  84. [page:Integer index]: The index of an instance. Values have to be in the range [0, count].
  85. </p>
  86. <p>
  87. [page:Color color]: The color of a single instance.
  88. </p>
  89. <p>
  90. Sets the given color to the defined instance.
  91. Make sure you set [page:.instanceColor][page:BufferAttribute.needsUpdate .needsUpdate] to true after updating all the colors.
  92. </p>
  93. <h3>[method:null setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
  94. <p>
  95. [page:Integer index]: The index of an instance. Values have to be in the range [0, count].
  96. </p>
  97. <p>
  98. [page:Matrix4 matrix]: A 4x4 matrix representing the local transformation of a single instance.
  99. </p>
  100. <p>
  101. Sets the given local transformation matrix to the defined instance.
  102. Make sure you set [page:.instanceMatrix][page:BufferAttribute.needsUpdate .needsUpdate] to true after updating all the matrices.
  103. </p>
  104. <h2>Source</h2>
  105. <p>
  106. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  107. </p>
  108. </body>
  109. </html>