ObjectLoader.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:Loader] &rarr;
  12. <h1>[name]</h1>
  13. <p class="desc">
  14. 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 />
  15. This uses the [page:FileLoader] internally for loading files.
  16. </p>
  17. <h2>Code Example</h2>
  18. <code>
  19. var 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. var object = loader.parse( a_json_object );
  40. scene.add( object );
  41. </code>
  42. <h2>Examples</h2>
  43. <p>
  44. [example:webgl_materials_lightmap WebGL / materials / lightmap]
  45. </p>
  46. <h2>Constructor</h2>
  47. <h3>[name]( [param:LoadingManager manager] )</h3>
  48. <p>
  49. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  50. Creates a new [name].
  51. </p>
  52. <h2>Properties</h2>
  53. <p>See the base [page:Loader] class for common properties.</p>
  54. <h2>Methods</h2>
  55. <p>See the base [page:Loader] class for common methods.</p>
  56. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  57. <p>
  58. [page:String url] — the path or URL to the file. This can also be a
  59. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  60. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Object3D object].<br />
  61. [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 />
  62. [page:Function onError] — Will be called when load errors.<br />
  63. </p>
  64. <p>
  65. Begin loading from url and call onLoad with the parsed response content.
  66. </p>
  67. <h3>[method:Object3D parse]( [param:Object json], [param:Function onLoad] )</h3>
  68. <p>
  69. [page:Object json] — required. The JSON source to parse.<br /><br />
  70. [page:Function onLoad] — Will be called when parsed completes. The argument will be the parsed [page:Object3D object].<br /><br />
  71. Parse a <em>JSON</em> structure and return a threejs object.
  72. This is used internally by [page:.load], but can also be used directly to parse
  73. a previously loaded JSON structure.
  74. </p>
  75. <h3>[method:Object3D parseGeometries]( [param:Object json] )</h3>
  76. <p>
  77. [page:Object json] — required. The JSON source to parse.<br /><br />
  78. This is used [page:.parse] to parse any [page:Geometry geometries] or [page:BufferGeometry buffer geometries] in the JSON structure.
  79. </p>
  80. <h3>[method:Object3D parseMaterials]( [param:Object json] )</h3>
  81. <p>
  82. [page:Object json] — required. The JSON source to parse.<br /><br />
  83. This is used [page:.parse] to parse any materials in the JSON structure using [page:MaterialLoader].
  84. </p>
  85. <h3>[method:Object3D parseAnimations]( [param:Object json] )</h3>
  86. <p>
  87. [page:Object json] — required. The JSON source to parse.<br /><br />
  88. This is used [page:.parse] to parse any animations in the JSON structure, using [page:AnimationClip.parse].
  89. </p>
  90. <h3>[method:Object3D parseImages]( [param:Object json] )</h3>
  91. <p>
  92. [page:Object json] — required. The JSON source to parse.<br /><br />
  93. This is used [page:.parse] to parse any images in the JSON structure, using [page:ImageLoader].
  94. </p>
  95. <h3>[method:Object3D parseTextures]( [param:Object json] )</h3>
  96. <p>
  97. [page:Object json] — required. The JSON source to parse.<br /><br />
  98. This is used [page:.parse] to parse any textures in the JSON structure.
  99. </p>
  100. <h3>[method:Object3D parseObject]( [param:Object json] )</h3>
  101. <p>
  102. [page:Object json] — required. The JSON source to parse.<br /><br />
  103. This is used [page:.parse] to parse any objects in the JSON structure.
  104. Objects can be of the following types:
  105. <ul>
  106. <li>
  107. [page:Scene]
  108. </li>
  109. <li>
  110. [page:PerspectiveCamera]
  111. </li>
  112. <li>
  113. [page:OrthographicCamera]
  114. </li>
  115. <li>
  116. [page:AmbientLight]
  117. </li>
  118. <li>
  119. [page:DirectionalLight]
  120. </li>
  121. <li>
  122. [page:PointLight]
  123. </li>
  124. <li>
  125. [page:SpotLight]
  126. </li>
  127. <li>
  128. [page:HemisphereLight]
  129. </li>
  130. <li>
  131. [page:Mesh]
  132. </li>
  133. <li>
  134. [page:LOD]
  135. </li>
  136. <li>
  137. [page:Line]
  138. </li>
  139. <li>
  140. [page:LineSegments]
  141. </li>
  142. <li>
  143. [page:Points]
  144. </li>
  145. <li>
  146. [page:Sprite]
  147. </li>
  148. <li>
  149. [page:Group]
  150. </li>
  151. <li>
  152. [page:Object3D]
  153. </li>
  154. </ul>
  155. </p>
  156. <h2>Source</h2>
  157. <p>
  158. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  159. </p>
  160. </body>
  161. </html>