@itwin/core-common 3.6.0-dev.5 → 3.6.0-dev.51

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 (123) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/LICENSE.md +1 -1
  3. package/lib/cjs/AuthorizationClient.d.ts +9 -3
  4. package/lib/cjs/AuthorizationClient.d.ts.map +1 -1
  5. package/lib/cjs/AuthorizationClient.js.map +1 -1
  6. package/lib/cjs/Code.d.ts +20 -7
  7. package/lib/cjs/Code.d.ts.map +1 -1
  8. package/lib/cjs/Code.js +13 -26
  9. package/lib/cjs/Code.js.map +1 -1
  10. package/lib/cjs/ElementMesh.js +2 -2
  11. package/lib/cjs/ElementMesh.js.map +1 -1
  12. package/lib/cjs/ElementProps.d.ts +5 -1
  13. package/lib/cjs/ElementProps.d.ts.map +1 -1
  14. package/lib/cjs/ElementProps.js.map +1 -1
  15. package/lib/cjs/EntityProps.d.ts +2 -1
  16. package/lib/cjs/EntityProps.d.ts.map +1 -1
  17. package/lib/cjs/EntityProps.js +1 -0
  18. package/lib/cjs/EntityProps.js.map +1 -1
  19. package/lib/cjs/IModelError.d.ts +10 -4
  20. package/lib/cjs/IModelError.d.ts.map +1 -1
  21. package/lib/cjs/IModelError.js +3 -4
  22. package/lib/cjs/IModelError.js.map +1 -1
  23. package/lib/cjs/Localization.d.ts.map +1 -1
  24. package/lib/cjs/Localization.js +8 -1
  25. package/lib/cjs/Localization.js.map +1 -1
  26. package/lib/cjs/RealityModelDisplaySettings.d.ts +65 -0
  27. package/lib/cjs/RealityModelDisplaySettings.d.ts.map +1 -1
  28. package/lib/cjs/RealityModelDisplaySettings.js +30 -2
  29. package/lib/cjs/RealityModelDisplaySettings.js.map +1 -1
  30. package/lib/cjs/ViewFlags.d.ts +2 -6
  31. package/lib/cjs/ViewFlags.d.ts.map +1 -1
  32. package/lib/cjs/ViewFlags.js.map +1 -1
  33. package/lib/cjs/core-common.d.ts +0 -1
  34. package/lib/cjs/core-common.d.ts.map +1 -1
  35. package/lib/cjs/core-common.js +0 -1
  36. package/lib/cjs/core-common.js.map +1 -1
  37. package/lib/cjs/geometry/BoundingSphere.d.ts +15 -2
  38. package/lib/cjs/geometry/BoundingSphere.d.ts.map +1 -1
  39. package/lib/cjs/geometry/BoundingSphere.js +18 -4
  40. package/lib/cjs/geometry/BoundingSphere.js.map +1 -1
  41. package/lib/cjs/geometry/FrustumPlanes.d.ts +59 -10
  42. package/lib/cjs/geometry/FrustumPlanes.d.ts.map +1 -1
  43. package/lib/cjs/geometry/FrustumPlanes.js +94 -33
  44. package/lib/cjs/geometry/FrustumPlanes.js.map +1 -1
  45. package/lib/cjs/tile/B3dmTileIO.js +5 -5
  46. package/lib/cjs/tile/B3dmTileIO.js.map +1 -1
  47. package/lib/cjs/tile/CompositeTileIO.js +2 -2
  48. package/lib/cjs/tile/CompositeTileIO.js.map +1 -1
  49. package/lib/cjs/tile/GltfTileIO.js +5 -5
  50. package/lib/cjs/tile/GltfTileIO.js.map +1 -1
  51. package/lib/cjs/tile/I3dmTileIO.js +6 -6
  52. package/lib/cjs/tile/I3dmTileIO.js.map +1 -1
  53. package/lib/cjs/tile/IModelTileIO.js +10 -10
  54. package/lib/cjs/tile/IModelTileIO.js.map +1 -1
  55. package/lib/cjs/tile/PntsTileIO.js +5 -5
  56. package/lib/cjs/tile/PntsTileIO.js.map +1 -1
  57. package/lib/cjs/tile/TileIO.js +3 -3
  58. package/lib/cjs/tile/TileIO.js.map +1 -1
  59. package/lib/esm/AuthorizationClient.d.ts +9 -3
  60. package/lib/esm/AuthorizationClient.d.ts.map +1 -1
  61. package/lib/esm/AuthorizationClient.js.map +1 -1
  62. package/lib/esm/Code.d.ts +20 -7
  63. package/lib/esm/Code.d.ts.map +1 -1
  64. package/lib/esm/Code.js +13 -26
  65. package/lib/esm/Code.js.map +1 -1
  66. package/lib/esm/ElementMesh.js +2 -2
  67. package/lib/esm/ElementMesh.js.map +1 -1
  68. package/lib/esm/ElementProps.d.ts +5 -1
  69. package/lib/esm/ElementProps.d.ts.map +1 -1
  70. package/lib/esm/ElementProps.js.map +1 -1
  71. package/lib/esm/EntityProps.d.ts +2 -1
  72. package/lib/esm/EntityProps.d.ts.map +1 -1
  73. package/lib/esm/EntityProps.js +1 -0
  74. package/lib/esm/EntityProps.js.map +1 -1
  75. package/lib/esm/IModelError.d.ts +10 -4
  76. package/lib/esm/IModelError.d.ts.map +1 -1
  77. package/lib/esm/IModelError.js +3 -2
  78. package/lib/esm/IModelError.js.map +1 -1
  79. package/lib/esm/Localization.d.ts.map +1 -1
  80. package/lib/esm/Localization.js +8 -1
  81. package/lib/esm/Localization.js.map +1 -1
  82. package/lib/esm/RealityModelDisplaySettings.d.ts +65 -0
  83. package/lib/esm/RealityModelDisplaySettings.d.ts.map +1 -1
  84. package/lib/esm/RealityModelDisplaySettings.js +30 -2
  85. package/lib/esm/RealityModelDisplaySettings.js.map +1 -1
  86. package/lib/esm/ViewFlags.d.ts +2 -6
  87. package/lib/esm/ViewFlags.d.ts.map +1 -1
  88. package/lib/esm/ViewFlags.js.map +1 -1
  89. package/lib/esm/core-common.d.ts +0 -1
  90. package/lib/esm/core-common.d.ts.map +1 -1
  91. package/lib/esm/core-common.js +0 -1
  92. package/lib/esm/core-common.js.map +1 -1
  93. package/lib/esm/geometry/BoundingSphere.d.ts +15 -2
  94. package/lib/esm/geometry/BoundingSphere.d.ts.map +1 -1
  95. package/lib/esm/geometry/BoundingSphere.js +18 -4
  96. package/lib/esm/geometry/BoundingSphere.js.map +1 -1
  97. package/lib/esm/geometry/FrustumPlanes.d.ts +59 -10
  98. package/lib/esm/geometry/FrustumPlanes.d.ts.map +1 -1
  99. package/lib/esm/geometry/FrustumPlanes.js +94 -33
  100. package/lib/esm/geometry/FrustumPlanes.js.map +1 -1
  101. package/lib/esm/tile/B3dmTileIO.js +5 -5
  102. package/lib/esm/tile/B3dmTileIO.js.map +1 -1
  103. package/lib/esm/tile/CompositeTileIO.js +2 -2
  104. package/lib/esm/tile/CompositeTileIO.js.map +1 -1
  105. package/lib/esm/tile/GltfTileIO.js +5 -5
  106. package/lib/esm/tile/GltfTileIO.js.map +1 -1
  107. package/lib/esm/tile/I3dmTileIO.js +6 -6
  108. package/lib/esm/tile/I3dmTileIO.js.map +1 -1
  109. package/lib/esm/tile/IModelTileIO.js +10 -10
  110. package/lib/esm/tile/IModelTileIO.js.map +1 -1
  111. package/lib/esm/tile/PntsTileIO.js +5 -5
  112. package/lib/esm/tile/PntsTileIO.js.map +1 -1
  113. package/lib/esm/tile/TileIO.js +3 -3
  114. package/lib/esm/tile/TileIO.js.map +1 -1
  115. package/package.json +7 -7
  116. package/lib/cjs/FeatureGates.d.ts +0 -32
  117. package/lib/cjs/FeatureGates.d.ts.map +0 -1
  118. package/lib/cjs/FeatureGates.js +0 -56
  119. package/lib/cjs/FeatureGates.js.map +0 -1
  120. package/lib/esm/FeatureGates.d.ts +0 -32
  121. package/lib/esm/FeatureGates.d.ts.map +0 -1
  122. package/lib/esm/FeatureGates.js +0 -52
  123. package/lib/esm/FeatureGates.js.map +0 -1
@@ -7,43 +7,104 @@
7
7
  */
8
8
  import { assert } from "@itwin/core-bentley";
9
9
  import { ClipPlane, Vector3d } from "@itwin/core-geometry";
10
+ const planePointIndices = [
11
+ [1, 3, 5],
12
+ [0, 4, 2],
13
+ [2, 6, 3],
14
+ [0, 1, 4],
15
+ [0, 2, 1],
16
+ [4, 5, 6], // front
17
+ ];
18
+ function computeFrustumPlanes(frustum) {
19
+ const planes = [];
20
+ const points = frustum.points;
21
+ const expandPlaneDistance = 1e-6;
22
+ for (const indices of planePointIndices) {
23
+ const i0 = indices[0], i1 = indices[1], i2 = indices[2];
24
+ const normal = Vector3d.createCrossProductToPoints(points[i2], points[i1], points[i0]);
25
+ normal.normalizeInPlace();
26
+ const plane = ClipPlane.createNormalAndDistance(normal, normal.dotProduct(points[i0]) - expandPlaneDistance);
27
+ if (!plane)
28
+ return [];
29
+ planes.push(plane);
30
+ }
31
+ assert(planes.length === 6);
32
+ return planes;
33
+ }
10
34
  // Scratch variable used by FrustumPlanes.computeContainment.
11
35
  const planesContainingSphere = [false, false, false, false, false, false];
12
- /** Represents a frustum as 6 planes and provides containment and intersection testing
13
- * @internal
36
+ /** Represents a the planes of a [[Frustum]] for testing containment and intersection.
37
+ * A valid frustum produces six planes. A degenerate frustum produces zero planes.
38
+ * @public
39
+ * @extensions
14
40
  */
15
41
  export class FrustumPlanes {
16
- constructor(frustum) {
17
- if (undefined !== frustum) {
18
- this.init(frustum);
19
- }
42
+ constructor(planes) {
43
+ this._planes = planes;
44
+ }
45
+ /** Compute the six planes of the specified frustum.
46
+ * If the frustum is degenerate - that is, its points do not represent a truncated pyramid - then the returned `FrustumPlanes` will contain zero planes.
47
+ * @see [[isValid]] to test this condition.
48
+ */
49
+ static fromFrustum(frustum) {
50
+ const planes = computeFrustumPlanes(frustum);
51
+ return new FrustumPlanes(planes);
52
+ }
53
+ /** Create an empty set of frustum planes. [[isValid]] will be `true`. This can be useful when you want to create a `FrustumPlanes` object and initialize it later via [[init]] -
54
+ * for example, if you intend to use the same object repeatedly with different [[Frustum]]s.
55
+ */
56
+ static createEmpty() {
57
+ return new FrustumPlanes([]);
58
+ }
59
+ /** Returns true if [[planes]] consists of six planes. This may return `false` if a degenerate [[Frustum]] was supplied to [[fromFrustum]], or if this object was created
60
+ * via [[createEmpty]] - in either case, [[planes]] will be an empty array.
61
+ */
62
+ get isValid() {
63
+ return this._planes.length === 6;
20
64
  }
21
- get isValid() { return undefined !== this._planes; }
22
- // Order: right, left, top, bottom, back, front
23
- get planes() { return this._planes; }
65
+ /** Obtain the list of planes defining the frustum. If [[isValid]] is `true`, it will have a length of six, with the planes ordered as
66
+ * right, left, top, bottom, back, front. Otherwise, it will be empty.
67
+ */
68
+ get planes() {
69
+ return this._planes;
70
+ }
71
+ /** Recompute the planes from the specified frustum.
72
+ * @returns true upon success, or false if the input frustum was degenerate, in which case [[isValid]] will be `false`.
73
+ */
24
74
  init(frustum) {
25
- if (undefined === this._planes) {
26
- this._planes = [];
27
- }
28
- else {
29
- this._planes.length = 0;
30
- }
31
- FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 1, 3, 5); // right
32
- FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 0, 4, 2); // left
33
- FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 2, 6, 3); // top
34
- FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 0, 1, 4); // bottom
35
- FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 0, 2, 1); // back
36
- FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 4, 5, 6); // front
75
+ this._planes = computeFrustumPlanes(frustum);
76
+ return this.isValid;
37
77
  }
