ObjectLoader.html 6.4 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. // pass the loaded data to the onLoad function.
  30. //Here it is assumed to be an object
  31. function ( obj ) {
  32. //add the loaded object to the scene
  33. scene.add( obj );
  34. },
  35. // Function called when download progresses
  36. function ( xhr ) {
  37. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  38. },
  39. // Function called when download errors
  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].
  52. </div>
  53. <div>
  54. Creates a new [name].
  55. </div>
  56. <h2>Properties</h2>
  57. <h3>[property:String crossOrigin]</h3>
  58. <div>
  59. If set, assigns the [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
  60. attribute of the image to the value of *crossOrigin*,
  61. prior to starting the load. Default is *undefined*.
  62. </div>
  63. <h3>[property:LoadingManager manager]</h3>
  64. <div>
  65. The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
  66. </div>
  67. <h3>[property:String texturePath]</h3>
  68. <div>
  69. The base path or URL from which textures will be loaded. See [page:.setTexturePath].
  70. Default is the empty string.
  71. </div>
  72. <h2>Methods</h2>
  73. <h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
  74. <div>
  75. [page:String url] — required<br />
  76. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Object3D object].<br />
  77. [page:Function onProgress] — Will be called while load progresses. The argument will be the XmlHttpRequest instance, that contain .[page:Integer total] and .[page:Integer loaded] bytes.<br />
  78. [page:Function onError] — Will be called when load errors.<br />
  79. </div>
  80. <div>
  81. Begin loading from url and call onLoad with the parsed response content.
  82. </div>
  83. <h3>[method:Object3D parse]( [page:Object json], [page:Function onLoad] )</h3>
  84. <div>
  85. [page:Object json] — required. The JSON source to parse.<br /><br />
  86. [page:Function onLoad] — Will be called when parsed completes. The argument will be the parsed [page:Object3D object].<br />
  87. Parse a <em>JSON</em> structure and return a threejs object.
  88. This is used internally by [page:.load], but can also be used directly to parse
  89. a previously loaded JSON structure.
  90. </div>
  91. <h3>[method:Object3D parseGeometries]( [page:Object json] )</h3>
  92. <div>
  93. [page:Object json] — required. The JSON source to parse.<br /><br />
  94. This is used [page:.parse] to parse any [page:Geometry geometries] or [page:BufferGeometry buffer geometries] in the JSON structure.
  95. Internally it uses [page:JSONLoader] for geometries and [page:BufferGeometryLoader] for buffer geometries.
  96. </div>
  97. <h3>[method:Object3D parseMaterials]( [page:Object json] )</h3>
  98. <div>
  99. [page:Object json] — required. The JSON source to parse.<br /><br />
  100. This is used [page:.parse] to parse any materials in the JSON structure using [page:MaterialLoader].
  101. </div>
  102. <h3>[method:Object3D parseAnimations]( [page:Object json] )</h3>
  103. <div>
  104. [page:Object json] — required. The JSON source to parse.<br /><br />
  105. This is used [page:.parse] to parse any animations in the JSON structure, using [page:AnimationClip.parse].
  106. </div>
  107. <h3>[method:Object3D parseImages]( [page:Object json] )</h3>
  108. <div>
  109. [page:Object json] — required. The JSON source to parse.<br /><br />
  110. This is used [page:.parse] to parse any images in the JSON structure, using [page:ImageLoader].
  111. </div>
  112. <h3>[method:Object3D parseTextures]( [page:Object json] )</h3>
  113. <div>
  114. [page:Object json] — required. The JSON source to parse.<br /><br />
  115. This is used [page:.parse] to parse any textures in the JSON structure.
  116. </div>
  117. <h3>[method:Object3D parseObject]( [page:Object json] )</h3>
  118. <div>
  119. [page:Object json] — required. The JSON source to parse.<br /><br />
  120. This is used [page:.parse] to parse any objects in the JSON structure.
  121. Objects can be of the following types:
  122. <ul>
  123. <li>
  124. [page:Scene]
  125. </li>
  126. <li>
  127. [page:PerspectiveCamera]
  128. </li>
  129. <li>
  130. [page:OrthographicCamera]
  131. </li>
  132. <li>
  133. [page:AmbientLight]
  134. </li>
  135. <li>
  136. [page:DirectionalLight]
  137. </li>
  138. <li>
  139. [page:PointLight]
  140. </li>
  141. <li>
  142. [page:SpotLight]
  143. </li>
  144. <li>
  145. [page:HemisphereLight]
  146. </li>
  147. <li>
  148. [page:Mesh]
  149. </li>
  150. <li>
  151. [page:LOD]
  152. </li>
  153. <li>
  154. [page:Line]
  155. </li>
  156. <li>
  157. [page:LineSegments]
  158. </li>
  159. <li>
  160. [page:Points]
  161. </li>
  162. <li>
  163. [page:Sprite]
  164. </li>
  165. <li>
  166. [page:Group]
  167. </li>
  168. <li>
  169. [page:Object3D]
  170. </li>
  171. </ul>
  172. </div>
  173. <h3>[method:null setCrossOrigin]( [page:String value] )</h3>
  174. <div>
  175. [page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
  176. </div>
  177. <h3>[method:null setTexturePath]( [page:String value] )</h3>
  178. <div>
  179. [page:String value] — The base path or URL from which textures will be loaded.<br /><br />
  180. </div>
  181. <h2>Source</h2>
  182. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  183. </body>
  184. </html>