@realsee/five 5.0.0-alpha.14 → 5.0.0-alpha.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +21 -11
  2. package/docs/.nojekyll +1 -0
  3. package/docs/assets/highlight.css +134 -0
  4. package/docs/assets/icons.css +1043 -0
  5. package/docs/assets/{images/icons.png → icons.png} +0 -0
  6. package/docs/assets/{images/icons@2x.png → icons@2x.png} +0 -0
  7. package/docs/assets/main.js +52 -0
  8. package/docs/assets/search.js +1 -0
  9. package/docs/assets/style.css +1413 -0
  10. package/docs/assets/{images/widgets.png → widgets.png} +0 -0
  11. package/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
  12. package/docs/classes/five.AnimationFrameLoop.html +15 -0
  13. package/docs/classes/five.BVH.html +10 -0
  14. package/docs/classes/five.BVHIntersect.html +1 -0
  15. package/docs/classes/five.BVHNode.html +7 -0
  16. package/docs/classes/five.BVHVector3.html +1 -0
  17. package/docs/classes/five.Camera.html +11 -0
  18. package/docs/classes/five.Five.html +310 -0
  19. package/docs/classes/five.InternalWebGLRenderer.html +1 -0
  20. package/docs/classes/five.IntersectMesh.html +1 -0
  21. package/docs/classes/five.LegacyPanoCircleMesh.html +5 -0
  22. package/docs/classes/five.Model.html +87 -0
  23. package/docs/classes/five.NetworkSubscribe.html +50 -0
  24. package/docs/classes/five.PBMContainer.html +17 -0
  25. package/docs/classes/five.PBMGroup.html +19 -0
  26. package/docs/classes/five.PBMMaterial.html +19 -0
  27. package/docs/classes/five.PBMMesh.html +7 -0
  28. package/docs/classes/five.PanoCircleMesh.html +7 -0
  29. package/docs/classes/five.Scene.html +3 -0
  30. package/docs/classes/five.Subscribe.html +56 -0
  31. package/docs/classes/five.Tile3D.html +34 -0
  32. package/docs/classes/five.Tile3DModel.html +15 -0
  33. package/docs/classes/five.TileBoundingSphere.html +1 -0
  34. package/docs/classes/five.TileCacheNode.html +1 -0
  35. package/docs/classes/five.TileCullingVolume.html +1 -0
  36. package/docs/classes/five.TileOrientedBoundingBox.html +1 -0
  37. package/docs/classes/five.TilePlane.html +1 -0
  38. package/docs/classes/five.TileRequestScheduler.html +16 -0
  39. package/docs/classes/five.Tileset3D.html +11 -0
  40. package/docs/classes/five.Tileset3DTraverser.html +1 -0
  41. package/docs/classes/five.TilesetCache.html +1 -0
  42. package/docs/classes/five.Work.html +30 -0
  43. package/docs/classes/five.XRButton.html +1 -0
  44. package/docs/classes/gltf_loader.GLTFLoader.html +17 -0
  45. package/docs/classes/gltf_loader.GLTFObject.html +7 -0
  46. package/docs/classes/line.Line.html +1 -0
  47. package/docs/classes/line.LineGeometry.html +1 -0
  48. package/docs/classes/line.LineMaterial.html +1 -0
  49. package/docs/classes/line.LineSegmentsGeometry.html +1 -0
  50. package/docs/classes/line.THREE_Line2.html +1 -0
  51. package/docs/classes/line.THREE_LineSegments2.html +1 -0
  52. package/docs/classes/react.Store.html +29 -0
  53. package/docs/classes/server.BVH.html +10 -0
  54. package/docs/classes/server.BVHIntersect.html +1 -0
  55. package/docs/classes/server.BVHNode.html +7 -0
  56. package/docs/classes/server.BVHVector3.html +1 -0
  57. package/docs/classes/server.Model.html +63 -0
  58. package/docs/classes/server.PBMGroup.html +9 -0
  59. package/docs/classes/server.PBMMesh.html +7 -0
  60. package/docs/classes/sticker.Sticker.html +32 -0
  61. package/docs/index.html +166 -422
  62. package/docs/interfaces/five.AddableObject.html +1 -0
  63. package/docs/interfaces/five.AnimationFrame.html +1 -0
  64. package/docs/interfaces/five.CameraPose.html +1 -0
  65. package/docs/interfaces/five.DepthPanoramaControllerCustomInitArgs.html +28 -0
  66. package/docs/interfaces/five.EventCallback.html +399 -0
  67. package/docs/interfaces/five.FiveInitArgs.html +107 -0
  68. package/docs/interfaces/five.FloorplanControllerCustomInitArgs.html +15 -0
  69. package/docs/interfaces/five.ImageOptions.html +18 -0
  70. package/docs/interfaces/five.ImageURLMappings.html +1 -0
  71. package/docs/interfaces/five.ImageURLOptions.html +17 -0
  72. package/docs/interfaces/five.IntersectMeshInterface.html +3 -0
  73. package/docs/interfaces/five.Intersection.html +7 -0
  74. package/docs/interfaces/five.MapviewControllerCustomInitArgs.html +15 -0
  75. package/docs/interfaces/five.ModelControllerCustomInitArgs.html +20 -0
  76. package/docs/interfaces/five.ModelEventCallback.html +22 -0
  77. package/docs/interfaces/five.MovePanoOptions.html +42 -0
  78. package/docs/interfaces/five.PBMPanoPicture.html +7 -0
  79. package/docs/interfaces/five.PBMParameters.html +19 -0
  80. package/docs/interfaces/five.PanoCircleMeshInterface.html +19 -0
  81. package/docs/interfaces/five.PanoramaControllerCustomInitArgs.html +33 -0
  82. package/docs/interfaces/five.PanoramaLikeControllerCustomInitArgs.html +20 -0
  83. package/docs/interfaces/five.Pose.html +37 -0
  84. package/docs/interfaces/five.Scissor.html +14 -0
  85. package/docs/interfaces/five.State.html +21 -0
  86. package/docs/interfaces/five.SubscribeMixinType.emit.html +1 -0
  87. package/docs/interfaces/five.SubscribeMixinType.hasListener.html +1 -0
  88. package/docs/interfaces/five.SubscribeMixinType.off.html +1 -0
  89. package/docs/interfaces/five.SubscribeMixinType.on.html +1 -0
  90. package/docs/interfaces/five.SubscribeMixinType.once.html +1 -0
  91. package/docs/interfaces/five.TextureOptions.html +20 -0
  92. package/docs/interfaces/five.Tile3DModelLoaderOptions.html +3 -0
  93. package/docs/interfaces/five.TileBoundingVolume.html +19 -0
  94. package/docs/interfaces/five.TileContent.html +1 -0
  95. package/docs/interfaces/five.Tileset3dOptions.html +1 -0
  96. package/docs/interfaces/five.TilesetJSON.html +1 -0
  97. package/docs/interfaces/five.TilesetJSONNode.html +1 -0
  98. package/docs/interfaces/five.TopviewControllerCustomInitArgs.html +7 -0
  99. package/docs/interfaces/five.VRPanoramaControllerCustomInitArgs.html +29 -0
  100. package/docs/interfaces/five.WorkCubeImage.html +13 -0
  101. package/docs/interfaces/five.WorkImage.html +21 -0
  102. package/docs/interfaces/five.WorkInitial.html +13 -0
  103. package/docs/interfaces/five.WorkModel.html +11 -0
  104. package/docs/interfaces/five.WorkModelTiles.html +3 -0
  105. package/docs/interfaces/five.WorkObserver.html +25 -0
  106. package/docs/interfaces/five.WorkTile.html +1 -0
  107. package/docs/interfaces/five.WorkVideo.html +9 -0
  108. package/docs/interfaces/five.XRPanoramaControllerCustomInitArgs.html +29 -0
  109. package/docs/interfaces/gltf_loader.GLTF.html +7 -0
  110. package/docs/interfaces/react.FiveActionReactCallbacks.html +62 -0
  111. package/docs/interfaces/react.FiveInjectionTypes.html +191 -0
  112. package/docs/interfaces/react.PropTypeOfFiveFeatures.html +1 -0
  113. package/docs/interfaces/server.Intersection.html +7 -0
  114. package/docs/interfaces/server.ModelEventCallback.html +18 -0
  115. package/docs/interfaces/sticker.IntersectionLike.html +8 -0
  116. package/docs/interfaces/vue.FiveActionVueCallbacks.html +62 -0
  117. package/docs/modules/five.SubscribeMixinType.html +1 -0
  118. package/docs/modules/five.html +496 -0
  119. package/docs/modules/gltf_loader.html +1 -0
  120. package/docs/modules/line.html +1 -0
  121. package/docs/modules/react.html +130 -1374
  122. package/docs/modules/server.html +18 -0
  123. package/docs/modules/sticker.html +1 -0
  124. package/docs/modules/vue.html +112 -0
  125. package/docs/modules.html +1 -120
  126. package/exporters/staticify.js +210 -0
  127. package/{index.d.ts → five/index.d.ts} +1211 -331
  128. package/five/index.js +372 -0
  129. package/gltf-loader/index.d.ts +76 -0
  130. package/gltf-loader/index.js +260 -0
  131. package/line/index.d.ts +69 -0
  132. package/line/index.js +260 -0
  133. package/package.json +25 -17
  134. package/react/index.d.ts +86 -24
  135. package/react/index.js +260 -1
  136. package/resource/{basis_transcoder.js → basis/basis_transcoder.js} +0 -0
  137. package/resource/{basis_transcoder.wasm → basis/basis_transcoder.wasm} +0 -0
  138. package/resource/gltf/draco_decoder.js +31 -0
  139. package/resource/gltf/draco_decoder.wasm +0 -0
  140. package/resource/gltf/draco_wasm_wrapper.js +119 -0
  141. package/scripts/five-staticify.js +26 -0
  142. package/server/index.d.ts +197 -26
  143. package/server/index.js +367 -1
  144. package/sticker/index.d.ts +71 -0
  145. package/sticker/index.js +260 -0
  146. package/templates/quick-start/README.md +1 -1
  147. package/templates/quick-start/package.json +1 -1
  148. package/templates/react-component/lib/index.tsx +3 -3
  149. package/umd/five-gltf-loader.js +2 -0
  150. package/umd/five-gltf-loader.js.LICENSE.txt +14 -0
  151. package/umd/five-line.js +2 -0
  152. package/umd/five-line.js.LICENSE.txt +14 -0
  153. package/umd/five-react.js +2 -0
  154. package/umd/five-react.js.LICENSE.txt +14 -0
  155. package/umd/five-sticker.js +2 -0
  156. package/umd/five-sticker.js.LICENSE.txt +14 -0
  157. package/umd/five-vue.js +1 -0
  158. package/umd/five.js +2 -0
  159. package/umd/five.js.LICENSE.txt +116 -0
  160. package/vue/index.d.ts +433 -0
  161. package/vue/index.js +260 -0
  162. package/bundles/five.js +0 -2
  163. package/bundles/five.js.LICENSE.txt +0 -160
  164. package/docs/assets/css/main.css +0 -2660
  165. package/docs/assets/js/main.js +0 -248
  166. package/docs/assets/js/search.js +0 -1
  167. package/docs/classes/index.five.html +0 -2498
  168. package/docs/classes/index.fivecamera.html +0 -311
  169. package/docs/classes/index.fivehashcubetexture.html +0 -240
  170. package/docs/classes/index.fiveline.html +0 -342
  171. package/docs/classes/index.fivelinegeometry.html +0 -500
  172. package/docs/classes/index.fivelinematerial.html +0 -276
  173. package/docs/classes/index.fivelinesegmentsgeometry.html +0 -447
  174. package/docs/classes/index.fivescene.html +0 -186
  175. package/docs/classes/index.internalwebglrenderer.html +0 -200
  176. package/docs/classes/index.model.html +0 -883
  177. package/docs/classes/index.pbmgroup.html +0 -415
  178. package/docs/classes/index.pbmmaterial.html +0 -521
  179. package/docs/classes/index.pbmmesh.html +0 -242
  180. package/docs/classes/index.subscribe.html +0 -556
  181. package/docs/classes/react.store.html +0 -584
  182. package/docs/interfaces/index.depthpanoramacontrollercustominitargs.html +0 -408
  183. package/docs/interfaces/index.eventcallback.html +0 -2452
  184. package/docs/interfaces/index.fiveinitargs.html +0 -695
  185. package/docs/interfaces/index.floorplancontrollercustominitargs.html +0 -283
  186. package/docs/interfaces/index.imageoptions.html +0 -320
  187. package/docs/interfaces/index.intersection.html +0 -215
  188. package/docs/interfaces/index.intersectmeshinterface.html +0 -176
  189. package/docs/interfaces/index.modelcontrollercustominitargs.html +0 -354
  190. package/docs/interfaces/index.modeleventcallback.html +0 -316
  191. package/docs/interfaces/index.movepanooptions.html +0 -457
  192. package/docs/interfaces/index.panocirclemeshinterface.html +0 -349
  193. package/docs/interfaces/index.panoramacontrollercustominitargs.html +0 -433
  194. package/docs/interfaces/index.panoramalikecontrollercustominitargs.html +0 -352
  195. package/docs/interfaces/index.pbmparameters.html +0 -462
  196. package/docs/interfaces/index.pose.html +0 -258
  197. package/docs/interfaces/index.scissor.html +0 -240
  198. package/docs/interfaces/index.state.html +0 -288
  199. package/docs/interfaces/index.subscribemixintype.emit.html +0 -180
  200. package/docs/interfaces/index.subscribemixintype.haslistener.html +0 -171
  201. package/docs/interfaces/index.subscribemixintype.off.html +0 -198
  202. package/docs/interfaces/index.subscribemixintype.on.html +0 -213
  203. package/docs/interfaces/index.subscribemixintype.once.html +0 -210
  204. package/docs/interfaces/index.topviewcontrollercustominitargs.html +0 -214
  205. package/docs/interfaces/index.vrpanoramacontrollercustominitargs.html +0 -420
  206. package/docs/interfaces/react.fiveactionreactcallbacks.html +0 -559
  207. package/docs/interfaces/react.fiveinjectiontypes.html +0 -1473
  208. package/docs/interfaces/react.injectfivetoprops.html +0 -259
  209. package/docs/modules/index.html +0 -3027
  210. package/docs/modules/index.subscribemixintype.html +0 -143
  211. package/five.js.LICENSE.txt +0 -160
  212. package/index.js +0 -1
  213. package/scripts/export-five-resource/chfs.exe +0 -0
  214. package/scripts/export-five-resource/fileify.js +0 -192
  215. package/scripts/export-five-resource/format-work.js +0 -71
  216. package/scripts/export-five-resource/staticify.js +0 -327
  217. package/scripts/transcode-model/BufferGeometryUtils.js +0 -832
  218. package/scripts/transcode-model/LoaderSupport.js +0 -1545
  219. package/scripts/transcode-model/MTLLoader.js +0 -602
  220. package/scripts/transcode-model/OBJLoader2.js +0 -1470
  221. package/scripts/transcode-model/obj2pbm.js +0 -65
