ObjectLoader.html 6.6 KB

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