ObjectLoader.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format].<br /><br />
  14. This uses the [page:FileLoader] internally for loading files.
  15. </p>
  16. <h2>Code Example</h2>
  17. <code>
  18. const loader = new THREE.ObjectLoader();
  19. loader.load(
  20. // resource URL
  21. "models/json/example.json",
  22. // onLoad callback
  23. // Here the loaded data is assumed to be an object
  24. function ( obj ) {
  25. // Add the loaded object to the scene
  26. scene.add( obj );
  27. },
  28. // onProgress callback
  29. function ( xhr ) {
  30. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  31. },
  32. // onError callback
  33. function ( err ) {
  34. console.error( 'An error happened' );
  35. }
  36. );
  37. // Alternatively, to parse a previously loaded JSON structure
  38. const object = loader.parse( a_json_object );
  39. scene.add( object );
  40. </code>
  41. <h2>Examples</h2>
  42. <p>
  43. [example:webgl_materials_lightmap WebGL / materials / lightmap]
  44. </p>
  45. <h2>Constructor</h2>
  46. <h3>[name]( [param:LoadingManager manager] )</h3>
  47. <p>
  48. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] 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>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  56. <p>
  57. [page:String url] — the path or URL to the file. This can also be a
  58. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  59. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Object3D object].<br />
  60. [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes.<br />
  61. [page:Function onError] — Will be called when load errors.<br />
  62. </p>
  63. <p>
  64. Begin loading from url and call onLoad with the parsed response content.
  65. </p>
  66. <h3>[method:Object3D parse]( [param:Object json], [param:Function onLoad] )</h3>
  67. <p>
  68. [page:Object json] — required. The JSON source to parse.<br /><br />
  69. [page:Function onLoad] — Will be called when parsed completes. The argument will be the parsed [page:Object3D object].<br /><br />
  70. Parse a <em>JSON</em> structure and return a threejs object.
  71. This is used internally by [page:.load], but can also be used directly to parse
  72. a previously loaded JSON structure.
  73. </p>
  74. <h3>[method:Object3D parseGeometries]( [param:Object json] )</h3>
  75. <p>
  76. [page:Object json] — required. The JSON source to parse.<br /><br />
  77. This is used [page:.parse] to parse any [page:Geometry geometries] or [page:BufferGeometry buffer geometries] in the JSON structure.
  78. </p>
  79. <h3>[method:Object3D parseMaterials]( [param:Object json] )</h3>
  80. <p>
  81. [page:Object json] — required. The JSON source to parse.<br /><br />
  82. This is used [page:.parse] to parse any materials in the JSON structure using [page:MaterialLoader].
  83. </p>
  84. <h3>[method:Object3D parseAnimations]( [param:Object json] )</h3>
  85. <p>
  86. [page:Object json] — required. The JSON source to parse.<br /><br />
  87. This is used [page:.parse] to parse any animations in the JSON structure, using [page:AnimationClip.parse].
  88. </p>
  89. <h3>[method:Object3D parseImages]( [param:Object json] )</h3>
  90. <p>
  91. [page:Object json] — required. The JSON source to parse.<br /><br />
  92. This is used [page:.parse] to parse any images in the JSON structure, using [page:ImageLoader].
  93. </p>
  94. <h3>[method:Object3D parseTextures]( [param:Object json] )</h3>
  95. <p>
  96. [page:Object json] — required. The JSON source to parse.<br /><br />
  97. This is used [page:.parse] to parse any textures in the JSON structure.
  98. </p>
  99. <h3>[method:Object3D parseObject]( [param:Object json] )</h3>
  100. <p>
  101. [page:Object json] — required. The JSON source to parse.<br /><br />
  102. This is used [page:.parse] to parse any objects in the JSON structure.
  103. Objects can be of the following types:
  104. <ul>
  105. <li>
  106. [page:Scene]
  107. </li>
  108. <li>
  109. [page:PerspectiveCamera]
  110. </li>
  111. <li>
  112. [page:OrthographicCamera]
  113. </li>
  114. <li>
  115. [page:AmbientLight]
  116. </li>
  117. <li>
  118. [page:DirectionalLight]
  119. </li>
  120. <li>
  121. [page:PointLight]
  122. </li>
  123. <li>
  124. [page:SpotLight]
  125. </li>
  126. <li>
  127. [page:HemisphereLight]
  128. </li>
  129. <li>
  130. [page:Mesh]
  131. </li>
  132. <li>
  133. [page:LOD]
  134. </li>
  135. <li>
  136. [page:Line]
  137. </li>
  138. <li>
  139. [page:LineSegments]
  140. </li>
  141. <li>
  142. [page:Points]
  143. </li>
  144. <li>
  145. [page:Sprite]
  146. </li>
  147. <li>
  148. [page:Group]
  149. </li>
  150. <li>
  151. [page:Object3D]
  152. </li>
  153. </ul>
  154. </p>
  155. <h2>Source</h2>
  156. <p>
  157. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  158. </p>
  159. </body>
  160. </html>