PLYLoader.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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:Loader] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. A loader for the PLY (Polygon File Format) file format, also known as the Stanford Triangle Format. [name] supports both ASCII and binary files as well as the following PLY properties:
  14. <ul>
  15. <li>x, y, z (vertex positions)</li>
  16. <li>nx, ny, nz (vertex normals)</li>
  17. <li>s, t / u, v (texture coordinates)</li>
  18. <li>red, green, blue (vertex colors)</li>
  19. <li>vertex_indices (face indices)</li>
  20. <li>Custom properties via property name mapping</li>
  21. </ul>
  22. </p>
  23. <h2>Import</h2>
  24. <p>
  25. [name] is an add-on, and must be imported explicitly.
  26. See [link:#manual/introduction/Installation Installation / Addons].
  27. </p>
  28. <code>
  29. import { PLYLoader } from 'three/addons/loaders/PLYLoader.js';
  30. </code>
  31. <h2>Code Example</h2>
  32. <code>
  33. // instantiate a loader
  34. const loader = new PLYLoader();
  35. // load a resource
  36. loader.load(
  37. // resource URL
  38. 'models/ply/ascii/dolphins.ply',
  39. // called when the resource is loaded
  40. function ( geometry ) {
  41. // compute vertex normals if not present in the file
  42. geometry.computeVertexNormals();
  43. const material = new THREE.MeshStandardMaterial( { color: 0x0055ff } );
  44. const mesh = new THREE.Mesh( geometry, material );
  45. scene.add( mesh );
  46. },
  47. // called when loading is in progress
  48. function ( xhr ) {
  49. console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
  50. },
  51. // called when loading has errors
  52. function ( error ) {
  53. console.log( 'An error happened' );
  54. }
  55. );
  56. </code>
  57. <h2>Examples</h2>
  58. <p>
  59. [example:webgl_loader_ply]
  60. </p>
  61. <h2>Constructor</h2>
  62. <h3>[name]( [param:LoadingManager manager] )</h3>
  63. <p>
  64. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
  65. </p>
  66. <p>
  67. Creates a new [name].
  68. </p>
  69. <h2>Properties</h2>
  70. <p>See the base [page:Loader] class for common properties.</p>
  71. <h3>[page:Object propertyNameMapping]</h3>
  72. <p>
  73. An object that maps default property names to custom ones. Used for handling non-standard PLY property names.
  74. </p>
  75. <h3>[page:Object customPropertyMapping]</h3>
  76. <p>
  77. An object that defines custom property mappings for attributes not covered by the standard position, normal, uv, and color properties.
  78. </p>
  79. <h2>Methods</h2>
  80. <p>See the base [page:Loader] class for common methods.</p>
  81. <h3>[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  82. <p>
  83. [page:String url] — A string containing the path/URL of the `.ply` file.<br />
  84. [page:Function onLoad] — (optional) A function to be called after loading is successfully completed. The function receives the loaded [page:BufferGeometry] as an argument.<br />
  85. [page:Function onProgress] — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains [page:Integer total] and [page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.<br />
  86. [page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives the error as an argument.<br />
  87. </p>
  88. <p>
  89. Begin loading from url and call onLoad with the parsed response content.
  90. </p>
  91. <h3>[method:BufferGeometry parse]( [param:ArrayBuffer data] )</h3>
  92. <p>
  93. [page:ArrayBuffer data] — The binary or text structure to parse.
  94. </p>
  95. <p>
  96. Parse a PLY binary or ASCII structure and return a [page:BufferGeometry].<br />
  97. The geometry contains vertex positions and may include vertex normals, texture coordinates, vertex colors, and face indices depending on the PLY file content.
  98. </p>
  99. <h3>[method:undefined setPropertyNameMapping]( [param:Object mapping] )</h3>
  100. <p>
  101. [page:Object mapping] — An object that maps default property names to custom ones.
  102. </p>
  103. <p>
  104. Sets a property name mapping that maps default property names to custom ones. For example, the following maps the properties "diffuse_(red|green|blue)" in the file to standard color names:
  105. </p>
  106. <code>
  107. loader.setPropertyNameMapping( {
  108. diffuse_red: 'red',
  109. diffuse_green: 'green',
  110. diffuse_blue: 'blue'
  111. } );
  112. </code>
  113. <h3>[method:undefined setCustomPropertyNameMapping]( [param:Object mapping] )</h3>
  114. <p>
  115. [page:Object mapping] — An object that defines custom property mappings.
  116. </p>
  117. <p>
  118. Custom properties outside of the defaults for position, uv, normal and color attributes can be added using this method. For example, the following maps the element properties "custom_property_a" and "custom_property_b" to an attribute "customAttribute" with an item size of 2:
  119. </p>
  120. <code>
  121. loader.setCustomPropertyNameMapping( {
  122. customAttribute: ['custom_property_a', 'custom_property_b']
  123. } );
  124. </code>
  125. <h2>Source</h2>
  126. <p>
  127. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PLYLoader.js examples/jsm/loaders/PLYLoader.js]
  128. </p>
  129. </body>
  130. </html>
粤ICP备19079148号