ObjectLoader.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. <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>Example</h2>
  17. <p>
  18. [example:webgl_loader_json_claraio WebGL / loader / json / claraio]<br />
  19. [example:webgl_materials_lightmap WebGL / materials / lightmap]
  20. </p>
  21. <code>
  22. var loader = new THREE.ObjectLoader();
  23. loader.load(
  24. // resource URL
  25. "models/json/example.json",
  26. // onLoad callback
  27. // Here the loaded data is assumed to be an object
  28. function ( obj ) {
  29. // Add the loaded object to the scene
  30. scene.add( obj );
  31. },
  32. // onProgress callback
  33. function ( xhr ) {
  34. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  35. },
  36. // onError callback
  37. function ( err ) {
  38. console.error( 'An error happened' );
  39. }
  40. );
  41. // Alternatively, to parse a previously loaded JSON structure
  42. var object = loader.parse( a_json_object );
  43. scene.add( object );
  44. </code>
  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. <h3>[property:String crossOrigin]</h3>
  53. <p>
  54. If set, assigns the [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
  55. attribute of the image to the value of *crossOrigin*, prior to starting the load. Default is *"anonymous"*.
  56. </p>
  57. <h3>[property:LoadingManager manager]</h3>
  58. <p>
  59. The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
  60. </p>
  61. <h3>[property:String resourcePath]</h3>
  62. <p>
  63. The base path or URL from which additional resources like textuures will be loaded. See [page:.setResourcePath].
  64. Default is the empty string.
  65. </p>
  66. <h2>Methods</h2>
  67. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  68. <p>
  69. [page:String url] — the path or URL to the file. This can also be a
  70. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  71. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Object3D object].<br />
  72. [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 />
  73. [page:Function onError] — Will be called when load errors.<br />
  74. </p>
  75. <p>
  76. Begin loading from url and call onLoad with the parsed response content.
  77. </p>
  78. <h3>[method:Object3D parse]( [param:Object json], [param:Function onLoad] )</h3>
  79. <p>
  80. [page:Object json] — required. The JSON source to parse.<br /><br />
  81. [page:Function onLoad] — Will be called when parsed completes. The argument will be the parsed [page:Object3D object].<br /><br />
  82. Parse a <em>JSON</em> structure and return a threejs object.
  83. This is used internally by [page:.load], but can also be used directly to parse
  84. a previously loaded JSON structure.
  85. </p>
  86. <h3>[method:Object3D parseGeometries]( [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 [page:Geometry geometries] or [page:BufferGeometry buffer geometries] in the JSON structure.
  90. </p>
  91. <h3>[method:Object3D parseMaterials]( [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 materials in the JSON structure using [page:MaterialLoader].
  95. </p>
  96. <h3>[method:Object3D parseAnimations]( [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 animations in the JSON structure, using [page:AnimationClip.parse].
  100. </p>
  101. <h3>[method:Object3D parseImages]( [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 images in the JSON structure, using [page:ImageLoader].
  105. </p>
  106. <h3>[method:Object3D parseTextures]( [param:Object json] )</h3>
  107. <p>
  108. [page:Object json] — required. The JSON source to parse.<br /><br />
  109. This is used [page:.parse] to parse any textures in the JSON structure.
  110. </p>
  111. <h3>[method:Object3D parseObject]( [param:Object json] )</h3>
  112. <p>
  113. [page:Object json] — required. The JSON source to parse.<br /><br />
  114. This is used [page:.parse] to parse any objects in the JSON structure.
  115. Objects can be of the following types:
  116. <ul>
  117. <li>
  118. [page:Scene]
  119. </li>
  120. <li>
  121. [page:PerspectiveCamera]
  122. </li>
  123. <li>
  124. [page:OrthographicCamera]
  125. </li>
  126. <li>
  127. [page:AmbientLight]
  128. </li>
  129. <li>
  130. [page:DirectionalLight]
  131. </li>
  132. <li>
  133. [page:PointLight]
  134. </li>
  135. <li>
  136. [page:SpotLight]
  137. </li>
  138. <li>
  139. [page:HemisphereLight]
  140. </li>
  141. <li>
  142. [page:Mesh]
  143. </li>
  144. <li>
  145. [page:LOD]
  146. </li>
  147. <li>
  148. [page:Line]
  149. </li>
  150. <li>
  151. [page:LineSegments]
  152. </li>
  153. <li>
  154. [page:Points]
  155. </li>
  156. <li>
  157. [page:Sprite]
  158. </li>
  159. <li>
  160. [page:Group]
  161. </li>
  162. <li>
  163. [page:Object3D]
  164. </li>
  165. </ul>
  166. </p>
  167. <h3>[method:ObjectLoader setCrossOrigin]( [param:String value] )</h3>
  168. <p>
  169. [page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
  170. </p>
  171. <h3>[method:ObjectLoader setPath]( [param:String value] )</h3>
  172. <p>
  173. Set the base path for the original file.
  174. </p>
  175. <h3>[method:ObjectLoader setResourcePath]( [param:String value] )</h3>
  176. <p>
  177. Set the base path for dependent resources like textures.
  178. </p>
  179. <h2>Source</h2>
  180. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  181. </body>
  182. </html>