@itwin/core-common 5.3.0-dev.21 → 5.3.0-dev.23

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.
@@ -43,4 +43,13 @@ export declare class GlbHeader extends TileHeader {
43
43
  get isValid(): boolean;
44
44
  constructor(stream: ByteStream);
45
45
  }
46
+ /** @internal */
47
+ export declare class GltfHeader extends TileHeader {
48
+ readonly gltfLength: number;
49
+ readonly scenePosition: number;
50
+ readonly sceneStrLength: number;
51
+ readonly binaryPosition: number;
52
+ get isValid(): boolean;
53
+ constructor(stream: ByteStream);
54
+ }
46
55
  //# sourceMappingURL=GltfTileIO.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GltfTileIO.d.ts","sourceRoot":"","sources":["../../../src/tile/GltfTileIO.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAU,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,oBAAY,YAAY;IACtB,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,cAAc,IAAW;IACzB,gBAAgB,IAAI;CACrB;AAED,gBAAgB;AAChB,oBAAY,gBAAgB;IAC1B,IAAI,aAAa;IACjB,MAAM,UAAa;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAiB1D,gBAAgB;AAChB,qBAAa,SAAU,SAAQ,UAAU;IACvC,SAAgB,UAAU,EAAE,MAAM,CAAK;IACvC,SAAgB,SAAS,EAAE,SAAS,CAA4B;IAChE,SAAgB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxC,SAAgB,gBA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AA4C;gBAEtD,MAAM,EAAE,UAAU;CAqCtC"}
@@ -7,7 +7,7 @@
7
7
  * @module Tile
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.GlbHeader = exports.GltfV2ChunkTypes = exports.GltfVersions = void 0;
10
+ exports.GltfHeader = exports.GlbHeader = exports.GltfV2ChunkTypes = exports.GltfVersions = void 0;
11
11
  const core_bentley_1 = require("@itwin/core-bentley");
12
12
  const TileIO_1 = require("./TileIO");
