ObjectLoader.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. 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. </p>
  18. <h2>Example</h2>
  19. <p>
  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. </p>
  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 ( xhr ) {
  37. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  38. },
  39. // onError callback
  40. function ( err ) {
  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]( [param:LoadingManager manager] )</h3>
  50. <p>
  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. </p>
  54. <h2>Properties</h2>
  55. <h3>[property:String crossOrigin]</h3>
  56. <p>
  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*, prior to starting the load. Default is *"anonymous"*.
  59. </p>
  60. <h3>[property:LoadingManager manager]</h3>
  61. <p>
  62. The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
  63. </p>
  64. <h3>[property:String texturePath]</h3>
  65. <p>
  66. The base path or URL from which textures will be loaded. See [page:.setTexturePath].
  67. Default is the empty string.
  68. </p>
  69. <h2>Methods</h2>
  70. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  71. <p>
  72. [page:String url] — the path or URL to the file. This can also be a
  73. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  74. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Object3D object].<br />
  75. [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 />
  76. [page:Function onError] — Will be called when load errors.<br />
  77. </p>
  78. <p>
  79. Begin loading from url and call onLoad with the parsed response content.
  80. </p>
  81. <h3>[method:Object3D parse]( [param:Object json], [param:Function onLoad] )</h3>
  82. <p>
  83. [page:Object json] — required. The JSON source to parse.<br /><br />
  84. [page:Function onLoad] — Will be called when parsed completes. The argument will be the parsed [page:Object3D object].<br /><br />
  85. Parse a <em>JSON</em> structure and return a threejs object.
  86. This is used internally by [page:.load], but can also be used directly to parse
  87. a previously loaded JSON structure.
  88. </p>
  89. <h3>[method:Object3D parseGeometries]( [param:Object json] )</h3>
  90. <p>
  91. [page:Object json] — required. The JSON source to parse.<br /><br />
  92. This is used [page:.parse] to parse any [page:Geometry geometries] or [page:BufferGeometry buffer geometries] in the JSON structure.
  93. Internally it uses [page:JSONLoader] for geometries and [page:BufferGeometryLoader] for buffer geometries.
  94. </p>
  95. <h3>[method:Object3D parseMaterials]( [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 materials in the JSON structure using [page:MaterialLoader].
  99. </p>
  100. <h3>[method:Object3D parseAnimations]( [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 animations in the JSON structure, using [page:AnimationClip.parse].
  104. </p>
  105. <h3>[method:Object3D parseImages]( [param:Object json] )</h3>
  106. <p>
  107. [page:Object json] — required. The JSON source to parse.<br /><br />
  108. This is used [page:.parse] to parse any images in the JSON structure, using [page:ImageLoader].
  109. </p>
  110. <h3>[method:Object3D parseTextures]( [param:Object json] )</h3>
  111. <p>
  112. [page:Object json] — required. The JSON source to parse.<br /><br />
  113. This is used [page:.parse] to parse any textures in the JSON structure.
  114. </p>
  115. <h3>[method:Object3D parseObject]( [param:Object json] )</h3>
  116. <p>
  117. [page:Object json] — required. The JSON source to parse.<br /><br />
  118. This is used [page:.parse] to parse any objects in the JSON structure.
  119. Objects can be of the following types:
  120. <ul>
  121. <li>
  122. [page:Scene]
  123. </li>
  124. <li>
  125. [page:PerspectiveCamera]
  126. </li>
  127. <li>
  128. [page:OrthographicCamera]
  129. </li>
  130. <li>
  131. [page:AmbientLight]
  132. </li>
  133. <li>
  134. [page:DirectionalLight]
  135. </li>
  136. <li>
  137. [page:PointLight]
  138. </li>
  139. <li>
  140. [page:SpotLight]
  141. </li>
  142. <li>
  143. [page:HemisphereLight]
  144. </li>
  145. <li>
  146. [page:Mesh]
  147. </li>
  148. <li>
  149. [page:LOD]
  150. </li>
  151. <li>
  152. [page:Line]
  153. </li>
  154. <li>
  155. [page:LineSegments]
  156. </li>
  157. <li>
  158. [page:Points]
  159. </li>
  160. <li>
  161. [page:Sprite]
  162. </li>
  163. <li>
  164. [page:Group]
  165. </li>
  166. <li>
  167. [page:Object3D]
  168. </li>
  169. </ul>
  170. </p>
  171. <h3>[method:ObjectLoader setCrossOrigin]( [param:String value] )</h3>
  172. <p>
  173. [page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
  174. </p>
  175. <h3>[method:ObjectLoader setTexturePath]( [param:String value] )</h3>
  176. <p>
  177. [page:String value] — The base path or URL from which textures will be loaded.<br /><br />
  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>