SceneUtils.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. <h1>[name]</h1>
  11. <p class="desc">
  12. A class containing useful utility functions for scene manipulation.
  13. </p>
  14. <h2>Import</h2>
  15. <p>
  16. [name] is an add-on, and must be imported explicitly.
  17. See [link:#manual/introduction/Installation Installation / Addons].
  18. </p>
  19. <code>
  20. import * as SceneUtils from 'three/addons/utils/SceneUtils.js';
  21. </code>
  22. <h2>Methods</h2>
  23. <h3>[method:Group createMeshesFromInstancedMesh]( [param:InstancedMesh instancedMesh] )</h3>
  24. <p>
  25. instancedMesh -- The instanced mesh.
  26. </p>
  27. <p>
  28. Creates a new group object that contains a new mesh for each instance of the given instanced mesh.
  29. </p>
  30. <h3>[method:Group createMeshesFromMultiMaterialMesh]( [param:Mesh mesh] )</h3>
  31. <p>
  32. mesh -- A mesh with multiple materials.
  33. </p>
  34. <p>
  35. Converts the given multi-material mesh into an instance of [page:Group] holding for each material a separate mesh.
  36. </p>
  37. <h3>[method:Group createMultiMaterialObject]( [param:BufferGeometry geometry], [param:Array materials] )</h3>
  38. <p>
  39. geometry -- The geometry for the set of materials. <br />
  40. materials -- The materials for the object.
  41. </p>
  42. <p>
  43. Creates a new Group that contains a new mesh for each material defined in materials. Beware that this is not the same as an array of materials which defines multiple materials for 1 mesh.<br />
  44. This is mostly useful for objects that need both a material and a wireframe implementation.
  45. </p>
  46. <h3>[method:T reduceVertices]( [param:Object3D object], [param:function func], [param:T initialValue] )</h3>
  47. <p>
  48. object -- The object to traverse (uses [page:Object3D.traverseVisible traverseVisible] internally). <br />
  49. func -- The binary function applied for the reduction. Must have the signature: (value: T, vertex: Vector3): T. <br />
  50. initialValue -- The value to initialize the reduction with. This is required
  51. as it also sets the reduction type, which is not required to be Vector3.
  52. </p>
  53. <p>
  54. Akin to Array.prototype.reduce(), but operating on the vertices of all the
  55. visible descendant objects, in world space. Additionally, it can operate as a
  56. transform-reduce, returning a different type T than the Vector3 input. This
  57. can be useful for e.g. fitting a viewing frustum to the scene.
  58. </p>
  59. <h3>[method:undefined sortInstancedMesh]( [param:InstancedMesh mesh], [param:Function compareFn] )</h3>
  60. <p>
  61. mesh -- InstancedMesh in which instances will be sorted. <br />
  62. compareFn -- Comparator function defining the sort order.
  63. </p>
  64. <p>
  65. Sorts the instances within an [page:InstancedMesh], according to a user-defined
  66. callback. The callback will be provided with two arguments, <i>indexA</i>
  67. and <i>indexB</i>, and must return a numerical value. See
  68. [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description Array.prototype.sort]
  69. for more information on sorting callbacks and their return values.
  70. </p>
  71. <p>
  72. Because of the high performance cost, three.js does not sort
  73. [page:InstancedMesh] instances automatically. Manually sorting may be
  74. helpful to improve display of alpha blended materials (back to front),
  75. and to reduce overdraw in opaque materials (front to back).
  76. </p>
  77. <h3>[method:Generator traverseGenerator]( [param:Object3D object] )</h3>
  78. <p>
  79. object -- The 3D object to traverse.
  80. </p>
  81. <p>
  82. A generator based version of [page:Object3D.traverse]().
  83. </p>
  84. <h3>[method:Generator traverseVisibleGenerator]( [param:Object3D object] )</h3>
  85. <p>
  86. object -- The 3D object to traverse.
  87. </p>
  88. <p>
  89. A generator based version of [page:Object3D.traverseVisible]().
  90. </p>
  91. <h3>[method:Generator traverseAncestorsGenerator]( [param:Object3D object] )</h3>
  92. <p>
  93. object -- The 3D object to traverse.
  94. </p>
  95. <p>
  96. A generator based version of [page:Object3D.traverseAncestors]().
  97. </p>
  98. <h2>Source</h2>
  99. <p>
  100. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/utils/SceneUtils.js examples/jsm/utils/SceneUtils.js]
  101. </p>
  102. </body>
  103. </html>