|
@@ -4,27 +4,29 @@
|
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
|
*/
|
|
|
|
|
|
-import { WebGLContext } from '../../mol-gl/webgl/context';
|
|
|
-import { Scene } from '../../mol-gl/scene';
|
|
|
-import { Camera, ICamera } from '../camera';
|
|
|
-import { MeshBuilder } from '../../mol-geo/geometry/mesh/mesh-builder';
|
|
|
-import { Vec3, Mat4 } from '../../mol-math/linear-algebra';
|
|
|
+import produce from 'immer';
|
|
|
+import { addCylinder } from '../../mol-geo/geometry/mesh/builder/cylinder';
|
|
|
import { addSphere } from '../../mol-geo/geometry/mesh/builder/sphere';
|
|
|
-import { GraphicsRenderObject } from '../../mol-gl/render-object';
|
|
|
import { Mesh } from '../../mol-geo/geometry/mesh/mesh';
|
|
|
-import { ColorNames } from '../../mol-util/color/names';
|
|
|
-import { addCylinder } from '../../mol-geo/geometry/mesh/builder/cylinder';
|
|
|
-import { Viewport } from '../camera/util';
|
|
|
+import { MeshBuilder } from '../../mol-geo/geometry/mesh/mesh-builder';
|
|
|
+import { PickingId } from '../../mol-geo/geometry/picking';
|
|
|
+import { GraphicsRenderObject } from '../../mol-gl/render-object';
|
|
|
+import { Scene } from '../../mol-gl/scene';
|
|
|
+import { WebGLContext } from '../../mol-gl/webgl/context';
|
|
|
import { Sphere3D } from '../../mol-math/geometry';
|
|
|
-import { ParamDefinition as PD } from '../../mol-util/param-definition';
|
|
|
-import produce from 'immer';
|
|
|
+import { Mat4, Vec3 } from '../../mol-math/linear-algebra';
|
|
|
+import { DataLoci, EmptyLoci, Loci } from '../../mol-model/loci';
|
|
|
import { Shape } from '../../mol-model/shape';
|
|
|
+import { ColorNames } from '../../mol-util/color/names';
|
|
|
+import { ParamDefinition as PD } from '../../mol-util/param-definition';
|
|
|
+import { Camera, ICamera } from '../camera';
|
|
|
+import { Viewport } from '../camera/util';
|
|
|
|
|
|
// TODO add scale line/grid
|
|
|
|
|
|
const AxesParams = {
|
|
|
...Mesh.Params,
|
|
|
- alpha: { ...Mesh.Params.alpha, defaultValue: 0.33 },
|
|
|
+ alpha: { ...Mesh.Params.alpha, defaultValue: 0.51 },
|
|
|
ignoreLight: { ...Mesh.Params.ignoreLight, defaultValue: true },
|
|
|
colorX: PD.Color(ColorNames.red, { isEssential: true }),
|
|
|
colorY: PD.Color(ColorNames.green, { isEssential: true }),
|
|
@@ -87,6 +89,12 @@ export class CameraHelper {
|
|
|
return this.props.axes.name === 'on';
|
|
|
}
|
|
|
|
|
|
+ getLoci(pickingId: PickingId) {
|
|
|
+ const { objectId, groupId, instanceId } = pickingId;
|
|
|
+ if (!this.renderObject || objectId !== this.renderObject.id || groupId === CameraHelperAxis.None) return EmptyLoci;
|
|
|
+ return CameraAxesLoci(this, groupId, instanceId);
|
|
|
+ }
|
|
|
+
|
|
|
update(camera: ICamera) {
|
|
|
if (!this.renderObject) return;
|
|
|
|
|
@@ -102,6 +110,38 @@ export class CameraHelper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+export const enum CameraHelperAxis {
|
|
|
+ None = 0,
|
|
|
+ X,
|
|
|
+ Y,
|
|
|
+ Z,
|
|
|
+ XY,
|
|
|
+ XZ,
|
|
|
+ YZ
|
|
|
+}
|
|
|
+
|
|
|
+function getAxisLabel(axis: number) {
|
|
|
+ switch (axis) {
|
|
|
+ case CameraHelperAxis.X: return 'X Axis';
|
|
|
+ case CameraHelperAxis.Y: return 'Y Axis';
|
|
|
+ case CameraHelperAxis.Z: return 'Z Axis';
|
|
|
+ case CameraHelperAxis.XY: return 'XY Plane';
|
|
|
+ case CameraHelperAxis.XZ: return 'XZ Plane';
|
|
|
+ case CameraHelperAxis.YZ: return 'YZ Plane';
|
|
|
+ default: return 'Axes';
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function CameraAxesLoci(cameraHelper: CameraHelper, groupId: number, instanceId: number) {
|
|
|
+ return DataLoci('camera-axes', cameraHelper, [{ groupId, instanceId }],
|
|
|
+ void 0 /** bounding sphere */,
|
|
|
+ () => getAxisLabel(groupId));
|
|
|
+}
|
|
|
+export type CameraAxesLoci = ReturnType<typeof CameraAxesLoci>
|
|
|
+export function isCameraAxesLoci(x: Loci): x is CameraAxesLoci {
|
|
|
+ return x.kind === 'data-loci' && x.tag === 'camera-axes';
|
|
|
+}
|
|
|
+
|
|
|
function updateCamera(camera: Camera, viewport: Viewport, viewOffset: Camera.ViewOffset) {
|
|
|
const { near, far } = camera;
|
|
|
|
|
@@ -134,27 +174,52 @@ function updateCamera(camera: Camera, viewport: Viewport, viewOffset: Camera.Vie
|
|
|
|
|
|
function createAxesMesh(scale: number, mesh?: Mesh) {
|
|
|
const state = MeshBuilder.createState(512, 256, mesh);
|
|
|
- const radius = 0.05 * scale;
|
|
|
+ const radius = 0.075 * scale;
|
|
|
const x = Vec3.scale(Vec3(), Vec3.unitX, scale);
|
|
|
const y = Vec3.scale(Vec3(), Vec3.unitY, scale);
|
|
|
const z = Vec3.scale(Vec3(), Vec3.unitZ, scale);
|
|
|
const cylinderProps = { radiusTop: radius, radiusBottom: radius, radialSegments: 32 };
|
|
|
|
|
|
- state.currentGroup = 0;
|
|
|
+ state.currentGroup = CameraHelperAxis.None;
|
|
|
addSphere(state, Vec3.origin, radius, 2);
|
|
|
|
|
|
- state.currentGroup = 1;
|
|
|
+ state.currentGroup = CameraHelperAxis.X;
|
|
|
addSphere(state, x, radius, 2);
|
|
|
addCylinder(state, Vec3.origin, x, 1, cylinderProps);
|
|
|
|
|
|
- state.currentGroup = 2;
|
|
|
+ state.currentGroup = CameraHelperAxis.Y;
|
|
|
addSphere(state, y, radius, 2);
|
|
|
addCylinder(state, Vec3.origin, y, 1, cylinderProps);
|
|
|
|
|
|
- state.currentGroup = 3;
|
|
|
+ state.currentGroup = CameraHelperAxis.Z;
|
|
|
addSphere(state, z, radius, 2);
|
|
|
addCylinder(state, Vec3.origin, z, 1, cylinderProps);
|
|
|
|
|
|
+ Vec3.scale(x, x, 0.5);
|
|
|
+ Vec3.scale(y, y, 0.5);
|
|
|
+ Vec3.scale(z, z, 0.5);
|
|
|
+
|
|
|
+ state.currentGroup = CameraHelperAxis.XY;
|
|
|
+ MeshBuilder.addTriangle(state, Vec3.origin, x, y);
|
|
|
+ MeshBuilder.addTriangle(state, Vec3.origin, y, x);
|
|
|
+ const xy = Vec3.add(Vec3(), x, y);
|
|
|
+ MeshBuilder.addTriangle(state, xy, x, y);
|
|
|
+ MeshBuilder.addTriangle(state, xy, y, x);
|
|
|
+
|
|
|
+ state.currentGroup = CameraHelperAxis.XZ;
|
|
|
+ MeshBuilder.addTriangle(state, Vec3.origin, x, z);
|
|
|
+ MeshBuilder.addTriangle(state, Vec3.origin, z, x);
|
|
|
+ const xz = Vec3.add(Vec3(), x, z);
|
|
|
+ MeshBuilder.addTriangle(state, xz, x, z);
|
|
|
+ MeshBuilder.addTriangle(state, xz, z, x);
|
|
|
+
|
|
|
+ state.currentGroup = CameraHelperAxis.YZ;
|
|
|
+ MeshBuilder.addTriangle(state, Vec3.origin, y, z);
|
|
|
+ MeshBuilder.addTriangle(state, Vec3.origin, z, y);
|
|
|
+ const yz = Vec3.add(Vec3(), y, z);
|
|
|
+ MeshBuilder.addTriangle(state, yz, y, z);
|
|
|
+ MeshBuilder.addTriangle(state, yz, z, y);
|
|
|
+
|
|
|
return MeshBuilder.getMesh(state);
|
|
|
}
|
|
|
|