react-cheminfo 0.135.0 → 0.136.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/crystal/core/cellAtoms.d.ts +43 -0
- package/lib/crystal/core/cellAtoms.d.ts.map +1 -0
- package/lib/crystal/core/cellAtoms.js +70 -0
- package/lib/crystal/core/cellAtoms.js.map +1 -0
- package/lib/crystal/core/index.d.ts +2 -0
- package/lib/crystal/core/index.d.ts.map +1 -1
- package/lib/crystal/core/index.js +1 -0
- package/lib/crystal/core/index.js.map +1 -1
- package/lib/crystal/core/molecules.d.ts.map +1 -1
- package/lib/crystal/core/molecules.js +6 -40
- package/lib/crystal/core/molecules.js.map +1 -1
- package/lib/crystal3d/core/cellClip.d.ts +46 -0
- package/lib/crystal3d/core/cellClip.d.ts.map +1 -0
- package/lib/crystal3d/core/cellClip.js +198 -0
- package/lib/crystal3d/core/cellClip.js.map +1 -0
- package/lib/crystal3d/core/cellGeometry.d.ts +63 -0
- package/lib/crystal3d/core/cellGeometry.d.ts.map +1 -0
- package/lib/crystal3d/core/cellGeometry.js +153 -0
- package/lib/crystal3d/core/cellGeometry.js.map +1 -0
- package/lib/crystal3d/core/cellStack.d.ts +51 -0
- package/lib/crystal3d/core/cellStack.d.ts.map +1 -0
- package/lib/crystal3d/core/cellStack.js +79 -0
- package/lib/crystal3d/core/cellStack.js.map +1 -0
- package/lib/crystal3d/core/crystalView.d.ts +71 -0
- package/lib/crystal3d/core/crystalView.d.ts.map +1 -0
- package/lib/crystal3d/core/crystalView.js +48 -0
- package/lib/crystal3d/core/crystalView.js.map +1 -0
- package/lib/crystal3d/core/drawingSet.d.ts +31 -0
- package/lib/crystal3d/core/drawingSet.d.ts.map +1 -0
- package/lib/crystal3d/core/drawingSet.js +63 -0
- package/lib/crystal3d/core/drawingSet.js.map +1 -0
- package/lib/crystal3d/core/elementDrawing.d.ts +50 -0
- package/lib/crystal3d/core/elementDrawing.d.ts.map +1 -0
- package/lib/crystal3d/core/elementDrawing.js +100 -0
- package/lib/crystal3d/core/elementDrawing.js.map +1 -0
- package/lib/crystal3d/core/elementExtent.d.ts +42 -0
- package/lib/crystal3d/core/elementExtent.d.ts.map +1 -0
- package/lib/crystal3d/core/elementExtent.js +56 -0
- package/lib/crystal3d/core/elementExtent.js.map +1 -0
- package/lib/crystal3d/core/elementLabels.d.ts +31 -0
- package/lib/crystal3d/core/elementLabels.d.ts.map +1 -0
- package/lib/crystal3d/core/elementLabels.js +99 -0
- package/lib/crystal3d/core/elementLabels.js.map +1 -0
- package/lib/crystal3d/core/elementShapes.d.ts +43 -0
- package/lib/crystal3d/core/elementShapes.d.ts.map +1 -0
- package/lib/crystal3d/core/elementShapes.js +115 -0
- package/lib/crystal3d/core/elementShapes.js.map +1 -0
- package/lib/crystal3d/core/frame.d.ts +36 -0
- package/lib/crystal3d/core/frame.d.ts.map +1 -0
- package/lib/crystal3d/core/frame.js +35 -0
- package/lib/crystal3d/core/frame.js.map +1 -0
- package/lib/crystal3d/core/framing.d.ts +41 -0
- package/lib/crystal3d/core/framing.d.ts.map +1 -0
- package/lib/crystal3d/core/framing.js +79 -0
- package/lib/crystal3d/core/framing.js.map +1 -0
- package/lib/crystal3d/core/index.d.ts +42 -0
- package/lib/crystal3d/core/index.d.ts.map +1 -0
- package/lib/crystal3d/core/index.js +29 -0
- package/lib/crystal3d/core/index.js.map +1 -0
- package/lib/crystal3d/core/labelText.d.ts +19 -0
- package/lib/crystal3d/core/labelText.d.ts.map +1 -0
- package/lib/crystal3d/core/labelText.js +42 -0
- package/lib/crystal3d/core/labelText.js.map +1 -0
- package/lib/crystal3d/core/latticeBasis.d.ts +49 -0
- package/lib/crystal3d/core/latticeBasis.d.ts.map +1 -0
- package/lib/crystal3d/core/latticeBasis.js +89 -0
- package/lib/crystal3d/core/latticeBasis.js.map +1 -0
- package/lib/crystal3d/core/mat3.d.ts +68 -0
- package/lib/crystal3d/core/mat3.d.ts.map +1 -0
- package/lib/crystal3d/core/mat3.js +146 -0
- package/lib/crystal3d/core/mat3.js.map +1 -0
- package/lib/crystal3d/core/operationMatrix.d.ts +44 -0
- package/lib/crystal3d/core/operationMatrix.d.ts.map +1 -0
- package/lib/crystal3d/core/operationMatrix.js +172 -0
- package/lib/crystal3d/core/operationMatrix.js.map +1 -0
- package/lib/crystal3d/core/orientation.d.ts +62 -0
- package/lib/crystal3d/core/orientation.d.ts.map +1 -0
- package/lib/crystal3d/core/orientation.js +166 -0
- package/lib/crystal3d/core/orientation.js.map +1 -0
- package/lib/crystal3d/core/palette.d.ts +24 -0
- package/lib/crystal3d/core/palette.d.ts.map +1 -0
- package/lib/crystal3d/core/palette.js +34 -0
- package/lib/crystal3d/core/palette.js.map +1 -0
- package/lib/crystal3d/core/primitives.d.ts +133 -0
- package/lib/crystal3d/core/primitives.d.ts.map +1 -0
- package/lib/crystal3d/core/primitives.js +80 -0
- package/lib/crystal3d/core/primitives.js.map +1 -0
- package/lib/crystal3d/core/structureText.d.ts +20 -0
- package/lib/crystal3d/core/structureText.d.ts.map +1 -0
- package/lib/crystal3d/core/structureText.js +37 -0
- package/lib/crystal3d/core/structureText.js.map +1 -0
- package/lib/crystal3d/core/supercell.d.ts +20 -0
- package/lib/crystal3d/core/supercell.d.ts.map +1 -0
- package/lib/crystal3d/core/supercell.js +35 -0
- package/lib/crystal3d/core/supercell.js.map +1 -0
- package/lib/crystal3d/core/types.d.ts +166 -0
- package/lib/crystal3d/core/types.d.ts.map +1 -0
- package/lib/crystal3d/core/types.js +10 -0
- package/lib/crystal3d/core/types.js.map +1 -0
- package/lib/crystal3d/core/vec3.d.ts +75 -0
- package/lib/crystal3d/core/vec3.d.ts.map +1 -0
- package/lib/crystal3d/core/vec3.js +119 -0
- package/lib/crystal3d/core/vec3.js.map +1 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts +52 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.js +242 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.js.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureView.d.ts +17 -0
- package/lib/crystal3d/ui/CrystalStructureView.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureView.js +76 -0
- package/lib/crystal3d/ui/CrystalStructureView.js.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.d.ts +22 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.js +29 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.js.map +1 -0
- package/lib/crystal3d/ui/CrystalViewControls.d.ts +25 -0
- package/lib/crystal3d/ui/CrystalViewControls.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalViewControls.js +22 -0
- package/lib/crystal3d/ui/CrystalViewControls.js.map +1 -0
- package/lib/crystal3d/ui/CrystalViewer3D.d.ts +72 -0
- package/lib/crystal3d/ui/CrystalViewer3D.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalViewer3D.js +70 -0
- package/lib/crystal3d/ui/CrystalViewer3D.js.map +1 -0
- package/lib/crystal3d/ui/crystalScene.d.ts +91 -0
- package/lib/crystal3d/ui/crystalScene.d.ts.map +1 -0
- package/lib/crystal3d/ui/crystalScene.js +10 -0
- package/lib/crystal3d/ui/crystalScene.js.map +1 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts +52 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts.map +1 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.js +2 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.js.map +1 -0
- package/lib/crystal3d/ui/index.d.ts +16 -0
- package/lib/crystal3d/ui/index.d.ts.map +1 -0
- package/lib/crystal3d/ui/index.js +12 -0
- package/lib/crystal3d/ui/index.js.map +1 -0
- package/lib/crystal3d/ui/useCrystalCaption.d.ts +14 -0
- package/lib/crystal3d/ui/useCrystalCaption.d.ts.map +1 -0
- package/lib/crystal3d/ui/useCrystalCaption.js +32 -0
- package/lib/crystal3d/ui/useCrystalCaption.js.map +1 -0
- package/lib/crystal3d/viewer/animate.d.ts +49 -0
- package/lib/crystal3d/viewer/animate.d.ts.map +1 -0
- package/lib/crystal3d/viewer/animate.js +83 -0
- package/lib/crystal3d/viewer/animate.js.map +1 -0
- package/lib/crystal3d/viewer/camera.d.ts +44 -0
- package/lib/crystal3d/viewer/camera.d.ts.map +1 -0
- package/lib/crystal3d/viewer/camera.js +103 -0
- package/lib/crystal3d/viewer/camera.js.map +1 -0
- package/lib/crystal3d/viewer/index.d.ts +13 -0
- package/lib/crystal3d/viewer/index.d.ts.map +1 -0
- package/lib/crystal3d/viewer/index.js +8 -0
- package/lib/crystal3d/viewer/index.js.map +1 -0
- package/lib/crystal3d/viewer/layerRegistry.d.ts +24 -0
- package/lib/crystal3d/viewer/layerRegistry.d.ts.map +1 -0
- package/lib/crystal3d/viewer/layerRegistry.js +39 -0
- package/lib/crystal3d/viewer/layerRegistry.js.map +1 -0
- package/lib/crystal3d/viewer/meshPrimitives.d.ts +13 -0
- package/lib/crystal3d/viewer/meshPrimitives.d.ts.map +1 -0
- package/lib/crystal3d/viewer/meshPrimitives.js +76 -0
- package/lib/crystal3d/viewer/meshPrimitives.js.map +1 -0
- package/lib/crystal3d/viewer/plugin.d.ts +133 -0
- package/lib/crystal3d/viewer/plugin.d.ts.map +1 -0
- package/lib/crystal3d/viewer/plugin.js +181 -0
- package/lib/crystal3d/viewer/plugin.js.map +1 -0
- package/lib/crystal3d/viewer/renderCell.d.ts +43 -0
- package/lib/crystal3d/viewer/renderCell.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderCell.js +53 -0
- package/lib/crystal3d/viewer/renderCell.js.map +1 -0
- package/lib/crystal3d/viewer/renderElements.d.ts +54 -0
- package/lib/crystal3d/viewer/renderElements.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderElements.js +77 -0
- package/lib/crystal3d/viewer/renderElements.js.map +1 -0
- package/lib/crystal3d/viewer/renderStructure.d.ts +55 -0
- package/lib/crystal3d/viewer/renderStructure.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderStructure.js +103 -0
- package/lib/crystal3d/viewer/renderStructure.js.map +1 -0
- package/lib/crystal3d/viewer/sceneParts.d.ts +32 -0
- package/lib/crystal3d/viewer/sceneParts.d.ts.map +1 -0
- package/lib/crystal3d/viewer/sceneParts.js +77 -0
- package/lib/crystal3d/viewer/sceneParts.js.map +1 -0
- package/lib/crystal3d/viewer/shapeLayer.d.ts +41 -0
- package/lib/crystal3d/viewer/shapeLayer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/shapeLayer.js +57 -0
- package/lib/crystal3d/viewer/shapeLayer.js.map +1 -0
- package/lib/crystal3d/viewer/textLayer.d.ts +21 -0
- package/lib/crystal3d/viewer/textLayer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/textLayer.js +59 -0
- package/lib/crystal3d/viewer/textLayer.js.map +1 -0
- package/lib/crystal3d/viewer/viewer.d.ts +110 -0
- package/lib/crystal3d/viewer/viewer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/viewer.js +157 -0
- package/lib/crystal3d/viewer/viewer.js.map +1 -0
- package/lib/crystal3d.d.ts +12 -0
- package/lib/crystal3d.d.ts.map +1 -0
- package/lib/crystal3d.js +12 -0
- package/lib/crystal3d.js.map +1 -0
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +19 -1
- package/lib/locales/en.json +19 -1
- package/lib/locales/es.json +19 -1
- package/lib/locales/fr.json +19 -1
- package/lib/locales/it.json +19 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.js +16 -27
- package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
- package/lib/molstar/bonds/bondRule.d.ts +16 -0
- package/lib/molstar/bonds/bondRule.d.ts.map +1 -0
- package/lib/molstar/bonds/bondRule.js +23 -0
- package/lib/molstar/bonds/bondRule.js.map +1 -0
- package/lib/molstar/bonds/index.d.ts +9 -0
- package/lib/molstar/bonds/index.d.ts.map +1 -0
- package/lib/molstar/bonds/index.js +9 -0
- package/lib/molstar/bonds/index.js.map +1 -0
- package/lib/molstar/ui/MolstarToolbar.d.ts +47 -0
- package/lib/molstar/ui/MolstarToolbar.d.ts.map +1 -0
- package/lib/molstar/ui/MolstarToolbar.js +28 -0
- package/lib/molstar/ui/MolstarToolbar.js.map +1 -0
- package/lib/molstar/ui/index.d.ts +10 -0
- package/lib/molstar/ui/index.d.ts.map +1 -0
- package/lib/molstar/ui/index.js +8 -0
- package/lib/molstar/ui/index.js.map +1 -0
- package/lib/molstar/ui/useMolstarTools.d.ts +63 -0
- package/lib/molstar/ui/useMolstarTools.d.ts.map +1 -0
- package/lib/molstar/ui/useMolstarTools.js +36 -0
- package/lib/molstar/ui/useMolstarTools.js.map +1 -0
- package/package.json +2 -1
- package/src/crystal/core/cellAtoms.ts +106 -0
- package/src/crystal/core/index.ts +2 -0
- package/src/crystal/core/molecules.ts +7 -44
- package/src/crystal3d/core/cellClip.ts +229 -0
- package/src/crystal3d/core/cellGeometry.ts +193 -0
- package/src/crystal3d/core/cellStack.ts +87 -0
- package/src/crystal3d/core/crystalView.ts +114 -0
- package/src/crystal3d/core/drawingSet.ts +71 -0
- package/src/crystal3d/core/elementDrawing.ts +147 -0
- package/src/crystal3d/core/elementExtent.ts +81 -0
- package/src/crystal3d/core/elementLabels.ts +130 -0
- package/src/crystal3d/core/elementShapes.ts +141 -0
- package/src/crystal3d/core/frame.ts +56 -0
- package/src/crystal3d/core/framing.ts +101 -0
- package/src/crystal3d/core/index.ts +132 -0
- package/src/crystal3d/core/labelText.ts +44 -0
- package/src/crystal3d/core/latticeBasis.ts +110 -0
- package/src/crystal3d/core/mat3.ts +163 -0
- package/src/crystal3d/core/operationMatrix.ts +255 -0
- package/src/crystal3d/core/orientation.ts +229 -0
- package/src/crystal3d/core/palette.ts +43 -0
- package/src/crystal3d/core/primitives.ts +183 -0
- package/src/crystal3d/core/structureText.ts +43 -0
- package/src/crystal3d/core/supercell.ts +40 -0
- package/src/crystal3d/core/types.ts +186 -0
- package/src/crystal3d/core/vec3.ts +127 -0
- package/src/crystal3d/ui/CrystalCanvas3D.tsx +384 -0
- package/src/crystal3d/ui/CrystalStructureView.tsx +148 -0
- package/src/crystal3d/ui/CrystalStructureViewer.tsx +39 -0
- package/src/crystal3d/ui/CrystalViewControls.tsx +100 -0
- package/src/crystal3d/ui/CrystalViewer3D.tsx +183 -0
- package/src/crystal3d/ui/crystalScene.ts +100 -0
- package/src/crystal3d/ui/crystalStructureViewerProps.ts +54 -0
- package/src/crystal3d/ui/index.ts +20 -0
- package/src/crystal3d/ui/useCrystalCaption.ts +38 -0
- package/src/crystal3d/viewer/animate.ts +113 -0
- package/src/crystal3d/viewer/camera.ts +139 -0
- package/src/crystal3d/viewer/index.ts +13 -0
- package/src/crystal3d/viewer/layerRegistry.ts +47 -0
- package/src/crystal3d/viewer/meshPrimitives.ts +102 -0
- package/src/crystal3d/viewer/plugin.ts +258 -0
- package/src/crystal3d/viewer/renderCell.ts +98 -0
- package/src/crystal3d/viewer/renderElements.ts +121 -0
- package/src/crystal3d/viewer/renderStructure.ts +144 -0
- package/src/crystal3d/viewer/sceneParts.ts +119 -0
- package/src/crystal3d/viewer/shapeLayer.ts +108 -0
- package/src/crystal3d/viewer/textLayer.ts +85 -0
- package/src/crystal3d/viewer/viewer.ts +207 -0
- package/src/crystal3d.ts +12 -0
- package/src/locales/de.json +19 -1
- package/src/locales/en.json +19 -1
- package/src/locales/es.json +19 -1
- package/src/locales/fr.json +19 -1
- package/src/locales/it.json +19 -1
- package/src/molecule3d/ui/MoleculeCanvas3D.tsx +45 -71
- package/src/molstar/bonds/bondRule.ts +34 -0
- package/src/molstar/bonds/index.ts +9 -0
- package/src/molstar/ui/MolstarToolbar.tsx +103 -0
- package/src/molstar/ui/index.ts +14 -0
- package/src/molstar/ui/useMolstarTools.ts +98 -0
- package/styles/chrome.css +90 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The crystal in 3D: what surrounds the canvas, and what to say when there
|
|
3
|
+
* cannot be one.
|
|
4
|
+
*
|
|
5
|
+
* Two things are settled before molstar is touched. The WebGL probe runs first,
|
|
6
|
+
* because molstar ships no canvas or SVG fallback and a locked-down school
|
|
7
|
+
* machine would otherwise get a blank rectangle with no explanation. And the
|
|
8
|
+
* canvas is a `React.lazy` boundary, so a page that never shows a crystal
|
|
9
|
+
* never downloads it.
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { CrystalViewer3D } from 'react-cheminfo/crystal3d';
|
|
13
|
+
*
|
|
14
|
+
* <CrystalViewer3D scene={{ atoms, cell, repeat: [2, 2, 2] }} height={480} />;
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { Callout, Spinner, SpinnerSize } from '@blueprintjs/core';
|
|
19
|
+
import type { CSSProperties, ReactElement, ReactNode } from 'react';
|
|
20
|
+
import { Suspense, lazy, useState } from 'react';
|
|
21
|
+
|
|
22
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
23
|
+
import type { Molecule3DTools } from '../../molecule3d/core/settings.ts';
|
|
24
|
+
// Deep import on purpose: the probe imports nothing, while a barrel would pull
|
|
25
|
+
// molstar in — which is exactly what asking first exists to avoid.
|
|
26
|
+
import { probeViewerCapability } from '../../orbital/ui/capability.ts';
|
|
27
|
+
import { TOKEN } from '../../tokens/core/familyTokens.ts';
|
|
28
|
+
|
|
29
|
+
import type { CrystalScene, CrystalViewHandle } from './crystalScene.ts';
|
|
30
|
+
|
|
31
|
+
const CrystalCanvas3D = lazy(async () => {
|
|
32
|
+
const module = await import('./CrystalCanvas3D.tsx');
|
|
33
|
+
return { default: module.CrystalCanvas3D };
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** Props of {@link CrystalViewer3D}. */
|
|
37
|
+
export interface CrystalViewer3DProps {
|
|
38
|
+
/** What to show. */
|
|
39
|
+
scene: CrystalScene;
|
|
40
|
+
/**
|
|
41
|
+
* How tall the canvas is: pixels, or any CSS length.
|
|
42
|
+
* @default 420
|
|
43
|
+
*/
|
|
44
|
+
height?: number | string;
|
|
45
|
+
/**
|
|
46
|
+
* Scene background, `#rrggbb`.
|
|
47
|
+
* @default '#ffffff'
|
|
48
|
+
*/
|
|
49
|
+
background?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Which tools the toolbars offer; every one it does not name is on.
|
|
52
|
+
* @default every tool but the display options and the surface
|
|
53
|
+
*/
|
|
54
|
+
tools?: Partial<Molecule3DTools>;
|
|
55
|
+
/**
|
|
56
|
+
* Base name of a picture saved from the toolbar, extension excluded.
|
|
57
|
+
* @default 'crystal'
|
|
58
|
+
*/
|
|
59
|
+
fileName?: string;
|
|
60
|
+
/**
|
|
61
|
+
* One line under the canvas — what is on screen, or where it came from.
|
|
62
|
+
* @default undefined
|
|
63
|
+
*/
|
|
64
|
+
caption?: ReactNode;
|
|
65
|
+
/**
|
|
66
|
+
* What to say instead of a canvas when the scene holds no atoms.
|
|
67
|
+
* @default undefined — the frame stays empty
|
|
68
|
+
*/
|
|
69
|
+
emptyMessage?: ReactNode;
|
|
70
|
+
/**
|
|
71
|
+
* What to say on a machine that cannot draw in 3D, after the reason.
|
|
72
|
+
* @default undefined
|
|
73
|
+
*/
|
|
74
|
+
unsupportedNote?: ReactNode;
|
|
75
|
+
/**
|
|
76
|
+
* Called with the means to picture the scene once the canvas exists, and with
|
|
77
|
+
* `null` once it is gone.
|
|
78
|
+
* @default undefined
|
|
79
|
+
*/
|
|
80
|
+
onHandle?: (handle: CrystalViewHandle | null) => void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The 3D crystal, with its failure and no-WebGL messages.
|
|
85
|
+
* @param props - See {@link CrystalViewer3DProps}.
|
|
86
|
+
* @returns The viewer, or an explanation of why this machine cannot show one.
|
|
87
|
+
*/
|
|
88
|
+
export function CrystalViewer3D(props: CrystalViewer3DProps): ReactElement {
|
|
89
|
+
const {
|
|
90
|
+
scene,
|
|
91
|
+
height = 420,
|
|
92
|
+
background,
|
|
93
|
+
tools,
|
|
94
|
+
fileName,
|
|
95
|
+
caption,
|
|
96
|
+
emptyMessage,
|
|
97
|
+
unsupportedNote,
|
|
98
|
+
onHandle,
|
|
99
|
+
} = props;
|
|
100
|
+
const t = useChromeT();
|
|
101
|
+
const [capability] = useState(probeViewerCapability);
|
|
102
|
+
const [failure, setFailure] = useState<string | null>(null);
|
|
103
|
+
|
|
104
|
+
if (!capability.supported) {
|
|
105
|
+
return (
|
|
106
|
+
<Callout
|
|
107
|
+
intent="warning"
|
|
108
|
+
icon="desktop"
|
|
109
|
+
title={t('crystal3d.unsupported')}
|
|
110
|
+
compact
|
|
111
|
+
>
|
|
112
|
+
{t.or(`viewer.capability.${capability.reason}`, capability.message)}{' '}
|
|
113
|
+
{unsupportedNote}
|
|
114
|
+
</Callout>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<div style={ROOT_STYLE}>
|
|
120
|
+
<div style={{ ...FRAME_STYLE, height }}>
|
|
121
|
+
{scene.atoms.length === 0 ? (
|
|
122
|
+
<div style={NOTICE_STYLE}>{emptyMessage}</div>
|
|
123
|
+
) : (
|
|
124
|
+
<Suspense
|
|
125
|
+
fallback={
|
|
126
|
+
<div style={NOTICE_STYLE}>
|
|
127
|
+
<Spinner size={SpinnerSize.STANDARD} />
|
|
128
|
+
<span>{t('molecule3d.loadingViewer')}</span>
|
|
129
|
+
</div>
|
|
130
|
+
}
|
|
131
|
+
>
|
|
132
|
+
<CrystalCanvas3D
|
|
133
|
+
scene={scene}
|
|
134
|
+
background={background}
|
|
135
|
+
tools={tools}
|
|
136
|
+
fileName={fileName}
|
|
137
|
+
onFailure={setFailure}
|
|
138
|
+
onHandle={onHandle}
|
|
139
|
+
/>
|
|
140
|
+
</Suspense>
|
|
141
|
+
)}
|
|
142
|
+
</div>
|
|
143
|
+
{caption === undefined ? null : (
|
|
144
|
+
<div style={CAPTION_STYLE}>{caption}</div>
|
|
145
|
+
)}
|
|
146
|
+
{failure !== null && (
|
|
147
|
+
<Callout intent="danger" title={t('molecule3d.couldNotDraw')} compact>
|
|
148
|
+
{failure}
|
|
149
|
+
</Callout>
|
|
150
|
+
)}
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const ROOT_STYLE: CSSProperties = {
|
|
156
|
+
display: 'flex',
|
|
157
|
+
flexDirection: 'column',
|
|
158
|
+
gap: 6,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const FRAME_STYLE: CSSProperties = {
|
|
162
|
+
position: 'relative',
|
|
163
|
+
overflow: 'hidden',
|
|
164
|
+
borderRadius: TOKEN.radius,
|
|
165
|
+
border: `1px solid ${TOKEN.border}`,
|
|
166
|
+
background: TOKEN.surface,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const NOTICE_STYLE: CSSProperties = {
|
|
170
|
+
display: 'flex',
|
|
171
|
+
height: '100%',
|
|
172
|
+
flexDirection: 'column',
|
|
173
|
+
alignItems: 'center',
|
|
174
|
+
justifyContent: 'center',
|
|
175
|
+
gap: 10,
|
|
176
|
+
color: TOKEN.textMuted,
|
|
177
|
+
fontSize: 13,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const CAPTION_STYLE: CSSProperties = {
|
|
181
|
+
color: TOKEN.textMuted,
|
|
182
|
+
fontSize: 12,
|
|
183
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a page asks the crystal view to show.
|
|
3
|
+
*
|
|
4
|
+
* It is a plain description — atoms, a cell, a set of elements, an operation to
|
|
5
|
+
* play — so a page can build one without importing anything that pulls molstar
|
|
6
|
+
* in. The canvas that reads it is behind a `React.lazy` boundary, and this type
|
|
7
|
+
* is on the near side of it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Molecule3DCamera } from '../../molecule3d/core/camera.ts';
|
|
11
|
+
import type { Molecule3DCapture } from '../../molecule3d/ui/moleculeViewer3DProps.ts';
|
|
12
|
+
import type { ElementStyle } from '../core/primitives.ts';
|
|
13
|
+
import type {
|
|
14
|
+
CellRepeat,
|
|
15
|
+
SymmetryDrawing,
|
|
16
|
+
UnitCell,
|
|
17
|
+
ViewerAtom,
|
|
18
|
+
ViewerOperation,
|
|
19
|
+
} from '../core/types.ts';
|
|
20
|
+
|
|
21
|
+
/** An operation to apply, and the cue that applies it again. */
|
|
22
|
+
export interface OperationPlayback {
|
|
23
|
+
/**
|
|
24
|
+
* Changing this number replays the operation; keeping it leaves the structure
|
|
25
|
+
* where it is. It is a cue rather than a flag so that pressing *Apply* twice
|
|
26
|
+
* plays it twice.
|
|
27
|
+
*/
|
|
28
|
+
readonly nonce: number;
|
|
29
|
+
/** What to apply. */
|
|
30
|
+
readonly operation: ViewerOperation;
|
|
31
|
+
/**
|
|
32
|
+
* How long one application takes, milliseconds.
|
|
33
|
+
* @default 900
|
|
34
|
+
*/
|
|
35
|
+
readonly durationMs?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Everything on screen at once. */
|
|
39
|
+
export interface CrystalScene {
|
|
40
|
+
/**
|
|
41
|
+
* The atoms, expanded and repeated already, in Cartesian ångström. An empty
|
|
42
|
+
* list draws no structure, which is what an empty workbench shows.
|
|
43
|
+
*/
|
|
44
|
+
readonly atoms: readonly ViewerAtom[];
|
|
45
|
+
/**
|
|
46
|
+
* The cell the atoms sit in, when there is one.
|
|
47
|
+
* @default null
|
|
48
|
+
*/
|
|
49
|
+
readonly cell?: UnitCell | null;
|
|
50
|
+
/**
|
|
51
|
+
* How many cells the box is drawn around. It does not repeat the atoms —
|
|
52
|
+
* `supercellAtoms` does that, and the page has already called it.
|
|
53
|
+
* @default [1, 1, 1]
|
|
54
|
+
*/
|
|
55
|
+
readonly repeat?: CellRepeat;
|
|
56
|
+
/**
|
|
57
|
+
* The symmetry elements drawn over the structure.
|
|
58
|
+
* @default []
|
|
59
|
+
*/
|
|
60
|
+
readonly elements?: readonly SymmetryDrawing[];
|
|
61
|
+
/**
|
|
62
|
+
* Whether each element's name floats beside it.
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
readonly labels?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* How thick and how large those elements are drawn. A cell scales it to its
|
|
68
|
+
* own edges, so the same figure reads the same on a 3.9 Å perovskite and a
|
|
69
|
+
* 24 Å zeolite.
|
|
70
|
+
* @default the defaults of `primitives.ts`
|
|
71
|
+
*/
|
|
72
|
+
readonly elementStyle?: ElementStyle;
|
|
73
|
+
/**
|
|
74
|
+
* How the atoms are drawn.
|
|
75
|
+
* @default 'ball-and-stick'
|
|
76
|
+
*/
|
|
77
|
+
readonly representation?: 'ball-and-stick' | 'spacefill';
|
|
78
|
+
/**
|
|
79
|
+
* An operation waiting to be applied.
|
|
80
|
+
* @default null
|
|
81
|
+
*/
|
|
82
|
+
readonly play?: OperationPlayback | null;
|
|
83
|
+
/**
|
|
84
|
+
* Where the camera stands when this structure is drawn — the view a figure
|
|
85
|
+
* carried — instead of the framing every new structure gets. It is put back
|
|
86
|
+
* once; a later redraw frames the scene again.
|
|
87
|
+
* @default null
|
|
88
|
+
*/
|
|
89
|
+
readonly camera?: Molecule3DCamera | null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** What the canvas hands a page that pictures it. */
|
|
93
|
+
export interface CrystalViewHandle {
|
|
94
|
+
/** Render the scene as a figure. */
|
|
95
|
+
readonly capture: Molecule3DCapture;
|
|
96
|
+
/** Where the camera stands, against what is drawn; `null` before anything is. */
|
|
97
|
+
readonly readCamera: () => Promise<Molecule3DCamera | null>;
|
|
98
|
+
/** Resolves once the structure asked for last is drawn. */
|
|
99
|
+
readonly whenDrawn: () => Promise<void>;
|
|
100
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Molecule3DTools } from '../../molecule3d/core/settings.ts';
|
|
2
|
+
import type { CrystalViewSettings } from '../core/crystalView.ts';
|
|
3
|
+
|
|
4
|
+
import type { CrystalViewHandle } from './crystalScene.ts';
|
|
5
|
+
|
|
6
|
+
/** Props of `CrystalStructureViewer`. */
|
|
7
|
+
export interface CrystalStructureViewerProps {
|
|
8
|
+
/** The CIF, as text. */
|
|
9
|
+
cif: string;
|
|
10
|
+
/**
|
|
11
|
+
* What the crystal is called, at the head of the caption.
|
|
12
|
+
* @default ''
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
/**
|
|
16
|
+
* How the crystal is drawn, when the page owns it — to keep it in the
|
|
17
|
+
* address, for one.
|
|
18
|
+
* @default undefined
|
|
19
|
+
*/
|
|
20
|
+
settings?: CrystalViewSettings;
|
|
21
|
+
/**
|
|
22
|
+
* How the crystal is drawn at first, when the viewer owns it.
|
|
23
|
+
* @default DEFAULT_CRYSTAL_VIEW_SETTINGS
|
|
24
|
+
*/
|
|
25
|
+
defaultSettings?: CrystalViewSettings;
|
|
26
|
+
/**
|
|
27
|
+
* Called with every change a chip makes.
|
|
28
|
+
* @default undefined
|
|
29
|
+
*/
|
|
30
|
+
onSettingsChange?: (settings: CrystalViewSettings) => void;
|
|
31
|
+
/**
|
|
32
|
+
* How tall the canvas is: pixels, or any CSS length.
|
|
33
|
+
* @default 420
|
|
34
|
+
*/
|
|
35
|
+
height?: number | string;
|
|
36
|
+
/**
|
|
37
|
+
* Which tools the toolbars offer; every one it does not name is on.
|
|
38
|
+
* @default every tool but the display options and the surface
|
|
39
|
+
*/
|
|
40
|
+
tools?: Partial<Molecule3DTools>;
|
|
41
|
+
/**
|
|
42
|
+
* Base name of a picture saved from the toolbar, extension excluded.
|
|
43
|
+
* @default 'crystal'
|
|
44
|
+
*/
|
|
45
|
+
fileName?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Called with the means to picture the scene once the canvas exists, and with
|
|
48
|
+
* `null` once it is gone.
|
|
49
|
+
* @default undefined
|
|
50
|
+
*/
|
|
51
|
+
onHandle?: (handle: CrystalViewHandle | null) => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { DEFAULT_CRYSTAL_VIEW_SETTINGS as DEFAULT_SETTINGS } from '../core/crystalView.ts';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a page imports to show a crystal in 3D.
|
|
3
|
+
*
|
|
4
|
+
* **Nothing exported here may pull molstar in statically.** The canvas, the
|
|
5
|
+
* viewer class and the bond rule are reached through `React.lazy` only;
|
|
6
|
+
* type-only re-exports are erased and so are safe.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type {
|
|
10
|
+
CrystalScene,
|
|
11
|
+
CrystalViewHandle,
|
|
12
|
+
OperationPlayback,
|
|
13
|
+
} from './crystalScene.ts';
|
|
14
|
+
export type { CrystalStructureViewerProps } from './crystalStructureViewerProps.ts';
|
|
15
|
+
export { CrystalStructureViewer } from './CrystalStructureViewer.tsx';
|
|
16
|
+
export type { CrystalViewControlsProps } from './CrystalViewControls.tsx';
|
|
17
|
+
export { CrystalViewControls } from './CrystalViewControls.tsx';
|
|
18
|
+
export type { CrystalViewer3DProps } from './CrystalViewer3D.tsx';
|
|
19
|
+
export { CrystalViewer3D } from './CrystalViewer3D.tsx';
|
|
20
|
+
export { useCrystalCaption } from './useCrystalCaption.ts';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One line under a crystal saying what is on it: its name, what one cell
|
|
3
|
+
* holds, and how many cells are drawn.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
7
|
+
import type { CrystalView } from '../core/crystalView.ts';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The caption of a crystal view.
|
|
11
|
+
* @param name - What the crystal is called; left out when empty.
|
|
12
|
+
* @param view - What `crystalView` found.
|
|
13
|
+
* @param asked - Cells along each axis asked for.
|
|
14
|
+
* @returns e.g. `Aspirin · 4 molecules per cell · 2×2×2 cells`.
|
|
15
|
+
*/
|
|
16
|
+
export function useCrystalCaption(
|
|
17
|
+
name: string,
|
|
18
|
+
view: Pick<CrystalView, 'molecules' | 'atomsPerCell' | 'cells'>,
|
|
19
|
+
asked: number,
|
|
20
|
+
): string {
|
|
21
|
+
const t = useChromeT();
|
|
22
|
+
const parts = [
|
|
23
|
+
name,
|
|
24
|
+
view.molecules > 0
|
|
25
|
+
? view.molecules === 1
|
|
26
|
+
? t('crystal3d.caption.molecules.one')
|
|
27
|
+
: t('crystal3d.caption.molecules.other', { count: view.molecules })
|
|
28
|
+
: view.atomsPerCell === 1
|
|
29
|
+
? t('crystal3d.caption.atoms.one')
|
|
30
|
+
: t('crystal3d.caption.atoms.other', { count: view.atomsPerCell }),
|
|
31
|
+
view.cells < asked
|
|
32
|
+
? t('crystal3d.caption.cellsCapped', { count: view.cells, asked })
|
|
33
|
+
: view.cells === 1
|
|
34
|
+
? t('crystal3d.caption.cells.one')
|
|
35
|
+
: t('crystal3d.caption.cells.other', { count: view.cells }),
|
|
36
|
+
];
|
|
37
|
+
return parts.filter((part) => part !== '').join(' · ');
|
|
38
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applying an operation to the structure, so a student watches it land back on
|
|
3
|
+
* itself.
|
|
4
|
+
*
|
|
5
|
+
* The structure moves and the symmetry elements do not: an axis that turned with
|
|
6
|
+
* the molecule would prove nothing. Moving it costs one GPU uniform per frame —
|
|
7
|
+
* `Representation.State.transform` is written straight into the renderable — so
|
|
8
|
+
* nothing is rebuilt and nothing is re-uploaded while the animation runs.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Mat4 } from 'molstar/lib/mol-math/linear-algebra.js';
|
|
12
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
13
|
+
|
|
14
|
+
import type { Matrix4 } from '../core/operationMatrix.ts';
|
|
15
|
+
import { IDENTITY_MATRIX4, operationAt } from '../core/operationMatrix.ts';
|
|
16
|
+
import type { ViewerOperation } from '../core/types.ts';
|
|
17
|
+
|
|
18
|
+
import { structureRepresentation } from './renderStructure.ts';
|
|
19
|
+
|
|
20
|
+
/** How an operation is played. */
|
|
21
|
+
export interface PlayOptions {
|
|
22
|
+
/**
|
|
23
|
+
* How long one application takes, milliseconds.
|
|
24
|
+
* @default 900
|
|
25
|
+
*/
|
|
26
|
+
durationMs?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Called with the fraction played, 0 to 1, on every frame.
|
|
29
|
+
* @default undefined
|
|
30
|
+
*/
|
|
31
|
+
onProgress?: (fraction: number) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Play one application of an operation, and leave the structure where it lands.
|
|
36
|
+
*
|
|
37
|
+
* A second call cancels the first, so a student hammering the button never sees
|
|
38
|
+
* two animations fight.
|
|
39
|
+
* @param plugin - The molstar context.
|
|
40
|
+
* @param operation - What to apply.
|
|
41
|
+
* @param options - See {@link PlayOptions}.
|
|
42
|
+
* @returns Resolves when the operation has been applied in full, or as soon as
|
|
43
|
+
* a later call has taken over.
|
|
44
|
+
*/
|
|
45
|
+
export function playOperation(
|
|
46
|
+
plugin: PluginContext,
|
|
47
|
+
operation: ViewerOperation,
|
|
48
|
+
options: PlayOptions = {},
|
|
49
|
+
): Promise<void> {
|
|
50
|
+
const { durationMs = 900, onProgress } = options;
|
|
51
|
+
const token = (tokens.get(plugin) ?? 0) + 1;
|
|
52
|
+
tokens.set(plugin, token);
|
|
53
|
+
if (durationMs <= 0) {
|
|
54
|
+
setOperationFraction(plugin, operation, 1);
|
|
55
|
+
onProgress?.(1);
|
|
56
|
+
return Promise.resolve();
|
|
57
|
+
}
|
|
58
|
+
const started = now();
|
|
59
|
+
return new Promise<void>((resolve) => {
|
|
60
|
+
const step = (): void => {
|
|
61
|
+
if (tokens.get(plugin) !== token) {
|
|
62
|
+
resolve();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const fraction = Math.min(1, (now() - started) / durationMs);
|
|
66
|
+
setOperationFraction(plugin, operation, fraction);
|
|
67
|
+
onProgress?.(fraction);
|
|
68
|
+
if (fraction < 1) globalThis.requestAnimationFrame(step);
|
|
69
|
+
else resolve();
|
|
70
|
+
};
|
|
71
|
+
globalThis.requestAnimationFrame(step);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Hold the structure part-way through an operation, for a slider.
|
|
77
|
+
* @param plugin - The molstar context.
|
|
78
|
+
* @param operation - What is being applied.
|
|
79
|
+
* @param fraction - How far through, 0 to 1.
|
|
80
|
+
*/
|
|
81
|
+
export function setOperationFraction(
|
|
82
|
+
plugin: PluginContext,
|
|
83
|
+
operation: ViewerOperation,
|
|
84
|
+
fraction: number,
|
|
85
|
+
): void {
|
|
86
|
+
applyTransform(plugin, operationAt(operation, fraction));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Put the structure back where it started, and stop any animation in flight.
|
|
91
|
+
* @param plugin - The molstar context.
|
|
92
|
+
*/
|
|
93
|
+
export function resetOperation(plugin: PluginContext): void {
|
|
94
|
+
tokens.set(plugin, (tokens.get(plugin) ?? 0) + 1);
|
|
95
|
+
applyTransform(plugin, IDENTITY_MATRIX4);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function applyTransform(plugin: PluginContext, matrix: Matrix4): void {
|
|
99
|
+
const representation = structureRepresentation(plugin);
|
|
100
|
+
if (representation === undefined) return;
|
|
101
|
+
representation.setState({
|
|
102
|
+
transform: Mat4.fromArray(Mat4.identity(), matrix as number[], 0),
|
|
103
|
+
});
|
|
104
|
+
plugin.canvas3d?.update(representation);
|
|
105
|
+
plugin.canvas3d?.requestDraw();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function now(): number {
|
|
109
|
+
return globalThis.performance.now();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The animation in flight per plugin; a new one invalidates the old. */
|
|
113
|
+
const tokens = new WeakMap<PluginContext, number>();
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framing the scene.
|
|
3
|
+
*
|
|
4
|
+
* What is on screen is measured here rather than read off molstar, for the
|
|
5
|
+
* reason `framing.ts` gives: a representation's own bounding sphere is padded by
|
|
6
|
+
* the largest ball it could ever draw. Each part of the scene registers its
|
|
7
|
+
* extent as it is drawn, and the camera frames the union — the framing itself,
|
|
8
|
+
* and the union, are `react-cheminfo`'s.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Sphere3D } from 'molstar/lib/mol-math/geometry.js';
|
|
12
|
+
import { Vec3 } from 'molstar/lib/mol-math/linear-algebra.js';
|
|
13
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
14
|
+
|
|
15
|
+
import type { Molecule3DCamera } from '../../molecule3d/core/camera.ts';
|
|
16
|
+
import type { CameraReference } from '../../molstar/core/index.ts';
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_CAMERA_DURATION,
|
|
19
|
+
cameraToPose,
|
|
20
|
+
framedRadius,
|
|
21
|
+
poseToCamera,
|
|
22
|
+
resetCamera as frameScene,
|
|
23
|
+
unionSphere,
|
|
24
|
+
} from '../../molstar/core/index.ts';
|
|
25
|
+
import type { SceneSphere } from '../core/framing.ts';
|
|
26
|
+
import type { ViewOrientation } from '../core/orientation.ts';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The scene is measured as the ball through its furthest corners, and a camera
|
|
30
|
+
* fitting that ball to the window leaves a cell filling barely half of it: a
|
|
31
|
+
* cube touches its own circumscribed sphere only at eight corners, and uses
|
|
32
|
+
* about 82% of its diameter even seen square-on. So the ball handed to the
|
|
33
|
+
* camera is **smaller** than the one measured, by about the slack that costs.
|
|
34
|
+
* Nothing is cut at the orientations a cell is read at, and the reader can
|
|
35
|
+
* always pull back.
|
|
36
|
+
*/
|
|
37
|
+
const SCENE_MARGIN = -0.12;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Record how far one part of the scene reaches.
|
|
41
|
+
* @param plugin - The molstar context.
|
|
42
|
+
* @param key - Which part: the atoms, the cell, the elements.
|
|
43
|
+
* @param sphere - Its extent, or `null` once it is no longer drawn.
|
|
44
|
+
*/
|
|
45
|
+
export function setSceneExtent(
|
|
46
|
+
plugin: PluginContext,
|
|
47
|
+
key: string,
|
|
48
|
+
sphere: SceneSphere | null,
|
|
49
|
+
): void {
|
|
50
|
+
let parts = extents.get(plugin);
|
|
51
|
+
if (parts === undefined) {
|
|
52
|
+
parts = new Map<string, Sphere3D>();
|
|
53
|
+
extents.set(plugin, parts);
|
|
54
|
+
}
|
|
55
|
+
if (sphere === null) {
|
|
56
|
+
parts.delete(key);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const [x, y, z] = sphere.centre;
|
|
60
|
+
parts.set(key, Sphere3D.create(Vec3.create(x, y, z), sphere.radius));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Frame everything on screen.
|
|
65
|
+
* @param plugin - The molstar context.
|
|
66
|
+
* @param durationMs - Transition length; 0 jumps.
|
|
67
|
+
* @param orientation - Where to look from, from `sceneOrientation`. Left out,
|
|
68
|
+
* the camera keeps the direction it is already pointing, which is what a
|
|
69
|
+
* reframe after a reader has turned the scene should do.
|
|
70
|
+
*/
|
|
71
|
+
export function resetCamera(
|
|
72
|
+
plugin: PluginContext,
|
|
73
|
+
durationMs = DEFAULT_CAMERA_DURATION,
|
|
74
|
+
orientation?: ViewOrientation,
|
|
75
|
+
): void {
|
|
76
|
+
frameScene(plugin, {
|
|
77
|
+
spheres: [...(extents.get(plugin)?.values() ?? [])],
|
|
78
|
+
margin: SCENE_MARGIN,
|
|
79
|
+
durationMs,
|
|
80
|
+
orientation,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Where the camera stands, measured against what is drawn rather than in
|
|
86
|
+
* ångström, so a figure opens on the same view in a frame of another size.
|
|
87
|
+
* @param plugin - The molstar context.
|
|
88
|
+
* @returns The camera, or `null` while nothing is drawn to measure it against.
|
|
89
|
+
*/
|
|
90
|
+
export function readCamera(plugin: PluginContext): Molecule3DCamera | null {
|
|
91
|
+
const canvas = plugin.canvas3d;
|
|
92
|
+
const reference = sceneReference(plugin);
|
|
93
|
+
if (canvas === undefined || reference === null) return null;
|
|
94
|
+
return poseToCamera(
|
|
95
|
+
canvas.camera.getSnapshot(),
|
|
96
|
+
reference,
|
|
97
|
+
canvas.camera.getTargetDistance(reference.radius),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Put the camera where {@link readCamera} found it, against what is drawn now.
|
|
103
|
+
* @param plugin - The molstar context.
|
|
104
|
+
* @param camera - Where to stand.
|
|
105
|
+
*/
|
|
106
|
+
export function applyCamera(
|
|
107
|
+
plugin: PluginContext,
|
|
108
|
+
camera: Molecule3DCamera,
|
|
109
|
+
): void {
|
|
110
|
+
const canvas = plugin.canvas3d;
|
|
111
|
+
if (canvas === undefined) return;
|
|
112
|
+
// Resolves a reframe molstar has queued, which would otherwise land after
|
|
113
|
+
// this move and undo it.
|
|
114
|
+
canvas.commit(true);
|
|
115
|
+
const reference = sceneReference(plugin);
|
|
116
|
+
if (reference === null) return;
|
|
117
|
+
const pose = cameraToPose(
|
|
118
|
+
camera,
|
|
119
|
+
reference,
|
|
120
|
+
canvas.camera.getTargetDistance(reference.radius),
|
|
121
|
+
);
|
|
122
|
+
canvas.camera.setState({ ...pose, radius: reference.radius }, 0);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The sphere a camera is measured against: every part drawn, framed.
|
|
127
|
+
* @param plugin - The molstar context whose scene is measured.
|
|
128
|
+
* @returns The centre and framed radius, or `null` while nothing is drawn.
|
|
129
|
+
*/
|
|
130
|
+
function sceneReference(plugin: PluginContext): CameraReference | null {
|
|
131
|
+
const union = unionSphere([...(extents.get(plugin)?.values() ?? [])]);
|
|
132
|
+
if (union === null || !(union.radius > 0)) return null;
|
|
133
|
+
return { center: union.center, radius: framedRadius(union.radius) };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** What each part of the scene reaches, per plugin. */
|
|
137
|
+
const extents = new WeakMap<PluginContext, Map<string, Sphere3D>>();
|
|
138
|
+
|
|
139
|
+
export { DEFAULT_CAMERA_DURATION } from '../../molstar/core/index.ts';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The molstar half of the crystal viewer: the canvas, and everything drawn on
|
|
3
|
+
* it. Reaching it pulls molstar in, so only the lazy canvas imports it.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type { PlayOptions } from './animate.ts';
|
|
7
|
+
export { DEFAULT_CAMERA_DURATION } from './camera.ts';
|
|
8
|
+
export type { CrystalViewerOptions } from './plugin.ts';
|
|
9
|
+
export { CrystalViewerPlugin } from './plugin.ts';
|
|
10
|
+
export type { CellStyle } from './renderCell.ts';
|
|
11
|
+
export type { ElementLayerStyle } from './renderElements.ts';
|
|
12
|
+
export type { StructureStyle } from './renderStructure.ts';
|
|
13
|
+
export { CrystalViewer, createCrystalViewer } from './viewer.ts';
|