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