1
0

ObjectLoader.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 loading a JSON resource in the
  14. [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format].<br /><br />
  15. This uses the [page:FileLoader] internally for loading files.
  16. </p>
  17. <h2>Code Example</h2>
  18. <code>
  19. const loader = new THREE.ObjectLoader();
  20. loader.load(
  21. // resource URL
  22. "models/json/example.json",
  23. // onLoad callback
  24. // Here the loaded data is assumed to be an object
  25. function ( obj ) {
  26. // Add the loaded object to the scene
  27. scene.add( obj );
  28. },
  29. // onProgress callback
  30. function ( xhr ) {
  31. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  32. },
  33. // onError callback
  34. function ( err ) {
  35. console.error( 'An error happened' );
  36. }
  37. );
  38. // Alternatively, to parse a previously loaded JSON structure
  39. const object = loader.parse( a_json_object );
  40. scene.add( object );
  41. </code>
  42. <h2>Examples</h2>
  43. <p>[example:webgpu_materials_lightmap WebGL / materials / lightmap]</p>
  44. <h2>Constructor</h2>
  45. <h3>[name]( [param:LoadingManager manager] )</h3>
  46. <p>
  47. [page:LoadingManager manager] — The [page:LoadingManager loadingManager]
  48. for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  49. Creates a new [name].
  50. </p>
  51. <h2>Properties</h2>
  52. <p>See the base [page:Loader] class for common properties.</p>
  53. <h2>Methods</h2>
  54. <p>See the base [page:Loader] class for common methods.</p>
  55. <h3>
  56. [method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )
  57. </h3>
  58. <p>
  59. [page:String url] — the path or URL to the file. This can also be a
  60. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  61. [page:Function onLoad] — Will be called when load completes. The argument
  62. will be the loaded [page:Object3D object].<br />
  63. [page:Function onProgress] (optional) — Will be called while load
  64. progresses. The argument will be the ProgressEvent instance, which
  65. contains .[page:Boolean lengthComputable], .[page:Integer total] and
  66. .[page:Integer loaded]. If the server does not set the Content-Length
  67. header; .[page:Integer total] will be 0.<br />
  68. [page:Function onError] (optional) — Will be called when load errors.<br />
  69. </p>
  70. <p>
  71. Begin loading from url and call onLoad with the parsed response content.
  72. </p>
  73. <h3>
  74. [method:Object3D parse]( [param:Object json], [param:Function onLoad] )
  75. </h3>
  76. <p>
  77. [page:Object json] — required. The JSON source to parse.<br /><br />
  78. [page:Function onLoad] — Will be called when parsed completes. The
  79. argument will be the parsed [page:Object3D object].<br /><br />
  80. Parse a `JSON` structure and return a three.js object. This is used
  81. internally by [page:.load]() but can also be used directly to parse a
  82. previously loaded JSON structure.
  83. </p>
  84. <h3>[method:Object parseGeometries]( [param:Object json] )</h3>
  85. <p>
  86. [page:Object json] — required. The JSON source to parse.<br /><br />
  87. This is used by [page:.parse]() to parse any [page:BufferGeometry geometries] in the JSON structure.
  88. </p>
  89. <h3>[method:Object parseMaterials]( [param:Object json] )</h3>
  90. <p>
  91. [page:Object json] — required. The JSON source to parse.<br /><br />
  92. This is used by [page:.parse]() to parse any materials in the JSON
  93. structure using [page:MaterialLoader].
  94. </p>
  95. <h3>[method:Object parseAnimations]( [param:Object json] )</h3>
  96. <p>
  97. [page:Object json] — required. The JSON source to parse.<br /><br />
  98. This is used by [page:.parse]() to parse any animations in the JSON
  99. structure, using [page:AnimationClip.parse]().
  100. </p>
  101. <h3>[method:Object parseImages]( [param:Object json] )</h3>
  102. <p>
  103. [page:Object json] — required. The JSON source to parse.<br /><br />
  104. This is used by [page:.parse]() to parse any images in the JSON structure,
  105. using [page:ImageLoader].
  106. </p>
  107. <h3>[method:Object parseTextures]( [param:Object json] )</h3>
  108. <p>
  109. [page:Object json] — required. The JSON source to parse.<br /><br />
  110. This is used by [page:.parse]() to parse any textures in the JSON
  111. structure.
  112. </p>
  113. <h3>
  114. [method:Object3D parseObject]( [param:Object json], [param:BufferGeometry geometries], [param:Material materials], [param:AnimationClip animations] )
  115. </h3>
  116. <p>
  117. [page:Object json] — required. The JSON source to parse.<br />
  118. [page:BufferGeometry geometries] — required. The geometries of the
  119. JSON.<br />
  120. [page:Material materials] — required. The materials of the JSON.<br />
  121. [page:AnimationClip animations] — required. The animations of the JSON.<br /><br />
  122. This is used by [page:.parse]() to parse any 3D objects in the JSON
  123. structure.
  124. </p>
  125. <h2>Source</h2>
  126. <p>
  127. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  128. </p>
  129. </body>
  130. </html>