ObjectLoader.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  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. <p class="desc">
  13. A loader for loading a JSON resource in the [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format].<br /><br />
  14. This uses the [page:FileLoader] internally for loading files.
  15. </p>
  16. <h2>Code Example</h2>
  17. <code>
  18. const loader = new THREE.ObjectLoader();
  19. loader.load(
  20. // resource URL
  21. "models/json/example.json",
  22. // onLoad callback
  23. // Here the loaded data is assumed to be an object
  24. function ( obj ) {
  25. // Add the loaded object to the scene
  26. scene.add( obj );
  27. },
  28. // onProgress callback
  29. function ( xhr ) {
  30. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  31. },
  32. // onError callback
  33. function ( err ) {
  34. console.error( 'An error happened' );
  35. }
  36. );
  37. // Alternatively, to parse a previously loaded JSON structure
  38. const object = loader.parse( a_json_object );
  39. scene.add( object );
  40. </code>
  41. <h2>Examples</h2>
  42. <p>
  43. [example:webgl_materials_lightmap WebGL / materials / lightmap]
  44. </p>
  45. <h2>Constructor</h2>
  46. <h3>[name]( [param:LoadingManager manager] )</h3>
  47. <p>
  48. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  49. Creates a new [name].
  50. </p>
  51. <h2>Properties</h2>
  52. <p>See the base [page:Loader] class for common properties.</p>
  53. <h2>Methods</h2>
  54. <p>See the base [page:Loader] class for common methods.</p>
  55. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  56. <p>
  57. [page:String url] — the path or URL to the file. This can also be a
  58. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  59. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Object3D object].<br />
  60. [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 />
  61. [page:Function onError] — Will be called when load errors.<br />
  62. </p>
  63. <p>
  64. Begin loading from url and call onLoad with the parsed response content.
  65. </p>
  66. <h3>[method:Object3D parse]( [param:Object json], [param:Function onLoad] )</h3>
  67. <p>
  68. [page:Object json] — required. The JSON source to parse.<br /><br />
  69. [page:Function onLoad] — Will be called when parsed completes. The argument will be the parsed [page:Object3D object].<br /><br />
  70. Parse a <em>JSON</em> structure and return a threejs object.
  71. This is used internally by [page:.load]() but can also be used directly to parse a previously loaded JSON structure.
  72. </p>
  73. <h3>[method:Object3D parseGeometries]( [param:Object json] )</h3>
  74. <p>
  75. [page:Object json] — required. The JSON source to parse.<br /><br />
  76. This is used by [page:.parse]() to parse any [page:BufferGeometry geometries] in the JSON structure.
  77. </p>
  78. <h3>[method:Object3D parseMaterials]( [param:Object json] )</h3>
  79. <p>
  80. [page:Object json] — required. The JSON source to parse.<br /><br />
  81. This is used by [page:.parse]() to parse any materials in the JSON structure using [page:MaterialLoader].
  82. </p>
  83. <h3>[method:Object3D parseAnimations]( [param:Object json] )</h3>
  84. <p>
  85. [page:Object json] — required. The JSON source to parse.<br /><br />
  86. This is used by [page:.parse]() to parse any animations in the JSON structure, using [page:AnimationClip.parse]().
  87. </p>
  88. <h3>[method:Object3D parseImages]( [param:Object json] )</h3>
  89. <p>
  90. [page:Object json] — required. The JSON source to parse.<br /><br />
  91. This is used by [page:.parse]() to parse any images in the JSON structure, using [page:ImageLoader].
  92. </p>
  93. <h3>[method:Object3D parseTextures]( [param:Object json] )</h3>
  94. <p>
  95. [page:Object json] — required. The JSON source to parse.<br /><br />
  96. This is used by [page:.parse]() to parse any textures in the JSON structure.
  97. </p>
  98. <h3>[method:Object3D parseObject]( [param:Object json], [param:BufferGeometry geometries], [param:Material materials], [param:AnimationClip animations] )</h3>
  99. <p>
  100. [page:Object json] — required. The JSON source to parse.<br />
  101. [page:BufferGeometry geometries] — required. The geometries of the JSON.<br />
  102. [page:Material materials] — required. The materials of the JSON.<br />
  103. [page:AnimationClip animations] — required. The animations of the JSON.<br /><br />
  104. This is used by [page:.parse]() to parse any 3D objects in the JSON structure.
  105. </p>
  106. <h2>Source</h2>
  107. <p>
  108. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  109. </p>
  110. </body>
  111. </html>