JSONLoader.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. [page:Loader] &rarr;
  11. <h1>[name]</h1>
  12. <div class="desc">A loader for loading objects in JSON format.</div>
  13. <h2>Constructor</h2>
  14. <h3>[name]( [page:Boolean showStatus] )</h3>
  15. <div>
  16. [page:Boolean showStatus] — Show the status of loading div.
  17. </div>
  18. <div>
  19. Creates a new [name].
  20. </div>
  21. <h2>Properties</h2>
  22. <h3>[property:boolean withCredentials]</h3>
  23. <div>
  24. If true, the ajax request will use cookies.
  25. </div>
  26. <h2>Properties inherited from [page:Loader]</h2>
  27. <h3>[property:Boolean showStatus]</h3>
  28. <div>If true, show loading status in the statusDomElement.</div>
  29. <h3>[property:DOMElement statusDomElement]</h3>
  30. <div>This is the recipient of status messages.</div>
  31. <h3>[property:Function onLoadStart]</h3>
  32. <div>Will be called when load starts.</div>
  33. <div>The default is a function with empty body.</div>
  34. <!--
  35. <h3>[property:Function onLoadProgress]</h3>
  36. <div>Will be called while load progresses.</div>
  37. <div>The default is a function with empty body.</div>
  38. -->
  39. <h3>[property:Function onLoadComplete]</h3>
  40. <div>Will be called when load completes.</div>
  41. <div>The default is a function with empty body.</div>
  42. <h2>Methods</h2>
  43. <h3>[method:null load]( [page:String url], [page:Function callback], [page:String texturePath] )</h3>
  44. <div>
  45. [page:String url] — required<br />
  46. [page:Function callback] — required. Will be called when load completes. The arguments will be the loaded [page:Object3D] and the loaded [page:Array materials].<br />
  47. [page:String texturePath] — optional. If not specified, textures will be assumed to be in the same folder as the Javascript model file.
  48. </div>
  49. <h3>[method:null loadAjaxJSON]([page:JSONLoader context], [page:String url], [page:Function callback], [page:String texturePath], [page:Function callbackProgress])</h3>
  50. <div>
  51. [page:JSONLoader context] — The [page:JSONLoader] instance<br />
  52. [page:String url] — required<br />
  53. [page:Function callback] — required. This function will be called with the loaded model as an instance of [page:Geometry geometry] when the load is completed.<br />
  54. [page:String texturePath] — Base path for textures.<br />
  55. [page:Function callbackProgress] — Will be called while load progresses. The argument will be an [page:Object] containing two attributes: .[page:Integer total] and .[page:Integer loaded] bytes.
  56. </div>
  57. <div>
  58. Begin loading from url and call <em>callback</em> with the parsed response content.
  59. </div>
  60. <h3>[method:Object3D parse]( [page:Object json], [page:String texturePath] )</h3>
  61. <div>
  62. [page:String json] — JSON object to parse.<br />
  63. [page:String texturePath] — Base path for textures.
  64. </div>
  65. <div>
  66. Parse a <em>JSON</em> structure and return an [page:Object] containing the parsed .[page:Geometry] and .[page:Array materials].
  67. </div>
  68. <h2>Methods inherited from [page:Loader]</h2>
  69. <h3>[method:Boolean needsTangents]( [page:Array materials] )</h3>
  70. <div>
  71. [page:Array materials] — an array of [page:Material]
  72. </div>
  73. <div>
  74. Checks if the loaded object needs tangents based on its materials.
  75. </div>
  76. <h3>[method:null updateProgress]( [page:object progress] )</h3>
  77. <div>
  78. [page:Object progress] — an object containing loaded(contains the amount of bytes loaded) and optionally total (containing the total amount of bytes).
  79. </div>
  80. <div>
  81. Updates the DOM object with the progress made.
  82. </div>
  83. <h3>[method:Material createMaterial]( [page:object m], [page:string texturePath] )</h3>
  84. <div>
  85. [page:Object m] — The parameters to create the material. <br />
  86. [page:String texturePath] — The base path of the textures.
  87. </div>
  88. <div>
  89. Creates the Material based on the parameters m.
  90. </div>
  91. <h3>[method:Array initMaterials]( [page:Array materials], [page:string texturePath] )</h3>
  92. <div>
  93. [page:Array materials] — an array of parameters to create materials. <br />
  94. [page:String texturePath] — The base path of the textures.
  95. </div>
  96. <div>
  97. Creates an array of [page:Material] based on the array of parameters m. The index of the parameters decide the correct index of the materials.
  98. </div>
  99. <h3>[method:String extractUrlBase]( [page:string url] )</h3>
  100. <div>
  101. [page:String url] — The url to extract the base url from.
  102. </div>
  103. <div>
  104. Extract the base from the URL.
  105. </div>
  106. <h3>[method:DOMElement addStatusElement]()</h3>
  107. <div>
  108. Add a DOM element to indicate the progress and return the DOMElement
  109. </div>
  110. <h2>Example</h2>
  111. <code>
  112. // instantiate a loader
  113. var loader = new THREE.JSONLoader();
  114. // load a resource
  115. loader.load(
  116. // resource URL
  117. 'models/animated/monster/monster.js',
  118. // Function when resource is loaded
  119. function ( geometry, materials ) {
  120. var material = new THREE.MeshFaceMaterial( materials );
  121. var object = new THREE.Mesh( geometry, material );
  122. scene.add( object );
  123. }
  124. );
  125. </code>
  126. [example:webgl_loader_json_blender]
  127. <h2>Source</h2>
  128. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  129. </body>
  130. </html>