13
13
  /** Known version of the [glTF format](https://www.khronos.org/gltf/).
@@ -110,4 +110,47 @@ class GlbHeader extends TileIO_1.TileHeader {
110
110
  }
111
111
  }
112
112
  exports.GlbHeader = GlbHeader;
113
+ /** @internal */
114
+ class GltfHeader extends TileIO_1.TileHeader {
115
+ gltfLength;
116
+ scenePosition = 0;
117
+ sceneStrLength = 0;
118
+ binaryPosition = 0;
119
+ get isValid() { return TileIO_1.TileFormat.Gltf === this.format; }
120
+ constructor(stream) {
121
+ super(stream);
122
+ this.gltfLength = stream.readUint32();
123
+ this.sceneStrLength = stream.readUint32();
124
+ const value5 = stream.readUint32();
125
+ // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles
126
+ // validating the chunk type.
127
+ if (this.version === GltfVersions.Version2 && value5 === GltfVersions.Gltf1SceneFormat)
128
+ this.version = GltfVersions.Version1;
129
+ if (this.version === GltfVersions.Version1) {
130
+ const gltfSceneFormat = value5;
131
+ if (GltfVersions.Gltf1SceneFormat !== gltfSceneFormat) {
132
+ this.invalidate();
133
+ return;
134
+ }
135
+ this.scenePosition = stream.curPos;
136
+ this.binaryPosition = stream.curPos + this.sceneStrLength;
137
+ }
138
+ else if (this.version === GltfVersions.Version2) {
139
+ const sceneChunkType = value5;
140
+ this.scenePosition = stream.curPos;
141
+ stream.curPos = stream.curPos + this.sceneStrLength;
142
+ const binaryLength = stream.readUint32();
143
+ const binaryChunkType = stream.readUint32();
144
+ if (GltfV2ChunkTypes.JSON !== sceneChunkType || GltfV2ChunkTypes.Binary !== binaryChunkType || 0 === binaryLength) {
145
+ this.invalidate();
146
+ return;
147
+ }
148
+ this.binaryPosition = stream.curPos;
149
+ }
150
+ else {
151
+ this.invalidate();
152
+ }
153
+ }
154
+ }
155
+ exports.GltfHeader = GltfHeader;
113
156
  //# sourceMappingURL=GltfTileIO.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GltfTileIO.js","sourceRoot":"","sources":["../../../src/tile/GltfTileIO.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAyD;AACzD,qCAAkD;AAElD;;GAEG;AACH,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,uDAAY,CAAA;IACZ,mEAAyB,CAAA;IACzB,uEAAoB,CAAA;AACtB,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB;AAED,gBAAgB;AAChB,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,gEAAiB,CAAA;IACjB,iEAAmB,CAAA;AACrB,CAAC,EAHW,gBAAgB,gCAAhB,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;IAEjC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IACnC,IAAI,MAAM,CAAC,UAAU;QACnB,OAAO,SAAS,CAAC;IAEnB,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IACjC,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;AAChE,CAAC;AAED,gBAAgB;AAChB,MAAa,SAAU,SAAQ,mBAAU;IACvB,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------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tile\n */\n\nimport { assert, ByteStream } from \"@itwin/core-bentley\";\nimport { TileFormat, TileHeader } from \"./TileIO\";\n\n/** Known version of the [glTF format](https://www.khronos.org/gltf/).\n * @internal\n */\nexport enum GltfVersions {\n Version1 = 1,\n Version2 = 2,\n CurrentVersion = Version1,\n Gltf1SceneFormat = 0,\n}\n\n/** @internal */\nexport enum GltfV2ChunkTypes {\n JSON = 0x4E4F534a,\n Binary = 0x004E4942,\n}\n\n/** A chunk of a glb file.\n * @internal\n */\nexport interface GltfChunk {\n /** Offset of the first byte of the chunk's data relative to the beginning of the glb data.\n * This excludes the 8-byte chunk header containing the length and type fields.\n */\n offset: number;\n /** The number of bytes in the chunk's data. */\n length: number;\n}\n\n/** Describes a glTF chunk's data along with its type.\n * @internal\n */\nexport type TypedGltfChunk = GltfChunk & { type: number };\n\nfunction consumeNextChunk(stream: ByteStream): TypedGltfChunk | undefined | false {\n if (stream.isAtTheEnd)\n return undefined;\n\n const offset = stream.curPos + 8;\n\n const length = stream.readUint32();\n if (stream.isAtTheEnd)\n return undefined;\n\n const type = stream.readUint32();\n stream.advance(length);\n return stream.isPastTheEnd ? false : { offset, length, type };\n}\n\n/** @internal */\nexport class GlbHeader extends TileHeader {\n public readonly gltfLength: number = 0;\n public readonly jsonChunk: GltfChunk = { offset: 0, length: 0 };\n public readonly binaryChunk?: GltfChunk;\n public readonly additionalChunks: TypedGltfChunk[] = [];\n\n public get isValid(): boolean {\n return TileFormat.Gltf === this.format;\n }\n\n public constructor(stream: ByteStream) {\n super(stream);\n this.gltfLength = stream.readUint32();\n\n const jsonLength = stream.readUint32();\n const word5 = stream.readUint32();\n\n // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles\n // validating the chunk type.\n if (this.version === GltfVersions.Version2 && word5 === GltfVersions.Gltf1SceneFormat)\n this.version = GltfVersions.Version1;\n\n this.jsonChunk = { offset: stream.curPos, length: jsonLength };\n switch (this.version) {\n case GltfVersions.Version1:\n if (GltfVersions.Gltf1SceneFormat !== word5) {\n this.invalidate();\n return;\n }\n\n const binaryOffset = stream.curPos + jsonLength;\n this.binaryChunk = { offset: binaryOffset, length: this.gltfLength - binaryOffset };\n break;\n case GltfVersions.Version2:\n if (word5 !== GltfV2ChunkTypes.JSON) {\n this.invalidate();\n return;\n }\n\n stream.advance(jsonLength);\n if (stream.isPastTheEnd) {\n this.invalidate();\n return;\n }\n\n let chunk;\n while (chunk = consumeNextChunk(stream)) {\n switch (chunk.type) {\n case GltfV2ChunkTypes.JSON:\n // Only one JSON chunk permitted and it must be the first.\n this.invalidate();\n return;\n case GltfV2ChunkTypes.Binary:\n // At most one binary chunk permitted and it must be the second if present.\n if (this.binaryChunk || this.additionalChunks.length) {\n this.invalidate();\n return;\n }\n\n this.binaryChunk = { offset: chunk.offset, length: chunk.length };\n break;\n default:\n // Any other chunk type should be ignored - for use by extensions.\n this.additionalChunks.push(chunk);\n break;\n }\n }\n\n if (false === chunk) {\n this.invalidate();\n return;\n }\n\n assert(undefined === chunk);\n assert(stream.isAtTheEnd);\n break;\n default:\n this.invalidate();\n break;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"GltfTileIO.js","sourceRoot":"","sources":["../../../src/tile/GltfTileIO.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAyD;AACzD,qCAAkD;AAElD;;GAEG;AACH,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,uDAAY,CAAA;IACZ,mEAAyB,CAAA;IACzB,uEAAoB,CAAA;AACtB,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB;AAED,gBAAgB;AAChB,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,gEAAiB,CAAA;IACjB,iEAAmB,CAAA;AACr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AQ,CAAC;QAEvC,IAAI,IAAI,CAAC,OAAO,KAAK,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC3C,MAAM,eAAe,GAAG,MAAM,CAAC;YAC/B,IAAI,YAAY,CAAC,gBAAgB,KAAK,eAAe,EAAE,CAAC;gBACtD,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;YACnC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;QAC5D,CAAC;aAAM,IAAI,IAAI,CAAC,OAAO,KAAK,YAAY,CAAC,QAAQ,EAAE,CAAC;YAClD,MAAM,cAAc,GAAG,MAAM,CAAC;YAC9B,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;YACnC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;YACpD,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;YACzC,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;YAC5C,IAAI,gBAAgB,CAAC,IAAI,KAAK,cAAc,IAAI,gBAAgB,CAAC,MAAM,KAAK,eAAe,IAAI,CAAC,KAAK,YAAY,EAAE,CAAC;gBAClH,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;CACF;AA5CD,gCA4CC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tile\n */\n\nimport { assert, ByteStream } from \"@itwin/core-bentley\";\nimport { TileFormat, TileHeader } from \"./TileIO\";\n\n/** Known version of the [glTF format](https://www.khronos.org/gltf/).\n * @internal\n */\nexport enum GltfVersions {\n Version1 = 1,\n Version2 = 2,\n CurrentVersion = Version1,\n Gltf1SceneFormat = 0,\n}\n\n/** @internal */\nexport enum GltfV2ChunkTypes {\n JSON = 0x4E4F534a,\n Binary = 0x004E4942,\n}\n\n/** A chunk of a glb file.\n * @internal\n */\nexport interface GltfChunk {\n /** Offset of the first byte of the chunk's data relative to the beginning of the glb data.\n * This excludes the 8-byte chunk header containing the length and type fields.\n */\n offset: number;\n /** The number of bytes in the chunk's data. */\n length: number;\n}\n\n/** Describes a glTF chunk's data along with its type.\n * @internal\n */\nexport type TypedGltfChunk = GltfChunk & { type: number };\n\nfunction consumeNextChunk(stream: ByteStream): TypedGltfChunk | undefined | false {\n if (stream.isAtTheEnd)\n return undefined;\n\n const offset = stream.curPos + 8;\n\n const length = stream.readUint32();\n if (stream.isAtTheEnd)\n return undefined;\n\n const type = stream.readUint32();\n stream.advance(length);\n return stream.isPastTheEnd ? false : { offset, length, type };\n}\n\n/** @internal */\nexport class GlbHeader extends TileHeader {\n public readonly gltfLength: number = 0;\n public readonly jsonChunk: GltfChunk = { offset: 0, length: 0 };\n public readonly binaryChunk?: GltfChunk;\n public readonly additionalChunks: TypedGltfChunk[] = [];\n\n public get isValid(): boolean {\n return TileFormat.Gltf === this.format;\n }\n\n public constructor(stream: ByteStream) {\n super(stream);\n this.gltfLength = stream.readUint32();\n\n const jsonLength = stream.readUint32();\n const word5 = stream.readUint32();\n\n // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles\n // validating the chunk type.\n if (this.version === GltfVersions.Version2 && word5 === GltfVersions.Gltf1SceneFormat)\n this.version = GltfVersions.Version1;\n\n this.jsonChunk = { offset: stream.curPos, length: jsonLength };\n switch (this.version) {\n case GltfVersions.Version1:\n if (GltfVersions.Gltf1SceneFormat !== word5) {\n this.invalidate();\n return;\n }\n\n const binaryOffset = stream.curPos + jsonLength;\n this.binaryChunk = { offset: binaryOffset, length: this.gltfLength - binaryOffset };\n break;\n case GltfVersions.Version2:\n if (word5 !== GltfV2ChunkTypes.JSON) {\n this.invalidate();\n return;\n }\n\n stream.advance(jsonLength);\n if (stream.isPastTheEnd) {\n this.invalidate();\n return;\n }\n\n let chunk;\n while (chunk = consumeNextChunk(stream)) {\n switch (chunk.type) {\n case GltfV2ChunkTypes.JSON:\n // Only one JSON chunk permitted and it must be the first.\n this.invalidate();\n return;\n case GltfV2ChunkTypes.Binary:\n // At most one binary chunk permitted and it must be the second if present.\n if (this.binaryChunk || this.additionalChunks.length) {\n this.invalidate();\n return;\n }\n\n this.binaryChunk = { offset: chunk.offset, length: chunk.length };\n break;\n default:\n // Any other chunk type should be ignored - for use by extensions.\n this.additionalChunks.push(chunk);\n break;\n }\n }\n\n if (false === chunk) {\n this.invalidate();\n return;\n }\n\n assert(undefined === chunk);\n assert(stream.isAtTheEnd);\n break;\n default:\n this.invalidate();\n break;\n }\n }\n}\n\n/** @internal */\nexport class GltfHeader extends TileHeader {\n public readonly gltfLength: number;\n public readonly scenePosition: number = 0;\n public readonly sceneStrLength: number = 0;\n public readonly binaryPosition: number = 0;\n public get isValid(): boolean { return TileFormat.Gltf === this.format; }\n\n public constructor(stream: ByteStream) {\n super(stream);\n this.gltfLength = stream.readUint32();\n\n this.sceneStrLength = stream.readUint32();\n const value5 = stream.readUint32();\n\n // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles\n // validating the chunk type.\n if (this.version === GltfVersions.Version2 && value5 === GltfVersions.Gltf1SceneFormat)\n this.version = GltfVersions.Version1;\n\n if (this.version === GltfVersions.Version1) {\n const gltfSceneFormat = value5;\n if (GltfVersions.Gltf1SceneFormat !== gltfSceneFormat) {\n this.invalidate();\n return;\n }\n\n this.scenePosition = stream.curPos;\n this.binaryPosition = stream.curPos + this.sceneStrLength;\n } else if (this.version === GltfVersions.Version2) {\n const sceneChunkType = value5;\n this.scenePosition = stream.curPos;\n stream.curPos = stream.curPos + this.sceneStrLength;\n const binaryLength = stream.readUint32();\n const binaryChunkType = stream.readUint32();\n if (GltfV2ChunkTypes.JSON !== sceneChunkType || GltfV2ChunkTypes.Binary !== binaryChunkType || 0 === binaryLength) {\n this.invalidate();\n return;\n }\n\n this.binaryPosition = stream.curPos;\n } else {\n this.invalidate();\n }\n }\n}\n\n"]}
