How to use the @bentley/bentleyjs-core.JsonUtils.asArray 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
private readInstances(primitive: any): Point3d | InstancedGraphicParams | undefined {
      const viJson = primitive.viewIndependentOrigin;
      if (undefined !== viJson)
        return Point3d.fromJSON(viJson);

      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);
github imodeljs / imodeljs / test-apps / imodel-from-reality-model / src / RealityModelContextIModelCreator.ts View on Github external
private realityModelFromJson(json: any, worldRange: AxisAlignedBox3d): { realityModel: ContextRealityModelProps | undefined, geoLocated: boolean } {
    let geoLocated = true;
    if (undefined !== json.root.boundingVolume.region) {
      const region = JsonUtils.asArray(json.root.boundingVolume.region);
      if (undefined === region)
        throw new TypeError("Unable to determine GeoLocation - no root Transform or Region on root.");
      const ecefLow = (new Cartographic(region[0], region[1], region[4])).toEcef();
      const ecefHigh = (new Cartographic(region[2], region[3], region[5])).toEcef();
      const ecefRange = Range3d.create(ecefLow, ecefHigh);
      const cartoCenter = new Cartographic((region[0] + region[2]) / 2.0, (region[1] + region[3]) / 2.0, (region[4] + region[5]) / 2.0);
      const ecefLocation = EcefLocation.createFromCartographicOrigin(cartoCenter!);
      this.iModelDb.setEcefLocation(ecefLocation);
      const ecefToWorld = ecefLocation.getTransform().inverse()!;
      worldRange.extendRange(Range3d.fromJSON(ecefToWorld.multiplyRange(ecefRange)));
    } else {
      let rootTransform = RealityModelTileUtils.transformFromJson(json.root.transform);
      const range = RealityModelTileUtils.rangeFromBoundingVolume(json.root.boundingVolume)!;
      if (undefined === rootTransform)
        rootTransform = Transform.createIdentity();
github imodeljs / imodeljs / core / common / src / ViewProps.ts View on Github external
private findIndexOfSubCategoryOverrideInJSON(id: Id64String, allowAppend: boolean): number {
    const ovrsArray = JsonUtils.asArray(this._json.subCategoryOvr);
    if (undefined === ovrsArray) {
      if (allowAppend) {
        this._json.subCategoryOvr = [];
        return 0;
      } else {
        return -1;
      }
    } else {
      for (let i = 0; i < ovrsArray.length; i++) {
        if (ovrsArray[i].subCategory === id)
          return i;
      }

      return allowAppend ? ovrsArray.length : -1;
    }
  }
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
if (undefined === bytes)
        return undefined;

      const uniformFeatureID = undefined !== json.featureID ? JsonUtils.asInt(json.featureID) : undefined;

      const rangeMin = JsonUtils.asArray(json.params.decodedMin);
      const rangeMax = JsonUtils.asArray(json.params.decodedMax);
      if (undefined === rangeMin || undefined === rangeMax)
        return undefined;

      const qparams = QParams3d.fromRange(Range3d.create(Point3d.create(rangeMin[0], rangeMin[1], rangeMin[2]), Point3d.create(rangeMax[0], rangeMax[1], rangeMax[2])));

      const uniformColor = undefined !== json.uniformColor ? ColorDef.fromJSON(json.uniformColor) : undefined;
      let uvParams: QParams2d | undefined;
      if (undefined !== primitive.surface && undefined !== primitive.surface.uvParams) {
        const uvMin = JsonUtils.asArray(primitive.surface.uvParams.decodedMin);
        const uvMax = JsonUtils.asArray(primitive.surface.uvParams.decodedMax);
        if (undefined === uvMin || undefined === uvMax)
          return undefined;

        const uvRange = new Range2d(uvMin[0], uvMin[1], uvMax[0], uvMax[1]);
        uvParams = QParams2d.fromRange(uvRange);
      }

      return new VertexTable({
        data: bytes,
        qparams,
        width: json.width,
        height: json.height,
        hasTranslucency: json.hasTranslucency,
        uniformColor,
        featureIndexType: json.featureIndexType,
github imodeljs / imodeljs / core / common / src / ViewProps.ts View on Github external
this._monochrome = undefined !== this._json.monochromeColor ? ColorDef.fromJSON(this._json.monochromeColor) : ColorDef.white.clone();
    this._backgroundMap = BackgroundMapSettings.fromJSON(this._json.backgroundMap);

    const ovrsArray = JsonUtils.asArray(this._json.subCategoryOvr);
    if (undefined !== ovrsArray) {
      for (const ovrJson of ovrsArray) {
        const subCatId = Id64.fromJSON(ovrJson.subCategory);
        if (Id64.isValid(subCatId)) {
          const subCatOvr = SubCategoryOverride.fromJSON(ovrJson);
          if (subCatOvr.anyOverridden)
            this.changeSubCategoryOverride(subCatId, false, subCatOvr);
        }
      }
    }

    const exElemArray = JsonUtils.asArray(this._json.excludedElements);
    if (undefined !== exElemArray) {
      for (const exElemStr of exElemArray) {
        const exElem = Id64.fromJSON(exElemStr);
        if (Id64.isValid(exElem)) {
          this._excludedElements.add(exElem);
        }
      }
    }
  }
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
private readVertexTable(primitive: any): VertexTable | undefined {
      const json = primitive.vertices;
      if (undefined === json)
        return undefined;

      const bytes = this.findBuffer(JsonUtils.asString(json.bufferView));
      if (undefined === bytes)
        return undefined;

      const uniformFeatureID = undefined !== json.featureID ? JsonUtils.asInt(json.featureID) : undefined;

      const rangeMin = JsonUtils.asArray(json.params.decodedMin);
      const rangeMax = JsonUtils.asArray(json.params.decodedMax);
      if (undefined === rangeMin || undefined === rangeMax)
        return undefined;

      const qparams = QParams3d.fromRange(Range3d.create(Point3d.create(rangeMin[0], rangeMin[1], rangeMin[2]), Point3d.create(rangeMax[0], rangeMax[1], rangeMax[2])));

      const uniformColor = undefined !== json.uniformColor ? ColorDef.fromJSON(json.uniformColor) : undefined;
      let uvParams: QParams2d | undefined;
      if (undefined !== primitive.surface && undefined !== primitive.surface.uvParams) {
        const uvMin = JsonUtils.asArray(primitive.surface.uvParams.decodedMin);
        const uvMax = JsonUtils.asArray(primitive.surface.uvParams.decodedMax);
        if (undefined === uvMin || undefined === uvMax)
          return undefined;

        const uvRange = new Range2d(uvMin[0], uvMin[1], uvMax[0], uvMax[1]);
        uvParams = QParams2d.fromRange(uvRange);
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
return undefined;

      const uniformFeatureID = undefined !== json.featureID ? JsonUtils.asInt(json.featureID) : undefined;

      const rangeMin = JsonUtils.asArray(json.params.decodedMin);
      const rangeMax = JsonUtils.asArray(json.params.decodedMax);
      if (undefined === rangeMin || undefined === rangeMax)
        return undefined;

      const qparams = QParams3d.fromRange(Range3d.create(Point3d.create(rangeMin[0], rangeMin[1], rangeMin[2]), Point3d.create(rangeMax[0], rangeMax[1], rangeMax[2])));

      const uniformColor = undefined !== json.uniformColor ? ColorDef.fromJSON(json.uniformColor) : undefined;
      let uvParams: QParams2d | undefined;
      if (undefined !== primitive.surface && undefined !== primitive.surface.uvParams) {
        const uvMin = JsonUtils.asArray(primitive.surface.uvParams.decodedMin);
        const uvMax = JsonUtils.asArray(primitive.surface.uvParams.decodedMax);
        if (undefined === uvMin || undefined === uvMax)
          return undefined;

        const uvRange = new Range2d(uvMin[0], uvMin[1], uvMax[0], uvMax[1]);
        uvParams = QParams2d.fromRange(uvRange);
      }

      return new VertexTable({
        data: bytes,
        qparams,
        width: json.width,
        height: json.height,
        hasTranslucency: json.hasTranslucency,
        uniformColor,
        featureIndexType: json.featureIndexType,
        uniformFeatureID,