78
+ /** Compute to what degree a [[Frustum]] is contained with these frustum planes.
79
+ * @param box The frustum to test for containment.
80
+ * @param sphere An optional spherical bounding volume fully containing `box`. If supplied, this can reduce the amount of computation required.
81
+ * @returns the degree to which `box` is contained within the clipping planes.
82
+ */
38
83
  computeFrustumContainment(box, sphere) {
39
84
  return this.computeContainment(box.points, sphere);
40
85
  }
86
+ /** Determines whether a [[Frustum]] intersects with or is fully contained within these frustum planes.
87
+ * @param box The frustum to test for containment.
88
+ * @param sphere An optional spherical bounding volume fully containing `box`. If supplied, this can reduce the amount of computation required.
89
+ * @returns true if `box` is not entirely outside of the clipping planes.
90
+ */
41
91
  intersectsFrustum(box, sphere) {
42
92
  return FrustumPlanes.Containment.Outside !== this.computeFrustumContainment(box, sphere);
43
93
  }
94
+ /** Determines whether a point is contained within these frustum planes.
95
+ * @param point The point to test for containment.
96
+ * @param tolerance The maximum distance from the interior of the frustum planes that will still be considered "contained".
97
+ * @returns true if `point` is no further than `tolerance` meters outside of the clipping planes.
98
+ */
44
99
  containsPoint(point, tolerance = 1.0e-8) {
45
100
  return FrustumPlanes.Containment.Outside !== this.computeContainment([point], undefined, tolerance);
46
101
  }
102
+ /** Compute the degree to which a set of points is contained within these frustum planes.
103
+ * @param points The points to test for containment.
104
+ * @param sphere An optional spherical bounding volume fully containing all of the points. If supplied, this can reduce the amount of computation required.
105
+ * @param tolerance The maximum distance from the interior of the frustum planes a point must be to be considered "contained".
106
+ * @returns the degree to which all of the points are contained within the clipping planes.
107
+ */
47
108
  computeContainment(points, sphere, tolerance = 1.0e-8) {
48
109
  assert(this.isValid);
49
110
  if (undefined === this._planes)
@@ -77,6 +138,11 @@ export class FrustumPlanes {
77
138
  }
78
139
  return allInside ? FrustumPlanes.Containment.Inside : FrustumPlanes.Containment.Partial;
79
140
  }