@@ -43,4 +43,13 @@ export declare class GlbHeader extends TileHeader {
43
43
  get isValid(): boolean;
44
44
  constructor(stream: ByteStream);
45
45
  }
46
+ /** @internal */
47
+ export declare class GltfHeader extends TileHeader {
48
+ readonly gltfLength: number;
49
+ readonly scenePosition: number;
50
+ readonly sceneStrLength: number;
51
+ readonly binaryPosition: number;
52
+ get isValid(): boolean;
53
+ constructor(stream: ByteStream);
54
+ }
46
55
  //# sourceMappingURL=GltfTileIO.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GltfTileIO.d.ts","sourceRoot":"","sources":["../../../src/tile/GltfTileIO.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAU,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,oBAAY,YAAY;IACtB,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,cAAc,IAAW;IACzB,gBAAgB,IAAI;CACrB;AAED,gBAAgB;AAChB,oBAAY,gBAAgB;IAC1B,IAAI,aAAa;IACjB,MAAM,UAAa;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAiB1D,gBAAgB;AAChB,qBAAa,SAAU,S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;IACnC,SAAgB,aAAa,EAAE,MAAM,CAAK;IAC1C,SAAgB,cAAc,EAAE,MAAM,CAAK;IAC3C,SAAgB,cAAc,EAAE,MAAM,CAAK;IAC3C,IAAW,OAAO,IAAI,OAAO,CAA4C;gBAEtD,MAAM,EAAE,UAAU;CAqCtC"}
