Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
}
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;
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;
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);
const mesh = Mesh.create({ displayParams, type: Mesh.PrimitiveType.Mesh, range: BingElevationProvider._scratchRange, isPlanar: false, is2d: false });
const size = 16;
public clear(): void {
this.edges.clear();
this.silhouettes.clear();
this.polylines.clear();
this.width = 0;
this.linePixels = LinePixels.Solid;
}
public get isValid(): boolean { return this.edges.isValid || this.silhouettes.isValid || this.polylines.isValid; }
const refStepX = reverseY ? -refSpacing.x : refSpacing.x;
const refStepY = reverseX ? -refSpacing.y : refSpacing.y;
const fadeRefSteps = 8;
const fadeRefTransparencyStep = (255 - gridConstants.refTransparency) / (fadeRefSteps + 2);
let lastDist = 0.0;
const lastPt = Point3d.createZero();
const planeX = Plane3dByOriginAndUnitNormal.create(lastPt, Vector3d.unitX())!;
const planeY = Plane3dByOriginAndUnitNormal.create(lastPt, Vector3d.unitY())!;
const thisPt = Point3d.create();
const thisPt0 = Point3d.create();
const thisPt1 = Point3d.create();
const thisRay = Ray3d.createZero();
const refColor = color.clone(); refColor.setTransparency(gridConstants.refTransparency);
const linePat = eyeDot < 0.0 ? LinePixels.Code2 : LinePixels.Solid;
const drawRefX = (nRefRepetitionsX < gridConstants.maxRefLines || (vp.isCameraOn && unambiguousX));
const drawRefY = (nRefRepetitionsY < gridConstants.maxRefLines || (vp.isCameraOn && unambiguousY));
const drawGridLines = drawRefX && drawRefY && (gridsPerRef > 1 && !((spacing.x / meterPerPixel) < gridConstants.minSeparation || (spacing.y / meterPerPixel) < gridConstants.minSeparation));
if (drawRefX) {
builder.setSymbology(refColor, planeColor, 1, linePat);
for (let xRef = 0, refY = reverseX ? maxY : minY, doFadeX = false, xFade = 0; xRef <= nRefRepetitionsX && xFade < fadeRefSteps; ++xRef, refY += refStepY) {
const linePoints: Point3d[] = [Point3d.create(minX, refY), Point3d.create(maxX, refY)];
transform.multiplyPoint3dArrayInPlace(linePoints);
vp.worldToView(linePoints[0], thisPt0); thisPt0.z = 0.0;
vp.worldToView(linePoints[1], thisPt1); thisPt1.z = 0.0;
if (doFadeX) {
this.hasFeatures = FeatureIndexType.Empty !== params.vertices.featureIndexType;
if (FeatureIndexType.Uniform === params.vertices.featureIndexType)
this.uniformFeatureId = params.vertices.uniformFeatureID;
this.texture = params.surface.texture as Texture;
this.materialInfo = createMaterialInfo(params.surface.material);
this.type = params.surface.type;
this.fillFlags = params.surface.fillFlags;
this.isPlanar = params.isPlanar;
this.hasBakedLighting = params.surface.hasBakedLighting;
this.hasFixedNormals = params.surface.hasFixedNormals;
const edges = params.edges;
this.edgeWidth = undefined !== edges ? edges.weight : 1;
this.edgeLineCode = LineCode.valueFromLinePixels(undefined !== edges ? edges.linePixels : LinePixels.Solid);
}
if (undefined === tiles)
return;
const map = new Map();
for (const tile of tiles) {
let builder = map.get(tile.root);
if (undefined === builder) {
builder = context.createGraphicBuilder(GraphicType.WorldDecoration, tile.root.location);
map.set(tile.root, builder);
}
let color = ColorDef.white;
if (undefined !== tile.request)
color = tile.request.isQueued ? ColorDef.green : ColorDef.red;
builder.setSymbology(color, color, 1, LinePixels.Solid);
builder.addRangeBox(tile.range);
}
for (const builder of map.values())
context.addDecorationFromBuilder(builder);
}
this._rangeGraphicType = type;
this._rangeGraphic = dispose(this._rangeGraphic);
if (Tile.DebugBoundingBoxes.None !== type) {
const builder = context.createSceneGraphicBuilder();
if (Tile.DebugBoundingBoxes.Both === type) {
builder.setSymbology(ColorDef.blue, ColorDef.blue, 1);
addRangeGraphic(builder, this.range, this.root.is2d);
if (this.hasContentRange) {
builder.setSymbology(ColorDef.red, ColorDef.red, 1);
addRangeGraphic(builder, this.contentRange, this.root.is2d);
}
} else if (Tile.DebugBoundingBoxes.ChildVolumes === type) {
const ranges = computeChildRanges(this);
for (const range of ranges) {
const color = range.isEmpty ? ColorDef.blue : ColorDef.green;
const pixels = !range.isEmpty ? LinePixels.HiddenLine : LinePixels.Solid;
const width = !range.isEmpty ? 2 : 1;
builder.setSymbology(color, color, width, pixels);
addRangeGraphic(builder, range.range, this.root.is2d);
}
} else if (Tile.DebugBoundingBoxes.Sphere === type) {
builder.setSymbology(ColorDef.green, ColorDef.green, 1);
const x = new Vector3d(this.radius, 0, 0);
const y = new Vector3d(0, this.radius, 0);
const z = new Vector3d(0, 0, this.radius);
builder.addArc(Arc3d.create(this.center, x, y), false, false);
builder.addArc(Arc3d.create(this.center, x, z), false, false);
builder.addArc(Arc3d.create(this.center, y, z), false, false);
} else {
const color = this.hasSizeMultiplier ? ColorDef.red : (this.isLeaf ? ColorDef.blue : ColorDef.green);
builder.setSymbology(color, color, 1);
public constructor(type: DisplayParams.Type, lineColor: ColorDef, fillColor: ColorDef, width: number = 0, linePixels: LinePixels = LinePixels.Solid,
fillFlags: FillFlags = FillFlags.None, material?: RenderMaterial, gradient?: Gradient.Symb, ignoreLighting: boolean = false, textureMapping?: TextureMapping) {
this.type = type;
this.material = material;
this.gradient = gradient;
this.lineColor = DisplayParams.adjustTransparencyInPlace(lineColor);
this.fillColor = DisplayParams.adjustTransparencyInPlace(fillColor);
this.width = width;
this.linePixels = linePixels;
this.fillFlags = fillFlags;
this.ignoreLighting = ignoreLighting;
this._textureMapping = textureMapping;
assert(undefined === material || undefined === textureMapping);
}