141
+ /** Computes whether a ray intersects these clipping planes.
142
+ * @param origin The origin of the ray.
143
+ * @param direction The direction of the ray.
144
+ * @returns true if the ray extending from `origin` in the specified `direction` intersects at least one of the clipping planes.
145
+ */
80
146
  intersectsRay(origin, direction) {
81
147
  assert(this.isValid);
82
148
  if (undefined === this._planes) {
@@ -106,24 +172,19 @@ export class FrustumPlanes {
106
172
  return tNear <= tFar;
107
173
  }
108
174
  }
109
- /** @internal */
175
+ /** @public @extensions */
110
176
  (function (FrustumPlanes) {
111
- /** @internal */
177
+ /** Describes the degree to which an object is contained within the planes of a [[Frustum]].
178
+ * @see [[FrustumPlanes.computeContainment]], for example.
179
+ */
112
180
  let Containment;
113
181
  (function (Containment) {
182
+ /** The object is entirely outside of the frustum, intersecting none of its planes. */
114
183
  Containment[Containment["Outside"] = 0] = "Outside";
184
+ /** The object intersects at least one of the frustum planes. placing it partially inside of the frustum. */
115
185
  Containment[Containment["Partial"] = 1] = "Partial";
186
+ /** The object is entirely inside of the frustum, intersecting none of its planes. */
116
187
  Containment[Containment["Inside"] = 2] = "Inside";
117
188
  })(Containment = FrustumPlanes.Containment || (FrustumPlanes.Containment = {}));
118
- /** @internal */
119
- function addPlaneFromPoints(planes, points, i0, i1, i2, expandPlaneDistance = 1.0e-6) {
120
- const normal = Vector3d.createCrossProductToPoints(points[i2], points[i1], points[i0]);
121
- normal.normalizeInPlace();
122
- const plane = ClipPlane.createNormalAndDistance(normal, normal.dotProduct(points[i0]) - expandPlaneDistance);
123
- if (undefined !== plane) {
124
- planes.push(plane);
125
- }
126
- }
127
- FrustumPlanes.addPlaneFromPoints = addPlaneFromPoints;
128
189
  })(FrustumPlanes || (FrustumPlanes = {}));
129
190
  //# sourceMappingURL=FrustumPlanes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FrustumPlanes.js","sourceRoot":"","sources":["../../../src/geometry/FrustumPlanes.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAW,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIpE,6DAA6D;AAC7D,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAE1E;;GAEG;AACH,MAAM,OAAO,aAAa;IAGxB,YAAmB,OAAiB;QAClC,IAAI,SAAS,KAAK,OAAO,EAAE;YACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACpB;IACH,CAAC;IAED,IAAW,OAAO,KAAc,OAAO,SAAS,KAAK,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAEpE,+CAA+C;IAC/C,IAAW,MAAM,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAErC,IAAI,CAAC,OAAgB;QAC1B,IAAI,SAAS,KAAK,IAAI,CAAC,OAAO,EAAE;YAC9B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;SACnB;aAAM;YACL,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;SACzB;QAED,aAAa,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,QAAQ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,yBAAW,KAAX,yBAAW,QAItB;IAED,gBAAgB;IAChB,SAAgB,kBAAkB,CAAC,MAAmB,EAAE,MAAiB,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,sBAA8B,MAAM;QACjJ,MAAM,MAAM,GAAG,QAAQ,CAAC,0BAA0B,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QACvF,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,SAAS,CAAC,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC;QAC7G,IAAI,SAAS,KAAK,KAAK,EAAE;YACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpB;IACH,CAAC;IAPe,gCAAkB,qBAOjC,CAAA;AACH,CAAC,EAjBgB,aAAa,KAAb,aAAa,QAiB7B","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 Geometry\r\n */\r\n\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { ClipPlane, Point3d, Vector3d } from \"@itwin/core-geometry\";\r\nimport { Frustum } from \"../Frustum\";\r\nimport { BoundingSphere } from \"./BoundingSphere\";\r\n\r\n// Scratch variable used by FrustumPlanes.computeContainment.\r\nconst planesContainingSphere = [false, false, false, false, false, false];\r\n\r\n/** Represents a frustum as 6 planes and provides containment and intersection testing\r\n * @internal\r\n */\r\nexport class FrustumPlanes {\r\n private _planes?: ClipPlane[];\r\n\r\n public constructor(frustum?: Frustum) {\r\n if (undefined !== frustum) {\r\n this.init(frustum);\r\n }\r\n }\r\n\r\n public get isValid(): boolean { return undefined !== this._planes; }\r\n\r\n // Order: right, left, top, bottom, back, front\r\n public get planes() { return this._planes; }\r\n\r\n public init(frustum: Frustum) {\r\n if (undefined === this._planes) {\r\n this._planes = [];\r\n } else {\r\n this._planes.length = 0;\r\n }\r\n\r\n FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 1, 3, 5); // right\r\n FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 0, 4, 2); // left\r\n FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 2, 6, 3); // top\r\n FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 0, 1, 4); // bottom\r\n FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 0, 2, 1); // back\r\n FrustumPlanes.addPlaneFromPoints(this._planes, frustum.points, 4, 5, 6); // front\r\n }\r\n\r\n public computeFrustumContainment(box: Frustum, sphere?: BoundingSphere): FrustumPlanes.Containment {\r\n return this.computeContainment(box.points, sphere);\r\n }\r\n\r\n public intersectsFrustum(box: Frustum, sphere?: BoundingSphere): boolean {\r\n return FrustumPlanes.Containment.Outside !== this.computeFrustumContainment(box, sphere);\r\n }\r\n\r\n public containsPoint(point: Point3d, tolerance: number = 1.0e-8): boolean {\r\n return FrustumPlanes.Containment.Outside !== this.computeContainment([point], undefined, tolerance);\r\n }\r\n\r\n public computeContainment(points: Point3d[], sphere?: BoundingSphere, tolerance: number = 1.0e-8): FrustumPlanes.Containment {\r\n assert(this.isValid);\r\n if (undefined === this._planes)\r\n return FrustumPlanes.Containment.Outside;\r\n\r\n // Do the cheap test against bounding sphere first.\r\n if (sphere) {\r\n for (let i = 0; i < this._planes.length; i++) {\r\n const plane = this._planes[i];\r\n const centerDistance = plane.altitude(sphere.center);\r\n const tolerancePlusRadius = tolerance + sphere.radius;\r\n if (centerDistance < -tolerancePlusRadius)\r\n return FrustumPlanes.Containment.Outside;\r\n\r\n planesContainingSphere[i] = centerDistance > tolerancePlusRadius;\r\n }\r\n }\r\n\r\n // Test against points.\r\n let allInside = true;\r\n for (let i = 0; i < this._planes.length; i++) {\r\n if (sphere && planesContainingSphere[i])\r\n continue;\r\n\r\n const plane = this._planes[i];\r\n let nOutside = 0;\r\n for (const point of points) {\r\n if (plane.altitude(point) + tolerance < 0) {\r\n ++nOutside;\r\n allInside = false;\r\n }\r\n }\r\n\r\n if (nOutside === points.length)\r\n return FrustumPlanes.Containment.Outside;\r\n }\r\n\r\n return allInside ? FrustumPlanes.Containment.Inside : FrustumPlanes.Containment.Partial;\r\n }\r\n\r\n public intersectsRay(origin: Point3d, direction: Vector3d): boolean {\r\n assert(this.isValid);\r\n if (undefined === this._planes) {\r\n return false;\r\n }\r\n\r\n let tFar = 1e37;\r\n let tNear = -tFar;\r\n\r\n for (const plane of this._planes) {\r\n const vD = plane.velocity(direction);\r\n const vN = plane.altitude(origin);\r\n if (0.0 === vD) {\r\n // ray is parallel... no need to continue testing if outside halfspace.\r\n if (vN < 0.0) {\r\n return false;\r\n }\r\n } else {\r\n const rayDistance = -vN / vD;\r\n if (vD < 0.0) {\r\n tFar = Math.min(rayDistance, tFar);\r\n } else {\r\n tNear = Math.max(rayDistance, tNear);\r\n }\r\n }\r\n }\r\n\r\n return tNear <= tFar;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport namespace FrustumPlanes { // eslint-disable-line no-redeclare\r\n /** @internal */\r\n export enum Containment {\r\n Outside = 0,\r\n Partial = 1,\r\n Inside = 2,\r\n }\r\n\r\n /** @internal */\r\n export function addPlaneFromPoints(planes: ClipPlane[], points: Point3d[], i0: number, i1: number, i2: number, expandPlaneDistance: number = 1.0e-6): void {\r\n const normal = Vector3d.createCrossProductToPoints(points[i2], points[i1], points[i0]);\r\n normal.normalizeInPlace();\r\n const plane = ClipPlane.createNormalAndDistance(normal, normal.dotProduct(points[i0]) - expandPlaneDistance);\r\n if (undefined !== plane) {\r\n planes.push(plane);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"FrustumPlanes.js","sourceRoot":"","sources":["../../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AAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;iBACpC;qBAAM;oBACL,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;iBACtC;aACF;SACF;QAED,OAAO,KAAK,IAAI,IAAI,CAAC;IACvB,CAAC;CACF;AAED,0BAA0B;AAC1B,WAAiB,aAAa;IAC5B;;OAEG;IACH,IAAY,WAOX;IAPD,WAAY,WAAW;QACrB,sFAAsF;QACtF,mDAAW,CAAA;QACX,4GAA4G;QAC5G,mDAAW,CAAA;QACX,qFAAqF;QACrF,iDAAU,CAAA;IACZ,CAAC,EAPW,WAAW,GAAX,yBAAW,KAAX,yBAAW,QAOtB;AACH,CAAC,EAZgB,aAAa,KAAb,aAAa,QAY7B","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 Geometry\r\n */\r\n\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { ClipPlane, Point3d, Vector3d } from \"@itwin/core-geometry\";\r\nimport { Frustum } from \"../Frustum\";\r\nimport { BoundingSphere } from \"./BoundingSphere\";\r\n\r\nconst planePointIndices = [\r\n [1, 3, 5], // right\r\n [0, 4, 2], // left\r\n [2, 6, 3], // top\r\n [0, 1, 4], // bottom\r\n [0, 2, 1], // back\r\n [4, 5, 6], // front\r\n];\r\n\r\nfunction computeFrustumPlanes(frustum: Frustum): ClipPlane[] {\r\n const planes = [];\r\n const points = frustum.points;\r\n const expandPlaneDistance = 1e-6;\r\n\r\n for (const indices of planePointIndices) {\r\n const i0 = indices[0], i1 = indices[1], i2 = indices[2];\r\n const normal = Vector3d.createCrossProductToPoints(points[i2], points[i1], points[i0]);\r\n normal.normalizeInPlace();\r\n\r\n const plane = ClipPlane.createNormalAndDistance(normal, normal.dotProduct(points[i0]) - expandPlaneDistance);\r\n if (!plane)\r\n return [];\r\n\r\n planes.push(plane);\r\n }\r\n\r\n assert(planes.length === 6);\r\n return planes;\r\n}\r\n\r\n// Scratch variable used by FrustumPlanes.computeContainment.\r\nconst planesContainingSphere = [false, false, false, false, false, false];\r\n\r\n/** Represents a the planes of a [[Frustum]] for testing containment and intersection.\r\n * A valid frustum produces six planes. A degenerate frustum produces zero planes.\r\n * @public\r\n * @extensions\r\n */\r\nexport class FrustumPlanes {\r\n private _planes: ClipPlane[];\r\n\r\n private constructor(planes: ClipPlane[]) {\r\n this._planes = planes;\r\n }\r\n\r\n /** Compute the six planes of the specified frustum.\r\n * If the frustum is degenerate - that is, its points do not represent a truncated pyramid - then the returned `FrustumPlanes` will contain zero planes.\r\n * @see [[isValid]] to test this condition.\r\n */\r\n public static fromFrustum(frustum: Frustum): FrustumPlanes {\r\n const planes = computeFrustumPlanes(frustum);\r\n return new FrustumPlanes(planes);\r\n }\r\n\r\n /** Create an empty set of frustum planes. [[isValid]] will be `true`. This can be useful when you want to create a `FrustumPlanes` object and initialize it later via [[init]] -\r\n * for example, if you intend to use the same object repeatedly with different [[Frustum]]s.\r\n */\r\n public static createEmpty(): FrustumPlanes {\r\n return new FrustumPlanes([]);\r\n }\r\n\r\n /** Returns true if [[planes]] consists of six planes. This may return `false` if a degenerate [[Frustum]] was supplied to [[fromFrustum]], or if this object was created\r\n * via [[createEmpty]] - in either case, [[planes]] will be an empty array.\r\n */\r\n public get isValid(): boolean {\r\n return this._planes.length === 6;\r\n }\r\n\r\n /** Obtain the list of planes defining the frustum. If [[isValid]] is `true`, it will have a length of six, with the planes ordered as\r\n * right, left, top, bottom, back, front. Otherwise, it will be empty.\r\n */\r\n public get planes(): ClipPlane[] {\r\n return this._planes;\r\n }\r\n\r\n /** Recompute the planes from the specified frustum.\r\n * @returns true upon success, or false if the input frustum was degenerate, in which case [[isValid]] will be `false`.\r\n */\r\n public init(frustum: Frustum): boolean {\r\n this._planes = computeFrustumPlanes(frustum);\r\n return this.isValid;\r\n }\r\n\r\n /** Compute to what degree a [[Frustum]] is contained with these frustum planes.\r\n * @param box The frustum to test for containment.\r\n * @param sphere An optional spherical bounding volume fully containing `box`. If supplied, this can reduce the amount of computation required.\r\n * @returns the degree to which `box` is contained within the clipping planes.\r\n */\r\n public computeFrustumContainment(box: Frustum, sphere?: BoundingSphere): FrustumPlanes.Containment {\r\n return this.computeContainment(box.points, sphere);\r\n }\r\n\r\n /** Determines whether a [[Frustum]] intersects with or is fully contained within these frustum planes.\r\n * @param box The frustum to test for containment.\r\n * @param sphere An optional spherical bounding volume fully containing `box`. If supplied, this can reduce the amount of computation required.\r\n * @returns true if `box` is not entirely outside of the clipping planes.\r\n */\r\n public intersectsFrustum(box: Frustum, sphere?: BoundingSphere): boolean {\r\n return FrustumPlanes.Containment.Outside !== this.computeFrustumContainment(box, sphere);\r\n }\r\n\r\n /** Determines whether a point is contained within these frustum planes.\r\n * @param point The point to test for containment.\r\n * @param tolerance The maximum distance from the interior of the frustum planes that will still be considered \"contained\".\r\n * @returns true if `point` is no further than `tolerance` meters outside of the clipping planes.\r\n */\r\n public containsPoint(point: Point3d, tolerance: number = 1.0e-8): boolean {\r\n return FrustumPlanes.Containment.Outside !== this.computeContainment([point], undefined, tolerance);\r\n }\r\n\r\n /** Compute the degree to which a set of points is contained within these frustum planes.\r\n * @param points The points to test for containment.\r\n * @param sphere An optional spherical bounding volume fully containing all of the points. If supplied, this can reduce the amount of computation required.\r\n * @param tolerance The maximum distance from the interior of the frustum planes a point must be to be considered \"contained\".\r\n * @returns the degree to which all of the points are contained within the clipping planes.\r\n */\r\n public computeContainment(points: Point3d[], sphere?: BoundingSphere, tolerance: number = 1.0e-8): FrustumPlanes.Containment {\r\n assert(this.isValid);\r\n if (undefined === this._planes)\r\n return FrustumPlanes.Containment.Outside;\r\n\r\n // Do the cheap test against bounding sphere first.\r\n if (sphere) {\r\n for (let i = 0; i < this._planes.length; i++) {\r\n const plane = this._planes[i];\r\n const centerDistance = plane.altitude(sphere.center);\r\n const tolerancePlusRadius = tolerance + sphere.radius;\r\n if (centerDistance < -tolerancePlusRadius)\r\n return FrustumPlanes.Containment.Outside;\r\n\r\n planesContainingSphere[i] = centerDistance > tolerancePlusRadius;\r\n }\r\n }\r\n\r\n // Test against points.\r\n let allInside = true;\r\n for (let i = 0; i < this._planes.length; i++) {\r\n if (sphere && planesContainingSphere[i])\r\n continue;\r\n\r\n const plane = this._planes[i];\r\n let nOutside = 0;\r\n for (const point of points) {\r\n if (plane.altitude(point) + tolerance < 0) {\r\n ++nOutside;\r\n allInside = false;\r\n }\r\n }\r\n\r\n if (nOutside === points.length)\r\n return FrustumPlanes.Containment.Outside;\r\n }\r\n\r\n return allInside ? FrustumPlanes.Containment.Inside : FrustumPlanes.Containment.Partial;\r\n }\r\n\r\n /** Computes whether a ray intersects these clipping planes.\r\n * @param origin The origin of the ray.\r\n * @param direction The direction of the ray.\r\n * @returns true if the ray extending from `origin` in the specified `direction` intersects at least one of the clipping planes.\r\n */\r\n public intersectsRay(origin: Point3d, direction: Vector3d): boolean {\r\n assert(this.isValid);\r\n if (undefined === this._planes) {\r\n return false;\r\n }\r\n\r\n let tFar = 1e37;\r\n let tNear = -tFar;\r\n\r\n for (const plane of this._planes) {\r\n const vD = plane.velocity(direction);\r\n const vN = plane.altitude(origin);\r\n if (0.0 === vD) {\r\n // ray is parallel... no need to continue testing if outside halfspace.\r\n if (vN < 0.0) {\r\n return false;\r\n }\r\n } else {\r\n const rayDistance = -vN / vD;\r\n if (vD < 0.0) {\r\n tFar = Math.min(rayDistance, tFar);\r\n } else {\r\n tNear = Math.max(rayDistance, tNear);\r\n }\r\n }\r\n }\r\n\r\n return tNear <= tFar;\r\n }\r\n}\r\n\r\n/** @public @extensions */\r\nexport namespace FrustumPlanes { // eslint-disable-line no-redeclare\r\n /** Describes the degree to which an object is contained within the planes of a [[Frustum]].\r\n * @see [[FrustumPlanes.computeContainment]], for example.\r\n */\r\n export enum Containment {\r\n /** The object is entirely outside of the frustum, intersecting none of its planes. */\r\n Outside = 0,\r\n /** The object intersects at least one of the frustum planes. placing it partially inside of the frustum. */\r\n Partial = 1,\r\n /** The object is entirely inside of the frustum, intersecting none of its planes. */\r\n Inside = 2,\r\n }\r\n}\r\n"]}
@@ -13,11 +13,11 @@ import { TileFormat, TileHeader } from "./TileIO";
13
13
  export class B3dmHeader extends TileHeader {
14
14
  constructor(stream) {
15
15
  super(stream);
16
- this.length = stream.nextUint32;
17
- this.featureTableJsonLength = stream.nextUint32;
18
- this.featureTableBinaryLength = stream.nextUint32;
19
- this.batchTableJsonLength = stream.nextUint32;
20
- this.batchTableBinaryLength = stream.nextUint32;
16
+ this.length = stream.readUint32();
17
+ this.featureTableJsonLength = stream.readUint32();
18
+ this.featureTableBinaryLength = stream.readUint32();
19
+ this.batchTableJsonLength = stream.readUint32();
20
+ this.batchTableBinaryLength = stream.readUint32();
21
21
  // Keep this legacy check in for now since a lot of tilesets are still using the old header.
22
22
  // Legacy header #1: [batchLength] [batchTableByteLength]
23
23
  // Legacy header #2: [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength]
@@ -1 +1 @@
1
- {"version":3,"file":"B3dmTileIO.js","sourceRoot":"","sources":["../../../src/tile/B3dmTileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAc,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;IAUxC,YAAmB,MAAkB;QACnC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC;QAChC,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,UAAU,CAAC;QAChD,IAAI,CAAC,wBAAwB,GAAG,MAAM,CAAC,UAAU,CAAC;QAClD,IAAI,CAAC,oBA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ACnC,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YACjE,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;YAC5C,IAAI,QAAQ;gBACV,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAC9C;QAED,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAE5C,IAAI,MAAM,CAAC,YAAY;YACrB,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IApDD,IAAW,OAAO,KAAc,OAAO,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;CAqD1E","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 Tile\r\n */\r\n\r\nimport { ByteStream, utf8ToString } from \"@itwin/core-bentley\";\r\nimport { TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Header preceding tile content in [b3dm](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/TileFormats/Batched3DModel) format.\r\n * @internal\r\n */\r\nexport class B3dmHeader extends TileHeader {\r\n public readonly length: number;\r\n public readonly featureTableJsonLength: number;\r\n public readonly featureTableBinaryLength: number;\r\n public readonly batchTableJsonLength: number;\r\n public readonly batchTableBinaryLength: number;\r\n public readonly featureTableJson: any;\r\n public readonly batchTableJson: any;\r\n public get isValid(): boolean { return TileFormat.B3dm === this.format; }\r\n\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.length = stream.nextUint32;\r\n this.featureTableJsonLength = stream.nextUint32;\r\n this.featureTableBinaryLength = stream.nextUint32;\r\n this.batchTableJsonLength = stream.nextUint32;\r\n this.batchTableBinaryLength = stream.nextUint32;\r\n\r\n // Keep this legacy check in for now since a lot of tilesets are still using the old header.\r\n // Legacy header #1: [batchLength] [batchTableByteLength]\r\n // Legacy header #2: [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength]\r\n // Current header: [featureTableJsonByteLength] [featureTableBinaryByteLength] [batchTableJsonByteLength] [batchTableBinaryByteLength]\r\n // If the header is in the first legacy format 'batchTableJsonByteLength' will be the start of the JSON string (a quotation mark) or the glTF magic.\r\n // Accordingly its first byte will be either 0x22 or 0x67, and so the minimum uint32 expected is 0x22000000 = 570425344 = 570MB. It is unlikely that the feature table Json will exceed this length.\r\n // The check for the second legacy format is similar, except it checks 'batchTableBinaryByteLength' instead\r\n if (this.batchTableJsonLength >= 570425344) {\r\n // First legacy check\r\n stream.curPos = 20;\r\n this.batchTableJsonLength = this.featureTableBinaryLength;\r\n this.batchTableBinaryLength = 0;\r\n this.featureTableJsonLength = 0;\r\n this.featureTableBinaryLength = 0;\r\n } else if (this.batchTableBinaryLength >= 570425344) {\r\n // Second legacy check\r\n stream.curPos = 24;\r\n this.batchTableJsonLength = this.featureTableJsonLength;\r\n this.batchTableBinaryLength = this.featureTableBinaryLength;\r\n this.featureTableJsonLength = 0;\r\n this.featureTableBinaryLength = 0;\r\n }\r\n\r\n if (0 !== this.featureTableJsonLength) {\r\n const sceneStrData = stream.nextBytes(this.featureTableJsonLength);\r\n const sceneStr = utf8ToString(sceneStrData);\r\n if (sceneStr)\r\n this.featureTableJson = JSON.parse(sceneStr);\r\n }\r\n\r\n stream.advance(this.featureTableBinaryLength);\r\n if (0 !== this.batchTableJsonLength) {\r\n const batchStrData = stream.nextBytes(this.batchTableJsonLength);\r\n const batchStr = utf8ToString(batchStrData);\r\n if (batchStr)\r\n this.batchTableJson = JSON.parse(batchStr);\r\n }\r\n\r\n stream.advance(this.batchTableBinaryLength);\r\n\r\n if (stream.isPastTheEnd)\r\n this.invalidate();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"B3dmTileIO.js","sourceRo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,wBAAwB,CAAC;YAC5D,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC;YAChC,IAAI,CAAC,wBAAwB,GAAG,CAAC,CAAC;SACnC;QAED,IAAI,CAAC,KAAK,IAAI,CAAC,sBAAsB,EAAE;YACrC,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;YACnE,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;YAC5C,IAAI,QAAQ;gBACV,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAChD;QAED,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAC9C,IAAI,CAAC,KAAK,IAAI,CAAC,oBAAoB,EAAE;YACnC,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YACjE,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;YAC5C,IAAI,QAAQ;gBACV,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAC9C;QAED,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAE5C,IAAI,MAAM,CAAC,YAAY;YACrB,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IApDD,IAAW,OAAO,KAAc,OAAO,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;CAqD1E","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 Tile\r\n */\r\n\r\nimport { ByteStream, utf8ToString } from \"@itwin/core-bentley\";\r\nimport { TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Header preceding tile content in [b3dm](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/TileFormats/Batched3DModel) format.\r\n * @internal\r\n */\r\nexport class B3dmHeader extends TileHeader {\r\n public readonly length: number;\r\n public readonly featureTableJsonLength: number;\r\n public readonly featureTableBinaryLength: number;\r\n public readonly batchTableJsonLength: number;\r\n public readonly batchTableBinaryLength: number;\r\n public readonly featureTableJson: any;\r\n public readonly batchTableJson: any;\r\n public get isValid(): boolean { return TileFormat.B3dm === this.format; }\r\n\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.length = stream.readUint32();\r\n this.featureTableJsonLength = stream.readUint32();\r\n this.featureTableBinaryLength = stream.readUint32();\r\n this.batchTableJsonLength = stream.readUint32();\r\n this.batchTableBinaryLength = stream.readUint32();\r\n\r\n // Keep this legacy check in for now since a lot of tilesets are still using the old header.\r\n // Legacy header #1: [batchLength] [batchTableByteLength]\r\n // Legacy header #2: [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength]\r\n // Current header: [featureTableJsonByteLength] [featureTableBinaryByteLength] [batchTableJsonByteLength] [batchTableBinaryByteLength]\r\n // If the header is in the first legacy format 'batchTableJsonByteLength' will be the start of the JSON string (a quotation mark) or the glTF magic.\r\n // Accordingly its first byte will be either 0x22 or 0x67, and so the minimum uint32 expected is 0x22000000 = 570425344 = 570MB. It is unlikely that the feature table Json will exceed this length.\r\n // The check for the second legacy format is similar, except it checks 'batchTableBinaryByteLength' instead\r\n if (this.batchTableJsonLength >= 570425344) {\r\n // First legacy check\r\n stream.curPos = 20;\r\n this.batchTableJsonLength = this.featureTableBinaryLength;\r\n this.batchTableBinaryLength = 0;\r\n this.featureTableJsonLength = 0;\r\n this.featureTableBinaryLength = 0;\r\n } else if (this.batchTableBinaryLength >= 570425344) {\r\n // Second legacy check\r\n stream.curPos = 24;\r\n this.batchTableJsonLength = this.featureTableJsonLength;\r\n this.batchTableBinaryLength = this.featureTableBinaryLength;\r\n this.featureTableJsonLength = 0;\r\n this.featureTableBinaryLength = 0;\r\n }\r\n\r\n if (0 !== this.featureTableJsonLength) {\r\n const sceneStrData = stream.nextBytes(this.featureTableJsonLength);\r\n const sceneStr = utf8ToString(sceneStrData);\r\n if (sceneStr)\r\n this.featureTableJson = JSON.parse(sceneStr);\r\n }\r\n\r\n stream.advance(this.featureTableBinaryLength);\r\n if (0 !== this.batchTableJsonLength) {\r\n const batchStrData = stream.nextBytes(this.batchTableJsonLength);\r\n const batchStr = utf8ToString(batchStrData);\r\n if (batchStr)\r\n this.batchTableJson = JSON.parse(batchStr);\r\n }\r\n\r\n stream.advance(this.batchTableBinaryLength);\r\n\r\n if (stream.isPastTheEnd)\r\n this.invalidate();\r\n }\r\n}\r\n"]}
@@ -12,8 +12,8 @@ import { TileFormat, TileHeader } from "./TileIO";
12
12
  export class CompositeTileHeader extends TileHeader {
13
13
  constructor(stream) {
14
14
  super(stream);
15
- this.length = stream.nextUint32;
16
- this.tileCount = stream.nextUint32;
15
+ this.length = stream.readUint32();
16
+ this.tileCount = stream.readUint32();
17
17
  this.tilePosition = stream.curPos;
18
18
  if (stream.isPastTheEnd)
19
19
  this.invalidate();
@@ -1 +1 @@
1
- {"version":3,"file":"CompositeTileIO.js","sourceRoot":"","sources":["../../../src/tile/CompositeTileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IAOjD,YAAmB,MAAkB;QACnC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;QAElC,IAAI,MAAM,CAAC,YAAY;YACrB,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAVD,IAAW,OAAO,KAAc,OAAO,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;CAW1E","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 Tile\r\n */\r\n\r\nimport { ByteStream } from \"@itwin/core-bentley\";\r\nimport { TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Header preceding tile content in [composite](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/TileFormats/Composite) format, containing any number of tiles in other standard 3D tile formats.\r\n * @internal\r\n */\r\nexport class CompositeTileHeader extends TileHeader {\r\n public readonly length: number;\r\n public readonly tileCount: number;\r\n public readonly tilePosition: number;\r\n\r\n public get isValid(): boolean { return TileFormat.Cmpt === this.format; }\r\n\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.length = stream.nextUint32;\r\n this.tileCount = stream.nextUint32;\r\n this.tilePosition = stream.curPos;\r\n\r\n if (stream.isPastTheEnd)\r\n this.invalidate();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CompositeTileIO.js","sourceRoot":"","sources":["../../../src/tile/CompositeTileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IAOjD,YAAmB,MAAkB;QACnC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;QAElC,IAAI,MAAM,CAAC,YAAY;YACrB,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAVD,IAAW,OAAO,KAAc,OAAO,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;CAW1E","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 Tile\r\n */\r\n\r\nimport { ByteStream } from \"@itwin/core-bentley\";\r\nimport { TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Header preceding tile content in [composite](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/TileFormats/Composite) format, containing any number of tiles in other standard 3D tile formats.\r\n * @internal\r\n */\r\nexport class CompositeTileHeader extends TileHeader {\r\n public readonly length: number;\r\n public readonly tileCount: number;\r\n public readonly tilePosition: number;\r\n\r\n public get isValid(): boolean { return TileFormat.Cmpt === this.format; }\r\n\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.length = stream.readUint32();\r\n this.tileCount = stream.readUint32();\r\n this.tilePosition = stream.curPos;\r\n\r\n if (stream.isPastTheEnd)\r\n this.invalidate();\r\n }\r\n}\r\n"]}
@@ -27,8 +27,8 @@ function consumeNextChunk(stream) {
27
27
  if (stream.isAtTheEnd)
28
28
  return undefined;
29
29
  const offset = stream.curPos + 8;
30
- const length = stream.nextUint32;
31
- const type = stream.nextUint32;
30
+ const length = stream.readUint32();
31
+ const type = stream.readUint32();
32
32
  stream.advance(length);
33
33
  return stream.isPastTheEnd ? false : { offset, length, type };
34
34
  }
@@ -39,9 +39,9 @@ export class GlbHeader extends TileHeader {
39
39
  this.gltfLength = 0;
40
40
  this.jsonChunk = { offset: 0, length: 0 };
41
41
  this.additionalChunks = [];
42
- this.gltfLength = stream.nextUint32;
43
- const jsonLength = stream.nextUint32;
44
- const word5 = stream.nextUint32;
42
+ this.gltfLength = stream.readUint32();
43
+ const jsonLength = stream.readUint32();
44
+ const word5 = stream.readUint32();
45
45
  // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles
46
46
  // validating the chunk type.
47
47
  if (this.version === GltfVersions.Version2 && word5 === GltfVersions.Gltf1SceneFormat)
@@ -1 +1 @@
1
- {"version":3,"file":"GltfTileIO.js","sourceRoot":"","sources":["../../../src/tile/GltfTileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAc,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,CAAN,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,uDAAY,CAAA;IACZ,mEAAyB,CAAA;IACzB,uEAAoB,CAAA;AACtB,CAAC,EALW,YAAY,KAAZ,YAAY,QAKvB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,gEAAiB,CAAA;IACjB,iEAAmB,CAAA;AACrB,CAAC,EAHW,gBAAgB,KAAhB,gBAAgB,QAG3B;AAmBD,SAAS,gBAAgB,CAAC,MAAkB;IAC1C,IAAI,MAAM,CAAC,UAAU;QACnB,OAAO,SAAS,CAAC;IAEnB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC;IACjC,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC;IAC/B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AA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C,UAAU,CAAC,CAAC;gBAC3B,IAAI,MAAM,CAAC,YAAY,EAAE;oBACvB,IAAI,CAAC,UAAU,EAAE,CAAC;oBAClB,OAAO;iBACR;gBAED,IAAI,KAAK,CAAC;gBACV,OAAO,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC,EAAE;oBACvC,QAAQ,KAAK,CAAC,IAAI,EAAE;wBAClB,KAAK,gBAAgB,CAAC,IAAI;4BACxB,0DAA0D;4BAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;4BAClB,OAAO;wBACT,KAAK,gBAAgB,CAAC,MAAM;4BAC1B,2EAA2E;4BAC3E,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE;gCACpD,IAAI,CAAC,UAAU,EAAE,CAAC;gCAClB,OAAO;6BACR;4BAED,IAAI,CAAC,WAAW,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;4BAClE,MAAM;wBACR;4BACE,kEAAkE;4BAClE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;4BAClC,MAAM;qBACT;iBACF;gBAED,IAAI,KAAK,KAAK,KAAK,EAAE;oBACnB,IAAI,CAAC,UAAU,EAAE,CAAC;oBAClB,OAAO;iBACR;gBAED,MAAM,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC;gBAC5B,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAC1B,MAAM;YACR;gBACE,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClB,MAAM;SACT;IACH,CAAC;IA1ED,IAAW,OAAO;QAChB,OAAO,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC;IACzC,CAAC;CAyEF","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 Tile\r\n */\r\n\r\nimport { assert, ByteStream } from \"@itwin/core-bentley\";\r\nimport { TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Known version of the [glTF format](https://www.khronos.org/gltf/).\r\n * @internal\r\n */\r\nexport enum GltfVersions {\r\n Version1 = 1,\r\n Version2 = 2,\r\n CurrentVersion = Version1,\r\n Gltf1SceneFormat = 0,\r\n}\r\n\r\n/** @internal */\r\nexport enum GltfV2ChunkTypes {\r\n JSON = 0x4E4F534a,\r\n Binary = 0x004E4942,\r\n}\r\n\r\n/** A chunk of a glb file.\r\n * @internal\r\n */\r\nexport interface GltfChunk {\r\n /** Offset of the first byte of the chunk's data relative to the beginning of the glb data.\r\n * This excludes the 8-byte chunk header containing the length and type fields.\r\n */\r\n offset: number;\r\n /** The number of bytes in the chunk's data. */\r\n length: number;\r\n}\r\n\r\n/** Describes a glTF chunk's data along with its type.\r\n * @internal\r\n */\r\nexport type TypedGltfChunk = GltfChunk & { type: number };\r\n\r\nfunction consumeNextChunk(stream: ByteStream): TypedGltfChunk | undefined | false {\r\n if (stream.isAtTheEnd)\r\n return undefined;\r\n\r\n const offset = stream.curPos + 8;\r\n const length = stream.nextUint32;\r\n const type = stream.nextUint32;\r\n stream.advance(length);\r\n return stream.isPastTheEnd ? false : { offset, length, type };\r\n}\r\n\r\n/** @internal */\r\nexport class GlbHeader extends TileHeader {\r\n public readonly gltfLength: number = 0;\r\n public readonly jsonChunk: GltfChunk = { offset: 0, length: 0 };\r\n public readonly binaryChunk?: GltfChunk;\r\n public readonly additionalChunks: TypedGltfChunk[] = [];\r\n\r\n public get isValid(): boolean {\r\n return TileFormat.Gltf === this.format;\r\n }\r\n\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.gltfLength = stream.nextUint32;\r\n\r\n const jsonLength = stream.nextUint32;\r\n const word5 = stream.nextUint32;\r\n\r\n // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles\r\n // validating the chunk type.\r\n if (this.version === GltfVersions.Version2 && word5 === GltfVersions.Gltf1SceneFormat)\r\n this.version = GltfVersions.Version1;\r\n\r\n this.jsonChunk = { offset: stream.curPos, length: jsonLength };\r\n switch (this.version) {\r\n case GltfVersions.Version1:\r\n if (GltfVersions.Gltf1SceneFormat !== word5) {\r\n this.invalidate();\r\n return;\r\n }\r\n\r\n const binaryOffset = stream.curPos + jsonLength;\r\n this.binaryChunk = { offset: binaryOffset, length: this.gltfLength - binaryOffset };\r\n break;\r\n case GltfVersions.Version2:\r\n if (word5 !== GltfV2ChunkTypes.JSON) {\r\n this.invalidate();\r\n return;\r\n }\r\n\r\n stream.advance(jsonLength);\r\n if (stream.isPastTheEnd) {\r\n this.invalidate();\r\n return;\r\n }\r\n\r\n let chunk;\r\n while (chunk = consumeNextChunk(stream)) {\r\n switch (chunk.type) {\r\n case GltfV2ChunkTypes.JSON:\r\n // Only one JSON chunk permitted and it must be the first.\r\n this.invalidate();\r\n return;\r\n case GltfV2ChunkTypes.Binary:\r\n // At most one binary chunk permitted and it must be the second if present.\r\n if (this.binaryChunk || this.additionalChunks.length) {\r\n this.invalidate();\r\n return;\r\n }\r\n\r\n this.binaryChunk = { offset: chunk.offset, length: chunk.length };\r\n break;\r\n default:\r\n // Any other chunk type should be ignored - for use by extensions.\r\n this.additionalChunks.push(chunk);\r\n break;\r\n }\r\n }\r\n\r\n if (false === chunk) {\r\n this.invalidate();\r\n return;\r\n }\r\n\r\n assert(undefined === chunk);\r\n assert(stream.isAtTheEnd);\r\n break;\r\n default:\r\n this.invalidate();\r\n break;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"GltfTileIO.js","sourceRoot":"","sources":["../../../src/tile/GltfTileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAc,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,U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IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE;gCACpD,IAAI,CAAC,UAAU,EAAE,CAAC;gCAClB,OAAO;6BACR;4BAED,IAAI,CAAC,WAAW,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;4BAClE,MAAM;wBACR;4BACE,kEAAkE;4BAClE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;4BAClC,MAAM;qBACT;iBACF;gBAED,IAAI,KAAK,KAAK,KAAK,EAAE;oBACnB,IAAI,CAAC,UAAU,EAAE,CAAC;oBAClB,OAAO;iBACR;gBAED,MAAM,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC;gBAC5B,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAC1B,MAAM;YACR;gBACE,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClB,MAAM;SACT;IACH,CAAC;IA1ED,IAAW,OAAO;QAChB,OAAO,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC;IACzC,CAAC;CAyEF","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 Tile\r\n */\r\n\r\nimport { assert, ByteStream } from \"@itwin/core-bentley\";\r\nimport { TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Known version of the [glTF format](https://www.khronos.org/gltf/).\r\n * @internal\r\n */\r\nexport enum GltfVersions {\r\n Version1 = 1,\r\n Version2 = 2,\r\n CurrentVersion = Version1,\r\n Gltf1SceneFormat = 0,\r\n}\r\n\r\n/** @internal */\r\nexport enum GltfV2ChunkTypes {\r\n JSON = 0x4E4F534a,\r\n Binary = 0x004E4942,\r\n}\r\n\r\n/** A chunk of a glb file.\r\n * @internal\r\n */\r\nexport interface GltfChunk {\r\n /** Offset of the first byte of the chunk's data relative to the beginning of the glb data.\r\n * This excludes the 8-byte chunk header containing the length and type fields.\r\n */\r\n offset: number;\r\n /** The number of bytes in the chunk's data. */\r\n length: number;\r\n}\r\n\r\n/** Describes a glTF chunk's data along with its type.\r\n * @internal\r\n */\r\nexport type TypedGltfChunk = GltfChunk & { type: number };\r\n\r\nfunction consumeNextChunk(stream: ByteStream): TypedGltfChunk | undefined | false {\r\n if (stream.isAtTheEnd)\r\n return undefined;\r\n\r\n const offset = stream.curPos + 8;\r\n const length = stream.readUint32();\r\n const type = stream.readUint32();\r\n stream.advance(length);\r\n return stream.isPastTheEnd ? false : { offset, length, type };\r\n}\r\n\r\n/** @internal */\r\nexport class GlbHeader extends TileHeader {\r\n public readonly gltfLength: number = 0;\r\n public readonly jsonChunk: GltfChunk = { offset: 0, length: 0 };\r\n public readonly binaryChunk?: GltfChunk;\r\n public readonly additionalChunks: TypedGltfChunk[] = [];\r\n\r\n public get isValid(): boolean {\r\n return TileFormat.Gltf === this.format;\r\n }\r\n\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.gltfLength = stream.readUint32();\r\n\r\n const jsonLength = stream.readUint32();\r\n const word5 = stream.readUint32();\r\n\r\n // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles\r\n // validating the chunk type.\r\n if (this.version === GltfVersions.Version2 && word5 === GltfVersions.Gltf1SceneFormat)\r\n this.version = GltfVersions.Version1;\r\n\r\n this.jsonChunk = { offset: stream.curPos, length: jsonLength };\r\n switch (this.version) {\r\n case GltfVersions.Version1:\r\n if (GltfVersions.Gltf1SceneFormat !== word5) {\r\n this.invalidate();\r\n return;\r\n }\r\n\r\n const binaryOffset = stream.curPos + jsonLength;\r\n this.binaryChunk = { offset: binaryOffset, length: this.gltfLength - binaryOffset };\r\n break;\r\n case GltfVersions.Version2:\r\n if (word5 !== GltfV2ChunkTypes.JSON) {\r\n this.invalidate();\r\n return;\r\n }\r\n\r\n stream.advance(jsonLength);\r\n if (stream.isPastTheEnd) {\r\n this.invalidate();\r\n return;\r\n }\r\n\r\n let chunk;\r\n while (chunk = consumeNextChunk(stream)) {\r\n switch (chunk.type) {\r\n case GltfV2ChunkTypes.JSON:\r\n // Only one JSON chunk permitted and it must be the first.\r\n this.invalidate();\r\n return;\r\n case GltfV2ChunkTypes.Binary:\r\n // At most one binary chunk permitted and it must be the second if present.\r\n if (this.binaryChunk || this.additionalChunks.length) {\r\n this.invalidate();\r\n return;\r\n }\r\n\r\n this.binaryChunk = { offset: chunk.offset, length: chunk.length };\r\n break;\r\n default:\r\n // Any other chunk type should be ignored - for use by extensions.\r\n this.additionalChunks.push(chunk);\r\n break;\r\n }\r\n }\r\n\r\n if (false === chunk) {\r\n this.invalidate();\r\n return;\r\n }\r\n\r\n assert(undefined === chunk);\r\n assert(stream.isAtTheEnd);\r\n break;\r\n default:\r\n this.invalidate();\r\n break;\r\n }\r\n }\r\n}\r\n"]}
@@ -13,12 +13,12 @@ import { TileFormat, TileHeader } from "./TileIO";
13
13
  export class I3dmHeader extends TileHeader {
14
14
  constructor(stream) {
15
15
  super(stream);
16
- this.length = stream.nextUint32;
17
- this.featureTableJsonLength = stream.nextUint32;
18
- this.featureTableBinaryLength = stream.nextUint32;
19
- this.batchTableJsonLength = stream.nextUint32;
20
- this.batchTableBinaryLength = stream.nextUint32;
21
- this.gltfVersion = stream.nextUint32;
16
+ this.length = stream.readUint32();
17
+ this.featureTableJsonLength = stream.readUint32();
18
+ this.featureTableBinaryLength = stream.readUint32();
19
+ this.batchTableJsonLength = stream.readUint32();
20
+ this.batchTableBinaryLength = stream.readUint32();
21
+ this.gltfVersion = stream.readUint32();
22
22
  this.featureTableJsonPosition = stream.curPos;
23
23
  stream.advance(this.featureTableJsonLength);
24
24
  stream.advance(this.featureTableBinaryLength);
@@ -1 +1 @@
1
- {"version":3,"file":"I3dmTileIO.js","sourceRoot":"","sources":["../../../src/tile/I3dmTileIO.ts"],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AAc,OAAO,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;CAwB1E","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 Tile\r\n */\r\n\r\nimport { ByteStream, utf8ToString } from \"@itwin/core-bentley\";\r\nimport { TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Header preceding tile content in [i3dm](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/TileFormats/Instanced3DModel) format.\r\n * @internal\r\n */\r\nexport class I3dmHeader extends TileHeader {\r\n public readonly length: number;\r\n public readonly featureTableJsonPosition: number;\r\n public readonly featureTableJsonLength: number;\r\n public readonly featureTableBinaryLength: number;\r\n public readonly batchTableJsonLength: number;\r\n public readonly batchTableBinaryLength: number;\r\n public readonly gltfVersion: number;\r\n public readonly batchTableJson: any;\r\n public get isValid(): boolean { return TileFormat.I3dm === this.format; }\r\n\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.length = stream.nextUint32;\r\n this.featureTableJsonLength = stream.nextUint32;\r\n this.featureTableBinaryLength = stream.nextUint32;\r\n this.batchTableJsonLength = stream.nextUint32;\r\n this.batchTableBinaryLength = stream.nextUint32;\r\n this.gltfVersion = stream.nextUint32;\r\n this.featureTableJsonPosition = stream.curPos;\r\n stream.advance(this.featureTableJsonLength);\r\n stream.advance(this.featureTableBinaryLength);\r\n if (0 !== this.batchTableJsonLength) {\r\n const batchStrData = stream.nextBytes(this.batchTableJsonLength);\r\n const batchStr = utf8ToString(batchStrData);\r\n if (batchStr)\r\n this.batchTableJson = JSON.parse(batchStr);\r\n }\r\n stream.advance(this.batchTableBinaryLength);\r\n\r\n if (stream.isPastTheEnd)\r\n this.invalidate();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"I3dmTileIO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AAC,YAAY;YACrB,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAvBD,IAAW,OAAO,KAAc,OAAO,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;CAwB1E","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 Tile\r\n */\r\n\r\nimport { ByteStream, utf8ToString } from \"@itwin/core-bentley\";\r\nimport { TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Header preceding tile content in [i3dm](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/TileFormats/Instanced3DModel) format.\r\n * @internal\r\n */\r\nexport class I3dmHeader extends TileHeader {\r\n public readonly length: number;\r\n public readonly featureTableJsonPosition: number;\r\n public readonly featureTableJsonLength: number;\r\n public readonly featureTableBinaryLength: number;\r\n public readonly batchTableJsonLength: number;\r\n public readonly batchTableBinaryLength: number;\r\n public readonly gltfVersion: number;\r\n public readonly batchTableJson: any;\r\n public get isValid(): boolean { return TileFormat.I3dm === this.format; }\r\n\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.length = stream.readUint32();\r\n this.featureTableJsonLength = stream.readUint32();\r\n this.featureTableBinaryLength = stream.readUint32();\r\n this.batchTableJsonLength = stream.readUint32();\r\n this.batchTableBinaryLength = stream.readUint32();\r\n this.gltfVersion = stream.readUint32();\r\n this.featureTableJsonPosition = stream.curPos;\r\n stream.advance(this.featureTableJsonLength);\r\n stream.advance(this.featureTableBinaryLength);\r\n if (0 !== this.batchTableJsonLength) {\r\n const batchStrData = stream.nextBytes(this.batchTableJsonLength);\r\n const batchStr = utf8ToString(batchStrData);\r\n if (batchStr)\r\n this.batchTableJson = JSON.parse(batchStr);\r\n }\r\n stream.advance(this.batchTableBinaryLength);\r\n\r\n if (stream.isPastTheEnd)\r\n this.invalidate();\r\n }\r\n}\r\n"]}
@@ -48,17 +48,17 @@ export class ImdlHeader extends TileHeader {
48
48
  */
49
49
  constructor(stream) {
50
50
  super(stream);
51
- this.headerLength = stream.nextUint32;
52
- this.flags = stream.nextUint32;
51
+ this.headerLength = stream.readUint32();
52
+ this.flags = stream.readUint32();
53
53
  this.contentRange = new Range3d();
54
54
  nextPoint3d64FromByteStream(stream, this.contentRange.low);
55
55
  nextPoint3d64FromByteStream(stream, this.contentRange.high);
56
- this.tolerance = stream.nextFloat64;
57
- this.numElementsIncluded = stream.nextUint32;
58
- this.numElementsExcluded = stream.nextUint32;
59
- this.tileLength = stream.nextUint32;
56
+ this.tolerance = stream.readFloat64();
57
+ this.numElementsIncluded = stream.readUint32();
58
+ this.numElementsExcluded = stream.readUint32();
59
+ this.tileLength = stream.readUint32();
60
60
  // empty sub-volume bit field introduced in format v02.00
61
- this.emptySubRanges = this.versionMajor >= 2 ? stream.nextUint32 : 0;
61
+ this.emptySubRanges = this.versionMajor >= 2 ? stream.readUint32() : 0;
62
62
  // Skip any unprocessed bytes in header
63
63
  const remainingHeaderBytes = this.headerLength - stream.curPos;
64
64
  assert(remainingHeaderBytes >= 0);
@@ -81,9 +81,9 @@ export class FeatureTableHeader {
81
81
  this.count = count;
82
82
  }
83
83
  static readFrom(stream) {
84
- const length = stream.nextUint32;
85
- const maxFeatures = stream.nextUint32;
86
- const count = stream.nextUint32;
84
+ const length = stream.readUint32();
85
+ const maxFeatures = stream.readUint32();
86
+ const count = stream.readUint32();
87
87
  return stream.isPastTheEnd ? undefined : new FeatureTableHeader(length, maxFeatures, count);
88
88
  }
89
89
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IModelTileIO.js","sourceRoot":"","sources":["../../../src/tile/IModelTileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAc,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,OAAO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,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC9F,CAAC;;AAEa,8BAAW,GAAG,EAAE,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 Tile\r\n */\r\n\r\nimport { assert, ByteStream } from \"@itwin/core-bentley\";\r\nimport { Range3d } from \"@itwin/core-geometry\";\r\nimport { ElementAlignedBox3d } from \"../geometry/Placement\";\r\nimport { nextPoint3d64FromByteStream, TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Flags describing the geometry contained within a tile in iMdl format.\r\n * @internal\r\n */\r\nexport enum ImdlFlags {\r\n /** No special flags */\r\n None = 0,\r\n /** The tile contains some curved geometry */\r\n ContainsCurves = 1 << 0,\r\n /** Some geometry within the tile range was omitted based on its size */\r\n Incomplete = 1 << 2,\r\n /** The tile must be refined by sub-division, not magnification. */\r\n DisallowMagnification = 1 << 3,\r\n}\r\n\r\n/** Describes the maximum major and minor version of the iMdl tile format supported by this version of this package.\r\n * @internal\r\n */\r\nexport enum CurrentImdlVersion {\r\n /** The unsigned 16-bit major version number. If the major version specified in the tile header is greater than this value, then this\r\n * front-end is not capable of reading the tile content. Otherwise, this front-end can read the tile content even if the header specifies a\r\n * greater minor version than CurrentVersion.Minor, although some data may be skipped.\r\n */\r\n Major = 29,\r\n /** The unsigned 16-bit minor version number. If the major version in the tile header is equal to CurrentVersion.Major, then this package can\r\n * read the tile content even if the minor version in the tile header is greater than this value, although some data may be skipped.\r\n */\r\n Minor = 0,\r\n /** The unsigned 32-bit version number derived from the 16-bit major and minor version numbers. */\r\n Combined = (Major << 0x10) | Minor,\r\n}\r\n\r\n/** Header embedded at the beginning of binary tile data in iMdl format describing its contents.\r\n * @internal\r\n */\r\nexport class ImdlHeader extends TileHeader {\r\n /** The size of this header in bytes. */\r\n public readonly headerLength: number;\r\n /** Flags describing the geometry contained within the tile */\r\n public readonly flags: ImdlFlags;\r\n /** A bounding box no larger than the tile's range, tightly enclosing the tile's geometry; or a null range if the tile is empty */\r\n public readonly contentRange: ElementAlignedBox3d;\r\n /** The chord tolerance in meters at which the tile's geometry was faceted */\r\n public readonly tolerance: number;\r\n /** The number of elements which contributed at least some geometry to the tile content */\r\n public readonly numElementsIncluded: number;\r\n /** The number of elements within the tile range which contributed no geometry to the tile content */\r\n public readonly numElementsExcluded: number;\r\n /** The total number of bytes in the binary tile data, including this header */\r\n public readonly tileLength: number;\r\n /** A bitfield wherein each set bit indicates an empty sub-volume. */\r\n public readonly emptySubRanges: number;\r\n\r\n public get versionMajor(): number { return this.version >>> 0x10; }\r\n public get versionMinor(): number { return (this.version & 0xffff) >>> 0; }\r\n\r\n public get isValid(): boolean { return TileFormat.IModel === this.format; }\r\n public get isReadableVersion(): boolean { return this.versionMajor <= CurrentImdlVersion.Major; }\r\n\r\n /** Deserialize a header from the binary data at the stream's current position.\r\n * If the binary data does not contain a valid header, the Header will be marked 'invalid'.\r\n */\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.headerLength = stream.nextUint32;\r\n this.flags = stream.nextUint32;\r\n\r\n this.contentRange = new Range3d();\r\n nextPoint3d64FromByteStream(stream, this.contentRange.low);\r\n nextPoint3d64FromByteStream(stream, this.contentRange.high);\r\n\r\n this.tolerance = stream.nextFloat64;\r\n this.numElementsIncluded = stream.nextUint32;\r\n this.numElementsExcluded = stream.nextUint32;\r\n this.tileLength = stream.nextUint32;\r\n\r\n // empty sub-volume bit field introduced in format v02.00\r\n this.emptySubRanges = this.versionMajor >= 2 ? stream.nextUint32 : 0;\r\n\r\n // Skip any unprocessed bytes in header\r\n const remainingHeaderBytes = this.headerLength - stream.curPos;\r\n assert(remainingHeaderBytes >= 0);\r\n stream.advance(remainingHeaderBytes);\r\n\r\n if (stream.isPastTheEnd)\r\n this.invalidate();\r\n }\r\n}\r\n\r\n/** Header preceding the feature table embedded in an iMdl tile's content.\r\n * @internal\r\n */\r\nexport class FeatureTableHeader {\r\n public static readFrom(stream: ByteStream) {\r\n const length = stream.nextUint32;\r\n const maxFeatures = stream.nextUint32;\r\n const count = stream.nextUint32;\r\n return stream.isPastTheEnd ? undefined : new FeatureTableHeader(length, maxFeatures, count);\r\n }\r\n\r\n public static sizeInBytes = 12;\r\n\r\n private constructor(public readonly length: number,\r\n public readonly maxFeatures: number,\r\n public readonly count: number) { }\r\n}\r\n"]}
1
+ {"version":3,"file":"IModelTileIO.js","sourceRoot":"","sources":["../../../src/tile/IModelTileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAc,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,2BAA2B,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE/E;;GAEG;AACH,MAAM,CAAN,IAAY,SASX;AATD,WAAY,SAAS;IACnB,uBAAuB;IACvB,yCAAQ,CAAA;IACR,6CAA6C;IAC7C,6DAAuB,CAAA;IACvB,wEAAwE;IACxE,qDAAmB,CAAA;IACnB,mEAAmE;IACnE,2EAA8B,CAAA;AAChC,CAAC,EATW,SAAS,KAAT,SAAS,QASpB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,kBAYX;AAZD,WAAY,kBAAkB;IAC5B;;;OAGG;IACH,8DAAU,CAAA;IACV;;OAEG;IACH,6DAAS,CAAA;IACT,kGAAkG;IAClG,yEAAkC,CAAA;AACpC,CAAC,EAZW,kBAAkB,KAAlB,kBAAkB,QAY7B;AAED;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;IAwBxC;;OAEG;IACH,YAAmB,MAAkB;QACnC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,UAAU,EAAE,C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,KAAc,OAAO,IAAI,CAAC,YAAY,IAAI,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;CA8BlG;AAED;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAU7B,YAAoC,MAAc,EAChC,WAAmB,EACnB,KAAa;QAFK,WAAM,GAAN,MAAM,CAAQ;QAChC,gBAAW,GAAX,WAAW,CAAQ;QACnB,UAAK,GAAL,KAAK,CAAQ;IAAI,CAAC;IAX7B,MAAM,CAAC,QAAQ,CAAC,MAAkB;QACvC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACnC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC9F,CAAC;;AAEa,8BAAW,GAAG,EAAE,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 Tile\r\n */\r\n\r\nimport { assert, ByteStream } from \"@itwin/core-bentley\";\r\nimport { Range3d } from \"@itwin/core-geometry\";\r\nimport { ElementAlignedBox3d } from \"../geometry/Placement\";\r\nimport { nextPoint3d64FromByteStream, TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Flags describing the geometry contained within a tile in iMdl format.\r\n * @internal\r\n */\r\nexport enum ImdlFlags {\r\n /** No special flags */\r\n None = 0,\r\n /** The tile contains some curved geometry */\r\n ContainsCurves = 1 << 0,\r\n /** Some geometry within the tile range was omitted based on its size */\r\n Incomplete = 1 << 2,\r\n /** The tile must be refined by sub-division, not magnification. */\r\n DisallowMagnification = 1 << 3,\r\n}\r\n\r\n/** Describes the maximum major and minor version of the iMdl tile format supported by this version of this package.\r\n * @internal\r\n */\r\nexport enum CurrentImdlVersion {\r\n /** The unsigned 16-bit major version number. If the major version specified in the tile header is greater than this value, then this\r\n * front-end is not capable of reading the tile content. Otherwise, this front-end can read the tile content even if the header specifies a\r\n * greater minor version than CurrentVersion.Minor, although some data may be skipped.\r\n */\r\n Major = 29,\r\n /** The unsigned 16-bit minor version number. If the major version in the tile header is equal to CurrentVersion.Major, then this package can\r\n * read the tile content even if the minor version in the tile header is greater than this value, although some data may be skipped.\r\n */\r\n Minor = 0,\r\n /** The unsigned 32-bit version number derived from the 16-bit major and minor version numbers. */\r\n Combined = (Major << 0x10) | Minor,\r\n}\r\n\r\n/** Header embedded at the beginning of binary tile data in iMdl format describing its contents.\r\n * @internal\r\n */\r\nexport class ImdlHeader extends TileHeader {\r\n /** The size of this header in bytes. */\r\n public readonly headerLength: number;\r\n /** Flags describing the geometry contained within the tile */\r\n public readonly flags: ImdlFlags;\r\n /** A bounding box no larger than the tile's range, tightly enclosing the tile's geometry; or a null range if the tile is empty */\r\n public readonly contentRange: ElementAlignedBox3d;\r\n /** The chord tolerance in meters at which the tile's geometry was faceted */\r\n public readonly tolerance: number;\r\n /** The number of elements which contributed at least some geometry to the tile content */\r\n public readonly numElementsIncluded: number;\r\n /** The number of elements within the tile range which contributed no geometry to the tile content */\r\n public readonly numElementsExcluded: number;\r\n /** The total number of bytes in the binary tile data, including this header */\r\n public readonly tileLength: number;\r\n /** A bitfield wherein each set bit indicates an empty sub-volume. */\r\n public readonly emptySubRanges: number;\r\n\r\n public get versionMajor(): number { return this.version >>> 0x10; }\r\n public get versionMinor(): number { return (this.version & 0xffff) >>> 0; }\r\n\r\n public get isValid(): boolean { return TileFormat.IModel === this.format; }\r\n public get isReadableVersion(): boolean { return this.versionMajor <= CurrentImdlVersion.Major; }\r\n\r\n /** Deserialize a header from the binary data at the stream's current position.\r\n * If the binary data does not contain a valid header, the Header will be marked 'invalid'.\r\n */\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.headerLength = stream.readUint32();\r\n this.flags = stream.readUint32();\r\n\r\n this.contentRange = new Range3d();\r\n nextPoint3d64FromByteStream(stream, this.contentRange.low);\r\n nextPoint3d64FromByteStream(stream, this.contentRange.high);\r\n\r\n this.tolerance = stream.readFloat64();\r\n this.numElementsIncluded = stream.readUint32();\r\n this.numElementsExcluded = stream.readUint32();\r\n this.tileLength = stream.readUint32();\r\n\r\n // empty sub-volume bit field introduced in format v02.00\r\n this.emptySubRanges = this.versionMajor >= 2 ? stream.readUint32() : 0;\r\n\r\n // Skip any unprocessed bytes in header\r\n const remainingHeaderBytes = this.headerLength - stream.curPos;\r\n assert(remainingHeaderBytes >= 0);\r\n stream.advance(remainingHeaderBytes);\r\n\r\n if (stream.isPastTheEnd)\r\n this.invalidate();\r\n }\r\n}\r\n\r\n/** Header preceding the feature table embedded in an iMdl tile's content.\r\n * @internal\r\n */\r\nexport class FeatureTableHeader {\r\n public static readFrom(stream: ByteStream) {\r\n const length = stream.readUint32();\r\n const maxFeatures = stream.readUint32();\r\n const count = stream.readUint32();\r\n return stream.isPastTheEnd ? undefined : new FeatureTableHeader(length, maxFeatures, count);\r\n }\r\n\r\n public static sizeInBytes = 12;\r\n\r\n private constructor(public readonly length: number,\r\n public readonly maxFeatures: number,\r\n public readonly count: number) { }\r\n}\r\n"]}
@@ -12,11 +12,11 @@ import { TileFormat, TileHeader } from "./TileIO";
12
12
  export class PntsHeader extends TileHeader {
13
13
  constructor(stream) {
14
14
  super(stream);
15
- this.length = stream.nextUint32;
16
- this.featureTableJsonLength = stream.nextUint32;
17
- this.featureTableBinaryLength = stream.nextUint32;
18
- this.batchTableJsonLength = stream.nextUint32;
19
- this.batchTableBinaryLength = stream.nextUint32;
15
+ this.length = stream.readUint32();
16
+ this.featureTableJsonLength = stream.readUint32();
17
+ this.featureTableBinaryLength = stream.readUint32();
18
+ this.batchTableJsonLength = stream.readUint32();
19
+ this.batchTableBinaryLength = stream.readUint32();
20
20
  }
21
21
  get isValid() { return TileFormat.Pnts === this.format; }
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PntsTileIO.js","sourceRoot":"","sources":["../../../src/tile/PntsTileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;IAQxC,YAAmB,MAAkB;QACnC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC;QAChC,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,UAAU,CAAC;QAChD,IAAI,CAAC,wBAAwB,GAAG,MAAM,CAAC,UAAU,CAAC;QAClD,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,UAAU,CAAC;QAC9C,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,UAAU,CAAC;IAClD,CAAC;IATD,IAAW,OAAO,KAAc,OAAO,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;CAU1E","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 Tile\r\n */\r\n\r\nimport { ByteStream } from \"@itwin/core-bentley\";\r\nimport { TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Header preceding tile content in [pnts](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/TileFormats/PointCloud) format.\r\n * @internal\r\n */\r\nexport class PntsHeader extends TileHeader {\r\n public readonly length: number;\r\n public readonly featureTableJsonLength: number;\r\n public readonly featureTableBinaryLength: number;\r\n public readonly batchTableJsonLength: number;\r\n public readonly batchTableBinaryLength: number;\r\n public get isValid(): boolean { return TileFormat.Pnts === this.format; }\r\n\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.length = stream.nextUint32;\r\n this.featureTableJsonLength = stream.nextUint32;\r\n this.featureTableBinaryLength = stream.nextUint32;\r\n this.batchTableJsonLength = stream.nextUint32;\r\n this.batchTableBinaryLength = stream.nextUint32;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"PntsTileIO.js","sourceRoot":"","sources":["../../../src/tile/PntsTileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;IAQxC,YAAmB,MAAkB;QACnC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QAClD,IAAI,CAAC,wBAAwB,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACpD,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QAChD,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IACpD,CAAC;IATD,IAAW,OAAO,KAAc,OAAO,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;CAU1E","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 Tile\r\n */\r\n\r\nimport { ByteStream } from \"@itwin/core-bentley\";\r\nimport { TileFormat, TileHeader } from \"./TileIO\";\r\n\r\n/** Header preceding tile content in [pnts](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/TileFormats/PointCloud) format.\r\n * @internal\r\n */\r\nexport class PntsHeader extends TileHeader {\r\n public readonly length: number;\r\n public readonly featureTableJsonLength: number;\r\n public readonly featureTableBinaryLength: number;\r\n public readonly batchTableJsonLength: number;\r\n public readonly batchTableBinaryLength: number;\r\n public get isValid(): boolean { return TileFormat.Pnts === this.format; }\r\n\r\n public constructor(stream: ByteStream) {\r\n super(stream);\r\n this.length = stream.readUint32();\r\n this.featureTableJsonLength = stream.readUint32();\r\n this.featureTableBinaryLength = stream.readUint32();\r\n this.batchTableJsonLength = stream.readUint32();\r\n this.batchTableBinaryLength = stream.readUint32();\r\n }\r\n}\r\n"]}
@@ -89,8 +89,8 @@ export class TileReadError extends BentleyError {
89
89
  export class TileHeader {
90
90
  /** Construct a Header from the binary data at the supplied stream's current read position */
91
91
  constructor(stream) {
92
- this._format = tileFormatFromNumber(stream.nextUint32);
93
- this.version = stream.nextUint32;
92
+ this._format = tileFormatFromNumber(stream.readUint32());
93
+ this.version = stream.readUint32();
94
94
  }
95
95
  get format() { return this._format; }
96
96
  /** Mark the header as representing invalid data */
@@ -102,7 +102,7 @@ export class TileHeader {
102
102
  * @internal
103
103
  */
104
104
  export function nextPoint3d64FromByteStream(stream, result) {
105
- const x = stream.nextFloat64, y = stream.nextFloat64, z = stream.nextFloat64;
105
+ const x = stream.readFloat64(), y = stream.readFloat64(), z = stream.readFloat64();
106
106
  if (undefined === result)
107
107
  return new Point3d(x, y, z);
108
108
  result.set(x, y, z);
@@ -1 +1 @@
1
- {"version":3,"file":"TileIO.js","sourceRoot":"","sources":["../../../src/tile/TileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAc,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAN,IAAY,UASX;AATD,WAA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C;AAEF;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAY;IAC7C,YAAmB,MAAsB,EAAE,OAAgB;QACzD,IAAI,SAAS,KAAK,OAAO;YACvB,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEvC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,IAAW,WAAW,KAAc,OAAO,cAAc,CAAC,QAAQ,KAAK,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;CAC3F;AAED;;;;GAIG;AACH,MAAM,OAAgB,UAAU;IAI9B,6FAA6F;IAC7F,YAAmB,MAAkB;QACnC,IAAI,CAAC,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC;IACnC,CAAC;IAED,IAAW,MAAM,KAAiB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAKxD,mDAAmD;IACzC,UAAU;QAClB,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAAkB,EAAE,MAAgB;IAC9E,MAAM,CAAC,GAAG,MAAM,CAAC,WAAW,EAC1B,CAAC,GAAG,MAAM,CAAC,WAAW,EACtB,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC;IAEzB,IAAI,SAAS,KAAK,MAAM;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAE9B,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpB,OAAO,MAAM,CAAC;AAChB,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 Tile\r\n */\r\n\r\nimport { BentleyError, ByteStream } from \"@itwin/core-bentley\";\r\nimport { Point3d } from \"@itwin/core-geometry\";\r\n\r\n/** Type codes for various tile formats. Often these are embedded as 32-bit 'magic numbers' in a binary stream to indicate the format.\r\n * @internal\r\n */\r\nexport enum TileFormat {\r\n Unknown = 0,\r\n B3dm = 0x6d643362, // \"b3dm\"\r\n Gltf = 0x46546c67, // \"glTF\"\r\n Pnts = 0x73746e70, // \"pnts\"\r\n IModel = 0x6c644d69, // \"iMdl\"\r\n Cmpt = 0x74706d63, // cmpt\r\n I3dm = 0x6d643369, // i3dm\r\n A3x = 0x583341, // A3X0 (numeric 0 not char '0')\r\n}\r\n\r\n/** Given a magic number, return whether it identifies a known tile format.\r\n * @internal\r\n */\r\nexport function isKnownTileFormat(format: number) {\r\n switch (format) {\r\n case TileFormat.Unknown:\r\n case TileFormat.B3dm:\r\n case TileFormat.Gltf:\r\n case TileFormat.IModel:\r\n case TileFormat.Pnts:\r\n case TileFormat.Cmpt:\r\n case TileFormat.I3dm:\r\n case TileFormat.A3x:\r\n return true;\r\n default:\r\n return false;\r\n }\r\n}\r\n\r\n/** Given a magic number, attempt to convert it to a known TileFormat.\r\n * @internal\r\n */\r\nexport function tileFormatFromNumber(formatNumber: number): TileFormat {\r\n const format = formatNumber as TileFormat;\r\n return isKnownTileFormat(format) ? format : TileFormat.Unknown;\r\n}\r\n\r\n/** Status codes for tile reading operations\r\n * @internal\r\n */\r\nexport enum TileReadStatus {\r\n Success = 0,\r\n InvalidTileData,\r\n InvalidHeader,\r\n InvalidBatchTable,\r\n InvalidScene,\r\n InvalidFeatureTable,\r\n NewerMajorVersion,\r\n Canceled,\r\n}\r\n\r\nconst readStatusMessages = [\r\n \"Success\",\r\n \"Invalid tile data\",\r\n \"Invalid tile header\",\r\n \"Invalid batch table\",\r\n \"Invalid scene\",\r\n \"Invalid feature table\",\r\n \"Major version too new\",\r\n \"Canceled\",\r\n];\r\n\r\n/** Exception thrown by functions that deserialize tiles.\r\n * @internal\r\n */\r\nexport class TileReadError extends BentleyError {\r\n public constructor(status: TileReadStatus, message?: string) {\r\n if (undefined === message)\r\n message = readStatusMessages[status];\r\n\r\n super(status, message);\r\n }\r\n\r\n public get wasCanceled(): boolean { return TileReadStatus.Canceled === this.errorNumber; }\r\n}\r\n\r\n/** The base header preceding tile data of most formats, identifying the tile format and version of that format.\r\n * Specific tile formats may define their own headers as sub-types of this Header, appending\r\n * additional format-specific data.\r\n * @internal\r\n */\r\nexport abstract class TileHeader {\r\n private _format: TileFormat;\r\n public version: number;\r\n\r\n /** Construct a Header from the binary data at the supplied stream's current read position */\r\n public constructor(stream: ByteStream) {\r\n this._format = tileFormatFromNumber(stream.nextUint32);\r\n this.version = stream.nextUint32;\r\n }\r\n\r\n public get format(): TileFormat { return this._format; }\r\n\r\n /** Returns whether the header represents valid data */\r\n public abstract get isValid(): boolean;\r\n\r\n /** Mark the header as representing invalid data */\r\n protected invalidate(): void {\r\n this._format = TileFormat.Unknown;\r\n }\r\n}\r\n\r\n/** Read 3 64-bit floating point numbers at the byte stream's current read position, advance by 24 bytes, and return a Point3d constructed from the 3 numbers.\r\n * @internal\r\n */\r\nexport function nextPoint3d64FromByteStream(stream: ByteStream, result?: Point3d): Point3d {\r\n const x = stream.nextFloat64,\r\n y = stream.nextFloat64,\r\n z = stream.nextFloat64;\r\n\r\n if (undefined === result)\r\n return new Point3d(x, y, z);\r\n\r\n result.set(x, y, z);\r\n return result;\r\n}\r\n"]}
1
+ {"version":3,"file":"TileIO.js","sourceRoot":"","sources":["../../../src/tile/TileIO.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAc,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAN,IAAY,UASX;AATD,WAAY,UAAU;IACpB,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;AACH,MAAM,OAAO,aAAc,SAAQ,YAAY;IAC7C,YAAmB,MAAsB,EAAE,OAAgB;QACzD,IAAI,SAAS,KAAK,OAAO;YACvB,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEvC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,IAAW,WAAW,KAAc,OAAO,cAAc,CAAC,QAAQ,KAAK,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;CAC3F;AAED;;;;GAIG;AACH,MAAM,OAAgB,UAAU;IAI9B,6FAA6F;IAC7F,YAAmB,MAAkB;QACnC,IAAI,CAAC,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;IAED,IAAW,MAAM,KAAiB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAKxD,mDAAmD;IACzC,UAAU;QAClB,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAAkB,EAAE,MAAgB;IAC9E,MAAM,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,EAC5B,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,EACxB,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IAE3B,IAAI,SAAS,KAAK,MAAM;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAE9B,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpB,OAAO,MAAM,CAAC;AAChB,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 Tile\r\n */\r\n\r\nimport { BentleyError, ByteStream } from \"@itwin/core-bentley\";\r\nimport { Point3d } from \"@itwin/core-geometry\";\r\n\r\n/** Type codes for various tile formats. Often these are embedded as 32-bit 'magic numbers' in a binary stream to indicate the format.\r\n * @internal\r\n */\r\nexport enum TileFormat {\r\n Unknown = 0,\r\n B3dm = 0x6d643362, // \"b3dm\"\r\n Gltf = 0x46546c67, // \"glTF\"\r\n Pnts = 0x73746e70, // \"pnts\"\r\n IModel = 0x6c644d69, // \"iMdl\"\r\n Cmpt = 0x74706d63, // cmpt\r\n I3dm = 0x6d643369, // i3dm\r\n A3x = 0x583341, // A3X0 (numeric 0 not char '0')\r\n}\r\n\r\n/** Given a magic number, return whether it identifies a known tile format.\r\n * @internal\r\n */\r\nexport function isKnownTileFormat(format: number) {\r\n switch (format) {\r\n case TileFormat.Unknown:\r\n case TileFormat.B3dm:\r\n case TileFormat.Gltf:\r\n case TileFormat.IModel:\r\n case TileFormat.Pnts:\r\n case TileFormat.Cmpt:\r\n case TileFormat.I3dm:\r\n case TileFormat.A3x:\r\n return true;\r\n default:\r\n return false;\r\n }\r\n}\r\n\r\n/** Given a magic number, attempt to convert it to a known TileFormat.\r\n * @internal\r\n */\r\nexport function tileFormatFromNumber(formatNumber: number): TileFormat {\r\n const format = formatNumber as TileFormat;\r\n return isKnownTileFormat(format) ? format : TileFormat.Unknown;\r\n}\r\n\r\n/** Status codes for tile reading operations\r\n * @internal\r\n */\r\nexport enum TileReadStatus {\r\n Success = 0,\r\n InvalidTileData,\r\n InvalidHeader,\r\n InvalidBatchTable,\r\n InvalidScene,\r\n InvalidFeatureTable,\r\n NewerMajorVersion,\r\n Canceled,\r\n}\r\n\r\nconst readStatusMessages = [\r\n \"Success\",\r\n \"Invalid tile data\",\r\n \"Invalid tile header\",\r\n \"Invalid batch table\",\r\n \"Invalid scene\",\r\n \"Invalid feature table\",\r\n \"Major version too new\",\r\n \"Canceled\",\r\n];\r\n\r\n/** Exception thrown by functions that deserialize tiles.\r\n * @internal\r\n */\r\nexport class TileReadError extends BentleyError {\r\n public constructor(status: TileReadStatus, message?: string) {\r\n if (undefined === message)\r\n message = readStatusMessages[status];\r\n\r\n super(status, message);\r\n }\r\n\r\n public get wasCanceled(): boolean { return TileReadStatus.Canceled === this.errorNumber; }\r\n}\r\n\r\n/** The base header preceding tile data of most formats, identifying the tile format and version of that format.\r\n * Specific tile formats may define their own headers as sub-types of this Header, appending\r\n * additional format-specific data.\r\n * @internal\r\n */\r\nexport abstract class TileHeader {\r\n private _format: TileFormat;\r\n public version: number;\r\n\r\n /** Construct a Header from the binary data at the supplied stream's current read position */\r\n public constructor(stream: ByteStream) {\r\n this._format = tileFormatFromNumber(stream.readUint32());\r\n this.version = stream.readUint32();\r\n }\r\n\r\n public get format(): TileFormat { return this._format; }\r\n\r\n /** Returns whether the header represents valid data */\r\n public abstract get isValid(): boolean;\r\n\r\n /** Mark the header as representing invalid data */\r\n protected invalidate(): void {\r\n this._format = TileFormat.Unknown;\r\n }\r\n}\r\n\r\n/** Read 3 64-bit floating point numbers at the byte stream's current read position, advance by 24 bytes, and return a Point3d constructed from the 3 numbers.\r\n * @internal\r\n */\r\nexport function nextPoint3d64FromByteStream(stream: ByteStream, result?: Point3d): Point3d {\r\n const x = stream.readFloat64(),\r\n y = stream.readFloat64(),\r\n z = stream.readFloat64();\r\n\r\n if (undefined === result)\r\n return new Point3d(x, y, z);\r\n\r\n result.set(x, y, z);\r\n return result;\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-common",
3
- "version": "3.6.0-dev.5",
3
+ "version": "3.6.0-dev.51",
4
4
  "description": "iTwin.js components common to frontend and backend",
5
5
  "main": "lib/cjs/core-common.js",
6
6
  "module": "lib/esm/core-common.js",
@@ -28,14 +28,14 @@
28
28
  "js-base64": "^3.6.1"
29
29
  },
30
30
  "peerDependencies": {
31
- "@itwin/core-bentley": "^3.6.0-dev.5",
32
- "@itwin/core-geometry": "^3.6.0-dev.5"
31
+ "@itwin/core-bentley": "^3.6.0-dev.51",
32
+ "@itwin/core-geometry": "^3.6.0-dev.51"
33
33
  },
34
34
  "devDependencies": {
35
- "@itwin/build-tools": "3.6.0-dev.5",
36
- "@itwin/core-bentley": "3.6.0-dev.5",
37
- "@itwin/core-geometry": "3.6.0-dev.5",
38
- "@itwin/eslint-plugin": "3.6.0-dev.5",
35
+ "@itwin/build-tools": "3.6.0-dev.51",
36
+ "@itwin/core-bentley": "3.6.0-dev.51",
37
+ "@itwin/core-geometry": "3.6.0-dev.51",
38
+ "@itwin/eslint-plugin": "3.6.0-dev.51",
39
39
  "@types/chai": "4.3.1",
40
40
  "@types/flatbuffers": "~1.10.0",
41
41
  "@types/mocha": "^8.2.2",