How to use the @bentley/bentleyjs-core.JsonUtils.asBool 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
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;
          const gradient = undefined !== gradientProps ? Gradient.Symb.fromJSON(gradientProps) : undefined;
          if (undefined !== gradient) {
github imodeljs / imodeljs / core / backend / src / Model.ts View on Github external
constructor(props: ModelProps, iModel: IModelDb) {
    super(props, iModel);
    this.name = props.name ? props.name : ""; // NB this isn't really a property of Model (it's the code.value of the modeled element), but it comes in ModelProps because it's often needed
    this.isPrivate = JsonUtils.asBool(props.isPrivate);
    this.isTemplate = JsonUtils.asBool(props.isTemplate);
    this.jsonProperties = Object.assign({}, props.jsonProperties); // make sure we have our own copy
  }
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
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));
    }
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
materialParams.diffuse = JsonUtils.asDouble(materialJson.diffuse);
        materialParams.specularColor = this.colorDefFromMaterialJson(materialJson.specularColor);
        if (materialJson.specular !== undefined)
          materialParams.specular = JsonUtils.asDouble(materialJson.specular);
        materialParams.reflectColor = this.colorDefFromMaterialJson(materialJson.reflectColor);
        if (materialJson.reflect !== undefined)
          materialParams.reflect = JsonUtils.asDouble(materialJson.reflect);

        if (materialJson.specularExponent !== undefined)
          materialParams.specularExponent = materialJson.specularExponent;

        if (undefined !== materialJson.transparency)
          materialParams.alpha = 1.0 - materialJson.transparency;

        materialParams.refract = JsonUtils.asDouble(materialJson.refract);
        materialParams.shadows = JsonUtils.asBool(materialJson.shadows);
        materialParams.ambient = JsonUtils.asDouble(materialJson.ambient);

        if (undefined !== materialJson.textureMapping)
          materialParams.textureMapping = this.textureMappingFromJson(materialJson.textureMapping.texture);

        material = this._system.createMaterial(materialParams, this._iModel);
      }

      return material;
    }
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:
          return this.createMeshGraphic(primitive, displayParams, vertices, isPlanar, this.readAuxChannelTable(primitive), instances);
        case Mesh.PrimitiveType.Polyline:
          return this.createPolylineGraphic(primitive, displayParams, vertices, isPlanar, instances);
        case Mesh.PrimitiveType.Point:
          return this.createPointStringGraphic(primitive, displayParams, vertices, instances);
      }

      assert(false, "unhandled primitive type");
      return undefined;
    }
github imodeljs / imodeljs / core / frontend / src / tile / IModelTileIO.ts View on Github external
const indices = this.readVertexIndices(surf.indices);
      if (undefined === indices)
        return undefined;

      const type = JsonUtils.asInt(surf.type, -1);
      if (!isValidSurfaceType(type))
        return undefined;

      const texture = undefined !== displayParams.textureMapping ? displayParams.textureMapping.texture : undefined;
      let material: SurfaceMaterial | undefined;
      const atlas = mesh.vertices.materialAtlas;
      const numColors = mesh.vertices.numColors;
      if (undefined !== atlas && undefined !== numColors) {
        material = {
          isAtlas: true,
          hasTranslucency: JsonUtils.asBool(atlas.hasTranslucency),
          overridesAlpha: JsonUtils.asBool(atlas.overridesAlpha, false),
          vertexTableOffset: JsonUtils.asInt(numColors),
          numMaterials: JsonUtils.asInt(atlas.numMaterials),
        };
      } else {
        material = createSurfaceMaterial(displayParams.material);
      }

      return {
        type,
        indices,
        fillFlags: displayParams.fillFlags,
        hasBakedLighting: false,
        hasFixedNormals: false,
        material,
        texture,
github imodeljs / imodeljs / core / frontend / src / tile / DgnTileIO.ts View on Github external
materialParams.diffuseColor = this.colorDefFromMaterialJson(materialJson.diffuseColor);
        if (materialJson.diffuse !== undefined)
          materialParams.diffuse = JsonUtils.asDouble(materialJson.diffuse);
        materialParams.specularColor = this.colorDefFromMaterialJson(materialJson.specularColor);
        if (materialJson.specular !== undefined)
          materialParams.specular = JsonUtils.asDouble(materialJson.specular);
        materialParams.reflectColor = this.colorDefFromMaterialJson(materialJson.reflectColor);
        if (materialJson.reflect !== undefined)
          materialParams.reflect = JsonUtils.asDouble(materialJson.reflect);

        if (materialJson.specularExponent !== undefined)
          materialParams.specularExponent = materialJson.specularExponent;
        if (materialJson.transparency !== undefined)
          materialParams.transparency = materialJson.transparency;
        materialParams.refract = JsonUtils.asDouble(materialJson.refract);
        materialParams.shadows = JsonUtils.asBool(materialJson.shadows);
        materialParams.ambient = JsonUtils.asDouble(materialJson.ambient);

        if (undefined !== materialJson.textureMapping)
          materialParams.textureMapping = this.textureMappingFromJson(materialJson.textureMapping.texture);

        material = this._system.createMaterial(materialParams, this._iModel);
      }

      return material;
    }