@@ -106,4 +106,46 @@ export class GlbHeader extends TileHeader {
106
106
  }
107
107
  }
108
108
  }
109
+ /** @internal */
110
+ export class GltfHeader extends TileHeader {
111
+ gltfLength;
112
+ scenePosition = 0;
113
+ sceneStrLength = 0;
114
+ binaryPosition = 0;
115
+ get isValid() { return TileFormat.Gltf === this.format; }
116
+ constructor(stream) {
117
+ super(stream);
118
+ this.gltfLength = stream.readUint32();
119
+ this.sceneStrLength = stream.readUint32();
120
+ const value5 = stream.readUint32();
121
+ // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles
122
+ // validating the chunk type.
123
+ if (this.version === GltfVersions.Version2 && value5 === GltfVersions.Gltf1SceneFormat)
124
+ this.version = GltfVersions.Version1;
125
+ if (this.version === GltfVersions.Version1) {
126
+ const gltfSceneFormat = value5;
127
+ if (GltfVersions.Gltf1SceneFormat !== gltfSceneFormat) {
128
+ this.invalidate();
129
+ return;
130
+ }
131
+ this.scenePosition = stream.curPos;
132
+ this.binaryPosition = stream.curPos + this.sceneStrLength;
133
+ }
134
+ else if (this.version === GltfVersions.Version2) {
135
+ const sceneChunkType = value5;
136
+ this.scenePosition = stream.curPos;
137
+ stream.curPos = stream.curPos + this.sceneStrLength;
138
+ const binaryLength = stream.readUint32();
139
+ const binaryChunkType = stream.readUint32();
140
+ if (GltfV2ChunkTypes.JSON !== sceneChunkType || GltfV2ChunkTypes.Binary !== binaryChunkType || 0 === binaryLength) {
141
+ this.invalidate();
142
+ return;
143
+ }
144
+ this.binaryPosition = stream.curPos;
145
+ }
146
+ else {
147
+ this.invalidate();
148
+ }
149
+ }
150
+ }
109
151
  //# sourceMappingURL=GltfTileIO.js.map
