itowns 2.44.3-next.40 → 2.44.3-next.42

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 (199) hide show
  1. package/README.md +3 -129
  2. package/package.json +16 -72
  3. package/CODING.md +0 -120
  4. package/CONTRIBUTING.md +0 -150
  5. package/CONTRIBUTORS.md +0 -56
  6. package/LICENSE.md +0 -44
  7. package/changelog.md +0 -1361
  8. package/dist/455.js +0 -2
  9. package/dist/455.js.map +0 -1
  10. package/dist/debug.js +0 -3
  11. package/dist/debug.js.LICENSE.txt +0 -13
  12. package/dist/debug.js.map +0 -1
  13. package/dist/itowns.js +0 -3
  14. package/dist/itowns.js.LICENSE.txt +0 -5
  15. package/dist/itowns.js.map +0 -1
  16. package/dist/itowns_lasparser.js +0 -2
  17. package/dist/itowns_lasparser.js.map +0 -1
  18. package/dist/itowns_lasworker.js +0 -2
  19. package/dist/itowns_lasworker.js.map +0 -1
  20. package/dist/itowns_potree2worker.js +0 -2
  21. package/dist/itowns_potree2worker.js.map +0 -1
  22. package/dist/itowns_widgets.js +0 -2
  23. package/dist/itowns_widgets.js.map +0 -1
  24. package/examples/.eslintrc.cjs +0 -35
  25. package/examples/jsm/.eslintrc.cjs +0 -38
  26. package/lib/Controls/FirstPersonControls.js +0 -308
  27. package/lib/Controls/FlyControls.js +0 -175
  28. package/lib/Controls/GlobeControls.js +0 -1179
  29. package/lib/Controls/PlanarControls.js +0 -1025
  30. package/lib/Controls/StateControl.js +0 -432
  31. package/lib/Controls/StreetControls.js +0 -392
  32. package/lib/Converter/Feature2Mesh.js +0 -614
  33. package/lib/Converter/Feature2Texture.js +0 -175
  34. package/lib/Converter/convertToTile.js +0 -70
  35. package/lib/Converter/textureConverter.js +0 -43
  36. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  37. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  38. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  39. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  40. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  41. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  42. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  43. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  44. package/lib/Core/AnimationPlayer.js +0 -142
  45. package/lib/Core/CopcNode.js +0 -174
  46. package/lib/Core/Deprecated/Undeprecator.js +0 -74
  47. package/lib/Core/EntwinePointTileNode.js +0 -126
  48. package/lib/Core/Feature.js +0 -489
  49. package/lib/Core/Geographic/CoordStars.js +0 -80
  50. package/lib/Core/Geographic/Coordinates.js +0 -331
  51. package/lib/Core/Geographic/Crs.js +0 -170
  52. package/lib/Core/Geographic/Extent.js +0 -550
  53. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  54. package/lib/Core/Label.js +0 -222
  55. package/lib/Core/MainLoop.js +0 -209
  56. package/lib/Core/Math/Ellipsoid.js +0 -185
  57. package/lib/Core/Picking.js +0 -255
  58. package/lib/Core/PointCloudNode.js +0 -42
  59. package/lib/Core/Potree2Node.js +0 -206
  60. package/lib/Core/Potree2PointAttributes.js +0 -139
  61. package/lib/Core/PotreeNode.js +0 -101
  62. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -295
  63. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -152
  64. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +0 -111
  65. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  66. package/lib/Core/Prefab/GlobeView.js +0 -156
  67. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -59
  68. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  69. package/lib/Core/Prefab/PlanarView.js +0 -62
  70. package/lib/Core/Prefab/TileBuilder.js +0 -82
  71. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -248
  72. package/lib/Core/Scheduler/Cache.js +0 -17
  73. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  74. package/lib/Core/Scheduler/Scheduler.js +0 -294
  75. package/lib/Core/Style.js +0 -660
  76. package/lib/Core/StyleOptions.js +0 -486
  77. package/lib/Core/System/Capabilities.js +0 -63
  78. package/lib/Core/Tile/Tile.js +0 -207
  79. package/lib/Core/Tile/TileGrid.js +0 -49
  80. package/lib/Core/TileGeometry.js +0 -124
  81. package/lib/Core/TileMesh.js +0 -108
  82. package/lib/Core/View.js +0 -1116
  83. package/lib/Layer/C3DTilesLayer.js +0 -459
  84. package/lib/Layer/ColorLayer.js +0 -154
  85. package/lib/Layer/CopcLayer.js +0 -63
  86. package/lib/Layer/ElevationLayer.js +0 -139
  87. package/lib/Layer/EntwinePointTileLayer.js +0 -71
  88. package/lib/Layer/FeatureGeometryLayer.js +0 -77
  89. package/lib/Layer/GeoidLayer.js +0 -80
  90. package/lib/Layer/GeometryLayer.js +0 -233
  91. package/lib/Layer/InfoLayer.js +0 -64
  92. package/lib/Layer/LabelLayer.js +0 -470
  93. package/lib/Layer/Layer.js +0 -335
  94. package/lib/Layer/LayerUpdateState.js +0 -89
  95. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  96. package/lib/Layer/OGC3DTilesLayer.js +0 -543
  97. package/lib/Layer/OrientedImageLayer.js +0 -228
  98. package/lib/Layer/PointCloudLayer.js +0 -405
  99. package/lib/Layer/Potree2Layer.js +0 -171
  100. package/lib/Layer/PotreeLayer.js +0 -72
  101. package/lib/Layer/RasterLayer.js +0 -37
  102. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  103. package/lib/Layer/TiledGeometryLayer.js +0 -459
  104. package/lib/Loader/LASLoader.js +0 -193
  105. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  106. package/lib/Loader/Potree2Loader.js +0 -207
  107. package/lib/Main.js +0 -115
  108. package/lib/MainBundle.js +0 -4
  109. package/lib/Parser/B3dmParser.js +0 -174
  110. package/lib/Parser/CameraCalibrationParser.js +0 -94
  111. package/lib/Parser/GDFParser.js +0 -72
  112. package/lib/Parser/GTXParser.js +0 -75
  113. package/lib/Parser/GeoJsonParser.js +0 -212
  114. package/lib/Parser/GpxParser.js +0 -25
  115. package/lib/Parser/ISGParser.js +0 -71
  116. package/lib/Parser/KMLParser.js +0 -25
  117. package/lib/Parser/LASParser.js +0 -137
  118. package/lib/Parser/MapBoxUrlParser.js +0 -83
  119. package/lib/Parser/PntsParser.js +0 -131
  120. package/lib/Parser/Potree2BinParser.js +0 -92
  121. package/lib/Parser/PotreeBinParser.js +0 -106
  122. package/lib/Parser/PotreeCinParser.js +0 -29
  123. package/lib/Parser/ShapefileParser.js +0 -78
  124. package/lib/Parser/VectorTileParser.js +0 -215
  125. package/lib/Parser/XbilParser.js +0 -120
  126. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  127. package/lib/Parser/iGLTFLoader.js +0 -168
  128. package/lib/Process/3dTilesProcessing.js +0 -304
  129. package/lib/Process/FeatureProcessing.js +0 -76
  130. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  131. package/lib/Process/ObjectRemovalHelper.js +0 -97
  132. package/lib/Process/handlerNodeError.js +0 -23
  133. package/lib/Provider/3dTilesProvider.js +0 -149
  134. package/lib/Provider/DataSourceProvider.js +0 -8
  135. package/lib/Provider/Fetcher.js +0 -233
  136. package/lib/Provider/PointCloudProvider.js +0 -45
  137. package/lib/Provider/TileProvider.js +0 -16
  138. package/lib/Provider/URLBuilder.js +0 -116
  139. package/lib/Renderer/Camera.js +0 -281
  140. package/lib/Renderer/Color.js +0 -56
  141. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  142. package/lib/Renderer/CommonMaterial.js +0 -31
  143. package/lib/Renderer/Label2DRenderer.js +0 -192
  144. package/lib/Renderer/LayeredMaterial.js +0 -243
  145. package/lib/Renderer/OBB.js +0 -151
  146. package/lib/Renderer/OrientedImageCamera.js +0 -118
  147. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  148. package/lib/Renderer/PointsMaterial.js +0 -485
  149. package/lib/Renderer/RasterTile.js +0 -208
  150. package/lib/Renderer/RenderMode.js +0 -31
  151. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  152. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  153. package/lib/Renderer/SphereHelper.js +0 -17
  154. package/lib/Renderer/WebXR.js +0 -51
  155. package/lib/Renderer/c3DEngine.js +0 -214
  156. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  157. package/lib/Source/C3DTilesIonSource.js +0 -54
  158. package/lib/Source/C3DTilesSource.js +0 -30
  159. package/lib/Source/CopcSource.js +0 -126
  160. package/lib/Source/EntwinePointTileSource.js +0 -72
  161. package/lib/Source/FileSource.js +0 -188
  162. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  163. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  164. package/lib/Source/OGC3DTilesSource.js +0 -21
  165. package/lib/Source/OrientedImageSource.js +0 -59
  166. package/lib/Source/Potree2Source.js +0 -167
  167. package/lib/Source/PotreeSource.js +0 -82
  168. package/lib/Source/Source.js +0 -203
  169. package/lib/Source/TMSSource.js +0 -144
  170. package/lib/Source/VectorTilesSource.js +0 -182
  171. package/lib/Source/WFSSource.js +0 -170
  172. package/lib/Source/WMSSource.js +0 -168
  173. package/lib/Source/WMTSSource.js +0 -92
  174. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  175. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -506
  176. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  177. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  178. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -400
  179. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2879
  180. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -709
  181. package/lib/ThreeExtended/math/ColorSpaces.js +0 -59
  182. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  183. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  184. package/lib/Utils/CameraUtils.js +0 -555
  185. package/lib/Utils/DEMUtils.js +0 -350
  186. package/lib/Utils/FeaturesUtils.js +0 -156
  187. package/lib/Utils/Gradients.js +0 -16
  188. package/lib/Utils/OrientationUtils.js +0 -457
  189. package/lib/Utils/ThreeUtils.js +0 -115
  190. package/lib/Utils/gui/C3DTilesStyle.js +0 -215
  191. package/lib/Utils/gui/Main.js +0 -7
  192. package/lib/Utils/gui/Minimap.js +0 -154
  193. package/lib/Utils/gui/Navigation.js +0 -245
  194. package/lib/Utils/gui/Scale.js +0 -107
  195. package/lib/Utils/gui/Searchbar.js +0 -234
  196. package/lib/Utils/gui/Widget.js +0 -80
  197. package/lib/Utils/placeObjectOnGround.js +0 -136
  198. package/lib/Worker/LASLoaderWorker.js +0 -19
  199. 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,400 +0,0 @@
