JSONLoader.html 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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]()</h3>
  15. <div>
  16. Creates a new [name].
  17. </div>
  18. <h2>Properties</h2>
  19. <h3>[property:boolean withCredentials]</h3>
  20. <div>
  21. If true, the ajax request will use cookies.
  22. </div>
  23. <h2>Methods</h2>
  24. <h3>[method:null load]( [page:String url], [page:Function callback], [page:String texturePath] )</h3>
  25. <div>
  26. [page:String url] — required<br />
  27. [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 />
  28. [page:String texturePath] — optional. If not specified, textures will be assumed to be in the same folder as the Javascript model file.
  29. </div>
  30. <h3>[method:null loadAjaxJSON]([page:JSONLoader context], [page:String url], [page:Function callback], [page:String texturePath], [page:Function callbackProgress])</h3>
  31. <div>
  32. [page:JSONLoader context] — The [page:JSONLoader] instance<br />
  33. [page:String url] — required<br />
  34. [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 />
  35. [page:String texturePath] — Base path for textures.<br />
  36. [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.
  37. </div>
  38. <div>
  39. Begin loading from url and call <em>callback</em> with the parsed response content.
  40. </div>
  41. <h3>[method:Object3D parse]( [page:Object json], [page:String texturePath] )</h3>
  42. <div>
  43. [page:String json] — JSON object to parse.<br />
  44. [page:String texturePath] — Base path for textures.
  45. </div>
  46. <div>
  47. Parse a <em>JSON</em> structure and return an [page:Object] containing the parsed .[page:Geometry] and .[page:Array materials].
  48. </div>
  49. <h2>Example</h2>
  50. <code>
  51. // instantiate a loader
  52. var loader = new THREE.JSONLoader();
  53. // load a resource
  54. loader.load(
  55. // resource URL
  56. 'models/animated/monster/monster.js',
  57. // Function when resource is loaded
  58. function ( geometry, materials ) {
  59. var material = new THREE.MeshFaceMaterial( materials );
  60. var object = new THREE.Mesh( geometry, material );
  61. scene.add( object );
  62. }
  63. );
  64. </code>
  65. [example:webgl_loader_json_blender]
  66. <h2>Source</h2>
  67. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  68. </body>
  69. </html>