itowns 2.45.1-next.0 → 2.45.1-next.1
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.
- package/dist/455.js +2 -0
- package/dist/455.js.map +1 -0
- package/dist/debug.js +3 -0
- package/dist/debug.js.LICENSE.txt +13 -0
- package/dist/debug.js.map +1 -0
- package/dist/itowns.js +3 -0
- package/dist/itowns.js.LICENSE.txt +5 -0
- package/dist/itowns.js.map +1 -0
- package/dist/itowns_lasparser.js +2 -0
- package/dist/itowns_lasparser.js.map +1 -0
- package/dist/itowns_lasworker.js +2 -0
- package/dist/itowns_lasworker.js.map +1 -0
- package/dist/itowns_potree2worker.js +2 -0
- package/dist/itowns_potree2worker.js.map +1 -0
- package/dist/itowns_widgets.js +2 -0
- package/dist/itowns_widgets.js.map +1 -0
- package/lib/Controls/FirstPersonControls.js +308 -0
- package/lib/Controls/FlyControls.js +175 -0
- package/lib/Controls/GlobeControls.js +1178 -0
- package/lib/Controls/PlanarControls.js +1025 -0
- package/lib/Controls/StateControl.js +432 -0
- package/lib/Controls/StreetControls.js +392 -0
- package/lib/Converter/Feature2Mesh.js +612 -0
- package/lib/Converter/Feature2Texture.js +174 -0
- package/lib/Converter/convertToTile.js +70 -0
- package/lib/Converter/textureConverter.js +43 -0
- package/lib/Core/3DTiles/C3DTBatchTable.js +131 -0
- package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +96 -0
- package/lib/Core/3DTiles/C3DTBoundingVolume.js +156 -0
- package/lib/Core/3DTiles/C3DTExtensions.js +97 -0
- package/lib/Core/3DTiles/C3DTFeature.js +110 -0
- package/lib/Core/3DTiles/C3DTilesEnums.js +20 -0
- package/lib/Core/3DTiles/C3DTileset.js +99 -0
- package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +100 -0
- package/lib/Core/AnimationPlayer.js +142 -0
- package/lib/Core/CopcNode.js +174 -0
- package/lib/Core/Deprecated/Undeprecator.js +74 -0
- package/lib/Core/EntwinePointTileNode.js +126 -0
- package/lib/Core/Feature.js +488 -0
- package/lib/Core/Geographic/GeoidGrid.js +108 -0
- package/lib/Core/Label.js +222 -0
- package/lib/Core/MainLoop.js +209 -0
- package/lib/Core/Picking.js +255 -0
- package/lib/Core/PointCloudNode.js +42 -0
- package/lib/Core/Potree2Node.js +206 -0
- package/lib/Core/Potree2PointAttributes.js +139 -0
- package/lib/Core/PotreeNode.js +101 -0
- package/lib/Core/Prefab/Globe/Atmosphere.js +293 -0
- package/lib/Core/Prefab/Globe/GlobeLayer.js +152 -0
- package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +110 -0
- package/lib/Core/Prefab/Globe/SkyShader.js +78 -0
- package/lib/Core/Prefab/GlobeView.js +155 -0
- package/lib/Core/Prefab/Planar/PlanarLayer.js +59 -0
- package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +71 -0
- package/lib/Core/Prefab/PlanarView.js +62 -0
- package/lib/Core/Prefab/TileBuilder.js +82 -0
- package/lib/Core/Prefab/computeBufferTileGeometry.js +248 -0
- package/lib/Core/Scheduler/Cache.js +17 -0
- package/lib/Core/Scheduler/CancelledCommandException.js +15 -0
- package/lib/Core/Scheduler/Scheduler.js +294 -0
- package/lib/Core/Style.js +660 -0
- package/lib/Core/StyleOptions.js +486 -0
- package/lib/Core/System/Capabilities.js +63 -0
- package/lib/Core/Tile/Tile.js +205 -0
- package/lib/Core/Tile/TileGrid.js +49 -0
- package/lib/Core/TileGeometry.js +124 -0
- package/lib/Core/TileMesh.js +108 -0
- package/lib/Core/View.js +1115 -0
- package/lib/Layer/C3DTilesLayer.js +459 -0
- package/lib/Layer/ColorLayer.js +154 -0
- package/lib/Layer/CopcLayer.js +63 -0
- package/lib/Layer/ElevationLayer.js +139 -0
- package/lib/Layer/EntwinePointTileLayer.js +71 -0
- package/lib/Layer/FeatureGeometryLayer.js +77 -0
- package/lib/Layer/GeoidLayer.js +80 -0
- package/lib/Layer/GeometryLayer.js +233 -0
- package/lib/Layer/InfoLayer.js +64 -0
- package/lib/Layer/LabelLayer.js +469 -0
- package/lib/Layer/Layer.js +335 -0
- package/lib/Layer/LayerUpdateState.js +89 -0
- package/lib/Layer/LayerUpdateStrategy.js +80 -0
- package/lib/Layer/OGC3DTilesLayer.js +543 -0
- package/lib/Layer/OrientedImageLayer.js +227 -0
- package/lib/Layer/PointCloudLayer.js +405 -0
- package/lib/Layer/Potree2Layer.js +171 -0
- package/lib/Layer/PotreeLayer.js +72 -0
- package/lib/Layer/RasterLayer.js +37 -0
- package/lib/Layer/ReferencingLayerProperties.js +62 -0
- package/lib/Layer/TiledGeometryLayer.js +459 -0
- package/lib/Loader/LASLoader.js +193 -0
- package/lib/Loader/Potree2BrotliLoader.js +261 -0
- package/lib/Loader/Potree2Loader.js +207 -0
- package/lib/Main.js +113 -0
- package/lib/MainBundle.js +4 -0
- package/lib/Parser/B3dmParser.js +174 -0
- package/lib/Parser/CameraCalibrationParser.js +94 -0
- package/lib/Parser/GDFParser.js +72 -0
- package/lib/Parser/GTXParser.js +75 -0
- package/lib/Parser/GeoJsonParser.js +212 -0
- package/lib/Parser/GpxParser.js +25 -0
- package/lib/Parser/ISGParser.js +71 -0
- package/lib/Parser/KMLParser.js +25 -0
- package/lib/Parser/LASParser.js +137 -0
- package/lib/Parser/MapBoxUrlParser.js +83 -0
- package/lib/Parser/PntsParser.js +131 -0
- package/lib/Parser/Potree2BinParser.js +92 -0
- package/lib/Parser/PotreeBinParser.js +106 -0
- package/lib/Parser/PotreeCinParser.js +29 -0
- package/lib/Parser/ShapefileParser.js +78 -0
- package/lib/Parser/VectorTileParser.js +215 -0
- package/lib/Parser/XbilParser.js +120 -0
- package/lib/Parser/deprecated/LegacyGLTFLoader.js +1386 -0
- package/lib/Parser/iGLTFLoader.js +168 -0
- package/lib/Process/3dTilesProcessing.js +304 -0
- package/lib/Process/FeatureProcessing.js +76 -0
- package/lib/Process/LayeredMaterialNodeProcessing.js +229 -0
- package/lib/Process/ObjectRemovalHelper.js +97 -0
- package/lib/Process/handlerNodeError.js +23 -0
- package/lib/Provider/3dTilesProvider.js +149 -0
- package/lib/Provider/DataSourceProvider.js +24 -0
- package/lib/Provider/Fetcher.js +233 -0
- package/lib/Provider/PointCloudProvider.js +45 -0
- package/lib/Provider/TileProvider.js +16 -0
- package/lib/Provider/URLBuilder.js +116 -0
- package/lib/Renderer/Camera.js +281 -0
- package/lib/Renderer/Color.js +56 -0
- package/lib/Renderer/ColorLayersOrdering.js +115 -0
- package/lib/Renderer/CommonMaterial.js +31 -0
- package/lib/Renderer/Label2DRenderer.js +192 -0
- package/lib/Renderer/LayeredMaterial.js +243 -0
- package/lib/Renderer/OBB.js +150 -0
- package/lib/Renderer/OrientedImageCamera.js +118 -0
- package/lib/Renderer/OrientedImageMaterial.js +167 -0
- package/lib/Renderer/PointsMaterial.js +485 -0
- package/lib/Renderer/RasterTile.js +243 -0
- package/lib/Renderer/RenderMode.js +31 -0
- package/lib/Renderer/Shader/ShaderChunk.js +160 -0
- package/lib/Renderer/Shader/ShaderUtils.js +47 -0
- package/lib/Renderer/SphereHelper.js +17 -0
- package/lib/Renderer/WebXR.js +51 -0
- package/lib/Renderer/c3DEngine.js +214 -0
- package/lib/Source/C3DTilesGoogleSource.js +74 -0
- package/lib/Source/C3DTilesIonSource.js +54 -0
- package/lib/Source/C3DTilesSource.js +30 -0
- package/lib/Source/CopcSource.js +126 -0
- package/lib/Source/EntwinePointTileSource.js +72 -0
- package/lib/Source/FileSource.js +188 -0
- package/lib/Source/OGC3DTilesGoogleSource.js +29 -0
- package/lib/Source/OGC3DTilesIonSource.js +34 -0
- package/lib/Source/OGC3DTilesSource.js +21 -0
- package/lib/Source/OrientedImageSource.js +59 -0
- package/lib/Source/Potree2Source.js +167 -0
- package/lib/Source/PotreeSource.js +82 -0
- package/lib/Source/Source.js +202 -0
- package/lib/Source/TMSSource.js +144 -0
- package/lib/Source/VectorTilesSource.js +182 -0
- package/lib/Source/WFSSource.js +170 -0
- package/lib/Source/WMSSource.js +167 -0
- package/lib/Source/WMTSSource.js +92 -0
- package/lib/ThreeExtended/capabilities/WebGL.js +69 -0
- package/lib/ThreeExtended/libs/ktx-parse.module.js +506 -0
- package/lib/ThreeExtended/libs/zstddec.module.js +29 -0
- package/lib/ThreeExtended/loaders/DDSLoader.js +200 -0
- package/lib/ThreeExtended/loaders/DRACOLoader.js +400 -0
- package/lib/ThreeExtended/loaders/GLTFLoader.js +2879 -0
- package/lib/ThreeExtended/loaders/KTX2Loader.js +709 -0
- package/lib/ThreeExtended/math/ColorSpaces.js +59 -0
- package/lib/ThreeExtended/utils/BufferGeometryUtils.js +846 -0
- package/lib/ThreeExtended/utils/WorkerPool.js +70 -0
- package/lib/Utils/CameraUtils.js +554 -0
- package/lib/Utils/DEMUtils.js +350 -0
- package/lib/Utils/FeaturesUtils.js +156 -0
- package/lib/Utils/Gradients.js +16 -0
- package/lib/Utils/ThreeUtils.js +115 -0
- package/lib/Utils/gui/C3DTilesStyle.js +218 -0
- package/lib/Utils/gui/Main.js +7 -0
- package/lib/Utils/gui/Minimap.js +152 -0
- package/lib/Utils/gui/Navigation.js +245 -0
- package/lib/Utils/gui/Scale.js +104 -0
- package/lib/Utils/gui/Searchbar.js +234 -0
- package/lib/Utils/gui/Widget.js +80 -0
- package/lib/Utils/placeObjectOnGround.js +136 -0
- package/lib/Worker/LASLoaderWorker.js +19 -0
- package/lib/Worker/Potree2Worker.js +21 -0
- package/package.json +2 -2
|
@@ -0,0 +1,200 @@
|
|
|
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 };
|
|
@@ -0,0 +1,400 @@
|
|
|
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 };
|