itowns 2.44.3-next.4 → 2.44.3-next.41

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 (217) hide show
  1. package/README.md +3 -129
  2. package/examples/3dtiles_loader.html +123 -48
  3. package/examples/config.json +3 -10
  4. package/examples/copc_simple_loader.html +15 -5
  5. package/examples/effects_stereo.html +2 -2
  6. package/examples/entwine_3d_loader.html +3 -1
  7. package/examples/entwine_simple_loader.html +1 -1
  8. package/examples/images/itowns_logo.svg +123 -0
  9. package/examples/js/plugins/COGParser.js +1 -1
  10. package/examples/jsm/OGC3DTilesHelper.js +6 -1
  11. package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
  12. package/examples/misc_collada.html +2 -2
  13. package/examples/source_file_geojson_3d.html +0 -1
  14. package/examples/source_file_kml_raster_usgs.html +0 -1
  15. package/examples/source_stream_wfs_raster.html +0 -7
  16. package/examples/vector_tile_mapbox_raster.html +91 -0
  17. package/examples/view_3d_map_webxr.html +3 -1
  18. package/examples/view_multi_25d.html +2 -2
  19. package/package.json +21 -75
  20. package/CODING.md +0 -120
  21. package/CONTRIBUTING.md +0 -150
  22. package/CONTRIBUTORS.md +0 -55
  23. package/LICENSE.md +0 -44
  24. package/changelog.md +0 -1361
  25. package/dist/455.js +0 -2
  26. package/dist/455.js.map +0 -1
  27. package/dist/debug.js +0 -3
  28. package/dist/debug.js.LICENSE.txt +0 -13
  29. package/dist/debug.js.map +0 -1
  30. package/dist/itowns.js +0 -3
  31. package/dist/itowns.js.LICENSE.txt +0 -7
  32. package/dist/itowns.js.map +0 -1
  33. package/dist/itowns_lasparser.js +0 -2
  34. package/dist/itowns_lasparser.js.map +0 -1
  35. package/dist/itowns_lasworker.js +0 -2
  36. package/dist/itowns_lasworker.js.map +0 -1
  37. package/dist/itowns_potree2worker.js +0 -2
  38. package/dist/itowns_potree2worker.js.map +0 -1
  39. package/dist/itowns_widgets.js +0 -2
  40. package/dist/itowns_widgets.js.map +0 -1
  41. package/examples/.eslintrc.cjs +0 -35
  42. package/examples/3dtiles_25d.html +0 -120
  43. package/examples/3dtiles_basic.html +0 -94
  44. package/examples/3dtiles_batch_table.html +0 -86
  45. package/examples/3dtiles_ion.html +0 -126
  46. package/examples/3dtiles_pointcloud.html +0 -95
  47. package/examples/jsm/.eslintrc.cjs +0 -38
  48. package/lib/Controls/FirstPersonControls.js +0 -308
  49. package/lib/Controls/FlyControls.js +0 -175
  50. package/lib/Controls/GlobeControls.js +0 -1162
  51. package/lib/Controls/PlanarControls.js +0 -1025
  52. package/lib/Controls/StateControl.js +0 -429
  53. package/lib/Controls/StreetControls.js +0 -392
  54. package/lib/Converter/Feature2Mesh.js +0 -608
  55. package/lib/Converter/Feature2Texture.js +0 -170
  56. package/lib/Converter/convertToTile.js +0 -75
  57. package/lib/Converter/textureConverter.js +0 -44
  58. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  59. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  60. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  61. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  62. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  63. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  64. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  65. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  66. package/lib/Core/AnimationPlayer.js +0 -142
  67. package/lib/Core/CopcNode.js +0 -174
  68. package/lib/Core/Deprecated/Undeprecator.js +0 -75
  69. package/lib/Core/EntwinePointTileNode.js +0 -126
  70. package/lib/Core/Feature.js +0 -490
  71. package/lib/Core/Geographic/CoordStars.js +0 -80
  72. package/lib/Core/Geographic/Coordinates.js +0 -320
  73. package/lib/Core/Geographic/Crs.js +0 -175
  74. package/lib/Core/Geographic/Extent.js +0 -726
  75. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  76. package/lib/Core/Label.js +0 -222
  77. package/lib/Core/MainLoop.js +0 -211
  78. package/lib/Core/Math/Ellipsoid.js +0 -144
  79. package/lib/Core/Picking.js +0 -255
  80. package/lib/Core/PointCloudNode.js +0 -42
  81. package/lib/Core/Potree2Node.js +0 -206
  82. package/lib/Core/Potree2PointAttributes.js +0 -139
  83. package/lib/Core/PotreeNode.js +0 -101
  84. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
  85. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
  86. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
  87. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  88. package/lib/Core/Prefab/GlobeView.js +0 -161
  89. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
  90. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  91. package/lib/Core/Prefab/PlanarView.js +0 -62
  92. package/lib/Core/Prefab/TileBuilder.js +0 -80
  93. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
  94. package/lib/Core/Scheduler/Cache.js +0 -256
  95. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  96. package/lib/Core/Scheduler/Scheduler.js +0 -294
  97. package/lib/Core/Style.js +0 -1121
  98. package/lib/Core/System/Capabilities.js +0 -63
  99. package/lib/Core/TileGeometry.js +0 -40
  100. package/lib/Core/TileMesh.js +0 -108
  101. package/lib/Core/View.js +0 -1109
  102. package/lib/Layer/C3DTilesLayer.js +0 -455
  103. package/lib/Layer/ColorLayer.js +0 -128
  104. package/lib/Layer/CopcLayer.js +0 -58
  105. package/lib/Layer/ElevationLayer.js +0 -107
  106. package/lib/Layer/EntwinePointTileLayer.js +0 -64
  107. package/lib/Layer/FeatureGeometryLayer.js +0 -63
  108. package/lib/Layer/GeoidLayer.js +0 -80
  109. package/lib/Layer/GeometryLayer.js +0 -202
  110. package/lib/Layer/InfoLayer.js +0 -64
  111. package/lib/Layer/LabelLayer.js +0 -452
  112. package/lib/Layer/Layer.js +0 -304
  113. package/lib/Layer/LayerUpdateState.js +0 -89
  114. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  115. package/lib/Layer/OGC3DTilesLayer.js +0 -387
  116. package/lib/Layer/OrientedImageLayer.js +0 -222
  117. package/lib/Layer/PointCloudLayer.js +0 -359
  118. package/lib/Layer/Potree2Layer.js +0 -164
  119. package/lib/Layer/PotreeLayer.js +0 -65
  120. package/lib/Layer/RasterLayer.js +0 -27
  121. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  122. package/lib/Layer/TiledGeometryLayer.js +0 -403
  123. package/lib/Loader/LASLoader.js +0 -193
  124. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  125. package/lib/Loader/Potree2Loader.js +0 -207
  126. package/lib/Main.js +0 -115
  127. package/lib/MainBundle.js +0 -4
  128. package/lib/Parser/B3dmParser.js +0 -174
  129. package/lib/Parser/CameraCalibrationParser.js +0 -94
  130. package/lib/Parser/GDFParser.js +0 -72
  131. package/lib/Parser/GTXParser.js +0 -75
  132. package/lib/Parser/GeoJsonParser.js +0 -212
  133. package/lib/Parser/GpxParser.js +0 -25
  134. package/lib/Parser/ISGParser.js +0 -71
  135. package/lib/Parser/KMLParser.js +0 -25
  136. package/lib/Parser/LASParser.js +0 -137
  137. package/lib/Parser/MapBoxUrlParser.js +0 -83
  138. package/lib/Parser/PntsParser.js +0 -131
  139. package/lib/Parser/Potree2BinParser.js +0 -92
  140. package/lib/Parser/PotreeBinParser.js +0 -106
  141. package/lib/Parser/PotreeCinParser.js +0 -29
  142. package/lib/Parser/ShapefileParser.js +0 -78
  143. package/lib/Parser/VectorTileParser.js +0 -202
  144. package/lib/Parser/XbilParser.js +0 -108
  145. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  146. package/lib/Parser/iGLTFLoader.js +0 -168
  147. package/lib/Process/3dTilesProcessing.js +0 -304
  148. package/lib/Process/FeatureProcessing.js +0 -76
  149. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  150. package/lib/Process/ObjectRemovalHelper.js +0 -97
  151. package/lib/Process/handlerNodeError.js +0 -23
  152. package/lib/Provider/3dTilesProvider.js +0 -149
  153. package/lib/Provider/DataSourceProvider.js +0 -8
  154. package/lib/Provider/Fetcher.js +0 -229
  155. package/lib/Provider/PointCloudProvider.js +0 -45
  156. package/lib/Provider/TileProvider.js +0 -16
  157. package/lib/Provider/URLBuilder.js +0 -105
  158. package/lib/Renderer/Camera.js +0 -281
  159. package/lib/Renderer/Color.js +0 -56
  160. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  161. package/lib/Renderer/CommonMaterial.js +0 -31
  162. package/lib/Renderer/Label2DRenderer.js +0 -190
  163. package/lib/Renderer/LayeredMaterial.js +0 -243
  164. package/lib/Renderer/OBB.js +0 -153
  165. package/lib/Renderer/OrientedImageCamera.js +0 -118
  166. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  167. package/lib/Renderer/PointsMaterial.js +0 -485
  168. package/lib/Renderer/RasterTile.js +0 -209
  169. package/lib/Renderer/RenderMode.js +0 -31
  170. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  171. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  172. package/lib/Renderer/SphereHelper.js +0 -23
  173. package/lib/Renderer/WebXR.js +0 -51
  174. package/lib/Renderer/c3DEngine.js +0 -214
  175. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  176. package/lib/Source/C3DTilesIonSource.js +0 -54
  177. package/lib/Source/C3DTilesSource.js +0 -30
  178. package/lib/Source/CopcSource.js +0 -115
  179. package/lib/Source/EntwinePointTileSource.js +0 -62
  180. package/lib/Source/FileSource.js +0 -189
  181. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  182. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  183. package/lib/Source/OGC3DTilesSource.js +0 -21
  184. package/lib/Source/OrientedImageSource.js +0 -59
  185. package/lib/Source/Potree2Source.js +0 -167
  186. package/lib/Source/PotreeSource.js +0 -82
  187. package/lib/Source/Source.js +0 -223
  188. package/lib/Source/TMSSource.js +0 -143
  189. package/lib/Source/VectorTilesSource.js +0 -178
  190. package/lib/Source/WFSSource.js +0 -165
  191. package/lib/Source/WMSSource.js +0 -130
  192. package/lib/Source/WMTSSource.js +0 -86
  193. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  194. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
  195. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  196. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  197. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
  198. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
  199. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
  200. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  201. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  202. package/lib/Utils/CameraUtils.js +0 -555
  203. package/lib/Utils/DEMUtils.js +0 -350
  204. package/lib/Utils/FeaturesUtils.js +0 -156
  205. package/lib/Utils/Gradients.js +0 -16
  206. package/lib/Utils/OrientationUtils.js +0 -457
  207. package/lib/Utils/ThreeUtils.js +0 -115
  208. package/lib/Utils/gui/C3DTilesStyle.js +0 -216
  209. package/lib/Utils/gui/Main.js +0 -7
  210. package/lib/Utils/gui/Minimap.js +0 -154
  211. package/lib/Utils/gui/Navigation.js +0 -245
  212. package/lib/Utils/gui/Scale.js +0 -107
  213. package/lib/Utils/gui/Searchbar.js +0 -234
  214. package/lib/Utils/gui/Widget.js +0 -80
  215. package/lib/Utils/placeObjectOnGround.js +0 -137
  216. package/lib/Worker/LASLoaderWorker.js +0 -19
  217. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,200 +0,0 @@