@@ -1 +1 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AI,MAAM,CAAC,YAAY,EAAE,CAAC;oBACxB,IAAI,CAAC,UAAU,EAAE,CAAC;oBAClB,OAAO;gBACT,CAAC;gBAED,IAAI,KAAK,CAAC;gBACV,OAAO,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;oBACxC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;wBACnB,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,CAAC;gCACrD,IAAI,CAAC,UAAU,EAAE,CAAC;gCAClB,OAAO;4BACT,CAAC;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;oBACV,CAAC;gBACH,CAAC;gBAED,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;oBACpB,IAAI,CAAC,UAAU,EAAE,CAAC;oBAClB,OAAO;gBACT,CAAC;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;QACV,CAAC;IACH,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tile\n */\n\nimport { assert, ByteStream } from \"@itwin/core-bentley\";\nimport { TileFormat, TileHeader } from \"./TileIO\";\n\n/** Known version of the [glTF format](https://www.khronos.org/gltf/).\n * @internal\n */\nexport enum GltfVersions {\n Version1 = 1,\n Version2 = 2,\n CurrentVersion = Version1,\n Gltf1SceneFormat = 0,\n}\n\n/** @internal */\nexport enum GltfV2ChunkTypes {\n JSON = 0x4E4F534a,\n Binary = 0x004E4942,\n}\n\n/** A chunk of a glb file.\n * @internal\n */\nexport interface GltfChunk {\n /** Offset of the first byte of the chunk's data relative to the beginning of the glb data.\n * This excludes the 8-byte chunk header containing the length and type fields.\n */\n offset: number;\n /** The number of bytes in the chunk's data. */\n length: number;\n}\n\n/** Describes a glTF chunk's data along with its type.\n * @internal\n */\nexport type TypedGltfChunk = GltfChunk & { type: number };\n\nfunction consumeNextChunk(stream: ByteStream): TypedGltfChunk | undefined | false {\n if (stream.isAtTheEnd)\n return undefined;\n\n const offset = stream.curPos + 8;\n\n const length = stream.readUint32();\n if (stream.isAtTheEnd)\n return undefined;\n\n const type = stream.readUint32();\n stream.advance(length);\n return stream.isPastTheEnd ? false : { offset, length, type };\n}\n\n/** @internal */\nexport class GlbHeader extends TileHeader {\n public readonly gltfLength: number = 0;\n public readonly jsonChunk: GltfChunk = { offset: 0, length: 0 };\n public readonly binaryChunk?: GltfChunk;\n public readonly additionalChunks: TypedGltfChunk[] = [];\n\n public get isValid(): boolean {\n return TileFormat.Gltf === this.format;\n }\n\n public constructor(stream: ByteStream) {\n super(stream);\n this.gltfLength = stream.readUint32();\n\n const jsonLength = stream.readUint32();\n const word5 = stream.readUint32();\n\n // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles\n // validating the chunk type.\n if (this.version === GltfVersions.Version2 && word5 === GltfVersions.Gltf1SceneFormat)\n this.version = GltfVersions.Version1;\n\n this.jsonChunk = { offset: stream.curPos, length: jsonLength };\n switch (this.version) {\n case GltfVersions.Version1:\n if (GltfVersions.Gltf1SceneFormat !== word5) {\n this.invalidate();\n return;\n }\n\n const binaryOffset = stream.curPos + jsonLength;\n this.binaryChunk = { offset: binaryOffset, length: this.gltfLength - binaryOffset };\n break;\n case GltfVersions.Version2:\n if (word5 !== GltfV2ChunkTypes.JSON) {\n this.invalidate();\n return;\n }\n\n stream.advance(jsonLength);\n if (stream.isPastTheEnd) {\n this.invalidate();\n return;\n }\n\n let chunk;\n while (chunk = consumeNextChunk(stream)) {\n switch (chunk.type) {\n case GltfV2ChunkTypes.JSON:\n // Only one JSON chunk permitted and it must be the first.\n this.invalidate();\n return;\n case GltfV2ChunkTypes.Binary:\n // At most one binary chunk permitted and it must be the second if present.\n if (this.binaryChunk || this.additionalChunks.length) {\n this.invalidate();\n return;\n }\n\n this.binaryChunk = { offset: chunk.offset, length: chunk.length };\n break;\n default:\n // Any other chunk type should be ignored - for use by extensions.\n this.additionalChunks.push(chunk);\n break;\n }\n }\n\n if (false === chunk) {\n this.invalidate();\n return;\n }\n\n assert(undefined === chunk);\n assert(stream.isAtTheEnd);\n break;\n default:\n this.invalidate();\n break;\n }\n }\n}\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,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,QAG3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EAAE,CAAC;YAC3C,MAAM,eAAe,GAAG,MAAM,CAAC;YAC/B,IAAI,YAAY,CAAC,gBAAgB,KAAK,eAAe,EAAE,CAAC;gBACtD,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;YACnC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;QAC5D,CAAC;aAAM,IAAI,IAAI,CAAC,OAAO,KAAK,YAAY,CAAC,QAAQ,EAAE,CAAC;YAClD,MAAM,cAAc,GAAG,MAAM,CAAC;YAC9B,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;YACnC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;YACpD,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;YACzC,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;YAC5C,IAAI,gBAAgB,CAAC,IAAI,KAAK,cAAc,IAAI,gBAAgB,CAAC,MAAM,KAAK,eAAe,IAAI,CAAC,KAAK,YAAY,EAAE,CAAC;gBAClH,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tile\n */\n\nimport { assert, ByteStream } from \"@itwin/core-bentley\";\nimport { TileFormat, TileHeader } from \"./TileIO\";\n\n/** Known version of the [glTF format](https://www.khronos.org/gltf/).\n * @internal\n */\nexport enum GltfVersions {\n Version1 = 1,\n Version2 = 2,\n CurrentVersion = Version1,\n Gltf1SceneFormat = 0,\n}\n\n/** @internal */\nexport enum GltfV2ChunkTypes {\n JSON = 0x4E4F534a,\n Binary = 0x004E4942,\n}\n\n/** A chunk of a glb file.\n * @internal\n */\nexport interface GltfChunk {\n /** Offset of the first byte of the chunk's data relative to the beginning of the glb data.\n * This excludes the 8-byte chunk header containing the length and type fields.\n */\n offset: number;\n /** The number of bytes in the chunk's data. */\n length: number;\n}\n\n/** Describes a glTF chunk's data along with its type.\n * @internal\n */\nexport type TypedGltfChunk = GltfChunk & { type: number };\n\nfunction consumeNextChunk(stream: ByteStream): TypedGltfChunk | undefined | false {\n if (stream.isAtTheEnd)\n return undefined;\n\n const offset = stream.curPos + 8;\n\n const length = stream.readUint32();\n if (stream.isAtTheEnd)\n return undefined;\n\n const type = stream.readUint32();\n stream.advance(length);\n return stream.isPastTheEnd ? false : { offset, length, type };\n}\n\n/** @internal */\nexport class GlbHeader extends TileHeader {\n public readonly gltfLength: number = 0;\n public readonly jsonChunk: GltfChunk = { offset: 0, length: 0 };\n public readonly binaryChunk?: GltfChunk;\n public readonly additionalChunks: TypedGltfChunk[] = [];\n\n public get isValid(): boolean {\n return TileFormat.Gltf === this.format;\n }\n\n public constructor(stream: ByteStream) {\n super(stream);\n this.gltfLength = stream.readUint32();\n\n const jsonLength = stream.readUint32();\n const word5 = stream.readUint32();\n\n // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles\n // validating the chunk type.\n if (this.version === GltfVersions.Version2 && word5 === GltfVersions.Gltf1SceneFormat)\n this.version = GltfVersions.Version1;\n\n this.jsonChunk = { offset: stream.curPos, length: jsonLength };\n switch (this.version) {\n case GltfVersions.Version1:\n if (GltfVersions.Gltf1SceneFormat !== word5) {\n this.invalidate();\n return;\n }\n\n const binaryOffset = stream.curPos + jsonLength;\n this.binaryChunk = { offset: binaryOffset, length: this.gltfLength - binaryOffset };\n break;\n case GltfVersions.Version2:\n if (word5 !== GltfV2ChunkTypes.JSON) {\n this.invalidate();\n return;\n }\n\n stream.advance(jsonLength);\n if (stream.isPastTheEnd) {\n this.invalidate();\n return;\n }\n\n let chunk;\n while (chunk = consumeNextChunk(stream)) {\n switch (chunk.type) {\n case GltfV2ChunkTypes.JSON:\n // Only one JSON chunk permitted and it must be the first.\n this.invalidate();\n return;\n case GltfV2ChunkTypes.Binary:\n // At most one binary chunk permitted and it must be the second if present.\n if (this.binaryChunk || this.additionalChunks.length) {\n this.invalidate();\n return;\n }\n\n this.binaryChunk = { offset: chunk.offset, length: chunk.length };\n break;\n default:\n // Any other chunk type should be ignored - for use by extensions.\n this.additionalChunks.push(chunk);\n break;\n }\n }\n\n if (false === chunk) {\n this.invalidate();\n return;\n }\n\n assert(undefined === chunk);\n assert(stream.isAtTheEnd);\n break;\n default:\n this.invalidate();\n break;\n }\n }\n}\n\n/** @internal */\nexport class GltfHeader extends TileHeader {\n public readonly gltfLength: number;\n public readonly scenePosition: number = 0;\n public readonly sceneStrLength: number = 0;\n public readonly binaryPosition: number = 0;\n public get isValid(): boolean { return TileFormat.Gltf === this.format; }\n\n public constructor(stream: ByteStream) {\n super(stream);\n this.gltfLength = stream.readUint32();\n\n this.sceneStrLength = stream.readUint32();\n const value5 = stream.readUint32();\n\n // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles\n // validating the chunk type.\n if (this.version === GltfVersions.Version2 && value5 === GltfVersions.Gltf1SceneFormat)\n this.version = GltfVersions.Version1;\n\n if (this.version === GltfVersions.Version1) {\n const gltfSceneFormat = value5;\n if (GltfVersions.Gltf1SceneFormat !== gltfSceneFormat) {\n this.invalidate();\n return;\n }\n\n this.scenePosition = stream.curPos;\n this.binaryPosition = stream.curPos + this.sceneStrLength;\n } else if (this.version === GltfVersions.Version2) {\n const sceneChunkType = value5;\n this.scenePosition = stream.curPos;\n stream.curPos = stream.curPos + this.sceneStrLength;\n const binaryLength = stream.readUint32();\n const binaryChunkType = stream.readUint32();\n if (GltfV2ChunkTypes.JSON !== sceneChunkType || GltfV2ChunkTypes.Binary !== binaryChunkType || 0 === binaryLength) {\n this.invalidate();\n return;\n }\n\n this.binaryPosition = stream.curPos;\n } else {\n this.invalidate();\n }\n }\n}\n\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-common",
3
- "version": "5.3.0-dev.21",
3
+ "version": "5.3.0-dev.23",
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",
@@ -27,8 +27,8 @@
27
27
  "js-base64": "^3.6.1"
28
28
  },
29
29
  "peerDependencies": {
30
- "@itwin/core-bentley": "5.3.0-dev.21",
31
- "@itwin/core-geometry": "5.3.0-dev.21"
30
+ "@itwin/core-bentley": "5.3.0-dev.23",
31
+ "@itwin/core-geometry": "5.3.0-dev.23"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@itwin/eslint-plugin": "5.2.2-dev.2",
@@ -42,9 +42,9 @@
42
42
  "rimraf": "^6.0.1",
43
43
  "typescript": "~5.6.2",
44
44
  "vitest": "^3.0.6",
45
- "@itwin/build-tools": "5.3.0-dev.21",
46
- "@itwin/core-geometry": "5.3.0-dev.21",
47
- "@itwin/core-bentley": "5.3.0-dev.21"
45
+ "@itwin/build-tools": "5.3.0-dev.23",
46
+ "@itwin/core-geometry": "5.3.0-dev.23",
47
+ "@itwin/core-bentley": "5.3.0-dev.23"
48
48
  },
49
49
  "nyc": {
50
50
  "extends": "./node_modules/@itwin/build-tools/.nycrc",