JSONLoader.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 objects in JSON format.
  14. This uses the [page:FileLoader] internally for loading files.
  15. </p>
  16. <h2>Example</h2>
  17. <p>
  18. [example:webgl_loader_json WebGL / loader / json]<br />
  19. [example:webgl_loader_json_objconverter WebGL / loader / json / objconverter]
  20. </p>
  21. <code>
  22. // instantiate a loader
  23. var loader = new THREE.JSONLoader();
  24. // load a resource
  25. loader.load(
  26. // resource URL
  27. 'models/animated/monster/monster.js',
  28. // onLoad callback
  29. function ( geometry, materials ) {
  30. var material = materials[ 0 ];
  31. var object = new THREE.Mesh( geometry, material );
  32. scene.add( object );
  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.log( 'An error happened' );
  41. }
  42. );
  43. </code>
  44. <h2>Constructor</h2>
  45. <h3>[name]( [param:LoadingManager manager] )</h3>
  46. <p>
  47. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
  48. </p>
  49. <p>
  50. Creates a new [name].
  51. </p>
  52. <h2>Properties</h2>
  53. <h3>[property:String crossOrigin]</h3>
  54. <p>
  55. If set, assigns the [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
  56. attribute of the image to the value of *crossOrigin*, prior to starting the load. Default is *"anonymous"*.
  57. </p>
  58. <h3>[property:LoadingManager manager]</h3>
  59. <p>
  60. The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
  61. </p>
  62. <h3>[property:String withCredentials]</h3>
  63. <p>
  64. Whether the XMLHttpRequest uses credentials.
  65. Default is *false*.
  66. </p>
  67. <h2>Methods</h2>
  68. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  69. <p>
  70. [page:String url] — the path or URL to the file. This can also be a
  71. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI]..<br />
  72. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded text response.<br />
  73. [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 />
  74. [page:Function onError] — Will be called when load errors.<br />
  75. </p>
  76. <p>
  77. Begin loading from url and pass the <em>JSON</em> to onLoad.
  78. </p>
  79. <h3>[method:JSONLoader setCrossOrigin]( [param:String value] )</h3>
  80. <p>
  81. Set the [page:.crossOrigin] attribute.
  82. </p>
  83. <h3>[method:JSONLoader setTexturePath]( [param:String texturePath] )</h3>
  84. <p>
  85. Set the base path or URL from which to load files. This can be useful if
  86. you are loading many files from the same directory.
  87. </p>
  88. <h3>[method:Object3D parse]( [param:Object json], [param:String texturePath] )</h3>
  89. <p>
  90. [page:String json] — JSON object to parse.<br />
  91. [page:String texturePath] — Base path for textures.<br /><br />
  92. Parse a <em>JSON</em> structure and return an [page:object] containing the parsed [page:Geometry geometry] and [page:Array materials].
  93. </p>
  94. <h2>Source</h2>
  95. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  96. </body>
  97. </html>