1
0

MeshSurfaceSampler.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE html>
  2. <html lang="zh">
  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">用于在网格表面上对加权随机点进行采样的实用类。</p>
  12. <p>加权采样对于诸如地形的特定区域内更浓密的植被生长或来自网格特定部分的浓缩粒子排放等效果非常有用。顶点权重可以通过编程方式编写,也可以在 3D 工具(如 Blender)中作为顶点颜色手工绘制。</p>
  13. <h2>导入</h2>
  14. <p>
  15. [name] 是一个附加组件,必须显式导入。请参阅 [link:#manual/introduction/Installation Installation / Addons].
  16. </p>
  17. <code>
  18. import { MeshSurfaceSampler } from 'three/addons/math/MeshSurfaceSampler.js';
  19. </code>
  20. <h2>代码示例</h2>
  21. <code>
  22. // Create a sampler for a Mesh surface.
  23. const sampler = new MeshSurfaceSampler( surfaceMesh )
  24. .setWeightAttribute( 'color' )
  25. .build();
  26. const mesh = new THREE.InstancedMesh( sampleGeometry, sampleMaterial, 100 );
  27. const position = new THREE.Vector3();
  28. const matrix = new THREE.Matrix4();
  29. // Sample randomly from the surface, creating an instance of the sample
  30. // geometry at each sample point.
  31. for ( let i = 0; i < 100; i ++ ) {
  32. sampler.sample( position );
  33. matrix.makeTranslation( position.x, position.y, position.z );
  34. mesh.setMatrixAt( i, matrix );
  35. }
  36. scene.add( mesh );
  37. </code>
  38. <h2>例子</h2>
  39. <p>
  40. [example:webgl_instancing_scatter]
  41. </p>
  42. <h2>构造函数</h2>
  43. <h3>[name]( [param:Mesh mesh] )</h3>
  44. <p>
  45. [page:Mesh mesh] — ​​进行采样的表面网格。
  46. </p>
  47. <p>
  48. 创建一个新的 [name]。如果输入的几何体是索引的,将创建一个非索引的副本。构造后,采样器无法返回样本,直到调用 [page:MeshSurfaceSampler.build build] 方法。
  49. </p>
  50. <h2>方法</h2>
  51. <h3>[method:this setWeightAttribute]( [param:String name] )</h3>
  52. <p>
  53. 指定从表面采样时用作权重的顶点属性。权重较高的面更有可能被采样,而权重为零的面则根本不会被采样。对于向量属性,仅使用 <i>.x</i> 进行采样。
  54. </p>
  55. <p>如果没有选择权重属性,则按区域随机分布采样。</p>
  56. <h3>[method:this build]()</h3>
  57. <p>
  58. 处理输入几何体并准备返回样本。几何体或采样器的任何配置都必须在调用此方法之前进行。对于具有 <i>n</i> 个面的曲面,时间复杂度为<i>O(n)</i>。
  59. </p>
  60. <h3>[method:this sample]( [param:Vector3 targetPosition], [param:Vector3 targetNormal], [param:Color targetColor],
  61. [param:Vector2 targetUV] )</h3>
  62. <p>
  63. 选择输入几何体表面上的随机点,返回该点的位置以及可选的法线向量、颜色和 UV 坐标。对于具有 <i>n</i> 个面的曲面,时间复杂度为<i>O(n)</i>。
  64. </p>
  65. <h2>源代码</h2>
  66. <p>
  67. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/math/MeshSurfaceSampler.js examples/jsm/math/MeshSurfaceSampler.js]
  68. </p>
  69. </body>
  70. </html>