2
0

LoaderSupport.html 18 KB

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