LoaderSupport.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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">Supporting classes for file loaders and web worker based loaders.</p>
  13. <h2>Sub-Classes</h2>
  14. [page:LoaderSupport.Builder]<br>
  15. [page:LoaderSupport.LoadedMeshUserOverride]<br>
  16. [page:LoaderSupport.WorkerSupport]<br>
  17. [page:LoaderSupport.WorkerRunnerRefImpl]<br>
  18. [page:LoaderSupport.WorkerDirector]<br>
  19. [page:LoaderSupport.ResourceDescriptor]<br>
  20. [page:LoaderSupport.PrepData]<br>
  21. [page:LoaderSupport.Callbacks]<br>
  22. [page:LoaderSupport.Validator]<br>
  23. <h2>Example</h2>
  24. [example:webgl_loader_obj2_meshspray] - Example using [page:LoaderSupport.LoaderWorkerDirector] and [page:LoaderSupport.LoaderWorkerSupport].<br>
  25. <h2>Classes</h2>
  26. <br>
  27. <a name="Builder"></a><h1>Builder</h1>
  28. <h2>Constructor</h2>
  29. <h3>Builder()</h3>
  30. <p>
  31. Builds one or many [page:Mesh] from one raw set of Arraybuffers, materialGroup descriptions and further parameters.
  32. Supports vertex, vertexColor, normal, uv and index buffers.
  33. </p>
  34. <h2>Methods</h2>
  35. <h3>[method:null setLogging] ( [param:Boolean enabled], [param:Boolean debug] )</h3>
  36. <p>
  37. [page:Boolean enabled] True or false.<br>
  38. [page:Boolean debug] True or false.
  39. </p>
  40. <p>
  41. Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
  42. </p>
  43. <h3>[method:null init] ()</h3>
  44. <p>
  45. Initializes the Builder (currently only default material initialisation).
  46. </p>
  47. <h3>[method:null setMaterials] ( Array of [param:Material materials] )</h3>
  48. <p>
  49. Array of [page:Material materials] - Array of [page:Material Materials]
  50. </p>
  51. <p>
  52. Set materials loaded by any supplier of an Array of [page:Material Materials].
  53. </p>
  54. <h3>[method:Array processPayload] ( Object payload )</h3>
  55. <p>
  56. [page:Object payload] - Raw Mesh or Material descriptions.
  57. </p>
  58. <p>
  59. Delegates processing of the payload (mesh building or material update) to the corresponding functions (BW-compatibility).
  60. </p>
  61. <h3>[method:Array buildMeshes] ( Object meshPayload )</h3>
  62. <p>
  63. [page:Object meshPayload] - Raw mesh description (buffers, params, materials) used to build one to many meshes.
  64. </p>
  65. <p>
  66. Builds one or multiple meshes from the data described in the payload (buffers, params, material info).
  67. </p>
  68. <h3>[method:null updateMaterials] ( Object materialPayload )</h3>
  69. <p>
  70. [page:Object materialPayload] - Material update instructions
  71. </p>
  72. <p>
  73. Updates the materials with contained material objects (sync) or from alteration instructions (async).
  74. </p>
  75. <h3>[method:Object getMaterialsJSON] ()</h3>
  76. <p>
  77. Returns the mapping object of material name and corresponding jsonified material.
  78. </p>
  79. <h3>[method:Object getMaterials] ()</h3>
  80. <p>
  81. Returns the mapping object of material name and corresponding material.
  82. </p>
  83. <br>
  84. <br>
  85. <a name="LoadedMeshUserOverride"></a><h1>LoadedMeshUserOverride</h1>
  86. <h2>Constructor</h2>
  87. <h3>LoadedMeshUserOverride( [param:Boolean disregardMesh], [param:BufferGeometry bufferGeometry] )</h3>
  88. <p>
  89. [page:Boolean disregardMesh] - Tell implementation to completely disregard this mesh<br>
  90. [page:Boolean alteredMesh] - Tell implementation that mesh(es) have been altered or added
  91. </p>
  92. <p>
  93. Object to return by callback onMeshAlter. Used to disregard a certain mesh or to return one to many meshes.
  94. </p>
  95. <h2>Methods</h2>
  96. <h3>[method:null addMesh] ( [param:Mesh mesh] )</h3>
  97. <p>
  98. [page:Mesh mesh] - Mesh
  99. </p>
  100. <p>
  101. Add a mesh created within callback.
  102. </p>
  103. <h3>[method:boolean isDisregardMesh] ()</h3>
  104. <p>
  105. Answers if mesh shall be disregarded completely.
  106. </p>
  107. <h3>[method:boolean providesAlteredMeshes] ()</h3>
  108. <p>
  109. Answers if new mesh(es) were created.
  110. </p>
  111. <br>
  112. <br>
  113. <a name="WorkerSupport"></a><h1>WorkerSupport</h1>
  114. <h2>Constructor</h2>
  115. <h3>WorkerSupport()</h3>
  116. <p>
  117. This class provides means to transform existing parser code into a web worker.
  118. It defines a simple communication protocol which allows to configure the worker and receive raw mesh data during execution.
  119. </p>
  120. <h2>Methods</h2>
  121. <h3>[method:null setLogging]( [param:Boolean enabled], [param:Boolean debug] )</h3>
  122. <p>
  123. [page:Boolean enabled] True or false.<br>
  124. [page:Boolean debug] True or false.
  125. </p>
  126. <p>
  127. Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
  128. </p>
  129. <h3>[method:null setForceWorkerDataCopy]( [param:Boolean forceWorkerDataCopy] )</h3>
  130. <p>
  131. [page:Boolean forceWorkerDataCopy] True or false.
  132. </p>
  133. <p>
  134. Forces all ArrayBuffers to be transferred to worker to be copied.
  135. </p>
  136. <h3>[method:null validate] ( [param:Function functionCodeBuilder], Array of [param:String libLocations], [param:String libPath], [param:LoaderSupport.WorkerRunnerRefImpl runnerImpl] )</h3>
  137. <p>
  138. [page:Function functionCodeBuilder] - Function that is invoked with funcBuildObject and funcBuildSingleton that allows stringification of objects and singletons.<br>
  139. Array of [page:String libLocations] - URL of libraries that shall be added to worker code relative to libPath.<br>
  140. [page:String libPath] - Base path used for loading libraries.<br>
  141. [page:LoaderSupport.WorkerRunnerRefImpl runnerImpl] - The default worker parser wrapper implementation (communication and execution). An extended class could be passed here.
  142. </p>
  143. <p>
  144. Validate the status of worker code and the derived worker.
  145. </p>
  146. <h3>[method:null setTerminateRequested] ( [param:Boolean terminateRequested] )</h3>
  147. <p>
  148. [page:Boolean terminateRequested] - True or false.
  149. </p>
  150. <p>
  151. Request termination of worker once parser is finished.
  152. </p>
  153. <h3>[method:null setCallbacks] ( [param:Function builder], [param:Function onLoad] )</h3>
  154. <p>
  155. [page:Function builder] - The builder function. Default is [page:LoaderSupport.Builder].<br>
  156. [page:Function onLoad] - The function that is called when parsing is complete.
  157. </p>
  158. <p>
  159. Specify functions that should be build when new raw mesh data becomes available and when the parser is finished.
  160. </p>
  161. <h3>[method:null run] ( [param:Object payload] )</h3>
  162. <p>
  163. [page:Object payload] - Raw mesh description (buffers, params, materials) used to build one to many meshes.
  164. </p>
  165. <p>
  166. Runs the parser with the provided configuration.
  167. </p>
  168. <br>
  169. <br>
  170. <a name="WorkerRunnerRefImpl"></a><h1>WorkerRunnerRefImpl</h1>
  171. <h2>Constructor</h2>
  172. <h3>WorkerRunnerRefImpl()</h3>
  173. <p>
  174. Default implementation of the WorkerRunner responsible for creation and configuration of the parser within the worker.
  175. </p>
  176. <h2>Methods</h2>
  177. <h3>[method:null applyProperties] ( [param:Object parser], [param:Object params] )</h3>
  178. <p>
  179. [page:Object parser] - The parser instance<br>
  180. [page:Object params] - The parameter object
  181. </p>
  182. <p>
  183. Applies values from parameter object via set functions or via direct assignment.
  184. </p>
  185. <h3>[method:null run] ( [param:Object payload] )</h3>
  186. <p>
  187. [page:Object payload] - Raw mesh description (buffers, params, materials) used to build one to many meshes.
  188. </p>
  189. <p>
  190. Configures the Parser implementation according the supplied configuration object.
  191. </p>
  192. <br>
  193. <br>
  194. <a name="WorkerDirector"></a><h1>WorkerDirector</h1>
  195. <h2>Constructor</h2>
  196. <h3>WorkerDirector( [param:String classDef] )</h3>
  197. <p>
  198. [page:String classDef] - Class definition to be used for construction
  199. </p>
  200. <p>
  201. Orchestrate loading of multiple OBJ files/data from an instruction queue with a configurable amount of workers (1-16).<br>
  202. - Workflow:<br>
  203. - prepareWorkers<br>
  204. - enqueueForRun<br>
  205. - processQueue<br>
  206. - tearDown
  207. </p>
  208. <h2>Methods</h2>
  209. <h3>[method:null setLogging]( [param:Boolean enabled], [param:Boolean debug] )</h3>
  210. <p>
  211. [page:Boolean enabled] True or false.<br>
  212. [page:Boolean debug] True or false.
  213. </p>
  214. <p>
  215. Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
  216. </p>
  217. <h3>[method:null setForceWorkerDataCopy]( [param:Boolean forceWorkerDataCopy] )</h3>
  218. <p>
  219. [page:Boolean forceWorkerDataCopy] True or false.
  220. </p>
  221. <p>
  222. Forces all ArrayBuffers to be transferred to worker to be copied.
  223. </p>
  224. <h3>[method:null prepareWorkers]( [param:WWOBJLoader2.Callbacks globalCallbacks], [param:Number maxQueueSize], [param:Number maxWebWorkers] )</h3>
  225. <p>
  226. [page:LoaderSupport.Callbacks globalCallbacks] - Register global callbacks used by all web workers<br>
  227. [page:Number maxQueueSize] - Set the maximum size of the instruction queue (1-1024)<br>
  228. [page:Number maxWebWorkers] - Set the maximum amount of workers (1-16)
  229. </p>
  230. <p>
  231. Create or destroy workers according limits. Set the name and register callbacks for dynamically created web workers.
  232. </p>
  233. <h3>[method:null enqueueForRun]( [param:LoaderSupport.PrepData runParams] )</h3>
  234. <p>
  235. [page:LoaderSupport.PrepData runParams]
  236. </p>
  237. <p>
  238. Store run instructions in internal instructionQueue.
  239. </p>
  240. <h3>[method:null processQueue]()</h3>
  241. <p>
  242. Process the instructionQueue until it is depleted.
  243. </p>
  244. <h3>[method:null tearDown]( [param:Function callbackOnFinishedProcessing] )</h3>
  245. <p>
  246. [page:Function callbackOnFinishedProcessing] - Function called once all workers finished processing.
  247. </p>
  248. <p>
  249. Terminate all workers.
  250. </p>
  251. <h3>[method:null getMaxQueueSize]()</h3>
  252. <p>
  253. Returns the maximum length of the instruction queue.
  254. </p>
  255. <h3>[method:null getMaxWebWorkers]()</h3>
  256. <p>
  257. Returns the maximum number of workers.
  258. </p>
  259. <h3>[method:Boolean isRunning]()</h3>
  260. <p>
  261. Returns if any workers are running.
  262. </p>
  263. <h3>[method:null setCrossOrigin]( [param:String crossOrigin] )</h3>
  264. <p>
  265. [page:String crossOrigin] - CORS value
  266. </p>
  267. <p>
  268. Sets the CORS string to be used.
  269. </p>
  270. <br>
  271. <br>
  272. <a name="ResourceDescriptor"></a><h1>ResourceDescriptor</h1>
  273. <h2>Constructor</h2>
  274. <h3>ResourceDescriptor( [param:String url], [param:String extension] )</h3>
  275. <p>
  276. [page:String url] - URL to the file<br>
  277. [page:String extension] - The file extension (type)
  278. </p>
  279. <p>
  280. A resource description used by [page:LoaderSupport.PrepData] and others.
  281. </p>
  282. <h2>Methods</h2>
  283. <h3>[method:null setContent]( [param:Object content )</h3>
  284. <p>
  285. [page:Object content] - The file content as ArrayBuffer or text
  286. </p>
  287. <p>
  288. Set the content of this resource
  289. </p>
  290. <br>
  291. <br>
  292. <a name="PrepData"></a><h1>PrepData</h1>
  293. <h2>Constructor</h2>
  294. <h3>PrepData( [param:String modelName] )</h3>
  295. <p>
  296. [page:String modelName] - Overall name of the model
  297. </p>
  298. <p>
  299. Configuration instructions to be used by run method.
  300. </p>
  301. <h2>Methods</h2>
  302. <h3>[method:null setLogging]( [param:Boolean enabled], [param:Boolean debug] )</h3>
  303. <p>
  304. [page:Boolean enabled] True or false.<br>
  305. [page:Boolean debug] True or false.
  306. </p>
  307. <p>
  308. Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
  309. </p>
  310. <h3>[method:Callbacks getCallbacks]()</h3>
  311. <p>
  312. Returns all callbacks as [page:LoaderSupport.Callbacks].
  313. </p>
  314. <h3>[method:null addResource]( [param:LoaderSupport.ResourceDescriptor resource] )</h3>
  315. <p>
  316. [page:LoaderSupport.ResourceDescriptor resource] Adds a [page:LoaderSupport.ResourceDescriptor]
  317. </p>
  318. <p>
  319. Add a resource description.
  320. </p>
  321. <h3>[method:null checkResourceDescriptorFiles] ( [param:LoaderSupport.ResourceDescriptor resources], [param:Object fileDesc] )</h3>
  322. <p>
  323. [page:LoaderSupport.ResourceDescriptor resources] - Array of [page:LoaderSupport.ResourceDescriptor]<br>
  324. [page:Object fileDesc] - Object describing which resources are of interest (ext, type (string or UInt8Array) and ignore (boolean))
  325. </p>
  326. <p>
  327. Identify files or content of interest from an Array of [page:LoaderSupport.ResourceDescriptor].
  328. Returns Object with each "ext" and the corresponding [page:LoaderSupport.ResourceDescriptor]
  329. </p>
  330. <h3>[method:PrepData clone] ()</h3>
  331. <p>
  332. Clones this object and returns it afterwards. Callbacks and resources are not cloned deep (references!).
  333. </p>
  334. <br>
  335. <br>
  336. <a name="Callbacks"></a><h1>Callbacks</h1>
  337. <h2>Constructor</h2>
  338. <h3>Callbacks()</h3>
  339. <p>
  340. Callbacks utilized by loaders and builder.
  341. </p>
  342. <h2>Methods</h2>
  343. <h3>[method:null setCallbackOnProgress]( [param:Function callbackOnProgress] )</h3>
  344. <p>
  345. [page:Function callbackOnProgress] - Callback function for described functionality
  346. </p>
  347. <p>
  348. Register callback function that is invoked by internal function "announceProgress" to print feedback.
  349. </p>
  350. <h3>[method:null setCallbackOnMeshAlter]( [param:Function callbackOnMeshAlter] )</h3>
  351. <p>
  352. [page:Function callbackOnMeshAlter] - Callback function for described functionality
  353. </p>
  354. <p>
  355. Register callback function that is called every time a mesh was loaded.
  356. Use [page:LoadedMeshUserOverride] for alteration instructions (geometry, material or disregard mesh).
  357. </p>
  358. <h3>[method:null setCallbackOnLoad]( [param:Function callbackOnLoad] )</h3>
  359. <p>
  360. [page:Function callbackOnLoad] - Callback function for described functionality
  361. </p>
  362. <p>
  363. Register callback function that is called once loading of the complete OBJ file is completed.
  364. </p>
  365. <h3>[method:null setCallbackOnLoadMaterials]( [param:Function callbackOnLoadMaterials] )</h3>
  366. <p>
  367. [page:Function callbackOnLoadMaterials] - Callback function for described functionality
  368. </p>
  369. <p>
  370. Register callback function that is called when materials have been loaded.
  371. </p>
  372. <br>
  373. <br>
  374. <a name="Validator"></a><h1>Validator</h1>
  375. <h2>Constructor</h2>
  376. <h3>Validator()</h3>
  377. <p>
  378. Validation functions.
  379. </p>
  380. <h2>Methods</h2>
  381. <h3>[method:Boolean isValid]( [param:Object input] )</h3>
  382. <p>
  383. [page:Object input] - Can be anything
  384. </p>
  385. <p>
  386. If given input is null or undefined, false is returned otherwise true.
  387. </p>
  388. <h3>[method:null verifyInput]( [param:Object input], [param:Object defaultValue] )</h3>
  389. <p>
  390. [page:Object input] - Can be anything<br>
  391. [page:Object defaultValue] - Can be anything
  392. </p>
  393. <p>
  394. If given input is null or undefined, the defaultValue is returned otherwise the given input.
  395. </p>
  396. <br>
  397. <br>
  398. <h2>Source</h2>
  399. [link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/LoaderSupport.js examples/js/loaders/LoaderSupport.js]
  400. </body>
  401. </html>