How to use the @bentley/bentleyjs-core.JsonUtils.asString function in @bentley/bentleyjs-core

To help you get started, we’ve selected a few @bentley/bentleyjs-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
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)
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
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 };
    }
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
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 };
    }
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
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);
    }
github imodeljs / imodeljs / core / frontend / src / tile / DgnTileIO.ts View on Github external
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;
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
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),
      };
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
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:
github imodeljs / imodeljs / core / backend / src / Category.ts View on Github external
public constructor(props: SubCategoryProps, iModel: IModelDb) {
    super(props, iModel);
    this.appearance = new SubCategoryAppearance(props.appearance);
    this.description = JsonUtils.asString(props.description);
  }