@@ -1,1545 +0,0 @@
1
- /**
2
- * @author Kai Salmen / https://kaisalmen.de
3
- * Development repository: https://github.com/kaisalmen/WWOBJLoader
4
- */
5
-
6
- var THREE = require('three')
7
-
8
- if ( THREE.LoaderSupport === undefined ) {
9
-
10
- THREE.LoaderSupport = {};
11
-
12
- }
13
-
14
- /**
15
- * Validation functions.
16
- * @class
17
- */
18
- THREE.LoaderSupport.Validator = {
19
- /**
20
- * If given input is null or undefined, false is returned otherwise true.
21
- *
22
- * @param input Can be anything
23
- * @returns {boolean}
24
- */
25
- isValid: function( input ) {
26
- return ( input !== null && input !== undefined );
27
- },
28
- /**
29
- * If given input is null or undefined, the defaultValue is returned otherwise the given input.
30
- *
31
- * @param input Can be anything
32
- * @param defaultValue Can be anything
33
- * @returns {*}
34
- */
35
- verifyInput: function( input, defaultValue ) {
36
- return ( input === null || input === undefined ) ? defaultValue : input;
37
- }
38
- };
39
-
40
-
41
- /**
42
- * Callbacks utilized by loaders and builders.
43
- * @class
44
- */
45
- THREE.LoaderSupport.Callbacks = (function () {
46
-
47
- var Validator = THREE.LoaderSupport.Validator;
48
-
49
- function Callbacks() {
50
- this.onProgress = null;
51
- this.onReportError = null;
52
- this.onMeshAlter = null;
53
- this.onLoad = null;
54
- this.onLoadMaterials = null;
55
- }
56
-
57
- /**
58
- * Register callback function that is invoked by internal function "announceProgress" to print feedback.
59
- * @memberOf THREE.LoaderSupport.Callbacks
60
- *
61
- * @param {callback} callbackOnProgress Callback function for described functionality
62
- */
63
- Callbacks.prototype.setCallbackOnProgress = function ( callbackOnProgress ) {
64
- this.onProgress = Validator.verifyInput( callbackOnProgress, this.onProgress );
65
- };
66
-
67
- /**
68
- * Register callback function that is invoked when an error is reported.
69
- * @memberOf THREE.LoaderSupport.Callbacks
70
- *
71
- * @param {callback} callbackOnReportError Callback function for described functionality
72
- */
73
- Callbacks.prototype.setCallbackOnReportError = function ( callbackOnReportError ) {
74
- this.onReportError = Validator.verifyInput( callbackOnReportError, this.onReportError );
75
- };
76
-
77
- /**
78
- * Register callback function that is called every time a mesh was loaded.
79
- * Use {@link THREE.LoaderSupport.LoadedMeshUserOverride} for alteration instructions (geometry, material or disregard mesh).
80
- * @memberOf THREE.LoaderSupport.Callbacks
81
- *
82
- * @param {callback} callbackOnMeshAlter Callback function for described functionality
83
- */
84
- Callbacks.prototype.setCallbackOnMeshAlter = function ( callbackOnMeshAlter ) {
85
- this.onMeshAlter = Validator.verifyInput( callbackOnMeshAlter, this.onMeshAlter );
86
- };
87
-
88
- /**
89
- * Register callback function that is called once loading of the complete OBJ file is completed.
90
- * @memberOf THREE.LoaderSupport.Callbacks
91
- *
92
- * @param {callback} callbackOnLoad Callback function for described functionality
93
- */
94
- Callbacks.prototype.setCallbackOnLoad = function ( callbackOnLoad ) {
95
- this.onLoad = Validator.verifyInput( callbackOnLoad, this.onLoad );
96
- };
97
-
98
- /**
99
- * Register callback function that is called when materials have been loaded.
100
- * @memberOf THREE.LoaderSupport.Callbacks
101
- *
102
- * @param {callback} callbackOnLoadMaterials Callback function for described functionality
103
- */
104
- Callbacks.prototype.setCallbackOnLoadMaterials = function ( callbackOnLoadMaterials ) {
105
- this.onLoadMaterials = Validator.verifyInput( callbackOnLoadMaterials, this.onLoadMaterials );
106
- };
107
-
108
- return Callbacks;
109
- })();
110
-
111
-
112
- /**
113
- * Object to return by callback onMeshAlter. Used to disregard a certain mesh or to return one to many meshes.
114
- * @class
115
- *
116
- * @param {boolean} disregardMesh=false Tell implementation to completely disregard this mesh
117
- * @param {boolean} disregardMesh=false Tell implementation that mesh(es) have been altered or added
118
- */
119
- THREE.LoaderSupport.LoadedMeshUserOverride = (function () {
120
-
121
- function LoadedMeshUserOverride( disregardMesh, alteredMesh ) {
122
- this.disregardMesh = disregardMesh === true;
123
- this.alteredMesh = alteredMesh === true;
124
- this.meshes = [];
125
- }
126
-
127
- /**
128
- * Add a mesh created within callback.
129
- *
130
- * @memberOf THREE.OBJLoader2.LoadedMeshUserOverride
131
- *
132
- * @param {THREE.Mesh} mesh
133
- */
134
- LoadedMeshUserOverride.prototype.addMesh = function ( mesh ) {
135
- this.meshes.push( mesh );
136
- this.alteredMesh = true;
137
- };
138
-
139
- /**
140
- * Answers if mesh shall be disregarded completely.
141
- *
142
- * @returns {boolean}
143
- */
144
- LoadedMeshUserOverride.prototype.isDisregardMesh = function () {
145
- return this.disregardMesh;
146
- };
147
-
148
- /**
149
- * Answers if new mesh(es) were created.
150
- *
151
- * @returns {boolean}
152
- */
153
- LoadedMeshUserOverride.prototype.providesAlteredMeshes = function () {
154
- return this.alteredMesh;
155
- };
156
-
157
- return LoadedMeshUserOverride;
158
- })();
159
-
160
-
161
- /**
162
- * A resource description used by {@link THREE.LoaderSupport.PrepData} and others.
163
- * @class
164
- *
165
- * @param {string} url URL to the file
166
- * @param {string} extension The file extension (type)
167
- */
168
- THREE.LoaderSupport.ResourceDescriptor = (function () {
169
-
170
- var Validator = THREE.LoaderSupport.Validator;
171
-
172
- function ResourceDescriptor( url, extension ) {
173
- var urlParts = url.split( '/' );
174
-
175
- if ( urlParts.length < 2 ) {
176
-
177
- this.path = null;
178
- this.name = url;
179
- this.url = url;
180
-
181
- } else {
182
-
183
- this.path = Validator.verifyInput( urlParts.slice( 0, urlParts.length - 1).join( '/' ) + '/', null );
184
- this.name = urlParts[ urlParts.length - 1 ];
185
- this.url = url;
186
-
187
- }
188
- this.name = Validator.verifyInput( this.name, 'Unnamed_Resource' );
189
- this.extension = Validator.verifyInput( extension, 'default' );
190
- this.extension = this.extension.trim();
191
- this.content = null;
192
- }
193
-
194
- /**
195
- * Set the content of this resource
196
- * @memberOf THREE.LoaderSupport.ResourceDescriptor
197
- *
198
- * @param {Object} content The file content as arraybuffer or text
199
- */
200
- ResourceDescriptor.prototype.setContent = function ( content ) {
201
- this.content = Validator.verifyInput( content, null );
202
- };
203
-
204
- return ResourceDescriptor;
205
- })();
206
-
207
-
208
- /**
209
- * Configuration instructions to be used by run method.
210
- * @class
211
- */
212
- THREE.LoaderSupport.PrepData = (function () {
213
-
214
- var Validator = THREE.LoaderSupport.Validator;
215
-
216
- function PrepData( modelName ) {
217
- this.logging = {
218
- enabled: true,
219
- debug: false
220
- };
221
- this.modelName = Validator.verifyInput( modelName, '' );
222
- this.resources = [];
223
- this.callbacks = new THREE.LoaderSupport.Callbacks();
224
- }
225
-
226
- /**
227
- * Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
228
- * @memberOf THREE.LoaderSupport.PrepData
229
- *
230
- * @param {boolean} enabled True or false.
231
- * @param {boolean} debug True or false.
232
- */
233
- PrepData.prototype.setLogging = function ( enabled, debug ) {
234
- this.logging.enabled = enabled === true;
235
- this.logging.debug = debug === true;
236
- };
237
-
238
- /**
239
- * Returns all callbacks as {@link THREE.LoaderSupport.Callbacks}
240
- * @memberOf THREE.LoaderSupport.PrepData
241
- *
242
- * @returns {THREE.LoaderSupport.Callbacks}
243
- */
244
- PrepData.prototype.getCallbacks = function () {
245
- return this.callbacks;
246
- };
247
-
248
- /**
249
- * Add a resource description.
250
- * @memberOf THREE.LoaderSupport.PrepData
251
- *
252
- * @param {THREE.LoaderSupport.ResourceDescriptor} Adds a {@link THREE.LoaderSupport.ResourceDescriptor}
253
- */
254
- PrepData.prototype.addResource = function ( resource ) {
255
- this.resources.push( resource );
256
- };
257
-
258
- /**
259
- * Clones this object and returns it afterwards. Callbacks and resources are not cloned deep (references!).
260
- * @memberOf THREE.LoaderSupport.PrepData
261
- *
262
- * @returns {@link THREE.LoaderSupport.PrepData}
263
- */
264
- PrepData.prototype.clone = function () {
265
- var clone = new THREE.LoaderSupport.PrepData( this.modelName );
266
- clone.logging.enabled = this.logging.enabled;
267
- clone.logging.debug = this.logging.debug;
268
- clone.resources = this.resources;
269
- clone.callbacks = this.callbacks;
270
-
271
- var property, value;
272
- for ( property in this ) {
273
-
274
- value = this[ property ];
275
- if ( ! clone.hasOwnProperty( property ) && typeof this[ property ] !== 'function' ) {
276
-
277
- clone[ property ] = value;
278
-
279
- }
280
- }
281
-
282
- return clone;
283
- };
284
-
285
-
286
- /**
287
- * Identify files or content of interest from an Array of {@link THREE.LoaderSupport.ResourceDescriptor}.
288
- * @memberOf THREE.LoaderSupport.PrepData
289
- *
290
- * @param {THREE.LoaderSupport.ResourceDescriptor[]} resources Array of {@link THREE.LoaderSupport.ResourceDescriptor}
291
- * @param Object fileDesc Object describing which resources are of interest (ext, type (string or UInt8Array) and ignore (boolean))
292
- * @returns {{}} Object with each "ext" and the corresponding {@link THREE.LoaderSupport.ResourceDescriptor}
293
- */
294
- PrepData.prototype.checkResourceDescriptorFiles = function ( resources, fileDesc ) {
295
- var resource, triple, i, found;
296
- var result = {};
297
-
298
- for ( var index in resources ) {
299
-
300
- resource = resources[ index ];
301
- found = false;
302
- if ( ! Validator.isValid( resource.name ) ) continue;
303
- if ( Validator.isValid( resource.content ) ) {
304
-
305
- for ( i = 0; i < fileDesc.length && !found; i++ ) {
306
-
307
- triple = fileDesc[ i ];
308
- if ( resource.extension.toLowerCase() === triple.ext.toLowerCase() ) {
309
-
310
- if ( triple.ignore ) {
311
-
312
- found = true;
313
-
314
- } else if ( triple.type === "ArrayBuffer" ) {
315
-
316
- // fast-fail on bad type
317
- if ( ! ( resource.content instanceof ArrayBuffer || resource.content instanceof Uint8Array ) ) throw 'Provided content is not of type ArrayBuffer! Aborting...';
318
- result[ triple.ext ] = resource;
319
- found = true;
320
-
321
- } else if ( triple.type === "String" ) {
322
-
323
- if ( ! ( typeof( resource.content ) === 'string' || resource.content instanceof String) ) throw 'Provided content is not of type String! Aborting...';
324
- result[ triple.ext ] = resource;
325
- found = true;
326
-
327
- }
328
-
329
- }
330
-
331
- }
332
- if ( !found ) throw 'Unidentified resource "' + resource.name + '": ' + resource.url;
333
-
334
- } else {
335
-
336
- // fast-fail on bad type
337
- if ( ! ( typeof( resource.name ) === 'string' || resource.name instanceof String ) ) throw 'Provided file is not properly defined! Aborting...';
338
- for ( i = 0; i < fileDesc.length && !found; i++ ) {
339
-
340
- triple = fileDesc[ i ];
341
- if ( resource.extension.toLowerCase() === triple.ext.toLowerCase() ) {
342
-
343
- if ( ! triple.ignore ) result[ triple.ext ] = resource;
344
- found = true;
345
-
346
- }
347
-
348
- }
349
- if ( !found ) throw 'Unidentified resource "' + resource.name + '": ' + resource.url;
350
-
351
- }
352
- }
353
-
354
- return result;
355
- };
356
-
357
- return PrepData;
358
- })();
359
-
360
- /**
361
- * Builds one or many THREE.Mesh from one raw set of Arraybuffers, materialGroup descriptions and further parameters.
362
- * Supports vertex, vertexColor, normal, uv and index buffers.
363
- * @class
364
- */
365
- THREE.LoaderSupport.MeshBuilder = (function () {
366
-
367
- var LOADER_MESH_BUILDER_VERSION = '1.2.2';
368
-
369
- var Validator = THREE.LoaderSupport.Validator;
370
-
371
- function MeshBuilder() {
372
- // console.info( 'Using THREE.LoaderSupport.MeshBuilder version: ' + LOADER_MESH_BUILDER_VERSION );
373
- this.logging = {
374
- enabled: true,
375
- debug: false
376
- };
377
-
378
- this.callbacks = new THREE.LoaderSupport.Callbacks();
379
- this.materials = [];
380
- }
381
-
382
- /**
383
- * Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
384
- * @memberOf THREE.LoaderSupport.MeshBuilder
385
- *
386
- * @param {boolean} enabled True or false.
387
- * @param {boolean} debug True or false.
388
- */
389
- MeshBuilder.prototype.setLogging = function ( enabled, debug ) {
390
- this.logging.enabled = enabled === true;
391
- this.logging.debug = debug === true;
392
- };
393
-
394
- /**
395
- * Initializes the MeshBuilder (currently only default material initialisation).
396
- * @memberOf THREE.LoaderSupport.MeshBuilder
397
- *
398
- */
399
- MeshBuilder.prototype.init = function () {
400
- var defaultMaterial = new THREE.MeshStandardMaterial( { color: 0xDCF1FF } );
401
- defaultMaterial.name = 'defaultMaterial';
402
-
403
- var defaultVertexColorMaterial = new THREE.MeshStandardMaterial( { color: 0xDCF1FF } );
404
- defaultVertexColorMaterial.name = 'defaultVertexColorMaterial';
405
- defaultVertexColorMaterial.vertexColors = THREE.VertexColors;
406
-
407
- var defaultLineMaterial = new THREE.LineBasicMaterial();
408
- defaultLineMaterial.name = 'defaultLineMaterial';
409
-
410
- var defaultPointMaterial = new THREE.PointsMaterial( { size: 1 } );
411
- defaultPointMaterial.name = 'defaultPointMaterial';
412
-
413
- var runtimeMaterials = {};
414
- runtimeMaterials[ defaultMaterial.name ] = defaultMaterial;
415
- runtimeMaterials[ defaultVertexColorMaterial.name ] = defaultVertexColorMaterial;
416
- runtimeMaterials[ defaultLineMaterial.name ] = defaultLineMaterial;
417
- runtimeMaterials[ defaultPointMaterial.name ] = defaultPointMaterial;
418
-
419
- this.updateMaterials(
420
- {
421
- cmd: 'materialData',
422
- materials: {
423
- materialCloneInstructions: null,
424
- serializedMaterials: null,
425
- runtimeMaterials: runtimeMaterials
426
- }
427
- }
428
- );
429
- };
430
-
431
- /**
432
- * Set materials loaded by any supplier of an Array of {@link THREE.Material}.
433
- * @memberOf THREE.LoaderSupport.MeshBuilder
434
- *
435
- * @param {THREE.Material[]} materials Array of {@link THREE.Material}
436
- */
437
- MeshBuilder.prototype.setMaterials = function ( materials ) {
438
- var payload = {
439
- cmd: 'materialData',
440
- materials: {
441
- materialCloneInstructions: null,
442
- serializedMaterials: null,
443
- runtimeMaterials: Validator.isValid( this.callbacks.onLoadMaterials ) ? this.callbacks.onLoadMaterials( materials ) : materials
444
- }
445
- };
446
- this.updateMaterials( payload );
447
- };
448
-
449
- MeshBuilder.prototype._setCallbacks = function ( callbacks ) {
450
- if ( Validator.isValid( callbacks.onProgress ) ) this.callbacks.setCallbackOnProgress( callbacks.onProgress );
451
- if ( Validator.isValid( callbacks.onReportError ) ) this.callbacks.setCallbackOnReportError( callbacks.onReportError );
452
- if ( Validator.isValid( callbacks.onMeshAlter ) ) this.callbacks.setCallbackOnMeshAlter( callbacks.onMeshAlter );
453
- if ( Validator.isValid( callbacks.onLoad ) ) this.callbacks.setCallbackOnLoad( callbacks.onLoad );
454
- if ( Validator.isValid( callbacks.onLoadMaterials ) ) this.callbacks.setCallbackOnLoadMaterials( callbacks.onLoadMaterials );
455
- };
456
-
457
- /**
458
- * Delegates processing of the payload (mesh building or material update) to the corresponding functions (BW-compatibility).
459
- * @memberOf THREE.LoaderSupport.MeshBuilder
460
- *
461
- * @param {Object} payload Raw Mesh or Material descriptions.
462
- * @returns {THREE.Mesh[]} mesh Array of {@link THREE.Mesh} or null in case of material update
463
- */
464
- MeshBuilder.prototype.processPayload = function ( payload ) {
465
- if ( payload.cmd === 'meshData' ) {
466
-
467
- return this.buildMeshes( payload );
468
-
469
- } else if ( payload.cmd === 'materialData' ) {
470
-
471
- this.updateMaterials( payload );
472
- return null;
473
-
474
- }
475
- };
476
-
477
- /**
478
- * Builds one or multiple meshes from the data described in the payload (buffers, params, material info).
479
- * @memberOf THREE.LoaderSupport.MeshBuilder
480
- *
481
- * @param {Object} meshPayload Raw mesh description (buffers, params, materials) used to build one to many meshes.
482
- * @returns {THREE.Mesh[]} mesh Array of {@link THREE.Mesh}
483
- */
484
- MeshBuilder.prototype.buildMeshes = function ( meshPayload ) {
485
- var meshName = meshPayload.params.meshName;
486
-
487
- var bufferGeometry = new THREE.BufferGeometry();
488
- bufferGeometry.setAttribute( 'position', new THREE.BufferAttribute( new Float32Array( meshPayload.buffers.vertices ), 3 ) );
489
- if ( Validator.isValid( meshPayload.buffers.indices ) ) {
490
-
491
- bufferGeometry.setIndex( new THREE.BufferAttribute( new Uint32Array( meshPayload.buffers.indices ), 1 ));
492
-
493
- }
494
- var haveVertexColors = Validator.isValid( meshPayload.buffers.colors );
495
- if ( haveVertexColors ) {
496
-
497
- bufferGeometry.setAttribute( 'color', new THREE.BufferAttribute( new Float32Array( meshPayload.buffers.colors ), 3 ) );
498
-
499
- }
500
- if ( Validator.isValid( meshPayload.buffers.normals ) ) {
501
-
502
- bufferGeometry.setAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( meshPayload.buffers.normals ), 3 ) );
503
-
504
- } else {
505
-
506
- bufferGeometry.computeVertexNormals();
507
-
508
- }
509
- if ( Validator.isValid( meshPayload.buffers.uvs ) ) {
510
-
511
- bufferGeometry.setAttribute( 'uv', new THREE.BufferAttribute( new Float32Array( meshPayload.buffers.uvs ), 2 ) );
512
-
513
- }
514
-
515
- var material, materialName, key;
516
- var materialNames = meshPayload.materials.materialNames;
517
- var createMultiMaterial = meshPayload.materials.multiMaterial;
518
- var multiMaterials = [];
519
- for ( key in materialNames ) {
520
-
521
- materialName = materialNames[ key ];
522
- material = this.materials[ materialName ];
523
- if ( createMultiMaterial ) multiMaterials.push( material );
524
-
525
- }
526
- if ( createMultiMaterial ) {
527
-
528
- material = multiMaterials;
529
- var materialGroups = meshPayload.materials.materialGroups;
530
- var materialGroup;
531
- for ( key in materialGroups ) {
532
-
533
- materialGroup = materialGroups[ key ];
534
- bufferGeometry.addGroup( materialGroup.start, materialGroup.count, materialGroup.index );
535
-
536
- }
537
-
538
- }
539
-
540
- var meshes = [];
541
- var mesh;
542
- var callbackOnMeshAlter = this.callbacks.onMeshAlter;
543
- var callbackOnMeshAlterResult;
544
- var useOrgMesh = true;
545
- var geometryType = Validator.verifyInput( meshPayload.geometryType, 0 );
546
- if ( Validator.isValid( callbackOnMeshAlter ) ) {
547
-
548
- callbackOnMeshAlterResult = callbackOnMeshAlter(
549
- {
550
- detail: {
551
- meshName: meshName,
552
- bufferGeometry: bufferGeometry,
553
- material: material,
554
- geometryType: geometryType
555
- }
556
- }
557
- );
558
- if ( Validator.isValid( callbackOnMeshAlterResult ) ) {
559
-
560
- if ( callbackOnMeshAlterResult.isDisregardMesh() ) {
561
-
562
- useOrgMesh = false;
563
-
564
- } else if ( callbackOnMeshAlterResult.providesAlteredMeshes() ) {
565
-
566
- for ( var i in callbackOnMeshAlterResult.meshes ) {
567
-
568
- meshes.push( callbackOnMeshAlterResult.meshes[ i ] );
569
-
570
- }
571
- useOrgMesh = false;
572
-
573
- }
574
-
575
- }
576
-
577
- }
578
- if ( useOrgMesh ) {
579
-
580
- if ( meshPayload.computeBoundingSphere ) bufferGeometry.computeBoundingSphere();
581
- if ( geometryType === 0 ) {
582
-
583
- mesh = new THREE.Mesh( bufferGeometry, material );
584
-
585
- } else if ( geometryType === 1) {
586
-
587
- mesh = new THREE.LineSegments( bufferGeometry, material );
588
-
589
- } else {
590
-
591
- mesh = new THREE.Points( bufferGeometry, material );
592
-
593
- }
594
- mesh.name = meshName;
595
- meshes.push( mesh );
596
-
597
- }
598
-
599
- var progressMessage;
600
- if ( Validator.isValid( meshes ) && meshes.length > 0 ) {
601
-
602
- var meshNames = [];
603
- for ( var i in meshes ) {
604
-
605
- mesh = meshes[ i ];
606
- meshNames[ i ] = mesh.name;
607
-
608
- }
609
- progressMessage = 'Adding mesh(es) (' + meshNames.length + ': ' + meshNames + ') from input mesh: ' + meshName;
610
- progressMessage += ' (' + ( meshPayload.progress.numericalValue * 100 ).toFixed( 2 ) + '%)';
611
-
612
- } else {
613
-
614
- progressMessage = 'Not adding mesh: ' + meshName;
615
- progressMessage += ' (' + ( meshPayload.progress.numericalValue * 100 ).toFixed( 2 ) + '%)';
616
-
617
- }
618
- var callbackOnProgress = this.callbacks.onProgress;
619
- if ( Validator.isValid( callbackOnProgress ) ) {
620
-
621
- var event = new CustomEvent( 'MeshBuilderEvent', {
622
- detail: {
623
- type: 'progress',
624
- modelName: meshPayload.params.meshName,
625
- text: progressMessage,
626
- numericalValue: meshPayload.progress.numericalValue
627
- }
628
- } );
629
- callbackOnProgress( event );
630
-
631
- }
632
-
633
- return meshes;
634
- };
635
-
636
- /**
637
- * Updates the materials with contained material objects (sync) or from alteration instructions (async).
638
- * @memberOf THREE.LoaderSupport.MeshBuilder
639
- *
640
- * @param {Object} materialPayload Material update instructions
641
- */
642
- MeshBuilder.prototype.updateMaterials = function ( materialPayload ) {
643
- var material, materialName;
644
- var materialCloneInstructions = materialPayload.materials.materialCloneInstructions;
645
- if ( Validator.isValid( materialCloneInstructions ) ) {
646
-
647
- var materialNameOrg = materialCloneInstructions.materialNameOrg;
648
- var materialOrg = this.materials[ materialNameOrg ];
649
-
650
- if ( Validator.isValid( materialNameOrg ) ) {
651
-
652
- material = materialOrg.clone();
653
-
654
- materialName = materialCloneInstructions.materialName;
655
- material.name = materialName;
656
-
657
- var materialProperties = materialCloneInstructions.materialProperties;
658
- for ( var key in materialProperties ) {
659
-
660
- if ( material.hasOwnProperty( key ) && materialProperties.hasOwnProperty( key ) ) material[ key ] = materialProperties[ key ];
661
-
662
- }
663
- this.materials[ materialName ] = material;
664
-
665
- } else {
666
-
667
- console.warn( 'Requested material "' + materialNameOrg + '" is not available!' );
668
-
669
- }
670
- }
671
-
672
- var materials = materialPayload.materials.serializedMaterials;
673
- if ( Validator.isValid( materials ) && Object.keys( materials ).length > 0 ) {
674
-
675
- var loader = new THREE.MaterialLoader();
676
- var materialJson;
677
- for ( materialName in materials ) {
678
-
679
- materialJson = materials[ materialName ];
680
- if ( Validator.isValid( materialJson ) ) {
681
-
682
- material = loader.parse( materialJson );
683
- if ( this.logging.enabled ) console.info( 'De-serialized material with name "' + materialName + '" will be added.' );
684
- this.materials[ materialName ] = material;
685
- }
686
-
687
- }
688
-
689
- }
690
-
691
- materials = materialPayload.materials.runtimeMaterials;
692
- if ( Validator.isValid( materials ) && Object.keys( materials ).length > 0 ) {
693
-
694
- for ( materialName in materials ) {
695
-
696
- material = materials[ materialName ];
697
- if ( this.logging.enabled ) console.info( 'Material with name "' + materialName + '" will be added.' );
698
- this.materials[ materialName ] = material;
699
-
700
- }
701
-
702
- }
703
- };
704
-
705
- /**
706
- * Returns the mapping object of material name and corresponding jsonified material.
707
- *
708
- * @returns {Object} Map of Materials in JSON representation
709
- */
710
- MeshBuilder.prototype.getMaterialsJSON = function () {
711
- var materialsJSON = {};
712
- var material;
713
- for ( var materialName in this.materials ) {
714
-
715
- material = this.materials[ materialName ];
716
- materialsJSON[ materialName ] = material.toJSON();
717
- }
718
-
719
- return materialsJSON;
720
- };
721
-
722
- /**
723
- * Returns the mapping object of material name and corresponding material.
724
- *
725
- * @returns {Object} Map of {@link THREE.Material}
726
- */
727
- MeshBuilder.prototype.getMaterials = function () {
728
- return this.materials;
729
- };
730
-
731
- return MeshBuilder;
732
- })();
733
-
734
- /**
735
- * Default implementation of the WorkerRunner responsible for creation and configuration of the parser within the worker.
736
- *
737
- * @class
738
- */
739
- THREE.LoaderSupport.WorkerRunnerRefImpl = (function () {
740
-
741
- function WorkerRunnerRefImpl() {
742
- var scope = this;
743
- var scopedRunner = function( event ) {
744
- scope.processMessage( event.data );
745
- };
746
- self.addEventListener( 'message', scopedRunner, false );
747
- }
748
-
749
- /**
750
- * Applies values from parameter object via set functions or via direct assignment.
751
- * @memberOf THREE.LoaderSupport.WorkerRunnerRefImpl
752
- *
753
- * @param {Object} parser The parser instance
754
- * @param {Object} params The parameter object
755
- */
756
- WorkerRunnerRefImpl.prototype.applyProperties = function ( parser, params ) {
757
- var property, funcName, values;
758
- for ( property in params ) {
759
- funcName = 'set' + property.substring( 0, 1 ).toLocaleUpperCase() + property.substring( 1 );
760
- values = params[ property ];
761
-
762
- if ( typeof parser[ funcName ] === 'function' ) {
763
-
764
- parser[ funcName ]( values );
765
-
766
- } else if ( parser.hasOwnProperty( property ) ) {
767
-
768
- parser[ property ] = values;
769
-
770
- }
771
- }
772
- };
773
-
774
- /**
775
- * Configures the Parser implementation according the supplied configuration object.
776
- * @memberOf THREE.LoaderSupport.WorkerRunnerRefImpl
777
- *
778
- * @param {Object} payload Raw mesh description (buffers, params, materials) used to build one to many meshes.
779
- */
780
- WorkerRunnerRefImpl.prototype.processMessage = function ( payload ) {
781
- if ( payload.cmd === 'run' ) {
782
-
783
- var callbacks = {
784
- callbackMeshBuilder: function ( payload ) {
785
- self.postMessage( payload );
786
- },
787
- callbackProgress: function ( text ) {
788
- if ( payload.logging.enabled && payload.logging.debug ) console.debug( 'WorkerRunner: progress: ' + text );
789
- }
790
- };
791
-
792
- // Parser is expected to be named as such
793
- var parser = new Parser();
794
- if ( typeof parser[ 'setLogging' ] === 'function' ) parser.setLogging( payload.logging.enabled, payload.logging.debug );
795
- this.applyProperties( parser, payload.params );
796
- this.applyProperties( parser, payload.materials );
797
- this.applyProperties( parser, callbacks );
798
- parser.workerScope = self;
799
- parser.parse( payload.data.input, payload.data.options );
800
-
801
- if ( payload.logging.enabled ) console.log( 'WorkerRunner: Run complete!' );
802
-
803
- callbacks.callbackMeshBuilder( {
804
- cmd: 'complete',
805
- msg: 'WorkerRunner completed run.'
806
- } );
807
-
808
- } else {
809
-
810
- console.error( 'WorkerRunner: Received unknown command: ' + payload.cmd );
811
-
812
- }
813
- };
814
-
815
- return WorkerRunnerRefImpl;
816
- })();
817
-
818
- /**
819
- * This class provides means to transform existing parser code into a web worker. It defines a simple communication protocol
820
- * which allows to configure the worker and receive raw mesh data during execution.
821
- * @class
822
- */
823
- THREE.LoaderSupport.WorkerSupport = (function () {
824
-
825
- var WORKER_SUPPORT_VERSION = '2.2.1';
826
-
827
- var Validator = THREE.LoaderSupport.Validator;
828
-
829
- var LoaderWorker = (function () {
830
-
831
- function LoaderWorker() {
832
- this._reset();
833
- }
834
-
835
- LoaderWorker.prototype._reset = function () {
836
- this.logging = {
837
- enabled: true,
838
- debug: false
839
- };
840
- this.worker = null;
841
- this.runnerImplName = null;
842
- this.callbacks = {
843
- meshBuilder: null,
844
- onLoad: null
845
- };
846
- this.terminateRequested = false;
847
- this.queuedMessage = null;
848
- this.started = false;
849
- this.forceCopy = false;
850
- };
851
-
852
- LoaderWorker.prototype.setLogging = function ( enabled, debug ) {
853
- this.logging.enabled = enabled === true;
854
- this.logging.debug = debug === true;
855
- };
856
-
857
- LoaderWorker.prototype.setForceCopy = function ( forceCopy ) {
858
- this.forceCopy = forceCopy === true;
859
- };
860
-
861
- LoaderWorker.prototype.initWorker = function ( code, runnerImplName ) {
862
- this.runnerImplName = runnerImplName;
863
- var blob = new Blob( [ code ], { type: 'application/javascript' } );
864
- this.worker = new Worker( window.URL.createObjectURL( blob ) );
865
- this.worker.onmessage = this._receiveWorkerMessage;
866
-
867
- // set referemce to this, then processing in worker scope within "_receiveWorkerMessage" can access members
868
- this.worker.runtimeRef = this;
869
-
870
- // process stored queuedMessage
871
- this._postMessage();
872
- };
873
-
874
- /**
875
- * Executed in worker scope
876
- */
877
- LoaderWorker.prototype._receiveWorkerMessage = function ( e ) {
878
- var payload = e.data;
879
- switch ( payload.cmd ) {
880
- case 'meshData':
881
- case 'materialData':
882
- case 'imageData':
883
- this.runtimeRef.callbacks.meshBuilder( payload );
884
- break;
885
-
886
- case 'complete':
887
- this.runtimeRef.queuedMessage = null;
888
- this.started = false;
889
- this.runtimeRef.callbacks.onLoad( payload.msg );
890
-
891
- if ( this.runtimeRef.terminateRequested ) {
892
-
893
- if ( this.runtimeRef.logging.enabled ) console.info( 'WorkerSupport [' + this.runtimeRef.runnerImplName + ']: Run is complete. Terminating application on request!' );
894
- this.runtimeRef._terminate();
895
-
896
- }
897
- break;
898
-
899
- case 'error':
900
- console.error( 'WorkerSupport [' + this.runtimeRef.runnerImplName + ']: Reported error: ' + payload.msg );
901
- this.runtimeRef.queuedMessage = null;
902
- this.started = false;
903
- this.runtimeRef.callbacks.onLoad( payload.msg );
904
-
905
- if ( this.runtimeRef.terminateRequested ) {
906
-
907
- if ( this.runtimeRef.logging.enabled ) console.info( 'WorkerSupport [' + this.runtimeRef.runnerImplName + ']: Run reported error. Terminating application on request!' );
908
- this.runtimeRef._terminate();
909
-
910
- }
911
- break;
912
-
913
- default:
914
- console.error( 'WorkerSupport [' + this.runtimeRef.runnerImplName + ']: Received unknown command: ' + payload.cmd );
915
- break;
916
-
917
- }
918
- };
919
-
920
- LoaderWorker.prototype.setCallbacks = function ( meshBuilder, onLoad ) {
921
- this.callbacks.meshBuilder = Validator.verifyInput( meshBuilder, this.callbacks.meshBuilder );
922
- this.callbacks.onLoad = Validator.verifyInput( onLoad, this.callbacks.onLoad );
923
- };
924
-
925
- LoaderWorker.prototype.run = function( payload ) {
926
- if ( Validator.isValid( this.queuedMessage ) ) {
927
-
928
- console.warn( 'Already processing message. Rejecting new run instruction' );
929
- return;
930
-
931
- } else {
932
-
933
- this.queuedMessage = payload;
934
- this.started = true;
935
-
936
- }
937
- if ( ! Validator.isValid( this.callbacks.meshBuilder ) ) throw 'Unable to run as no "MeshBuilder" callback is set.';
938
- if ( ! Validator.isValid( this.callbacks.onLoad ) ) throw 'Unable to run as no "onLoad" callback is set.';
939
- if ( payload.cmd !== 'run' ) payload.cmd = 'run';
940
- if ( Validator.isValid( payload.logging ) ) {
941
-
942
- payload.logging.enabled = payload.logging.enabled === true;
943
- payload.logging.debug = payload.logging.debug === true;
944
-
945
- } else {
946
-
947
- payload.logging = {
948
- enabled: true,
949
- debug: false
950
- };
951
-
952
- }
953
- this._postMessage();
954
- };
955
-
956
- LoaderWorker.prototype._postMessage = function () {
957
- if ( Validator.isValid( this.queuedMessage ) && Validator.isValid( this.worker ) ) {
958
-
959
- if ( this.queuedMessage.data.input instanceof ArrayBuffer ) {
960
-
961
- var content;
962
- if ( this.forceCopy ) {
963
-
964
- content = this.queuedMessage.data.input.slice( 0 );
965
-
966
- } else {
967
-
968
- content = this.queuedMessage.data.input;
969
-
970
- }
971
- this.worker.postMessage( this.queuedMessage, [ content ] );
972
-
973
- } else {
974
-
975
- this.worker.postMessage( this.queuedMessage );
976
-
977
- }
978
-
979
- }
980
- };
981
-
982
- LoaderWorker.prototype.setTerminateRequested = function ( terminateRequested ) {
983
- this.terminateRequested = terminateRequested === true;
984
- if ( this.terminateRequested && Validator.isValid( this.worker ) && ! Validator.isValid( this.queuedMessage ) && this.started ) {
985
-
986
- if ( this.logging.enabled ) console.info( 'Worker is terminated immediately as it is not running!' );
987
- this._terminate();
988
-
989
- }
990
- };
991
-
992
- LoaderWorker.prototype._terminate = function () {
993
- this.worker.terminate();
994
- this._reset();
995
- };
996
-
997
- return LoaderWorker;
998
-
999
- })();
1000
-
1001
- function WorkerSupport() {
1002
- console.info( 'Using THREE.LoaderSupport.WorkerSupport version: ' + WORKER_SUPPORT_VERSION );
1003
- this.logging = {
1004
- enabled: true,
1005
- debug: false
1006
- };
1007
-
1008
- // check worker support first
1009
- if ( window.Worker === undefined ) throw "This browser does not support web workers!";
1010
- if ( window.Blob === undefined ) throw "This browser does not support Blob!";
1011
- if ( typeof window.URL.createObjectURL !== 'function' ) throw "This browser does not support Object creation from URL!";
1012
-
1013
- this.loaderWorker = new LoaderWorker();
1014
- }
1015
-
1016
- /**
1017
- * Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
1018
- * @memberOf THREE.LoaderSupport.WorkerSupport
1019
- *
1020
- * @param {boolean} enabled True or false.
1021
- * @param {boolean} debug True or false.
1022
- */
1023
- WorkerSupport.prototype.setLogging = function ( enabled, debug ) {
1024
- this.logging.enabled = enabled === true;
1025
- this.logging.debug = debug === true;
1026
- this.loaderWorker.setLogging( this.logging.enabled, this.logging.debug );
1027
- };
1028
-
1029
- /**
1030
- * Forces all ArrayBuffers to be transferred to worker to be copied.
1031
- * @memberOf THREE.LoaderSupport.WorkerSupport
1032
- *
1033
- * @param {boolean} forceWorkerDataCopy True or false.
1034
- */
1035
- WorkerSupport.prototype.setForceWorkerDataCopy = function ( forceWorkerDataCopy ) {
1036
- this.loaderWorker.setForceCopy( forceWorkerDataCopy );
1037
- };
1038
-
1039
- /**
1040
- * Validate the status of worker code and the derived worker.
1041
- * @memberOf THREE.LoaderSupport.WorkerSupport
1042
- *
1043
- * @param {Function} functionCodeBuilder Function that is invoked with funcBuildObject and funcBuildSingleton that allows stringification of objects and singletons.
1044
- * @param {String} parserName Name of the Parser object
1045
- * @param {String[]} libLocations URL of libraries that shall be added to worker code relative to libPath
1046
- * @param {String} libPath Base path used for loading libraries
1047
- * @param {THREE.LoaderSupport.WorkerRunnerRefImpl} runnerImpl The default worker parser wrapper implementation (communication and execution). An extended class could be passed here.
1048
- */
1049
- WorkerSupport.prototype.validate = function ( functionCodeBuilder, parserName, libLocations, libPath, runnerImpl ) {
1050
- if ( Validator.isValid( this.loaderWorker.worker ) ) return;
1051
-
1052
- if ( this.logging.enabled ) {
1053
-
1054
- console.info( 'WorkerSupport: Building worker code...' );
1055
- console.time( 'buildWebWorkerCode' );
1056
-
1057
- }
1058
- if ( Validator.isValid( runnerImpl ) ) {
1059
-
1060
- if ( this.logging.enabled ) console.info( 'WorkerSupport: Using "' + runnerImpl.name + '" as Runner class for worker.' );
1061
-
1062
- } else {
1063
-
1064
- runnerImpl = THREE.LoaderSupport.WorkerRunnerRefImpl;
1065
- if ( this.logging.enabled ) console.info( 'WorkerSupport: Using DEFAULT "THREE.LoaderSupport.WorkerRunnerRefImpl" as Runner class for worker.' );
1066
-
1067
- }
1068
-
1069
- var userWorkerCode = functionCodeBuilder( buildObject, buildSingleton );
1070
- userWorkerCode += 'var Parser = '+ parserName + ';\n\n';
1071
- userWorkerCode += buildSingleton( runnerImpl.name, runnerImpl );
1072
- userWorkerCode += 'new ' + runnerImpl.name + '();\n\n';
1073
-
1074
- var scope = this;
1075
- if ( Validator.isValid( libLocations ) && libLocations.length > 0 ) {
1076
-
1077
- var libsContent = '';
1078
- var loadAllLibraries = function ( path, locations ) {
1079
- if ( locations.length === 0 ) {
1080
-
1081
- scope.loaderWorker.initWorker( libsContent + userWorkerCode, runnerImpl.name );
1082
- if ( scope.logging.enabled ) console.timeEnd( 'buildWebWorkerCode' );
1083
-
1084
- } else {
1085
-
1086
- var loadedLib = function ( contentAsString ) {
1087
- libsContent += contentAsString;
1088
- loadAllLibraries( path, locations );
1089
- };
1090
-
1091
- var fileLoader = new THREE.FileLoader();
1092
- fileLoader.setPath( path );
1093
- fileLoader.setResponseType( 'text' );
1094
- fileLoader.load( locations[ 0 ], loadedLib );
1095
- locations.shift();
1096
-
1097
- }
1098
- };
1099
- loadAllLibraries( libPath, libLocations );
1100
-
1101
- } else {
1102
-
1103
- this.loaderWorker.initWorker( userWorkerCode, runnerImpl.name );
1104
- if ( this.logging.enabled ) console.timeEnd( 'buildWebWorkerCode' );
1105
-
1106
- }
1107
- };
1108
-
1109
- /**
1110
- * Specify functions that should be build when new raw mesh data becomes available and when the parser is finished.
1111
- * @memberOf THREE.LoaderSupport.WorkerSupport
1112
- *
1113
- * @param {Function} meshBuilder The mesh builder function. Default is {@link THREE.LoaderSupport.MeshBuilder}.
1114
- * @param {Function} onLoad The function that is called when parsing is complete.
1115
- */
1116
- WorkerSupport.prototype.setCallbacks = function ( meshBuilder, onLoad ) {
1117
- this.loaderWorker.setCallbacks( meshBuilder, onLoad );
1118
- };
1119
-
1120
- /**
1121
- * Runs the parser with the provided configuration.
1122
- * @memberOf THREE.LoaderSupport.WorkerSupport
1123
- *
1124
- * @param {Object} payload Raw mesh description (buffers, params, materials) used to build one to many meshes.
1125
- */
1126
- WorkerSupport.prototype.run = function ( payload ) {
1127
- this.loaderWorker.run( payload );
1128
- };
1129
-
1130
- /**
1131
- * Request termination of worker once parser is finished.
1132
- * @memberOf THREE.LoaderSupport.WorkerSupport
1133
- *
1134
- * @param {boolean} terminateRequested True or false.
1135
- */
1136
- WorkerSupport.prototype.setTerminateRequested = function ( terminateRequested ) {
1137
- this.loaderWorker.setTerminateRequested( terminateRequested );
1138
- };
1139
-
1140
- var buildObject = function ( fullName, object ) {
1141
- var objectString = fullName + ' = {\n';
1142
- var part;
1143
- for ( var name in object ) {
1144
-
1145
- part = object[ name ];
1146
- if ( typeof( part ) === 'string' || part instanceof String ) {
1147
-
1148
- part = part.replace( '\n', '\\n' );
1149
- part = part.replace( '\r', '\\r' );
1150
- objectString += '\t' + name + ': "' + part + '",\n';
1151
-
1152
- } else if ( part instanceof Array ) {
1153
-
1154
- objectString += '\t' + name + ': [' + part + '],\n';
1155
-
1156
- } else if ( Number.isInteger( part ) ) {
1157
-
1158
- objectString += '\t' + name + ': ' + part + ',\n';
1159
-
1160
- } else if ( typeof part === 'function' ) {
1161
-
1162
- objectString += '\t' + name + ': ' + part + ',\n';
1163
-
1164
- }
1165
-
1166
- }
1167
- objectString += '}\n\n';
1168
-
1169
- return objectString;
1170
- };
1171
-
1172
- var buildSingleton = function ( fullName, object, internalName, basePrototypeName, ignoreFunctions ) {
1173
- var objectString = '';
1174
- var objectName = ( Validator.isValid( internalName ) ) ? internalName : object.name;
1175
-
1176
- var funcString, objectPart, constructorString;
1177
- ignoreFunctions = Validator.verifyInput( ignoreFunctions, [] );
1178
- for ( var name in object.prototype ) {
1179
-
1180
- objectPart = object.prototype[ name ];
1181
- if ( name === 'constructor' ) {
1182
-
1183
- funcString = objectPart.toString();
1184
- funcString = funcString.replace( 'function', '' );
1185
- constructorString = '\tfunction ' + objectName + funcString + ';\n\n';
1186
-
1187
- } else if ( typeof objectPart === 'function' ) {
1188
-
1189
- if ( ignoreFunctions.indexOf( name ) < 0 ) {
1190
-
1191
- funcString = objectPart.toString();
1192
- objectString += '\t' + objectName + '.prototype.' + name + ' = ' + funcString + ';\n\n';
1193
-
1194
- }
1195
-
1196
- }
1197
-
1198
- }
1199
- objectString += '\treturn ' + objectName + ';\n';
1200
- objectString += '})();\n\n';
1201
-
1202
- var inheritanceBlock = '';
1203
- if ( Validator.isValid( basePrototypeName ) ) {
1204
-
1205
- inheritanceBlock += '\n';
1206
- inheritanceBlock += objectName + '.prototype = Object.create( ' + basePrototypeName + '.prototype );\n';
1207
- inheritanceBlock += objectName + '.constructor = ' + objectName + ';\n';
1208
- inheritanceBlock += '\n';
1209
- }
1210
- if ( ! Validator.isValid( constructorString ) ) {
1211
-
1212
- constructorString = fullName + ' = (function () {\n\n';
1213
- constructorString += inheritanceBlock + '\t' + object.prototype.constructor.toString() + '\n\n';
1214
- objectString = constructorString + objectString;
1215
-
1216
- } else {
1217
-
1218
- objectString = fullName + ' = (function () {\n\n' + inheritanceBlock + constructorString + objectString;
1219
-
1220
- }
1221
-
1222
- return objectString;
1223
- };
1224
-
1225
- return WorkerSupport;
1226
-
1227
- })();
1228
-
1229
- /**
1230
- * Orchestrate loading of multiple OBJ files/data from an instruction queue with a configurable amount of workers (1-16).
1231
- * Workflow:
1232
- * prepareWorkers
1233
- * enqueueForRun
1234
- * processQueue
1235
- * tearDown (to force stop)
1236
- *
1237
- * @class
1238
- *
1239
- * @param {string} classDef Class definition to be used for construction
1240
- */
1241
- THREE.LoaderSupport.WorkerDirector = (function () {
1242
-
1243
- var LOADER_WORKER_DIRECTOR_VERSION = '2.2.2';
1244
-
1245
- var Validator = THREE.LoaderSupport.Validator;
1246
-
1247
- var MAX_WEB_WORKER = 16;
1248
- var MAX_QUEUE_SIZE = 8192;
1249
-
1250
- function WorkerDirector( classDef ) {
1251
- console.info( 'Using THREE.LoaderSupport.WorkerDirector version: ' + LOADER_WORKER_DIRECTOR_VERSION );
1252
- this.logging = {
1253
- enabled: true,
1254
- debug: false
1255
- };
1256
-
1257
- this.maxQueueSize = MAX_QUEUE_SIZE ;
1258
- this.maxWebWorkers = MAX_WEB_WORKER;
1259
- this.crossOrigin = null;
1260
-
1261
- if ( ! Validator.isValid( classDef ) ) throw 'Provided invalid classDef: ' + classDef;
1262
-
1263
- this.workerDescription = {
1264
- classDef: classDef,
1265
- globalCallbacks: {},
1266
- workerSupports: {},
1267
- forceWorkerDataCopy: true
1268
- };
1269
- this.objectsCompleted = 0;
1270
- this.instructionQueue = [];
1271
- this.instructionQueuePointer = 0;
1272
-
1273
- this.callbackOnFinishedProcessing = null;
1274
- }
1275
-
1276
- /**
1277
- * Enable or disable logging in general (except warn and error), plus enable or disable debug logging.
1278
- * @memberOf THREE.LoaderSupport.WorkerDirector
1279
- *
1280
- * @param {boolean} enabled True or false.
1281
- * @param {boolean} debug True or false.
1282
- */
1283
- WorkerDirector.prototype.setLogging = function ( enabled, debug ) {
1284
- this.logging.enabled = enabled === true;
1285
- this.logging.debug = debug === true;
1286
- };
1287
-
1288
- /**
1289
- * Returns the maximum length of the instruction queue.
1290
- * @memberOf THREE.LoaderSupport.WorkerDirector
1291
- *
1292
- * @returns {number}
1293
- */
1294
- WorkerDirector.prototype.getMaxQueueSize = function () {
1295
- return this.maxQueueSize;
1296
- };
1297
-
1298
- /**
1299
- * Returns the maximum number of workers.
1300
- * @memberOf THREE.LoaderSupport.WorkerDirector
1301
- *
1302
- * @returns {number}
1303
- */
1304
- WorkerDirector.prototype.getMaxWebWorkers = function () {
1305
- return this.maxWebWorkers;
1306
- };
1307
-
1308
- /**
1309
- * Sets the CORS string to be used.
1310
- * @memberOf THREE.LoaderSupport.WorkerDirector
1311
- *
1312
- * @param {string} crossOrigin CORS value
1313
- */
1314
- WorkerDirector.prototype.setCrossOrigin = function ( crossOrigin ) {
1315
- this.crossOrigin = crossOrigin;
1316
- };
1317
-
1318
- /**
1319
- * Forces all ArrayBuffers to be transferred to worker to be copied.
1320
- * @memberOf THREE.LoaderSupport.WorkerDirector
1321
- *
1322
- * @param {boolean} forceWorkerDataCopy True or false.
1323
- */
1324
- WorkerDirector.prototype.setForceWorkerDataCopy = function ( forceWorkerDataCopy ) {
1325
- this.workerDescription.forceWorkerDataCopy = forceWorkerDataCopy === true;
1326
- };
1327
-
1328
- /**
1329
- * Create or destroy workers according limits. Set the name and register callbacks for dynamically created web workers.
1330
- * @memberOf THREE.LoaderSupport.WorkerDirector
1331
- *
1332
- * @param {THREE.OBJLoader2.WWOBJLoader2.PrepDataCallbacks} globalCallbacks Register global callbacks used by all web workers
1333
- * @param {number} maxQueueSize Set the maximum size of the instruction queue (1-1024)
1334
- * @param {number} maxWebWorkers Set the maximum amount of workers (1-16)
1335
- */
1336
- WorkerDirector.prototype.prepareWorkers = function ( globalCallbacks, maxQueueSize, maxWebWorkers ) {
1337
- if ( Validator.isValid( globalCallbacks ) ) this.workerDescription.globalCallbacks = globalCallbacks;
1338
- this.maxQueueSize = Math.min( maxQueueSize, MAX_QUEUE_SIZE );
1339
- this.maxWebWorkers = Math.min( maxWebWorkers, MAX_WEB_WORKER );
1340
- this.maxWebWorkers = Math.min( this.maxWebWorkers, this.maxQueueSize );
1341
- this.objectsCompleted = 0;
1342
- this.instructionQueue = [];
1343
- this.instructionQueuePointer = 0;
1344
-
1345
- for ( var instanceNo = 0; instanceNo < this.maxWebWorkers; instanceNo++ ) {
1346
-
1347
- var workerSupport = new THREE.LoaderSupport.WorkerSupport();
1348
- workerSupport.setLogging( this.logging.enabled, this.logging.debug );
1349
- workerSupport.setForceWorkerDataCopy( this.workerDescription.forceWorkerDataCopy );
1350
- this.workerDescription.workerSupports[ instanceNo ] = {
1351
- instanceNo: instanceNo,
1352
- inUse: false,
1353
- terminateRequested: false,
1354
- workerSupport: workerSupport,
1355
- loader: null
1356
- };
1357
-
1358
- }
1359
- };
1360
-
1361
- /**
1362
- * Store run instructions in internal instructionQueue.
1363
- * @memberOf THREE.LoaderSupport.WorkerDirector
1364
- *
1365
- * @param {THREE.LoaderSupport.PrepData} prepData
1366
- */
1367
- WorkerDirector.prototype.enqueueForRun = function ( prepData ) {
1368
- if ( this.instructionQueue.length < this.maxQueueSize ) {
1369
- this.instructionQueue.push( prepData );
1370
- }
1371
- };
1372
-
1373
- /**
1374
- * Returns if any workers are running.
1375
- *
1376
- * @memberOf THREE.LoaderSupport.WorkerDirector
1377
- * @returns {boolean}
1378
- */
1379
- WorkerDirector.prototype.isRunning = function () {
1380
- var wsKeys = Object.keys( this.workerDescription.workerSupports );
1381
- return ( ( this.instructionQueue.length > 0 && this.instructionQueuePointer < this.instructionQueue.length ) || wsKeys.length > 0 );
1382
- };
1383
-
1384
- /**
1385
- * Process the instructionQueue until it is depleted.
1386
- * @memberOf THREE.LoaderSupport.WorkerDirector
1387
- */
1388
- WorkerDirector.prototype.processQueue = function () {
1389
- var prepData, supportDesc;
1390
- for ( var instanceNo in this.workerDescription.workerSupports ) {
1391
-
1392
- supportDesc = this.workerDescription.workerSupports[ instanceNo ];
1393
- if ( ! supportDesc.inUse ) {
1394
-
1395
- if ( this.instructionQueuePointer < this.instructionQueue.length ) {
1396
-
1397
- prepData = this.instructionQueue[ this.instructionQueuePointer ];
1398
- this._kickWorkerRun( prepData, supportDesc );
1399
- this.instructionQueuePointer++;
1400
-
1401
- } else {
1402
-
1403
- this._deregister( supportDesc );
1404
-
1405
- }
1406
-
1407
- }
1408
-
1409
- }
1410
-
1411
- if ( ! this.isRunning() && this.callbackOnFinishedProcessing !== null ) {
1412
-
1413
- this.callbackOnFinishedProcessing();
1414
- this.callbackOnFinishedProcessing = null;
1415
-
1416
- }
1417
- };
1418
-
1419
- WorkerDirector.prototype._kickWorkerRun = function( prepData, supportDesc ) {
1420
- supportDesc.inUse = true;
1421
- supportDesc.workerSupport.setTerminateRequested( supportDesc.terminateRequested );
1422
-
1423
- if ( this.logging.enabled ) console.info( '\nAssigning next item from queue to worker (queue length: ' + this.instructionQueue.length + ')\n\n' );
1424
-
1425
- var scope = this;
1426
- var prepDataCallbacks = prepData.getCallbacks();
1427
- var globalCallbacks = this.workerDescription.globalCallbacks;
1428
- var wrapperOnLoad = function ( event ) {
1429
- if ( Validator.isValid( globalCallbacks.onLoad ) ) globalCallbacks.onLoad( event );
1430
- if ( Validator.isValid( prepDataCallbacks.onLoad ) ) prepDataCallbacks.onLoad( event );
1431
- scope.objectsCompleted++;
1432
- supportDesc.inUse = false;
1433
-
1434
- scope.processQueue();
1435
- };
1436
-
1437
- var wrapperOnProgress = function ( event ) {
1438
- if ( Validator.isValid( globalCallbacks.onProgress ) ) globalCallbacks.onProgress( event );
1439
- if ( Validator.isValid( prepDataCallbacks.onProgress ) ) prepDataCallbacks.onProgress( event );
1440
- };
1441
-
1442
- var wrapperOnMeshAlter = function ( event, override ) {
1443
- if ( Validator.isValid( globalCallbacks.onMeshAlter ) ) override = globalCallbacks.onMeshAlter( event, override );
1444
- if ( Validator.isValid( prepDataCallbacks.onMeshAlter ) ) override = globalCallbacks.onMeshAlter( event, override );
1445
- return override;
1446
- };
1447
-
1448
- var wrapperOnLoadMaterials = function ( materials ) {
1449
- if ( Validator.isValid( globalCallbacks.onLoadMaterials ) ) materials = globalCallbacks.onLoadMaterials( materials );
1450
- if ( Validator.isValid( prepDataCallbacks.onLoadMaterials ) ) materials = prepDataCallbacks.onLoadMaterials( materials );
1451
- return materials;
1452
- };
1453
-
1454
- var wrapperOnReportError = function ( errorMessage ) {
1455
- var continueProcessing = true;
1456
- if ( Validator.isValid( globalCallbacks.onReportError ) ) continueProcessing = globalCallbacks.onReportError( supportDesc, errorMessage );
1457
- if ( Validator.isValid( prepDataCallbacks.onReportError ) ) continueProcessing = prepDataCallbacks.onReportError( supportDesc, errorMessage );
1458
-
1459
- if ( ! Validator.isValid( globalCallbacks.onReportError ) && ! Validator.isValid( prepDataCallbacks.onReportError ) ) {
1460
-
1461
- console.error( 'Loader reported an error: ' );
1462
- console.error( errorMessage );
1463
-
1464
- }
1465
- if ( continueProcessing ) {
1466
-
1467
- supportDesc.inUse = false;
1468
- scope.processQueue();
1469
-
1470
- }
1471
- };
1472
-
1473
- supportDesc.loader = this._buildLoader( supportDesc.instanceNo );
1474
-
1475
- var updatedCallbacks = new THREE.LoaderSupport.Callbacks();
1476
- updatedCallbacks.setCallbackOnLoad( wrapperOnLoad );
1477
- updatedCallbacks.setCallbackOnProgress( wrapperOnProgress );
1478
- updatedCallbacks.setCallbackOnReportError( wrapperOnReportError );
1479
- updatedCallbacks.setCallbackOnMeshAlter( wrapperOnMeshAlter );
1480
- updatedCallbacks.setCallbackOnLoadMaterials( wrapperOnLoadMaterials );
1481
- prepData.callbacks = updatedCallbacks;
1482
-
1483
- supportDesc.loader.run( prepData, supportDesc.workerSupport );
1484
- };
1485
-
1486
- WorkerDirector.prototype._buildLoader = function ( instanceNo ) {
1487
- var classDef = this.workerDescription.classDef;
1488
- var loader = Object.create( classDef.prototype );
1489
- classDef.call( loader, THREE.DefaultLoadingManager );
1490
-
1491
- // verify that all required functions are implemented
1492
- if ( ! loader.hasOwnProperty( 'instanceNo' ) ) throw classDef.name + ' has no property "instanceNo".';
1493
- loader.instanceNo = instanceNo;
1494
-
1495
- if ( ! loader.hasOwnProperty( 'workerSupport' ) ) {
1496
-
1497
- throw classDef.name + ' has no property "workerSupport".';
1498
-
1499
- }
1500
- if ( typeof loader.run !== 'function' ) throw classDef.name + ' has no function "run".';
1501
- if ( ! loader.hasOwnProperty( 'callbacks' ) || ! Validator.isValid( loader.callbacks ) ) {
1502
-
1503
- console.warn( classDef.name + ' has an invalid property "callbacks". Will change to "THREE.LoaderSupport.Callbacks"' );
1504
- loader.callbacks = new THREE.LoaderSupport.Callbacks();
1505
-
1506
- }
1507
-
1508
- return loader;
1509
- };
1510
-
1511
- WorkerDirector.prototype._deregister = function ( supportDesc ) {
1512
- if ( Validator.isValid( supportDesc ) ) {
1513
-
1514
- supportDesc.workerSupport.setTerminateRequested( true );
1515
- if ( this.logging.enabled ) console.info( 'Requested termination of worker #' + supportDesc.instanceNo + '.' );
1516
-
1517
- var loaderCallbacks = supportDesc.loader.callbacks;
1518
- if ( Validator.isValid( loaderCallbacks.onProgress ) ) loaderCallbacks.onProgress( { detail: { text: '' } } );
1519
- delete this.workerDescription.workerSupports[ supportDesc.instanceNo ];
1520
-
1521
- }
1522
- };
1523
-
1524
- /**
1525
- * Terminate all workers.
1526
- * @memberOf THREE.LoaderSupport.WorkerDirector
1527
- *
1528
- * @param {callback} callbackOnFinishedProcessing Function called once all workers finished processing.
1529
- */
1530
- WorkerDirector.prototype.tearDown = function ( callbackOnFinishedProcessing ) {
1531
- if ( this.logging.enabled ) console.info( 'WorkerDirector received the deregister call. Terminating all workers!' );
1532
-
1533
- this.instructionQueuePointer = this.instructionQueue.length;
1534
- this.callbackOnFinishedProcessing = Validator.verifyInput( callbackOnFinishedProcessing, null );
1535
-
1536
- for ( var name in this.workerDescription.workerSupports ) {
1537
-
1538
- this.workerDescription.workerSupports[ name ].terminateRequested = true;
1539
-
1540
- }
1541
- };
1542
-
1543
- return WorkerDirector;
1544
-
1545
- })();