Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const json = primitive.instances;
if (undefined === json)
return undefined;
const count = JsonUtils.asInt(json.count, 0);
if (count <= 0)
return undefined;
const centerComponents = JsonUtils.asArray(json.transformCenter);
if (undefined === centerComponents || 3 !== centerComponents.length)
return undefined;
const transformCenter = Point3d.create(centerComponents[0], centerComponents[1], centerComponents[2]);
const featureIds = this.findBuffer(JsonUtils.asString(json.featureIds));
if (undefined === featureIds)
return undefined;
const transformBytes = this.findBuffer(JsonUtils.asString(json.transforms));
if (undefined === transformBytes)
return undefined;
// 1 transform = 3 rows of 4 floats = 12 floats per instance
const numFloats = transformBytes.byteLength / 4;
assert(Math.floor(numFloats) === numFloats);
assert(0 === numFloats % 12);
const transforms = new Float32Array(transformBytes.buffer, transformBytes.byteOffset, numFloats);
let symbologyOverrides: Uint8Array | undefined;
if (undefined !== json.symbologyOverrides)
const count = JsonUtils.asInt(json.count, 0);
if (count <= 0)
return undefined;
const centerComponents = JsonUtils.asArray(json.transformCenter);
if (undefined === centerComponents || 3 !== centerComponents.length)
return undefined;
const transformCenter = Point3d.create(centerComponents[0], centerComponents[1], centerComponents[2]);
const featureIds = this.findBuffer(JsonUtils.asString(json.featureIds));
if (undefined === featureIds)
return undefined;
const transformBytes = this.findBuffer(JsonUtils.asString(json.transforms));
if (undefined === transformBytes)
return undefined;
// 1 transform = 3 rows of 4 floats = 12 floats per instance
const numFloats = transformBytes.byteLength / 4;
assert(Math.floor(numFloats) === numFloats);
assert(0 === numFloats % 12);
const transforms = new Float32Array(transformBytes.buffer, transformBytes.byteOffset, numFloats);
let symbologyOverrides: Uint8Array | undefined;
if (undefined !== json.symbologyOverrides)
symbologyOverrides = this.findBuffer(JsonUtils.asString(json.symbologyOverrides));
return { count, transforms, transformCenter, featureIds, symbologyOverrides };
}
return undefined;
const transformBytes = this.findBuffer(JsonUtils.asString(json.transforms));
if (undefined === transformBytes)
return undefined;
// 1 transform = 3 rows of 4 floats = 12 floats per instance
const numFloats = transformBytes.byteLength / 4;
assert(Math.floor(numFloats) === numFloats);
assert(0 === numFloats % 12);
const transforms = new Float32Array(transformBytes.buffer, transformBytes.byteOffset, numFloats);
let symbologyOverrides: Uint8Array | undefined;
if (undefined !== json.symbologyOverrides)
symbologyOverrides = this.findBuffer(JsonUtils.asString(json.symbologyOverrides));
return { count, transforms, transformCenter, featureIds, symbologyOverrides };
}
private readAuxChannelTable(primitive: any): AuxChannelTable | undefined {
const json = primitive.auxChannels;
if (undefined === json)
return undefined;
const bytes = this.findBuffer(JsonUtils.asString(json.bufferView));
if (undefined === bytes)
return undefined;
const props: AuxChannelTableProps = {
data: bytes,
width: json.width,
height: json.height,
count: json.count,
numBytesPerVertex: json.numBytesPerVertex,
displacements: json.displacements,
normals: json.normals,
params: json.params,
};
return AuxChannelTable.fromJSON(props);
}
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;
private textureMappingFromJson(json: any): TextureMapping | undefined {
if (undefined === json)
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),
};
private readMeshGraphic(primitive: any): RenderGraphic | undefined {
const materialName = JsonUtils.asString(primitive.material);
const materialValue = 0 < materialName.length ? JsonUtils.asObject(this._materialValues[materialName]) : undefined;
const displayParams = undefined !== materialValue ? this.createDisplayParams(materialValue) : undefined;
if (undefined === displayParams)
return undefined;
const vertices = this.readVertexTable(primitive);
if (undefined === vertices) {
assert(false, "bad vertex table in tile data.");
return undefined;
}
const isPlanar = JsonUtils.asBool(primitive.isPlanar);
const primitiveType = JsonUtils.asInt(primitive.type, Mesh.PrimitiveType.Mesh);
const instances = this.readInstances(primitive);
switch (primitiveType) {
case Mesh.PrimitiveType.Mesh:
public constructor(props: SubCategoryProps, iModel: IModelDb) {
super(props, iModel);
this.appearance = new SubCategoryAppearance(props.appearance);
this.description = JsonUtils.asString(props.description);
}