LoaderSupport.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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. <div class="desc">Supporting classes for file loaders and web worker based loaders.</div>
  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.PrepData]<br>
  20. [page:LoaderSupport.LoaderBase]<br>
  21. [page:LoaderSupport.Callbacks]<br>
  22. [page:LoaderSupport.Validator]<br>
  23. [page:LoaderSupport.ConsoleLogger]
  24. <h2>Example</h2>
  25. [example:webgl_loader_obj2_meshspray] - Example using [page:LoaderSupport.LoaderWorkerDirector] and [page:LoaderSupport.LoaderWorkerSupport].<br>
  26. <h2>Classes</h2>
  27. <br>
  28. <a name="Builder"></a><h1>Builder</h1>
  29. <h2>Constructor</h2>
  30. <h3>Builder()</h3>
  31. <div>
  32. Builds one or many [page:Mesh] from one raw set of Arraybuffers, materialGroup descriptions and further parameters.
  33. Supports vertex, vertexColor, normal, uv and index buffers.
  34. </div>
  35. <h2>Methods</h2>
  36. <h3>[method:null setMaterials] ( Array of [page:Material materials] )</h3>
  37. <div>
  38. Array of [page:Material materials] - Array of [page:Material Materials]
  39. </div>
  40. <div>
  41. Set materials loaded by any supplier of an Array of [page:Material Materials].
  42. </div>
  43. <h3>[method:Array processPayload] ( Object payload )</h3>
  44. <div>
  45. [page:Object payload] - Raw Mesh or Material descriptions.
  46. </div>
  47. <div>
  48. Delegates processing of the payload (mesh building or material update) to the corresponding functions (BW-compatibility).
  49. </div>
  50. <br>
  51. <br>
  52. <h3>[method:Array buildMeshes] ( Object meshPayload )</h3>
  53. <div>
  54. [page:Object meshPayload] - Raw mesh description (buffers, params, materials) used to build one to many meshes.
  55. </div>
  56. <div>
  57. Builds one or multiple meshes from the data described in the payload (buffers, params, material info).
  58. </div>
  59. <br>
  60. <br>
  61. <h3>[method:null updateMaterials] ( Object materialPayload )</h3>
  62. <div>
  63. [page:Object materialPayload] - Material update instructions
  64. </div>
  65. <div>
  66. Updates the materials with contained material objects (sync) or from alteration instructions (async).
  67. </div>
  68. <br>
  69. <br>
  70. <h3>[method:Object getMaterialsJSON] ()</h3>
  71. <div>
  72. Returns the mapping object of material name and corresponding jsonified material.
  73. </div>
  74. <br>
  75. <br>
  76. <h3>[method:Object getMaterials] ()</h3>
  77. <div>
  78. Returns the mapping object of material name and corresponding material.
  79. </div>
  80. <br>
  81. <br>
  82. <a name="LoadedMeshUserOverride"></a><h1>LoadedMeshUserOverride</h1>
  83. <h2>Constructor</h2>
  84. <h3>LoadedMeshUserOverride( [page:Boolean disregardMesh], [page:BufferGeometry bufferGeometry] )</h3>
  85. <div>
  86. [page:Boolean disregardMesh] - Tell implementation to completely disregard this mesh<br>
  87. [page:Boolean alteredMesh] - Tell implementation that mesh(es) have been altered or added
  88. </div>
  89. <div>
  90. Object to return by callback onMeshAlter. Used to disregard a certain mesh or to return one to many meshes.
  91. </div>
  92. <h2>Methods</h2>
  93. <h3>[method:null addMesh] ( [page:Mesh mesh] )</h3>
  94. <div>
  95. [page:Mesh mesh] - Mesh
  96. </div>
  97. <div>
  98. Add a mesh created within callback.
  99. </div>
  100. <h3>[method:boolean isDisregardMesh] ()</h3>
  101. <div>
  102. Answers if mesh shall be disregarded completely.
  103. </div>
  104. <h3>[method:boolean providesAlteredMeshes] ()</h3>
  105. <div>
  106. Answers if new mesh(es) were created.
  107. </div>
  108. <br>
  109. <br>
  110. <a name="WorkerSupport"></a><h1>WorkerSupport</h1>
  111. <h2>Constructor</h2>
  112. <h3>WorkerSupport( [page:LoaderSupport.ConsoleLogger logger] )</h3>
  113. <div>
  114. [page:LoaderSupport.ConsoleLogger logger] - logger to be used
  115. </div>
  116. <div>
  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. </div>
  120. <h2>Methods</h2>
  121. <h3>[method:null validate] ( [page:Function functionCodeBuilder], Array of [page:String libLocations], [page:String libPath], [page:LoaderSupport.WorkerRunnerRefImpl runnerImpl] )</h3>
  122. <div>
  123. [page:Function functionCodeBuilder] - Function that is invoked with funcBuildObject and funcBuildSingelton that allows stringification of objects and singletons.<br>
  124. Array of [page:String libLocations] - URL of libraries that shall be added to worker code relative to libPath.<br>
  125. [page:String libPath] - Base path used for loading libraries.<br>
  126. [page:LoaderSupport.WorkerRunnerRefImpl runnerImpl] - The default worker parser wrapper implementation (communication and execution). An extended class could be passed here.
  127. </div>
  128. <div>
  129. Validate the status of worker code and the derived worker.
  130. </div>
  131. <h3>[method:null setTerminateRequested] ( [page:Boolean terminateRequested] )</h3>
  132. <div>
  133. [page:Boolean terminateRequested] - True or false.
  134. </div>
  135. <div>
  136. Request termination of worker once parser is finished.
  137. </div>
  138. <h3>[method:null setCallbacks] ( [page:Function builder], [page:Function onLoad] )</h3>
  139. <div>
  140. [page:Function builder] - The builder function. Default is [page:LoaderSupport.Builder].<br>
  141. [page:Function onLoad] - The function that is called when parsing is complete.
  142. </div>
  143. <div>
  144. Specify functions that should be build when new raw mesh data becomes available and when the parser is finished.
  145. </div>
  146. <h3>[method:null run] ( [page:Object payload] )</h3>
  147. <div>
  148. [page:Object payload] - Raw mesh description (buffers, params, materials) used to build one to many meshes.
  149. </div>
  150. <div>
  151. Runs the parser with the provided configuration.
  152. </div>
  153. <br>
  154. <br>
  155. <a name="WorkerRunnerRefImpl"></a><h1>WorkerRunnerRefImpl</h1>
  156. <h2>Constructor</h2>
  157. <h3>WorkerRunnerRefImpl()</h3>
  158. <div>
  159. Default implementation of the WorkerRunner responsible for creation and configuration of the parser within the worker.
  160. </div>
  161. <h2>Methods</h2>
  162. <h3>[method:null applyProperties] ( [page:Object parser], [page:Object params] )</h3>
  163. <div>
  164. [page:Object parser] - The parser instance<br>
  165. [page:Object params] - The parameter object
  166. </div>
  167. <div>
  168. Applies values from parameter object via set functions or via direct assignment.
  169. </div>
  170. <h3>[method:null run] ( [page:Object payload] )</h3>
  171. <div>
  172. [page:Object payload] - Raw mesh description (buffers, params, materials) used to build one to many meshes.
  173. </div>
  174. <div>
  175. Configures the Parser implementation according the supplied configuration object.
  176. </div>
  177. <br>
  178. <br>
  179. <a name="WorkerDirector"></a><h1>WorkerDirector</h1>
  180. <h2>Constructor</h2>
  181. <h3>WorkerDirector( [page:String classDef], [page:LoaderSupport.ConsoleLogger logger] )</h3>
  182. <div>
  183. [page:String classDef] - Class definition to be used for construction<br>
  184. [page:LoaderSupport.ConsoleLogger logger] - logger to be used
  185. </div>
  186. <div>
  187. Orchestrate loading of multiple OBJ files/data from an instruction queue with a configurable amount of workers (1-16).<br>
  188. - Workflow:<br>
  189. - prepareWorkers<br>
  190. - enqueueForRun<br>
  191. - processQueue<br>
  192. - tearDown
  193. </div>
  194. <h2>Methods</h2>
  195. <h3>[method:null prepareWorkers]( [page:WWOBJLoader2.Callbacks globalCallbacks], [page:Number maxQueueSize], [page:Number maxWebWorkers] )</h3>
  196. <div>
  197. [page:LoaderSupport.Callbacks globalCallbacks] - Register global callbacks used by all web workers<br>
  198. [page:Number maxQueueSize] - Set the maximum size of the instruction queue (1-1024)<br>
  199. [page:Number maxWebWorkers] - Set the maximum amount of workers (1-16)
  200. </div>
  201. <div>
  202. Create or destroy workers according limits. Set the name and register callbacks for dynamically created web workers.
  203. </div>
  204. <h3>[method:null enqueueForRun]( [page:LoaderSupport.PrepData runParams] )</h3>
  205. <div>
  206. [page:LoaderSupport.PrepData runParams]
  207. </div>
  208. <div>
  209. Store run instructions in internal instructionQueue.
  210. </div>
  211. <h3>[method:null processQueue]()</h3>
  212. <div>
  213. Process the instructionQueue until it is depleted.
  214. </div>
  215. <h3>[method:null tearDown]( [page:Function callbackOnFinishedProcessing] )</h3>
  216. <div>
  217. [page:Function callbackOnFinishedProcessing] - Function called once all workers finished processing.
  218. </div>
  219. <div>
  220. Terminate all workers.
  221. </div>
  222. <h3>[method:null getMaxQueueSize]()</h3>
  223. <div>
  224. Returns the maximum length of the instruction queue.
  225. </div>
  226. <h3>[method:null getMaxWebWorkers]()</h3>
  227. <div>
  228. Returns the maximum number of workers.
  229. </div>
  230. <h3>[method:Boolean isRunning]()</h3>
  231. <div>
  232. Returns if any workers are running.
  233. </div>
  234. <h3>[method:null setCrossOrigin]( [page:String crossOrigin] )</h3>
  235. <div>
  236. [page:String crossOrigin] - CORS value
  237. </div>
  238. <div>
  239. Sets the CORS string to be used.
  240. </div>
  241. <a name="PrepData"></a><h1>PrepData</h1>
  242. <h2>Constructor</h2>
  243. <h3>PrepData( [page:String modelName] )</h3>
  244. <div>
  245. [page:String modelName] - Overall name of the model
  246. </div>
  247. <div>
  248. Configuration instructions to be used by run method.
  249. </div>
  250. <h2>Methods</h2>
  251. <h3>[method:null setStreamMeshesTo] ( [page:Object3D streamMeshesTo] )</h3>
  252. <div>
  253. [page:Object3D streamMeshesTo] - Object already attached to scenegraph where new meshes will be attached to
  254. </div>
  255. <div>
  256. Set the node where the loaded objects will be attached directly.
  257. </div>
  258. <h3>[method:null setMaterialPerSmoothingGroup] ( [page:boolean materialPerSmoothingGroup] )</h3>
  259. <div>
  260. [page:boolean materialPerSmoothingGroup]
  261. </div>
  262. <div>
  263. Tells whether a material shall be created per smoothing group.
  264. </div>
  265. <h3>[method:null setUseIndices]( [page:Boolean useIndices] )</h3>
  266. <div>
  267. [page:Boolean useIndices] - Default is false
  268. </div>
  269. <div>
  270. Instructs loaders to create indexed [page:BufferGeometry].
  271. </div>
  272. <h3>[method:null setDisregardNormals]( [page:Boolean disregardNormals] )</h3>
  273. <div>
  274. [page:Boolean disregardNormals]
  275. </div>
  276. <div>
  277. Tells whether normals should be completely disregarded and regenerated.
  278. </div>
  279. <h3>[method:Callbacks getCallbacks]()</h3>
  280. <div>
  281. Returns all callbacks as [page:LoaderSupport.Callbacks].
  282. </div>
  283. <h3>[method:null setCrossOrigin]( [page:String crossOrigin] )</h3>
  284. <div>
  285. [page:String crossOrigin] - CORS value
  286. </div>
  287. <div>
  288. Sets the CORS string to be used.
  289. </div>
  290. <h3>[method:null addResource]( [page:LoaderSupport.ResourceDescriptor resource] )</h3>
  291. <div>
  292. [page:LoaderSupport.ResourceDescriptor resource]
  293. </div>
  294. <div>
  295. Add a resource description.
  296. </div>
  297. <h3>[method:null setUseAsync]( [page:Boolean useAsync] )</h3>
  298. <div>
  299. [page:Boolean useAsync]
  300. </div>
  301. <div>
  302. If true uses async loading with worker, if false loads data synchronously.
  303. </div>
  304. <br>
  305. <br>
  306. <a name="LoaderBase"></a><h1>LoaderBase</h1>
  307. <h2>Constructor</h2>
  308. <h3>LoaderBase( [page:LoadingManager manager], [page:LoaderSupport.ConsoleLogger logger] )</h3>
  309. <div>
  310. [page:LoadingManager manager] - The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
  311. [page:LoaderSupport.ConsoleLogger logger] - logger to be used
  312. </div>
  313. <div>
  314. Base class to be used by loaders.
  315. </div>
  316. <h2>Methods</h2>
  317. <h3>[method:ConsoleLogger getLogger] ()</h3>
  318. <div>
  319. Returns [page:LoaderSupport.ConsoleLogger].
  320. </div>
  321. <h3>[method:null setModelName] ( [page:String modelName] )</h3>
  322. <div>
  323. [page:String modelName]
  324. </div>
  325. <div>
  326. Set the name of the model.
  327. </div>
  328. <h3>[method:null setPath] ( [page:String path] )</h3>
  329. <div>
  330. [page:String path] - URL
  331. </div>
  332. <div>
  333. The URL of the base path.
  334. </div>
  335. <h3>[method:null setStreamMeshesTo] ( [page:Object3D streamMeshesTo] )</h3>
  336. <div>
  337. [page:Object3D streamMeshesTo] - Object already attached to scenegraph where new meshes will be attached to
  338. </div>
  339. <div>
  340. Set the node where the loaded objects will be attached directly.
  341. </div>
  342. <h3>[method:null setMaterials] ( Array of [page:Material materials] )</h3>
  343. <div>
  344. Array of [page:Material materials] - Array of [page:Material Materials]
  345. </div>
  346. <div>
  347. Set materials loaded by MTLLoader or any other supplier of an Array of [page:Material Materials].
  348. </div>
  349. <h3>[method:null setUseIndices]( [page:Boolean useIndices] )</h3>
  350. <div>
  351. [page:Boolean useIndices]
  352. </div>
  353. <div>
  354. Instructs loaders to create indexed [page:BufferGeometry].
  355. </div>
  356. <h3>[method:null setDisregardNormals]( [page:Boolean disregardNormals] )</h3>
  357. <div>
  358. [page:Boolean disregardNormals]
  359. </div>
  360. <div>
  361. Tells whether normals should be completely disregarded and regenerated.
  362. </div>
  363. <h3>[method:null onProgress]( [page:String type], [page:String text], [page:Number numericalValue] )</h3>
  364. <div>
  365. [page:String type] - The type of event<br>
  366. [page:String text] - Textual description of the event<br>
  367. [page:Number numericalValue] - Numerical value describing the progress
  368. </div>
  369. <div>
  370. Announce feedback which is give to the registered [page:LoaderSupport.Callbacks].
  371. </div>
  372. <br>
  373. <br>
  374. <a name="Callbacks"></a><h1>Callbacks</h1>
  375. <h2>Constructor</h2>
  376. <h3>Callbacks()</h3>
  377. <div>
  378. Callbacks utilized by loaders and builder.
  379. </div>
  380. <h2>Methods</h2>
  381. <h3>[method:null setCallbackOnProgress]( [page:Function callbackOnProgress] )</h3>
  382. <div>
  383. [page:Function callbackOnProgress] - Callback function for described functionality
  384. </div>
  385. <div>
  386. Register callback function that is invoked by internal function "announceProgress" to print feedback.
  387. </div>
  388. <h3>[method:null setCallbackOnMeshAlter]( [page:Function callbackOnMeshAlter] )</h3>
  389. <div>
  390. [page:Function callbackOnMeshAlter] - Callback function for described functionality
  391. </div>
  392. <div>
  393. Register callback function that is called every time a mesh was loaded.
  394. Use [page:LoadedMeshUserOverride] for alteration instructions (geometry, material or disregard mesh).
  395. </div>
  396. <h3>[method:null setCallbackOnLoad]( [page:Function callbackOnLoad] )</h3>
  397. <div>
  398. [page:Function callbackOnLoad] - Callback function for described functionality
  399. </div>
  400. <div>
  401. Register callback function that is called once loading of the complete OBJ file is completed.
  402. </div>
  403. <h3>[method:null setCallbackOnLoadMaterials]( [page:Function callbackOnLoadMaterials] )</h3>
  404. <div>
  405. [page:Function callbackOnLoadMaterials] - Callback function for described functionality
  406. </div>
  407. <div>
  408. Register callback function that is called when materials have been loaded.
  409. </div>
  410. <br>
  411. <br>
  412. <a name="Validator"></a><h1>Validator</h1>
  413. <h2>Constructor</h2>
  414. <h3>Validator()</h3>
  415. <div>
  416. Validation functions.
  417. </div>
  418. <h2>Methods</h2>
  419. <h3>[method:Boolean isValid]( [page:Object input] )</h3>
  420. <div>
  421. [page:Object input] - Can be anything
  422. </div>
  423. <div>
  424. If given input is null or undefined, false is returned otherwise true.
  425. </div>
  426. <h3>[method:null verifyInput]( [page:Object input], [page:Object defaultValue] )</h3>
  427. <div>
  428. [page:Object input] - Can be anything
  429. [page:Object defaultValue] - Can be anything
  430. </div>
  431. <div>
  432. If given input is null or undefined, the defaultValue is returned otherwise the given input.
  433. </div>
  434. <br>
  435. <br>
  436. <a name="ConsoleLogger"></a><h1>ConsoleLogger</h1>
  437. <h2>Constructor</h2>
  438. <h3>ConsoleLogger( [page:Boolean enabled], [page:Boolean debug] )</h3>
  439. <div>
  440. [page:Boolean enabled] - Tell if logger is enabled.
  441. [page:Boolean debug] - Toggle debug logging.
  442. <div>
  443. Logging wrapper for console.
  444. </div>
  445. <h2>Methods</h2>
  446. <h3>[method:null setDebug]( [page:Boolean debug] )</h3>
  447. <div>
  448. [page:Boolean debug] - True or False
  449. </div>
  450. <div>
  451. Enable or disable debug logging.
  452. </div>
  453. <h3>[method:Boolean isDebug]()</h3>
  454. <div>
  455. Returns if is enabled and debug.
  456. </div>
  457. <h3>[method:null setEnabled]( [page:Boolean enabled] )</h3>
  458. <div>
  459. [page:Boolean enabled] - True or False
  460. </div>
  461. <div>
  462. Enable or disable info, debug and time logging.
  463. </div>
  464. <h3>[method:Boolean isEnabled]()</h3>
  465. <div>
  466. Returns if is enabled.
  467. </div>
  468. <h3>[method:null logDebug]( [page:String message] )</h3>
  469. <div>
  470. [page:String message] - Message to log
  471. </div>
  472. <div>
  473. Log a debug message if enabled and debug is set.
  474. </div>
  475. <h3>[method:null logInfo]( [page:String message] )</h3>
  476. <div>
  477. [page:String message] - Message to log
  478. </div>
  479. <div>
  480. Log an info message if enabled.
  481. </div>
  482. <h3>[method:null logWarn]( [page:String message] )</h3>
  483. <div>
  484. [page:String message] - Message to log
  485. </div>
  486. <div>
  487. Log a warn message (always).
  488. </div>
  489. <h3>[method:null logError]( [page:String message] )</h3>
  490. <div>
  491. [page:String message] - Message to log
  492. </div>
  493. <div>
  494. Log an error message (always).
  495. </div>
  496. <h3>[method:null logTimeStart]( [page:String id] )</h3>
  497. <div>
  498. [page:String id] - Time identification
  499. </div>
  500. <div>
  501. Start time measurement with provided id.
  502. </div>
  503. <h3>[method:null logTimeEnd]( [page:String id] )</h3>
  504. <div>
  505. [page:String id] - Time identification
  506. </div>
  507. <div>
  508. Stop time measurement started with provided id.
  509. </div>
  510. <br>
  511. <br>
  512. <h2>Source</h2>
  513. [link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/LoaderSupport.js examples/js/loaders/LoaderSupport.js]
  514. </body>
  515. </html>