1
- import { BufferAttribute, BufferGeometry, Color, ColorManagement, 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);
154
- ColorManagement.toWorkingColorSpace(_color, SRGBColorSpace);
155
- attribute.setXYZ(i, _color.r, _color.g, _color.b);
156
- }
157
- }
158
- _loadLibrary(url, responseType) {
159
- const loader = new FileLoader(this.manager);
160
- loader.setPath(this.decoderPath);
161
- loader.setResponseType(responseType);
162
- loader.setWithCredentials(this.withCredentials);
163
- return new Promise((resolve, reject) => {
164
- loader.load(url, resolve, undefined, reject);
165
- });
166
- }
167
- preload() {
168
- this._initDecoder();
169
- return this;
170
- }
171
- _initDecoder() {
172
- if (this.decoderPending) return this.decoderPending;
173
- const useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
174
- const librariesPending = [];
175
- if (useJS) {
176
- librariesPending.push(this._loadLibrary('draco_decoder.js', 'text'));
177
- } else {
178
- librariesPending.push(this._loadLibrary('draco_wasm_wrapper.js', 'text'));
179
- librariesPending.push(this._loadLibrary('draco_decoder.wasm', 'arraybuffer'));
180
- }
181
- this.decoderPending = Promise.all(librariesPending).then(libraries => {
182
- const jsContent = libraries[0];
183
- if (!useJS) {
184
- this.decoderConfig.wasmBinary = libraries[1];
185
- }
186
- const fn = DRACOWorker.toString();
187
- const body = ['/* draco decoder */', jsContent, '', '/* worker */', fn.substring(fn.indexOf('{') + 1, fn.lastIndexOf('}'))].join('\n');
188
- this.workerSourceURL = URL.createObjectURL(new Blob([body]));
189
- });
190
- return this.decoderPending;
191
- }
192
- _getWorker(taskID, taskCost) {
193
- return this._initDecoder().then(() => {
194
- if (this.workerPool.length < this.workerLimit) {
195
- const worker = new Worker(this.workerSourceURL);
196
- worker._callbacks = {};
197
- worker._taskCosts = {};
198
- worker._taskLoad = 0;
199
- worker.postMessage({
200
- type: 'init',
201
- decoderConfig: this.decoderConfig
202
- });
203
- worker.onmessage = function (e) {
204
- const message = e.data;
205
- switch (message.type) {
206
- case 'decode':
207
- worker._callbacks[message.id].resolve(message);
208
- break;
209
- case 'error':
210
- worker._callbacks[message.id].reject(message);
211
- break;
212
- default:
213
- console.error('THREE.DRACOLoader: Unexpected message, "' + message.type + '"');
214
- }
215
- };
216
- this.workerPool.push(worker);
217
- } else {
218
- this.workerPool.sort(function (a, b) {
219
- return a._taskLoad > b._taskLoad ? -1 : 1;
220
- });
221
- }
222
- const worker = this.workerPool[this.workerPool.length - 1];
223
- worker._taskCosts[taskID] = taskCost;
224
- worker._taskLoad += taskCost;
225
- return worker;
226
- });
227
- }
228
- _releaseTask(worker, taskID) {
229
- worker._taskLoad -= worker._taskCosts[taskID];
230
- delete worker._callbacks[taskID];
231
- delete worker._taskCosts[taskID];
232
- }
233
- debug() {
234
- console.log('Task load: ', this.workerPool.map(worker => worker._taskLoad));
235
- }
236
- dispose() {
237
- for (let i = 0; i < this.workerPool.length; ++i) {
238
- this.workerPool[i].terminate();
239
- }
240
- this.workerPool.length = 0;
241
- if (this.workerSourceURL !== '') {
242
- URL.revokeObjectURL(this.workerSourceURL);
243
- }
244
- return this;
245
- }
246
- }
247
-
248
- /* WEB WORKER */
249
-
250
- function DRACOWorker() {
251
- let decoderConfig;
252
- let decoderPending;
253
- onmessage = function (e) {
254
- const message = e.data;
255
- switch (message.type) {
256
- case 'init':
257
- decoderConfig = message.decoderConfig;
258
- decoderPending = new Promise(function (resolve /*, reject*/) {
259
- decoderConfig.onModuleLoaded = function (draco) {
260
- // Module is Promise-like. Wrap before resolving to avoid loop.
261
- resolve({
262
- draco: draco
263
- });
264
- };
265
- DracoDecoderModule(decoderConfig); // eslint-disable-line no-undef
266
- });
267
- break;
268
- case 'decode':
269
- const buffer = message.buffer;
270
- const taskConfig = message.taskConfig;
271
- decoderPending.then(module => {
272
- const draco = module.draco;
273
- const decoder = new draco.Decoder();
274
- try {
275
- const geometry = decodeGeometry(draco, decoder, new Int8Array(buffer), taskConfig);
276
- const buffers = geometry.attributes.map(attr => attr.array.buffer);
277
- if (geometry.index) buffers.push(geometry.index.array.buffer);
278
- self.postMessage({
279
- type: 'decode',
280
- id: message.id,
281
- geometry
282
- }, buffers);
283
- } catch (error) {
284
- console.error(error);
285
- self.postMessage({
286
- type: 'error',
287
- id: message.id,
288
- error: error.message
289
- });
290
- } finally {
291
- draco.destroy(decoder);
292
- }
293
- });
294
- break;
295
- }
296
- };
297
- function decodeGeometry(draco, decoder, array, taskConfig) {
298
- const attributeIDs = taskConfig.attributeIDs;
299
- const attributeTypes = taskConfig.attributeTypes;
300
- let dracoGeometry;
301
- let decodingStatus;
302
- const geometryType = decoder.GetEncodedGeometryType(array);
303
- if (geometryType === draco.TRIANGULAR_MESH) {
304
- dracoGeometry = new draco.Mesh();
305
- decodingStatus = decoder.DecodeArrayToMesh(array, array.byteLength, dracoGeometry);
306
- } else if (geometryType === draco.POINT_CLOUD) {
307
- dracoGeometry = new draco.PointCloud();
308
- decodingStatus = decoder.DecodeArrayToPointCloud(array, array.byteLength, dracoGeometry);
309
- } else {
310
- throw new Error('THREE.DRACOLoader: Unexpected geometry type.');
311
- }
312
- if (!decodingStatus.ok() || dracoGeometry.ptr === 0) {
313
- throw new Error('THREE.DRACOLoader: Decoding failed: ' + decodingStatus.error_msg());
314
- }
315
- const geometry = {
316
- index: null,
317
- attributes: []
318
- };
319
-
320
- // Gather all vertex attributes.
321
- for (const attributeName in attributeIDs) {
322
- const attributeType = self[attributeTypes[attributeName]];
323
- let attribute;
324
- let attributeID;
325
-
326
- // A Draco file may be created with default vertex attributes, whose attribute IDs
327
- // are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
328
- // a Draco file may contain a custom set of attributes, identified by known unique
329
- // IDs. glTF files always do the latter, and `.drc` files typically do the former.
330
- if (taskConfig.useUniqueIDs) {
331
- attributeID = attributeIDs[attributeName];
332
- attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeID);
333
- } else {
334
- attributeID = decoder.GetAttributeId(dracoGeometry, draco[attributeIDs[attributeName]]);
335
- if (attributeID === -1) continue;
336
- attribute = decoder.GetAttribute(dracoGeometry, attributeID);
337
- }
338
- const attributeResult = decodeAttribute(draco, decoder, dracoGeometry, attributeName, attributeType, attribute);
339
- if (attributeName === 'color') {
340
- attributeResult.vertexColorSpace = taskConfig.vertexColorSpace;
341
- }
342
- geometry.attributes.push(attributeResult);
343
- }
344
-
345
- // Add index.
346
- if (geometryType === draco.TRIANGULAR_MESH) {
347
- geometry.index = decodeIndex(draco, decoder, dracoGeometry);
348
- }
349
- draco.destroy(dracoGeometry);
350
- return geometry;
351
- }
352
- function decodeIndex(draco, decoder, dracoGeometry) {
353
- const numFaces = dracoGeometry.num_faces();
354
- const numIndices = numFaces * 3;
355
- const byteLength = numIndices * 4;
356
- const ptr = draco._malloc(byteLength);
357
- decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
358
- const index = new Uint32Array(draco.HEAPF32.buffer, ptr, numIndices).slice();
359
- draco._free(ptr);
360
- return {
361
- array: index,
362
- itemSize: 1
363
- };
364
- }
365
- function decodeAttribute(draco, decoder, dracoGeometry, attributeName, attributeType, attribute) {
366
- const numComponents = attribute.num_components();
367
- const numPoints = dracoGeometry.num_points();
368
- const numValues = numPoints * numComponents;
369
- const byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
370
- const dataType = getDracoDataType(draco, attributeType);
371
- const ptr = draco._malloc(byteLength);
372
- decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, attribute, dataType, byteLength, ptr);
373
- const array = new attributeType(draco.HEAPF32.buffer, ptr, numValues).slice();
374
- draco._free(ptr);
375
- return {
376
- name: attributeName,
377
- array: array,
378
- itemSize: numComponents
379
- };
380
- }
381
- function getDracoDataType(draco, attributeType) {
382
- switch (attributeType) {
383
- case Float32Array:
384
- return draco.DT_FLOAT32;
385
- case Int8Array:
386
- return draco.DT_INT8;
387
- case Int16Array:
388
- return draco.DT_INT16;
389
- case Int32Array:
390
- return draco.DT_INT32;
391
- case Uint8Array:
392
- return draco.DT_UINT8;
393
- case Uint16Array:
394
- return draco.DT_UINT16;
395
- case Uint32Array:
396
- return draco.DT_UINT32;
397
- }
398
- }
399
- }
400
- export { DRACOLoader };