ObjectLoader.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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_loader_json_claraio WebGL / loader / json / claraio]<br />
  45. [example:webgl_materials_lightmap WebGL / materials / lightmap]
  46. </p>
  47. <h2>Constructor</h2>
  48. <h3>[name]( [param:LoadingManager manager] )</h3>
  49. <p>
  50. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  51. Creates a new [name].
  52. </p>
  53. <h2>Properties</h2>
  54. <p>See the base [page:Loader] class for common properties.</p>
  55. <h2>Methods</h2>
  56. <p>See the base [page:Loader] class for common methods.</p>
  57. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</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 will be the loaded [page:Object3D object].<br />
  62. [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 />
  63. [page:Function onError] — Will be called when load errors.<br />
  64. </p>
  65. <p>
  66. Begin loading from url and call onLoad with the parsed response content.
  67. </p>
  68. <h3>[method:Object3D parse]( [param:Object json], [param:Function onLoad] )</h3>
  69. <p>
  70. [page:Object json] — required. The JSON source to parse.<br /><br />
  71. [page:Function onLoad] — Will be called when parsed completes. The argument will be the parsed [page:Object3D object].<br /><br />
  72. Parse a <em>JSON</em> structure and return a threejs object.
  73. This is used internally by [page:.load], but can also be used directly to parse
  74. a previously loaded JSON structure.
  75. </p>
  76. <h3>[method:Object3D parseGeometries]( [param:Object json] )</h3>
  77. <p>
  78. [page:Object json] — required. The JSON source to parse.<br /><br />
  79. This is used [page:.parse] to parse any [page:Geometry geometries] or [page:BufferGeometry buffer geometries] in the JSON structure.
  80. </p>
  81. <h3>[method:Object3D parseMaterials]( [param:Object json] )</h3>
  82. <p>
  83. [page:Object json] — required. The JSON source to parse.<br /><br />
  84. This is used [page:.parse] to parse any materials in the JSON structure using [page:MaterialLoader].
  85. </p>
  86. <h3>[method:Object3D parseAnimations]( [param:Object json] )</h3>
  87. <p>
  88. [page:Object json] — required. The JSON source to parse.<br /><br />
  89. This is used [page:.parse] to parse any animations in the JSON structure, using [page:AnimationClip.parse].
  90. </p>
  91. <h3>[method:Object3D parseImages]( [param:Object json] )</h3>
  92. <p>
  93. [page:Object json] — required. The JSON source to parse.<br /><br />
  94. This is used [page:.parse] to parse any images in the JSON structure, using [page:ImageLoader].
  95. </p>
  96. <h3>[method:Object3D parseTextures]( [param:Object json] )</h3>
  97. <p>
  98. [page:Object json] — required. The JSON source to parse.<br /><br />
  99. This is used [page:.parse] to parse any textures in the JSON structure.
  100. </p>
  101. <h3>[method:Object3D parseObject]( [param:Object json] )</h3>
  102. <p>
  103. [page:Object json] — required. The JSON source to parse.<br /><br />
  104. This is used [page:.parse] to parse any objects in the JSON structure.
  105. Objects can be of the following types:
  106. <ul>
  107. <li>
  108. [page:Scene]
  109. </li>
  110. <li>
  111. [page:PerspectiveCamera]
  112. </li>
  113. <li>
  114. [page:OrthographicCamera]
  115. </li>
  116. <li>
  117. [page:AmbientLight]
  118. </li>
  119. <li>
  120. [page:DirectionalLight]
  121. </li>
  122. <li>
  123. [page:PointLight]
  124. </li>
  125. <li>
  126. [page:SpotLight]
  127. </li>
  128. <li>
  129. [page:HemisphereLight]
  130. </li>
  131. <li>
  132. [page:Mesh]
  133. </li>
  134. <li>
  135. [page:LOD]
  136. </li>
  137. <li>
  138. [page:Line]
  139. </li>
  140. <li>
  141. [page:LineSegments]
  142. </li>
  143. <li>
  144. [page:Points]
  145. </li>
  146. <li>
  147. [page:Sprite]
  148. </li>
  149. <li>
  150. [page:Group]
  151. </li>
  152. <li>
  153. [page:Object3D]
  154. </li>
  155. </ul>
  156. </p>
  157. <h2>Source</h2>
  158. <p>
  159. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  160. </p>
  161. </body>
  162. </html>