How to use the @bentley/geometry-core.Range3d.fromJSON function in @bentley/geometry-core

To help you get started, we’ve selected a few @bentley/geometry-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 / IModelConnection.ts View on Github external
private constructor(iModel: IModelProps, openMode: OpenMode) {
    super(iModel.iModelToken ? IModelToken.fromJSON(iModel.iModelToken) : undefined);
    super.initialize(iModel.name!, iModel);
    this.isBlank = undefined === iModel.iModelToken; // to differentiate between previously-open-but-now-closed vs. blank
    this.openMode = openMode;
    this.models = new IModelConnection.Models(this);
    this.elements = new IModelConnection.Elements(this);
    this.codeSpecs = new IModelConnection.CodeSpecs(this);
    this.views = new IModelConnection.Views(this);
    this.selectionSet = new SelectionSet(this);
    this.hilited = new HiliteSet(this);
    this.tiles = new IModelConnection.Tiles(this);
    this.subcategories = new SubCategoriesCache(this);
    this.geoServices = new GeoServices(this);
    this.displayedExtents = Range3d.fromJSON(this.projectExtents);
  }
github imodeljs / imodeljs / test-apps / imodel-from-reality-model / src / RealityModelContextIModelCreator.ts View on Github external
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();

      const tileRange = rootTransform.multiplyRange(range);
      if (rootTransform.matrix.isIdentity && range.center.magnitude() < 1.0E5) {
        geoLocated = false;
        worldRange.extendRange(Range3d.fromJSON(tileRange));
      } else {
        const ecefCenter = tileRange.localXYZToWorld(.5, .5, .5)!;
        const cartoCenter = Cartographic.fromEcef(ecefCenter);
        const ecefLocation = EcefLocation.createFromCartographicOrigin(cartoCenter!);
        this.iModelDb.setEcefLocation(ecefLocation);
        const ecefToWorld = ecefLocation.getTransform().inverse()!;
        worldRange.extendRange(Range3d.fromJSON(ecefToWorld.multiplyRange(tileRange)));
      }
    }
    return { realityModel: { tilesetUrl: this.url, name: this._name ? this._name : this.url }, geoLocated };
  }
  /** Perform the import */
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();

      const tileRange = rootTransform.multiplyRange(range);
      if (rootTransform.matrix.isIdentity && range.center.magnitude() < 1.0E5) {
        geoLocated = false;
        worldRange.extendRange(Range3d.fromJSON(tileRange));
      } else {
        const ecefCenter = tileRange.localXYZToWorld(.5, .5, .5)!;
        const cartoCenter = Cartographic.fromEcef(ecefCenter);
        const ecefLocation = EcefLocation.createFromCartographicOrigin(cartoCenter!);
        this.iModelDb.setEcefLocation(ecefLocation);
        const ecefToWorld = ecefLocation.getTransform().inverse()!;
github imodeljs / imodeljs / test-apps / imodel-from-reality-model / src / RealityModelContextIModelCreator.ts View on Github external
requestPromise(this.url, { json: true }).then((json: any) => {
      if (this.url.endsWith("_AppData.json")) {
        const nameIndex = this.url.lastIndexOf("TileSets");
        const prefix = this.url.substr(0, nameIndex);
        let worldToEcef: Transform | undefined;
        for (const modelValue of Object.values(json.models)) {
          const model = modelValue as any;
          if (model.tilesetUrl !== undefined &&
            model.type === "spatial") {
            let modelUrl = prefix + model.tilesetUrl.replace(/\/\//g, "/");
            modelUrl = modelUrl.replace(/ /g, "%20");
            const ecefRange = Range3d.fromJSON(model.extents);
            if (!worldToEcef) {
              worldToEcef = RealityModelTileUtils.transformFromJson(model.transform)!;
              const ecefCenter = ecefRange.localXYZToWorld(.5, .5, .5)!;
              const cartoCenter = Cartographic.fromEcef(ecefCenter);
              const ecefLocation = EcefLocation.createFromCartographicOrigin(cartoCenter!);
              this.iModelDb.setEcefLocation(ecefLocation);
              geoLocated = true;
            }
            worldRange.extendRange(worldToEcef.inverse()!.multiplyRange(ecefRange));
            realityModels.push({ tilesetUrl: modelUrl, name: this._name ? this._name : model.name });
          }
        }
      } else {
        const result = this.realityModelFromJson(json, worldRange);
        if (result.realityModel) {
          realityModels.push(result.realityModel);
github imodeljs / imodeljs / core / backend / src / rpc-impl / IModelWriteRpcImpl.ts View on Github external
public async updateProjectExtents(tokenProps: IModelTokenProps, newExtents: AxisAlignedBox3dProps): Promise {
    const iModelToken = IModelToken.fromJSON(tokenProps);
    IModelDb.find(iModelToken).updateProjectExtents(Range3d.fromJSON(newExtents));
  }
github imodeljs / imodeljs / core / frontend / src / tile / Tile.ts View on Github external
export function paramsFromJSON(props: TileProps, root: TileTree, parent?: Tile): Params {
    const contentRange = undefined !== props.contentRange ? Range3d.fromJSON(props.contentRange) : undefined;
    const transformToRoot = undefined !== props.transformToRoot ? Transform.fromJSON(props.transformToRoot) : undefined;
    return {
      root,
      contentId: props.contentId,
      range: Range3d.fromJSON(props.range),
      maximumSize: props.maximumSize,
      isLeaf: props.isLeaf,
      parent,
      contentRange,
      transformToRoot,
      sizeMultiplier: props.sizeMultiplier,
    };
  }
github imodeljs / imodeljs / core / backend / src / Element.ts View on Github external
public constructor(props: GeometryPartProps, iModel: IModelDb) {
    super(props, iModel);
    this.geom = props.geom;
    this.bbox = Range3d.fromJSON(props.bbox);
  }
github imodeljs / imodeljs / core / common / src / geometry / GeometryStream.ts View on Github external
if (entry.fill.gradient)
          this.entry.geomParams.gradient = Gradient.Symb.fromJSON(entry.fill.gradient);
        else if (entry.fill.backgroundFill)
          this.entry.geomParams.backgroundFill = entry.fill.backgroundFill;
        else if (entry.fill.color)
          this.entry.geomParams.fillColor = new ColorDef(entry.fill.color);
      } else if (entry.pattern) {
        const params = AreaPattern.Params.fromJSON(entry.pattern);
        if (this.entry.localToWorld !== undefined)
          params.applyTransform(this.entry.localToWorld);
        this.entry.geomParams.pattern = params;
      } else if (entry.material) {
        if (entry.material.materialId)
          this.entry.geomParams.materialId = Id64.fromJSON(entry.material.materialId);
      } else if (entry.subRange) {
        this.entry.localRange = Range3d.fromJSON(entry.subRange);
      } else if (entry.geomPart) {
        this.entry.partId = Id64.fromJSON(entry.geomPart.part);
        if (entry.geomPart.origin !== undefined || entry.geomPart.rotation !== undefined || entry.geomPart.scale !== undefined) {
          const origin = entry.geomPart.origin ? Point3d.fromJSON(entry.geomPart.origin) : Point3d.createZero();
          const rotation = entry.geomPart.rotation ? YawPitchRollAngles.fromJSON(entry.geomPart.rotation).toMatrix3d() : Matrix3d.createIdentity();
          this.entry.partToLocal = Transform.createRefs(origin, rotation);
          if (entry.geomPart.scale)
            this.entry.partToLocal.multiplyTransformTransform(Transform.createRefs(Point3d.createZero(), Matrix3d.createUniformScale(entry.geomPart.scale)), this.entry.partToLocal);
        }
        return { value: this.entry, done: false };
      } else if (entry.textString) {
        this.entry.textString = new TextString(entry.textString);
        if (this.entry.localToWorld !== undefined)
          this.entry.textString.transformInPlace(this.entry.localToWorld);
        return { value: this.entry, done: false };
      } else if (entry.brep) {