SceneLoader.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <script src="../../list.js"></script>
  6. <script src="../../page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="../../page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <div class="desc">A loader for loading a [page:Scene] from a <em>JSON</em> resource.</div>
  12. <h2>Constructor</h2>
  13. <h3>[name]( [page:LoadingManager manager] )</h3>
  14. <div>
  15. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
  16. </div>
  17. <div>
  18. Creates a new [name].
  19. </div>
  20. <h2>Properties</h2>
  21. <h2>Methods</h2>
  22. <h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
  23. <div>
  24. [page:String url] — required<br />
  25. [page:Function onLoad] — Will be called when load completes. The argument will be an [page:Object] containing the loaded components.<br />
  26. [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 />
  27. [page:Function onError] — Will be called when load errors.<br />
  28. </div>
  29. <div>
  30. Begin loading from url and call onLoad with the parsed scene.
  31. </div>
  32. <h3>[method:Object parse]( [page:Object json], [page:Function callbackFinished], [page:String url] )</h3>
  33. <div>
  34. [page:Object json] — The <em>JSON</em> structure to parse.<br />
  35. [page:Function callbackFinished] — Will be called when parse completes.<br />
  36. [page:String url] — Will be used as base for assets' relative URLs.<br />
  37. </div>
  38. <div>
  39. Parse a <em>JSON</em> scene description and return a new [page:Object] with fully instantiated Three.js objects.
  40. </div>
  41. <h3>[method:null setCrossOrigin]( [page:String value] )</h3>
  42. <div>
  43. [page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
  44. </div>
  45. <h3>[method:null addGeometryHandler]( [page:String typeID], [page:Function loaderClass] )</h3>
  46. <div>
  47. [page:String typeID] — The type to handle.<br />
  48. [page:Function loaderClass] — The handler class.<br />
  49. </div>
  50. <div>
  51. Add an handler for a specific geometry type.
  52. </div>
  53. <h3>[method:null addHierarchyHandler]( [page:String typeID], [page:Function loaderClass] )</h3>
  54. <div>
  55. [page:String typeID] — The type to handle.<br />
  56. [page:Function loaderClass] — The handler class.<br />
  57. </div>
  58. <div>
  59. Add an handler for a specific object type.
  60. </div>
  61. <h2>Example</h2>
  62. <code>
  63. // instantiate a loader
  64. var loader = new THREE.SceneLoader();
  65. // Handle STL geometries
  66. loader.addGeometryHandler( "stl", THREE.STLLoader );
  67. // Handle OBJ objects
  68. loader.addHierarchyHandler( "obj", THREE.OBJLoader );
  69. // load a JSON resource
  70. loader.load(
  71. // resource URL
  72. 'scenes/test_scene.js',
  73. // Function when resource is loaded
  74. function ( result ) {
  75. scene.add( result.scene );
  76. },
  77. // Function called when download progresses
  78. function ( xhr ) {
  79. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  80. },
  81. // Function called when download errors
  82. function ( xhr ) {
  83. console.log( 'An error happened' );
  84. }
  85. );
  86. </code>
  87. [example:webgl_loader_scene]
  88. <h2>Source</h2>
  89. [link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/SceneLoader.js examples/js/loaders/SceneLoader.js]
  90. </body>
  91. </html>