Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return undefined;
// NB: We make a copy of the sub-array because we don't want to pin the entire data array in memory.
const numUint32s = (header.length - FeatureTableHeader.sizeInBytes) / 4;
const packedFeatureArray = new Uint32Array(this._buffer.nextUint32s(numUint32s));
if (this._buffer.isPastTheEnd)
return undefined;
let animNodesArray: Uint8Array | Uint16Array | Uint32Array | undefined;
const animationNodes = JsonUtils.asObject(this._scene.animationNodes);
if (undefined !== animationNodes) {
const bytesPerId = JsonUtils.asInt(animationNodes.bytesPerId);
const bufferViewId = JsonUtils.asString(animationNodes.bufferView);
const bufferViewJson = this._bufferViews[bufferViewId];
if (undefined !== bufferViewJson) {
const byteOffset = JsonUtils.asInt(bufferViewJson.byteOffset);
const byteLength = JsonUtils.asInt(bufferViewJson.byteLength);
const bytes = this._binaryData.subarray(byteOffset, byteOffset + byteLength);
switch (bytesPerId) {
case 1:
animNodesArray = new Uint8Array(bytes);
break;
case 2:
// NB: A *copy* of the subarray.
animNodesArray = Uint16Array.from(new Uint16Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 2));
break;
case 4:
// NB: A *copy* of the subarray.
animNodesArray = Uint32Array.from(new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4));
break;
}
}
protected createDisplayParams(json: any): DisplayParams | undefined {
const type = JsonUtils.asInt(json.type, DisplayParams.Type.Mesh);
const lineColor = new ColorDef(JsonUtils.asInt(json.lineColor));
const fillColor = new ColorDef(JsonUtils.asInt(json.fillColor));
const width = JsonUtils.asInt(json.lineWidth);
const linePixels = JsonUtils.asInt(json.linePixels, LinePixels.Solid);
const fillFlags = JsonUtils.asInt(json.fillFlags, FillFlags.None);
const ignoreLighting = JsonUtils.asBool(json.ignoreLighting);
// Material will always contain its own texture if it has one
const materialKey = json.materialId;
const material = undefined !== materialKey ? this.materialFromJson(materialKey) : undefined;
// We will only attempt to include the texture if material is undefined
let textureMapping;
if (!material) {
const textureJson = json.texture;
textureMapping = undefined !== textureJson ? this.textureMappingFromJson(textureJson) : undefined;
if (undefined === textureMapping) {
// Look for a gradient. If defined, create a texture mapping. No reason to pass the Gradient.Symb to the DisplayParams once we have the texture.
protected createDisplayParams(json: any): DisplayParams | undefined {
const type = JsonUtils.asInt(json.type, DisplayParams.Type.Mesh);
const lineColor = new ColorDef(JsonUtils.asInt(json.lineColor));
const fillColor = new ColorDef(JsonUtils.asInt(json.fillColor));
const width = JsonUtils.asInt(json.lineWidth);
const linePixels = JsonUtils.asInt(json.linePixels, LinePixels.Solid);
const fillFlags = JsonUtils.asInt(json.fillFlags, FillFlags.None);
const ignoreLighting = JsonUtils.asBool(json.ignoreLighting);
// Material will always contain its own texture if it has one
const materialKey = json.materialId;
const material = undefined !== materialKey ? this.materialFromJson(materialKey) : undefined;
// We will only attempt to include the texture if material is undefined
let textureMapping;
if (!material) {
const textureJson = json.texture;
textureMapping = undefined !== textureJson ? this.textureMappingFromJson(textureJson) : undefined;
if (undefined === textureMapping) {
// Look for a gradient. If defined, create a texture mapping. No reason to pass the Gradient.Symb to the DisplayParams once we have the texture.
protected createDisplayParams(json: any): DisplayParams | undefined {
const type = JsonUtils.asInt(json.type, DisplayParams.Type.Mesh);
const lineColor = new ColorDef(JsonUtils.asInt(json.lineColor));
const fillColor = new ColorDef(JsonUtils.asInt(json.fillColor));
const width = JsonUtils.asInt(json.lineWidth);
const linePixels = JsonUtils.asInt(json.linePixels, LinePixels.Solid);
const fillFlags = JsonUtils.asInt(json.fillFlags, FillFlags.None);
const ignoreLighting = JsonUtils.asBool(json.ignoreLighting);
// Material will always contain its own texture if it has one
const materialKey = json.materialId;
const material = undefined !== materialKey ? this.materialFromJson(materialKey) : undefined;
// We will only attempt to include the texture if material is undefined
let textureMapping;
if (!material) {
const textureJson = json.texture;
textureMapping = undefined !== textureJson ? this.textureMappingFromJson(textureJson) : undefined;
if (undefined === textureMapping) {
// Look for a gradient. If defined, create a texture mapping. No reason to pass the Gradient.Symb to the DisplayParams once we have the texture.
const gradientProps = json.gradient as Gradient.SymbProps;
protected createDisplayParams(json: any): DisplayParams | undefined {
const type = JsonUtils.asInt(json.type, DisplayParams.Type.Mesh);
const lineColor = new ColorDef(JsonUtils.asInt(json.lineColor));
const fillColor = new ColorDef(JsonUtils.asInt(json.fillColor));
const width = JsonUtils.asInt(json.lineWidth);
const linePixels = JsonUtils.asInt(json.linePixels, LinePixels.Solid);
const fillFlags = JsonUtils.asInt(json.fillFlags, FillFlags.None);
const ignoreLighting = JsonUtils.asBool(json.ignoreLighting);
// Material will always contain its own texture if it has one
const materialKey = json.materialId;
const material = undefined !== materialKey ? this.materialFromJson(materialKey) : undefined;
// We will only attempt to include the texture if material is undefined
let textureMapping;
if (!material) {
const textureJson = json.texture;
textureMapping = undefined !== textureJson ? this.textureMappingFromJson(textureJson) : undefined;
// NB: We make a copy of the sub-array because we don't want to pin the entire data array in memory.
const numUint32s = (header.length - FeatureTableHeader.sizeInBytes) / 4;
const packedFeatureArray = new Uint32Array(this._buffer.nextUint32s(numUint32s));
if (this._buffer.isPastTheEnd)
return undefined;
let animNodesArray: Uint8Array | Uint16Array | Uint32Array | undefined;
const animationNodes = JsonUtils.asObject(this._scene.animationNodes);
if (undefined !== animationNodes) {
const bytesPerId = JsonUtils.asInt(animationNodes.bytesPerId);
const bufferViewId = JsonUtils.asString(animationNodes.bufferView);
const bufferViewJson = this._bufferViews[bufferViewId];
if (undefined !== bufferViewJson) {
const byteOffset = JsonUtils.asInt(bufferViewJson.byteOffset);
const byteLength = JsonUtils.asInt(bufferViewJson.byteLength);
const bytes = this._binaryData.subarray(byteOffset, byteOffset + byteLength);
switch (bytesPerId) {
case 1:
animNodesArray = new Uint8Array(bytes);
break;
case 2:
// NB: A *copy* of the subarray.
animNodesArray = Uint16Array.from(new Uint16Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 2));
break;
case 4:
// NB: A *copy* of the subarray.
animNodesArray = Uint32Array.from(new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4));
break;
}
}
}
private async readNamedTexture(namedTex: any, name: string): Promise {
const bufferViewId = JsonUtils.asString(namedTex.bufferView);
const bufferViewJson = 0 !== bufferViewId.length ? this._bufferViews[bufferViewId] : undefined;
if (undefined === bufferViewJson)
return Promise.resolve(undefined);
const byteOffset = JsonUtils.asInt(bufferViewJson.byteOffset);
const byteLength = JsonUtils.asInt(bufferViewJson.byteLength);
if (0 === byteLength)
return Promise.resolve(undefined);
const bytes = this._binaryData.subarray(byteOffset, byteOffset + byteLength);
const format = namedTex.format;
const imageSource = new ImageSource(bytes, format);
return imageElementFromImageSource(imageSource).then((image) => {
if (this._isCanceled)
return undefined;
let textureType = RenderTexture.Type.Normal;
if (JsonUtils.asBool(namedTex.isGlyph))
textureType = RenderTexture.Type.Glyph;
else if (JsonUtils.asBool(namedTex.isTileSection))
textureType = RenderTexture.Type.TileSection;
private async readNamedTexture(namedTex: any): Promise {
const bufferViewId = JsonUtils.asString(namedTex.bufferView);
const bufferViewJson = 0 !== bufferViewId.length ? this._bufferViews[bufferViewId] : undefined;
if (undefined === bufferViewJson)
return Promise.resolve(undefined);
const byteOffset = JsonUtils.asInt(bufferViewJson.byteOffset);
const byteLength = JsonUtils.asInt(bufferViewJson.byteLength);
if (0 === byteLength)
return Promise.resolve(undefined);
const bytes = this._binaryData.subarray(byteOffset, byteOffset + byteLength);
const format = namedTex.format;
const imageSource = new ImageSource(bytes, format);
return imageElementFromImageSource(imageSource).then((image) => {
if (this._isCanceled)
return undefined;
let textureType = RenderTexture.Type.Normal;
if (JsonUtils.asBool(namedTex.isGlyph))
textureType = RenderTexture.Type.Glyph;
else if (JsonUtils.asBool(namedTex.isTileSection))
textureType = RenderTexture.Type.TileSection;
return undefined;
const name = JsonUtils.asString(json.name);
const namedTex = 0 !== name.length ? this._namedTextures[name] : undefined;
const texture = undefined !== namedTex ? namedTex.renderTexture as RenderTexture : undefined;
if (undefined === texture) {
assert(false, "bad texture mapping json");
return undefined;
}
const paramsJson = json.params;
const tf = paramsJson.transform;
const paramProps: TextureMapping.ParamProps = {
textureMat2x3: new TextureMapping.Trans2x3(tf[0][0], tf[0][1], tf[0][2], tf[1][0], tf[1][1], tf[1][2]),
textureWeight: JsonUtils.asDouble(paramsJson.weight, 1.0),
mapMode: JsonUtils.asInt(paramsJson.mode),
worldMapping: JsonUtils.asBool(paramsJson.worldMapping),
};
return new TextureMapping(texture, new TextureMapping.Params(paramProps));
}