Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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) {
const texture = this._system.getGradientTexture(gradient, this._iModel);
if (undefined !== texture) {
// ###TODO: would be better if DisplayParams created the TextureMapping - but that requires an IModelConnection and a RenderSystem...
textureMapping = new TextureMapping(texture, new TextureMapping.Params({ textureMat2x3: new TextureMapping.Trans2x3(0, 1, 0, 1, 0, 0) }));
}
}
}
}
return new DisplayParams(type, lineColor, fillColor, width, linePixels, fillFlags, material, undefined, ignoreLighting, textureMapping);
}
// 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) {
const texture = this._system.getGradientTexture(gradient, this._iModel);
if (undefined !== texture) {
// ###TODO: would be better if DisplayParams created the TextureMapping - but that requires an IModelConnection and a RenderSystem...
textureMapping = new TextureMapping(texture, new TextureMapping.Params({ textureMat2x3: new TextureMapping.Trans2x3(0, 1, 0, 1, 0, 0) }));
}
}
}
}
return new DisplayParams(type, lineColor, fillColor, width, linePixels, fillFlags, material, undefined, ignoreLighting, textureMapping);
}
public static createForType(type: DisplayParams.Type, gf: GraphicParams, resolveGradient?: (grad: Gradient.Symb) => RenderTexture | undefined): DisplayParams {
const lineColor = DisplayParams.adjustTransparencyInPlace(gf.lineColor.clone());
switch (type) {
case DisplayParams.Type.Mesh: {
let gradientMapping: TextureMapping | undefined;
if (undefined !== gf.gradient && undefined !== resolveGradient) {
const gradientTexture = resolveGradient(gf.gradient);
if (undefined !== gradientTexture)
gradientMapping = new TextureMapping(gradientTexture, new TextureMapping.Params());
}
return new DisplayParams(type, lineColor, DisplayParams.adjustTransparencyInPlace(gf.fillColor.clone()), gf.rasterWidth, gf.linePixels, gf.fillFlags, gf.material, gf.gradient, false, gradientMapping);
}
case DisplayParams.Type.Linear:
return new DisplayParams(type, lineColor, lineColor, gf.rasterWidth, gf.linePixels);
default: // DisplayParams.Type.Text
return new DisplayParams(type, lineColor, lineColor, 0, LinePixels.Solid, FillFlags.Always, undefined, undefined, true);
}
}
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));
}
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)
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));
}
public async getGraphic(latLongRange: Range2d, corners: Point3d[], groundBias: number, texture: RenderTexture, system: RenderSystem): Promise {
const heights = await this.getHeights(latLongRange);
if (undefined === heights)
return undefined;
const patch = new BilinearPatch(corners[0], corners[1], corners[2], corners[3]);
const textureParams = new TextureMapping.Params({ mapMode: TextureMapping.Mode.Parametric });
const textureMapping = new TextureMapping(texture!, textureParams);
const displayParams = new DisplayParams(DisplayParams.Type.Mesh, ColorDef.white.clone(), ColorDef.white.clone(), 0.0, LinePixels.Solid, FillFlags.None, undefined, undefined, false, textureMapping);
BingElevationProvider._scratchRange.setNull();
BingElevationProvider._scratchRange.extendArray(corners);
BingElevationProvider._scratchRange.low.z = 10E8;
BingElevationProvider._scratchRange.high.z = -1.0E8;
for (const height of heights) {
BingElevationProvider._scratchRange.low.z = Math.min(BingElevationProvider._scratchRange.low.z, height);
BingElevationProvider._scratchRange.high.z = Math.max(BingElevationProvider._scratchRange.high.z, height);
}
BingElevationProvider._scratchRange.low.z += groundBias;
BingElevationProvider._scratchRange.high.z += groundBias;
BingElevationProvider._scratchQParams.setFromRange(BingElevationProvider._scratchRange);