Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
startRotMatrix: Matrix3d;
endRotMatrix: Matrix3d;
animation: number;
hoverMap: { [key: string]: CubeHover };
face: Face;
}
/** Cube Navigation Aid Component
* @alpha
*/
export class CubeNavigationAid extends React.Component {
private _start: Vector2d = Vector2d.createZero();
public readonly state: Readonly = {
dragging: false,
startRotMatrix: Matrix3d.createIdentity(),
endRotMatrix: Matrix3d.createIdentity(),
animation: 1,
hoverMap: {},
face: Face.Top,
};
private _lastTime: number | undefined;
private _animationFrame: any;
private _mounted: boolean = false;
/** @internal */
public componentDidMount() {
this._mounted = true;
ViewportComponentEvents.onViewRotationChangeEvent.addListener(this._handleViewRotationChangeEvent);
// set initial rotation
const activeContentControl = this.props.contentControlOverride !== undefined ? this.props.contentControlOverride : /* istanbul ignore next */ ContentViewManager.getActiveContentControl();
}
/** Get the NavigationAidControl associated with this ContentControl */
public get navigationAidControl(): string {
return "CubeNavigationAid";
}
}
interface CubeContentState {
rotMatrix: Matrix3d;
}
class CubeContent extends React.Component<{}, CubeContentState> {
public readonly state: CubeContentState = {
rotMatrix: Matrix3d.createIdentity(),
};
public render(): React.ReactNode {
return (
<div>
</div>
);
}
public componentDidMount() {
ViewportComponentEvents.onCubeRotationChangeEvent.addListener(this._handleCubeRotationChangeEvent);
}
this._removeListener = IModelApp.viewManager.onSelectedViewportChanged.addListener(ViewportComponentEvents.handleSelectedViewportChanged);
}
/** @internal - for unit testing */
public static terminate() {
if (this._removeListener) {
this._removeListener();
this._removeListener = undefined;
}
}
public static face = Face.None;
public static readonly origin = Point3d.createZero();
public static readonly extents = Vector3d.createZero();
public static readonly rotationMatrix = Matrix3d.createIdentity();
public static readonly onDrawingViewportChangeEvent = new DrawingViewportChangeEvent();
public static readonly onCubeRotationChangeEvent = new CubeRotationChangeEvent();
public static readonly onStandardRotationChangeEvent = new StandardRotationChangeEvent();
public static readonly onViewRotationChangeEvent = new ViewRotationChangeEvent();
public static readonly onViewClassFullNameChangedEvent = new ViewClassFullNameChangedEvent();
public static readonly onViewIdChangedEvent = new ViewIdChangedEvent();
private static handleSelectedViewportChanged(args: SelectedViewportChangedArgs): void {
if (args.current)
ViewportComponentEvents.setViewMatrix(args.current);
}
public static setCubeMatrix(rotMatrix: Matrix3d, face = Face.None, complete: boolean = false): void {
this.rotationMatrix.setFrom(rotMatrix);
this.face = face;
this.onCubeRotationChangeEvent.emit({ rotMatrix, complete, face });
case RotationMode.View: {
baseRMatrix = vp ? vp.rotation : Matrix3d.createIdentity();
break;
}
case RotationMode.Context: {
const axes = new ThreeAxes();
axes.setFrom(this.baseAxes);
this.accountForAuxRotationPlane(axes, this.flags.auxRotationPlane);
baseRMatrix = axes.toMatrix3d();
break;
}
default: {
baseRMatrix = Matrix3d.createIdentity();
break;
}
}
return baseRMatrix;
}
case 2: vecP.y = -1.0; break;
}
this.accountForACSContextLock(vecP);
break;
case RotationMode.Side:
switch (whichVec) {
case 0: vecP.y = 1.0; break;
case 1: vecP.z = 1.0; break;
case 2: vecP.x = 1.0; break;
}
this.accountForACSContextLock(vecP);
break;
case RotationMode.ACS:
rMatrix = vp ? vp.getAuxCoordRotation() : Matrix3d.createIdentity();
myAxes = ThreeAxes.createFromMatrix3d(rMatrix);
this.accountForAuxRotationPlane(myAxes, this.flags.auxRotationPlane);
switch (whichVec) {
case 0: vecP.setFrom(myAxes.x); break;
case 1: vecP.setFrom(myAxes.y); break;
case 2: vecP.setFrom(myAxes.z); break;
}
break;
case RotationMode.View:
rMatrix = vp ? vp.rotation : Matrix3d.createIdentity();
rMatrix.getRow(whichVec, vecP);
break;
case RotationMode.Context:
myAxes = this.baseAxes.clone();
constructor(props: DrawingNavigationAidProps) {
super(props);
const mode = props.initialMapMode || MapMode.Closed;
const mapExtents = mode === MapMode.Closed ? this._getClosedMapSize() : this._getOpenedMapSize();
const startMapExtents = mapExtents;
this.state = {
startOrigin: Point3d.createZero(),
origin: Point3d.createZero(),
extents: Vector3d.create(1, 1, 1),
startRotation: Matrix3d.createIdentity(),
rotation: Matrix3d.createIdentity(),
startMapOrigin: Point3d.createZero(),
mapOrigin: Point3d.createZero(),
startMapExtents,
mapExtents,
mouseStart: Point2d.createZero(),
panningDirection: Vector3d.createZero(),
startDrawingZoom: 1.0,
drawingZoom: 1.0,
mode,
animation: 1.0,
viewId: props.initialView !== undefined ? props.initialView.id : "",
view: props.initialView,
this.accountForACSContextLock(vecP);
break;
case RotationMode.ACS:
rMatrix = vp ? vp.getAuxCoordRotation() : Matrix3d.createIdentity();
myAxes = ThreeAxes.createFromMatrix3d(rMatrix);
this.accountForAuxRotationPlane(myAxes, this.flags.auxRotationPlane);
switch (whichVec) {
case 0: vecP.setFrom(myAxes.x); break;
case 1: vecP.setFrom(myAxes.y); break;
case 2: vecP.setFrom(myAxes.z); break;
}
break;
case RotationMode.View:
rMatrix = vp ? vp.rotation : Matrix3d.createIdentity();
rMatrix.getRow(whichVec, vecP);
break;
case RotationMode.Context:
myAxes = this.baseAxes.clone();
this.accountForAuxRotationPlane(myAxes, this.flags.auxRotationPlane);
switch (whichVec) {
case 0: vecP.setFrom(myAxes.x); break;
case 1: vecP.setFrom(myAxes.y); break;
case 2: vecP.setFrom(myAxes.z); break;
}
break;
}
return vecP;
}
protected getReferenceAxes(vp?: Viewport): Matrix3d {
const refAxes = Matrix3d.createIdentity();
if (undefined !== vp && vp.isContextRotationRequired)
vp.getAuxCoordRotation(refAxes);
return refAxes;
}
case RotationMode.Side: {
baseRMatrix = AccuDraw.getStandardRotation(StandardViewId.Right, vp, useAcs)!;
break;
}
case RotationMode.ACS: {
baseRMatrix = vp ? vp.getAuxCoordRotation() : Matrix3d.createIdentity();
const axes = ThreeAxes.createFromMatrix3d(baseRMatrix);
this.accountForAuxRotationPlane(axes, this.flags.auxRotationPlane);
axes.toMatrix3d(baseRMatrix);
break;
}
case RotationMode.View: {
baseRMatrix = vp ? vp.rotation : Matrix3d.createIdentity();
break;
}
case RotationMode.Context: {
const axes = new ThreeAxes();
axes.setFrom(this.baseAxes);
this.accountForAuxRotationPlane(axes, this.flags.auxRotationPlane);
baseRMatrix = axes.toMatrix3d();
break;
}
default: {
baseRMatrix = Matrix3d.createIdentity();
break;
}
}
private readInstances(): InstancedGraphicParams | undefined {
const count = JsonUtils.asInt(this._featureJson.INSTANCES_LENGTH, 0);
if (count <= 0)
return undefined;
const json = this._featureJson;
const binary = this._featureBinary;
const batchIds = json.BATCH_ID ? new Int32Array(binary.buffer, binary.byteOffset + json.BATCH_ID.byteOffset, count) : undefined;
const positions = json.POSITION ? new Float32Array(binary.buffer, binary.byteOffset + json.POSITION.byteOffset, count * 3) : undefined;
const upNormals = json.NORMAL_UP ? new Float32Array(binary.buffer, binary.byteOffset + json.NORMAL_UP.byteOffset, count * 3) : undefined;
const rightNormals = json.NORMAL_RIGHT ? new Float32Array(binary.buffer, binary.byteOffset + json.NORMAL_RIGHT.byteOffset, count * 3) : undefined;
const scales = json.SCALE ? new Float32Array(binary.buffer, binary.byteOffset + json.SCALE.byteOffset, count) : undefined;
const nonUniformScales = json.SCALE_NON_UNIFORM ? new Float32Array(binary.buffer, binary.byteOffset + json.SCALE_NON_UNIFORM.byteOffset, count * 3) : undefined;
const matrix = Matrix3d.createIdentity();
const position = Point3d.createZero();
const upNormal = Vector3d.create(0, 0, 1);
const rightNormal = Vector3d.create(1, 0, 0);
const scale = Vector3d.create(1, 1, 1);
const transformCenter = this._range.center;
const transforms = new Float32Array(12 * count);
for (let i = 0; i < count; i++) {
const index = i * 3;
if (positions)
position.set(positions[index] - transformCenter.x, positions[index + 1] - transformCenter.y, positions[index + 2] - transformCenter.z);
if (upNormals || rightNormals) {
if (upNormals)
upNormal.set(upNormals[index], upNormals[index + 1], upNormals[index + 2]);