1
- import { CompressedTextureLoader, RGBAFormat, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_ETC1_Format, RGB_S3TC_DXT1_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format } from 'three';
2
- class DDSLoader extends CompressedTextureLoader {
3
- constructor(manager) {
4
- super(manager);
5
- }
6
- parse(buffer, loadMipmaps) {
7
- const dds = {
8
- mipmaps: [],
9
- width: 0,
10
- height: 0,
11
- format: null,
12
- mipmapCount: 1
13
- };
14
-
15
- // Adapted from @toji's DDS utils
16
- // https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js
17
-
18
- // All values and structures referenced from:
19
- // http://msdn.microsoft.com/en-us/library/bb943991.aspx/
20
-
21
- // const DDSD_CAPS = 0x1;
22
- // const DDSD_HEIGHT = 0x2;
23
- // const DDSD_WIDTH = 0x4;
24
- // const DDSD_PITCH = 0x8;
25
- // const DDSD_PIXELFORMAT = 0x1000;
26
-
27
- // const DDSD_LINEARSIZE = 0x80000;
28
- // const DDSD_DEPTH = 0x800000;
29
-
30
- // const DDSCAPS_COMPLEX = 0x8;
31
- // const DDSCAPS_MIPMAP = 0x400000;
32
- // const DDSCAPS_TEXTURE = 0x1000;
33
-
34
- // const DDSCAPS2_VOLUME = 0x200000;
35
-
36
- // const DDPF_ALPHAPIXELS = 0x1;
37
- // const DDPF_ALPHA = 0x2;
38
- // const DDPF_FOURCC = 0x4;
39
- // const DDPF_RGB = 0x40;
40
- // const DDPF_YUV = 0x200;
41
- // const DDPF_LUMINANCE = 0x20000;
42
-
43
- function fourCCToInt32(value) {
44
- return value.charCodeAt(0) + (value.charCodeAt(1) << 8) + (value.charCodeAt(2) << 16) + (value.charCodeAt(3) << 24);
45
- }
46
- function int32ToFourCC(value) {
47
- return String.fromCharCode(value & 0xff, value >> 8 & 0xff, value >> 16 & 0xff, value >> 24 & 0xff);
48
- }
49
- function loadARGBMip(buffer, dataOffset, width, height) {
50
- const dataLength = width * height * 4;
51
- const srcBuffer = new Uint8Array(buffer, dataOffset, dataLength);
52
- const byteArray = new Uint8Array(dataLength);
53
- let dst = 0;
54
- let src = 0;
55
- for (let y = 0; y < height; y++) {
56
- for (let x = 0; x < width; x++) {
57
- const b = srcBuffer[src];
58
- src++;
59
- const g = srcBuffer[src];
60
- src++;
61
- const r = srcBuffer[src];
62
- src++;
63
- const a = srcBuffer[src];
64
- src++;
65
- byteArray[dst] = r;
66
- dst++; //r
67
- byteArray[dst] = g;
68
- dst++; //g
69
- byteArray[dst] = b;
70
- dst++; //b
71
- byteArray[dst] = a;
72
- dst++; //a
73
- }
74
- }
75
- return byteArray;
76
- }
77
- const FOURCC_DXT1 = fourCCToInt32('DXT1');
78
- const FOURCC_DXT3 = fourCCToInt32('DXT3');
79
- const FOURCC_DXT5 = fourCCToInt32('DXT5');
80
- const FOURCC_ETC1 = fourCCToInt32('ETC1');
81
- const FOURCC_DX10 = fourCCToInt32('DX10');
82
- const headerLengthInt = 31; // The header length in 32 bit ints
83
- const extendedHeaderLengthInt = 5; // The extended header length in 32 bit ints
84
-
85
- // Offsets into the header array
86
-
87
- // const off_pfFlags = 20;
88
-
89
- // const off_caps = 27;
90
-
91
- // const off_caps3 = 29;
92
- // const off_caps4 = 30;
93
-
94
- // If fourCC = DX10, the extended header starts after 32
95
-
96
- // Parse header
97
-
98
- const header = new Int32Array(buffer, 0, headerLengthInt);
99
- if (header[0] !== 0x20534444) {
100
- console.error('THREE.DDSLoader.parse: Invalid magic number in DDS header.');
101
- return dds;
102
- }
103
- let blockBytes;
104
- const fourCC = header[21];
105
- let isRGBAUncompressed = false;
106
- let dataOffset = header[1] + 4;
107
- switch (fourCC) {
108
- case FOURCC_DXT1:
109
- blockBytes = 8;
110
- dds.format = RGB_S3TC_DXT1_Format;
111
- break;
112
- case FOURCC_DXT3:
113
- blockBytes = 16;
114
- dds.format = RGBA_S3TC_DXT3_Format;
115
- break;
116
- case FOURCC_DXT5:
117
- blockBytes = 16;
118
- dds.format = RGBA_S3TC_DXT5_Format;
119
- break;
120
- case FOURCC_ETC1:
121
- blockBytes = 8;
122
- dds.format = RGB_ETC1_Format;
123
- break;
124
- case FOURCC_DX10:
125
- dataOffset += extendedHeaderLengthInt * 4;
126
- const extendedHeader = new Int32Array(buffer, (headerLengthInt + 1) * 4, extendedHeaderLengthInt);
127
- const dxgiFormat = extendedHeader[0];
128
- switch (dxgiFormat) {
129
- case 96:
130
- {
131
- blockBytes = 16;
132
- dds.format = RGB_BPTC_SIGNED_Format;
133
- break;
134
- }
135
- case 95:
136
- {
137
- blockBytes = 16;
138
- dds.format = RGB_BPTC_UNSIGNED_Format;
139
- break;
140
- }
141
- default:
142
- {
143
- console.error('THREE.DDSLoader.parse: Unsupported DXGI_FORMAT code ', dxgiFormat);
144
- return dds;
145
- }
146
- }
147
- break;
148
- default:
149
- if (header[22] === 32 && header[23] & 0xff0000 && header[24] & 0xff00 && header[25] & 0xff && header[26] & 0xff000000) {
150
- isRGBAUncompressed = true;
151
- blockBytes = 64;
152
- dds.format = RGBAFormat;
153
- } else {
154
- console.error('THREE.DDSLoader.parse: Unsupported FourCC code ', int32ToFourCC(fourCC));
155
- return dds;
156
- }
157
- }
158
- dds.mipmapCount = 1;
159
- if (header[2] & 0x20000 && loadMipmaps !== false) {
160
- dds.mipmapCount = Math.max(1, header[7]);
161
- }
162
- const caps2 = header[28];
163
- dds.isCubemap = caps2 & 0x200 ? true : false;
164
- if (dds.isCubemap && (!(caps2 & 0x400) || !(caps2 & 0x800) || !(caps2 & 0x1000) || !(caps2 & 0x2000) || !(caps2 & 0x4000) || !(caps2 & 0x8000))) {
165
- console.error('THREE.DDSLoader.parse: Incomplete cubemap faces');
166
- return dds;
167
- }
168
- dds.width = header[4];
169
- dds.height = header[3];
170
-
171
- // Extract mipmaps buffers
172
-
173
- const faces = dds.isCubemap ? 6 : 1;
174
- for (let face = 0; face < faces; face++) {
175
- let width = dds.width;
176
- let height = dds.height;
177
- for (let i = 0; i < dds.mipmapCount; i++) {
178
- let byteArray, dataLength;
179
- if (isRGBAUncompressed) {
180
- byteArray = loadARGBMip(buffer, dataOffset, width, height);
181
- dataLength = byteArray.length;
182
- } else {
183
- dataLength = Math.max(4, width) / 4 * Math.max(4, height) / 4 * blockBytes;
184
- byteArray = new Uint8Array(buffer, dataOffset, dataLength);
185
- }
186
- const mipmap = {
187
- 'data': byteArray,
188
- 'width': width,
189
- 'height': height
190
- };
191
- dds.mipmaps.push(mipmap);
192
- dataOffset += dataLength;
193
- width = Math.max(width >> 1, 1);
194
- height = Math.max(height >> 1, 1);
195
- }
196
- }
197
- return dds;
198
- }
199
- }
200
- export { DDSLoader };
@@ -1,399 +0,0 @@
1
- import { BufferAttribute, BufferGeometry, Color, FileLoader, Loader, LinearSRGBColorSpace, SRGBColorSpace } from 'three';
2
- const _taskCache = new WeakMap();
3
- class DRACOLoader extends Loader {
4
- constructor(manager) {
5
- super(manager);
6
- this.decoderPath = '';
7
- this.decoderConfig = {};
8
- this.decoderBinary = null;
9
- this.decoderPending = null;
10
- this.workerLimit = 4;
11
- this.workerPool = [];
12
- this.workerNextTaskID = 1;
13
- this.workerSourceURL = '';
14
- this.defaultAttributeIDs = {
15
- position: 'POSITION',
16
- normal: 'NORMAL',
17
- color: 'COLOR',
18
- uv: 'TEX_COORD'
19
- };
20
- this.defaultAttributeTypes = {
21
- position: 'Float32Array',
22
- normal: 'Float32Array',
23
- color: 'Float32Array',
24
- uv: 'Float32Array'
25
- };
26
- }
27
- setDecoderPath(path) {
28
- this.decoderPath = path;
29
- return this;
30
- }
31
- setDecoderConfig(config) {
32
- this.decoderConfig = config;
33
- return this;
34
- }
35
- setWorkerLimit(workerLimit) {
36
- this.workerLimit = workerLimit;
37
- return this;
38
- }
39
- load(url, onLoad, onProgress, onError) {
40
- const loader = new FileLoader(this.manager);
41
- loader.setPath(this.path);
42
- loader.setResponseType('arraybuffer');
43
- loader.setRequestHeader(this.requestHeader);
44
- loader.setWithCredentials(this.withCredentials);
45
- loader.load(url, buffer => {
46
- this.parse(buffer, onLoad, onError);
47
- }, onProgress, onError);
48
- }
49
- parse(buffer, onLoad) {
50
- let onError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : () => {};
51
- this.decodeDracoFile(buffer, onLoad, null, null, SRGBColorSpace, onError).catch(onError);
52
- }
53
- decodeDracoFile(buffer, callback, attributeIDs, attributeTypes) {
54
- let vertexColorSpace = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : LinearSRGBColorSpace;
55
- let onError = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : () => {};
56
- const taskConfig = {
57
- attributeIDs: attributeIDs || this.defaultAttributeIDs,
58
- attributeTypes: attributeTypes || this.defaultAttributeTypes,
59
- useUniqueIDs: !!attributeIDs,
60
- vertexColorSpace: vertexColorSpace
61
- };
62
- return this.decodeGeometry(buffer, taskConfig).then(callback).catch(onError);
63
- }
64
- decodeGeometry(buffer, taskConfig) {
65
- const taskKey = JSON.stringify(taskConfig);
66
-
67
- // Check for an existing task using this buffer. A transferred buffer cannot be transferred
68
- // again from this thread.
69
- if (_taskCache.has(buffer)) {
70
- const cachedTask = _taskCache.get(buffer);
71
- if (cachedTask.key === taskKey) {
72
- return cachedTask.promise;
73
- } else if (buffer.byteLength === 0) {
74
- // Technically, it would be possible to wait for the previous task to complete,
75
- // transfer the buffer back, and decode again with the second configuration. That
76
- // is complex, and I don't know of any reason to decode a Draco buffer twice in
77
- // different ways, so this is left unimplemented.
78
- throw new Error('THREE.DRACOLoader: Unable to re-decode a buffer with different ' + 'settings. Buffer has already been transferred.');
79
- }
80
- }
81
-
82
- //
83
-
84
- let worker;
85
- const taskID = this.workerNextTaskID++;
86
- const taskCost = buffer.byteLength;
87
-
88
- // Obtain a worker and assign a task, and construct a geometry instance
89
- // when the task completes.
90
- const geometryPending = this._getWorker(taskID, taskCost).then(_worker => {
91
- worker = _worker;
92
- return new Promise((resolve, reject) => {
93
- worker._callbacks[taskID] = {
94
- resolve,
95
- reject
96
- };
97
- worker.postMessage({
98
- type: 'decode',
99
- id: taskID,
100
- taskConfig,
101
- buffer
102
- }, [buffer]);
103
-
104
- // this.debug();
105
- });
106
- }).then(message => this._createGeometry(message.geometry));
107
-
108
- // Remove task from the task list.
109
- // Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)
110
- geometryPending.catch(() => true).then(() => {
111
- if (worker && taskID) {
112
- this._releaseTask(worker, taskID);
113
-
114
- // this.debug();
115
- }
116
- });
117
-
118
- // Cache the task result.
119
- _taskCache.set(buffer, {
120
- key: taskKey,
121
- promise: geometryPending
122
- });
123
- return geometryPending;
124
- }
125
- _createGeometry(geometryData) {
126
- const geometry = new BufferGeometry();
127
- if (geometryData.index) {
128
- geometry.setIndex(new BufferAttribute(geometryData.index.array, 1));
129
- }
130
- for (let i = 0; i < geometryData.attributes.length; i++) {
131
- const result = geometryData.attributes[i];
132
- const name = result.name;
133
- const array = result.array;
134
- const itemSize = result.itemSize;
135
- const attribute = new BufferAttribute(array, itemSize);
136
- if (name === 'color') {
137
- this._assignVertexColorSpace(attribute, result.vertexColorSpace);
138
- attribute.normalized = array instanceof Float32Array === false;
139
- }
140
- geometry.setAttribute(name, attribute);
141
- }
142
- return geometry;
143
- }
144
- _assignVertexColorSpace(attribute, inputColorSpace) {
145
- // While .drc files do not specify colorspace, the only 'official' tooling
146
- // is PLY and OBJ converters, which use sRGB. We'll assume sRGB when a .drc
147
- // file is passed into .load() or .parse(). GLTFLoader uses internal APIs
148
- // to decode geometry, and vertex colors are already Linear-sRGB in there.
149
-
150
- if (inputColorSpace !== SRGBColorSpace) return;
151
- const _color = new Color();
152
- for (let i = 0, il = attribute.count; i < il; i++) {
153
- _color.fromBufferAttribute(attribute, i).convertSRGBToLinear();
154
- attribute.setXYZ(i, _color.r, _color.g, _color.b);
155
- }
156
- }
157
- _loadLibrary(url, responseType) {
158
- const loader = new FileLoader(this.manager);
159
- loader.setPath(this.decoderPath);
160
- loader.setResponseType(responseType);
161
- loader.setWithCredentials(this.withCredentials);
162
- return new Promise((resolve, reject) => {
163
- loader.load(url, resolve, undefined, reject);
164
- });
165
- }
166
- preload() {
167
- this._initDecoder();
168
- return this;
169
- }
170
- _initDecoder() {
171
- if (this.decoderPending) return this.decoderPending;
172
- const useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
173
- const librariesPending = [];
174
- if (useJS) {
175
- librariesPending.push(this._loadLibrary('draco_decoder.js', 'text'));
176
- } else {
177
- librariesPending.push(this._loadLibrary('draco_wasm_wrapper.js', 'text'));
178
- librariesPending.push(this._loadLibrary('draco_decoder.wasm', 'arraybuffer'));
179
- }
180
- this.decoderPending = Promise.all(librariesPending).then(libraries => {
181
- const jsContent = libraries[0];
182
- if (!useJS) {
183
- this.decoderConfig.wasmBinary = libraries[1];
184
- }
185
- const fn = DRACOWorker.toString();
186
- const body = ['/* draco decoder */', jsContent, '', '/* worker */', fn.substring(fn.indexOf('{') + 1, fn.lastIndexOf('}'))].join('\n');
187
- this.workerSourceURL = URL.createObjectURL(new Blob([body]));
188
- });
189
- return this.decoderPending;
190
- }
191
- _getWorker(taskID, taskCost) {
192
- return this._initDecoder().then(() => {
193
- if (this.workerPool.length < this.workerLimit) {
194
- const worker = new Worker(this.workerSourceURL);
195
- worker._callbacks = {};
196
- worker._taskCosts = {};
197
- worker._taskLoad = 0;
198
- worker.postMessage({
199
- type: 'init',
200
- decoderConfig: this.decoderConfig
201
- });
202
- worker.onmessage = function (e) {
203
- const message = e.data;
204
- switch (message.type) {
205
- case 'decode':
206
- worker._callbacks[message.id].resolve(message);
207
- break;
208
- case 'error':
209
- worker._callbacks[message.id].reject(message);
210
- break;
211
- default:
212
- console.error('THREE.DRACOLoader: Unexpected message, "' + message.type + '"');
213
- }
214
- };
215
- this.workerPool.push(worker);
216
- } else {
217
- this.workerPool.sort(function (a, b) {
218
- return a._taskLoad > b._taskLoad ? -1 : 1;
219
- });
220
- }
221
- const worker = this.workerPool[this.workerPool.length - 1];
222
- worker._taskCosts[taskID] = taskCost;
223
- worker._taskLoad += taskCost;
224
- return worker;
225
- });
226
- }
227
- _releaseTask(worker, taskID) {
228
- worker._taskLoad -= worker._taskCosts[taskID];
229
- delete worker._callbacks[taskID];
230
- delete worker._taskCosts[taskID];
231
- }
232
- debug() {
233
- console.log('Task load: ', this.workerPool.map(worker => worker._taskLoad));
234
- }
235
- dispose() {
236
- for (let i = 0; i < this.workerPool.length; ++i) {
237
- this.workerPool[i].terminate();
238
- }
239
- this.workerPool.length = 0;
240
- if (this.workerSourceURL !== '') {
241
- URL.revokeObjectURL(this.workerSourceURL);
242
- }
243
- return this;
244
- }
245
- }
246
-
247
- /* WEB WORKER */
248
-
249
- function DRACOWorker() {
250
- let decoderConfig;
251
- let decoderPending;
252
- onmessage = function (e) {
253
- const message = e.data;
254
- switch (message.type) {
255
- case 'init':
256
- decoderConfig = message.decoderConfig;
257
- decoderPending = new Promise(function (resolve /*, reject*/) {
258
- decoderConfig.onModuleLoaded = function (draco) {
259
- // Module is Promise-like. Wrap before resolving to avoid loop.
260
- resolve({
261
- draco: draco
262
- });
263
- };
264
- DracoDecoderModule(decoderConfig); // eslint-disable-line no-undef
265
- });
266
- break;
267
- case 'decode':
268
- const buffer = message.buffer;
269
- const taskConfig = message.taskConfig;
270
- decoderPending.then(module => {
271
- const draco = module.draco;
272
- const decoder = new draco.Decoder();
273
- try {
274
- const geometry = decodeGeometry(draco, decoder, new Int8Array(buffer), taskConfig);
275
- const buffers = geometry.attributes.map(attr => attr.array.buffer);
276
- if (geometry.index) buffers.push(geometry.index.array.buffer);
277
- self.postMessage({
278
- type: 'decode',
279
- id: message.id,
280
- geometry
281
- }, buffers);
282
- } catch (error) {
283
- console.error(error);
284
- self.postMessage({
285
- type: 'error',
286
- id: message.id,
287
- error: error.message
288
- });
289
- } finally {
290
- draco.destroy(decoder);
291
- }
292
- });
293
- break;
294
- }
295
- };
296
- function decodeGeometry(draco, decoder, array, taskConfig) {
297
- const attributeIDs = taskConfig.attributeIDs;
298
- const attributeTypes = taskConfig.attributeTypes;
299
- let dracoGeometry;
300
- let decodingStatus;
301
- const geometryType = decoder.GetEncodedGeometryType(array);
302
- if (geometryType === draco.TRIANGULAR_MESH) {
303
- dracoGeometry = new draco.Mesh();
304
- decodingStatus = decoder.DecodeArrayToMesh(array, array.byteLength, dracoGeometry);
305
- } else if (geometryType === draco.POINT_CLOUD) {
306
- dracoGeometry = new draco.PointCloud();
307
- decodingStatus = decoder.DecodeArrayToPointCloud(array, array.byteLength, dracoGeometry);
308
- } else {
309
- throw new Error('THREE.DRACOLoader: Unexpected geometry type.');
310
- }
311
- if (!decodingStatus.ok() || dracoGeometry.ptr === 0) {
312
- throw new Error('THREE.DRACOLoader: Decoding failed: ' + decodingStatus.error_msg());
313
- }
314
- const geometry = {
315
- index: null,
316
- attributes: []
317
- };
318
-
319
- // Gather all vertex attributes.
320
- for (const attributeName in attributeIDs) {
321
- const attributeType = self[attributeTypes[attributeName]];
322
- let attribute;
323
- let attributeID;
324
-
325
- // A Draco file may be created with default vertex attributes, whose attribute IDs
326
- // are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
327
- // a Draco file may contain a custom set of attributes, identified by known unique
328
- // IDs. glTF files always do the latter, and `.drc` files typically do the former.
329
- if (taskConfig.useUniqueIDs) {
330
- attributeID = attributeIDs[attributeName];
331
- attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeID);
332
- } else {
333
- attributeID = decoder.GetAttributeId(dracoGeometry, draco[attributeIDs[attributeName]]);
334
- if (attributeID === -1) continue;
335
- attribute = decoder.GetAttribute(dracoGeometry, attributeID);
336
- }
337
- const attributeResult = decodeAttribute(draco, decoder, dracoGeometry, attributeName, attributeType, attribute);
338
- if (attributeName === 'color') {
339
- attributeResult.vertexColorSpace = taskConfig.vertexColorSpace;
340
- }
341
- geometry.attributes.push(attributeResult);
342
- }
343
-
344
- // Add index.
345
- if (geometryType === draco.TRIANGULAR_MESH) {
346
- geometry.index = decodeIndex(draco, decoder, dracoGeometry);
347
- }
348
- draco.destroy(dracoGeometry);
349
- return geometry;
350
- }
351
- function decodeIndex(draco, decoder, dracoGeometry) {
352
- const numFaces = dracoGeometry.num_faces();
353
- const numIndices = numFaces * 3;
354
- const byteLength = numIndices * 4;
355
- const ptr = draco._malloc(byteLength);
356
- decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
357
- const index = new Uint32Array(draco.HEAPF32.buffer, ptr, numIndices).slice();
358
- draco._free(ptr);
359
- return {
360
- array: index,
361
- itemSize: 1
362
- };
363
- }
364
- function decodeAttribute(draco, decoder, dracoGeometry, attributeName, attributeType, attribute) {
365
- const numComponents = attribute.num_components();
366
- const numPoints = dracoGeometry.num_points();
367
- const numValues = numPoints * numComponents;
368
- const byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
369
- const dataType = getDracoDataType(draco, attributeType);
370
- const ptr = draco._malloc(byteLength);
371
- decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, attribute, dataType, byteLength, ptr);
372
- const array = new attributeType(draco.HEAPF32.buffer, ptr, numValues).slice();
373
- draco._free(ptr);
374
- return {
375
- name: attributeName,
376
- array: array,
377
- itemSize: numComponents
378
- };
379
- }
380
- function getDracoDataType(draco, attributeType) {
381
- switch (attributeType) {
382
- case Float32Array:
383
- return draco.DT_FLOAT32;
384
- case Int8Array:
385
- return draco.DT_INT8;
386
- case Int16Array:
387
- return draco.DT_INT16;
388
- case Int32Array:
389
- return draco.DT_INT32;
390
- case Uint8Array:
391
- return draco.DT_UINT8;
392
- case Uint16Array:
393
- return draco.DT_UINT16;
394
- case Uint32Array:
395
- return draco.DT_UINT32;
396
- }
397
- }
398
- }
399
- export { DRACOLoader };