@itwin/core-frontend 3.1.0-dev.27 → 3.1.0-dev.28
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/CHANGELOG.md +156 -35
- package/lib/cjs/DrawingViewState.d.ts.map +1 -1
- package/lib/cjs/DrawingViewState.js +6 -5
- package/lib/cjs/DrawingViewState.js.map +1 -1
- package/lib/cjs/IModelApp.d.ts +1 -3
- package/lib/cjs/IModelApp.d.ts.map +1 -1
- package/lib/cjs/IModelApp.js +8 -6
- package/lib/cjs/IModelApp.js.map +1 -1
- package/lib/cjs/SheetViewState.js +4 -0
- package/lib/cjs/SheetViewState.js.map +1 -1
- package/lib/cjs/ViewState.d.ts +8 -0
- package/lib/cjs/ViewState.d.ts.map +1 -1
- package/lib/cjs/ViewState.js.map +1 -1
- package/lib/cjs/Viewport.d.ts +19 -3
- package/lib/cjs/Viewport.d.ts.map +1 -1
- package/lib/cjs/Viewport.js +20 -0
- package/lib/cjs/Viewport.js.map +1 -1
- package/lib/cjs/core-frontend.d.ts +1 -0
- package/lib/cjs/core-frontend.d.ts.map +1 -1
- package/lib/cjs/core-frontend.js +1 -0
- package/lib/cjs/core-frontend.js.map +1 -1
- package/lib/cjs/quantity-formatting/BasicUnitsProvider.d.ts +2 -2
- package/lib/cjs/quantity-formatting/BasicUnitsProvider.d.ts.map +1 -1
- package/lib/cjs/quantity-formatting/BasicUnitsProvider.js +48 -44
- package/lib/cjs/quantity-formatting/BasicUnitsProvider.js.map +1 -1
- package/lib/cjs/quantity-formatting/QuantityFormatter.d.ts +90 -80
- package/lib/cjs/quantity-formatting/QuantityFormatter.d.ts.map +1 -1
- package/lib/cjs/quantity-formatting/QuantityFormatter.js +76 -45
- package/lib/cjs/quantity-formatting/QuantityFormatter.js.map +1 -1
- package/lib/cjs/quantity-formatting/QuantityTypesEditorSpecs.d.ts +54 -0
- package/lib/cjs/quantity-formatting/QuantityTypesEditorSpecs.d.ts.map +1 -0
- package/lib/cjs/quantity-formatting/QuantityTypesEditorSpecs.js +32 -0
- package/lib/cjs/quantity-formatting/QuantityTypesEditorSpecs.js.map +1 -0
- package/lib/cjs/quantity-formatting/UnitsData.d.ts +11 -0
- package/lib/cjs/quantity-formatting/UnitsData.d.ts.map +1 -0
- package/lib/cjs/quantity-formatting/UnitsData.js +59 -0
- package/lib/cjs/quantity-formatting/UnitsData.js.map +1 -0
- package/lib/cjs/tile/PntsReader.d.ts.map +1 -1
- package/lib/cjs/tile/PntsReader.js +79 -17
- package/lib/cjs/tile/PntsReader.js.map +1 -1
- package/lib/esm/DrawingViewState.d.ts.map +1 -1
- package/lib/esm/DrawingViewState.js +6 -5
- package/lib/esm/DrawingViewState.js.map +1 -1
- package/lib/esm/IModelApp.d.ts +1 -3
- package/lib/esm/IModelApp.d.ts.map +1 -1
- package/lib/esm/IModelApp.js +8 -6
- package/lib/esm/IModelApp.js.map +1 -1
- package/lib/esm/SheetViewState.js +4 -0
- package/lib/esm/SheetViewState.js.map +1 -1
- package/lib/esm/ViewState.d.ts +8 -0
- package/lib/esm/ViewState.d.ts.map +1 -1
- package/lib/esm/ViewState.js.map +1 -1
- package/lib/esm/Viewport.d.ts +19 -3
- package/lib/esm/Viewport.d.ts.map +1 -1
- package/lib/esm/Viewport.js +20 -0
- package/lib/esm/Viewport.js.map +1 -1
- package/lib/esm/core-frontend.d.ts +1 -0
- package/lib/esm/core-frontend.d.ts.map +1 -1
- package/lib/esm/core-frontend.js +1 -0
- package/lib/esm/core-frontend.js.map +1 -1
- package/lib/esm/quantity-formatting/BasicUnitsProvider.d.ts +2 -2
- package/lib/esm/quantity-formatting/BasicUnitsProvider.d.ts.map +1 -1
- package/lib/esm/quantity-formatting/BasicUnitsProvider.js +48 -44
- package/lib/esm/quantity-formatting/BasicUnitsProvider.js.map +1 -1
- package/lib/esm/quantity-formatting/QuantityFormatter.d.ts +90 -80
- package/lib/esm/quantity-formatting/QuantityFormatter.d.ts.map +1 -1
- package/lib/esm/quantity-formatting/QuantityFormatter.js +75 -41
- package/lib/esm/quantity-formatting/QuantityFormatter.js.map +1 -1
- package/lib/esm/quantity-formatting/QuantityTypesEditorSpecs.d.ts +54 -0
- package/lib/esm/quantity-formatting/QuantityTypesEditorSpecs.d.ts.map +1 -0
- package/lib/esm/quantity-formatting/QuantityTypesEditorSpecs.js +26 -0
- package/lib/esm/quantity-formatting/QuantityTypesEditorSpecs.js.map +1 -0
- package/lib/esm/quantity-formatting/UnitsData.d.ts +11 -0
- package/lib/esm/quantity-formatting/UnitsData.d.ts.map +1 -0
- package/lib/esm/quantity-formatting/UnitsData.js +56 -0
- package/lib/esm/quantity-formatting/UnitsData.js.map +1 -0
- package/lib/esm/tile/PntsReader.d.ts.map +1 -1
- package/lib/esm/tile/PntsReader.js +79 -17
- package/lib/esm/tile/PntsReader.js.map +1 -1
- package/package.json +20 -20
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnitsData.js","sourceRoot":"","sources":["../../../src/quantity-formatting/UnitsData.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,8BAA8B;IAC9B,EAAE,IAAI,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAC,QAAQ,CAAC,EAAE;IACnD,qBAAqB;IACrB,EAAE,IAAI,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE;IACzD,EAAE,IAAI,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC,KAAK,CAAC,EAAE;IACvD,EAAE,IAAI,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC,KAAK,CAAC,EAAE;IACvD,EAAE,IAAI,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE;IAChD,4BAA4B;IAC5B,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC,KAAK,CAAC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aAAa,EAAE,gBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE;CAClD,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module QuantityFormatting\r\n */\r\n\r\n/**\r\n * Additional unit data such alternate display label not found in the Units Schema\r\n */\r\nexport const UNIT_EXTRA_DATA = [\r\n // Angles ( base unit radian )\r\n { name: \"Units.RAD\", altDisplayLabels: [\"radian\"] },\r\n // 1 rad = 180.0/PI °\r\n { name: \"Units.ARC_DEG\", altDisplayLabels: [\"deg\", \"^\"] },\r\n { name: \"Units.ARC_MINUTE\", altDisplayLabels: [\"min\"] },\r\n { name: \"Units.ARC_SECOND\", altDisplayLabels: [\"sec\"] },\r\n { name: \"Units.GRAD\", altDisplayLabels: [\"gd\"] },\r\n // Time ( base unit second )\r\n { name: \"Units.S\", altDisplayLabels: [\"sec\"] },\r\n { name: \"Units.MIN\", altDisplayLabels: [] },\r\n { name: \"Units.HR\", altDisplayLabels: [\"hr\"] },\r\n { name: \"Units.DAY\", altDisplayLabels: [\"day\"] },\r\n { name: \"Units.WEEK\", altDisplayLabels: [\"week\"] },\r\n { name: \"Units.YR\", altDisplayLabels: [\"year\"] },\r\n // conversion => specified unit to base unit of m\r\n { name: \"Units.M\", altDisplayLabels: [\"meter\"] },\r\n { name: \"Units.MM\", altDisplayLabels: [\"MM\"] },\r\n { name: \"Units.CM\", altDisplayLabels: [\"CM\"] },\r\n { name: \"Units.DM\", altDisplayLabels: [\"DM\"] },\r\n { name: \"Units.KM\", altDisplayLabels: [\"KM\"] },\r\n { name: \"Units.UM\", altDisplayLabels: [] },\r\n { name: \"Units.MILLIINCH\", altDisplayLabels: [] },\r\n { name: \"Units.MICROINCH\", altDisplayLabels: [] },\r\n { name: \"Units.MILLIFOOT\", altDisplayLabels: [] },\r\n { name: \"Units.IN\", altDisplayLabels: [\"IN\", \"\\\"\"] },\r\n { name: \"Units.FT\", altDisplayLabels: [\"F\", \"FT\", \"'\"] },\r\n { name: \"Units.CHAIN\", altDisplayLabels: [\"CHAIN\"] },\r\n { name: \"Units.YRD\", altDisplayLabels: [\"YRD\", \"yrd\"] },\r\n { name: \"Units.MILE\", altDisplayLabels: [\"mile\", \"Miles\", \"Mile\"] },\r\n { name: \"Units.US_SURVEY_FT\", altDisplayLabels: [\"ft\", \"SF\", \"USF\", \"ft (US Survey)\"] },\r\n { name: \"Units.US_SURVEY_YRD\", altDisplayLabels: [\"USY\", \"yards (US Survey)\"] },\r\n { name: \"Units.US_SURVEY_IN\", altDisplayLabels: [\"USI\", \"inches (US Survey)\"] },\r\n { name: \"Units.US_SURVEY_MILE\", altDisplayLabels: [\"miles (US Survey)\", \"mile (US Survey)\", \"USM\"] },\r\n { name: \"Units.US_SURVEY_CHAIN\", altDisplayLabels: [\"chains (US Survey)\"] },\r\n // conversion => specified unit to base unit of m²\r\n { name: \"Units.SQ_FT\", altDisplayLabels: [\"sf\"] },\r\n { name: \"Units.SQ_US_SURVEY_FT\", altDisplayLabels: [\"sussf\"] },\r\n { name: \"Units.SQ_M\", altDisplayLabels: [\"sm\"] },\r\n // conversion => specified unit to base unit m³\r\n { name: \"Units.CUB_FT\", altDisplayLabels: [\"cf\"] },\r\n { name: \"Units.CUB_US_SURVEY_FT\", altDisplayLabels: [\"cf\"] },\r\n { name: \"Units.CUB_YRD\", altDisplayLabels: [\"cy\"] },\r\n { name: \"Units.CUB_M\", altDisplayLabels: [\"cm\"] },\r\n];\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PntsReader.d.ts","sourceRoot":"","sources":["../../../src/tile/PntsReader.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAwB,MAAM,qBAAqB,CAAC;AAEnF,OAAO,EAAa,mBAAmB,EAA4F,MAAM,oBAAoB,CAAC;AAE9J,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"PntsReader.d.ts","sourceRoot":"","sources":["../../../src/tile/PntsReader.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAwB,MAAM,qBAAqB,CAAC;AAEnF,OAAO,EAAa,mBAAmB,EAA4F,MAAM,oBAAoB,CAAC;AAE9J,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAsMtD;;GAEG;AACH,wBAAsB,yBAAyB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA0DvN"}
|
|
@@ -11,6 +11,70 @@ import { BatchType, Feature, FeatureTable, PackedFeatureTable, PntsHeader, QPara
|
|
|
11
11
|
import { FrontendLoggerCategory } from "../FrontendLoggerCategory";
|
|
12
12
|
import { Mesh } from "../render/primitives/mesh/MeshPrimitives";
|
|
13
13
|
import { PointCloudArgs } from "../render/primitives/PointCloudPrimitive";
|
|
14
|
+
function readPntsColors(stream, dataOffset, pnts) {
|
|
15
|
+
const nPts = pnts.POINTS_LENGTH;
|
|
16
|
+
const nComponents = 3 * nPts;
|
|
17
|
+
if (pnts.RGB)
|
|
18
|
+
return new Uint8Array(stream.arrayBuffer, dataOffset + pnts.RGB.byteOffset, nComponents);
|
|
19
|
+
if (pnts.RGBA) {
|
|
20
|
+
// ###TODO support point cloud transparency.
|
|
21
|
+
const rgb = new Uint8Array(nComponents);
|
|
22
|
+
const rgba = new Uint8Array(stream.arrayBuffer, dataOffset + pnts.RGBA.byteOffset, nComponents);
|
|
23
|
+
for (let i = 0; i < nComponents; i += 4) {
|
|
24
|
+
rgb[i + 0] = rgba[i + 0];
|
|
25
|
+
rgb[i + 1] = rgba[i + 1];
|
|
26
|
+
rgb[i + 2] = rgba[i + 2];
|
|
27
|
+
}
|
|
28
|
+
return rgb;
|
|
29
|
+
}
|
|
30
|
+
else if (pnts.RGB565) {
|
|
31
|
+
// Each color is 16 bits: 5 red, 6 green, 5 blue.
|
|
32
|
+
const crgb = new Uint16Array(stream.arrayBuffer, dataOffset + pnts.RGB565.byteOffset, nPts);
|
|
33
|
+
const rgb = new Uint8Array(nComponents);
|
|
34
|
+
for (let i = 0; i < nPts; i++) {
|
|
35
|
+
const c = crgb[i];
|
|
36
|
+
rgb[i + 0] = (c >> 11) & 0x1f;
|
|
37
|
+
rgb[i + 1] = (c >> 5) & 0x3f;
|
|
38
|
+
rgb[i + 2] = c & 0x1f;
|
|
39
|
+
}
|
|
40
|
+
return rgb;
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
function readPnts(stream, dataOffset, pnts) {
|
|
45
|
+
const nPts = pnts.POINTS_LENGTH;
|
|
46
|
+
let params;
|
|
47
|
+
let points;
|
|
48
|
+
if (pnts.POSITION_QUANTIZED) {
|
|
49
|
+
const qpos = pnts.POSITION_QUANTIZED;
|
|
50
|
+
const offset = pnts.QUANTIZED_VOLUME_OFFSET;
|
|
51
|
+
const scale = pnts.QUANTIZED_VOLUME_SCALE;
|
|
52
|
+
const qOrigin = new Point3d(offset[0], offset[1], offset[2]);
|
|
53
|
+
const qScale = new Point3d(Quantization.computeScale(scale[0]), Quantization.computeScale(scale[1]), Quantization.computeScale(scale[2]));
|
|
54
|
+
params = QParams3d.fromOriginAndScale(qOrigin, qScale);
|
|
55
|
+
points = new Uint16Array(stream.arrayBuffer, dataOffset + qpos.byteOffset, 3 * nPts);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const nCoords = nPts * 3;
|
|
59
|
+
const fpts = new Float32Array(stream.arrayBuffer, dataOffset + pnts.POSITION.byteOffset, 3 * nPts);
|
|
60
|
+
const range = Range3d.createNull();
|
|
61
|
+
for (let i = 0; i < nCoords; i += 3)
|
|
62
|
+
range.extendXYZ(fpts[i], fpts[i + 1], fpts[i + 2]);
|
|
63
|
+
params = QParams3d.fromRange(range);
|
|
64
|
+
const qpt = new QPoint3d();
|
|
65
|
+
const fpt = new Point3d();
|
|
66
|
+
points = new Uint16Array(3 * nPts);
|
|
67
|
+
for (let i = 0; i < nCoords; i += 3) {
|
|
68
|
+
fpt.set(fpts[i], fpts[i + 1], fpts[i + 2]);
|
|
69
|
+
qpt.init(fpt, params);
|
|
70
|
+
points[i] = qpt.x;
|
|
71
|
+
points[i + 1] = qpt.y;
|
|
72
|
+
points[i + 2] = qpt.z;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const colors = readPntsColors(stream, dataOffset, pnts);
|
|
76
|
+
return { params, points, colors };
|
|
77
|
+
}
|
|
14
78
|
async function decodeDracoPointCloud(buf) {
|
|
15
79
|
var _a, _b, _c, _d, _e, _f;
|
|
16
80
|
try {
|
|
@@ -23,6 +87,7 @@ async function decodeDracoPointCloud(buf) {
|
|
|
23
87
|
return undefined;
|
|
24
88
|
let colors = (_c = (_b = mesh.attributes.RGB) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : (_d = mesh.attributes.COLOR_0) === null || _d === void 0 ? void 0 : _d.value;
|
|
25
89
|
if (!colors) {
|
|
90
|
+
// ###TODO support point cloud transparency.
|
|
26
91
|
const rgba = (_e = mesh.attributes.RGBA) === null || _e === void 0 ? void 0 : _e.value;
|
|
27
92
|
if (rgba && (rgba.length % 4) === 0) {
|
|
28
93
|
// We currently don't support alpha channel for point clouds - strip it.
|
|
@@ -64,21 +129,6 @@ async function decodeDracoPointCloud(buf) {
|
|
|
64
129
|
return undefined;
|
|
65
130
|
}
|
|
66
131
|
}
|
|
67
|
-
function readPnts(stream, dataOffset, pnts) {
|
|
68
|
-
const offset = pnts.QUANTIZED_VOLUME_OFFSET;
|
|
69
|
-
const scale = pnts.QUANTIZED_VOLUME_SCALE;
|
|
70
|
-
const qpos = pnts.POSITION_QUANTIZED;
|
|
71
|
-
const nPts = pnts.POINTS_LENGTH;
|
|
72
|
-
if (!offset || !scale || !qpos || !nPts)
|
|
73
|
-
return undefined;
|
|
74
|
-
const qOrigin = new Point3d(offset[0], offset[1], offset[2]);
|
|
75
|
-
const qScale = new Point3d(Quantization.computeScale(scale[0]), Quantization.computeScale(scale[1]), Quantization.computeScale(scale[2]));
|
|
76
|
-
return {
|
|
77
|
-
params: QParams3d.fromOriginAndScale(qOrigin, qScale),
|
|
78
|
-
points: new Uint16Array(stream.arrayBuffer, dataOffset + qpos.byteOffset, 3 * nPts),
|
|
79
|
-
colors: pnts.RGB ? new Uint8Array(stream.arrayBuffer, dataOffset + pnts.RGB.byteOffset, 3 * nPts) : undefined,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
132
|
/** Deserialize a point cloud tile and return it as a RenderGraphic.
|
|
83
133
|
* @internal
|
|
84
134
|
*/
|
|
@@ -112,10 +162,22 @@ export async function readPointCloudTileContent(stream, iModel, modelId, _is3d,
|
|
|
112
162
|
if (featureValue.RTC_CENTER)
|
|
113
163
|
props.params = QParams3d.fromOriginAndScale(props.params.origin.plus(Vector3d.fromJSON(featureValue.RTC_CENTER)), props.params.scale);
|
|
114
164
|
if (!props.colors) {
|
|
165
|
+
// ###TODO we really should support uniform color instead of allocating an RGB value per point...
|
|
115
166
|
props.colors = new Uint8Array(3 * featureValue.POINTS_LENGTH);
|
|
116
|
-
|
|
167
|
+
const rgba = featureValue.CONSTANT_RGBA;
|
|
168
|
+
if (rgba) {
|
|
169
|
+
// ###TODO support point cloud transparency.
|
|
170
|
+
for (let i = 0; i < featureValue.POINTS_LENGTH * 3; i += 3) {
|
|
171
|
+
props.colors[i] = rgba[0];
|
|
172
|
+
props.colors[i + 1] = rgba[1];
|
|
173
|
+
props.colors[i + 2] = rgba[2];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// Default to white.
|
|
178
|
+
props.colors.fill(0xff, 0, props.colors.length);
|
|
179
|
+
}
|
|
117
180
|
}
|
|
118
|
-
// ###TODO? Do we expect a batch table? not currently handled...
|
|
119
181
|
const featureTable = new FeatureTable(1, modelId, BatchType.Primary);
|
|
120
182
|
const features = new Mesh.Features(featureTable);
|
|
121
183
|
features.add(new Feature(modelId), 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PntsReader.js","sourceRoot":"","sources":["../../../src/tile/PntsReader.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAA0B,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAuB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9J,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AA0B1E,KAAK,UAAU,qBAAqB,CAAC,GAAe;;IAClD,IAAI;QACF,MAAM,WAAW,GAAG,CAAC,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,WAAW,CAAC;QACpE,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,KAAK,CAA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CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;IAE5D,IAAI,aAAa,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;IACvI,aAAa,GAAG,MAAM,CAAC,WAAW,CAAC,aAAc,EAAE,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;IACjG,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Tiles\r\n */\r\n\r\nimport { ByteStream, Id64String, Logger, utf8ToString } from \"@itwin/core-bentley\";\r\nimport { Point3d, Range3d, Vector3d } from \"@itwin/core-geometry\";\r\nimport { BatchType, ElementAlignedBox3d, Feature, FeatureTable, PackedFeatureTable, PntsHeader, QParams3d, QPoint3d, Quantization } from \"@itwin/core-common\";\r\nimport { FrontendLoggerCategory } from \"../FrontendLoggerCategory\";\r\nimport { IModelConnection } from \"../IModelConnection\";\r\nimport { Mesh } from \"../render/primitives/mesh/MeshPrimitives\";\r\nimport { PointCloudArgs } from \"../render/primitives/PointCloudPrimitive\";\r\nimport { RenderGraphic } from \"../render/RenderGraphic\";\r\nimport { RenderSystem } from \"../render/RenderSystem\";\r\n\r\n/** Schema for the [3DTILES_draco_point_compression](https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_draco_point_compression) extension. */\r\ninterface DracoPointCloud {\r\n byteLength: number;\r\n byteOffset: number;\r\n /** Each specifies the Id of a compressed attribute. */\r\n properties: {\r\n POSITION?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n RGB?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n RGBA?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n NORMAL?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n BATCH_ID?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n /** This is not in the spec but is present in sample data in Cesium's git repository. */\r\n COLOR_0?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n };\r\n}\r\n\r\ninterface PointCloudProps {\r\n params: QParams3d;\r\n points: Uint16Array;\r\n colors?: Uint8Array;\r\n}\r\n\r\nasync function decodeDracoPointCloud(buf: Uint8Array): Promise<PointCloudProps | undefined> {\r\n try {\r\n const dracoLoader = (await import(\"@loaders.gl/draco\")).DracoLoader;\r\n const mesh = await dracoLoader.parse(buf, { });\r\n if (mesh.topology !== \"point-list\")\r\n return undefined;\r\n\r\n const pos = mesh.attributes.POSITION?.value;\r\n if (!pos || (pos.length % 3) !== 0)\r\n return undefined;\r\n\r\n let colors = mesh.attributes.RGB?.value ?? mesh.attributes.COLOR_0?.value;\r\n if (!colors) {\r\n const rgba = mesh.attributes.RGBA?.value;\r\n if (rgba && (rgba.length % 4) === 0) {\r\n // We currently don't support alpha channel for point clouds - strip it.\r\n colors = new Uint8Array(3 * rgba.length / 4);\r\n let j = 0;\r\n for (let i = 0; i < rgba.length; i += 4) {\r\n colors[j++] = rgba[i];\r\n colors[j++] = rgba[i + 1];\r\n colors[j++] = rgba[i + 2];\r\n }\r\n }\r\n }\r\n\r\n let posRange: Range3d;\r\n const bbox = mesh.header?.boundingBox;\r\n if (bbox) {\r\n posRange = Range3d.createXYZXYZ(bbox[0][0], bbox[0][1], bbox[0][2], bbox[1][0], bbox[1][1], bbox[1][2]);\r\n } else {\r\n posRange = Range3d.createNull();\r\n for (let i = 0; i < pos.length; i += 3)\r\n posRange.extendXYZ(pos[i], pos[i + 1], pos[i + 2]);\r\n }\r\n\r\n const params = QParams3d.fromRange(posRange);\r\n const pt = Point3d.createZero();\r\n const qpt = QPoint3d.create(pt, params);\r\n const points = new Uint16Array(pos.length);\r\n for (let i = 0; i < pos.length; i += 3) {\r\n pt.set(pos[i], pos[i + 1], pos[i + 2]);\r\n qpt.init(pt, params);\r\n points[i] = qpt.x;\r\n points[i + 1] = qpt.y;\r\n points[i + 2] = qpt.z;\r\n }\r\n\r\n return { points, params, colors: colors instanceof Uint8Array ? colors : undefined };\r\n } catch (err) {\r\n Logger.logWarning(FrontendLoggerCategory.Render, \"Failed to decode draco-encoded point cloud\");\r\n Logger.logException(FrontendLoggerCategory.Render, err);\r\n return undefined;\r\n }\r\n}\r\n\r\ninterface PntsProps {\r\n POSITION_QUANTIZED?: { byteOffset: number }; // eslint-disable-line @typescript-eslint/naming-convention\r\n QUANTIZED_VOLUME_OFFSET?: number[]; // eslint-disable-line @typescript-eslint/naming-convention\r\n QUANTIZED_VOLUME_SCALE?: number[]; // eslint-disable-line @typescript-eslint/naming-convention\r\n POINTS_LENGTH?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n RGB?: { byteOffset: number }; // eslint-disable-line @typescript-eslint/naming-convention\r\n}\r\n\r\nfunction readPnts(stream: ByteStream, dataOffset: number, pnts: PntsProps): PointCloudProps | undefined {\r\n const offset = pnts.QUANTIZED_VOLUME_OFFSET;\r\n const scale = pnts.QUANTIZED_VOLUME_SCALE;\r\n const qpos = pnts.POSITION_QUANTIZED;\r\n const nPts = pnts.POINTS_LENGTH;\r\n if (!offset || !scale || !qpos || !nPts)\r\n return undefined;\r\n\r\n const qOrigin = new Point3d(offset[0], offset[1], offset[2]);\r\n const qScale = new Point3d(Quantization.computeScale(scale[0]), Quantization.computeScale(scale[1]), Quantization.computeScale(scale[2]));\r\n\r\n return {\r\n params: QParams3d.fromOriginAndScale(qOrigin, qScale),\r\n points: new Uint16Array(stream.arrayBuffer, dataOffset + qpos.byteOffset, 3 * nPts),\r\n colors: pnts.RGB ? new Uint8Array(stream.arrayBuffer, dataOffset + pnts.RGB.byteOffset, 3 * nPts) : undefined,\r\n };\r\n}\r\n\r\n/** Deserialize a point cloud tile and return it as a RenderGraphic.\r\n * @internal\r\n */\r\nexport async function readPointCloudTileContent(stream: ByteStream, iModel: IModelConnection, modelId: Id64String, _is3d: boolean, range: ElementAlignedBox3d, system: RenderSystem): Promise<RenderGraphic | undefined> {\r\n const header = new PntsHeader(stream);\r\n if (!header.isValid)\r\n return undefined;\r\n\r\n const featureTableJsonOffset = stream.curPos;\r\n const featureStrData = stream.nextBytes(header.featureTableJsonLength);\r\n const featureStr = utf8ToString(featureStrData);\r\n const featureValue = JSON.parse(featureStr as string);\r\n\r\n if (undefined === featureValue)\r\n return undefined;\r\n\r\n let props: PointCloudProps | undefined;\r\n const dataOffset = featureTableJsonOffset + header.featureTableJsonLength;\r\n const draco: DracoPointCloud | undefined = featureValue.extensions ? featureValue.extensions[\"3DTILES_draco_point_compression\"] : undefined;\r\n if (draco) {\r\n try {\r\n const buf = new Uint8Array(stream.arrayBuffer, dataOffset + draco.byteOffset, draco.byteLength);\r\n props = await decodeDracoPointCloud(buf);\r\n } catch (_) {\r\n //\r\n }\r\n } else {\r\n props = readPnts(stream, dataOffset, featureValue);\r\n }\r\n\r\n if (!props)\r\n return undefined;\r\n\r\n if (featureValue.RTC_CENTER)\r\n props.params = QParams3d.fromOriginAndScale(props.params.origin.plus(Vector3d.fromJSON(featureValue.RTC_CENTER)), props.params.scale);\r\n\r\n if (!props.colors) {\r\n props.colors = new Uint8Array(3 * featureValue.POINTS_LENGTH);\r\n props.colors.fill(0xff, 0, props.colors.length); // TBD... Default color?\r\n }\r\n\r\n // ###TODO? Do we expect a batch table? not currently handled...\r\n const featureTable = new FeatureTable(1, modelId, BatchType.Primary);\r\n const features = new Mesh.Features(featureTable);\r\n features.add(new Feature(modelId), 1);\r\n const voxelSize = props.params.rangeDiagonal.maxAbs() / 256;\r\n\r\n let renderGraphic = system.createPointCloud(new PointCloudArgs(props.points, props.params, props.colors, features, voxelSize), iModel);\r\n renderGraphic = system.createBatch(renderGraphic!, PackedFeatureTable.pack(featureTable), range);\r\n return renderGraphic;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"PntsReader.js","sourceRoot":"","sources":["../../../src/tile/PntsReader.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAA0B,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAuB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9J,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAsE1E,SAAS,cAAc,CAAC,MAAkB,EAAE,UAAkB,EAAE,IAAe;IAC7E,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC;IAChC,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC;IAC7B,IAAI,IAAI,CAAC,GAAG;QACV,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAE3F,IAAI,IAAI,CAAC,IAAI,EAAE;QACb,4CAA4C;QAC5C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAChG,KAAK,IAAI,CAAC,GA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CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;aAC/B;SACF;aAAM;YACL,oBAAoB;YACpB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACjD;KACF;IAED,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IACjD,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;IAE5D,IAAI,aAAa,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;IACvI,aAAa,GAAG,MAAM,CAAC,WAAW,CAAC,aAAc,EAAE,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;IACjG,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Tiles\r\n */\r\n\r\nimport { ByteStream, Id64String, Logger, utf8ToString } from \"@itwin/core-bentley\";\r\nimport { Point3d, Range3d, Vector3d } from \"@itwin/core-geometry\";\r\nimport { BatchType, ElementAlignedBox3d, Feature, FeatureTable, PackedFeatureTable, PntsHeader, QParams3d, QPoint3d, Quantization } from \"@itwin/core-common\";\r\nimport { FrontendLoggerCategory } from \"../FrontendLoggerCategory\";\r\nimport { IModelConnection } from \"../IModelConnection\";\r\nimport { Mesh } from \"../render/primitives/mesh/MeshPrimitives\";\r\nimport { PointCloudArgs } from \"../render/primitives/PointCloudPrimitive\";\r\nimport { RenderGraphic } from \"../render/RenderGraphic\";\r\nimport { RenderSystem } from \"../render/RenderSystem\";\r\n\r\n/** Schema for the [3DTILES_draco_point_compression](https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_draco_point_compression) extension. */\r\ninterface DracoPointCloud {\r\n byteLength: number;\r\n byteOffset: number;\r\n /** Each specifies the Id of a compressed attribute. */\r\n properties: {\r\n POSITION?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n RGB?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n RGBA?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n NORMAL?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n BATCH_ID?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n /** This is not in the spec but is present in sample data in Cesium's git repository. */\r\n COLOR_0?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n };\r\n}\r\n\r\ninterface PointCloudProps {\r\n params: QParams3d;\r\n points: Uint16Array;\r\n colors?: Uint8Array;\r\n}\r\n\r\ninterface BinaryBodyReference {\r\n byteOffset: number;\r\n}\r\n\r\n/** [3D tiles specification section 10.3](https://docs.opengeospatial.org/cs/18-053r2/18-053r2.html#199).\r\n * [JSON schema](https://github.com/CesiumGS/3d-tiles/blob/main/specification/schema/pnts.featureTable.schema.json).\r\n */\r\ninterface CommonPntsProps {\r\n POINTS_LENGTH: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n RTC_CENTER?: number[]; // eslint-disable-line @typescript-eslint/naming-convention\r\n CONSTANT_RGBA?: number[]; // eslint-disable-line @typescript-eslint/naming-convention\r\n RGB?: BinaryBodyReference; // eslint-disable-line @typescript-eslint/naming-convention\r\n RGBA?: BinaryBodyReference; // eslint-disable-line @typescript-eslint/naming-convention\r\n RGB565?: BinaryBodyReference; // eslint-disable-line @typescript-eslint/naming-convention\r\n\r\n extensions?: {\r\n \"3DTILES_draco_point_compression\"?: DracoPointCloud; // eslint-disable-line @typescript-eslint/naming-convention\r\n };\r\n\r\n // The following are currently ignored.\r\n NORMAL?: BinaryBodyReference; // eslint-disable-line @typescript-eslint/naming-convention\r\n NORMAL_OCT16P?: BinaryBodyReference; // eslint-disable-line @typescript-eslint/naming-convention\r\n BATCH_ID?: BinaryBodyReference; // eslint-disable-line @typescript-eslint/naming-convention\r\n BATCH_LENGTH?: number; // eslint-disable-line @typescript-eslint/naming-convention\r\n}\r\n\r\ntype QuantizedPntsProps = CommonPntsProps & {\r\n POSITION_QUANTIZED: BinaryBodyReference; // eslint-disable-line @typescript-eslint/naming-convention\r\n QUANTIZED_VOLUME_OFFSET: number[]; // eslint-disable-line @typescript-eslint/naming-convention\r\n QUANTIZED_VOLUME_SCALE: number[]; // eslint-disable-line @typescript-eslint/naming-convention\r\n\r\n POSITION?: never; // eslint-disable-line @typescript-eslint/naming-convention\r\n};\r\n\r\ntype UnquantizedPntsProps = CommonPntsProps & {\r\n POSITION: BinaryBodyReference; // eslint-disable-line @typescript-eslint/naming-convention\r\n\r\n POSITION_QUANTIZED?: never; // eslint-disable-line @typescript-eslint/naming-convention\r\n QUANTIZED_VOLUME_OFFSET?: never; // eslint-disable-line @typescript-eslint/naming-convention\r\n QUANTIZED_VOLUME_SCALE?: never; // eslint-disable-line @typescript-eslint/naming-convention\r\n};\r\n\r\ntype PntsProps = QuantizedPntsProps | UnquantizedPntsProps;\r\n\r\nfunction readPntsColors(stream: ByteStream, dataOffset: number, pnts: PntsProps): Uint8Array | undefined {\r\n const nPts = pnts.POINTS_LENGTH;\r\n const nComponents = 3 * nPts;\r\n if (pnts.RGB)\r\n return new Uint8Array(stream.arrayBuffer, dataOffset + pnts.RGB.byteOffset, nComponents);\r\n\r\n if (pnts.RGBA) {\r\n // ###TODO support point cloud transparency.\r\n const rgb = new Uint8Array(nComponents);\r\n const rgba = new Uint8Array(stream.arrayBuffer, dataOffset + pnts.RGBA.byteOffset, nComponents);\r\n for (let i = 0; i < nComponents; i += 4) {\r\n rgb[i + 0] = rgba[i + 0];\r\n rgb[i + 1] = rgba[i + 1];\r\n rgb[i + 2] = rgba[i + 2];\r\n }\r\n\r\n return rgb;\r\n } else if (pnts.RGB565) {\r\n // Each color is 16 bits: 5 red, 6 green, 5 blue.\r\n const crgb = new Uint16Array(stream.arrayBuffer, dataOffset + pnts.RGB565.byteOffset, nPts);\r\n const rgb = new Uint8Array(nComponents);\r\n for (let i = 0; i < nPts; i++) {\r\n const c = crgb[i];\r\n rgb[i + 0] = (c >> 11) & 0x1f;\r\n rgb[i + 1] = (c >> 5) & 0x3f;\r\n rgb[i + 2] = c & 0x1f;\r\n }\r\n\r\n return rgb;\r\n }\r\n\r\n return undefined;\r\n}\r\n\r\nfunction readPnts(stream: ByteStream, dataOffset: number, pnts: PntsProps): PointCloudProps | undefined {\r\n const nPts = pnts.POINTS_LENGTH;\r\n let params: QParams3d;\r\n let points: Uint16Array;\r\n\r\n if (pnts.POSITION_QUANTIZED) {\r\n const qpos = pnts.POSITION_QUANTIZED;\r\n const offset = pnts.QUANTIZED_VOLUME_OFFSET;\r\n const scale = pnts.QUANTIZED_VOLUME_SCALE;\r\n\r\n const qOrigin = new Point3d(offset[0], offset[1], offset[2]);\r\n const qScale = new Point3d(Quantization.computeScale(scale[0]), Quantization.computeScale(scale[1]), Quantization.computeScale(scale[2]));\r\n\r\n params = QParams3d.fromOriginAndScale(qOrigin, qScale);\r\n points = new Uint16Array(stream.arrayBuffer, dataOffset + qpos.byteOffset, 3 * nPts);\r\n } else {\r\n const nCoords = nPts * 3;\r\n const fpts = new Float32Array(stream.arrayBuffer, dataOffset + pnts.POSITION.byteOffset, 3 * nPts);\r\n const range = Range3d.createNull();\r\n for (let i = 0; i < nCoords; i += 3)\r\n range.extendXYZ(fpts[i], fpts[i + 1], fpts[i + 2]);\r\n\r\n params = QParams3d.fromRange(range);\r\n const qpt = new QPoint3d();\r\n const fpt = new Point3d();\r\n points = new Uint16Array(3 * nPts);\r\n for (let i = 0; i < nCoords; i += 3) {\r\n fpt.set(fpts[i], fpts[i + 1], fpts[i + 2]);\r\n qpt.init(fpt, params);\r\n points[i] = qpt.x;\r\n points[i + 1] = qpt.y;\r\n points[i + 2] = qpt.z;\r\n }\r\n }\r\n\r\n const colors = readPntsColors(stream, dataOffset, pnts);\r\n return { params, points, colors };\r\n}\r\n\r\nasync function decodeDracoPointCloud(buf: Uint8Array): Promise<PointCloudProps | undefined> {\r\n try {\r\n const dracoLoader = (await import(\"@loaders.gl/draco\")).DracoLoader;\r\n const mesh = await dracoLoader.parse(buf, { });\r\n if (mesh.topology !== \"point-list\")\r\n return undefined;\r\n\r\n const pos = mesh.attributes.POSITION?.value;\r\n if (!pos || (pos.length % 3) !== 0)\r\n return undefined;\r\n\r\n let colors = mesh.attributes.RGB?.value ?? mesh.attributes.COLOR_0?.value;\r\n if (!colors) {\r\n // ###TODO support point cloud transparency.\r\n const rgba = mesh.attributes.RGBA?.value;\r\n if (rgba && (rgba.length % 4) === 0) {\r\n // We currently don't support alpha channel for point clouds - strip it.\r\n colors = new Uint8Array(3 * rgba.length / 4);\r\n let j = 0;\r\n for (let i = 0; i < rgba.length; i += 4) {\r\n colors[j++] = rgba[i];\r\n colors[j++] = rgba[i + 1];\r\n colors[j++] = rgba[i + 2];\r\n }\r\n }\r\n }\r\n\r\n let posRange: Range3d;\r\n const bbox = mesh.header?.boundingBox;\r\n if (bbox) {\r\n posRange = Range3d.createXYZXYZ(bbox[0][0], bbox[0][1], bbox[0][2], bbox[1][0], bbox[1][1], bbox[1][2]);\r\n } else {\r\n posRange = Range3d.createNull();\r\n for (let i = 0; i < pos.length; i += 3)\r\n posRange.extendXYZ(pos[i], pos[i + 1], pos[i + 2]);\r\n }\r\n\r\n const params = QParams3d.fromRange(posRange);\r\n const pt = Point3d.createZero();\r\n const qpt = QPoint3d.create(pt, params);\r\n const points = new Uint16Array(pos.length);\r\n for (let i = 0; i < pos.length; i += 3) {\r\n pt.set(pos[i], pos[i + 1], pos[i + 2]);\r\n qpt.init(pt, params);\r\n points[i] = qpt.x;\r\n points[i + 1] = qpt.y;\r\n points[i + 2] = qpt.z;\r\n }\r\n\r\n return { points, params, colors: colors instanceof Uint8Array ? colors : undefined };\r\n } catch (err) {\r\n Logger.logWarning(FrontendLoggerCategory.Render, \"Failed to decode draco-encoded point cloud\");\r\n Logger.logException(FrontendLoggerCategory.Render, err);\r\n return undefined;\r\n }\r\n}\r\n\r\n/** Deserialize a point cloud tile and return it as a RenderGraphic.\r\n * @internal\r\n */\r\nexport async function readPointCloudTileContent(stream: ByteStream, iModel: IModelConnection, modelId: Id64String, _is3d: boolean, range: ElementAlignedBox3d, system: RenderSystem): Promise<RenderGraphic | undefined> {\r\n const header = new PntsHeader(stream);\r\n if (!header.isValid)\r\n return undefined;\r\n\r\n const featureTableJsonOffset = stream.curPos;\r\n const featureStrData = stream.nextBytes(header.featureTableJsonLength);\r\n const featureStr = utf8ToString(featureStrData);\r\n const featureValue = JSON.parse(featureStr as string) as PntsProps;\r\n\r\n if (undefined === featureValue)\r\n return undefined;\r\n\r\n let props: PointCloudProps | undefined;\r\n const dataOffset = featureTableJsonOffset + header.featureTableJsonLength;\r\n const draco = featureValue.extensions ? featureValue.extensions[\"3DTILES_draco_point_compression\"] : undefined;\r\n if (draco) {\r\n try {\r\n const buf = new Uint8Array(stream.arrayBuffer, dataOffset + draco.byteOffset, draco.byteLength);\r\n props = await decodeDracoPointCloud(buf);\r\n } catch (_) {\r\n //\r\n }\r\n } else {\r\n props = readPnts(stream, dataOffset, featureValue);\r\n }\r\n\r\n if (!props)\r\n return undefined;\r\n\r\n if (featureValue.RTC_CENTER)\r\n props.params = QParams3d.fromOriginAndScale(props.params.origin.plus(Vector3d.fromJSON(featureValue.RTC_CENTER)), props.params.scale);\r\n\r\n if (!props.colors) {\r\n // ###TODO we really should support uniform color instead of allocating an RGB value per point...\r\n props.colors = new Uint8Array(3 * featureValue.POINTS_LENGTH);\r\n const rgba = featureValue.CONSTANT_RGBA;\r\n if (rgba) {\r\n // ###TODO support point cloud transparency.\r\n for (let i = 0; i < featureValue.POINTS_LENGTH * 3; i += 3) {\r\n props.colors[i] = rgba[0];\r\n props.colors[i + 1] = rgba[1];\r\n props.colors[i + 2] = rgba[2];\r\n }\r\n } else {\r\n // Default to white.\r\n props.colors.fill(0xff, 0, props.colors.length);\r\n }\r\n }\r\n\r\n const featureTable = new FeatureTable(1, modelId, BatchType.Primary);\r\n const features = new Mesh.Features(featureTable);\r\n features.add(new Feature(modelId), 1);\r\n const voxelSize = props.params.rangeDiagonal.maxAbs() / 256;\r\n\r\n let renderGraphic = system.createPointCloud(new PointCloudArgs(props.points, props.params, props.colors, features, voxelSize), iModel);\r\n renderGraphic = system.createBatch(renderGraphic!, PackedFeatureTable.pack(featureTable), range);\r\n return renderGraphic;\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-frontend",
|
|
3
|
-
"version": "3.1.0-dev.
|
|
3
|
+
"version": "3.1.0-dev.28",
|
|
4
4
|
"description": "iTwin.js frontend components",
|
|
5
5
|
"main": "lib/cjs/core-frontend.js",
|
|
6
6
|
"module": "lib/esm/core-frontend.js",
|
|
@@ -23,29 +23,29 @@
|
|
|
23
23
|
"url": "http://www.bentley.com"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@itwin/appui-abstract": "^3.1.0-dev.
|
|
27
|
-
"@itwin/core-bentley": "^3.1.0-dev.
|
|
28
|
-
"@itwin/core-common": "^3.1.0-dev.
|
|
29
|
-
"@itwin/core-geometry": "^3.1.0-dev.
|
|
30
|
-
"@itwin/core-orbitgt": "^3.1.0-dev.
|
|
31
|
-
"@itwin/core-quantity": "^3.1.0-dev.
|
|
32
|
-
"@itwin/webgl-compatibility": "^3.1.0-dev.
|
|
26
|
+
"@itwin/appui-abstract": "^3.1.0-dev.28",
|
|
27
|
+
"@itwin/core-bentley": "^3.1.0-dev.28",
|
|
28
|
+
"@itwin/core-common": "^3.1.0-dev.28",
|
|
29
|
+
"@itwin/core-geometry": "^3.1.0-dev.28",
|
|
30
|
+
"@itwin/core-orbitgt": "^3.1.0-dev.28",
|
|
31
|
+
"@itwin/core-quantity": "^3.1.0-dev.28",
|
|
32
|
+
"@itwin/webgl-compatibility": "^3.1.0-dev.28"
|
|
33
33
|
},
|
|
34
34
|
"//devDependencies": [
|
|
35
35
|
"NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
|
|
36
36
|
"NOTE: All tools used by scripts in this package must be listed as devDependencies"
|
|
37
37
|
],
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@itwin/appui-abstract": "3.1.0-dev.
|
|
40
|
-
"@itwin/build-tools": "3.1.0-dev.
|
|
41
|
-
"@itwin/core-bentley": "3.1.0-dev.
|
|
42
|
-
"@itwin/core-common": "3.1.0-dev.
|
|
43
|
-
"@itwin/core-geometry": "3.1.0-dev.
|
|
44
|
-
"@itwin/core-orbitgt": "3.1.0-dev.
|
|
45
|
-
"@itwin/core-quantity": "3.1.0-dev.
|
|
46
|
-
"@itwin/certa": "3.1.0-dev.
|
|
47
|
-
"@itwin/eslint-plugin": "3.1.0-dev.
|
|
48
|
-
"@itwin/webgl-compatibility": "3.1.0-dev.
|
|
39
|
+
"@itwin/appui-abstract": "3.1.0-dev.28",
|
|
40
|
+
"@itwin/build-tools": "3.1.0-dev.28",
|
|
41
|
+
"@itwin/core-bentley": "3.1.0-dev.28",
|
|
42
|
+
"@itwin/core-common": "3.1.0-dev.28",
|
|
43
|
+
"@itwin/core-geometry": "3.1.0-dev.28",
|
|
44
|
+
"@itwin/core-orbitgt": "3.1.0-dev.28",
|
|
45
|
+
"@itwin/core-quantity": "3.1.0-dev.28",
|
|
46
|
+
"@itwin/certa": "3.1.0-dev.28",
|
|
47
|
+
"@itwin/eslint-plugin": "3.1.0-dev.28",
|
|
48
|
+
"@itwin/webgl-compatibility": "3.1.0-dev.28",
|
|
49
49
|
"@types/chai": "^4.1.4",
|
|
50
50
|
"@types/chai-as-promised": "^7",
|
|
51
51
|
"@types/deep-assign": "^0.1.0",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"NOTE: core-frontend should remain UI technology agnostic, so no react/angular dependencies are allowed"
|
|
75
75
|
],
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@itwin/core-i18n": "3.1.0-dev.
|
|
78
|
-
"@itwin/core-telemetry": "3.1.0-dev.
|
|
77
|
+
"@itwin/core-i18n": "3.1.0-dev.28",
|
|
78
|
+
"@itwin/core-telemetry": "3.1.0-dev.28",
|
|
79
79
|
"@loaders.gl/core": "^3.1.6",
|
|
80
80
|
"@loaders.gl/draco": "^3.1.6",
|
|
81
81
|
"deep-assign": "^2.0.0",
|