Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _colorTexture?: Texture;
private _featureTexture?: Texture;
private _hiliteTexture?: Texture;
private _combinedTexture?: Texture;
private _fbo?: FrameBuffer;
private _featureFbo?: FrameBuffer; // For multi-pass case only.
private _hiliteFbo?: FrameBuffer;
private _combinedFbo?: FrameBuffer;
private _projectionMatrix = new Matrix4();
private _graphics: RenderGraphic[] = [];
private _frustum?: Frustum;
private _width = 0;
private _height = 0;
private _baseBatchId = 0;
private _anyHilited = false;
private _plane = Plane3dByOriginAndUnitNormal.create(new Point3d(0, 0, 0), new Vector3d(0, 0, 1))!; // TBD -- Support other planes - default to X-Y for now.
private _postProjectionMatrix = Matrix4d.createRowValues(/* Row 1 */ 0, 1, 0, 0, /* Row 1 */ 0, 0, -1, 0, /* Row 3 */ 1, 0, 0, 0, /* Row 4 */ 0, 0, 0, 1);
private constructor(private _classifier: SpatialClassificationProps.Classifier) { super(); }
public get hiliteTexture(): Texture | undefined { return this._hiliteTexture; }
public get combinedTexture(): Texture | undefined { return this._combinedTexture; }
public get projectionMatrix(): Matrix4 { return this._projectionMatrix; }
public get properties(): SpatialClassificationProps.Classifier { return this._classifier; }
public get baseBatchId(): number { return this._baseBatchId; }
public get anyHilited(): boolean { return this._anyHilited; }
public get insideDisplay(): SpatialClassificationProps.Display { return this._classifier.flags.inside; }
public get outsideDisplay(): SpatialClassificationProps.Display { return this._classifier.flags.outside; }
public addGraphic(graphic: RenderGraphic) { this._graphics.push(graphic); }
public static create(properties: SpatialClassificationProps.Classifier, tileTree: TileTree, classifiedTree: TileTree, sceneContext: SceneContext): PlanarClassifier {
const classifier = new PlanarClassifier(properties);
classifier.collectGraphics(sceneContext, classifiedTree, tileTree);
private constructionPlane(outPtP: Point3d, inPtP: Point3d, pointOnPlaneP: Point3d, normalVectorP: Vector3d, vp: Viewport, perpendicular: boolean): BentleyStatus {
let fromPtP: Point3d;
let dotProduct: number;
let distance: number;
let projectionVector = new Vector3d();
if (perpendicular) {
if (AccuDraw.useACSContextRotation(vp, true)) { // Project along ACS axis to AccuDraw plane...
const rMatrix = vp.getAuxCoordRotation(AccuDraw._tempRot);
const axes = ThreeAxes.createFromMatrix3d(rMatrix);
this.accountForAuxRotationPlane(axes, this.flags.auxRotationPlane);
linePlaneIntersect(outPtP, inPtP, axes.z, pointOnPlaneP, normalVectorP, false);
} else {
projectionVector = inPtP.vectorTo(pointOnPlaneP);
distance = projectionVector.dotProduct(normalVectorP);
inPtP.plusScaled(normalVectorP, distance, outPtP);
}
} else {
const isCamera = vp.isCameraOn;
if (vp.view.is3d() && isCamera) {
const cameraPos = vp.view.getEyePoint();
litColor.rgb += (ambientIntensity * ambientWeight) * baseColor.rgb;
// Clamp while preserving hue.
float maxIntensity = max(litColor.r, max(litColor.g, litColor.b));
baseColor.rgb = litColor / max(1.0, maxIntensity);
}
return baseColor;
`;
/** NB: addMaterial() sets up the mat_* variables used by applyLighting.
* @internal
*/
const scratch3Floats = new Float32Array(3);
const scratchDirection = new Vector3d();
const scratchTransform = Transform.createIdentity();
export function addLighting(builder: ProgramBuilder) {
addFrustum(builder);
const frag = builder.frag;
frag.addFunction(computeSimpleLighting);
frag.set(FragmentShaderComponent.ApplyLighting, applyLighting);
frag.addUniform("u_sunDir", VariableType.Vec3, (prog) => {
prog.addProgramUniform("u_sunDir", (uniform, params) => {
const shadowMap = params.target.compositor.solarShadowMap;
if (shadowMap && shadowMap.isEnabled && undefined !== shadowMap.direction) {
// replace first light dir with solar direction (relative to model instead of view)
let mvt = params.target.viewMatrix.clone(scratchTransform);
mvt = mvt.multiplyTransformTransform(params.target.currentTransform, mvt);
public fixPointPolar(vp: Viewport): void {
let angleChanged = false;
let distChanged = false;
const zLocked = this.isZLocked(vp);
const xyCorrection = new Point3d();
this.planePt.setFrom(this.origin);
if (zLocked && !(this.delta.z < Constants.SMALL_ANGLE && this.delta.z > -Constants.SMALL_ANGLE))
this.planePt.addScaledInPlace(this.axes.z, this.delta.z);
if (this.locked & LockedStates.VEC_BM) {
if (!TentativeOrAccuSnap.isHot) {
const normVec = new Vector3d();
this.planeByVectorAndView(normVec, this.vector, vp);
this.softConstructionPlane(this._rawPointOnPlane, this._rawPoint, this.planePt, normVec, vp, false);
} else {
this._rawPointOnPlane.setFrom(this._rawPoint);
this.flags.pointIsOnPlane = false;
}
} else {
if (zLocked) {
this.hardConstructionPlane(this._rawPointOnPlane, this._rawPoint, this.planePt, this.axes.z, vp, TentativeOrAccuSnap.isHot);
this.flags.pointIsOnPlane = true;
} else {
this.flags.pointIsOnPlane = (this.softConstructionPlane(this._rawPointOnPlane, this._rawPoint, this.planePt, this.axes.z, vp, TentativeOrAccuSnap.isHot) || !!(this.locked & LockedStates.XY_BM));
}
}
let delta: Vector3d;
public appendGeometryPart3d(partId: Id64String, instanceOrigin?: Point3d, instanceRotation?: YawPitchRollAngles, instanceScale?: number): boolean {
if (undefined === this._worldToLocal) {
this.geometryStream.push({ geomPart: { part: partId, origin: instanceOrigin, rotation: instanceRotation, scale: instanceScale } });
return true;
}
const partTrans = Transform.createOriginAndMatrix(instanceOrigin, instanceRotation ? instanceRotation.toMatrix3d() : Matrix3d.createIdentity());
if (undefined !== instanceScale)
partTrans.matrix.scaleColumnsInPlace(instanceScale, instanceScale, instanceScale);
const resultTrans = partTrans.multiplyTransformTransform(this._worldToLocal);
const scales = new Vector3d();
if (!resultTrans.matrix.normalizeColumnsInPlace(scales))
return false;
const newRotation = YawPitchRollAngles.createFromMatrix3d(resultTrans.matrix);
if (undefined === newRotation)
return false;
this.geometryStream.push({ geomPart: { part: partId, origin: resultTrans.getOrigin(), rotation: newRotation, scale: scales.x } });
return true;
}
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);
const range = Tile.DebugBoundingBoxes.Content === type ? this.contentRange : this.range;
addRangeGraphic(builder, range, this.root.is2d);
}
this._rangeGraphic = builder.finish();
}
return this._rangeGraphic;
}
protected displayDelta(context: DecorateContext, seg: any): void {
const xVec = new Vector3d(seg.delta.x, 0.0, 0.0);
const yVec = new Vector3d(0.0, seg.delta.y, 0.0);
const zVec = new Vector3d(0.0, 0.0, seg.delta.z);
seg.refAxes.multiplyVectorInPlace(xVec);
seg.refAxes.multiplyVectorInPlace(yVec);
seg.refAxes.multiplyVectorInPlace(zVec);
const builderAxes = context.createGraphicBuilder(GraphicType.WorldOverlay);
let basePt = seg.start.clone();
if (xVec.magnitude() > 1.0e-5) {
const segPoints: Point3d[] = [];
segPoints.push(basePt); basePt = basePt.plus(xVec);
segPoints.push(basePt);
const colorX = ColorDef.red.adjustForContrast(context.viewport.view.backgroundColor);
builderAxes.setSymbology(colorX, ColorDef.black, 5);
builderAxes.addLineString(segPoints);
protected displayDelta(context: DecorateContext, seg: any): void {
const xVec = new Vector3d(seg.delta.x, 0.0, 0.0);
const yVec = new Vector3d(0.0, seg.delta.y, 0.0);
const zVec = new Vector3d(0.0, 0.0, seg.delta.z);
seg.refAxes.multiplyVectorInPlace(xVec);
seg.refAxes.multiplyVectorInPlace(yVec);
seg.refAxes.multiplyVectorInPlace(zVec);
const builderAxes = context.createGraphicBuilder(GraphicType.WorldOverlay);
let basePt = seg.start.clone();
if (xVec.magnitude() > 1.0e-5) {
const segPoints: Point3d[] = [];
segPoints.push(basePt); basePt = basePt.plus(xVec);
segPoints.push(basePt);
const colorX = ColorDef.red.adjustForContrast(context.viewport.view.backgroundColor);
builderAxes.setSymbology(colorX, ColorDef.black, 5);
builderAxes.addLineString(segPoints);
}