mirror of
https://github.com/molstar/molstar.git
synced 2026-06-05 05:44:23 +08:00
Compare commits
175 Commits
clamp-cube
...
v3.29.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcf9d1c3bb | ||
|
|
c0c2e4ce4a | ||
|
|
3557f4e738 | ||
|
|
6595c00cff | ||
|
|
c612018ba8 | ||
|
|
ec06ef2dfb | ||
|
|
2febf45700 | ||
|
|
3e6066a1a1 | ||
|
|
b61e5c76db | ||
|
|
bdee4859f2 | ||
|
|
b5e45aae95 | ||
|
|
7fd12c5622 | ||
|
|
47442be989 | ||
|
|
3a484dc41a | ||
|
|
9a2dfd7e57 | ||
|
|
c9a168a138 | ||
|
|
3726f28eeb | ||
|
|
ead25d6a9c | ||
|
|
55f4abb6be | ||
|
|
2e013fafc8 | ||
|
|
0809379f91 | ||
|
|
0d4a95f5af | ||
|
|
2e9129a71c | ||
|
|
7384bebf4e | ||
|
|
0e197b1885 | ||
|
|
54697ae0d5 | ||
|
|
7b6eb9337e | ||
|
|
a94fb84052 | ||
|
|
528aeb1873 | ||
|
|
e7b35daf45 | ||
|
|
7d10971617 | ||
|
|
3d83211503 | ||
|
|
cd8c8fa020 | ||
|
|
4c03009357 | ||
|
|
047f547863 | ||
|
|
83c62c614b | ||
|
|
c39b3569de | ||
|
|
7fea62aa46 | ||
|
|
d816f510ea | ||
|
|
c2064aa318 | ||
|
|
109709ce8b | ||
|
|
b200725762 | ||
|
|
9cf34bf987 | ||
|
|
be3a91bb14 | ||
|
|
fc948d8b27 | ||
|
|
8774658f4e | ||
|
|
0bf32148af | ||
|
|
97d158b615 | ||
|
|
b772dea188 | ||
|
|
5c8f0b35ec | ||
|
|
1b382653f2 | ||
|
|
c7cee63c97 | ||
|
|
ba9474fa62 | ||
|
|
b7ec7ea686 | ||
|
|
74560adb08 | ||
|
|
e6a303bdda | ||
|
|
7afcf0bb68 | ||
|
|
7aae2d0616 | ||
|
|
9255505a3b | ||
|
|
6c0dfd338d | ||
|
|
c306e988c8 | ||
|
|
86f7a8b273 | ||
|
|
2428a8efab | ||
|
|
cba12e487f | ||
|
|
e98d7931ca | ||
|
|
f8e2d2e3d0 | ||
|
|
4455bab6ac | ||
|
|
b21fb27041 | ||
|
|
5402ee0019 | ||
|
|
02654ea57b | ||
|
|
9cd4aeabaa | ||
|
|
d788511a83 | ||
|
|
378b5b8096 | ||
|
|
e26eb2f751 | ||
|
|
26264b15f7 | ||
|
|
309e3dd981 | ||
|
|
4ff5ed3b5d | ||
|
|
270a757756 | ||
|
|
79e4030ab4 | ||
|
|
fd86927e04 | ||
|
|
df3a7e5037 | ||
|
|
fefc6f14c9 | ||
|
|
923fbef0e4 | ||
|
|
601bd5ba7a | ||
|
|
5798f20c41 | ||
|
|
f2e26f91a8 | ||
|
|
e2cdc45be6 | ||
|
|
96493bc75e | ||
|
|
d78ad4a78e | ||
|
|
0c54b0dd6e | ||
|
|
65310e52de | ||
|
|
285d3cd9b8 | ||
|
|
10486abb64 | ||
|
|
8c1a9fc988 | ||
|
|
7bdd0b470b | ||
|
|
b7a51f12bf | ||
|
|
e002ac5474 | ||
|
|
211d339ce0 | ||
|
|
509fb14473 | ||
|
|
ef838a1b83 | ||
|
|
f84b5b633d | ||
|
|
8ec8c1170d | ||
|
|
920b98e4d1 | ||
|
|
c80f52d4bc | ||
|
|
0b6aa42daf | ||
|
|
04dc6427ef | ||
|
|
77e366b484 | ||
|
|
add7cfa0f2 | ||
|
|
14d4fa142c | ||
|
|
7fe1617f25 | ||
|
|
cbe4cb521c | ||
|
|
7c394525c1 | ||
|
|
12ed051fea | ||
|
|
014913c635 | ||
|
|
369e45c282 | ||
|
|
2892caec0c | ||
|
|
eb609e918a | ||
|
|
9217e58845 | ||
|
|
26b633618a | ||
|
|
e3054d6ee1 | ||
|
|
0b6294f4ec | ||
|
|
7b130dc0f3 | ||
|
|
d93c128c25 | ||
|
|
e1dd74775e | ||
|
|
e61e706607 | ||
|
|
a57d46deaa | ||
|
|
60efdc0071 | ||
|
|
4dc1155a9e | ||
|
|
5cabe6fb42 | ||
|
|
42239c305f | ||
|
|
fd3c763349 | ||
|
|
daa9bbf2c9 | ||
|
|
c7dad00908 | ||
|
|
24317717e8 | ||
|
|
dd3eac6db6 | ||
|
|
1606f8517f | ||
|
|
3a98401ada | ||
|
|
4764251241 | ||
|
|
3de04b7b9d | ||
|
|
04908495e9 | ||
|
|
3c835c848e | ||
|
|
0f1788f122 | ||
|
|
3d72e700a4 | ||
|
|
a5cf41e65f | ||
|
|
7029bc41d7 | ||
|
|
b87d40c844 | ||
|
|
9e154376d3 | ||
|
|
4a9fdbce57 | ||
|
|
775e335292 | ||
|
|
e553bf4deb | ||
|
|
db0e09ec6e | ||
|
|
ba50760f92 | ||
|
|
524e6d4f81 | ||
|
|
db93a669ab | ||
|
|
423f5b0502 | ||
|
|
2bc45c25fe | ||
|
|
d341463f67 | ||
|
|
19d1ecb36a | ||
|
|
ffe4047f97 | ||
|
|
15a3c29e7a | ||
|
|
42ff593004 | ||
|
|
5140af4e6f | ||
|
|
0f5b4c00a9 | ||
|
|
feb69f4987 | ||
|
|
84eb9a58ca | ||
|
|
fbd96f473a | ||
|
|
69228157dc | ||
|
|
6808f32b8d | ||
|
|
9e69f5dcfa | ||
|
|
409ed9ad67 | ||
|
|
06e78e19d0 | ||
|
|
9a1d746170 | ||
|
|
ef87ce3507 | ||
|
|
2b9053eac4 | ||
|
|
116ef719be |
2
.github/workflows/node.yml
vendored
2
.github/workflows/node.yml
vendored
@@ -1,3 +1,5 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
83
CHANGELOG.md
83
CHANGELOG.md
@@ -6,18 +6,97 @@ Note that since we don't clearly distinguish between a public and private interf
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [v3.29.0] - 2023-01-15
|
||||
|
||||
- `meshes` extension: Fixed a bug in mesh visualization (show backfaces when opacity < 1)
|
||||
- Add color quick select control to Volume controls
|
||||
- Fix `dropFiles` bug
|
||||
- Fix some cyclic imports and reduce the use of const enums. This should make it easier to use the library with the `isolatedModules: true` TS config.
|
||||
- Fix `dropFiles` bug (#679)
|
||||
- Add `input type='color'` picker to `CombinedColorControl`
|
||||
- Set `ParameterMappingControl` disabled when state is updating
|
||||
- Performance tweaks
|
||||
- Update clip `defines` only when changed
|
||||
- Check for identity in structure/unit areEqual methods
|
||||
- Avoid cloning of structure representation parameters
|
||||
- Make SymmetryOperator.createMapping monomorphic
|
||||
- Improve bonding-sphere calculation
|
||||
- Defer Scene properties calculation (markerAverage, opacityAverage, hasOpaque)
|
||||
- Improve checks in in UnitsRepresentation setVisualState
|
||||
- Add StructureElement.Loci.forEachLocation
|
||||
- Add RepresentationRegistry.clear and ThemeRegistry.clear
|
||||
- Add generic Loci support for overpaint, substance, clipping themes
|
||||
- Add `.getCenter` and `.center` to `Camera`
|
||||
- Add support to dim unmarked groups
|
||||
- Add support for marker edge strength
|
||||
|
||||
## [v3.28.0] - 2022-12-20
|
||||
|
||||
- Show histogram in direct volume control point settings
|
||||
- Add `solidInterior` parameter to sphere/cylinder impostors
|
||||
- [Breaking] Tweak `ignoreHydrogens` non-polar handling (introduced in 3.27.0)
|
||||
- Add `meshes` and `volumes-and-segmentations` extensions
|
||||
- See https://molstarvolseg.ncbr.muni.cz/ for more info
|
||||
- Fix missing support for info in `ParamDefinition.Converted`
|
||||
- Add support for multi-visual volume representations
|
||||
- Improve volume isosurface bounding-sphere
|
||||
- Add basic volume segmentation support to core
|
||||
- Add `Volume.Segment` model
|
||||
- Add `Segmentation` custom volume property
|
||||
- Add `SegmentRepresentation` representation
|
||||
- Add `volume-segment` color theme
|
||||
- Fix GPU marching cubes failing for large meshes with webgl2 (due to use of float16)
|
||||
|
||||
## [v3.27.0] - 2022-12-15
|
||||
|
||||
- Add an `includeTransparent` parameter to hide/show outlines of components that are transparent
|
||||
- Fix 'once' for animations of systems with many frames
|
||||
- Better guard against issue (black fringes) with bumpiness in impostors
|
||||
- Improve impostor shaders
|
||||
- Fix sphere near-clipping with orthographic projection
|
||||
- Fix cylinder near-clipping
|
||||
- Add interior cylinder caps
|
||||
- Add per-pixel object clipping
|
||||
- Fix `QualityAssessment` assignment bug for structures with different auth vs label sequence numbering
|
||||
- Refresh `ApplyActionControl`'s param definition when toggling expanded state
|
||||
- Fix `struct_conn` bond assignment for ions
|
||||
- Ability to show only polar hydrogens
|
||||
|
||||
## [v3.26.0] - 2022-12-04
|
||||
|
||||
- Support for ``powerPreference`` webgl attribute. Add ``PluginConfig.General.PowerPreference`` and ``power-preference`` Viewer GET param.
|
||||
- Excluded common protein caps `NME` and `ACE` from the ligand selection query
|
||||
- Add screen-space shadow post-processing effect
|
||||
- Add "Structure Molecular Surface" visual
|
||||
- Add `external-volume` theme (coloring of arbitrary geometries by user-selected volume)
|
||||
|
||||
## [v3.25.1] - 2022-11-20
|
||||
|
||||
- Fix edge-case in `Structure.eachUnitPair` with single-element units
|
||||
- Fix 'auto' structure-quality for coarse models
|
||||
|
||||
## [v3.25.0] - 2022-11-16
|
||||
|
||||
- Fix handling of gzipped assets (reverts #615)
|
||||
|
||||
## [v3.24.0] - 2022-11-13
|
||||
|
||||
- Make `PluginContext.initContainer` checkered canvas background optional
|
||||
- Store URL of downloaded assets to detect zip/gzip based on extension (#615)
|
||||
- Add optional `operator.key`; can be referenced in `IndexPairBonds`
|
||||
- Add overpaint/transparency/substance theme strength to representations
|
||||
- Fix viewport color for transparent background
|
||||
|
||||
## [v3.23.0] - 2022-10-19
|
||||
|
||||
- Add `PluginContext.initContainer/mount/unmount` methods; these should make it easier to reuse a plugin context with both custom and built-in UI
|
||||
- Add `PluginContext.canvas3dInitialized`
|
||||
- `createPluginUI` now resolves after the 3d canvas has been initialized
|
||||
- Change EM Volume Streaming default from `Whote Structure` to `Auto`
|
||||
- Change EM Volume Streaming default from `Whole Structure` to `Auto`
|
||||
|
||||
## [v3.22.0] - 2022-10-17
|
||||
|
||||
- Replace `VolumeIsosurfaceParams.pickingGranularity` param with `Volume.PickingGranuality`
|
||||
- Replace `VolumeIsosurfaceParams.pickingGranularity` param with `Volume.PickingGranuality`
|
||||
|
||||
## [v3.21.0] - 2022-10-17
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[](./LICENSE)
|
||||
[](https://www.npmjs.com/package/molstar)
|
||||
[](https://travis-ci.org/molstar/molstar)
|
||||
[](https://github.com/molstar/molstar/actions/workflows/node.yml)
|
||||
[](https://gitter.im/molstar/Lobby)
|
||||
|
||||
# Mol*
|
||||
|
||||
28000
examples/long_animation.sdf
Normal file
28000
examples/long_animation.sdf
Normal file
File diff suppressed because it is too large
Load Diff
5564
package-lock.json
generated
5564
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
76
package.json
76
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "molstar",
|
||||
"version": "3.23.0",
|
||||
"version": "3.29.0",
|
||||
"description": "A comprehensive macromolecular library.",
|
||||
"homepage": "https://github.com/molstar/molstar#readme",
|
||||
"repository": {
|
||||
@@ -13,7 +13,7 @@
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"lint-fix": "eslint . --fix",
|
||||
"test": "npm install --no-save \"gl@^5.0.0\" && npm run lint && jest",
|
||||
"test": "npm install --no-save \"gl@^6.0.2\" && npm run lint && jest",
|
||||
"jest": "jest",
|
||||
"build": "npm run build-tsc && npm run build-extra && npm run build-webpack",
|
||||
"clean": "node ./scripts/clean.js",
|
||||
@@ -92,57 +92,59 @@
|
||||
"Panagiotis Tourlas <panagiot_tourlov@hotmail.com>",
|
||||
"Adam Midlik <midlik@gmail.com>",
|
||||
"Koya Sakuma <koya.sakuma.work@gmail.com>",
|
||||
"Gianluca Tomasello <giagitom@gmail.com>"
|
||||
"Gianluca Tomasello <giagitom@gmail.com>",
|
||||
"Jason Pattle <jpattle@exscientia.co.uk>",
|
||||
"David Williams <dwilliams@nobiastx.com>"
|
||||
],
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@graphql-codegen/add": "^3.2.1",
|
||||
"@graphql-codegen/cli": "^2.13.7",
|
||||
"@graphql-codegen/time": "^3.2.1",
|
||||
"@graphql-codegen/typescript": "^2.7.4",
|
||||
"@graphql-codegen/add": "^3.2.3",
|
||||
"@graphql-codegen/cli": "^2.16.4",
|
||||
"@graphql-codegen/time": "^3.2.3",
|
||||
"@graphql-codegen/typescript": "^2.8.7",
|
||||
"@graphql-codegen/typescript-graphql-files-modules": "^2.2.1",
|
||||
"@graphql-codegen/typescript-graphql-request": "^4.5.6",
|
||||
"@graphql-codegen/typescript-operations": "^2.5.4",
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/gl": "^4.1.1",
|
||||
"@types/jest": "^29.1.2",
|
||||
"@types/react": "^18.0.21",
|
||||
"@types/react-dom": "^18.0.6",
|
||||
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
||||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"@graphql-codegen/typescript-graphql-request": "^4.5.8",
|
||||
"@graphql-codegen/typescript-operations": "^2.5.12",
|
||||
"@types/cors": "^2.8.13",
|
||||
"@types/gl": "^6.0.2",
|
||||
"@types/jest": "^29.2.5",
|
||||
"@types/react": "^18.0.26",
|
||||
"@types/react-dom": "^18.0.10",
|
||||
"@typescript-eslint/eslint-plugin": "^5.48.1",
|
||||
"@typescript-eslint/parser": "^5.48.1",
|
||||
"benchmark": "^2.1.4",
|
||||
"concurrently": "^7.4.0",
|
||||
"concurrently": "^7.6.0",
|
||||
"cpx2": "^4.2.0",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"css-loader": "^6.7.1",
|
||||
"eslint": "^8.25.0",
|
||||
"css-loader": "^6.7.3",
|
||||
"eslint": "^8.32.0",
|
||||
"extra-watch-webpack-plugin": "^1.0.3",
|
||||
"file-loader": "^6.2.0",
|
||||
"fs-extra": "^10.1.0",
|
||||
"fs-extra": "^11.1.0",
|
||||
"graphql": "^16.6.0",
|
||||
"http-server": "^14.1.1",
|
||||
"jest": "^29.2.0",
|
||||
"mini-css-extract-plugin": "^2.6.1",
|
||||
"jest": "^29.3.1",
|
||||
"mini-css-extract-plugin": "^2.7.2",
|
||||
"path-browserify": "^1.0.1",
|
||||
"raw-loader": "^4.0.2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"sass": "^1.55.0",
|
||||
"sass-loader": "^13.1.0",
|
||||
"simple-git": "^3.14.1",
|
||||
"sass": "^1.57.1",
|
||||
"sass-loader": "^13.2.0",
|
||||
"simple-git": "^3.15.1",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"style-loader": "^3.3.1",
|
||||
"ts-jest": "^29.0.3",
|
||||
"typescript": "^4.8.4",
|
||||
"webpack": "^5.74.0",
|
||||
"webpack-cli": "^4.10.0"
|
||||
"ts-jest": "^29.0.5",
|
||||
"typescript": "^4.9.4",
|
||||
"webpack": "^5.75.0",
|
||||
"webpack-cli": "^5.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/argparse": "^2.0.10",
|
||||
"@types/benchmark": "^2.1.2",
|
||||
"@types/compression": "1.7.2",
|
||||
"@types/express": "^4.17.14",
|
||||
"@types/node": "^16.11.66",
|
||||
"@types/express": "^4.17.15",
|
||||
"@types/node": "^16.18.11",
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"@types/swagger-ui-dist": "3.30.1",
|
||||
"argparse": "^2.0.1",
|
||||
@@ -151,12 +153,12 @@
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"h264-mp4-encoder": "^1.0.12",
|
||||
"immer": "^9.0.15",
|
||||
"immutable": "^4.1.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"rxjs": "^7.5.7",
|
||||
"swagger-ui-dist": "^4.14.3",
|
||||
"tslib": "^2.4.0",
|
||||
"immer": "^9.0.17",
|
||||
"immutable": "^4.2.2",
|
||||
"node-fetch": "^2.6.8",
|
||||
"rxjs": "^7.8.0",
|
||||
"swagger-ui-dist": "^4.15.5",
|
||||
"tslib": "^2.4.1",
|
||||
"util.promisify": "^1.1.1",
|
||||
"xhr2": "^0.2.1"
|
||||
},
|
||||
|
||||
@@ -31,7 +31,8 @@ function shinyStyle(plugin: PluginContext) {
|
||||
postprocessing: {
|
||||
...plugin.canvas3d!.props.postprocessing,
|
||||
occlusion: { name: 'off', params: {} },
|
||||
outline: { name: 'off', params: {} }
|
||||
shadow: { name: 'off', params: {} },
|
||||
outline: { name: 'off', params: {} },
|
||||
}
|
||||
} });
|
||||
}
|
||||
@@ -48,13 +49,15 @@ function occlusionStyle(plugin: PluginContext) {
|
||||
blurKernelSize: 15,
|
||||
radius: 5,
|
||||
samples: 32,
|
||||
resolutionScale: 1
|
||||
resolutionScale: 1,
|
||||
} },
|
||||
outline: { name: 'on', params: {
|
||||
scale: 1.0,
|
||||
threshold: 0.33,
|
||||
color: Color(0x0000),
|
||||
} }
|
||||
includeTransparent: true,
|
||||
} },
|
||||
shadow: { name: 'off', params: {} },
|
||||
}
|
||||
} });
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { ANVILMembraneOrientation } from '../../extensions/anvil/behavior';
|
||||
import { CellPack } from '../../extensions/cellpack';
|
||||
import { DnatcoConfalPyramids } from '../../extensions/dnatco';
|
||||
import { G3DFormat, G3dProvider } from '../../extensions/g3d/format';
|
||||
import { Volseg, VolsegVolumeServerConfig } from '../../extensions/volumes-and-segmentations';
|
||||
import { GeometryExport } from '../../extensions/geo-export';
|
||||
import { MAQualityAssessment } from '../../extensions/model-archive/quality-assessment/behavior';
|
||||
import { QualityAssessmentPLDDTPreset, QualityAssessmentQmeanPreset } from '../../extensions/model-archive/quality-assessment/behavior';
|
||||
@@ -56,6 +57,7 @@ const CustomFormats = [
|
||||
];
|
||||
|
||||
const Extensions = {
|
||||
'volseg': PluginSpec.Behavior(Volseg),
|
||||
'backgrounds': PluginSpec.Behavior(Backgrounds),
|
||||
'cellpack': PluginSpec.Behavior(CellPack),
|
||||
'dnatco-confal-pyramids': PluginSpec.Behavior(DnatcoConfalPyramids),
|
||||
@@ -91,6 +93,7 @@ const DefaultViewerOptions = {
|
||||
enableDpoit: PluginConfig.General.EnableDpoit.defaultValue,
|
||||
preferWebgl1: PluginConfig.General.PreferWebGl1.defaultValue,
|
||||
allowMajorPerformanceCaveat: PluginConfig.General.AllowMajorPerformanceCaveat.defaultValue,
|
||||
powerPreference: PluginConfig.General.PowerPreference.defaultValue,
|
||||
|
||||
viewportShowExpand: PluginConfig.Viewport.ShowExpand.defaultValue,
|
||||
viewportShowControls: PluginConfig.Viewport.ShowControls.defaultValue,
|
||||
@@ -104,6 +107,7 @@ const DefaultViewerOptions = {
|
||||
pdbProvider: PluginConfig.Download.DefaultPdbProvider.defaultValue,
|
||||
emdbProvider: PluginConfig.Download.DefaultEmdbProvider.defaultValue,
|
||||
saccharideCompIdMapType: 'default' as SaccharideCompIdMapType,
|
||||
volumesAndSegmentationsDefaultServer: VolsegVolumeServerConfig.DefaultServer.defaultValue,
|
||||
};
|
||||
type ViewerOptions = typeof DefaultViewerOptions;
|
||||
|
||||
@@ -163,6 +167,7 @@ export class Viewer {
|
||||
[PluginConfig.General.EnableDpoit, o.enableDpoit],
|
||||
[PluginConfig.General.PreferWebGl1, o.preferWebgl1],
|
||||
[PluginConfig.General.AllowMajorPerformanceCaveat, o.allowMajorPerformanceCaveat],
|
||||
[PluginConfig.General.PowerPreference, o.powerPreference],
|
||||
[PluginConfig.Viewport.ShowExpand, o.viewportShowExpand],
|
||||
[PluginConfig.Viewport.ShowControls, o.viewportShowControls],
|
||||
[PluginConfig.Viewport.ShowSettings, o.viewportShowSettings],
|
||||
@@ -177,6 +182,7 @@ export class Viewer {
|
||||
[PluginConfig.Download.DefaultEmdbProvider, o.emdbProvider],
|
||||
[PluginConfig.Structure.DefaultRepresentationPreset, ViewerAutoPreset.id],
|
||||
[PluginConfig.Structure.SaccharideCompIdMapType, o.saccharideCompIdMapType],
|
||||
[VolsegVolumeServerConfig.DefaultServer, o.volumesAndSegmentationsDefaultServer],
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
var enableDpoit = getParam('enable-dpoit', '[^&]+').trim() === '1';
|
||||
var preferWebgl1 = getParam('prefer-webgl1', '[^&]+').trim() === '1' || void 0;
|
||||
var allowMajorPerformanceCaveat = getParam('allow-major-performance-caveat', '[^&]+').trim() === '1';
|
||||
var powerPreference = getParam('power-preference', '[^&]+').trim().toLowerCase();
|
||||
|
||||
molstar.Viewer.create('app', {
|
||||
layoutShowControls: !hideControls,
|
||||
@@ -80,6 +81,7 @@
|
||||
enableDpoit: enableDpoit ? true : void 0,
|
||||
preferWebgl1: preferWebgl1,
|
||||
allowMajorPerformanceCaveat: allowMajorPerformanceCaveat,
|
||||
powerPreference: powerPreference || 'high-performance',
|
||||
}).then(viewer => {
|
||||
var snapshotId = getParam('snapshot-id', '[^&]+').trim();
|
||||
if (snapshotId) viewer.setRemoteSnapshot(snapshotId);
|
||||
|
||||
@@ -38,7 +38,7 @@ function print(volume: Volume) {
|
||||
}
|
||||
|
||||
async function doMesh(volume: Volume, filename: string) {
|
||||
const mesh = await Task.create('', runtime => createVolumeIsosurfaceMesh({ runtime }, volume, Theme.createEmpty(), { isoValue: Volume.IsoValue.absolute(1.5) })).run();
|
||||
const mesh = await Task.create('', runtime => createVolumeIsosurfaceMesh({ runtime }, volume, -1, Theme.createEmpty(), { isoValue: Volume.IsoValue.absolute(1.5) })).run();
|
||||
console.log({ vc: mesh.vertexCount, tc: mesh.triangleCount });
|
||||
|
||||
// Export the mesh in OBJ format.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
@@ -25,7 +25,8 @@ const Canvas3DPresets = {
|
||||
canvas3d: <Preset>{
|
||||
postprocessing: {
|
||||
occlusion: { name: 'on', params: { samples: 32, radius: 6, bias: 1.4, blurKernelSize: 15, resolutionScale: 1 } },
|
||||
outline: { name: 'on', params: { scale: 1, threshold: 0.33, color: Color(0x000000) } }
|
||||
outline: { name: 'on', params: { scale: 1, threshold: 0.33, color: Color(0x000000), includeTransparent: true, } },
|
||||
shadow: { name: 'off', params: {} },
|
||||
},
|
||||
renderer: {
|
||||
ambientIntensity: 1.0,
|
||||
@@ -37,7 +38,8 @@ const Canvas3DPresets = {
|
||||
canvas3d: <Preset>{
|
||||
postprocessing: {
|
||||
occlusion: { name: 'on', params: { samples: 32, radius: 6, bias: 1.4, blurKernelSize: 15, resolutionScale: 1 } },
|
||||
outline: { name: 'off', params: {} }
|
||||
outline: { name: 'off', params: {} },
|
||||
shadow: { name: 'off', params: {} },
|
||||
},
|
||||
renderer: {
|
||||
ambientIntensity: 0.4,
|
||||
@@ -50,7 +52,8 @@ const Canvas3DPresets = {
|
||||
canvas3d: <Preset>{
|
||||
postprocessing: {
|
||||
occlusion: { name: 'off', params: {} },
|
||||
outline: { name: 'off', params: {} }
|
||||
outline: { name: 'off', params: {} },
|
||||
shadow: { name: 'off', params: {} },
|
||||
},
|
||||
renderer: {
|
||||
ambientIntensity: 0.4,
|
||||
|
||||
@@ -52,7 +52,7 @@ export interface Compartment {
|
||||
}
|
||||
|
||||
// Primitives discribing a compartment
|
||||
export const enum CompartmentPrimitiveType {
|
||||
export enum CompartmentPrimitiveType {
|
||||
MetaBall = 0,
|
||||
Sphere = 1,
|
||||
Cube = 2,
|
||||
|
||||
@@ -585,7 +585,7 @@ export const LoadCellPackModel = StateAction.build({
|
||||
... ctx.managers.structure.component.state.options,
|
||||
visualQuality: 'custom',
|
||||
ignoreLight: true,
|
||||
showHydrogens: false,
|
||||
hydrogens: 'hide-all',
|
||||
});
|
||||
ctx.canvas3d?.setProps({
|
||||
multiSample: { mode: 'off' },
|
||||
@@ -606,12 +606,22 @@ export const LoadCellPackModel = StateAction.build({
|
||||
resolutionScale: 1,
|
||||
}
|
||||
},
|
||||
shadow: {
|
||||
name: 'on',
|
||||
params: {
|
||||
bias: 0.6,
|
||||
maxDistance: 80,
|
||||
steps: 3,
|
||||
tolerance: 1.0,
|
||||
}
|
||||
},
|
||||
outline: {
|
||||
name: 'on',
|
||||
params: {
|
||||
scale: 1,
|
||||
threshold: 0.33,
|
||||
color: ColorNames.black,
|
||||
includeTransparent: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
187
src/extensions/meshes/examples.ts
Normal file
187
src/extensions/meshes/examples.ts
Normal file
@@ -0,0 +1,187 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
/** Testing examples for using mesh-extension.ts. */
|
||||
|
||||
import { CIF } from '../../mol-io/reader/cif';
|
||||
import { Volume } from '../../mol-model/volume';
|
||||
import { createStructureRepresentationParams } from '../../mol-plugin-state/helpers/structure-representation-params';
|
||||
import { createVolumeRepresentationParams } from '../../mol-plugin-state/helpers/volume-representation-params';
|
||||
import { PluginStateObject } from '../../mol-plugin-state/objects';
|
||||
import { StateTransforms } from '../../mol-plugin-state/transforms';
|
||||
import { PluginContext } from '../../mol-plugin/context';
|
||||
import { StateObjectSelector } from '../../mol-state';
|
||||
import { Asset } from '../../mol-util/assets';
|
||||
import { Color } from '../../mol-util/color';
|
||||
import { ParamDefinition } from '../../mol-util/param-definition';
|
||||
|
||||
import { createMeshFromUrl } from './mesh-extension';
|
||||
import { MeshServerInfo } from './mesh-streaming/server-info';
|
||||
import { InitMeshStreaming } from './mesh-streaming/transformers';
|
||||
import * as MeshUtils from './mesh-utils';
|
||||
|
||||
|
||||
export const DB_URL = '/db'; // local
|
||||
|
||||
|
||||
export async function runMeshExtensionExamples(plugin: PluginContext, db_url: string = DB_URL) {
|
||||
console.time('TIME MESH EXAMPLES');
|
||||
// await runIsosurfaceExample(plugin, db_url);
|
||||
// await runMolsurfaceExample(plugin);
|
||||
|
||||
// Focused Ion Beam-Scanning Electron Microscopy of mitochondrial reticulum in murine skeletal muscle: https://www.ebi.ac.uk/empiar/EMPIAR-10070/
|
||||
// await runMeshExample(plugin, 'all', db_url);
|
||||
// await runMeshExample(plugin, 'fg', db_url);
|
||||
// await runMultimeshExample(plugin, 'fg', 'worst', db_url);
|
||||
// await runCifMeshExample(plugin);
|
||||
// await runMeshExample2(plugin, 'fg');
|
||||
await runMeshStreamingExample(plugin);
|
||||
|
||||
console.timeEnd('TIME MESH EXAMPLES');
|
||||
}
|
||||
|
||||
/** Example for downloading multiple separate segments, each containing 1 mesh. */
|
||||
export async function runMeshExample(plugin: PluginContext, segments: 'fg' | 'all', db_url: string = DB_URL) {
|
||||
const detail = 2;
|
||||
const segmentIds = (segments === 'all') ?
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17] // segment-16 has no detail-2
|
||||
: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 17]; // segment-13 and segment-15 are quasi background
|
||||
|
||||
for (const segmentId of segmentIds) {
|
||||
await createMeshFromUrl(plugin, `${db_url}/empiar-10070-mesh-rounded/segment-${segmentId}/detail-${detail}`, segmentId, detail, true, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
/** Example for downloading multiple separate segments, each containing 1 mesh. */
|
||||
export async function runMeshExample2(plugin: PluginContext, segments: 'one' | 'few' | 'fg' | 'all') {
|
||||
const detail = 1;
|
||||
const segmentIds = (segments === 'one') ? [15]
|
||||
: (segments === 'few') ? [1, 4, 7, 10, 16]
|
||||
: (segments === 'all') ? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17] // segment-16 has no detail-2
|
||||
: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 17]; // segment-13 and segment-15 are quasi background
|
||||
|
||||
for (const segmentId of segmentIds) {
|
||||
await createMeshFromUrl(plugin, `http://localhost:9000/v2/empiar/empiar-10070/mesh_bcif/${segmentId}/${detail}`, segmentId, detail, false, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
/** Example for downloading a single segment containing multiple meshes. */
|
||||
export async function runMultimeshExample(plugin: PluginContext, segments: 'fg' | 'all', detailChoice: 'best' | 'worst', db_url: string = DB_URL) {
|
||||
const urlDetail = (detailChoice === 'best') ? '2' : 'worst';
|
||||
const numDetail = (detailChoice === 'best') ? 2 : 1000;
|
||||
await createMeshFromUrl(plugin, `${db_url}/empiar-10070-multimesh-rounded/segments-${segments}/detail-${urlDetail}`, 0, numDetail, false, undefined);
|
||||
}
|
||||
|
||||
export async function runMeshStreamingExample(plugin: PluginContext, source: MeshServerInfo.MeshSource = 'empiar', entryId: string = 'empiar-10070', serverUrl?: string, parent?: StateObjectSelector) {
|
||||
const params = ParamDefinition.getDefaultValues(MeshServerInfo.Params);
|
||||
if (serverUrl) params.serverUrl = serverUrl;
|
||||
params.source = source;
|
||||
params.entryId = entryId;
|
||||
await plugin.runTask(plugin.state.data.applyAction(InitMeshStreaming, params, parent?.ref), { useOverlay: false });
|
||||
}
|
||||
|
||||
/** Example for downloading a protein structure and visualizing molecular surface. */
|
||||
export async function runMolsurfaceExample(plugin: PluginContext) {
|
||||
const entryId = 'pdb-7etq';
|
||||
|
||||
// Node "https://www.ebi.ac.uk/pdbe/entry-files/download/7etq.bcif" ("transformer": "ms-plugin.download") -> var data
|
||||
const data = await plugin.builders.data.download({ url: 'https://www.ebi.ac.uk/pdbe/entry-files/download/7etq.bcif', isBinary: true }, { state: { isGhost: false } });
|
||||
console.log('formats:', plugin.dataFormats.list);
|
||||
|
||||
// Node "CIF File" ("transformer": "ms-plugin.parse-cif")
|
||||
// Node "7ETQ 1 model" ("transformer": "ms-plugin.trajectory-from-mmcif") -> var trajectory
|
||||
const parsed = await plugin.dataFormats.get('mmcif')!.parse(plugin, data, { entryId });
|
||||
const trajectory: StateObjectSelector<PluginStateObject.Molecule.Trajectory> = parsed.trajectory;
|
||||
console.log('parsed', parsed);
|
||||
console.log('trajectory', trajectory);
|
||||
|
||||
// Node "Model 1" ("transformer": "ms-plugin.model-from-trajectory") -> var model
|
||||
const model = await plugin.build().to(trajectory).apply(StateTransforms.Model.ModelFromTrajectory).commit();
|
||||
console.log('model:', model);
|
||||
|
||||
// Node "Model 91 elements" ("transformer": "ms-plugin.structure-from-model") -> var structure
|
||||
const structure = await plugin.build().to(model).apply(StateTransforms.Model.StructureFromModel,).commit();
|
||||
console.log('structure:', structure);
|
||||
|
||||
// Node "Molecular Surface" ("transformer": "ms-plugin.structure-representation-3d") -> var repr
|
||||
const reprParams = createStructureRepresentationParams(plugin, undefined, { type: 'molecular-surface' });
|
||||
const repr = await plugin.build().to(structure).apply(StateTransforms.Representation.StructureRepresentation3D, reprParams).commit();
|
||||
console.log('repr:', repr);
|
||||
}
|
||||
|
||||
/** Example for downloading an EMDB density data and visualizing isosurface. */
|
||||
export async function runIsosurfaceExample(plugin: PluginContext, db_url: string = DB_URL) {
|
||||
const entryId = 'emd-1832';
|
||||
const isoLevel = 2.73;
|
||||
|
||||
let root = await plugin.build();
|
||||
const data = await plugin.builders.data.download({ url: `${db_url}/emd-1832-box`, isBinary: true }, { state: { isGhost: false } });
|
||||
const parsed = await plugin.dataFormats.get('dscif')!.parse(plugin, data, { entryId });
|
||||
|
||||
const volume: StateObjectSelector<PluginStateObject.Volume.Data> = parsed.volumes?.[0] ?? parsed.volume;
|
||||
const volumeData = volume.cell!.obj!.data;
|
||||
console.log('data:', data);
|
||||
console.log('parsed:', parsed);
|
||||
console.log('volume:', volume);
|
||||
console.log('volumeData:', volumeData);
|
||||
|
||||
root = await plugin.build();
|
||||
console.log('root:', root);
|
||||
console.log('to:', root.to(volume));
|
||||
console.log('toRoot:', root.toRoot());
|
||||
|
||||
let volumeParams;
|
||||
volumeParams = createVolumeRepresentationParams(plugin, volumeData, {
|
||||
type: 'isosurface',
|
||||
typeParams: {
|
||||
alpha: 0.5,
|
||||
isoValue: Volume.adjustedIsoValue(volumeData, isoLevel, 'relative'),
|
||||
visuals: ['solid'],
|
||||
sizeFactor: 1,
|
||||
},
|
||||
color: 'uniform',
|
||||
colorParams: { value: Color(0x00aaaa) },
|
||||
|
||||
});
|
||||
root.to(volume).apply(StateTransforms.Representation.VolumeRepresentation3D, volumeParams);
|
||||
|
||||
volumeParams = createVolumeRepresentationParams(plugin, volumeData, {
|
||||
type: 'isosurface',
|
||||
typeParams: {
|
||||
alpha: 1.0,
|
||||
isoValue: Volume.adjustedIsoValue(volumeData, isoLevel, 'relative'),
|
||||
visuals: ['wireframe'],
|
||||
sizeFactor: 1,
|
||||
},
|
||||
color: 'uniform',
|
||||
colorParams: { value: Color(0x8800aa) },
|
||||
|
||||
});
|
||||
root.to(volume).apply(StateTransforms.Representation.VolumeRepresentation3D, volumeParams);
|
||||
await root.commit();
|
||||
}
|
||||
|
||||
|
||||
export async function runCifMeshExample(plugin: PluginContext, api: string = 'http://localhost:9000/v2',
|
||||
source: MeshServerInfo.MeshSource = 'empiar', entryId: string = 'empiar-10070',
|
||||
segmentId: number = 1, detail: number = 10,
|
||||
) {
|
||||
const url = `${api}/${source}/${entryId}/mesh_bcif/${segmentId}/${detail}`;
|
||||
getMeshFromBcif(plugin, url);
|
||||
}
|
||||
|
||||
async function getMeshFromBcif(plugin: PluginContext, url: string) {
|
||||
const urlAsset = Asset.getUrlAsset(plugin.managers.asset, url);
|
||||
const asset = await plugin.runTask(plugin.managers.asset.resolve(urlAsset, 'binary'));
|
||||
const parsed = await plugin.runTask(CIF.parseBinary(asset.data));
|
||||
if (parsed.isError) {
|
||||
plugin.log.error('VolumeStreaming, parsing CIF: ' + parsed.toString());
|
||||
return;
|
||||
}
|
||||
console.log('blocks:', parsed.result.blocks);
|
||||
const mesh = await MeshUtils.meshFromCif(parsed.result);
|
||||
console.log(mesh);
|
||||
}
|
||||
40
src/extensions/meshes/mesh-cif-schema.ts
Normal file
40
src/extensions/meshes/mesh-cif-schema.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { Column, Database } from '../../mol-data/db';
|
||||
import { CifFrame } from '../../mol-io/reader/cif';
|
||||
import { toDatabase } from '../../mol-io/reader/cif/schema';
|
||||
|
||||
|
||||
const int = Column.Schema.int;
|
||||
const float = Column.Schema.float;
|
||||
|
||||
|
||||
// TODO in future, move to molstar/src/mol-io/reader/cif/schema/mesh.ts
|
||||
export const Mesh_Data_Schema = {
|
||||
mesh: {
|
||||
id: int,
|
||||
},
|
||||
mesh_vertex: {
|
||||
mesh_id: int,
|
||||
vertex_id: int,
|
||||
x: float,
|
||||
y: float,
|
||||
z: float,
|
||||
},
|
||||
/** Table of triangles, 3 rows per triangle */
|
||||
mesh_triangle: {
|
||||
mesh_id: int,
|
||||
/** Indices of vertices within mesh */
|
||||
vertex_id: int,
|
||||
}
|
||||
};
|
||||
export type Mesh_Data_Schema = typeof Mesh_Data_Schema;
|
||||
export interface Mesh_Data_Database extends Database<Mesh_Data_Schema> {}
|
||||
|
||||
|
||||
// TODO in future, move to molstar/src/mol-io/reader/cif.ts: CIF.schema.mesh
|
||||
export const CIF_schema_mesh = (frame: CifFrame) => toDatabase<Mesh_Data_Schema, Mesh_Data_Database>(Mesh_Data_Schema, frame);
|
||||
223
src/extensions/meshes/mesh-extension.ts
Normal file
223
src/extensions/meshes/mesh-extension.ts
Normal file
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
/** Defines new types of State tree transformers for dealing with mesh data. */
|
||||
|
||||
|
||||
import { BaseGeometry, VisualQuality, VisualQualityOptions } from '../../mol-geo/geometry/base';
|
||||
import { Mesh } from '../../mol-geo/geometry/mesh/mesh';
|
||||
import { CifFile } from '../../mol-io/reader/cif';
|
||||
import { Box3D } from '../../mol-math/geometry';
|
||||
import { Vec3 } from '../../mol-math/linear-algebra';
|
||||
import { Shape } from '../../mol-model/shape';
|
||||
import { ShapeProvider } from '../../mol-model/shape/provider';
|
||||
import { PluginStateObject } from '../../mol-plugin-state/objects';
|
||||
import { StateTransforms } from '../../mol-plugin-state/transforms';
|
||||
import { Download } from '../../mol-plugin-state/transforms/data';
|
||||
import { ShapeRepresentation3D } from '../../mol-plugin-state/transforms/representation';
|
||||
import { PluginContext } from '../../mol-plugin/context';
|
||||
import { StateObjectRef, StateObjectSelector, StateTransformer } from '../../mol-state';
|
||||
import { Task } from '../../mol-task';
|
||||
import { Color } from '../../mol-util/color';
|
||||
import { ParamDefinition as PD } from '../../mol-util/param-definition';
|
||||
import * as MeshUtils from './mesh-utils';
|
||||
|
||||
|
||||
export const BACKGROUND_OPACITY = 0.2;
|
||||
export const FOREROUND_OPACITY = 1;
|
||||
|
||||
export const VolsegTransform: StateTransformer.Builder.Root = StateTransformer.builderFactory('volseg');
|
||||
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // //
|
||||
// Parsed data
|
||||
|
||||
/** Data type for `MeshlistStateObject` - list of meshes */
|
||||
export interface MeshlistData {
|
||||
segmentId: number,
|
||||
segmentName: string,
|
||||
detail: number,
|
||||
meshIds: number[],
|
||||
mesh: Mesh,
|
||||
/** Reference to the object which created this meshlist (e.g. `MeshStreaming.Behavior`) */
|
||||
ownerId?: string,
|
||||
}
|
||||
|
||||
export namespace MeshlistData {
|
||||
export function empty(): MeshlistData {
|
||||
return {
|
||||
segmentId: 0,
|
||||
segmentName: 'Empty',
|
||||
detail: 0,
|
||||
meshIds: [],
|
||||
mesh: Mesh.createEmpty(),
|
||||
};
|
||||
};
|
||||
export async function fromCIF(data: CifFile, segmentId: number, segmentName: string, detail: number): Promise<MeshlistData> {
|
||||
const { mesh, meshIds } = await MeshUtils.meshFromCif(data);
|
||||
return {
|
||||
segmentId,
|
||||
segmentName,
|
||||
detail,
|
||||
meshIds,
|
||||
mesh,
|
||||
};
|
||||
}
|
||||
export function stats(meshListData: MeshlistData): string {
|
||||
return `Meshlist "${meshListData.segmentName}" (detail ${meshListData.detail}): ${meshListData.meshIds.length} meshes, ${meshListData.mesh.vertexCount} vertices, ${meshListData.mesh.triangleCount} triangles`;
|
||||
}
|
||||
export function getShape(data: MeshlistData, color: Color): Shape<Mesh> {
|
||||
const mesh = data.mesh;
|
||||
const meshShape: Shape<Mesh> = Shape.create(data.segmentName, data, mesh,
|
||||
() => color,
|
||||
() => 1,
|
||||
// group => `${data.segmentName} | Segment ${data.segmentId} | Detail ${data.detail} | Mesh ${group}`,
|
||||
group => data.segmentName,
|
||||
);
|
||||
return meshShape;
|
||||
}
|
||||
|
||||
export function combineBBoxes(boxes: (Box3D | null)[]): Box3D | null {
|
||||
let result = null;
|
||||
for (const box of boxes) {
|
||||
if (!box) continue;
|
||||
if (result) {
|
||||
Vec3.min(result.min, result.min, box.min);
|
||||
Vec3.max(result.max, result.max, box.max);
|
||||
} else {
|
||||
result = Box3D.zero();
|
||||
Box3D.copy(result, box);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export function bbox(data: MeshlistData): Box3D | null {
|
||||
return MeshUtils.bbox(data.mesh);
|
||||
}
|
||||
|
||||
export function allVerticesUsed(data: MeshlistData): boolean {
|
||||
const unusedVertices = new Set();
|
||||
for (let i = 0; i < data.mesh.vertexCount; i++) {
|
||||
unusedVertices.add(i);
|
||||
}
|
||||
for (let i = 0; i < 3 * data.mesh.triangleCount; i++) {
|
||||
const v = data.mesh.vertexBuffer.ref.value[i];
|
||||
unusedVertices.delete(v);
|
||||
}
|
||||
return unusedVertices.size === 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // //
|
||||
// Raw Data -> Parsed data
|
||||
|
||||
export class MeshlistStateObject extends PluginStateObject.Create<MeshlistData>({ name: 'Parsed Meshlist', typeClass: 'Object' }) { }
|
||||
|
||||
export const ParseMeshlistTransformer = VolsegTransform({
|
||||
name: 'meshlist-from-string',
|
||||
from: PluginStateObject.Format.Cif,
|
||||
to: MeshlistStateObject,
|
||||
params: {
|
||||
label: PD.Text(MeshlistStateObject.type.name, { isHidden: true }),
|
||||
segmentId: PD.Numeric(1, {}, { isHidden: true }),
|
||||
segmentName: PD.Text('Segment'),
|
||||
detail: PD.Numeric(1, {}, { isHidden: true }),
|
||||
/** Reference to the object which manages this meshlist (e.g. `MeshStreaming.Behavior`) */
|
||||
ownerId: PD.Text('', { isHidden: true }),
|
||||
}
|
||||
})({
|
||||
apply({ a, params }, globalCtx) { // `a` is the parent node, params are 2nd argument to To.apply(), `globalCtx` is the plugin
|
||||
return Task.create('Create Parsed Meshlist', async ctx => {
|
||||
const meshlistData = await MeshlistData.fromCIF(a.data, params.segmentId, params.segmentName, params.detail);
|
||||
meshlistData.ownerId = params.ownerId;
|
||||
const es = meshlistData.meshIds.length === 1 ? '' : 'es';
|
||||
return new MeshlistStateObject(meshlistData, { label: params.label, description: `${meshlistData.segmentName} (${meshlistData.meshIds.length} mesh${es})` });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // //
|
||||
// Parsed data -> Shape
|
||||
|
||||
/** Data type for PluginStateObject.Shape.Provider */
|
||||
type MeshShapeProvider = ShapeProvider<MeshlistData, Mesh, Mesh.Params>;
|
||||
namespace MeshShapeProvider {
|
||||
export function fromMeshlistData(meshlist: MeshlistData, color?: Color): MeshShapeProvider {
|
||||
const theColor = color ?? MeshUtils.ColorGenerator.next().value;
|
||||
return {
|
||||
label: 'Mesh',
|
||||
data: meshlist,
|
||||
params: meshShapeProviderParams,
|
||||
geometryUtils: Mesh.Utils,
|
||||
getShape: (ctx, data: MeshlistData) => MeshlistData.getShape(data, theColor),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const meshShapeProviderParams: Mesh.Params = {
|
||||
...Mesh.Params,
|
||||
quality: PD.Select<VisualQuality>('custom', VisualQualityOptions, { isEssential: true, description: 'Visual/rendering quality of the representation.' }), // use 'custom' when wanting to apply doubleSided
|
||||
doubleSided: PD.Boolean(true, BaseGeometry.CustomQualityParamInfo),
|
||||
// set `flatShaded`: true to see the real mesh vertices and triangles
|
||||
transparentBackfaces: PD.Select('on', PD.arrayToOptions(['off', 'on', 'opaque']), BaseGeometry.ShadingCategory), // 'on' means: show backfaces with correct opacity, even when opacity < 1 (requires doubleSided) ¯\_(ツ)_/¯
|
||||
};
|
||||
|
||||
|
||||
export const MeshShapeTransformer = VolsegTransform({
|
||||
name: 'shape-from-meshlist',
|
||||
display: { name: 'Shape from Meshlist', description: 'Create Shape from Meshlist data' },
|
||||
from: MeshlistStateObject,
|
||||
to: PluginStateObject.Shape.Provider,
|
||||
params: {
|
||||
color: PD.Value<Color | undefined>(undefined), // undefined means random color
|
||||
},
|
||||
})({
|
||||
apply({ a, params }) {
|
||||
const shapeProvider = MeshShapeProvider.fromMeshlistData(a.data, params.color);
|
||||
return new PluginStateObject.Shape.Provider(shapeProvider, { label: PluginStateObject.Shape.Provider.type.name, description: a.description });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
|
||||
/** Download data and create state tree hierarchy down to visual representation. */
|
||||
export async function createMeshFromUrl(plugin: PluginContext, meshDataUrl: string, segmentId: number, detail: number,
|
||||
collapseTree: boolean, color?: Color, parent?: StateObjectSelector | StateObjectRef, transparentIfBboxAbove?: number,
|
||||
name?: string, ownerId?: string) {
|
||||
|
||||
const update = parent ? plugin.build().to(parent) : plugin.build().toRoot();
|
||||
const rawDataNodeRef = update.apply(Download,
|
||||
{ url: meshDataUrl, isBinary: true, label: `Downloaded Data ${segmentId}` },
|
||||
{ state: { isCollapsed: collapseTree } }
|
||||
).ref;
|
||||
const parsedDataNode = await update.to(rawDataNodeRef)
|
||||
.apply(StateTransforms.Data.ParseCif)
|
||||
.apply(ParseMeshlistTransformer,
|
||||
{ label: undefined, segmentId: segmentId, segmentName: name ?? `Segment ${segmentId}`, detail: detail, ownerId: ownerId },
|
||||
{}
|
||||
)
|
||||
.commit();
|
||||
|
||||
let transparent = false;
|
||||
if (transparentIfBboxAbove !== undefined && parsedDataNode.data) {
|
||||
const bbox = MeshlistData.bbox(parsedDataNode.data) || Box3D.zero();
|
||||
transparent = Box3D.volume(bbox) > transparentIfBboxAbove;
|
||||
}
|
||||
|
||||
await plugin.build().to(parsedDataNode)
|
||||
.apply(MeshShapeTransformer, { color: color },)
|
||||
.apply(ShapeRepresentation3D,
|
||||
{ alpha: transparent ? BACKGROUND_OPACITY : FOREROUND_OPACITY },
|
||||
{ tags: ['mesh-segment-visual', `segment-${segmentId}`] }
|
||||
)
|
||||
.commit();
|
||||
|
||||
return rawDataNodeRef;
|
||||
}
|
||||
332
src/extensions/meshes/mesh-streaming/behavior.ts
Normal file
332
src/extensions/meshes/mesh-streaming/behavior.ts
Normal file
@@ -0,0 +1,332 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { distinctUntilChanged, map } from 'rxjs';
|
||||
|
||||
import { CIF } from '../../../mol-io/reader/cif';
|
||||
import { Box3D } from '../../../mol-math/geometry';
|
||||
import { PluginStateObject } from '../../../mol-plugin-state/objects';
|
||||
import { PluginBehavior } from '../../../mol-plugin/behavior';
|
||||
import { PluginCommand } from '../../../mol-plugin/command';
|
||||
import { PluginCommands } from '../../../mol-plugin/commands';
|
||||
import { PluginContext } from '../../../mol-plugin/context';
|
||||
import { UUID } from '../../../mol-util';
|
||||
import { Asset } from '../../../mol-util/assets';
|
||||
import { Color } from '../../../mol-util/color';
|
||||
import { ColorNames } from '../../../mol-util/color/names';
|
||||
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
|
||||
|
||||
import { Choice } from '../../volumes-and-segmentations/helpers';
|
||||
import { MetadataWrapper } from '../../volumes-and-segmentations/volseg-api/utils';
|
||||
|
||||
import { MeshlistData } from '../mesh-extension';
|
||||
import { MeshServerInfo } from './server-info';
|
||||
|
||||
|
||||
const DEFAULT_SEGMENT_NAME = 'Untitled segment';
|
||||
const DEFAULT_SEGMENT_COLOR = ColorNames.lightgray;
|
||||
export const NO_SEGMENT = -1;
|
||||
/** Maximum (worst) detail level available in GUI (TODO set actual maximum possible value) */
|
||||
const MAX_DETAIL = 10;
|
||||
const DEFAULT_DETAIL = 7; // TODO decide a reasonable default
|
||||
/** Segments whose bounding box volume is above this value (relative to the overall bounding box) are considered as background segments */
|
||||
export const BACKGROUND_SEGMENT_VOLUME_THRESHOLD = 0.5;
|
||||
|
||||
|
||||
export class MeshStreaming extends PluginStateObject.CreateBehavior<MeshStreaming.Behavior>({ name: 'Mesh Streaming' }) { }
|
||||
|
||||
export namespace MeshStreaming {
|
||||
|
||||
export namespace Params {
|
||||
export const ViewTypeChoice = new Choice({ off: 'Off', select: 'Select', all: 'All' }, 'select'); // TODO add camera target?
|
||||
export type ViewType = Choice.Values<typeof ViewTypeChoice>;
|
||||
|
||||
export function create(options: MeshServerInfo.Data) {
|
||||
return {
|
||||
view: PD.MappedStatic('select', {
|
||||
'off': PD.Group({}),
|
||||
'select': PD.Group({
|
||||
baseDetail: PD.Numeric(DEFAULT_DETAIL, { min: 1, max: MAX_DETAIL, step: 1 }, { description: 'Detail level for the non-selected segments (lower number = better)' }),
|
||||
focusDetail: PD.Numeric(1, { min: 1, max: MAX_DETAIL, step: 1 }, { description: 'Detail level for the selected segment (lower number = better)' }),
|
||||
selectedSegment: PD.Numeric(NO_SEGMENT, {}, { isHidden: true }),
|
||||
}, { isFlat: true }),
|
||||
'all': PD.Group({
|
||||
detail: PD.Numeric(DEFAULT_DETAIL, { min: 1, max: MAX_DETAIL, step: 1 }, { description: 'Detail level for all segments (lower number = better)' })
|
||||
}, { isFlat: true }),
|
||||
}, { description: '"Off" hides all segments. \n"Select" shows all segments in lower detail, clicked segment in better detail. "All" shows all segment in the same level.' }),
|
||||
};
|
||||
}
|
||||
|
||||
export type Definition = ReturnType<typeof create>
|
||||
export type Values = PD.Values<Definition>
|
||||
|
||||
export function copyValues(params: Values): Values {
|
||||
return {
|
||||
view: {
|
||||
name: params.view.name,
|
||||
params: { ...params.view.params } as any,
|
||||
}
|
||||
};
|
||||
}
|
||||
export function valuesEqual(p: Values, q: Values): boolean {
|
||||
if (p.view.name !== q.view.name) return false;
|
||||
for (const key in p.view.params) {
|
||||
if ((p.view.params as any)[key] !== (q.view.params as any)[key]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
export function detailsEqual(p: Values, q: Values): boolean {
|
||||
switch (p.view.name) {
|
||||
case 'off':
|
||||
return q.view.name === 'off';
|
||||
case 'select':
|
||||
return q.view.name === 'select' && p.view.params.baseDetail === q.view.params.baseDetail && p.view.params.focusDetail === q.view.params.focusDetail;
|
||||
case 'all':
|
||||
return q.view.name === 'all' && p.view.params.detail === q.view.params.detail;
|
||||
default:
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface VisualInfo {
|
||||
tag: string, // e.g. high-2, low-1 // ? remove if can be omitted
|
||||
segmentId: number, // ? remove if unused
|
||||
segmentName: string, // ? remove if unused
|
||||
detailType: VisualInfo.DetailType, // ? remove if unused
|
||||
detail: number, // ? remove if unused
|
||||
color: Color, // move to MeshlistData?
|
||||
visible: boolean,
|
||||
data?: MeshlistData,
|
||||
}
|
||||
export namespace VisualInfo {
|
||||
export type DetailType = 'low' | 'high';
|
||||
export const DetailTypes: DetailType[] = ['low', 'high'];
|
||||
export function tagFor(segmentId: number, detail: DetailType) {
|
||||
return `${detail}-${segmentId}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class Behavior extends PluginBehavior.WithSubscribers<Params.Values> {
|
||||
private id: string;
|
||||
private ref: string = '';
|
||||
public parentData: MeshServerInfo.Data;
|
||||
private metadata?: MetadataWrapper;
|
||||
public visuals?: { [tag: string]: VisualInfo };
|
||||
public backgroundSegments: { [segmentId: number]: boolean } = {};
|
||||
private focusObservable = this.plugin.behaviors.interaction.click.pipe( // QUESTION is this OK way to get focused segment?
|
||||
map(evt => evt.current.loci),
|
||||
map(loci => (loci.kind === 'group-loci') ? loci.shape.sourceData as MeshlistData : null),
|
||||
map(data => (data?.ownerId === this.id) ? data : null), // do not process shapes created by others
|
||||
distinctUntilChanged((old, current) => old?.segmentId === current?.segmentId),
|
||||
);
|
||||
private focusSubscription?: PluginCommand.Subscription = undefined;
|
||||
private backgroundSegmentsInitialized = false;
|
||||
|
||||
constructor(plugin: PluginContext, data: MeshServerInfo.Data, params: Params.Values) {
|
||||
super(plugin, params);
|
||||
this.id = UUID.create22();
|
||||
this.parentData = data;
|
||||
}
|
||||
|
||||
register(ref: string): void {
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
unregister(): void {
|
||||
if (this.focusSubscription) {
|
||||
this.focusSubscription.unsubscribe();
|
||||
this.focusSubscription = undefined;
|
||||
}
|
||||
// TODO empty cache here (if used)
|
||||
}
|
||||
|
||||
selectSegment(segmentId: number) {
|
||||
if (this.params.view.name === 'select') {
|
||||
if (this.params.view.params.selectedSegment === segmentId) return;
|
||||
const newParams = Params.copyValues(this.params);
|
||||
if (newParams.view.name === 'select') {
|
||||
newParams.view.params.selectedSegment = segmentId;
|
||||
}
|
||||
const state = this.plugin.state.data;
|
||||
const update = state.build().to(this.ref).update(newParams);
|
||||
PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotUpdateCurrent: true } });
|
||||
}
|
||||
}
|
||||
|
||||
async update(params: Params.Values) {
|
||||
const oldParams = this.params;
|
||||
this.params = params;
|
||||
|
||||
if (!this.metadata) {
|
||||
const response = await fetch(this.getMetadataUrl());
|
||||
const rawMetadata = await response.json();
|
||||
this.metadata = new MetadataWrapper(rawMetadata);
|
||||
}
|
||||
|
||||
if (!this.visuals) {
|
||||
this.initVisualInfos();
|
||||
} else if (!Params.detailsEqual(this.params, oldParams)) {
|
||||
this.updateVisualInfoDetails();
|
||||
}
|
||||
|
||||
switch (params.view.name) {
|
||||
case 'off':
|
||||
await this.disableVisuals();
|
||||
break;
|
||||
case 'select':
|
||||
await this.enableVisuals(params.view.params.selectedSegment);
|
||||
break;
|
||||
case 'all':
|
||||
await this.enableVisuals();
|
||||
break;
|
||||
default:
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
if (params.view.name !== 'off' && !this.backgroundSegmentsInitialized) {
|
||||
this.guessBackgroundSegments();
|
||||
this.backgroundSegmentsInitialized = true;
|
||||
}
|
||||
if (params.view.name === 'select' && !this.focusSubscription) {
|
||||
this.focusSubscription = this.subscribeObservable(this.focusObservable, data => { this.selectSegment(data?.segmentId ?? NO_SEGMENT); });
|
||||
} else if (params.view.name !== 'select' && this.focusSubscription) {
|
||||
this.focusSubscription.unsubscribe();
|
||||
this.focusSubscription = undefined;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private getMetadataUrl() {
|
||||
return `${this.parentData.serverUrl}/${this.parentData.source}/${this.parentData.entryId}/metadata`;
|
||||
}
|
||||
|
||||
private getMeshUrl(segment: number, detail: number) {
|
||||
return `${this.parentData.serverUrl}/${this.parentData.source}/${this.parentData.entryId}/mesh_bcif/${segment}/${detail}`;
|
||||
}
|
||||
|
||||
private initVisualInfos() {
|
||||
const visuals: { [tag: string]: VisualInfo } = {};
|
||||
for (const segid of this.metadata!.meshSegmentIds) {
|
||||
const name = this.metadata?.getSegment(segid)?.biological_annotation.name ?? DEFAULT_SEGMENT_NAME;
|
||||
const color = this.metadata?.getSegmentColor(segid) ?? DEFAULT_SEGMENT_COLOR;
|
||||
for (const detailType of VisualInfo.DetailTypes) {
|
||||
const visual: VisualInfo = {
|
||||
tag: VisualInfo.tagFor(segid, detailType),
|
||||
segmentId: segid,
|
||||
segmentName: name,
|
||||
detailType: detailType,
|
||||
detail: -1, // to be set at the end
|
||||
color: color,
|
||||
visible: false,
|
||||
data: undefined,
|
||||
};
|
||||
visuals[visual.tag] = visual;
|
||||
}
|
||||
}
|
||||
this.visuals = visuals;
|
||||
this.updateVisualInfoDetails();
|
||||
}
|
||||
private updateVisualInfoDetails() {
|
||||
let highDetail: number | undefined;
|
||||
let lowDetail: number | undefined;
|
||||
switch (this.params.view.name) {
|
||||
case 'off':
|
||||
lowDetail = undefined;
|
||||
highDetail = undefined;
|
||||
break;
|
||||
case 'select':
|
||||
lowDetail = this.params.view.params.baseDetail;
|
||||
highDetail = this.params.view.params.focusDetail;
|
||||
break;
|
||||
case 'all':
|
||||
lowDetail = this.params.view.params.detail;
|
||||
highDetail = undefined;
|
||||
break;
|
||||
}
|
||||
for (const tag in this.visuals) {
|
||||
const visual = this.visuals[tag];
|
||||
const preferredDetail = (visual.detailType === 'high') ? highDetail : lowDetail;
|
||||
if (preferredDetail !== undefined) {
|
||||
visual.detail = this.metadata!.getSufficientMeshDetail(visual.segmentId, preferredDetail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async enableVisuals(highDetailSegment?: number) {
|
||||
for (const tag in this.visuals) {
|
||||
const visual = this.visuals[tag];
|
||||
const requiredDetailType = visual.segmentId === highDetailSegment ? 'high' : 'low';
|
||||
if (visual.detailType === requiredDetailType) {
|
||||
visual.data = await this.getMeshData(visual);
|
||||
visual.visible = true;
|
||||
} else {
|
||||
visual.visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async disableVisuals() {
|
||||
for (const tag in this.visuals) {
|
||||
const visual = this.visuals[tag];
|
||||
visual.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Fetch data in current `visual.detail`, or return already fetched data (if available in the correct detail). */
|
||||
private async getMeshData(visual: VisualInfo): Promise<MeshlistData> {
|
||||
if (visual.data && visual.data.detail === visual.detail) {
|
||||
// Do not recreate
|
||||
return visual.data;
|
||||
}
|
||||
// TODO cache
|
||||
const url = this.getMeshUrl(visual.segmentId, visual.detail);
|
||||
const urlAsset = Asset.getUrlAsset(this.plugin.managers.asset, url);
|
||||
const asset = await this.plugin.runTask(this.plugin.managers.asset.resolve(urlAsset, 'binary'));
|
||||
const parsed = await this.plugin.runTask(CIF.parseBinary(asset.data));
|
||||
if (parsed.isError) {
|
||||
throw new Error(`Failed parsing CIF file from ${url}`);
|
||||
}
|
||||
const meshlistData = await MeshlistData.fromCIF(parsed.result, visual.segmentId, visual.segmentName, visual.detail);
|
||||
meshlistData.ownerId = this.id;
|
||||
// const bbox = MeshlistData.bbox(meshlistData);
|
||||
// const bboxVolume = bbox ? MS.Box3D.volume(bbox) : 0.0;
|
||||
// console.log(`BBox ${visual.segmentId}: ${Math.round(bboxVolume! / 1e6)} M`, bbox); // DEBUG
|
||||
return meshlistData;
|
||||
}
|
||||
|
||||
private async guessBackgroundSegments() {
|
||||
const bboxes: { [segid: number]: Box3D } = {};
|
||||
for (const tag in this.visuals) {
|
||||
const visual = this.visuals[tag];
|
||||
if (visual.detailType === 'low' && visual.data) {
|
||||
const bbox = MeshlistData.bbox(visual.data);
|
||||
if (bbox) {
|
||||
bboxes[visual.segmentId] = bbox;
|
||||
}
|
||||
}
|
||||
}
|
||||
const totalBbox = MeshlistData.combineBBoxes(Object.values(bboxes));
|
||||
const totalVolume = totalBbox ? Box3D.volume(totalBbox) : 0.0;
|
||||
// console.log(`BBox total: ${Math.round(totalVolume! / 1e6)} M`, totalBbox); // DEBUG
|
||||
|
||||
const isBgSegment: { [segid: number]: boolean } = {};
|
||||
for (const segid in bboxes) {
|
||||
const bbox = bboxes[segid];
|
||||
const bboxVolume = Box3D.volume(bbox);
|
||||
isBgSegment[segid] = (bboxVolume > totalVolume * BACKGROUND_SEGMENT_VOLUME_THRESHOLD);
|
||||
// console.log(`BBox ${segid}: ${Math.round(bboxVolume! / 1e6)} M, ${bboxVolume / totalVolume}`, bbox); // DEBUG
|
||||
}
|
||||
this.backgroundSegments = isBgSegment;
|
||||
}
|
||||
|
||||
getDescription() {
|
||||
return Params.ViewTypeChoice.prettyName(this.params.view.name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
28
src/extensions/meshes/mesh-streaming/server-info.ts
Normal file
28
src/extensions/meshes/mesh-streaming/server-info.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { PluginStateObject } from '../../../mol-plugin-state/objects';
|
||||
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
|
||||
|
||||
import { Choice } from '../../volumes-and-segmentations/helpers';
|
||||
|
||||
|
||||
export const DEFAULT_MESH_SERVER = 'http://localhost:9000/v2';
|
||||
|
||||
|
||||
export class MeshServerInfo extends PluginStateObject.Create<MeshServerInfo.Data>({ name: 'Volume Server', typeClass: 'Object' }) { }
|
||||
|
||||
export namespace MeshServerInfo {
|
||||
export const MeshSourceChoice = new Choice({ empiar: 'EMPIAR', emdb: 'EMDB' }, 'empiar');
|
||||
export type MeshSource = Choice.Values<typeof MeshSourceChoice>;
|
||||
|
||||
export const Params = {
|
||||
serverUrl: PD.Text(DEFAULT_MESH_SERVER),
|
||||
source: MeshSourceChoice.PDSelect(),
|
||||
entryId: PD.Text(''),
|
||||
};
|
||||
export type Data = PD.Values<typeof Params>;
|
||||
}
|
||||
214
src/extensions/meshes/mesh-streaming/transformers.ts
Normal file
214
src/extensions/meshes/mesh-streaming/transformers.ts
Normal file
@@ -0,0 +1,214 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { Mesh } from '../../../mol-geo/geometry/mesh/mesh';
|
||||
import { PluginStateObject } from '../../../mol-plugin-state/objects';
|
||||
import { PluginContext } from '../../../mol-plugin/context';
|
||||
import { ShapeRepresentation } from '../../../mol-repr/shape/representation';
|
||||
import { StateAction, StateTransformer } from '../../../mol-state';
|
||||
import { Task } from '../../../mol-task';
|
||||
import { shallowEqualObjects } from '../../../mol-util';
|
||||
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
|
||||
|
||||
import { BACKGROUND_OPACITY, FOREROUND_OPACITY, MeshlistData, VolsegTransform } from '../mesh-extension';
|
||||
import { MeshStreaming, NO_SEGMENT } from './behavior';
|
||||
import { MeshServerInfo } from './server-info';
|
||||
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
export const MeshServerTransformer = VolsegTransform({
|
||||
name: 'mesh-server-info',
|
||||
from: PluginStateObject.Root,
|
||||
to: MeshServerInfo,
|
||||
params: MeshServerInfo.Params,
|
||||
})({
|
||||
apply({ a, params }, plugin: PluginContext) { // `a` is the parent node, `params` are 2nd argument to To.apply()
|
||||
params.serverUrl = params.serverUrl.replace(/\/*$/, ''); // trim trailing slash
|
||||
const description: string = params.entryId;
|
||||
return new MeshServerInfo({ ...params }, { label: 'Mesh Server', description: description });
|
||||
}
|
||||
});
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
export const MeshStreamingTransformer = VolsegTransform({
|
||||
name: 'mesh-streaming-from-server-info',
|
||||
display: { name: 'Mesh Streaming' },
|
||||
from: MeshServerInfo,
|
||||
to: MeshStreaming,
|
||||
params: a => MeshStreaming.Params.create(a!.data),
|
||||
})({
|
||||
canAutoUpdate() { return true; },
|
||||
apply({ a, params }, plugin: PluginContext) {
|
||||
return Task.create('Mesh Streaming', async ctx => {
|
||||
const behavior = new MeshStreaming.Behavior(plugin, a.data, params);
|
||||
await behavior.update(params);
|
||||
return new MeshStreaming(behavior, { label: 'Mesh Streaming', description: behavior.getDescription() });
|
||||
});
|
||||
},
|
||||
update({ a, b, oldParams, newParams }) {
|
||||
return Task.create('Update Mesh Streaming', async ctx => {
|
||||
if (a.data.source !== b.data.parentData.source || a.data.entryId !== b.data.parentData.entryId) {
|
||||
return StateTransformer.UpdateResult.Recreate;
|
||||
}
|
||||
b.data.parentData = a.data;
|
||||
await b.data.update(newParams);
|
||||
b.description = b.data.getDescription();
|
||||
return StateTransformer.UpdateResult.Updated;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
interface MeshVisualGroupData {
|
||||
opacity: number,
|
||||
}
|
||||
|
||||
// export type MeshVisualGroupTransformer = typeof MeshVisualGroupTransformer;
|
||||
export const MeshVisualGroupTransformer = VolsegTransform({
|
||||
name: 'mesh-visual-group-from-streaming',
|
||||
display: { name: 'Mesh Visuals for a Segment' },
|
||||
from: MeshStreaming,
|
||||
to: PluginStateObject.Group,
|
||||
params: {
|
||||
/** Shown on the node in GUI */
|
||||
label: PD.Text('', { isHidden: true }),
|
||||
/** Shown on the node in GUI (gray letters) */
|
||||
description: PD.Text(''),
|
||||
segmentId: PD.Numeric(NO_SEGMENT, {}, { isHidden: true }),
|
||||
opacity: PD.Numeric(-1, { min: 0, max: 1, step: 0.01 }),
|
||||
}
|
||||
})({
|
||||
apply({ a, params }, plugin) {
|
||||
trySetAutoOpacity(params, a);
|
||||
return new PluginStateObject.Group({ opacity: params.opacity }, params);
|
||||
},
|
||||
update({ a, b, oldParams, newParams }, plugin) {
|
||||
if (shallowEqualObjects(oldParams, newParams)) {
|
||||
return StateTransformer.UpdateResult.Unchanged;
|
||||
}
|
||||
newParams.label ||= oldParams.label; // Protect against resetting params to invalid defaults
|
||||
if (newParams.segmentId === NO_SEGMENT) newParams.segmentId = oldParams.segmentId; // Protect against resetting params to invalid defaults
|
||||
trySetAutoOpacity(newParams, a);
|
||||
b.label = newParams.label;
|
||||
b.description = newParams.description;
|
||||
(b.data as MeshVisualGroupData).opacity = newParams.opacity;
|
||||
return StateTransformer.UpdateResult.Updated;
|
||||
},
|
||||
canAutoUpdate({ oldParams, newParams }, plugin) {
|
||||
return newParams.description === oldParams.description;
|
||||
},
|
||||
});
|
||||
|
||||
function trySetAutoOpacity(params: StateTransformer.Params<typeof MeshVisualGroupTransformer>, parent: MeshStreaming) {
|
||||
if (params.opacity === -1) {
|
||||
const isBgSegment = parent.data.backgroundSegments[params.segmentId];
|
||||
if (isBgSegment !== undefined) {
|
||||
params.opacity = isBgSegment ? BACKGROUND_OPACITY : FOREROUND_OPACITY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
export const MeshVisualTransformer = VolsegTransform({
|
||||
name: 'mesh-visual-from-streaming',
|
||||
display: { name: 'Mesh Visual from Streaming' },
|
||||
from: MeshStreaming,
|
||||
to: PluginStateObject.Shape.Representation3D,
|
||||
params: {
|
||||
/** Must be set to PluginStateObject reference to self */
|
||||
ref: PD.Text('', { isHidden: true, isEssential: true }), // QUESTION what is isEssential
|
||||
/** Identification of the mesh visual, e.g. 'low-2' */
|
||||
tag: PD.Text('', { isHidden: true, isEssential: true }),
|
||||
/** Opacity of the visual (not to be set directly, but controlled by the opacity of the parent Group, and by VisualInfo.visible) */
|
||||
opacity: PD.Numeric(-1, { min: 0, max: 1, step: 0.01 }, { isHidden: true }),
|
||||
}
|
||||
})({
|
||||
apply({ a, params, spine }, plugin: PluginContext) {
|
||||
return Task.create('Mesh Visual', async ctx => {
|
||||
const visualInfo: MeshStreaming.VisualInfo = a.data.visuals![params.tag];
|
||||
if (!visualInfo) throw new Error(`VisualInfo with tag '${params.tag}' is missing.`);
|
||||
const groupData = spine.getAncestorOfType(PluginStateObject.Group)?.data as MeshVisualGroupData | undefined;
|
||||
params.opacity = visualInfo.visible ? (groupData?.opacity ?? FOREROUND_OPACITY) : 0.0;
|
||||
const props = PD.getDefaultValues(Mesh.Params);
|
||||
props.flatShaded = true; // `flatShaded: true` is to see the real mesh vertices and triangles (default: false)
|
||||
props.alpha = params.opacity;
|
||||
const repr = ShapeRepresentation((ctx, meshlist: MeshlistData) => MeshlistData.getShape(meshlist, visualInfo.color), Mesh.Utils);
|
||||
await repr.createOrUpdate(props, visualInfo.data ?? MeshlistData.empty()).runInContext(ctx);
|
||||
return new PluginStateObject.Shape.Representation3D({ repr, sourceData: visualInfo.data }, { label: 'Mesh Visual', description: params.tag });
|
||||
});
|
||||
},
|
||||
update({ a, b, oldParams, newParams, spine }, plugin: PluginContext) {
|
||||
return Task.create('Update Mesh Visual', async ctx => {
|
||||
newParams.ref ||= oldParams.ref; // Protect against resetting params to invalid defaults
|
||||
newParams.tag ||= oldParams.tag; // Protect against resetting params to invalid defaults
|
||||
const visualInfo: MeshStreaming.VisualInfo = a.data.visuals![newParams.tag];
|
||||
if (!visualInfo) throw new Error(`VisualInfo with tag '${newParams.tag}' is missing.`);
|
||||
const oldData = b.data.sourceData as MeshlistData | undefined;
|
||||
if (visualInfo.data?.detail !== oldData?.detail) {
|
||||
return StateTransformer.UpdateResult.Recreate;
|
||||
}
|
||||
const groupData = spine.getAncestorOfType(PluginStateObject.Group)?.data as MeshVisualGroupData | undefined;
|
||||
const newOpacity = visualInfo.visible ? (groupData?.opacity ?? FOREROUND_OPACITY) : 0.0; // do not store to newParams directly, because oldParams and newParams might point to the same object!
|
||||
if (newOpacity !== oldParams.opacity) {
|
||||
newParams.opacity = newOpacity;
|
||||
await b.data.repr.createOrUpdate({ alpha: newParams.opacity }).runInContext(ctx);
|
||||
return StateTransformer.UpdateResult.Updated;
|
||||
} else {
|
||||
return StateTransformer.UpdateResult.Unchanged;
|
||||
}
|
||||
});
|
||||
},
|
||||
canAutoUpdate(params, globalCtx) {
|
||||
return true;
|
||||
},
|
||||
dispose({ b, params }, plugin) {
|
||||
b?.data.repr.destroy(); // QUESTION is this correct?
|
||||
},
|
||||
});
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
export const InitMeshStreaming = StateAction.build({
|
||||
display: { name: 'Mesh Streaming' },
|
||||
from: PluginStateObject.Root,
|
||||
params: MeshServerInfo.Params,
|
||||
isApplicable: (a, _, plugin: PluginContext) => true
|
||||
})(function (p, plugin: PluginContext) {
|
||||
return Task.create('Mesh Streaming', async ctx => {
|
||||
const { params } = p;
|
||||
// p.ref
|
||||
const serverNode = await plugin.build().to(p.ref).apply(MeshServerTransformer, params).commit();
|
||||
// const serverNode = await plugin.build().toRoot().apply(MeshServerTransformer, params).commit();
|
||||
const streamingNode = await plugin.build().to(serverNode).apply(MeshStreamingTransformer, {}).commit();
|
||||
const visuals = streamingNode.data?.visuals ?? {};
|
||||
const bgSegments = streamingNode.data?.backgroundSegments ?? {};
|
||||
|
||||
const segmentGroups: { [segid: number]: string } = {};
|
||||
for (const tag in visuals) {
|
||||
const segid = visuals[tag].segmentId;
|
||||
if (!segmentGroups[segid]) {
|
||||
let description = visuals[tag].segmentName;
|
||||
if (bgSegments[segid]) description += ' (background)';
|
||||
const group = await plugin.build().to(streamingNode).apply(MeshVisualGroupTransformer, { label: `Segment ${segid}`, description: description, segmentId: segid }, { state: { isCollapsed: true } }).commit();
|
||||
segmentGroups[segid] = group.ref;
|
||||
}
|
||||
}
|
||||
const visualsUpdate = plugin.build();
|
||||
for (const tag in visuals) {
|
||||
const ref = `${streamingNode.ref}-${tag}`;
|
||||
const segid = visuals[tag].segmentId;
|
||||
visualsUpdate.to(segmentGroups[segid]).apply(MeshVisualTransformer, { ref: ref, tag: tag }, { ref: ref }); // ref - hack to allow the node make itself invisible
|
||||
}
|
||||
await plugin.state.data.updateTree(visualsUpdate).runInContext(ctx); // QUESTION what is really the difference between this and `visualsUpdate.commit()`?
|
||||
});
|
||||
});
|
||||
|
||||
// TODO make available in GUI, in left panel or in right panel like Volume Streaming in src/mol-plugin-ui/structure/volume.tsx?
|
||||
340
src/extensions/meshes/mesh-utils.ts
Normal file
340
src/extensions/meshes/mesh-utils.ts
Normal file
@@ -0,0 +1,340 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
/** Helper functions for manipulation with mesh data. */
|
||||
|
||||
import { Mesh } from '../../mol-geo/geometry/mesh/mesh';
|
||||
import { CIF, CifFile } from '../../mol-io/reader/cif';
|
||||
import { Box3D } from '../../mol-math/geometry';
|
||||
import { Mat4, Vec3 } from '../../mol-math/linear-algebra';
|
||||
import { volumeFromDensityServerData } from '../../mol-model-formats/volume/density-server';
|
||||
import { Grid } from '../../mol-model/volume';
|
||||
import { ColorNames } from '../../mol-util/color/names';
|
||||
import { TypedArray } from '../../mol-util/type-helpers';
|
||||
|
||||
import { CIF_schema_mesh } from './mesh-cif-schema';
|
||||
|
||||
|
||||
type MeshModificationParams = {
|
||||
scale?: [number, number, number],
|
||||
shift?: [number, number, number],
|
||||
matrix?: Mat4,
|
||||
group?: number,
|
||||
invertSides?: boolean
|
||||
};
|
||||
|
||||
/** Modify mesh in-place */
|
||||
export function modify(m: Mesh, params: MeshModificationParams) {
|
||||
if (params.scale !== undefined) {
|
||||
const [qx, qy, qz] = params.scale;
|
||||
const vertices = m.vertexBuffer.ref.value;
|
||||
for (let i = 0; i < vertices.length; i += 3) {
|
||||
vertices[i] *= qx;
|
||||
vertices[i + 1] *= qy;
|
||||
vertices[i + 2] *= qz;
|
||||
}
|
||||
}
|
||||
if (params.shift !== undefined) {
|
||||
const [dx, dy, dz] = params.shift;
|
||||
const vertices = m.vertexBuffer.ref.value;
|
||||
for (let i = 0; i < vertices.length; i += 3) {
|
||||
vertices[i] += dx;
|
||||
vertices[i + 1] += dy;
|
||||
vertices[i + 2] += dz;
|
||||
}
|
||||
}
|
||||
if (params.matrix !== undefined) {
|
||||
const r = m.vertexBuffer.ref.value;
|
||||
const matrix = params.matrix;
|
||||
const size = 3 * m.vertexCount;
|
||||
for (let i = 0; i < size; i += 3) {
|
||||
Vec3.transformMat4Offset(r, r, matrix, i, i, 0);
|
||||
}
|
||||
}
|
||||
if (params.group !== undefined) {
|
||||
const groups = m.groupBuffer.ref.value;
|
||||
for (let i = 0; i < groups.length; i++) {
|
||||
groups[i] = params.group;
|
||||
}
|
||||
}
|
||||
if (params.invertSides) {
|
||||
const indices = m.indexBuffer.ref.value;
|
||||
let tmp;
|
||||
for (let i = 0; i < indices.length; i += 3) {
|
||||
tmp = indices[i];
|
||||
indices[i] = indices[i + 1];
|
||||
indices[i + 1] = tmp;
|
||||
}
|
||||
const normals = m.normalBuffer.ref.value;
|
||||
for (let i = 0; i < normals.length; i++) {
|
||||
normals[i] *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Create a copy a mesh, possibly modified */
|
||||
export function copy(m: Mesh, modification?: MeshModificationParams): Mesh {
|
||||
const nVertices = m.vertexCount;
|
||||
const nTriangles = m.triangleCount;
|
||||
const vertices = new Float32Array(m.vertexBuffer.ref.value);
|
||||
const indices = new Uint32Array(m.indexBuffer.ref.value);
|
||||
const normals = new Float32Array(m.normalBuffer.ref.value);
|
||||
const groups = new Float32Array(m.groupBuffer.ref.value);
|
||||
const result = Mesh.create(vertices, indices, normals, groups, nVertices, nTriangles);
|
||||
if (modification) {
|
||||
modify(result, modification);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Join more meshes into one */
|
||||
export function concat(...meshes: Mesh[]): Mesh {
|
||||
const nVertices = sum(meshes.map(m => m.vertexCount));
|
||||
const nTriangles = sum(meshes.map(m => m.triangleCount));
|
||||
const vertices = concatArrays(Float32Array, meshes.map(m => m.vertexBuffer.ref.value));
|
||||
const normals = concatArrays(Float32Array, meshes.map(m => m.normalBuffer.ref.value));
|
||||
const groups = concatArrays(Float32Array, meshes.map(m => m.groupBuffer.ref.value));
|
||||
const newIndices = [];
|
||||
let offset = 0;
|
||||
for (const m of meshes) {
|
||||
newIndices.push(m.indexBuffer.ref.value.map(i => i + offset));
|
||||
offset += m.vertexCount;
|
||||
}
|
||||
const indices = concatArrays(Uint32Array, newIndices);
|
||||
return Mesh.create(vertices, indices, normals, groups, nVertices, nTriangles);
|
||||
}
|
||||
|
||||
/** Return Mesh from CIF data and mesh IDs (group IDs).
|
||||
* Assume the CIF contains coords in grid space,
|
||||
* transform the output mesh to `space` */
|
||||
export async function meshFromCif(data: CifFile, invertSides: boolean | undefined = undefined, outSpace: 'grid' | 'fractional' | 'cartesian' = 'cartesian'): Promise<{ mesh: Mesh, meshIds: number[] }> {
|
||||
const volumeInfoBlock = data.blocks.find(b => b.header === 'VOLUME_INFO');
|
||||
const meshesBlock = data.blocks.find(b => b.header === 'MESHES');
|
||||
if (!volumeInfoBlock || !meshesBlock) throw new Error('Missing VOLUME_INFO or MESHES block in mesh CIF file');
|
||||
const volumeInfoCif = CIF.schema.densityServer(volumeInfoBlock);
|
||||
const meshCif = CIF_schema_mesh(meshesBlock);
|
||||
|
||||
const nVertices = meshCif.mesh_vertex._rowCount;
|
||||
const nTriangles = Math.floor(meshCif.mesh_triangle._rowCount / 3);
|
||||
|
||||
const mesh_id = meshCif.mesh.id.toArray();
|
||||
const vertex_meshId = meshCif.mesh_vertex.mesh_id.toArray();
|
||||
const x = meshCif.mesh_vertex.x.toArray();
|
||||
const y = meshCif.mesh_vertex.y.toArray();
|
||||
const z = meshCif.mesh_vertex.z.toArray();
|
||||
const triangle_meshId = meshCif.mesh_triangle.mesh_id.toArray();
|
||||
const triangle_vertexId = meshCif.mesh_triangle.vertex_id.toArray();
|
||||
|
||||
// Shift indices from within-mesh indices to overall indices
|
||||
const indices = new Uint32Array(3 * nTriangles);
|
||||
const offsets = offsetMap(vertex_meshId);
|
||||
for (let i = 0; i < 3 * nTriangles; i++) {
|
||||
const offset = offsets.get(triangle_meshId[i])!;
|
||||
indices[i] = offset + triangle_vertexId[i];
|
||||
}
|
||||
const vertices = flattenCoords(x, y, z);
|
||||
const normals = new Float32Array(3 * nVertices);
|
||||
const groups = new Float32Array(vertex_meshId);
|
||||
const mesh = Mesh.create(vertices, indices, normals, groups, nVertices, nTriangles);
|
||||
|
||||
invertSides ??= isInverted(mesh);
|
||||
if (invertSides) {
|
||||
modify(mesh, { invertSides: true }); // Vertex orientation convention is opposite in Volseg API and in MolStar
|
||||
}
|
||||
|
||||
if (outSpace === 'cartesian') {
|
||||
const volume = await volumeFromDensityServerData(volumeInfoCif).run();
|
||||
const gridToCartesian = Grid.getGridToCartesianTransform(volume.grid);
|
||||
modify(mesh, { matrix: gridToCartesian });
|
||||
} else if (outSpace === 'fractional') {
|
||||
const gridSize = volumeInfoCif.volume_data_3d_info.sample_count.value(0);
|
||||
const originFract = volumeInfoCif.volume_data_3d_info.origin.value(0);
|
||||
const dimensionFract = volumeInfoCif.volume_data_3d_info.dimensions.value(0);
|
||||
if (dimensionFract[0] !== 1 || dimensionFract[1] !== 1 || dimensionFract[2] !== 1) throw new Error(`Asserted the fractional dimensions are [1,1,1], but are actually [${dimensionFract}]`);
|
||||
const scale: [number, number, number] = [1 / gridSize[0], 1 / gridSize[1], 1 / gridSize[2]];
|
||||
modify(mesh, { scale: scale, shift: Array.from(originFract) as any });
|
||||
}
|
||||
|
||||
Mesh.computeNormals(mesh); // normals only necessary if flatShaded==false
|
||||
|
||||
// const boxMesh = makeMeshFromBox([[0,0,0], [1,1,1]], 1);
|
||||
// const gridSize = volumeInfoCif.volume_data_3d_info.sample_count.value(0); const boxMesh = makeMeshFromBox([[0,0,0], Array.from(gridSize)] as any, 1);
|
||||
// const cellSize = volumeInfoCif.volume_data_3d_info.spacegroup_cell_size.value(0); const boxMesh = makeMeshFromBox([[0, 0, 0], Array.from(cellSize)] as any, 1);
|
||||
// mesh = concat(mesh, boxMesh); // debug
|
||||
return { mesh: mesh, meshIds: Array.from(mesh_id) };
|
||||
}
|
||||
|
||||
function isInverted(mesh: Mesh): boolean {
|
||||
const vertices = mesh.vertexBuffer.ref.value;
|
||||
const indices = mesh.indexBuffer.ref.value;
|
||||
const center = meshCenter(mesh);
|
||||
const center3 = Vec3.create(3 * center[0], 3 * center[1], 3 * center[2]);
|
||||
|
||||
let dirMetric = 0.0;
|
||||
const [a, b, c, u, v, normal, radius] = [Vec3(), Vec3(), Vec3(), Vec3(), Vec3(), Vec3(), Vec3()];
|
||||
for (let i = 0; i < indices.length; i += 3) {
|
||||
Vec3.fromArray(a, vertices, 3 * indices[i]);
|
||||
Vec3.fromArray(b, vertices, 3 * indices[i + 1]);
|
||||
Vec3.fromArray(c, vertices, 3 * indices[i + 2]);
|
||||
Vec3.sub(u, b, a);
|
||||
Vec3.sub(v, c, b);
|
||||
Vec3.cross(normal, u, v); // direction of the surface
|
||||
Vec3.add(radius, a, b);
|
||||
Vec3.add(radius, radius, c);
|
||||
Vec3.sub(radius, radius, center3); // direction center -> this triangle
|
||||
dirMetric += Vec3.dot(radius, normal);
|
||||
}
|
||||
return dirMetric < 0;
|
||||
}
|
||||
|
||||
function meshCenter(mesh: Mesh) {
|
||||
const vertices = mesh.vertexBuffer.ref.value;
|
||||
const n = vertices.length;
|
||||
let x = 0.0;
|
||||
let y = 0.0;
|
||||
let z = 0.0;
|
||||
for (let i = 0; i < vertices.length; i += 3) {
|
||||
x += vertices[i];
|
||||
y += vertices[i + 1];
|
||||
z += vertices[i + 2];
|
||||
}
|
||||
return Vec3.create(x / n, y / n, z / n);
|
||||
}
|
||||
|
||||
function flattenCoords(x: ArrayLike<number>, y: ArrayLike<number>, z: ArrayLike<number>): Float32Array {
|
||||
const n = x.length;
|
||||
const out = new Float32Array(3 * n);
|
||||
for (let i = 0; i < n; i++) {
|
||||
out[3 * i] = x[i];
|
||||
out[3 * i + 1] = y[i];
|
||||
out[3 * i + 2] = z[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Get mapping of unique values to the position of their first occurrence */
|
||||
function offsetMap(values: ArrayLike<number>) {
|
||||
const result = new Map<number, number>();
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
if (!result.has(values[i])) {
|
||||
result.set(values[i], i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Return bounding box */
|
||||
export function bbox(mesh: Mesh): Box3D | null { // Is there no function for this?
|
||||
const nVertices = mesh.vertexCount;
|
||||
const coords = mesh.vertexBuffer.ref.value;
|
||||
if (nVertices === 0) {
|
||||
return null;
|
||||
}
|
||||
let minX = coords[0], minY = coords[1], minZ = coords[2];
|
||||
let maxX = minX, maxY = minY, maxZ = minZ;
|
||||
for (let i = 0; i < 3 * nVertices; i += 3) {
|
||||
const x = coords[i], y = coords[i + 1], z = coords[i + 2];
|
||||
if (x < minX) minX = x;
|
||||
if (y < minY) minY = y;
|
||||
if (z < minZ) minZ = z;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y > maxY) maxY = y;
|
||||
if (z > maxZ) maxZ = z;
|
||||
}
|
||||
return Box3D.create(Vec3.create(minX, minY, minZ), Vec3.create(maxX, maxY, maxZ));
|
||||
}
|
||||
|
||||
/** Example mesh - 1 triangle */
|
||||
export function fakeFakeMesh1(): Mesh {
|
||||
const nVertices = 3;
|
||||
const nTriangles = 1;
|
||||
const vertices = new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0]);
|
||||
const indices = new Uint32Array([0, 1, 2]);
|
||||
const normals = new Float32Array([0, 0, 1]);
|
||||
const groups = new Float32Array([0]);
|
||||
return Mesh.create(vertices, indices, normals, groups, nVertices, nTriangles);
|
||||
}
|
||||
|
||||
/** Example mesh - irregular tetrahedron */
|
||||
export function fakeMesh4(): Mesh {
|
||||
const nVertices = 4;
|
||||
const nTriangles = 4;
|
||||
const vertices = new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
||||
const indices = new Uint32Array([0, 2, 1, 0, 1, 3, 1, 2, 3, 2, 0, 3]);
|
||||
const normals = new Float32Array([-1, -1, -1, 1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
||||
const groups = new Float32Array([0, 1, 2, 3]);
|
||||
return Mesh.create(vertices, indices, normals, groups, nVertices, nTriangles);
|
||||
}
|
||||
|
||||
/** Return a box-shaped mesh */
|
||||
export function meshFromBox(box: [[number, number, number], [number, number, number]], group: number = 0) {
|
||||
const [[x0, y0, z0], [x1, y1, z1]] = box;
|
||||
const vertices = new Float32Array([
|
||||
x0, y0, z0,
|
||||
x1, y0, z0,
|
||||
x0, y1, z0,
|
||||
x1, y1, z0,
|
||||
x0, y0, z1,
|
||||
x1, y0, z1,
|
||||
x0, y1, z1,
|
||||
x1, y1, z1,
|
||||
]);
|
||||
const indices = new Uint32Array([
|
||||
2, 1, 0, 1, 2, 3,
|
||||
1, 4, 0, 4, 1, 5,
|
||||
3, 5, 1, 5, 3, 7,
|
||||
2, 7, 3, 7, 2, 6,
|
||||
0, 6, 2, 6, 0, 4,
|
||||
4, 7, 6, 7, 4, 5,
|
||||
]);
|
||||
const groups = new Float32Array([group, group, group, group, group, group, group, group]);
|
||||
const normals = new Float32Array(8);
|
||||
const mesh = Mesh.create(vertices, indices, normals, groups, 8, 12);
|
||||
Mesh.computeNormals(mesh); // normals only necessary if flatShaded==false
|
||||
return mesh;
|
||||
}
|
||||
|
||||
function sum(array: number[]): number {
|
||||
return array.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
|
||||
function concatArrays<T extends TypedArray>(t: new (len: number) => T, arrays: T[]): T {
|
||||
const totalLength = arrays.map(a => a.length).reduce((a, b) => a + b, 0);
|
||||
const result: T = new t(totalLength);
|
||||
let offset = 0;
|
||||
for (const array of arrays) {
|
||||
result.set(array, offset);
|
||||
offset += array.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Generate random colors (in a cycle) */
|
||||
export const ColorGenerator = function* () {
|
||||
const colors = shuffleArray(Object.values(ColorNames));
|
||||
let i = 0;
|
||||
while (true) {
|
||||
yield colors[i];
|
||||
i++;
|
||||
if (i >= colors.length) i = 0;
|
||||
}
|
||||
}();
|
||||
function shuffleArray<T>(array: T[]): T[] {
|
||||
// Stealed from https://www.w3docs.com/snippets/javascript/how-to-randomize-shuffle-a-javascript-array.html
|
||||
let curId = array.length;
|
||||
// There remain elements to shuffle
|
||||
while (0 !== curId) {
|
||||
// Pick a remaining element
|
||||
const randId = Math.floor(Math.random() * curId);
|
||||
curId -= 1;
|
||||
// Swap it with the current element.
|
||||
const tmp = array[curId];
|
||||
array[curId] = array[randId];
|
||||
array[randId] = tmp;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
* @author David Sehnal <david.sehnal@gmail.com>
|
||||
*/
|
||||
|
||||
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
|
||||
@@ -14,6 +15,7 @@ import { CustomPropSymbol } from '../../../mol-script/language/symbol';
|
||||
import { Type } from '../../../mol-script/language/type';
|
||||
import { CustomPropertyDescriptor } from '../../../mol-model/custom-property';
|
||||
import { MmcifFormat } from '../../../mol-model-formats/structure/mmcif';
|
||||
import { AtomicIndex } from '../../../mol-model/structure/model/properties/atomic';
|
||||
|
||||
export { QualityAssessment };
|
||||
|
||||
@@ -71,14 +73,28 @@ namespace QualityAssessment {
|
||||
localNames.set(ma_qa_metric.id.value(i), name);
|
||||
}
|
||||
|
||||
const residueKey: AtomicIndex.ResidueLabelKey = {
|
||||
label_entity_id: '',
|
||||
label_asym_id: '',
|
||||
label_seq_id: 0,
|
||||
pdbx_PDB_ins_code: undefined,
|
||||
};
|
||||
|
||||
for (let i = 0, il = ma_qa_metric_local._rowCount; i < il; i++) {
|
||||
if (model_id.value(i) !== model.modelNum) continue;
|
||||
|
||||
const labelAsymId = label_asym_id.value(i);
|
||||
const entityIndex = index.findEntity(labelAsymId);
|
||||
const rI = index.findResidue(model.entities.data.id.value(entityIndex), labelAsymId, label_seq_id.value(i));
|
||||
const name = localNames.get(metric_id.value(i))!;
|
||||
localMetrics.get(name)!.set(rI, metric_value.value(i));
|
||||
|
||||
residueKey.label_entity_id = model.entities.data.id.value(entityIndex);
|
||||
residueKey.label_asym_id = labelAsymId;
|
||||
residueKey.label_seq_id = label_seq_id.value(i);
|
||||
|
||||
const rI = index.findResidueLabel(residueKey);
|
||||
if (rI >= 0) {
|
||||
const name = localNames.get(metric_id.value(i))!;
|
||||
localMetrics.get(name)!.set(rI, metric_value.value(i));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -4,7 +4,7 @@ export type InputMaybe<T> = Maybe<T>;
|
||||
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
|
||||
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
|
||||
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
|
||||
// Generated on 2022-08-20T16:36:05-07:00
|
||||
// Generated on 2023-01-15T10:00:07-08:00
|
||||
|
||||
/** All built-in and custom scalars, mapped to their actual values */
|
||||
export type Scalars = {
|
||||
@@ -343,6 +343,14 @@ export type Citation = {
|
||||
*
|
||||
*/
|
||||
readonly journal_abbrev?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* Full name of the cited journal; relevant for journal articles.
|
||||
*
|
||||
* Examples:
|
||||
* Journal of Molecular Biology
|
||||
*
|
||||
*/
|
||||
readonly journal_full?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* The American Society for Testing and Materials (ASTM) code
|
||||
* assigned to the journal cited (also referred to as the CODEN
|
||||
@@ -550,6 +558,7 @@ export type CoreBranchedEntityInstance = {
|
||||
readonly rcsb_id: Scalars['String'];
|
||||
readonly rcsb_latest_revision?: Maybe<RcsbLatestRevision>;
|
||||
readonly rcsb_ligand_neighbors?: Maybe<ReadonlyArray<Maybe<RcsbLigandNeighbors>>>;
|
||||
readonly struct_asym?: Maybe<StructAsym>;
|
||||
};
|
||||
|
||||
export type CoreChemComp = {
|
||||
@@ -661,6 +670,7 @@ export type CoreEntry = {
|
||||
readonly exptl?: Maybe<ReadonlyArray<Maybe<Exptl>>>;
|
||||
readonly exptl_crystal?: Maybe<ReadonlyArray<Maybe<ExptlCrystal>>>;
|
||||
readonly exptl_crystal_grow?: Maybe<ReadonlyArray<Maybe<ExptlCrystalGrow>>>;
|
||||
readonly ma_data?: Maybe<ReadonlyArray<Maybe<MaData>>>;
|
||||
/** Get all non-polymer (non-solvent) entities for this PDB entry. */
|
||||
readonly nonpolymer_entities?: Maybe<ReadonlyArray<Maybe<CoreNonpolymerEntity>>>;
|
||||
readonly pdbx_SG_project?: Maybe<ReadonlyArray<Maybe<PdbxSgProject>>>;
|
||||
@@ -701,6 +711,7 @@ export type CoreEntry = {
|
||||
/** The list of content types associated with this entry. */
|
||||
readonly rcsb_associated_holdings?: Maybe<CurrentEntry>;
|
||||
readonly rcsb_binding_affinity?: Maybe<ReadonlyArray<Maybe<RcsbBindingAffinity>>>;
|
||||
readonly rcsb_comp_model_provenance?: Maybe<RcsbCompModelProvenance>;
|
||||
readonly rcsb_entry_container_identifiers: RcsbEntryContainerIdentifiers;
|
||||
readonly rcsb_entry_group_membership?: Maybe<ReadonlyArray<Maybe<RcsbEntryGroupMembership>>>;
|
||||
readonly rcsb_entry_info: RcsbEntryInfo;
|
||||
@@ -713,6 +724,7 @@ export type CoreEntry = {
|
||||
*
|
||||
*/
|
||||
readonly rcsb_id: Scalars['String'];
|
||||
readonly rcsb_ma_qa_metric_global?: Maybe<ReadonlyArray<Maybe<RcsbMaQaMetricGlobal>>>;
|
||||
readonly rcsb_primary_citation?: Maybe<RcsbPrimaryCitation>;
|
||||
readonly refine?: Maybe<ReadonlyArray<Maybe<Refine>>>;
|
||||
readonly refine_analyze?: Maybe<ReadonlyArray<Maybe<RefineAnalyze>>>;
|
||||
@@ -786,6 +798,7 @@ export type CoreNonpolymerEntityInstance = {
|
||||
readonly rcsb_nonpolymer_instance_validation_score?: Maybe<ReadonlyArray<Maybe<RcsbNonpolymerInstanceValidationScore>>>;
|
||||
readonly rcsb_nonpolymer_struct_conn?: Maybe<ReadonlyArray<Maybe<RcsbNonpolymerStructConn>>>;
|
||||
readonly rcsb_target_neighbors?: Maybe<ReadonlyArray<Maybe<RcsbTargetNeighbors>>>;
|
||||
readonly struct_asym?: Maybe<StructAsym>;
|
||||
};
|
||||
|
||||
export type CorePfam = {
|
||||
@@ -919,6 +932,7 @@ export type CorePolymerEntityInstance = {
|
||||
readonly rcsb_polymer_instance_feature?: Maybe<ReadonlyArray<Maybe<RcsbPolymerInstanceFeature>>>;
|
||||
readonly rcsb_polymer_instance_feature_summary?: Maybe<ReadonlyArray<Maybe<RcsbPolymerInstanceFeatureSummary>>>;
|
||||
readonly rcsb_polymer_struct_conn?: Maybe<ReadonlyArray<Maybe<RcsbPolymerStructConn>>>;
|
||||
readonly struct_asym?: Maybe<StructAsym>;
|
||||
};
|
||||
|
||||
export type CorePubmed = {
|
||||
@@ -1284,9 +1298,9 @@ export type Em2dCrystalEntity = {
|
||||
readonly id: Scalars['String'];
|
||||
/** pointer to _em_image_processing.id in the EM_IMAGE_PROCESSING category. */
|
||||
readonly image_processing_id: Scalars['String'];
|
||||
/** Unit-cell length a in Angstroms. */
|
||||
/** Unit-cell length a in angstroms. */
|
||||
readonly length_a?: Maybe<Scalars['Float']>;
|
||||
/** Unit-cell length b in Angstroms. */
|
||||
/** Unit-cell length b in angstroms. */
|
||||
readonly length_b?: Maybe<Scalars['Float']>;
|
||||
/** Thickness of 2D crystal */
|
||||
readonly length_c?: Maybe<Scalars['Float']>;
|
||||
@@ -1317,11 +1331,11 @@ export type Em3dCrystalEntity = {
|
||||
readonly id: Scalars['String'];
|
||||
/** pointer to _em_image_processing.id in the EM_IMAGE_PROCESSING category. */
|
||||
readonly image_processing_id: Scalars['String'];
|
||||
/** Unit-cell length a in Angstroms. */
|
||||
/** Unit-cell length a in angstroms. */
|
||||
readonly length_a?: Maybe<Scalars['Float']>;
|
||||
/** Unit-cell length b in Angstroms. */
|
||||
/** Unit-cell length b in angstroms. */
|
||||
readonly length_b?: Maybe<Scalars['Float']>;
|
||||
/** Unit-cell length c in Angstroms. */
|
||||
/** Unit-cell length c in angstroms. */
|
||||
readonly length_c?: Maybe<Scalars['Float']>;
|
||||
/**
|
||||
* Space group name.
|
||||
@@ -1482,7 +1496,7 @@ export type Em3dReconstruction = {
|
||||
*/
|
||||
readonly refinement_type?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* The final resolution (in Angstroms)of the 3D reconstruction.
|
||||
* The final resolution (in angstroms)of the 3D reconstruction.
|
||||
*
|
||||
* Examples:
|
||||
* null, null
|
||||
@@ -1558,7 +1572,7 @@ export type EmDiffractionShell = {
|
||||
*/
|
||||
readonly fourier_space_coverage?: Maybe<Scalars['Float']>;
|
||||
/**
|
||||
* High resolution limit for this shell (Angstroms)
|
||||
* High resolution limit for this shell (angstroms)
|
||||
*
|
||||
* Examples:
|
||||
* null
|
||||
@@ -1568,7 +1582,7 @@ export type EmDiffractionShell = {
|
||||
/** Unique identifier for the category em_diffraction_shell */
|
||||
readonly id: Scalars['String'];
|
||||
/**
|
||||
* Low resolution limit for this shell (Angstroms)
|
||||
* Low resolution limit for this shell (angstroms)
|
||||
*
|
||||
* Examples:
|
||||
* null
|
||||
@@ -1614,7 +1628,7 @@ export type EmDiffractionStats = {
|
||||
*/
|
||||
readonly fourier_space_coverage?: Maybe<Scalars['Float']>;
|
||||
/**
|
||||
* High resolution limit of the structure factor data, in Angstroms
|
||||
* High resolution limit of the structure factor data, in angstroms
|
||||
*
|
||||
* Examples:
|
||||
* null
|
||||
@@ -1998,12 +2012,12 @@ export type EmImaging = {
|
||||
/** The magnification indicated by the microscope readout. */
|
||||
readonly nominal_magnification?: Maybe<Scalars['Int']>;
|
||||
/**
|
||||
* The specimen temperature maximum (degrees Kelvin) for the duration
|
||||
* The specimen temperature maximum (kelvin) for the duration
|
||||
* of imaging.
|
||||
*/
|
||||
readonly recording_temperature_maximum?: Maybe<Scalars['Float']>;
|
||||
/**
|
||||
* The specimen temperature minimum (degrees Kelvin) for the duration
|
||||
* The specimen temperature minimum (kelvin) for the duration
|
||||
* of imaging.
|
||||
*/
|
||||
readonly recording_temperature_minimum?: Maybe<Scalars['Float']>;
|
||||
@@ -2028,7 +2042,7 @@ export type EmImaging = {
|
||||
/** Foreign key to the EM_SPECIMEN category */
|
||||
readonly specimen_id?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* The mean specimen stage temperature (degrees Kelvin) during imaging
|
||||
* The mean specimen stage temperature (in kelvin) during imaging
|
||||
* in the microscope.
|
||||
*/
|
||||
readonly temperature?: Maybe<Scalars['Float']>;
|
||||
@@ -2215,7 +2229,7 @@ export type EmStaining = {
|
||||
};
|
||||
|
||||
export type EmVitrification = {
|
||||
/** The temperature (in degrees Kelvin) of the sample just prior to vitrification. */
|
||||
/** The temperature (in kelvin) of the sample just prior to vitrification. */
|
||||
readonly chamber_temperature?: Maybe<Scalars['Float']>;
|
||||
/**
|
||||
* This is the name of the cryogen.
|
||||
@@ -2259,7 +2273,7 @@ export type EmVitrification = {
|
||||
/** This data item is a pointer to _em_specimen.id */
|
||||
readonly specimen_id: Scalars['String'];
|
||||
/**
|
||||
* The vitrification temperature (in degrees Kelvin), e.g.,
|
||||
* The vitrification temperature (in kelvin), e.g.,
|
||||
* temperature of the plunge instrument cryogen bath.
|
||||
*/
|
||||
readonly temp?: Maybe<Scalars['Float']>;
|
||||
@@ -2364,6 +2378,14 @@ export type EntityPoly = {
|
||||
*
|
||||
*/
|
||||
readonly pdbx_seq_one_letter_code_can?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* Evidence for the assignment of the polymer sequence.
|
||||
*
|
||||
* Allowable values:
|
||||
* depositor provided, derived from coordinates
|
||||
*
|
||||
*/
|
||||
readonly pdbx_sequence_evidence_code?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* The PDB strand/chain id(s) corresponding to this polymer entity.
|
||||
*
|
||||
@@ -3005,6 +3027,8 @@ export type Entry = {
|
||||
* identifier.
|
||||
*/
|
||||
readonly id: Scalars['String'];
|
||||
/** An identifier for the model collection associated with the entry. */
|
||||
readonly ma_collection_id?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
export type Exptl = {
|
||||
@@ -3263,6 +3287,29 @@ export type InterfacePartnerFeatureFeaturePositions = {
|
||||
readonly values?: Maybe<ReadonlyArray<Maybe<Scalars['Float']>>>;
|
||||
};
|
||||
|
||||
export type MaData = {
|
||||
/**
|
||||
* The type of data held in the dataset.
|
||||
*
|
||||
* Allowable values:
|
||||
* coevolution MSA, input structure, model coordinates, other, polymeric template library, spatial restraints, target, target-template alignment, template structure
|
||||
*
|
||||
*/
|
||||
readonly content_type?: Maybe<Scalars['String']>;
|
||||
/** Details for other content types. */
|
||||
readonly content_type_other_details?: Maybe<Scalars['String']>;
|
||||
/** A unique identifier for the data. */
|
||||
readonly id: Scalars['Int'];
|
||||
/**
|
||||
* An author-given name for the content held in the dataset.
|
||||
*
|
||||
* Examples:
|
||||
* NMR NOE Distances, Target Template Alignment, Coevolution Data
|
||||
*
|
||||
*/
|
||||
readonly name?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
export type MethodDetails = {
|
||||
/** A description of special aspects of the clustering process */
|
||||
readonly description?: Maybe<Scalars['String']>;
|
||||
@@ -4199,7 +4246,7 @@ export type PdbxNmrExptlSampleConditions = {
|
||||
*/
|
||||
readonly pressure_units?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* The temperature (in Kelvin) at which NMR data were
|
||||
* The temperature (in kelvin) at which NMR data were
|
||||
* collected.
|
||||
*/
|
||||
readonly temperature?: Maybe<Scalars['String']>;
|
||||
@@ -4453,7 +4500,7 @@ export type PdbxPrdAudit = {
|
||||
* An identifier for the wwPDB site creating or modifying the molecule.
|
||||
*
|
||||
* Allowable values:
|
||||
* BMRB, PDBC, PDBJ, PDBe, RCSB
|
||||
* BMRB, PDBC, PDBE, PDBJ, RCSB
|
||||
*
|
||||
*/
|
||||
readonly processing_site?: Maybe<Scalars['String']>;
|
||||
@@ -6817,7 +6864,7 @@ export type Query = {
|
||||
readonly assemblies?: Maybe<ReadonlyArray<Maybe<CoreAssembly>>>;
|
||||
/** Get an assembly given the PDB ID and ASSEMBLY ID. Here ASSEMBLY ID is '1', '2', '3', etc. or 'deposited' for deposited coordinates. */
|
||||
readonly assembly?: Maybe<CoreAssembly>;
|
||||
/** Get a list of PDB branched entities given a list of ENTITY IDs. Here ENTITY ID is a compound identifier that includes entry_id and entity_id separated by '_', e.g. 1XXX_1. */
|
||||
/** Get a list of PDB branched entities given a list of ENTITY IDs. Here ENTITY ID is a compound identifier that includes entry_id and entity_id separated by '_', e.g. 1XXX_1. Note that the ENTRY ID part must be upper case. */
|
||||
readonly branched_entities?: Maybe<ReadonlyArray<Maybe<CoreBranchedEntity>>>;
|
||||
/** Get a PDB branched entity, given the PDB ID and ENTITY ID. Here ENTITY ID is a '1', '2', '3', etc. */
|
||||
readonly branched_entity?: Maybe<CoreBranchedEntity>;
|
||||
@@ -6841,9 +6888,9 @@ export type Query = {
|
||||
readonly group_provenance?: Maybe<GroupProvenance>;
|
||||
/** Get a pairwise polymeric interface given the PDB ID, ASSEMBLY ID and INTERFACE ID. */
|
||||
readonly interface?: Maybe<CoreInterface>;
|
||||
/** Get a list of pairwise polymeric interfaces given a list of INTERFACE IDs. Here INTERFACE ID is a compound identifier that includes entry_id, assembly_id and interface_id e.g. 1XXX-1.1. */
|
||||
/** Get a list of pairwise polymeric interfaces given a list of INTERFACE IDs. Here INTERFACE ID is a compound identifier that includes entry_id, assembly_id and interface_id e.g. 1XXX-1.1. Note that the ENTRY ID part must be upper case. */
|
||||
readonly interfaces?: Maybe<ReadonlyArray<Maybe<CoreInterface>>>;
|
||||
/** Get a list of PDB non-polymer entities given a list of ENTITY IDs. Here ENTITY ID is a compound identifier that includes entry_id and entity_id separated by '_', e.g. 1XXX_1. */
|
||||
/** Get a list of PDB non-polymer entities given a list of ENTITY IDs. Here ENTITY ID is a compound identifier that includes entry_id and entity_id separated by '_', e.g. 1XXX_1. Note that the ENTRY ID part must be upper case. */
|
||||
readonly nonpolymer_entities?: Maybe<ReadonlyArray<Maybe<CoreNonpolymerEntity>>>;
|
||||
/** Get a PDB non-polymer entity, given the PDB ID and ENTITY ID. Here ENTITY ID is a '1', '2', '3', etc. */
|
||||
readonly nonpolymer_entity?: Maybe<CoreNonpolymerEntity>;
|
||||
@@ -6851,7 +6898,7 @@ export type Query = {
|
||||
readonly nonpolymer_entity_instance?: Maybe<CoreNonpolymerEntityInstance>;
|
||||
/** Get a list of PDB non-polymer entity instances (chains), given the list of ENTITY INSTANCE IDs. Here ENTITY INSTANCE ID identifies structural element in the asymmetric unit, e.g. 'A', 'B', etc. */
|
||||
readonly nonpolymer_entity_instances?: Maybe<ReadonlyArray<Maybe<CoreNonpolymerEntityInstance>>>;
|
||||
/** Get a list of PDB polymer entities given a list of ENTITY IDs. Here ENTITY ID is a compound identifier that includes entry_id and entity_id separated by '_', e.g. 1XXX_1. */
|
||||
/** Get a list of PDB polymer entities given a list of ENTITY IDs. Here ENTITY ID is a compound identifier that includes entry_id and entity_id separated by '_', e.g. 1XXX_1. Note that the ENTRY ID part must be upper case. */
|
||||
readonly polymer_entities?: Maybe<ReadonlyArray<Maybe<CorePolymerEntity>>>;
|
||||
/** Get a PDB polymer entity, given the PDB ID and ENTITY ID. Here ENTITY ID is a '1', '2', '3', etc. */
|
||||
readonly polymer_entity?: Maybe<CorePolymerEntity>;
|
||||
@@ -8421,6 +8468,31 @@ export type RcsbClusterMembership = {
|
||||
readonly identity?: Maybe<Scalars['Int']>;
|
||||
};
|
||||
|
||||
export type RcsbCompModelProvenance = {
|
||||
/**
|
||||
* Entry identifier corresponding to the computed structure model.
|
||||
*
|
||||
* Examples:
|
||||
* AF-P60325-F1, ma-bak-cepc-0019
|
||||
*
|
||||
*/
|
||||
readonly entry_id: Scalars['String'];
|
||||
/**
|
||||
* Source database for the computed structure model.
|
||||
*
|
||||
* Allowable values:
|
||||
* AlphaFoldDB, ModelArchive
|
||||
*
|
||||
*/
|
||||
readonly source_db?: Maybe<Scalars['String']>;
|
||||
/** Source filename for the computed structure model. */
|
||||
readonly source_filename?: Maybe<Scalars['String']>;
|
||||
/** Source URL for computed structure model predicted aligned error (PAE) json file. */
|
||||
readonly source_pae_url?: Maybe<Scalars['String']>;
|
||||
/** Source URL for computed structure model file. */
|
||||
readonly source_url?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
export type RcsbEntityHostOrganism = {
|
||||
/**
|
||||
* The beginning polymer sequence position for the polymer section corresponding
|
||||
@@ -8657,7 +8729,7 @@ export type RcsbEntitySourceOrganism = {
|
||||
* A code indicating the provenance of the source organism details for the entity
|
||||
*
|
||||
* Allowable values:
|
||||
* PDB Primary Data
|
||||
* PDB Primary Data, UniProt
|
||||
*
|
||||
*/
|
||||
readonly provenance_source?: Maybe<Scalars['String']>;
|
||||
@@ -8731,7 +8803,7 @@ export type RcsbEntryContainerIdentifiers = {
|
||||
* Entry identifier for the container.
|
||||
*
|
||||
* Examples:
|
||||
* 1KIP, 4HHB
|
||||
* 4HHB, AF_AFP60325F1, MA_MABAKCEPC0019
|
||||
*
|
||||
*/
|
||||
readonly entry_id: Scalars['String'];
|
||||
@@ -8879,6 +8951,15 @@ export type RcsbEntryInfo = {
|
||||
*
|
||||
*/
|
||||
readonly na_polymer_entity_types?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* This data item identifies secondary structure
|
||||
* features of nucleic acids in the entry.
|
||||
*
|
||||
* Allowable values:
|
||||
* a-form double helix, b-form double helix, bulge loop, double helix, four-way junction, hairpin loop, internal loop, mismatched base pair, other right-handed double helix, parallel strands, quadruple helix, tetraloop, three-way junction, triple helix, two-way junction, z-form double helix
|
||||
*
|
||||
*/
|
||||
readonly ndb_struct_conf_na_feature_combined?: Maybe<ReadonlyArray<Maybe<Scalars['String']>>>;
|
||||
/** Bound nonpolymer components in this entry. */
|
||||
readonly nonpolymer_bound_components?: Maybe<ReadonlyArray<Maybe<Scalars['String']>>>;
|
||||
/** The number of distinct non-polymer entities in the structure entry exclusive of solvent. */
|
||||
@@ -8955,6 +9036,21 @@ export type RcsbEntryInfo = {
|
||||
readonly software_programs_combined?: Maybe<ReadonlyArray<Maybe<Scalars['String']>>>;
|
||||
/** The number of distinct solvent entities per deposited structure model. */
|
||||
readonly solvent_entity_count?: Maybe<Scalars['Int']>;
|
||||
/**
|
||||
* Indicates if the structure was determined using experimental or computational methods.
|
||||
*
|
||||
* Allowable values:
|
||||
* computational, experimental
|
||||
*
|
||||
*/
|
||||
readonly structure_determination_methodology: Scalars['String'];
|
||||
/**
|
||||
* Indicates the priority of the value in _rcsb_entry_info.structure_determination_methodology.
|
||||
* The lower the number the higher the priority.
|
||||
* Priority values for "experimental" structures is currently set to 10 and
|
||||
* the values for "computational" structures is set to 100.
|
||||
*/
|
||||
readonly structure_determination_methodology_priority?: Maybe<Scalars['Int']>;
|
||||
};
|
||||
|
||||
export type RcsbEntryInfoDiffrnResolutionHigh = {
|
||||
@@ -9294,6 +9390,49 @@ export type RcsbLigandNeighbors = {
|
||||
readonly seq_id?: Maybe<Scalars['Int']>;
|
||||
};
|
||||
|
||||
export type RcsbMaQaMetricGlobal = {
|
||||
readonly ma_qa_metric_global?: Maybe<ReadonlyArray<Maybe<RcsbMaQaMetricGlobalMaQaMetricGlobal>>>;
|
||||
/** The model identifier. */
|
||||
readonly model_id: Scalars['Int'];
|
||||
};
|
||||
|
||||
export type RcsbMaQaMetricGlobalMaQaMetricGlobal = {
|
||||
/**
|
||||
* Description of the global QA metric.
|
||||
*
|
||||
* Examples:
|
||||
* confidence score predicting accuracy according to the CA-only Local Distance Difference Test (lDDT-CA) in [0,100]
|
||||
*
|
||||
*/
|
||||
readonly description?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* Name of the global QA metric.
|
||||
*
|
||||
* Examples:
|
||||
* pLDDT
|
||||
*
|
||||
*/
|
||||
readonly name: Scalars['String'];
|
||||
/**
|
||||
* The type of global QA metric.
|
||||
*
|
||||
* Allowable values:
|
||||
* PAE, contact probability, distance, energy, ipTM, normalized score, other, pLDDT, pLDDT all-atom, pLDDT all-atom in [0,1], pLDDT in [0,1], pTM, zscore
|
||||
*
|
||||
*/
|
||||
readonly type: Scalars['String'];
|
||||
/** Details for other type of global QA metric. */
|
||||
readonly type_other_details?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* Value of the global QA metric.
|
||||
*
|
||||
* Examples:
|
||||
* null
|
||||
*
|
||||
*/
|
||||
readonly value: Scalars['Float'];
|
||||
};
|
||||
|
||||
export type RcsbMembraneLineage = {
|
||||
/** Hierarchy depth. */
|
||||
readonly depth?: Maybe<Scalars['Int']>;
|
||||
@@ -10332,7 +10471,7 @@ export type RcsbPolymerEntityContainerIdentifiersReferenceSequenceIdentifiers =
|
||||
* Source of the reference database assignment
|
||||
*
|
||||
* Allowable values:
|
||||
* PDB, RCSB, SIFTS
|
||||
* PDB, RCSB, SIFTS, UniProt
|
||||
*
|
||||
*/
|
||||
readonly provenance_source?: Maybe<Scalars['String']>;
|
||||
@@ -10737,7 +10876,7 @@ export type RcsbPolymerInstanceFeature = {
|
||||
* A type or category of the feature.
|
||||
*
|
||||
* Allowable values:
|
||||
* ANGLE_OUTLIER, BINDING_SITE, BOND_OUTLIER, C-MANNOSYLATION_SITE, CATH, CIS-PEPTIDE, ECOD, HELIX_P, MEMBRANE_SEGMENT, MOGUL_ANGLE_OUTLIER, MOGUL_BOND_OUTLIER, N-GLYCOSYLATION_SITE, O-GLYCOSYLATION_SITE, RAMACHANDRAN_OUTLIER, ROTAMER_OUTLIER, RSCC_OUTLIER, RSRZ_OUTLIER, S-GLYCOSYLATION_SITE, SABDAB_ANTIBODY_HEAVY_CHAIN_SUBCLASS, SABDAB_ANTIBODY_LIGHT_CHAIN_SUBCLASS, SABDAB_ANTIBODY_LIGHT_CHAIN_TYPE, SCOP, SCOP2B_SUPERFAMILY, SCOP2_FAMILY, SCOP2_SUPERFAMILY, SHEET, STEREO_OUTLIER, UNASSIGNED_SEC_STRUCT, UNOBSERVED_ATOM_XYZ, UNOBSERVED_RESIDUE_XYZ, ZERO_OCCUPANCY_ATOM_XYZ, ZERO_OCCUPANCY_RESIDUE_XYZ, ASA
|
||||
* ANGLE_OUTLIER, BEND, BINDING_SITE, BOND_OUTLIER, C-MANNOSYLATION_SITE, CATH, CIS-PEPTIDE, ECOD, HELIX_P, HELX_LH_PP_P, HELX_RH_3T_P, HELX_RH_AL_P, HELX_RH_PI_P, MA_QA_METRIC_LOCAL_TYPE_CONTACT_PROBABILITY, MA_QA_METRIC_LOCAL_TYPE_DISTANCE, MA_QA_METRIC_LOCAL_TYPE_ENERGY, MA_QA_METRIC_LOCAL_TYPE_IPTM, MA_QA_METRIC_LOCAL_TYPE_NORMALIZED_SCORE, MA_QA_METRIC_LOCAL_TYPE_OTHER, MA_QA_METRIC_LOCAL_TYPE_PAE, MA_QA_METRIC_LOCAL_TYPE_PLDDT, MA_QA_METRIC_LOCAL_TYPE_PLDDT_ALL-ATOM, MA_QA_METRIC_LOCAL_TYPE_PLDDT_ALL-ATOM_[0,1], MA_QA_METRIC_LOCAL_TYPE_PLDDT_[0,1], MA_QA_METRIC_LOCAL_TYPE_PTM, MA_QA_METRIC_LOCAL_TYPE_ZSCORE, MEMBRANE_SEGMENT, MOGUL_ANGLE_OUTLIER, MOGUL_BOND_OUTLIER, N-GLYCOSYLATION_SITE, O-GLYCOSYLATION_SITE, RAMACHANDRAN_OUTLIER, ROTAMER_OUTLIER, RSCC_OUTLIER, RSRZ_OUTLIER, S-GLYCOSYLATION_SITE, SABDAB_ANTIBODY_HEAVY_CHAIN_SUBCLASS, SABDAB_ANTIBODY_LIGHT_CHAIN_SUBCLASS, SABDAB_ANTIBODY_LIGHT_CHAIN_TYPE, SCOP, SCOP2B_SUPERFAMILY, SCOP2_FAMILY, SCOP2_SUPERFAMILY, SHEET, STEREO_OUTLIER, STRN, TURN_TY1_P, UNASSIGNED_SEC_STRUCT, UNOBSERVED_ATOM_XYZ, UNOBSERVED_RESIDUE_XYZ, ZERO_OCCUPANCY_ATOM_XYZ, ZERO_OCCUPANCY_RESIDUE_XYZ, ASA
|
||||
*
|
||||
*/
|
||||
readonly type?: Maybe<Scalars['String']>;
|
||||
@@ -10748,7 +10887,7 @@ export type RcsbPolymerInstanceFeatureAdditionalProperties = {
|
||||
* The additional property name.
|
||||
*
|
||||
* Allowable values:
|
||||
* CATH_DOMAIN_ID, CATH_NAME, ECOD_DOMAIN_ID, ECOD_FAMILY_NAME, OMEGA_ANGLE, PARTNER_ASYM_ID, PARTNER_BOND_DISTANCE, PARTNER_COMP_ID, SCOP2_DOMAIN_ID, SCOP2_FAMILY_ID, SCOP2_FAMILY_NAME, SCOP2_SUPERFAMILY_ID, SCOP2_SUPERFAMILY_NAME, SCOP_DOMAIN_ID, SCOP_NAME, SCOP_SUN_ID, SHEET_SENSE
|
||||
* CATH_DOMAIN_ID, CATH_NAME, ECOD_DOMAIN_ID, ECOD_FAMILY_NAME, MODELCIF_MODEL_ID, OMEGA_ANGLE, PARTNER_ASYM_ID, PARTNER_BOND_DISTANCE, PARTNER_COMP_ID, SCOP2_DOMAIN_ID, SCOP2_FAMILY_ID, SCOP2_FAMILY_NAME, SCOP2_SUPERFAMILY_ID, SCOP2_SUPERFAMILY_NAME, SCOP_DOMAIN_ID, SCOP_NAME, SCOP_SUN_ID, SHEET_SENSE
|
||||
*
|
||||
*/
|
||||
readonly name?: Maybe<Scalars['String']>;
|
||||
@@ -10818,7 +10957,7 @@ export type RcsbPolymerInstanceFeatureSummary = {
|
||||
* Type or category of the feature.
|
||||
*
|
||||
* Allowable values:
|
||||
* ANGLE_OUTLIER, BINDING_SITE, BOND_OUTLIER, C-MANNOSYLATION_SITE, CATH, CIS-PEPTIDE, ECOD, HELIX_P, MEMBRANE_SEGMENT, MOGUL_ANGLE_OUTLIER, MOGUL_BOND_OUTLIER, N-GLYCOSYLATION_SITE, O-GLYCOSYLATION_SITE, RAMACHANDRAN_OUTLIER, ROTAMER_OUTLIER, RSCC_OUTLIER, RSRZ_OUTLIER, S-GLYCOSYLATION_SITE, SABDAB_ANTIBODY_HEAVY_CHAIN_SUBCLASS, SABDAB_ANTIBODY_LIGHT_CHAIN_SUBCLASS, SABDAB_ANTIBODY_LIGHT_CHAIN_TYPE, SAbDab Antibody Heavy Chain Subclass, SAbDab Antibody Light Chain Subclass, SAbDab Antibody Light Chain Type, SCOP, SCOP2 Family, SCOP2 Superfamily, SCOP2B Superfamily, SCOP2B_SUPERFAMILY, SCOP2_FAMILY, SCOP2_SUPERFAMILY, SHEET, STEREO_OUTLIER, UNASSIGNED_SEC_STRUCT, UNOBSERVED_ATOM_XYZ, UNOBSERVED_RESIDUE_XYZ, ZERO_OCCUPANCY_ATOM_XYZ, ZERO_OCCUPANCY_RESIDUE_XYZ
|
||||
* ANGLE_OUTLIER, BEND, BINDING_SITE, BOND_OUTLIER, C-MANNOSYLATION_SITE, CATH, CIS-PEPTIDE, ECOD, HELIX_P, HELX_LH_PP_P, HELX_RH_3T_P, HELX_RH_AL_P, HELX_RH_PI_P, MA_QA_METRIC_LOCAL_TYPE_CONTACT_PROBABILITY, MA_QA_METRIC_LOCAL_TYPE_DISTANCE, MA_QA_METRIC_LOCAL_TYPE_ENERGY, MA_QA_METRIC_LOCAL_TYPE_IPTM, MA_QA_METRIC_LOCAL_TYPE_NORMALIZED_SCORE, MA_QA_METRIC_LOCAL_TYPE_OTHER, MA_QA_METRIC_LOCAL_TYPE_PAE, MA_QA_METRIC_LOCAL_TYPE_PLDDT, MA_QA_METRIC_LOCAL_TYPE_PLDDT_ALL-ATOM, MA_QA_METRIC_LOCAL_TYPE_PLDDT_ALL-ATOM_[0,1], MA_QA_METRIC_LOCAL_TYPE_PLDDT_[0,1], MA_QA_METRIC_LOCAL_TYPE_PTM, MA_QA_METRIC_LOCAL_TYPE_ZSCORE, MEMBRANE_SEGMENT, MOGUL_ANGLE_OUTLIER, MOGUL_BOND_OUTLIER, N-GLYCOSYLATION_SITE, O-GLYCOSYLATION_SITE, RAMACHANDRAN_OUTLIER, ROTAMER_OUTLIER, RSCC_OUTLIER, RSRZ_OUTLIER, S-GLYCOSYLATION_SITE, SABDAB_ANTIBODY_HEAVY_CHAIN_SUBCLASS, SABDAB_ANTIBODY_LIGHT_CHAIN_SUBCLASS, SABDAB_ANTIBODY_LIGHT_CHAIN_TYPE, SCOP, SCOP2B_SUPERFAMILY, SCOP2_FAMILY, SCOP2_SUPERFAMILY, SHEET, STEREO_OUTLIER, STRN, TURN_TY1_P, UNASSIGNED_SEC_STRUCT, UNOBSERVED_ATOM_XYZ, UNOBSERVED_RESIDUE_XYZ, ZERO_OCCUPANCY_ATOM_XYZ, ZERO_OCCUPANCY_RESIDUE_XYZ
|
||||
*
|
||||
*/
|
||||
readonly type?: Maybe<Scalars['String']>;
|
||||
@@ -13377,6 +13516,11 @@ export type ReflnsShell = {
|
||||
};
|
||||
|
||||
export type Software = {
|
||||
/**
|
||||
* This data item is a pointer to _citation.id in the CITATION
|
||||
* category.
|
||||
*/
|
||||
readonly citation_id?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* The classification of the program according to its
|
||||
* major function.
|
||||
@@ -13527,6 +13671,37 @@ export type Struct = {
|
||||
readonly title?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
export type StructAsym = {
|
||||
/**
|
||||
* This data item is a pointer to _atom_site.pdbx_PDB_strand_id the
|
||||
* ATOM_SITE category.
|
||||
*
|
||||
* Examples:
|
||||
* 1ABC
|
||||
*
|
||||
*/
|
||||
readonly pdbx_PDB_id?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* This data item is a pointer to _atom_site.ndb_alias_strand_id the
|
||||
* ATOM_SITE category.
|
||||
*/
|
||||
readonly pdbx_alt_id?: Maybe<Scalars['String']>;
|
||||
/**
|
||||
* This data item gives the order of the structural elements in the
|
||||
* ATOM_SITE category.
|
||||
*/
|
||||
readonly pdbx_order?: Maybe<Scalars['Int']>;
|
||||
/**
|
||||
* This data item describes the general type of the structural elements
|
||||
* in the ATOM_SITE category.
|
||||
*
|
||||
* Allowable values:
|
||||
* ATOMN, ATOMP, ATOMS, HETAC, HETAD, HETAI, HETAIN, HETAS, HETIC
|
||||
*
|
||||
*/
|
||||
readonly pdbx_type?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
export type StructKeywords = {
|
||||
/**
|
||||
* Terms characterizing the macromolecular structure.
|
||||
|
||||
103
src/extensions/volumes-and-segmentations/entry-meshes.ts
Normal file
103
src/extensions/volumes-and-segmentations/entry-meshes.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { PluginStateObject } from '../../mol-plugin-state/objects';
|
||||
import { CreateGroup } from '../../mol-plugin-state/transforms/misc';
|
||||
import { ShapeRepresentation3D } from '../../mol-plugin-state/transforms/representation';
|
||||
import { setSubtreeVisibility } from '../../mol-plugin/behavior/static/state';
|
||||
import { PluginCommands } from '../../mol-plugin/commands';
|
||||
import { Color } from '../../mol-util/color';
|
||||
import { ColorNames } from '../../mol-util/color/names';
|
||||
|
||||
import { BACKGROUND_SEGMENT_VOLUME_THRESHOLD } from '../meshes/mesh-streaming/behavior';
|
||||
import { createMeshFromUrl } from '../meshes/mesh-extension';
|
||||
|
||||
import { Segment } from './volseg-api/data';
|
||||
import { VolsegEntryData } from './entry-root';
|
||||
|
||||
|
||||
const DEFAULT_MESH_DETAIL: number | null = 5; // null means worst
|
||||
|
||||
|
||||
export class VolsegMeshSegmentationData {
|
||||
private entryData: VolsegEntryData;
|
||||
|
||||
constructor(rootData: VolsegEntryData) {
|
||||
this.entryData = rootData;
|
||||
}
|
||||
|
||||
async loadSegmentation() {
|
||||
const hasMeshes = this.entryData.metadata.meshSegmentIds.length > 0;
|
||||
if (hasMeshes) {
|
||||
await this.showSegments(this.entryData.metadata.allSegmentIds);
|
||||
}
|
||||
}
|
||||
|
||||
updateOpacity(opacity: number) {
|
||||
const visuals = this.entryData.findNodesByTags('mesh-segment-visual');
|
||||
const update = this.entryData.newUpdate();
|
||||
for (const visual of visuals) {
|
||||
update.to(visual).update(ShapeRepresentation3D, p => { (p as any).alpha = opacity; });
|
||||
}
|
||||
return update.commit();
|
||||
}
|
||||
|
||||
async highlightSegment(segment: Segment) {
|
||||
const visuals = this.entryData.findNodesByTags('mesh-segment-visual', `segment-${segment.id}`);
|
||||
for (const visual of visuals) {
|
||||
await PluginCommands.Interactivity.Object.Highlight(this.entryData.plugin, { state: this.entryData.plugin.state.data, ref: visual.transform.ref });
|
||||
}
|
||||
}
|
||||
|
||||
async selectSegment(segment?: number) {
|
||||
if (segment === undefined || segment < 0) return;
|
||||
const visuals = this.entryData.findNodesByTags('mesh-segment-visual', `segment-${segment}`);
|
||||
const reprNode: PluginStateObject.Shape.Representation3D | undefined = visuals[0]?.obj;
|
||||
if (!reprNode) return;
|
||||
const loci = reprNode.data.repr.getAllLoci()[0];
|
||||
if (!loci) return;
|
||||
this.entryData.plugin.managers.interactivity.lociSelects.select({ loci: loci, repr: reprNode.data.repr }, false);
|
||||
}
|
||||
|
||||
/** Make visible the specified set of mesh segments */
|
||||
async showSegments(segments: number[]) {
|
||||
const segmentsToShow = new Set(segments);
|
||||
|
||||
const visuals = this.entryData.findNodesByTags('mesh-segment-visual');
|
||||
for (const visual of visuals) {
|
||||
const theTag = visual.obj?.tags?.find(tag => tag.startsWith('segment-'));
|
||||
if (!theTag) continue;
|
||||
const id = parseInt(theTag.split('-')[1]);
|
||||
const visibility = segmentsToShow.has(id);
|
||||
setSubtreeVisibility(this.entryData.plugin.state.data, visual.transform.ref, !visibility); // true means hide, ¯\_(ツ)_/¯
|
||||
segmentsToShow.delete(id);
|
||||
}
|
||||
|
||||
const segmentsToCreate = this.entryData.metadata.meshSegmentIds.filter(seg => segmentsToShow.has(seg));
|
||||
if (segmentsToCreate.length === 0) return;
|
||||
|
||||
let group = this.entryData.findNodesByTags('mesh-segmentation-group')[0]?.transform.ref;
|
||||
if (!group) {
|
||||
const newGroupNode = await this.entryData.newUpdate().apply(CreateGroup, { label: 'Segmentation', description: 'Mesh' }, { tags: ['mesh-segmentation-group'], state: { isCollapsed: true } }).commit();
|
||||
group = newGroupNode.ref;
|
||||
}
|
||||
const totalVolume = this.entryData.metadata.gridTotalVolume;
|
||||
|
||||
const awaiting = [];
|
||||
for (const seg of segmentsToCreate) {
|
||||
const segment = this.entryData.metadata.getSegment(seg);
|
||||
if (!segment) continue;
|
||||
const detail = this.entryData.metadata.getSufficientMeshDetail(seg, DEFAULT_MESH_DETAIL);
|
||||
const color = segment.colour.length >= 3 ? Color.fromNormalizedArray(segment.colour, 0) : ColorNames.gray;
|
||||
const url = this.entryData.api.meshUrl_Bcif(this.entryData.source, this.entryData.entryId, seg, detail);
|
||||
const label = segment.biological_annotation.name ?? `Segment ${seg}`;
|
||||
const meshPromise = createMeshFromUrl(this.entryData.plugin, url, seg, detail, true, color, group,
|
||||
BACKGROUND_SEGMENT_VOLUME_THRESHOLD * totalVolume, `<b>${label}</b>`, this.entryData.ref);
|
||||
awaiting.push(meshPromise);
|
||||
}
|
||||
for (const promise of awaiting) await promise;
|
||||
}
|
||||
}
|
||||
60
src/extensions/volumes-and-segmentations/entry-models.ts
Normal file
60
src/extensions/volumes-and-segmentations/entry-models.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { Download, ParseCif } from '../../mol-plugin-state/transforms/data';
|
||||
import { CreateGroup } from '../../mol-plugin-state/transforms/misc';
|
||||
import { TrajectoryFromMmCif } from '../../mol-plugin-state/transforms/model';
|
||||
import { setSubtreeVisibility } from '../../mol-plugin/behavior/static/state';
|
||||
import { StateObjectRef, StateObjectSelector } from '../../mol-state';
|
||||
|
||||
import { VolsegEntryData } from './entry-root';
|
||||
|
||||
|
||||
export class VolsegModelData {
|
||||
private entryData: VolsegEntryData;
|
||||
|
||||
constructor(rootData: VolsegEntryData) {
|
||||
this.entryData = rootData;
|
||||
}
|
||||
|
||||
private async loadPdb(pdbId: string, parent: StateObjectSelector | StateObjectRef) {
|
||||
const url = `https://www.ebi.ac.uk/pdbe/entry-files/download/${pdbId}.bcif`;
|
||||
const dataNode = await this.entryData.plugin.build().to(parent).apply(Download, { url: url, isBinary: true }, { tags: ['fitted-model-data', `pdbid-${pdbId}`] }).commit();
|
||||
const cifNode = await this.entryData.plugin.build().to(dataNode).apply(ParseCif).commit();
|
||||
const trajectoryNode = await this.entryData.plugin.build().to(cifNode).apply(TrajectoryFromMmCif).commit();
|
||||
await this.entryData.plugin.builders.structure.hierarchy.applyPreset(trajectoryNode, 'default', { representationPreset: 'polymer-cartoon' });
|
||||
return dataNode;
|
||||
}
|
||||
|
||||
async showPdbs(pdbIds: string[]) {
|
||||
const segmentsToShow = new Set(pdbIds);
|
||||
|
||||
const visuals = this.entryData.findNodesByTags('fitted-model-data');
|
||||
for (const visual of visuals) {
|
||||
const theTag = visual.obj?.tags?.find(tag => tag.startsWith('pdbid-'));
|
||||
if (!theTag) continue;
|
||||
const id = theTag.split('-')[1];
|
||||
const visibility = segmentsToShow.has(id);
|
||||
setSubtreeVisibility(this.entryData.plugin.state.data, visual.transform.ref, !visibility); // true means hide, ¯\_(ツ)_/¯
|
||||
segmentsToShow.delete(id);
|
||||
}
|
||||
|
||||
const segmentsToCreate = Array.from(segmentsToShow);
|
||||
if (segmentsToCreate.length === 0) return;
|
||||
|
||||
let group = this.entryData.findNodesByTags('fitted-models-group')[0]?.transform.ref;
|
||||
if (!group) {
|
||||
const newGroupNode = await this.entryData.newUpdate().apply(CreateGroup, { label: 'Fitted Models' }, { tags: ['fitted-models-group'], state: { isCollapsed: true } }).commit();
|
||||
group = newGroupNode.ref;
|
||||
}
|
||||
|
||||
const awaiting = [];
|
||||
for (const pdbId of segmentsToCreate) {
|
||||
awaiting.push(this.loadPdb(pdbId, group));
|
||||
}
|
||||
for (const promise of awaiting) await promise;
|
||||
}
|
||||
}
|
||||
377
src/extensions/volumes-and-segmentations/entry-root.ts
Normal file
377
src/extensions/volumes-and-segmentations/entry-root.ts
Normal file
@@ -0,0 +1,377 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { BehaviorSubject, distinctUntilChanged, Subject, throttleTime } from 'rxjs';
|
||||
import { VolsegVolumeServerConfig } from '.';
|
||||
import { Loci } from '../../mol-model/loci';
|
||||
|
||||
import { ShapeGroup } from '../../mol-model/shape';
|
||||
import { Volume } from '../../mol-model/volume';
|
||||
import { LociLabelProvider } from '../../mol-plugin-state/manager/loci-label';
|
||||
import { PluginStateObject } from '../../mol-plugin-state/objects';
|
||||
import { PluginBehavior } from '../../mol-plugin/behavior';
|
||||
import { PluginCommands } from '../../mol-plugin/commands';
|
||||
import { PluginContext } from '../../mol-plugin/context';
|
||||
import { StateObjectCell, StateSelection, StateTransform } from '../../mol-state';
|
||||
import { shallowEqualObjects } from '../../mol-util';
|
||||
import { ParamDefinition } from '../../mol-util/param-definition';
|
||||
import { MeshlistData } from '../meshes/mesh-extension';
|
||||
|
||||
import { DEFAULT_VOLSEG_SERVER, VolumeApiV2 } from './volseg-api/api';
|
||||
import { Segment } from './volseg-api/data';
|
||||
import { MetadataWrapper } from './volseg-api/utils';
|
||||
import { VolsegMeshSegmentationData } from './entry-meshes';
|
||||
import { VolsegModelData } from './entry-models';
|
||||
import { VolsegLatticeSegmentationData } from './entry-segmentation';
|
||||
import { VolsegState, VolsegStateData, VolsegStateParams } from './entry-state';
|
||||
import { VolsegVolumeData, SimpleVolumeParamValues, VOLUME_VISUAL_TAG } from './entry-volume';
|
||||
import * as ExternalAPIs from './external-api';
|
||||
import { VolsegGlobalStateData } from './global-state';
|
||||
import { applyEllipsis, Choice, isDefined, lazyGetter, splitEntryId } from './helpers';
|
||||
import { type VolsegStateFromEntry } from './transformers';
|
||||
import { StateTransforms } from '../../mol-plugin-state/transforms';
|
||||
|
||||
|
||||
export const MAX_VOXELS = 10 ** 7;
|
||||
// export const MAX_VOXELS = 10 ** 2; // DEBUG
|
||||
export const BOX: [[number, number, number], [number, number, number]] | null = null;
|
||||
// export const BOX: [[number, number, number], [number, number, number]] | null = [[-90, -90, -90], [90, 90, 90]]; // DEBUG
|
||||
|
||||
const MAX_ANNOTATIONS_IN_LABEL = 6;
|
||||
|
||||
|
||||
const SourceChoice = new Choice({ emdb: 'EMDB', empiar: 'EMPIAR', idr: 'IDR' }, 'emdb');
|
||||
export type Source = Choice.Values<typeof SourceChoice>;
|
||||
|
||||
|
||||
export function createLoadVolsegParams(plugin?: PluginContext, entrylists: { [source: string]: string[] } = {}) {
|
||||
const defaultVolumeServer = plugin?.config.get(VolsegVolumeServerConfig.DefaultServer) ?? DEFAULT_VOLSEG_SERVER;
|
||||
return {
|
||||
serverUrl: ParamDefinition.Text(defaultVolumeServer),
|
||||
source: ParamDefinition.Mapped(SourceChoice.values[0], SourceChoice.options, src => entryParam(entrylists[src])),
|
||||
};
|
||||
}
|
||||
function entryParam(entries: string[] = []) {
|
||||
const options: [string, string][] = entries.map(e => [e, e]);
|
||||
options.push(['__custom__', 'Custom']);
|
||||
return ParamDefinition.Group({
|
||||
entryId: ParamDefinition.Select(options[0][0], options, { description: 'Choose an entry from the list, or choose "Custom" and type any entry ID (useful when using other than default server).' }),
|
||||
customEntryId: ParamDefinition.Text('', { hideIf: p => p.entryId !== '__custom__', description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }),
|
||||
}, { isFlat: true });
|
||||
}
|
||||
type LoadVolsegParamValues = ParamDefinition.Values<ReturnType<typeof createLoadVolsegParams>>;
|
||||
|
||||
export function createVolsegEntryParams(plugin?: PluginContext) {
|
||||
const defaultVolumeServer = plugin?.config.get(VolsegVolumeServerConfig.DefaultServer) ?? DEFAULT_VOLSEG_SERVER;
|
||||
return {
|
||||
serverUrl: ParamDefinition.Text(defaultVolumeServer),
|
||||
source: SourceChoice.PDSelect(),
|
||||
entryId: ParamDefinition.Text('emd-1832', { description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }),
|
||||
};
|
||||
}
|
||||
type VolsegEntryParamValues = ParamDefinition.Values<ReturnType<typeof createVolsegEntryParams>>;
|
||||
|
||||
export namespace VolsegEntryParamValues {
|
||||
export function fromLoadVolsegParamValues(params: LoadVolsegParamValues): VolsegEntryParamValues {
|
||||
let entryId = (params.source.params as any).entryId;
|
||||
if (entryId === '__custom__') {
|
||||
entryId = (params.source.params as any).customEntryId;
|
||||
}
|
||||
return {
|
||||
serverUrl: params.serverUrl,
|
||||
source: params.source.name as Source,
|
||||
entryId: entryId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class VolsegEntry extends PluginStateObject.CreateBehavior<VolsegEntryData>({ name: 'Vol & Seg Entry' }) { }
|
||||
|
||||
type VolRepr3DT = typeof StateTransforms.Representation.VolumeRepresentation3D
|
||||
|
||||
export class VolsegEntryData extends PluginBehavior.WithSubscribers<VolsegEntryParamValues> {
|
||||
plugin: PluginContext;
|
||||
ref: string = '';
|
||||
api: VolumeApiV2;
|
||||
source: Source;
|
||||
/** Number part of entry ID; e.g. '1832' */
|
||||
entryNumber: string;
|
||||
/** Full entry ID; e.g. 'emd-1832' */
|
||||
entryId: string;
|
||||
metadata: MetadataWrapper;
|
||||
pdbs: string[];
|
||||
|
||||
public readonly volumeData = new VolsegVolumeData(this);
|
||||
private readonly latticeSegmentationData = new VolsegLatticeSegmentationData(this);
|
||||
private readonly meshSegmentationData = new VolsegMeshSegmentationData(this);
|
||||
private readonly modelData = new VolsegModelData(this);
|
||||
private highlightRequest = new Subject<Segment | undefined>();
|
||||
|
||||
private getStateNode = lazyGetter(() => this.plugin.state.data.selectQ(q => q.byRef(this.ref).subtree().ofType(VolsegState))[0] as StateObjectCell<VolsegState, StateTransform<typeof VolsegStateFromEntry>>, 'Missing VolsegState node. Must first create VolsegState for this VolsegEntry.');
|
||||
public currentState = new BehaviorSubject(ParamDefinition.getDefaultValues(VolsegStateParams));
|
||||
public currentVolume = new BehaviorSubject<StateTransform<VolRepr3DT> | undefined>(undefined);
|
||||
|
||||
|
||||
private constructor(plugin: PluginContext, params: VolsegEntryParamValues) {
|
||||
super(plugin, params);
|
||||
this.plugin = plugin;
|
||||
this.api = new VolumeApiV2(params.serverUrl);
|
||||
this.source = params.source;
|
||||
this.entryId = params.entryId;
|
||||
this.entryNumber = splitEntryId(this.entryId).entryNumber;
|
||||
}
|
||||
|
||||
private async initialize() {
|
||||
const metadata = await this.api.getMetadata(this.source, this.entryId);
|
||||
this.metadata = new MetadataWrapper(metadata);
|
||||
this.pdbs = await ExternalAPIs.getPdbIdsForEmdbEntry(this.metadata.raw.grid.general.source_db_id ?? this.entryId);
|
||||
// TODO use Asset?
|
||||
}
|
||||
|
||||
static async create(plugin: PluginContext, params: VolsegEntryParamValues) {
|
||||
const result = new VolsegEntryData(plugin, params);
|
||||
await result.initialize();
|
||||
return result;
|
||||
}
|
||||
|
||||
async register(ref: string) {
|
||||
this.ref = ref;
|
||||
this.plugin.managers.lociLabels.addProvider(this.labelProvider);
|
||||
|
||||
try {
|
||||
const params = this.getStateNode().obj?.data;
|
||||
if (params) {
|
||||
this.currentState.next(params);
|
||||
}
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const volumeVisual = this.findNodesByTags(VOLUME_VISUAL_TAG)[0];
|
||||
if (volumeVisual) this.currentVolume.next(volumeVisual.transform);
|
||||
|
||||
let volumeRef: string | undefined;
|
||||
this.subscribeObservable(this.plugin.state.data.events.cell.stateUpdated, e => {
|
||||
try { (this.getStateNode()); } catch { return; } // if state not does not exist yet
|
||||
if (e.cell.transform.ref === this.getStateNode().transform.ref) {
|
||||
const newState = this.getStateNode().obj?.data;
|
||||
if (newState && !shallowEqualObjects(newState, this.currentState.value)) { // avoid repeated update
|
||||
this.currentState.next(newState);
|
||||
}
|
||||
} else if (e.cell.transform.tags?.includes(VOLUME_VISUAL_TAG)) {
|
||||
if (e.ref === volumeRef) {
|
||||
this.currentVolume.next(e.cell.transform);
|
||||
} else if (StateSelection.findAncestor(this.plugin.state.data.tree, this.plugin.state.data.cells, e.ref, a => a.transform.ref === ref)) {
|
||||
volumeRef = e.ref;
|
||||
this.currentVolume.next(e.cell.transform);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.subscribeObservable(this.plugin.state.data.events.cell.removed, e => {
|
||||
if (e.ref === volumeRef) {
|
||||
volumeRef = undefined;
|
||||
this.currentVolume.next(undefined);
|
||||
}
|
||||
});
|
||||
|
||||
this.subscribeObservable(this.plugin.behaviors.interaction.click, async e => {
|
||||
const loci = e.current.loci;
|
||||
const clickedSegment = this.getSegmentIdFromLoci(loci);
|
||||
if (clickedSegment === undefined) return;
|
||||
if (clickedSegment === this.currentState.value.selectedSegment) {
|
||||
this.actionSelectSegment(undefined);
|
||||
} else {
|
||||
this.actionSelectSegment(clickedSegment);
|
||||
}
|
||||
});
|
||||
|
||||
this.subscribeObservable(
|
||||
this.highlightRequest.pipe(throttleTime(50, undefined, { leading: true, trailing: true })),
|
||||
async segment => await this.highlightSegment(segment)
|
||||
);
|
||||
|
||||
this.subscribeObservable(
|
||||
this.currentState.pipe(distinctUntilChanged((a, b) => a.selectedSegment === b.selectedSegment)),
|
||||
async state => {
|
||||
if (VolsegGlobalStateData.getGlobalState(this.plugin)?.selectionMode) await this.selectSegment(state.selectedSegment);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async unregister() {
|
||||
this.plugin.managers.lociLabels.removeProvider(this.labelProvider);
|
||||
}
|
||||
|
||||
async loadVolume() {
|
||||
const result = await this.volumeData.loadVolume();
|
||||
if (result) {
|
||||
const isovalue = result.isovalue.kind === 'relative' ? result.isovalue.relativeValue : result.isovalue.absoluteValue;
|
||||
await this.updateStateNode({ volumeIsovalueKind: result.isovalue.kind, volumeIsovalueValue: isovalue });
|
||||
}
|
||||
}
|
||||
|
||||
async loadSegmentations() {
|
||||
await this.latticeSegmentationData.loadSegmentation();
|
||||
await this.meshSegmentationData.loadSegmentation();
|
||||
await this.actionShowSegments(this.metadata.allSegmentIds);
|
||||
}
|
||||
|
||||
|
||||
actionHighlightSegment(segment?: Segment) {
|
||||
this.highlightRequest.next(segment);
|
||||
}
|
||||
|
||||
async actionToggleSegment(segment: number) {
|
||||
const current = this.currentState.value.visibleSegments.map(seg => seg.segmentId);
|
||||
if (current.includes(segment)) {
|
||||
await this.actionShowSegments(current.filter(s => s !== segment));
|
||||
} else {
|
||||
await this.actionShowSegments([...current, segment]);
|
||||
}
|
||||
}
|
||||
|
||||
async actionToggleAllSegments() {
|
||||
const current = this.currentState.value.visibleSegments.map(seg => seg.segmentId);
|
||||
if (current.length !== this.metadata.allSegments.length) {
|
||||
await this.actionShowSegments(this.metadata.allSegmentIds);
|
||||
} else {
|
||||
await this.actionShowSegments([]);
|
||||
}
|
||||
}
|
||||
|
||||
async actionSelectSegment(segment?: number) {
|
||||
if (segment !== undefined && this.currentState.value.visibleSegments.find(s => s.segmentId === segment) === undefined) {
|
||||
// first make the segment visible if it is not
|
||||
await this.actionToggleSegment(segment);
|
||||
}
|
||||
await this.updateStateNode({ selectedSegment: segment });
|
||||
}
|
||||
|
||||
async actionSetOpacity(opacity: number) {
|
||||
if (opacity === this.getStateNode().obj?.data.segmentOpacity) return;
|
||||
this.latticeSegmentationData.updateOpacity(opacity);
|
||||
this.meshSegmentationData.updateOpacity(opacity);
|
||||
|
||||
await this.updateStateNode({ segmentOpacity: opacity });
|
||||
}
|
||||
|
||||
async actionShowFittedModel(pdbIds: string[]) {
|
||||
await this.modelData.showPdbs(pdbIds);
|
||||
await this.updateStateNode({ visibleModels: pdbIds.map(pdbId => ({ pdbId: pdbId })) });
|
||||
}
|
||||
|
||||
async actionSetVolumeVisual(type: 'isosurface' | 'direct-volume' | 'off') {
|
||||
await this.volumeData.setVolumeVisual(type);
|
||||
await this.updateStateNode({ volumeType: type });
|
||||
}
|
||||
|
||||
async actionUpdateVolumeVisual(params: SimpleVolumeParamValues) {
|
||||
await this.volumeData.updateVolumeVisual(params);
|
||||
await this.updateStateNode({
|
||||
volumeType: params.volumeType,
|
||||
volumeOpacity: params.opacity,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private async actionShowSegments(segments: number[]) {
|
||||
await this.latticeSegmentationData.showSegments(segments);
|
||||
await this.meshSegmentationData.showSegments(segments);
|
||||
await this.updateStateNode({ visibleSegments: segments.map(s => ({ segmentId: s })) });
|
||||
}
|
||||
|
||||
private async highlightSegment(segment?: Segment) {
|
||||
await PluginCommands.Interactivity.ClearHighlights(this.plugin);
|
||||
if (segment) {
|
||||
await this.latticeSegmentationData.highlightSegment(segment);
|
||||
await this.meshSegmentationData.highlightSegment(segment);
|
||||
}
|
||||
}
|
||||
|
||||
private async selectSegment(segment: number) {
|
||||
this.plugin.managers.interactivity.lociSelects.deselectAll();
|
||||
await this.latticeSegmentationData.selectSegment(segment);
|
||||
await this.meshSegmentationData.selectSegment(segment);
|
||||
await this.highlightSegment();
|
||||
}
|
||||
|
||||
private async updateStateNode(params: Partial<VolsegStateData>) {
|
||||
const oldParams = this.getStateNode().transform.params;
|
||||
const newParams = { ...oldParams, ...params };
|
||||
const state = this.plugin.state.data;
|
||||
const update = state.build().to(this.getStateNode().transform.ref).update(newParams);
|
||||
await PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotUpdateCurrent: true } });
|
||||
}
|
||||
|
||||
|
||||
/** Find the nodes under this entry root which have all of the given tags. */
|
||||
findNodesByTags(...tags: string[]) {
|
||||
return this.plugin.state.data.selectQ(q => {
|
||||
let builder = q.byRef(this.ref).subtree();
|
||||
for (const tag of tags) builder = builder.withTag(tag);
|
||||
return builder;
|
||||
});
|
||||
}
|
||||
|
||||
newUpdate() {
|
||||
if (this.ref !== '') {
|
||||
return this.plugin.build().to(this.ref);
|
||||
} else {
|
||||
return this.plugin.build().toRoot();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly labelProvider: LociLabelProvider = {
|
||||
label: (loci: Loci): string | undefined => {
|
||||
const segmentId = this.getSegmentIdFromLoci(loci);
|
||||
if (segmentId === undefined) return;
|
||||
const segment = this.metadata.getSegment(segmentId);
|
||||
if (!segment) return;
|
||||
const annotLabels = segment.biological_annotation.external_references.map(annot => `${applyEllipsis(annot.label)} [${annot.resource}:${annot.accession}]`);
|
||||
if (annotLabels.length === 0) return;
|
||||
if (annotLabels.length > MAX_ANNOTATIONS_IN_LABEL + 1) {
|
||||
const nHidden = annotLabels.length - MAX_ANNOTATIONS_IN_LABEL;
|
||||
annotLabels.length = MAX_ANNOTATIONS_IN_LABEL;
|
||||
annotLabels.push(`(${nHidden} more annotations, click on the segment to see all)`);
|
||||
}
|
||||
return '<hr class="msp-highlight-info-hr"/>' + annotLabels.filter(isDefined).join('<br/>');
|
||||
}
|
||||
};
|
||||
|
||||
private getSegmentIdFromLoci(loci: Loci): number | undefined {
|
||||
if (Volume.Segment.isLoci(loci) && loci.volume._propertyData.ownerId === this.ref) {
|
||||
if (loci.segments.length === 1) {
|
||||
return loci.segments[0];
|
||||
}
|
||||
}
|
||||
if (ShapeGroup.isLoci(loci)) {
|
||||
const meshData = (loci.shape.sourceData ?? {}) as MeshlistData;
|
||||
if (meshData.ownerId === this.ref && meshData.segmentId !== undefined) {
|
||||
return meshData.segmentId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async setTryUseGpu(tryUseGpu: boolean) {
|
||||
await Promise.all([
|
||||
this.volumeData.setTryUseGpu(tryUseGpu),
|
||||
this.latticeSegmentationData.setTryUseGpu(tryUseGpu),
|
||||
]);
|
||||
}
|
||||
async setSelectionMode(selectSegments: boolean) {
|
||||
if (selectSegments) {
|
||||
await this.selectSegment(this.currentState.value.selectedSegment);
|
||||
} else {
|
||||
this.plugin.managers.interactivity.lociSelects.deselectAll();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
131
src/extensions/volumes-and-segmentations/entry-segmentation.ts
Normal file
131
src/extensions/volumes-and-segmentations/entry-segmentation.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { Volume } from '../../mol-model/volume';
|
||||
import { createVolumeRepresentationParams } from '../../mol-plugin-state/helpers/volume-representation-params';
|
||||
import { StateTransforms } from '../../mol-plugin-state/transforms';
|
||||
import { Download, ParseCif } from '../../mol-plugin-state/transforms/data';
|
||||
import { CreateGroup } from '../../mol-plugin-state/transforms/misc';
|
||||
import { VolumeFromSegmentationCif } from '../../mol-plugin-state/transforms/volume';
|
||||
import { PluginCommands } from '../../mol-plugin/commands';
|
||||
import { Color } from '../../mol-util/color';
|
||||
|
||||
import { Segment } from './volseg-api/data';
|
||||
import { BOX, VolsegEntryData, MAX_VOXELS } from './entry-root';
|
||||
import { VolumeVisualParams } from './entry-volume';
|
||||
import { VolsegGlobalStateData } from './global-state';
|
||||
|
||||
|
||||
const GROUP_TAG = 'lattice-segmentation-group';
|
||||
const SEGMENT_VISUAL_TAG = 'lattice-segment-visual';
|
||||
|
||||
const DEFAULT_SEGMENT_COLOR = Color.fromNormalizedRgb(0.8, 0.8, 0.8);
|
||||
|
||||
|
||||
export class VolsegLatticeSegmentationData {
|
||||
private entryData: VolsegEntryData;
|
||||
|
||||
constructor(rootData: VolsegEntryData) {
|
||||
this.entryData = rootData;
|
||||
}
|
||||
|
||||
async loadSegmentation() {
|
||||
const hasLattices = this.entryData.metadata.raw.grid.segmentation_lattices.segmentation_lattice_ids.length > 0;
|
||||
if (hasLattices) {
|
||||
const url = this.entryData.api.latticeUrl(this.entryData.source, this.entryData.entryId, 0, BOX, MAX_VOXELS);
|
||||
let group = this.entryData.findNodesByTags(GROUP_TAG)[0]?.transform.ref;
|
||||
if (!group) {
|
||||
const newGroupNode = await this.entryData.newUpdate().apply(CreateGroup,
|
||||
{ label: 'Segmentation', description: 'Lattice' }, { tags: [GROUP_TAG], state: { isCollapsed: true } }).commit();
|
||||
group = newGroupNode.ref;
|
||||
}
|
||||
const segmentLabels = this.entryData.metadata.allSegments.map(seg => ({ id: seg.id, label: seg.biological_annotation.name ? `<b>${seg.biological_annotation.name}</b>` : '' }));
|
||||
const volumeNode = await this.entryData.newUpdate().to(group)
|
||||
.apply(Download, { url, isBinary: true, label: `Segmentation Data: ${url}` })
|
||||
.apply(ParseCif)
|
||||
.apply(VolumeFromSegmentationCif, { blockHeader: 'SEGMENTATION_DATA', segmentLabels: segmentLabels, ownerId: this.entryData.ref })
|
||||
.commit();
|
||||
const volumeData = volumeNode.data as Volume;
|
||||
const segmentation = Volume.Segmentation.get(volumeData);
|
||||
const segmentIds: number[] = Array.from(segmentation?.segments.keys() ?? []);
|
||||
await this.entryData.newUpdate().to(volumeNode)
|
||||
.apply(StateTransforms.Representation.VolumeRepresentation3D, createVolumeRepresentationParams(this.entryData.plugin, volumeData, {
|
||||
type: 'segment',
|
||||
typeParams: { tryUseGpu: VolsegGlobalStateData.getGlobalState(this.entryData.plugin)?.tryUseGpu },
|
||||
color: 'volume-segment',
|
||||
colorParams: { palette: this.createPalette(segmentIds) },
|
||||
}), { tags: [SEGMENT_VISUAL_TAG] }).commit();
|
||||
}
|
||||
}
|
||||
|
||||
private createPalette(segmentIds: number[]) {
|
||||
const colorMap = new Map<number, Color>();
|
||||
for (const segment of this.entryData.metadata.allSegments) {
|
||||
const color = Color.fromNormalizedArray(segment.colour, 0);
|
||||
colorMap.set(segment.id, color);
|
||||
}
|
||||
if (colorMap.size === 0) return undefined;
|
||||
for (const segid of segmentIds) {
|
||||
colorMap.get(segid);
|
||||
}
|
||||
const colors = segmentIds.map(segid => colorMap.get(segid) ?? DEFAULT_SEGMENT_COLOR);
|
||||
return { name: 'colors' as const, params: { list: { kind: 'set' as const, colors: colors } } };
|
||||
}
|
||||
|
||||
async updateOpacity(opacity: number) {
|
||||
const reprs = this.entryData.findNodesByTags(SEGMENT_VISUAL_TAG);
|
||||
const update = this.entryData.newUpdate();
|
||||
for (const s of reprs) {
|
||||
update.to(s).update(StateTransforms.Representation.VolumeRepresentation3D, p => { p.type.params.alpha = opacity; });
|
||||
}
|
||||
return await update.commit();
|
||||
}
|
||||
private makeLoci(segments: number[]) {
|
||||
const vis = this.entryData.findNodesByTags(SEGMENT_VISUAL_TAG)[0];
|
||||
if (!vis) return undefined;
|
||||
const repr = vis.obj?.data.repr;
|
||||
const wholeLoci = repr.getAllLoci()[0];
|
||||
if (!wholeLoci || !Volume.Segment.isLoci(wholeLoci)) return undefined;
|
||||
return { loci: Volume.Segment.Loci(wholeLoci.volume, segments), repr: repr };
|
||||
}
|
||||
async highlightSegment(segment: Segment) {
|
||||
const segmentLoci = this.makeLoci([segment.id]);
|
||||
if (!segmentLoci) return;
|
||||
this.entryData.plugin.managers.interactivity.lociHighlights.highlight(segmentLoci, false);
|
||||
}
|
||||
async selectSegment(segment?: number) {
|
||||
if (segment === undefined || segment < 0) return;
|
||||
const segmentLoci = this.makeLoci([segment]);
|
||||
if (!segmentLoci) return;
|
||||
this.entryData.plugin.managers.interactivity.lociSelects.select(segmentLoci, false);
|
||||
}
|
||||
|
||||
/** Make visible the specified set of lattice segments */
|
||||
async showSegments(segments: number[]) {
|
||||
const repr = this.entryData.findNodesByTags(SEGMENT_VISUAL_TAG)[0];
|
||||
if (!repr) return;
|
||||
const selectedSegment = this.entryData.currentState.value.selectedSegment;
|
||||
const mustReselect = segments.includes(selectedSegment) && !repr.params?.values.type.params.segments.includes(selectedSegment);
|
||||
const update = this.entryData.newUpdate();
|
||||
update.to(repr).update(StateTransforms.Representation.VolumeRepresentation3D, p => { p.type.params.segments = segments; });
|
||||
await update.commit();
|
||||
if (mustReselect) {
|
||||
await this.selectSegment(this.entryData.currentState.value.selectedSegment);
|
||||
}
|
||||
}
|
||||
|
||||
async setTryUseGpu(tryUseGpu: boolean) {
|
||||
const visuals = this.entryData.findNodesByTags(SEGMENT_VISUAL_TAG);
|
||||
for (const visual of visuals) {
|
||||
const oldParams: VolumeVisualParams = visual.transform.params;
|
||||
if (oldParams.type.params.tryUseGpu === !tryUseGpu) {
|
||||
const newParams = { ...oldParams, type: { ...oldParams.type, params: { ...oldParams.type.params, tryUseGpu: tryUseGpu } } };
|
||||
const update = this.entryData.newUpdate().to(visual.transform.ref).update(newParams);
|
||||
await PluginCommands.State.Update(this.entryData.plugin, { state: this.entryData.plugin.state.data, tree: update, options: { doNotUpdateCurrent: true } });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/extensions/volumes-and-segmentations/entry-state.ts
Normal file
33
src/extensions/volumes-and-segmentations/entry-state.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { PluginStateObject } from '../../mol-plugin-state/objects';
|
||||
import { ParamDefinition as PD } from '../../mol-util/param-definition';
|
||||
|
||||
import { Choice } from './helpers';
|
||||
|
||||
|
||||
export const VolumeTypeChoice = new Choice({ 'isosurface': 'Isosurface', 'direct-volume': 'Direct volume', 'off': 'Off' }, 'isosurface');
|
||||
export type VolumeType = Choice.Values<typeof VolumeTypeChoice>
|
||||
|
||||
|
||||
export const VolsegStateParams = {
|
||||
volumeType: VolumeTypeChoice.PDSelect(),
|
||||
volumeIsovalueKind: PD.Select('relative', [['relative', 'Relative'], ['absolute', 'Absolute']]),
|
||||
volumeIsovalueValue: PD.Numeric(1),
|
||||
volumeOpacity: PD.Numeric(0.2, { min: 0, max: 1, step: 0.05 }),
|
||||
segmentOpacity: PD.Numeric(1, { min: 0, max: 1, step: 0.05 }),
|
||||
selectedSegment: PD.Numeric(-1, { step: 1 }),
|
||||
visibleSegments: PD.ObjectList({ segmentId: PD.Numeric(0) }, s => s.segmentId.toString()),
|
||||
visibleModels: PD.ObjectList({ pdbId: PD.Text('') }, s => s.pdbId.toString()),
|
||||
};
|
||||
export type VolsegStateData = PD.Values<typeof VolsegStateParams>;
|
||||
|
||||
|
||||
export class VolsegState extends PluginStateObject.Create<VolsegStateData>({ name: 'Vol & Seg Entry State', typeClass: 'Data' }) { }
|
||||
|
||||
|
||||
export const VOLSEG_STATE_FROM_ENTRY_TRANSFORMER_NAME = 'volseg-state-from-entry'; // defined here to avoid cyclic dependency
|
||||
191
src/extensions/volumes-and-segmentations/entry-volume.ts
Normal file
191
src/extensions/volumes-and-segmentations/entry-volume.ts
Normal file
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { Vec2 } from '../../mol-math/linear-algebra';
|
||||
import { Volume } from '../../mol-model/volume';
|
||||
import { createVolumeRepresentationParams } from '../../mol-plugin-state/helpers/volume-representation-params';
|
||||
import { PluginStateObject } from '../../mol-plugin-state/objects';
|
||||
import { StateTransforms } from '../../mol-plugin-state/transforms';
|
||||
import { Download } from '../../mol-plugin-state/transforms/data';
|
||||
import { CreateGroup } from '../../mol-plugin-state/transforms/misc';
|
||||
import { setSubtreeVisibility } from '../../mol-plugin/behavior/static/state';
|
||||
import { PluginCommands } from '../../mol-plugin/commands';
|
||||
import { StateObjectSelector } from '../../mol-state';
|
||||
import { Color } from '../../mol-util/color';
|
||||
import { ParamDefinition as PD } from '../../mol-util/param-definition';
|
||||
|
||||
import { BOX, VolsegEntryData, MAX_VOXELS } from './entry-root';
|
||||
import { VolsegStateParams, VolumeTypeChoice } from './entry-state';
|
||||
import * as ExternalAPIs from './external-api';
|
||||
import { VolsegGlobalStateData } from './global-state';
|
||||
|
||||
|
||||
const GROUP_TAG = 'volume-group';
|
||||
export const VOLUME_VISUAL_TAG = 'volume-visual';
|
||||
|
||||
const DIRECT_VOLUME_RELATIVE_PEAK_HALFWIDTH = 0.5;
|
||||
|
||||
|
||||
export type VolumeVisualParams = ReturnType<typeof createVolumeRepresentationParams>;
|
||||
|
||||
interface VolumeStats { min: number, max: number, mean: number, sigma: number };
|
||||
|
||||
|
||||
export const SimpleVolumeParams = {
|
||||
volumeType: VolumeTypeChoice.PDSelect(),
|
||||
opacity: PD.Numeric(0.2, { min: 0, max: 1, step: 0.05 }, { hideIf: p => p.volumeType === 'off' }),
|
||||
};
|
||||
export type SimpleVolumeParamValues = PD.Values<typeof SimpleVolumeParams>;
|
||||
|
||||
|
||||
export class VolsegVolumeData {
|
||||
private entryData: VolsegEntryData;
|
||||
private visualTypeParamCache: { [type: string]: any } = {};
|
||||
|
||||
constructor(rootData: VolsegEntryData) {
|
||||
this.entryData = rootData;
|
||||
}
|
||||
|
||||
async loadVolume() {
|
||||
const hasVolumes = this.entryData.metadata.raw.grid.volumes.volume_downsamplings.length > 0;
|
||||
if (hasVolumes) {
|
||||
const isoLevelPromise = ExternalAPIs.tryGetIsovalue(this.entryData.metadata.raw.grid.general.source_db_id ?? this.entryData.entryId);
|
||||
let group = this.entryData.findNodesByTags(GROUP_TAG)[0]?.transform.ref;
|
||||
if (!group) {
|
||||
const newGroupNode = await this.entryData.newUpdate().apply(CreateGroup, { label: 'Volume' }, { tags: [GROUP_TAG], state: { isCollapsed: true } }).commit();
|
||||
group = newGroupNode.ref;
|
||||
}
|
||||
const url = this.entryData.api.volumeUrl(this.entryData.source, this.entryData.entryId, BOX, MAX_VOXELS);
|
||||
const data = await this.entryData.newUpdate().to(group).apply(Download, { url, isBinary: true, label: `Volume Data: ${url}` }).commit();
|
||||
const parsed = await this.entryData.plugin.dataFormats.get('dscif')!.parse(this.entryData.plugin, data);
|
||||
const volumeNode: StateObjectSelector<PluginStateObject.Volume.Data> = parsed.volumes?.[0] ?? parsed.volume;
|
||||
const volumeData = volumeNode.cell!.obj!.data;
|
||||
|
||||
const volumeType = VolsegStateParams.volumeType.defaultValue;
|
||||
let isovalue = await isoLevelPromise;
|
||||
if (!isovalue) {
|
||||
const stats = volumeData.grid.stats;
|
||||
const maxRelative = (stats.max - stats.mean) / stats.sigma;
|
||||
if (maxRelative > 1) {
|
||||
isovalue = { kind: 'relative', value: 1.0 };
|
||||
} else {
|
||||
isovalue = { kind: 'relative', value: maxRelative * 0.5 };
|
||||
}
|
||||
}
|
||||
|
||||
const adjustedIsovalue = Volume.adjustedIsoValue(volumeData, isovalue.value, isovalue.kind);
|
||||
const visualParams = this.createVolumeVisualParams(volumeData, volumeType);
|
||||
this.changeIsovalueInVolumeVisualParams(visualParams, adjustedIsovalue, volumeData.grid.stats);
|
||||
|
||||
await this.entryData.newUpdate()
|
||||
.to(volumeNode)
|
||||
.apply(StateTransforms.Representation.VolumeRepresentation3D, visualParams, { tags: [VOLUME_VISUAL_TAG], state: { isHidden: volumeType === 'off' } })
|
||||
.commit();
|
||||
return { isovalue: adjustedIsovalue };
|
||||
}
|
||||
}
|
||||
|
||||
async setVolumeVisual(type: 'isosurface' | 'direct-volume' | 'off') {
|
||||
const visual = this.entryData.findNodesByTags(VOLUME_VISUAL_TAG)[0];
|
||||
if (!visual) return;
|
||||
const oldParams: VolumeVisualParams = visual.transform.params;
|
||||
this.visualTypeParamCache[oldParams.type.name] = oldParams.type.params;
|
||||
if (type === 'off') {
|
||||
setSubtreeVisibility(this.entryData.plugin.state.data, visual.transform.ref, true); // true means hide, ¯\_(ツ)_/¯
|
||||
} else {
|
||||
setSubtreeVisibility(this.entryData.plugin.state.data, visual.transform.ref, false); // true means hide, ¯\_(ツ)_/¯
|
||||
if (oldParams.type.name === type) return;
|
||||
const newParams: VolumeVisualParams = {
|
||||
...oldParams,
|
||||
type: {
|
||||
name: type,
|
||||
params: this.visualTypeParamCache[type] ?? oldParams.type.params,
|
||||
}
|
||||
};
|
||||
const volumeStats = visual.obj?.data.sourceData.grid.stats;
|
||||
if (!volumeStats) throw new Error(`Cannot get volume stats from volume visual ${visual.transform.ref}`);
|
||||
this.changeIsovalueInVolumeVisualParams(newParams, undefined, volumeStats);
|
||||
const update = this.entryData.newUpdate().to(visual.transform.ref).update(newParams);
|
||||
await PluginCommands.State.Update(this.entryData.plugin, { state: this.entryData.plugin.state.data, tree: update, options: { doNotUpdateCurrent: true } });
|
||||
}
|
||||
}
|
||||
|
||||
async updateVolumeVisual(newParams: SimpleVolumeParamValues) {
|
||||
const { volumeType, opacity } = newParams;
|
||||
const visual = this.entryData.findNodesByTags(VOLUME_VISUAL_TAG)[0];
|
||||
if (!visual) return;
|
||||
const oldVisualParams: VolumeVisualParams = visual.transform.params;
|
||||
this.visualTypeParamCache[oldVisualParams.type.name] = oldVisualParams.type.params;
|
||||
|
||||
if (volumeType === 'off') {
|
||||
setSubtreeVisibility(this.entryData.plugin.state.data, visual.transform.ref, true); // true means hide, ¯\_(ツ)_/¯
|
||||
} else {
|
||||
setSubtreeVisibility(this.entryData.plugin.state.data, visual.transform.ref, false); // true means hide, ¯\_(ツ)_/¯
|
||||
const newVisualParams: VolumeVisualParams = {
|
||||
...oldVisualParams,
|
||||
type: {
|
||||
name: volumeType,
|
||||
params: this.visualTypeParamCache[volumeType] ?? oldVisualParams.type.params,
|
||||
}
|
||||
};
|
||||
newVisualParams.type.params.alpha = opacity;
|
||||
const volumeStats = visual.obj?.data.sourceData.grid.stats;
|
||||
if (!volumeStats) throw new Error(`Cannot get volume stats from volume visual ${visual.transform.ref}`);
|
||||
this.changeIsovalueInVolumeVisualParams(newVisualParams, undefined, volumeStats);
|
||||
const update = this.entryData.newUpdate().to(visual.transform.ref).update(newVisualParams);
|
||||
await PluginCommands.State.Update(this.entryData.plugin, { state: this.entryData.plugin.state.data, tree: update, options: { doNotUpdateCurrent: true } });
|
||||
}
|
||||
}
|
||||
|
||||
async setTryUseGpu(tryUseGpu: boolean) {
|
||||
const visuals = this.entryData.findNodesByTags(VOLUME_VISUAL_TAG);
|
||||
for (const visual of visuals) {
|
||||
const oldParams: VolumeVisualParams = visual.transform.params;
|
||||
if (oldParams.type.params.tryUseGpu === !tryUseGpu) {
|
||||
const newParams = { ...oldParams, type: { ...oldParams.type, params: { ...oldParams.type.params, tryUseGpu: tryUseGpu } } };
|
||||
const update = this.entryData.newUpdate().to(visual.transform.ref).update(newParams);
|
||||
await PluginCommands.State.Update(this.entryData.plugin, { state: this.entryData.plugin.state.data, tree: update, options: { doNotUpdateCurrent: true } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private getIsovalueFromState(): Volume.IsoValue {
|
||||
const { volumeIsovalueKind, volumeIsovalueValue } = this.entryData.currentState.value;
|
||||
return volumeIsovalueKind === 'relative'
|
||||
? Volume.IsoValue.relative(volumeIsovalueValue)
|
||||
: Volume.IsoValue.absolute(volumeIsovalueValue);
|
||||
}
|
||||
|
||||
private createVolumeVisualParams(volume: Volume, type: 'isosurface' | 'direct-volume' | 'off'): VolumeVisualParams {
|
||||
if (type === 'off') type = 'isosurface';
|
||||
return createVolumeRepresentationParams(this.entryData.plugin, volume, {
|
||||
type: type,
|
||||
typeParams: { alpha: 0.2, tryUseGpu: VolsegGlobalStateData.getGlobalState(this.entryData.plugin)?.tryUseGpu },
|
||||
color: 'uniform',
|
||||
colorParams: { value: Color(0x121212) },
|
||||
});
|
||||
}
|
||||
|
||||
private changeIsovalueInVolumeVisualParams(params: VolumeVisualParams, isovalue: Volume.IsoValue | undefined, stats: VolumeStats) {
|
||||
isovalue ??= this.getIsovalueFromState();
|
||||
switch (params.type.name) {
|
||||
case 'isosurface':
|
||||
params.type.params.isoValue = isovalue;
|
||||
params.type.params.tryUseGpu = VolsegGlobalStateData.getGlobalState(this.entryData.plugin)?.tryUseGpu;
|
||||
break;
|
||||
case 'direct-volume':
|
||||
const absIso = Volume.IsoValue.toAbsolute(isovalue, stats).absoluteValue;
|
||||
const fractIso = (absIso - stats.min) / (stats.max - stats.min);
|
||||
const peakHalfwidth = DIRECT_VOLUME_RELATIVE_PEAK_HALFWIDTH * stats.sigma / (stats.max - stats.min);
|
||||
params.type.params.controlPoints = [
|
||||
Vec2.create(Math.max(fractIso - peakHalfwidth, 0), 0),
|
||||
Vec2.create(fractIso, 1),
|
||||
Vec2.create(Math.min(fractIso + peakHalfwidth, 1), 0),
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
51
src/extensions/volumes-and-segmentations/external-api.ts
Normal file
51
src/extensions/volumes-and-segmentations/external-api.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { splitEntryId } from './helpers';
|
||||
|
||||
|
||||
/** Try to get author-defined contour value for isosurface from EMDB API. Return relative value 1.0, if not applicable or fails. */
|
||||
export async function tryGetIsovalue(entryId: string): Promise<{ kind: 'absolute' | 'relative', value: number } | undefined> {
|
||||
const split = splitEntryId(entryId);
|
||||
if (split.source === 'emdb') {
|
||||
try {
|
||||
const response = await fetch(`https://www.ebi.ac.uk/emdb/api/entry/map/${split.entryNumber}`);
|
||||
const json = await response.json();
|
||||
const contours: any[] = json?.map?.contour_list?.contour;
|
||||
if (contours && contours.length > 0) {
|
||||
const theContour = contours.find(c => c.primary) || contours[0];
|
||||
if (theContour.level === undefined) throw new Error('EMDB API response missing contour level.');
|
||||
return { kind: 'absolute', value: theContour.level };
|
||||
}
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export async function getPdbIdsForEmdbEntry(entryId: string): Promise<string[]> {
|
||||
const split = splitEntryId(entryId);
|
||||
const result = [];
|
||||
if (split.source === 'emdb') {
|
||||
entryId = entryId.toUpperCase();
|
||||
const apiUrl = `https://www.ebi.ac.uk/pdbe/api/emdb/entry/fitted/${entryId}`;
|
||||
try {
|
||||
const response = await fetch(apiUrl);
|
||||
if (response.ok) {
|
||||
const json = await response.json();
|
||||
const jsonEntry = json[entryId] ?? [];
|
||||
for (const record of jsonEntry) {
|
||||
const pdbs = record?.fitted_emdb_id_list?.pdb_id ?? [];
|
||||
result.push(...pdbs);
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
65
src/extensions/volumes-and-segmentations/global-state.ts
Normal file
65
src/extensions/volumes-and-segmentations/global-state.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { PluginStateObject } from '../../mol-plugin-state/objects';
|
||||
import { PluginBehavior } from '../../mol-plugin/behavior';
|
||||
import { PluginContext } from '../../mol-plugin/context';
|
||||
import { ParamDefinition as PD } from '../../mol-util/param-definition';
|
||||
import { VolsegEntry } from './entry-root';
|
||||
import { isDefined } from './helpers';
|
||||
|
||||
|
||||
export const VolsegGlobalStateParams = {
|
||||
tryUseGpu: PD.Boolean(true, { description: 'Attempt using GPU for faster rendering. \nCaution: with some hardware setups, this might render some objects incorrectly or not at all.' }),
|
||||
selectionMode: PD.Boolean(true, { description: 'Allow selecting/deselecting a segment by clicking on it.' }),
|
||||
};
|
||||
export type VolsegGlobalStateParamValues = PD.Values<typeof VolsegGlobalStateParams>;
|
||||
|
||||
|
||||
export class VolsegGlobalState extends PluginStateObject.CreateBehavior<VolsegGlobalStateData>({ name: 'Vol & Seg Global State' }) { }
|
||||
|
||||
export class VolsegGlobalStateData extends PluginBehavior.WithSubscribers<VolsegGlobalStateParamValues> {
|
||||
private ref: string;
|
||||
currentState = new BehaviorSubject(PD.getDefaultValues(VolsegGlobalStateParams));
|
||||
|
||||
constructor(plugin: PluginContext, params: VolsegGlobalStateParamValues) {
|
||||
super(plugin, params);
|
||||
this.currentState.next(params);
|
||||
}
|
||||
|
||||
register(ref: string) {
|
||||
this.ref = ref;
|
||||
}
|
||||
unregister() {
|
||||
this.ref = '';
|
||||
}
|
||||
isRegistered() {
|
||||
return this.ref !== '';
|
||||
}
|
||||
async updateState(plugin: PluginContext, state: Partial<VolsegGlobalStateParamValues>) {
|
||||
const oldState = this.currentState.value;
|
||||
|
||||
const promises = [];
|
||||
const allEntries = plugin.state.data.selectQ(q => q.ofType(VolsegEntry)).map(cell => cell.obj?.data).filter(isDefined);
|
||||
if (state.tryUseGpu !== undefined && state.tryUseGpu !== oldState.tryUseGpu) {
|
||||
for (const entry of allEntries) {
|
||||
promises.push(entry.setTryUseGpu(state.tryUseGpu));
|
||||
}
|
||||
}
|
||||
if (state.selectionMode !== undefined && state.selectionMode !== oldState.selectionMode) {
|
||||
for (const entry of allEntries) {
|
||||
promises.push(entry.setSelectionMode(state.selectionMode));
|
||||
}
|
||||
}
|
||||
await Promise.all(promises);
|
||||
await plugin.build().to(this.ref).update(state).commit();
|
||||
}
|
||||
|
||||
static getGlobalState(plugin: PluginContext): VolsegGlobalStateParamValues | undefined {
|
||||
return plugin.state.data.selectQ(q => q.ofType(VolsegGlobalState))[0]?.obj?.data.currentState.value;
|
||||
}
|
||||
}
|
||||
163
src/extensions/volumes-and-segmentations/helpers.ts
Normal file
163
src/extensions/volumes-and-segmentations/helpers.ts
Normal file
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { Volume } from '../../mol-model/volume';
|
||||
import { PluginStateObject } from '../../mol-plugin-state/objects';
|
||||
import { setSubtreeVisibility } from '../../mol-plugin/behavior/static/state';
|
||||
import { StateBuilder, StateObjectSelector, StateTransformer } from '../../mol-state';
|
||||
import { ParamDefinition } from '../../mol-util/param-definition';
|
||||
import { Source } from './entry-root';
|
||||
|
||||
|
||||
/** Split entry ID (e.g. 'emd-1832') into source ('emdb') and number ('1832') */
|
||||
export function splitEntryId(entryId: string) {
|
||||
const PREFIX_TO_SOURCE: { [prefix: string]: Source } = { 'emd': 'emdb' };
|
||||
const [prefix, entry] = entryId.split('-');
|
||||
return {
|
||||
source: PREFIX_TO_SOURCE[prefix] ?? prefix,
|
||||
entryNumber: entry
|
||||
};
|
||||
}
|
||||
|
||||
/** Create entry ID (e.g. 'emd-1832') for a combination of source ('emdb') and number ('1832') */
|
||||
export function createEntryId(source: Source, entryNumber: string | number) {
|
||||
const SOURCE_TO_PREFIX: { [prefix: string]: string } = { 'emdb': 'emd' };
|
||||
const prefix = SOURCE_TO_PREFIX[source] ?? source;
|
||||
return `${prefix}-${entryNumber}`;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Represents a set of values to choose from, with a default value. Example:
|
||||
* ```
|
||||
* export const MyChoice = new Choice({ yes: 'I agree', no: 'Nope' }, 'yes');
|
||||
* export type MyChoiceType = Choice.Values<typeof MyChoice>; // 'yes'|'no'
|
||||
* ```
|
||||
*/
|
||||
export class Choice<T extends string, D extends T> {
|
||||
readonly defaultValue: D;
|
||||
readonly options: [T, string][];
|
||||
private readonly nameDict: { [value in T]: string };
|
||||
constructor(opts: { [value in T]: string }, defaultValue: D) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.options = Object.keys(opts).map(k => [k as T, opts[k as T]]);
|
||||
this.nameDict = opts;
|
||||
}
|
||||
PDSelect(defaultValue?: T, info?: ParamDefinition.Info): ParamDefinition.Select<T> {
|
||||
return ParamDefinition.Select<T>(defaultValue ?? this.defaultValue, this.options, info);
|
||||
}
|
||||
prettyName(value: T): string {
|
||||
return this.nameDict[value];
|
||||
}
|
||||
get values(): T[] {
|
||||
return this.options.map(([value, pretty]) => value);
|
||||
}
|
||||
}
|
||||
export namespace Choice {
|
||||
export type Values<T extends Choice<any, any>> = T extends Choice<infer R, any> ? R : any;
|
||||
}
|
||||
|
||||
|
||||
export function isDefined<T>(x: T | undefined): x is T {
|
||||
return x !== undefined;
|
||||
}
|
||||
|
||||
|
||||
export class NodeManager {
|
||||
private nodes: { [key: string]: StateObjectSelector };
|
||||
|
||||
constructor() {
|
||||
this.nodes = {};
|
||||
}
|
||||
|
||||
private static nodeExists(node: StateObjectSelector): boolean {
|
||||
try {
|
||||
return node.checkValid();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public getNode(key: string): StateObjectSelector | undefined {
|
||||
const node = this.nodes[key];
|
||||
if (node && !NodeManager.nodeExists(node)) {
|
||||
delete this.nodes[key];
|
||||
return undefined;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public getNodes(): StateObjectSelector[] {
|
||||
return Object.keys(this.nodes).map(key => this.getNode(key)).filter(node => node) as StateObjectSelector[];
|
||||
}
|
||||
|
||||
public deleteAllNodes(update: StateBuilder.Root) {
|
||||
for (const node of this.getNodes()) {
|
||||
update.delete(node);
|
||||
}
|
||||
this.nodes = {};
|
||||
}
|
||||
|
||||
public hideAllNodes() {
|
||||
for (const node of this.getNodes()) {
|
||||
setSubtreeVisibility(node.state!, node.ref, true); // hide
|
||||
}
|
||||
}
|
||||
|
||||
public async showNode(key: string, factory: () => StateObjectSelector | Promise<StateObjectSelector>, forceVisible: boolean = true) {
|
||||
let node = this.getNode(key);
|
||||
if (node) {
|
||||
if (forceVisible) {
|
||||
setSubtreeVisibility(node.state!, node.ref, false); // show
|
||||
}
|
||||
} else {
|
||||
node = await factory();
|
||||
this.nodes[key] = node;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const CreateTransformer = StateTransformer.builderFactory('volseg');
|
||||
|
||||
export const CreateVolume = CreateTransformer({
|
||||
name: 'create-transformer',
|
||||
from: PluginStateObject.Root,
|
||||
to: PluginStateObject.Volume.Data,
|
||||
params: {
|
||||
label: ParamDefinition.Text('Volume', { isHidden: true }),
|
||||
description: ParamDefinition.Text('', { isHidden: true }),
|
||||
volume: ParamDefinition.Value<Volume>(undefined as any, { isHidden: true }),
|
||||
}
|
||||
})({
|
||||
apply({ params }) {
|
||||
return new PluginStateObject.Volume.Data(params.volume, { label: params.label, description: params.description });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
export function applyEllipsis(name: string, max_chars: number = 60) {
|
||||
if (name.length <= max_chars) return name;
|
||||
const beginning = name.substring(0, max_chars);
|
||||
let lastSpace = beginning.lastIndexOf(' ');
|
||||
if (lastSpace === -1) return beginning + '...';
|
||||
if (lastSpace > 0 && ',;.'.includes(name.charAt(lastSpace - 1))) lastSpace--;
|
||||
return name.substring(0, lastSpace) + '...';
|
||||
}
|
||||
|
||||
|
||||
export function lazyGetter<T>(getter: () => T, errorIfUndefined?: string) {
|
||||
let value: T | undefined = undefined;
|
||||
return () => {
|
||||
if (value === undefined) value = getter();
|
||||
if (errorIfUndefined && value === undefined) throw new Error(errorIfUndefined);
|
||||
return value;
|
||||
};
|
||||
}
|
||||
102
src/extensions/volumes-and-segmentations/index.ts
Normal file
102
src/extensions/volumes-and-segmentations/index.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { PluginStateObject as SO } from '../../mol-plugin-state/objects';
|
||||
import { PluginBehavior } from '../../mol-plugin/behavior';
|
||||
import { PluginConfigItem } from '../../mol-plugin/config';
|
||||
import { PluginContext } from '../../mol-plugin/context';
|
||||
import { StateAction } from '../../mol-state';
|
||||
import { Task } from '../../mol-task';
|
||||
import { DEFAULT_VOLSEG_SERVER, VolumeApiV2 } from './volseg-api/api';
|
||||
|
||||
import { VolsegEntryData, VolsegEntryParamValues, createLoadVolsegParams } from './entry-root';
|
||||
import { VolsegGlobalState } from './global-state';
|
||||
import { createEntryId } from './helpers';
|
||||
import { VolsegEntryFromRoot, VolsegGlobalStateFromRoot, VolsegStateFromEntry } from './transformers';
|
||||
import { VolsegUI } from './ui';
|
||||
|
||||
|
||||
const DEBUGGING = window.location.hostname === 'localhost';
|
||||
|
||||
export const VolsegVolumeServerConfig = {
|
||||
// DefaultServer: new PluginConfigItem('volseg-volume-server', DEFAULT_VOLUME_SERVER_V2),
|
||||
DefaultServer: new PluginConfigItem('volseg-volume-server', DEBUGGING ? 'http://localhost:9000/v2' : DEFAULT_VOLSEG_SERVER),
|
||||
};
|
||||
|
||||
|
||||
export const Volseg = PluginBehavior.create<{ autoAttach: boolean, showTooltip: boolean }>({
|
||||
name: 'volseg',
|
||||
category: 'misc',
|
||||
display: {
|
||||
name: 'Volseg',
|
||||
description: 'Volseg'
|
||||
},
|
||||
ctor: class extends PluginBehavior.Handler<{ autoAttach: boolean, showTooltip: boolean }> {
|
||||
register() {
|
||||
this.ctx.state.data.actions.add(LoadVolseg);
|
||||
this.ctx.customStructureControls.set('volseg', VolsegUI as any);
|
||||
this.initializeEntryLists(); // do not await
|
||||
|
||||
const entries = new Map<string, VolsegEntryData>();
|
||||
this.subscribeObservable(this.ctx.state.data.events.cell.created, o => {
|
||||
if (o.cell.obj instanceof VolsegEntryData) entries.set(o.ref, o.cell.obj);
|
||||
});
|
||||
|
||||
this.subscribeObservable(this.ctx.state.data.events.cell.removed, o => {
|
||||
if (entries.has(o.ref)) {
|
||||
entries.get(o.ref)!.dispose();
|
||||
entries.delete(o.ref);
|
||||
}
|
||||
});
|
||||
}
|
||||
unregister() {
|
||||
this.ctx.state.data.actions.remove(LoadVolseg);
|
||||
this.ctx.customStructureControls.delete('volseg');
|
||||
}
|
||||
private async initializeEntryLists() {
|
||||
const apiUrl = this.ctx.config.get(VolsegVolumeServerConfig.DefaultServer) ?? DEFAULT_VOLSEG_SERVER;
|
||||
const api = new VolumeApiV2(apiUrl);
|
||||
const entryLists = await api.getEntryList(10 ** 6);
|
||||
Object.values(entryLists).forEach(l => l.sort());
|
||||
(this.ctx.customState as any).volsegAvailableEntries = entryLists;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
export const LoadVolseg = StateAction.build({
|
||||
display: { name: 'Load Volume & Segmentation' },
|
||||
from: SO.Root,
|
||||
params: (a, plugin: PluginContext) => {
|
||||
const res = createLoadVolsegParams(plugin, (plugin.customState as any).volsegAvailableEntries);
|
||||
return res;
|
||||
},
|
||||
})(({ params, state }, ctx: PluginContext) => Task.create('Loading Volume & Segmentation', taskCtx => {
|
||||
return state.transaction(async () => {
|
||||
const entryParams = VolsegEntryParamValues.fromLoadVolsegParamValues(params);
|
||||
if (entryParams.entryId.trim().length === 0) {
|
||||
alert('Must specify Entry Id!');
|
||||
throw new Error('Specify Entry Id');
|
||||
}
|
||||
if (!entryParams.entryId.includes('-')) {
|
||||
// add source prefix if the user omitted it (e.g. 1832 -> emd-1832)
|
||||
entryParams.entryId = createEntryId(entryParams.source, entryParams.entryId);
|
||||
}
|
||||
ctx.behaviors.layout.leftPanelTabName.next('data');
|
||||
|
||||
const globalStateNode = ctx.state.data.selectQ(q => q.ofType(VolsegGlobalState))[0];
|
||||
if (!globalStateNode) {
|
||||
await state.build().toRoot().apply(VolsegGlobalStateFromRoot, {}, { state: { isGhost: !DEBUGGING } }).commit();
|
||||
}
|
||||
|
||||
const entryNode = await state.build().toRoot().apply(VolsegEntryFromRoot, entryParams).commit();
|
||||
await state.build().to(entryNode).apply(VolsegStateFromEntry, {}, { state: { isGhost: !DEBUGGING } }).commit();
|
||||
if (entryNode.data) {
|
||||
await entryNode.data.loadVolume();
|
||||
await entryNode.data.loadSegmentations();
|
||||
}
|
||||
}).runInContext(taskCtx);
|
||||
}));
|
||||
70
src/extensions/volumes-and-segmentations/transformers.ts
Normal file
70
src/extensions/volumes-and-segmentations/transformers.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { PluginStateObject, PluginStateTransform } from '../../mol-plugin-state/objects';
|
||||
import { PluginContext } from '../../mol-plugin/context';
|
||||
import { StateTransformer } from '../../mol-state';
|
||||
import { Task } from '../../mol-task';
|
||||
|
||||
import { VolsegEntry, VolsegEntryData, createVolsegEntryParams } from './entry-root';
|
||||
import { VolsegState, VolsegStateParams, VOLSEG_STATE_FROM_ENTRY_TRANSFORMER_NAME } from './entry-state';
|
||||
import { VolsegGlobalState, VolsegGlobalStateData, VolsegGlobalStateParams } from './global-state';
|
||||
|
||||
|
||||
export const VolsegEntryFromRoot = PluginStateTransform.BuiltIn({
|
||||
name: 'volseg-entry-from-root',
|
||||
display: { name: 'Vol & Seg Entry', description: 'Vol & Seg Entry' },
|
||||
from: PluginStateObject.Root,
|
||||
to: VolsegEntry,
|
||||
params: (a, plugin: PluginContext) => createVolsegEntryParams(plugin),
|
||||
})({
|
||||
apply({ a, params }, plugin: PluginContext) {
|
||||
return Task.create('Load Vol & Seg Entry', async () => {
|
||||
const data = await VolsegEntryData.create(plugin, params);
|
||||
return new VolsegEntry(data, { label: data.entryId, description: 'Vol & Seg Entry' });
|
||||
});
|
||||
},
|
||||
update({ b, oldParams, newParams }) {
|
||||
Object.assign(newParams, oldParams);
|
||||
console.error('Changing params of existing VolsegEntry node is not allowed');
|
||||
return StateTransformer.UpdateResult.Unchanged;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
export const VolsegStateFromEntry = PluginStateTransform.BuiltIn({
|
||||
name: VOLSEG_STATE_FROM_ENTRY_TRANSFORMER_NAME,
|
||||
display: { name: 'Vol & Seg Entry State', description: 'Vol & Seg Entry State' },
|
||||
from: VolsegEntry,
|
||||
to: VolsegState,
|
||||
params: VolsegStateParams,
|
||||
})({
|
||||
apply({ a, params }, plugin: PluginContext) {
|
||||
return Task.create('Create Vol & Seg Entry State', async () => {
|
||||
return new VolsegState(params, { label: 'State' });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
export const VolsegGlobalStateFromRoot = PluginStateTransform.BuiltIn({
|
||||
name: 'volseg-global-state-from-root',
|
||||
display: { name: 'Vol & Seg Global State', description: 'Vol & Seg Global State' },
|
||||
from: PluginStateObject.Root,
|
||||
to: VolsegGlobalState,
|
||||
params: VolsegGlobalStateParams,
|
||||
})({
|
||||
apply({ a, params }, plugin: PluginContext) {
|
||||
return Task.create('Create Vol & Seg Global State', async () => {
|
||||
const data = new VolsegGlobalStateData(plugin, params);
|
||||
return new VolsegGlobalState(data, { label: 'Global State', description: 'Vol & Seg Global State' });
|
||||
});
|
||||
},
|
||||
update({ b, oldParams, newParams }) {
|
||||
b.data.currentState.next(newParams);
|
||||
return StateTransformer.UpdateResult.Updated;
|
||||
}
|
||||
});
|
||||
264
src/extensions/volumes-and-segmentations/ui.tsx
Normal file
264
src/extensions/volumes-and-segmentations/ui.tsx
Normal file
@@ -0,0 +1,264 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
import { CollapsableControls, CollapsableState } from '../../mol-plugin-ui/base';
|
||||
import { Button, ControlRow, ExpandGroup, IconButton } from '../../mol-plugin-ui/controls/common';
|
||||
import * as Icons from '../../mol-plugin-ui/controls/icons';
|
||||
import { ParameterControls } from '../../mol-plugin-ui/controls/parameters';
|
||||
import { Slider } from '../../mol-plugin-ui/controls/slider';
|
||||
import { useBehavior } from '../../mol-plugin-ui/hooks/use-behavior';
|
||||
import { UpdateTransformControl } from '../../mol-plugin-ui/state/update-transform';
|
||||
import { PluginContext } from '../../mol-plugin/context';
|
||||
import { shallowEqualArrays } from '../../mol-util';
|
||||
import { ParamDefinition as PD } from '../../mol-util/param-definition';
|
||||
import { sleep } from '../../mol-util/sleep';
|
||||
|
||||
import { VolsegEntry, VolsegEntryData } from './entry-root';
|
||||
import { SimpleVolumeParams, SimpleVolumeParamValues } from './entry-volume';
|
||||
import { VolsegGlobalState, VolsegGlobalStateData, VolsegGlobalStateParams } from './global-state';
|
||||
import { isDefined } from './helpers';
|
||||
|
||||
|
||||
interface VolsegUIData {
|
||||
globalState?: VolsegGlobalStateData,
|
||||
availableNodes: VolsegEntry[],
|
||||
activeNode?: VolsegEntry,
|
||||
}
|
||||
namespace VolsegUIData {
|
||||
export function changeAvailableNodes(data: VolsegUIData, newNodes: VolsegEntry[]): VolsegUIData {
|
||||
const newActiveNode = newNodes.length > data.availableNodes.length ?
|
||||
newNodes[newNodes.length - 1]
|
||||
: newNodes.find(node => node.data.ref === data.activeNode?.data.ref) ?? newNodes[0];
|
||||
return { ...data, availableNodes: newNodes, activeNode: newActiveNode };
|
||||
}
|
||||
export function changeActiveNode(data: VolsegUIData, newActiveRef: string): VolsegUIData {
|
||||
const newActiveNode = data.availableNodes.find(node => node.data.ref === newActiveRef) ?? data.availableNodes[0];
|
||||
return { ...data, availableNodes: data.availableNodes, activeNode: newActiveNode };
|
||||
}
|
||||
export function equals(data1: VolsegUIData, data2: VolsegUIData) {
|
||||
return shallowEqualArrays(data1.availableNodes, data2.availableNodes) && data1.activeNode === data2.activeNode && data1.globalState === data2.globalState;
|
||||
}
|
||||
}
|
||||
|
||||
export class VolsegUI extends CollapsableControls<{}, { data: VolsegUIData }> {
|
||||
protected defaultState(): CollapsableState & { data: VolsegUIData } {
|
||||
return {
|
||||
header: 'Volume & Segmentation',
|
||||
isCollapsed: true,
|
||||
brand: { accent: 'orange', svg: Icons.ExtensionSvg },
|
||||
data: {
|
||||
globalState: undefined,
|
||||
availableNodes: [],
|
||||
activeNode: undefined,
|
||||
}
|
||||
};
|
||||
}
|
||||
protected renderControls(): JSX.Element | null {
|
||||
return <VolsegControls plugin={this.plugin} data={this.state.data} setData={d => this.setState({ data: d })} />;
|
||||
}
|
||||
componentDidMount(): void {
|
||||
this.setState({ isHidden: true, isCollapsed: false });
|
||||
this.subscribe(this.plugin.state.data.events.changed, e => {
|
||||
const nodes = e.state.selectQ(q => q.ofType(VolsegEntry)).map(cell => cell?.obj).filter(isDefined);
|
||||
const isHidden = nodes.length === 0;
|
||||
const newData = VolsegUIData.changeAvailableNodes(this.state.data, nodes);
|
||||
if (!this.state.data.globalState?.isRegistered()) {
|
||||
const globalState = e.state.selectQ(q => q.ofType(VolsegGlobalState))[0]?.obj?.data;
|
||||
if (globalState) newData.globalState = globalState;
|
||||
}
|
||||
if (!VolsegUIData.equals(this.state.data, newData) || this.state.isHidden !== isHidden) {
|
||||
this.setState({ data: newData, isHidden: isHidden });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function VolsegControls({ plugin, data, setData }: { plugin: PluginContext, data: VolsegUIData, setData: (d: VolsegUIData) => void }) {
|
||||
const entryData = data.activeNode?.data;
|
||||
if (!entryData) {
|
||||
return <p>No data!</p>;
|
||||
}
|
||||
if (!data.globalState) {
|
||||
return <p>No global state!</p>;
|
||||
}
|
||||
|
||||
const params = {
|
||||
/** Reference to the active VolsegEntry node */
|
||||
entry: PD.Select(data.activeNode!.data.ref, data.availableNodes.map(entry => [entry.data.ref, entry.data.entryId]))
|
||||
};
|
||||
const values: PD.Values<typeof params> = {
|
||||
entry: data.activeNode!.data.ref,
|
||||
};
|
||||
|
||||
const globalState = useBehavior(data.globalState.currentState);
|
||||
|
||||
return <>
|
||||
<ParameterControls params={params} values={values} onChangeValues={next => setData(VolsegUIData.changeActiveNode(data, next.entry))} />
|
||||
|
||||
<ExpandGroup header='Global options'>
|
||||
<WaitingParameterControls params={VolsegGlobalStateParams} values={globalState} onChangeValues={async next => await data.globalState?.updateState(plugin, next)} />
|
||||
</ExpandGroup>
|
||||
|
||||
<VolsegEntryControls entryData={entryData} key={entryData.ref} />
|
||||
</>;
|
||||
}
|
||||
|
||||
function VolsegEntryControls({ entryData }: { entryData: VolsegEntryData }) {
|
||||
const state = useBehavior(entryData.currentState);
|
||||
|
||||
const allSegments = entryData.metadata.allSegments;
|
||||
const selectedSegment = entryData.metadata.getSegment(state.selectedSegment);
|
||||
const visibleSegments = state.visibleSegments.map(seg => seg.segmentId);
|
||||
const visibleModels = state.visibleModels.map(model => model.pdbId);
|
||||
const allPdbs = entryData.pdbs;
|
||||
|
||||
return <>
|
||||
{/* Title */}
|
||||
<div style={{ fontWeight: 'bold', padding: 8, paddingTop: 6, paddingBottom: 4, overflow: 'hidden' }}>
|
||||
{entryData.metadata.raw.annotation?.name ?? 'Unnamed Annotation'}
|
||||
</div>
|
||||
|
||||
{/* Fitted models */}
|
||||
{allPdbs.length > 0 && <ExpandGroup header='Fitted models in PDB' initiallyExpanded>
|
||||
{allPdbs.map(pdb =>
|
||||
<WaitingButton key={pdb} onClick={() => entryData.actionShowFittedModel(visibleModels.includes(pdb) ? [] : [pdb])}
|
||||
style={{ fontWeight: visibleModels.includes(pdb) ? 'bold' : undefined, textAlign: 'left', marginTop: 1 }}>
|
||||
{pdb}
|
||||
</WaitingButton>
|
||||
)}
|
||||
</ExpandGroup>}
|
||||
|
||||
{/* Volume */}
|
||||
<VolumeControls entryData={entryData} />
|
||||
<ExpandGroup header='Segmentation data' initiallyExpanded>
|
||||
{/* Segment opacity slider */}
|
||||
<ControlRow label='Opacity' control={
|
||||
<WaitingSlider min={0} max={1} value={state.segmentOpacity} step={0.05} onChange={async v => await entryData.actionSetOpacity(v)} />
|
||||
} />
|
||||
|
||||
{/* Segment toggles */}
|
||||
{allSegments.length > 0 && <>
|
||||
<WaitingButton onClick={async () => { await sleep(20); await entryData.actionToggleAllSegments(); }} style={{ marginTop: 1 }}>
|
||||
Toggle All segments
|
||||
</WaitingButton>
|
||||
<div style={{ maxHeight: 200, overflow: 'hidden', overflowY: 'auto', marginBlock: 1 }}>
|
||||
{allSegments.map(segment =>
|
||||
<div style={{ display: 'flex', marginBottom: 1 }} key={segment.id}
|
||||
onMouseEnter={() => entryData.actionHighlightSegment(segment)}
|
||||
onMouseLeave={() => entryData.actionHighlightSegment()}>
|
||||
<Button onClick={() => entryData.actionSelectSegment(segment !== selectedSegment ? segment.id : undefined)}
|
||||
style={{ fontWeight: segment.id === selectedSegment?.id ? 'bold' : undefined, marginRight: 1, flexGrow: 1, textAlign: 'left' }}>
|
||||
<div title={segment.biological_annotation.name ?? 'Unnamed segment'} style={{ maxWidth: 240, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
||||
{segment.biological_annotation.name ?? 'Unnamed segment'} ({segment.id})
|
||||
</div>
|
||||
</Button>
|
||||
<IconButton svg={visibleSegments.includes(segment.id) ? Icons.VisibilityOutlinedSvg : Icons.VisibilityOffOutlinedSvg}
|
||||
onClick={() => entryData.actionToggleSegment(segment.id)} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>}
|
||||
</ExpandGroup>
|
||||
|
||||
{/* Segment annotations */}
|
||||
<ExpandGroup header='Selected segment annotation' initiallyExpanded>
|
||||
<div style={{ paddingTop: 4, paddingRight: 8, maxHeight: 300, overflow: 'hidden', overflowY: 'auto' }}>
|
||||
{!selectedSegment && 'No segment selected'}
|
||||
{selectedSegment && <b>Segment {selectedSegment.id}:<br />{selectedSegment.biological_annotation.name ?? 'Unnamed segment'}</b>}
|
||||
{selectedSegment?.biological_annotation.external_references.map(ref =>
|
||||
<p key={ref.id} style={{ marginTop: 4 }}>
|
||||
<small>{ref.resource}:{ref.accession}</small><br />
|
||||
<b>{capitalize(ref.label)}</b><br />
|
||||
{ref.description}
|
||||
</p>)}
|
||||
</div>
|
||||
</ExpandGroup>
|
||||
</>;
|
||||
}
|
||||
|
||||
function VolumeControls({ entryData }: { entryData: VolsegEntryData }) {
|
||||
const vol = useBehavior(entryData.currentVolume);
|
||||
if (!vol) return null;
|
||||
|
||||
const volumeValues: SimpleVolumeParamValues = {
|
||||
volumeType: vol.state.isHidden ? 'off' : vol.params?.type.name as any,
|
||||
opacity: vol.params?.type.params.alpha,
|
||||
};
|
||||
|
||||
return <ExpandGroup header='Volume data' initiallyExpanded>
|
||||
<WaitingParameterControls params={SimpleVolumeParams} values={volumeValues} onChangeValues={async next => { await sleep(20); await entryData.actionUpdateVolumeVisual(next); }} />
|
||||
<ExpandGroup header='Detailed Volume Params' headerStyle={{ marginTop: 1 }}>
|
||||
<UpdateTransformControl state={entryData.plugin.state.data} transform={vol} customHeader='none' />
|
||||
</ExpandGroup>
|
||||
</ExpandGroup>;
|
||||
}
|
||||
|
||||
type ComponentParams<T extends React.Component<any, any, any> | ((props: any) => JSX.Element)> =
|
||||
T extends React.Component<infer P, any, any> ? P : T extends (props: infer P) => JSX.Element ? P : never;
|
||||
|
||||
function WaitingSlider({ value, onChange, ...etc }: { value: number, onChange: (value: number) => any } & ComponentParams<Slider>) {
|
||||
const [changing, sliderValue, execute] = useAsyncChange(value);
|
||||
|
||||
return <Slider value={sliderValue} disabled={changing} onChange={newValue => execute(onChange, newValue)} {...etc} />;
|
||||
}
|
||||
|
||||
function WaitingButton({ onClick, ...etc }: { onClick: () => any } & ComponentParams<typeof Button>) {
|
||||
const [changing, _, execute] = useAsyncChange(undefined);
|
||||
|
||||
return <Button disabled={changing} onClick={() => execute(onClick, undefined)} {...etc}>
|
||||
{etc.children}
|
||||
</Button>;
|
||||
}
|
||||
|
||||
function WaitingParameterControls<T extends PD.Params>({ values, onChangeValues, ...etc }: { values: PD.ValuesFor<T>, onChangeValues: (values: PD.ValuesFor<T>) => any } & ComponentParams<ParameterControls<T>>) {
|
||||
const [changing, currentValues, execute] = useAsyncChange(values);
|
||||
|
||||
return <ParameterControls isDisabled={changing} values={currentValues} onChangeValues={newValue => execute(onChangeValues, newValue)} {...etc} />;
|
||||
}
|
||||
|
||||
function capitalize(text: string) {
|
||||
const first = text.charAt(0);
|
||||
const rest = text.slice(1);
|
||||
return first.toUpperCase() + rest;
|
||||
}
|
||||
|
||||
function useAsyncChange<T>(initialValue: T) {
|
||||
const [isExecuting, setIsExecuting] = useState(false);
|
||||
const [value, setValue] = useState(initialValue);
|
||||
const isMounted = useRef(false);
|
||||
|
||||
useEffect(() => setValue(initialValue), [initialValue]);
|
||||
|
||||
useEffect(() => {
|
||||
isMounted.current = true;
|
||||
return () => { isMounted.current = false; };
|
||||
}, []);
|
||||
|
||||
const execute = useCallback(
|
||||
async (func: (val: T) => Promise<any>, val: T) => {
|
||||
setIsExecuting(true);
|
||||
setValue(val);
|
||||
try {
|
||||
await func(val);
|
||||
} catch (err) {
|
||||
if (isMounted.current) {
|
||||
setValue(initialValue);
|
||||
}
|
||||
throw err;
|
||||
} finally {
|
||||
if (isMounted.current) {
|
||||
setIsExecuting(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
return [isExecuting, value, execute] as const;
|
||||
}
|
||||
65
src/extensions/volumes-and-segmentations/volseg-api/api.ts
Normal file
65
src/extensions/volumes-and-segmentations/volseg-api/api.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { type Metadata } from './data';
|
||||
|
||||
|
||||
export const DEFAULT_VOLSEG_SERVER = 'https://molstarvolseg.ncbr.muni.cz/v2';
|
||||
|
||||
|
||||
export class VolumeApiV2 {
|
||||
public volumeServerUrl: string;
|
||||
|
||||
public constructor(volumeServerUrl: string = DEFAULT_VOLSEG_SERVER) {
|
||||
this.volumeServerUrl = volumeServerUrl.replace(/\/$/, ''); // trim trailing slash
|
||||
}
|
||||
|
||||
public entryListUrl(maxEntries: number, keyword?: string): string {
|
||||
return `${this.volumeServerUrl}/list_entries/${maxEntries}/${keyword ?? ''}`;
|
||||
}
|
||||
|
||||
public metadataUrl(source: string, entryId: string): string {
|
||||
return `${this.volumeServerUrl}/${source}/${entryId}/metadata`;
|
||||
}
|
||||
public volumeUrl(source: string, entryId: string, box: [[number, number, number], [number, number, number]] | null, maxPoints: number): string {
|
||||
if (box) {
|
||||
const [[a1, a2, a3], [b1, b2, b3]] = box;
|
||||
return `${this.volumeServerUrl}/${source}/${entryId}/volume/box/${a1}/${a2}/${a3}/${b1}/${b2}/${b3}?max_points=${maxPoints}`;
|
||||
} else {
|
||||
return `${this.volumeServerUrl}/${source}/${entryId}/volume/cell?max_points=${maxPoints}`;
|
||||
}
|
||||
}
|
||||
public latticeUrl(source: string, entryId: string, segmentation: number, box: [[number, number, number], [number, number, number]] | null, maxPoints: number): string {
|
||||
if (box) {
|
||||
const [[a1, a2, a3], [b1, b2, b3]] = box;
|
||||
return `${this.volumeServerUrl}/${source}/${entryId}/segmentation/box/${segmentation}/${a1}/${a2}/${a3}/${b1}/${b2}/${b3}?max_points=${maxPoints}`;
|
||||
} else {
|
||||
return `${this.volumeServerUrl}/${source}/${entryId}/segmentation/cell/${segmentation}?max_points=${maxPoints}`;
|
||||
}
|
||||
}
|
||||
public meshUrl_Json(source: string, entryId: string, segment: number, detailLevel: number): string {
|
||||
return `${this.volumeServerUrl}/${source}/${entryId}/mesh/${segment}/${detailLevel}`;
|
||||
}
|
||||
|
||||
public meshUrl_Bcif(source: string, entryId: string, segment: number, detailLevel: number): string {
|
||||
return `${this.volumeServerUrl}/${source}/${entryId}/mesh_bcif/${segment}/${detailLevel}`;
|
||||
}
|
||||
public volumeInfoUrl(source: string, entryId: string): string {
|
||||
return `${this.volumeServerUrl}/${source}/${entryId}/volume_info`;
|
||||
}
|
||||
|
||||
public async getEntryList(maxEntries: number, keyword?: string): Promise<{ [source: string]: string[] }> {
|
||||
const response = await fetch(this.entryListUrl(maxEntries, keyword));
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
public async getMetadata(source: string, entryId: string): Promise<Metadata> {
|
||||
const url = this.metadataUrl(source, entryId);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error(`Failed to fetch metadata from ${url}`);
|
||||
return await response.json();
|
||||
}
|
||||
}
|
||||
83
src/extensions/volumes-and-segmentations/volseg-api/data.ts
Normal file
83
src/extensions/volumes-and-segmentations/volseg-api/data.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
export interface Metadata {
|
||||
grid: {
|
||||
general: {
|
||||
details: string,
|
||||
source_db_name: string,
|
||||
source_db_id: string,
|
||||
},
|
||||
volumes: Volumes,
|
||||
segmentation_lattices: SegmentationLattices,
|
||||
segmentation_meshes: SegmentationMeshes,
|
||||
},
|
||||
annotation: Annotation | null,
|
||||
}
|
||||
|
||||
export interface Volumes {
|
||||
volume_downsamplings: number[],
|
||||
voxel_size: { [downsampling: number]: Vector3 },
|
||||
origin: Vector3,
|
||||
grid_dimensions: Vector3,
|
||||
sampled_grid_dimensions: { [downsampling: number]: Vector3 },
|
||||
mean: { [downsampling: number]: number },
|
||||
std: { [downsampling: number]: number },
|
||||
min: { [downsampling: number]: number },
|
||||
max: { [downsampling: number]: number },
|
||||
volume_force_dtype: string,
|
||||
}
|
||||
|
||||
export interface SegmentationLattices {
|
||||
segmentation_lattice_ids: number[],
|
||||
segmentation_downsamplings: { [lattice: number]: number[] },
|
||||
}
|
||||
|
||||
export interface SegmentationMeshes {
|
||||
mesh_component_numbers: {
|
||||
segment_ids?: {
|
||||
[segId: number]: {
|
||||
detail_lvls: {
|
||||
[detail: number]: {
|
||||
mesh_ids: {
|
||||
[meshId: number]: {
|
||||
num_triangles: number,
|
||||
num_vertices: number
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
detail_lvl_to_fraction: {
|
||||
[lvl: number]: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface Annotation {
|
||||
name: string,
|
||||
details: string,
|
||||
segment_list: Segment[],
|
||||
}
|
||||
|
||||
export interface Segment {
|
||||
id: number,
|
||||
colour: number[],
|
||||
biological_annotation: BiologicalAnnotation,
|
||||
}
|
||||
|
||||
export interface BiologicalAnnotation {
|
||||
name: string,
|
||||
external_references: ExternalReference[]
|
||||
}
|
||||
|
||||
export interface ExternalReference {
|
||||
id: number, resource: string, accession: string, label: string,
|
||||
description: string
|
||||
}
|
||||
|
||||
type Vector3 = [number, number, number];
|
||||
74
src/extensions/volumes-and-segmentations/volseg-api/utils.ts
Normal file
74
src/extensions/volumes-and-segmentations/volseg-api/utils.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Adam Midlik <midlik@gmail.com>
|
||||
*/
|
||||
|
||||
import { Color } from '../../../mol-util/color';
|
||||
import { Metadata, Segment } from './data';
|
||||
|
||||
|
||||
export class MetadataWrapper {
|
||||
raw: Metadata;
|
||||
private segmentMap?: { [id: number]: Segment };
|
||||
|
||||
constructor(rawMetadata: Metadata) {
|
||||
this.raw = rawMetadata;
|
||||
}
|
||||
|
||||
get allSegments() {
|
||||
return this.raw.annotation?.segment_list ?? [];
|
||||
}
|
||||
|
||||
get allSegmentIds() {
|
||||
return this.allSegments.map(segment => segment.id);
|
||||
}
|
||||
|
||||
getSegment(segmentId: number): Segment | undefined {
|
||||
if (!this.segmentMap) {
|
||||
this.segmentMap = {};
|
||||
for (const segment of this.allSegments) {
|
||||
this.segmentMap[segment.id] = segment;
|
||||
}
|
||||
}
|
||||
return this.segmentMap[segmentId];
|
||||
}
|
||||
|
||||
getSegmentColor(segmentId: number): Color | undefined {
|
||||
const colorArray = this.getSegment(segmentId)?.colour;
|
||||
return colorArray ? Color.fromNormalizedArray(colorArray, 0) : undefined;
|
||||
}
|
||||
|
||||
/** Get the list of detail levels available for the given mesh segment. */
|
||||
getMeshDetailLevels(segmentId: number): number[] {
|
||||
const segmentIds = this.raw.grid.segmentation_meshes.mesh_component_numbers.segment_ids;
|
||||
if (!segmentIds) return [];
|
||||
const details = segmentIds[segmentId].detail_lvls;
|
||||
return Object.keys(details).map(s => parseInt(s));
|
||||
}
|
||||
|
||||
/** Get the worst available detail level that is not worse than preferredDetail.
|
||||
* If preferredDetail is null, get the worst detail level overall.
|
||||
* (worse = greater number) */
|
||||
getSufficientMeshDetail(segmentId: number, preferredDetail: number | null) {
|
||||
let availDetails = this.getMeshDetailLevels(segmentId);
|
||||
if (preferredDetail !== null) {
|
||||
availDetails = availDetails.filter(det => det <= preferredDetail);
|
||||
}
|
||||
return Math.max(...availDetails);
|
||||
}
|
||||
|
||||
/** IDs of all segments available as meshes */
|
||||
get meshSegmentIds() {
|
||||
const segmentIds = this.raw.grid.segmentation_meshes.mesh_component_numbers.segment_ids;
|
||||
if (!segmentIds) return [];
|
||||
return Object.keys(segmentIds).map(s => parseInt(s));
|
||||
}
|
||||
|
||||
get gridTotalVolume() {
|
||||
const [vx, vy, vz] = this.raw.grid.volumes.voxel_size[1];
|
||||
const [gx, gy, gz] = this.raw.grid.volumes.grid_dimensions;
|
||||
return vx * vy * vz * gx * gy * gz;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author David Sehnal <david.sehnal@gmail.com>
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
@@ -137,6 +137,18 @@ class Camera implements ICamera {
|
||||
return state;
|
||||
}
|
||||
|
||||
getCenter(target: Vec3, radius?: number): Partial<Camera.Snapshot> {
|
||||
Vec3.sub(this.deltaDirection, this.target, this.position);
|
||||
Vec3.sub(this.newPosition, target, this.deltaDirection);
|
||||
|
||||
const state = Camera.copySnapshot(Camera.createDefaultSnapshot(), this.state);
|
||||
state.target = Vec3.clone(target);
|
||||
state.position = Vec3.clone(this.newPosition);
|
||||
if (radius) state.radius = Math.max(radius, 0.01);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
getInvariantFocus(target: Vec3, radius: number, up: Vec3, dir: Vec3): Partial<Camera.Snapshot> {
|
||||
const r = Math.max(radius, 0.01);
|
||||
const targetDistance = this.getTargetDistance(r);
|
||||
@@ -160,6 +172,10 @@ class Camera implements ICamera {
|
||||
}
|
||||
}
|
||||
|
||||
center(target: Vec3, durationMs?: number) {
|
||||
this.setState(this.getCenter(target), durationMs);
|
||||
}
|
||||
|
||||
/** Transform point into 2D window coordinates. */
|
||||
project(out: Vec4, point: Vec3) {
|
||||
return cameraProject(out, point, this.viewport, this.projectionView);
|
||||
|
||||
@@ -120,6 +120,7 @@ interface Canvas3DContext {
|
||||
|
||||
namespace Canvas3DContext {
|
||||
export const DefaultAttribs = {
|
||||
powerPreference: 'high-performance' as WebGLContextAttributes['powerPreference'],
|
||||
failIfMajorPerformanceCaveat: false,
|
||||
/** true by default to avoid issues with Safari (Jan 2021) */
|
||||
antialias: true,
|
||||
@@ -140,8 +141,9 @@ namespace Canvas3DContext {
|
||||
|
||||
if (a.enableWboit && a.enableDpoit) throw new Error('Multiple transparency methods not allowed.');
|
||||
|
||||
const { failIfMajorPerformanceCaveat, antialias, preserveDrawingBuffer, pixelScale, preferWebGl1 } = a;
|
||||
const { powerPreference, failIfMajorPerformanceCaveat, antialias, preserveDrawingBuffer, pixelScale, preferWebGl1 } = a;
|
||||
const gl = getGLContext(canvas, {
|
||||
powerPreference,
|
||||
failIfMajorPerformanceCaveat,
|
||||
antialias,
|
||||
preserveDrawingBuffer,
|
||||
|
||||
@@ -135,7 +135,7 @@ export class CameraHelper {
|
||||
}
|
||||
}
|
||||
|
||||
export const enum CameraHelperAxis {
|
||||
export enum CameraHelperAxis {
|
||||
None = 0,
|
||||
X,
|
||||
Y,
|
||||
|
||||
@@ -19,7 +19,7 @@ type HoverEvent = import('../canvas3d').Canvas3D.HoverEvent
|
||||
type DragEvent = import('../canvas3d').Canvas3D.DragEvent
|
||||
type ClickEvent = import('../canvas3d').Canvas3D.ClickEvent
|
||||
|
||||
const enum InputEvent { Move, Click, Drag }
|
||||
enum InputEvent { Move, Click, Drag }
|
||||
|
||||
const tmpPosA = Vec3();
|
||||
const tmpPos = Vec3();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2019-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
* @author Áron Samuel Kovács <aron.kovacs@mail.muni.cz>
|
||||
@@ -142,7 +142,7 @@ export class DrawPass {
|
||||
}
|
||||
|
||||
if (PostprocessingPass.isEnabled(postprocessingProps)) {
|
||||
if (PostprocessingPass.isOutlineEnabled(postprocessingProps)) {
|
||||
if (PostprocessingPass.isTransparentOutlineEnabled(postprocessingProps)) {
|
||||
this.depthTargetTransparent.bind();
|
||||
renderer.clearDepth(true);
|
||||
if (scene.opacityAverage < 1) {
|
||||
@@ -150,7 +150,7 @@ export class DrawPass {
|
||||
}
|
||||
}
|
||||
|
||||
this.postprocessing.render(camera, false, transparentBackground, renderer.props.backgroundColor, postprocessingProps);
|
||||
this.postprocessing.render(camera, false, transparentBackground, renderer.props.backgroundColor, postprocessingProps, renderer.light);
|
||||
}
|
||||
|
||||
this.depthTextureOpaque.detachFramebuffer(this.colorTarget.framebuffer, 'depth');
|
||||
@@ -196,7 +196,7 @@ export class DrawPass {
|
||||
}
|
||||
|
||||
if (PostprocessingPass.isEnabled(postprocessingProps)) {
|
||||
if (PostprocessingPass.isOutlineEnabled(postprocessingProps)) {
|
||||
if (PostprocessingPass.isTransparentOutlineEnabled(postprocessingProps)) {
|
||||
this.depthTargetTransparent.bind();
|
||||
renderer.clearDepth(true);
|
||||
if (scene.opacityAverage < 1) {
|
||||
@@ -204,7 +204,7 @@ export class DrawPass {
|
||||
}
|
||||
}
|
||||
|
||||
this.postprocessing.render(camera, false, transparentBackground, renderer.props.backgroundColor, postprocessingProps);
|
||||
this.postprocessing.render(camera, false, transparentBackground, renderer.props.backgroundColor, postprocessingProps, renderer.light);
|
||||
}
|
||||
|
||||
// render transparent primitives and volumes
|
||||
@@ -260,7 +260,7 @@ export class DrawPass {
|
||||
this.colorTarget.depthRenderbuffer?.detachFramebuffer(this.postprocessing.target.framebuffer);
|
||||
}
|
||||
|
||||
if (PostprocessingPass.isOutlineEnabled(postprocessingProps)) {
|
||||
if (PostprocessingPass.isTransparentOutlineEnabled(postprocessingProps)) {
|
||||
this.depthTargetTransparent.bind();
|
||||
renderer.clearDepth(true);
|
||||
if (scene.opacityAverage < 1) {
|
||||
@@ -268,7 +268,7 @@ export class DrawPass {
|
||||
}
|
||||
}
|
||||
|
||||
this.postprocessing.render(camera, false, transparentBackground, renderer.props.backgroundColor, postprocessingProps);
|
||||
this.postprocessing.render(camera, false, transparentBackground, renderer.props.backgroundColor, postprocessingProps, renderer.light);
|
||||
|
||||
if (!this.packedDepth) {
|
||||
this.depthTextureOpaque.attachFramebuffer(this.postprocessing.target.framebuffer, 'depth');
|
||||
@@ -312,7 +312,7 @@ export class DrawPass {
|
||||
|
||||
const { x, y, width, height } = camera.viewport;
|
||||
renderer.setViewport(x, y, width, height);
|
||||
renderer.update(camera);
|
||||
renderer.update(camera, scene);
|
||||
|
||||
if (transparentBackground && !antialiasingEnabled && toDrawingBuffer) {
|
||||
this.drawTarget.bind();
|
||||
@@ -360,7 +360,7 @@ export class DrawPass {
|
||||
}
|
||||
if (helper.camera.isEnabled) {
|
||||
helper.camera.update(camera);
|
||||
renderer.update(helper.camera.camera);
|
||||
renderer.update(helper.camera.camera, helper.camera.scene);
|
||||
renderer.renderBlended(helper.camera.scene, helper.camera.camera);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2021-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
@@ -27,6 +27,8 @@ export const MarkingParams = {
|
||||
highlightEdgeColor: PD.Color(Color.darken(Color.fromNormalizedRgb(1.0, 0.4, 0.6), 1.0)),
|
||||
selectEdgeColor: PD.Color(Color.darken(Color.fromNormalizedRgb(0.2, 1.0, 0.1), 1.0)),
|
||||
edgeScale: PD.Numeric(1, { min: 1, max: 3, step: 1 }, { description: 'Thickness of the edge.' }),
|
||||
highlightEdgeStrength: PD.Numeric(1.0, { min: 0, max: 1, step: 0.1 }),
|
||||
selectEdgeStrength: PD.Numeric(1.0, { min: 0, max: 1, step: 0.1 }),
|
||||
ghostEdgeStrength: PD.Numeric(0.3, { min: 0, max: 1, step: 0.1 }, { description: 'Opacity of the hidden edges that are covered by other geometry. When set to 1, one less geometry render pass is done.' }),
|
||||
innerEdgeFactor: PD.Numeric(1.5, { min: 0, max: 3, step: 0.1 }, { description: 'Factor to multiply the inner edge color with - for added contrast.' }),
|
||||
};
|
||||
@@ -101,7 +103,7 @@ export class MarkingPass {
|
||||
}
|
||||
|
||||
update(props: MarkingProps) {
|
||||
const { highlightEdgeColor, selectEdgeColor, edgeScale, innerEdgeFactor, ghostEdgeStrength } = props;
|
||||
const { highlightEdgeColor, selectEdgeColor, edgeScale, innerEdgeFactor, ghostEdgeStrength, highlightEdgeStrength, selectEdgeStrength } = props;
|
||||
|
||||
const { values: edgeValues } = this.edge;
|
||||
const _edgeScale = Math.round(edgeScale * this.webgl.pixelRatio);
|
||||
@@ -113,8 +115,10 @@ export class MarkingPass {
|
||||
const { values: overlayValues } = this.overlay;
|
||||
ValueCell.update(overlayValues.uHighlightEdgeColor, Color.toVec3Normalized(overlayValues.uHighlightEdgeColor.ref.value, highlightEdgeColor));
|
||||
ValueCell.update(overlayValues.uSelectEdgeColor, Color.toVec3Normalized(overlayValues.uSelectEdgeColor.ref.value, selectEdgeColor));
|
||||
ValueCell.update(overlayValues.uInnerEdgeFactor, innerEdgeFactor);
|
||||
ValueCell.update(overlayValues.uGhostEdgeStrength, ghostEdgeStrength);
|
||||
ValueCell.updateIfChanged(overlayValues.uInnerEdgeFactor, innerEdgeFactor);
|
||||
ValueCell.updateIfChanged(overlayValues.uGhostEdgeStrength, ghostEdgeStrength);
|
||||
ValueCell.updateIfChanged(overlayValues.uHighlightEdgeStrength, highlightEdgeStrength);
|
||||
ValueCell.updateIfChanged(overlayValues.uSelectEdgeStrength, selectEdgeStrength);
|
||||
}
|
||||
|
||||
render(viewport: Viewport, target: RenderTarget | undefined) {
|
||||
@@ -170,6 +174,8 @@ const OverlaySchema = {
|
||||
uTexSizeInv: UniformSpec('v2'),
|
||||
uHighlightEdgeColor: UniformSpec('v3'),
|
||||
uSelectEdgeColor: UniformSpec('v3'),
|
||||
uHighlightEdgeStrength: UniformSpec('f'),
|
||||
uSelectEdgeStrength: UniformSpec('f'),
|
||||
uGhostEdgeStrength: UniformSpec('f'),
|
||||
uInnerEdgeFactor: UniformSpec('f'),
|
||||
};
|
||||
@@ -186,6 +192,8 @@ function getOverlayRenderable(ctx: WebGLContext, edgeTexture: Texture): OverlayR
|
||||
uTexSizeInv: ValueCell.create(Vec2.create(1 / width, 1 / height)),
|
||||
uHighlightEdgeColor: ValueCell.create(Vec3()),
|
||||
uSelectEdgeColor: ValueCell.create(Vec3()),
|
||||
uHighlightEdgeStrength: ValueCell.create(1),
|
||||
uSelectEdgeStrength: ValueCell.create(1),
|
||||
uGhostEdgeStrength: ValueCell.create(0),
|
||||
uInnerEdgeFactor: ValueCell.create(0),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2019-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
@@ -172,7 +172,7 @@ export class PickPass {
|
||||
|
||||
private renderVariant(renderer: Renderer, camera: ICamera, scene: Scene, helper: Helper, variant: 'pick' | 'depth', pickType: number) {
|
||||
renderer.clear(false);
|
||||
renderer.update(camera);
|
||||
renderer.update(camera, scene);
|
||||
renderer.renderPick(scene.primitives, camera, variant, null, pickType);
|
||||
|
||||
if (helper.handle.isEnabled) {
|
||||
@@ -181,7 +181,7 @@ export class PickPass {
|
||||
|
||||
if (helper.camera.isEnabled) {
|
||||
helper.camera.update(camera);
|
||||
renderer.update(helper.camera.camera);
|
||||
renderer.update(helper.camera.camera, helper.camera.scene);
|
||||
renderer.renderPick(helper.camera.scene, helper.camera.camera, variant, null, pickType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
* @author Áron Samuel Kovács <aron.kovacs@mail.muni.cz>
|
||||
* @author Ludovic Autin <ludovic.autin@gmail.com>
|
||||
*/
|
||||
|
||||
import { CopyRenderable, createCopyRenderable, QuadSchema, QuadValues } from '../../mol-gl/compute/util';
|
||||
@@ -30,6 +31,8 @@ import { SmaaParams, SmaaPass } from './smaa';
|
||||
import { isTimingMode } from '../../mol-util/debug';
|
||||
import { BackgroundParams, BackgroundPass } from './background';
|
||||
import { AssetManager } from '../../mol-util/assets';
|
||||
import { Light } from '../../mol-gl/renderer';
|
||||
import { shadows_frag } from '../../mol-gl/shader/shadows.frag';
|
||||
|
||||
const OutlinesSchema = {
|
||||
...QuadSchema,
|
||||
@@ -42,10 +45,12 @@ const OutlinesSchema = {
|
||||
uFar: UniformSpec('f'),
|
||||
|
||||
uMaxPossibleViewZDiff: UniformSpec('f'),
|
||||
|
||||
dTransparentOutline: DefineSpec('boolean'),
|
||||
};
|
||||
type OutlinesRenderable = ComputeRenderable<Values<typeof OutlinesSchema>>
|
||||
|
||||
function getOutlinesRenderable(ctx: WebGLContext, depthTextureOpaque: Texture, depthTextureTransparent: Texture): OutlinesRenderable {
|
||||
function getOutlinesRenderable(ctx: WebGLContext, depthTextureOpaque: Texture, depthTextureTransparent: Texture, transparentOutline: boolean): OutlinesRenderable {
|
||||
const width = depthTextureOpaque.getWidth();
|
||||
const height = depthTextureOpaque.getHeight();
|
||||
|
||||
@@ -60,6 +65,8 @@ function getOutlinesRenderable(ctx: WebGLContext, depthTextureOpaque: Texture, d
|
||||
uFar: ValueCell.create(10000),
|
||||
|
||||
uMaxPossibleViewZDiff: ValueCell.create(0.5),
|
||||
|
||||
dTransparentOutline: ValueCell.create(transparentOutline),
|
||||
};
|
||||
|
||||
const schema = { ...OutlinesSchema };
|
||||
@@ -69,6 +76,64 @@ function getOutlinesRenderable(ctx: WebGLContext, depthTextureOpaque: Texture, d
|
||||
return createComputeRenderable(renderItem, values);
|
||||
}
|
||||
|
||||
const ShadowsSchema = {
|
||||
...QuadSchema,
|
||||
tDepth: TextureSpec('texture', 'rgba', 'ubyte', 'nearest'),
|
||||
uTexSize: UniformSpec('v2'),
|
||||
|
||||
uProjection: UniformSpec('m4'),
|
||||
uInvProjection: UniformSpec('m4'),
|
||||
uBounds: UniformSpec('v4'),
|
||||
|
||||
dOrthographic: DefineSpec('number'),
|
||||
uNear: UniformSpec('f'),
|
||||
uFar: UniformSpec('f'),
|
||||
|
||||
dSteps: DefineSpec('number'),
|
||||
uMaxDistance: UniformSpec('f'),
|
||||
uTolerance: UniformSpec('f'),
|
||||
uBias: UniformSpec('f'),
|
||||
|
||||
uLightDirection: UniformSpec('v3[]'),
|
||||
uLightColor: UniformSpec('v3[]'),
|
||||
dLightCount: DefineSpec('number'),
|
||||
};
|
||||
type ShadowsRenderable = ComputeRenderable<Values<typeof ShadowsSchema>>
|
||||
|
||||
function getShadowsRenderable(ctx: WebGLContext, depthTexture: Texture): ShadowsRenderable {
|
||||
const width = depthTexture.getWidth();
|
||||
const height = depthTexture.getHeight();
|
||||
|
||||
const values: Values<typeof ShadowsSchema> = {
|
||||
...QuadValues,
|
||||
tDepth: ValueCell.create(depthTexture),
|
||||
uTexSize: ValueCell.create(Vec2.create(width, height)),
|
||||
|
||||
uProjection: ValueCell.create(Mat4.identity()),
|
||||
uInvProjection: ValueCell.create(Mat4.identity()),
|
||||
uBounds: ValueCell.create(Vec4()),
|
||||
|
||||
dOrthographic: ValueCell.create(0),
|
||||
uNear: ValueCell.create(1),
|
||||
uFar: ValueCell.create(10000),
|
||||
|
||||
dSteps: ValueCell.create(1),
|
||||
uMaxDistance: ValueCell.create(3.0),
|
||||
uTolerance: ValueCell.create(1.0),
|
||||
uBias: ValueCell.create(0.6),
|
||||
|
||||
uLightDirection: ValueCell.create([]),
|
||||
uLightColor: ValueCell.create([]),
|
||||
dLightCount: ValueCell.create(0),
|
||||
};
|
||||
|
||||
const schema = { ...ShadowsSchema };
|
||||
const shaderCode = ShaderCode('shadows', quad_vert, shadows_frag);
|
||||
const renderItem = createComputeRenderItem(ctx, 'triangles', shaderCode, schema, values);
|
||||
|
||||
return createComputeRenderable(renderItem, values);
|
||||
}
|
||||
|
||||
const SsaoSchema = {
|
||||
...QuadSchema,
|
||||
tDepth: TextureSpec('texture', 'rgba', 'ubyte', 'nearest'),
|
||||
@@ -204,6 +269,7 @@ const PostprocessingSchema = {
|
||||
tColor: TextureSpec('texture', 'rgba', 'ubyte', 'nearest'),
|
||||
tDepthOpaque: TextureSpec('texture', 'rgba', 'ubyte', 'nearest'),
|
||||
tDepthTransparent: TextureSpec('texture', 'rgba', 'ubyte', 'nearest'),
|
||||
tShadows: TextureSpec('texture', 'rgba', 'ubyte', 'nearest'),
|
||||
tOutlines: TextureSpec('texture', 'rgba', 'ubyte', 'nearest'),
|
||||
uTexSize: UniformSpec('v2'),
|
||||
|
||||
@@ -221,19 +287,25 @@ const PostprocessingSchema = {
|
||||
dOcclusionEnable: DefineSpec('boolean'),
|
||||
uOcclusionOffset: UniformSpec('v2'),
|
||||
|
||||
dShadowEnable: DefineSpec('boolean'),
|
||||
|
||||
dOutlineEnable: DefineSpec('boolean'),
|
||||
dOutlineScale: DefineSpec('number'),
|
||||
uOutlineThreshold: UniformSpec('f'),
|
||||
|
||||
dTransparentOutline: DefineSpec('boolean'),
|
||||
};
|
||||
type PostprocessingRenderable = ComputeRenderable<Values<typeof PostprocessingSchema>>
|
||||
|
||||
function getPostprocessingRenderable(ctx: WebGLContext, colorTexture: Texture, depthTextureOpaque: Texture, depthTextureTransparent: Texture, outlinesTexture: Texture, ssaoDepthTexture: Texture): PostprocessingRenderable {
|
||||
|
||||
function getPostprocessingRenderable(ctx: WebGLContext, colorTexture: Texture, depthTextureOpaque: Texture, depthTextureTransparent: Texture, shadowsTexture: Texture, outlinesTexture: Texture, ssaoDepthTexture: Texture, transparentOutline: boolean): PostprocessingRenderable {
|
||||
const values: Values<typeof PostprocessingSchema> = {
|
||||
...QuadValues,
|
||||
tSsaoDepth: ValueCell.create(ssaoDepthTexture),
|
||||
tColor: ValueCell.create(colorTexture),
|
||||
tDepthOpaque: ValueCell.create(depthTextureOpaque),
|
||||
tDepthTransparent: ValueCell.create(depthTextureTransparent),
|
||||
tShadows: ValueCell.create(shadowsTexture),
|
||||
tOutlines: ValueCell.create(outlinesTexture),
|
||||
uTexSize: ValueCell.create(Vec2.create(colorTexture.getWidth(), colorTexture.getHeight())),
|
||||
|
||||
@@ -251,9 +323,13 @@ function getPostprocessingRenderable(ctx: WebGLContext, colorTexture: Texture, d
|
||||
dOcclusionEnable: ValueCell.create(true),
|
||||
uOcclusionOffset: ValueCell.create(Vec2.create(0, 0)),
|
||||
|
||||
dShadowEnable: ValueCell.create(false),
|
||||
|
||||
dOutlineEnable: ValueCell.create(false),
|
||||
dOutlineScale: ValueCell.create(1),
|
||||
uOutlineThreshold: ValueCell.create(0.33),
|
||||
|
||||
dTransparentOutline: ValueCell.create(transparentOutline),
|
||||
};
|
||||
|
||||
const schema = { ...PostprocessingSchema };
|
||||
@@ -274,11 +350,21 @@ export const PostprocessingParams = {
|
||||
}),
|
||||
off: PD.Group({})
|
||||
}, { cycle: true, description: 'Darken occluded crevices with the ambient occlusion effect' }),
|
||||
shadow: PD.MappedStatic('off', {
|
||||
on: PD.Group({
|
||||
steps: PD.Numeric(1, { min: 1, max: 64, step: 1 }),
|
||||
bias: PD.Numeric(0.6, { min: 0.0, max: 1.0, step: 0.01 }),
|
||||
maxDistance: PD.Numeric(3, { min: 0, max: 256, step: 1 }),
|
||||
tolerance: PD.Numeric(1.0, { min: 0.0, max: 10.0, step: 0.1 }),
|
||||
}),
|
||||
off: PD.Group({})
|
||||
}, { cycle: true, description: 'Simplistic shadows' }),
|
||||
outline: PD.MappedStatic('off', {
|
||||
on: PD.Group({
|
||||
scale: PD.Numeric(1, { min: 1, max: 5, step: 1 }),
|
||||
threshold: PD.Numeric(0.33, { min: 0.01, max: 1, step: 0.01 }),
|
||||
color: PD.Color(Color(0x000000)),
|
||||
includeTransparent: PD.Boolean(true, { description: 'Whether to show outline for transparent objects' }),
|
||||
}),
|
||||
off: PD.Group({})
|
||||
}, { cycle: true, description: 'Draw outline around 3D objects' }),
|
||||
@@ -289,15 +375,16 @@ export const PostprocessingParams = {
|
||||
}, { options: [['fxaa', 'FXAA'], ['smaa', 'SMAA'], ['off', 'Off']], description: 'Smooth pixel edges' }),
|
||||
background: PD.Group(BackgroundParams, { isFlat: true }),
|
||||
};
|
||||
|
||||
export type PostprocessingProps = PD.Values<typeof PostprocessingParams>
|
||||
|
||||
export class PostprocessingPass {
|
||||
static isEnabled(props: PostprocessingProps) {
|
||||
return props.occlusion.name === 'on' || props.outline.name === 'on' || props.background.variant.name !== 'off';
|
||||
return props.occlusion.name === 'on' || props.shadow.name === 'on' || props.outline.name === 'on' || props.background.variant.name !== 'off';
|
||||
}
|
||||
|
||||
static isOutlineEnabled(props: PostprocessingProps) {
|
||||
return props.outline.name === 'on';
|
||||
static isTransparentOutlineEnabled(props: PostprocessingProps) {
|
||||
return props.outline.name === 'on' && props.outline.params.includeTransparent;
|
||||
}
|
||||
|
||||
readonly target: RenderTarget;
|
||||
@@ -305,6 +392,9 @@ export class PostprocessingPass {
|
||||
private readonly outlinesTarget: RenderTarget;
|
||||
private readonly outlinesRenderable: OutlinesRenderable;
|
||||
|
||||
private readonly shadowsTarget: RenderTarget;
|
||||
private readonly shadowsRenderable: ShadowsRenderable;
|
||||
|
||||
private readonly ssaoFramebuffer: Framebuffer;
|
||||
private readonly ssaoBlurFirstPassFramebuffer: Framebuffer;
|
||||
private readonly ssaoBlurSecondPassFramebuffer: Framebuffer;
|
||||
@@ -348,7 +438,10 @@ export class PostprocessingPass {
|
||||
this.target = webgl.createRenderTarget(width, height, false, 'uint8', 'linear');
|
||||
|
||||
this.outlinesTarget = webgl.createRenderTarget(width, height, false);
|
||||
this.outlinesRenderable = getOutlinesRenderable(webgl, depthTextureOpaque, depthTextureTransparent);
|
||||
this.outlinesRenderable = getOutlinesRenderable(webgl, depthTextureOpaque, depthTextureTransparent, true);
|
||||
|
||||
this.shadowsTarget = webgl.createRenderTarget(width, height, false);
|
||||
this.shadowsRenderable = getShadowsRenderable(webgl, depthTextureOpaque);
|
||||
|
||||
this.ssaoFramebuffer = webgl.resources.framebuffer();
|
||||
this.ssaoBlurFirstPassFramebuffer = webgl.resources.framebuffer();
|
||||
@@ -373,7 +466,7 @@ export class PostprocessingPass {
|
||||
this.ssaoRenderable = getSsaoRenderable(webgl, this.downsampleFactor === 1 ? depthTextureOpaque : this.downsampledDepthTarget.texture);
|
||||
this.ssaoBlurFirstPassRenderable = getSsaoBlurRenderable(webgl, this.ssaoDepthTexture, 'horizontal');
|
||||
this.ssaoBlurSecondPassRenderable = getSsaoBlurRenderable(webgl, this.ssaoDepthBlurProxyTexture, 'vertical');
|
||||
this.renderable = getPostprocessingRenderable(webgl, colorTarget.texture, depthTextureOpaque, depthTextureTransparent, this.outlinesTarget.texture, this.ssaoDepthTexture);
|
||||
this.renderable = getPostprocessingRenderable(webgl, colorTarget.texture, depthTextureOpaque, depthTextureTransparent, this.shadowsTarget.texture, this.outlinesTarget.texture, this.ssaoDepthTexture, true);
|
||||
|
||||
this.background = new BackgroundPass(webgl, assetManager, width, height);
|
||||
}
|
||||
@@ -389,12 +482,14 @@ export class PostprocessingPass {
|
||||
const sh = Math.floor(height * this.ssaoScale);
|
||||
this.target.setSize(width, height);
|
||||
this.outlinesTarget.setSize(width, height);
|
||||
this.shadowsTarget.setSize(width, height);
|
||||
this.downsampledDepthTarget.setSize(sw, sh);
|
||||
this.ssaoDepthTexture.define(sw, sh);
|
||||
this.ssaoDepthBlurProxyTexture.define(sw, sh);
|
||||
|
||||
ValueCell.update(this.renderable.values.uTexSize, Vec2.set(this.renderable.values.uTexSize.ref.value, width, height));
|
||||
ValueCell.update(this.outlinesRenderable.values.uTexSize, Vec2.set(this.outlinesRenderable.values.uTexSize.ref.value, width, height));
|
||||
ValueCell.update(this.shadowsRenderable.values.uTexSize, Vec2.set(this.shadowsRenderable.values.uTexSize.ref.value, width, height));
|
||||
ValueCell.update(this.downsampleDepthRenderable.values.uTexSize, Vec2.set(this.downsampleDepthRenderable.values.uTexSize.ref.value, sw, sh));
|
||||
ValueCell.update(this.ssaoRenderable.values.uTexSize, Vec2.set(this.ssaoRenderable.values.uTexSize.ref.value, sw, sh));
|
||||
ValueCell.update(this.ssaoBlurFirstPassRenderable.values.uTexSize, Vec2.set(this.ssaoBlurFirstPassRenderable.values.uTexSize.ref.value, sw, sh));
|
||||
@@ -404,25 +499,29 @@ export class PostprocessingPass {
|
||||
}
|
||||
}
|
||||
|
||||
private updateState(camera: ICamera, transparentBackground: boolean, backgroundColor: Color, props: PostprocessingProps) {
|
||||
private updateState(camera: ICamera, transparentBackground: boolean, backgroundColor: Color, props: PostprocessingProps, light: Light) {
|
||||
let needsUpdateShadows = false;
|
||||
let needsUpdateMain = false;
|
||||
let needsUpdateSsao = false;
|
||||
let needsUpdateSsaoBlur = false;
|
||||
let needsUpdateOutlines = false;
|
||||
|
||||
const orthographic = camera.state.mode === 'orthographic' ? 1 : 0;
|
||||
const outlinesEnabled = props.outline.name === 'on';
|
||||
const shadowsEnabled = props.shadow.name === 'on';
|
||||
const occlusionEnabled = props.occlusion.name === 'on';
|
||||
|
||||
const invProjection = Mat4.identity();
|
||||
Mat4.invert(invProjection, camera.projection);
|
||||
|
||||
const [w, h] = this.renderable.values.uTexSize.ref.value;
|
||||
const v = camera.viewport;
|
||||
|
||||
if (props.occlusion.name === 'on') {
|
||||
ValueCell.update(this.ssaoRenderable.values.uProjection, camera.projection);
|
||||
ValueCell.update(this.ssaoRenderable.values.uInvProjection, invProjection);
|
||||
|
||||
const [w, h] = this.renderable.values.uTexSize.ref.value;
|
||||
const b = this.ssaoRenderable.values.uBounds;
|
||||
const v = camera.viewport;
|
||||
const s = this.ssaoScale;
|
||||
Vec4.set(b.ref.value,
|
||||
Math.floor(v.x * s) / (w * s),
|
||||
@@ -494,8 +593,41 @@ export class PostprocessingPass {
|
||||
}
|
||||
}
|
||||
|
||||
if (props.shadow.name === 'on') {
|
||||
ValueCell.update(this.shadowsRenderable.values.uProjection, camera.projection);
|
||||
ValueCell.update(this.shadowsRenderable.values.uInvProjection, invProjection);
|
||||
|
||||
Vec4.set(this.shadowsRenderable.values.uBounds.ref.value,
|
||||
v.x / w,
|
||||
v.y / h,
|
||||
(v.x + v.width) / w,
|
||||
(v.y + v.height) / h
|
||||
);
|
||||
ValueCell.update(this.shadowsRenderable.values.uBounds, this.shadowsRenderable.values.uBounds.ref.value);
|
||||
|
||||
ValueCell.updateIfChanged(this.shadowsRenderable.values.uNear, camera.near);
|
||||
ValueCell.updateIfChanged(this.shadowsRenderable.values.uFar, camera.far);
|
||||
ValueCell.updateIfChanged(this.shadowsRenderable.values.dOrthographic, orthographic);
|
||||
|
||||
ValueCell.updateIfChanged(this.shadowsRenderable.values.uMaxDistance, props.shadow.params.maxDistance);
|
||||
ValueCell.updateIfChanged(this.shadowsRenderable.values.uTolerance, props.shadow.params.tolerance);
|
||||
ValueCell.updateIfChanged(this.shadowsRenderable.values.uBias, props.shadow.params.bias);
|
||||
if (this.shadowsRenderable.values.dSteps.ref.value !== props.shadow.params.steps) {
|
||||
ValueCell.update(this.shadowsRenderable.values.dSteps, props.shadow.params.steps);
|
||||
needsUpdateShadows = true;
|
||||
}
|
||||
|
||||
ValueCell.update(this.shadowsRenderable.values.uLightDirection, light.direction);
|
||||
ValueCell.update(this.shadowsRenderable.values.uLightColor, light.color);
|
||||
if (this.shadowsRenderable.values.dLightCount.ref.value !== light.count) {
|
||||
ValueCell.update(this.shadowsRenderable.values.dLightCount, light.count);
|
||||
needsUpdateShadows = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (props.outline.name === 'on') {
|
||||
let { threshold } = props.outline.params;
|
||||
let { threshold, includeTransparent } = props.outline.params;
|
||||
const transparentOutline = includeTransparent ?? true;
|
||||
// orthographic needs lower threshold
|
||||
if (camera.state.mode === 'orthographic') threshold /= 5;
|
||||
const factor = Math.pow(1000, threshold) / 1000;
|
||||
@@ -506,12 +638,16 @@ export class PostprocessingPass {
|
||||
ValueCell.updateIfChanged(this.outlinesRenderable.values.uNear, camera.near);
|
||||
ValueCell.updateIfChanged(this.outlinesRenderable.values.uFar, camera.far);
|
||||
ValueCell.updateIfChanged(this.outlinesRenderable.values.uMaxPossibleViewZDiff, maxPossibleViewZDiff);
|
||||
if (this.renderable.values.dTransparentOutline.ref.value !== transparentOutline) { needsUpdateOutlines = true; }
|
||||
ValueCell.updateIfChanged(this.outlinesRenderable.values.dTransparentOutline, transparentOutline);
|
||||
|
||||
ValueCell.update(this.renderable.values.uOutlineColor, Color.toVec3Normalized(this.renderable.values.uOutlineColor.ref.value, props.outline.params.color));
|
||||
|
||||
ValueCell.updateIfChanged(this.renderable.values.uMaxPossibleViewZDiff, maxPossibleViewZDiff);
|
||||
if (this.renderable.values.dOutlineScale.ref.value !== outlineScale) { needsUpdateMain = true; }
|
||||
ValueCell.updateIfChanged(this.renderable.values.dOutlineScale, outlineScale);
|
||||
if (this.renderable.values.dTransparentOutline.ref.value !== transparentOutline) { needsUpdateMain = true; }
|
||||
ValueCell.updateIfChanged(this.renderable.values.dTransparentOutline, transparentOutline);
|
||||
}
|
||||
|
||||
ValueCell.updateIfChanged(this.renderable.values.uFar, camera.far);
|
||||
@@ -522,11 +658,22 @@ export class PostprocessingPass {
|
||||
ValueCell.updateIfChanged(this.renderable.values.uTransparentBackground, transparentBackground);
|
||||
if (this.renderable.values.dOrthographic.ref.value !== orthographic) { needsUpdateMain = true; }
|
||||
ValueCell.updateIfChanged(this.renderable.values.dOrthographic, orthographic);
|
||||
|
||||
if (this.renderable.values.dOutlineEnable.ref.value !== outlinesEnabled) { needsUpdateMain = true; }
|
||||
ValueCell.updateIfChanged(this.renderable.values.dOutlineEnable, outlinesEnabled);
|
||||
if (this.renderable.values.dShadowEnable.ref.value !== shadowsEnabled) { needsUpdateMain = true; }
|
||||
ValueCell.updateIfChanged(this.renderable.values.dShadowEnable, shadowsEnabled);
|
||||
if (this.renderable.values.dOcclusionEnable.ref.value !== occlusionEnabled) { needsUpdateMain = true; }
|
||||
ValueCell.updateIfChanged(this.renderable.values.dOcclusionEnable, occlusionEnabled);
|
||||
|
||||
if (needsUpdateOutlines) {
|
||||
this.outlinesRenderable.update();
|
||||
}
|
||||
|
||||
if (needsUpdateShadows) {
|
||||
this.shadowsRenderable.update();
|
||||
}
|
||||
|
||||
if (needsUpdateSsao) {
|
||||
this.ssaoRenderable.update();
|
||||
}
|
||||
@@ -564,15 +711,20 @@ export class PostprocessingPass {
|
||||
this.transparentBackground = value;
|
||||
}
|
||||
|
||||
render(camera: ICamera, toDrawingBuffer: boolean, transparentBackground: boolean, backgroundColor: Color, props: PostprocessingProps) {
|
||||
render(camera: ICamera, toDrawingBuffer: boolean, transparentBackground: boolean, backgroundColor: Color, props: PostprocessingProps, light: Light) {
|
||||
if (isTimingMode) this.webgl.timer.mark('PostprocessingPass.render');
|
||||
this.updateState(camera, transparentBackground, backgroundColor, props);
|
||||
this.updateState(camera, transparentBackground, backgroundColor, props, light);
|
||||
|
||||
if (props.outline.name === 'on') {
|
||||
this.outlinesTarget.bind();
|
||||
this.outlinesRenderable.render();
|
||||
}
|
||||
|
||||
if (props.shadow.name === 'on') {
|
||||
this.shadowsTarget.bind();
|
||||
this.shadowsRenderable.render();
|
||||
}
|
||||
|
||||
// don't render occlusion if offset is given,
|
||||
// which will reuse the existing occlusion
|
||||
if (props.occlusion.name === 'on' && this.occlusionOffset[0] === 0 && this.occlusionOffset[1] === 0) {
|
||||
|
||||
@@ -93,20 +93,35 @@ namespace Column {
|
||||
return !!v && !!(v as Column<any>).schema && !!(v as Column<any>).value;
|
||||
}
|
||||
|
||||
export const enum ValueKind {
|
||||
// Value kinds are accessed very of often
|
||||
// Using a const enum is an internal optimization and is defined separately to better support
|
||||
// compiling with isolatedModules flag in 3rd party use-cases of Mol*.
|
||||
export const enum ValueKinds {
|
||||
/** Defined value (= 0) */
|
||||
Present = 0,
|
||||
/** Expressed in CIF as `.` */
|
||||
/** Expressed in CIF as `.` (= 1) */
|
||||
NotPresent = 1,
|
||||
/** Expressed in CIF as `?` */
|
||||
/** Expressed in CIF as `?` (= 2) */
|
||||
Unknown = 2
|
||||
}
|
||||
|
||||
export const ValueKind = {
|
||||
/** Defined value (= 0) */
|
||||
Present: ValueKinds.Present,
|
||||
/** Expressed in CIF as `.` (= 1) */
|
||||
NotPresent: ValueKinds.NotPresent,
|
||||
/** Expressed in CIF as `?` (= 2) */
|
||||
Unknown: ValueKinds.Unknown
|
||||
} as const;
|
||||
export type ValueKind = (typeof ValueKind)[keyof typeof ValueKinds];
|
||||
|
||||
|
||||
export function Undefined<T extends Schema>(rowCount: number, schema: T): Column<T['T']> {
|
||||
return constColumn(schema['T'], rowCount, schema, ValueKind.NotPresent);
|
||||
return constColumn(schema['T'], rowCount, schema, ValueKinds.NotPresent);
|
||||
}
|
||||
|
||||
export function ofConst<T extends Schema>(v: T['T'], rowCount: number, type: T): Column<T['T']> {
|
||||
return constColumn(v, rowCount, type, ValueKind.Present);
|
||||
return constColumn(v, rowCount, type, ValueKinds.Present);
|
||||
}
|
||||
|
||||
export function ofLambda<T extends Schema>(spec: LambdaSpec<T>): Column<T['T']> {
|
||||
@@ -256,7 +271,7 @@ function constColumn<T extends Column.Schema>(v: T['T'], rowCount: number, schem
|
||||
return {
|
||||
schema: schema,
|
||||
__array: void 0,
|
||||
isDefined: valueKind === Column.ValueKind.Present,
|
||||
isDefined: valueKind === Column.ValueKinds.Present,
|
||||
rowCount,
|
||||
value,
|
||||
valueKind: row => valueKind,
|
||||
@@ -276,7 +291,7 @@ function lambdaColumn<T extends Column.Schema>({ value, valueKind, areValuesEqua
|
||||
isDefined: true,
|
||||
rowCount,
|
||||
value,
|
||||
valueKind: valueKind ? valueKind : row => Column.ValueKind.Present,
|
||||
valueKind: valueKind ? valueKind : row => Column.ValueKinds.Present,
|
||||
toArray: params => {
|
||||
const { array, start } = ColumnHelpers.createArray(rowCount, params);
|
||||
for (let i = 0, _i = array.length; i < _i; i++) array[i] = value(i + start);
|
||||
@@ -304,7 +319,7 @@ function arrayColumn<T extends Column.Schema>({ array, schema, valueKind }: Colu
|
||||
isDefined: true,
|
||||
rowCount,
|
||||
value,
|
||||
valueKind: valueKind ? valueKind : row => Column.ValueKind.Present,
|
||||
valueKind: valueKind ? valueKind : row => Column.ValueKinds.Present,
|
||||
toArray: schema.valueType === 'str'
|
||||
? (schema as Column.Schema.Str).transform === 'lowercase'
|
||||
? params => {
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Table {
|
||||
rowCount,
|
||||
schema: schema[k],
|
||||
value: r => rows[r][k],
|
||||
valueKind: r => typeof rows[r][k] === 'undefined' ? Column.ValueKind.NotPresent : Column.ValueKind.Present
|
||||
valueKind: r => typeof rows[r][k] === 'undefined' ? Column.ValueKinds.NotPresent : Column.ValueKinds.Present
|
||||
});
|
||||
}
|
||||
return ret as R;
|
||||
@@ -267,7 +267,7 @@ namespace Table {
|
||||
StringBuilder.write(sb, '|');
|
||||
for (let i = 0; i < cols.length; i++) {
|
||||
const c = table[cols[i]];
|
||||
if (c.valueKind(r) === Column.ValueKind.Present) {
|
||||
if (c.valueKind(r) === Column.ValueKinds.Present) {
|
||||
StringBuilder.write(sb, c.value(r));
|
||||
StringBuilder.write(sb, '|');
|
||||
} else {
|
||||
|
||||
@@ -132,8 +132,8 @@ export namespace BaseGeometry {
|
||||
ValueCell.updateIfChanged(values.uBumpiness, props.material.bumpiness);
|
||||
|
||||
const clip = Clip.getClip(props.clip);
|
||||
ValueCell.update(values.dClipObjectCount, clip.objects.count);
|
||||
ValueCell.update(values.dClipVariant, clip.variant);
|
||||
ValueCell.updateIfChanged(values.dClipObjectCount, clip.objects.count);
|
||||
ValueCell.updateIfChanged(values.dClipVariant, clip.variant);
|
||||
ValueCell.update(values.uClipObjectType, clip.objects.type);
|
||||
ValueCell.update(values.uClipObjectInvert, clip.objects.invert);
|
||||
ValueCell.update(values.uClipObjectPosition, clip.objects.position);
|
||||
|
||||
@@ -158,6 +158,7 @@ export namespace Cylinders {
|
||||
ignoreLight: PD.Boolean(false, BaseGeometry.ShadingCategory),
|
||||
xrayShaded: PD.Boolean(false, BaseGeometry.ShadingCategory),
|
||||
transparentBackfaces: PD.Select('off', PD.arrayToOptions(['off', 'on', 'opaque']), BaseGeometry.ShadingCategory),
|
||||
solidInterior: PD.Boolean(true, BaseGeometry.ShadingCategory),
|
||||
bumpFrequency: PD.Numeric(0, { min: 0, max: 10, step: 0.1 }, BaseGeometry.ShadingCategory),
|
||||
bumpAmplitude: PD.Numeric(1, { min: 0, max: 5, step: 0.1 }, BaseGeometry.ShadingCategory),
|
||||
};
|
||||
@@ -245,6 +246,7 @@ export namespace Cylinders {
|
||||
dIgnoreLight: ValueCell.create(props.ignoreLight),
|
||||
dXrayShaded: ValueCell.create(props.xrayShaded),
|
||||
dTransparentBackfaces: ValueCell.create(props.transparentBackfaces),
|
||||
dSolidInterior: ValueCell.create(props.solidInterior),
|
||||
uBumpFrequency: ValueCell.create(props.bumpFrequency),
|
||||
uBumpAmplitude: ValueCell.create(props.bumpAmplitude),
|
||||
};
|
||||
@@ -263,6 +265,7 @@ export namespace Cylinders {
|
||||
ValueCell.updateIfChanged(values.dIgnoreLight, props.ignoreLight);
|
||||
ValueCell.updateIfChanged(values.dXrayShaded, props.xrayShaded);
|
||||
ValueCell.updateIfChanged(values.dTransparentBackfaces, props.transparentBackfaces);
|
||||
ValueCell.updateIfChanged(values.dSolidInterior, props.solidInterior);
|
||||
ValueCell.updateIfChanged(values.uBumpFrequency, props.bumpFrequency);
|
||||
ValueCell.updateIfChanged(values.uBumpAmplitude, props.bumpAmplitude);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
@@ -21,6 +21,7 @@ export type OverpaintData = {
|
||||
uOverpaintGridDim: ValueCell<Vec3>,
|
||||
uOverpaintGridTransform: ValueCell<Vec4>,
|
||||
dOverpaintType: ValueCell<string>,
|
||||
uOverpaintStrength: ValueCell<number>,
|
||||
}
|
||||
|
||||
export function applyOverpaintColor(array: Uint8Array, start: number, end: number, color: Color) {
|
||||
@@ -54,6 +55,7 @@ export function createOverpaint(count: number, type: OverpaintType, overpaintDat
|
||||
uOverpaintGridDim: ValueCell.create(Vec3.create(1, 1, 1)),
|
||||
uOverpaintGridTransform: ValueCell.create(Vec4.create(0, 0, 0, 1)),
|
||||
dOverpaintType: ValueCell.create(type),
|
||||
uOverpaintStrength: ValueCell.create(1),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -74,6 +76,7 @@ export function createEmptyOverpaint(overpaintData?: OverpaintData): OverpaintDa
|
||||
uOverpaintGridDim: ValueCell.create(Vec3.create(1, 1, 1)),
|
||||
uOverpaintGridTransform: ValueCell.create(Vec4.create(0, 0, 0, 1)),
|
||||
dOverpaintType: ValueCell.create('groupInstance'),
|
||||
uOverpaintStrength: ValueCell.create(1),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -130,6 +130,7 @@ export namespace Spheres {
|
||||
ignoreLight: PD.Boolean(false, BaseGeometry.ShadingCategory),
|
||||
xrayShaded: PD.Boolean(false, BaseGeometry.ShadingCategory),
|
||||
transparentBackfaces: PD.Select('off', PD.arrayToOptions(['off', 'on', 'opaque']), BaseGeometry.ShadingCategory),
|
||||
solidInterior: PD.Boolean(true, BaseGeometry.ShadingCategory),
|
||||
bumpFrequency: PD.Numeric(0, { min: 0, max: 10, step: 0.1 }, BaseGeometry.ShadingCategory),
|
||||
bumpAmplitude: PD.Numeric(1, { min: 0, max: 5, step: 0.1 }, BaseGeometry.ShadingCategory),
|
||||
};
|
||||
@@ -212,6 +213,7 @@ export namespace Spheres {
|
||||
dIgnoreLight: ValueCell.create(props.ignoreLight),
|
||||
dXrayShaded: ValueCell.create(props.xrayShaded),
|
||||
dTransparentBackfaces: ValueCell.create(props.transparentBackfaces),
|
||||
dSolidInterior: ValueCell.create(props.solidInterior),
|
||||
uBumpFrequency: ValueCell.create(props.bumpFrequency),
|
||||
uBumpAmplitude: ValueCell.create(props.bumpAmplitude),
|
||||
};
|
||||
@@ -230,6 +232,7 @@ export namespace Spheres {
|
||||
ValueCell.updateIfChanged(values.dIgnoreLight, props.ignoreLight);
|
||||
ValueCell.updateIfChanged(values.dXrayShaded, props.xrayShaded);
|
||||
ValueCell.updateIfChanged(values.dTransparentBackfaces, props.transparentBackfaces);
|
||||
ValueCell.updateIfChanged(values.dSolidInterior, props.solidInterior);
|
||||
ValueCell.updateIfChanged(values.uBumpFrequency, props.bumpFrequency);
|
||||
ValueCell.updateIfChanged(values.uBumpAmplitude, props.bumpAmplitude);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2021-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
@@ -21,6 +21,7 @@ export type SubstanceData = {
|
||||
uSubstanceGridDim: ValueCell<Vec3>,
|
||||
uSubstanceGridTransform: ValueCell<Vec4>,
|
||||
dSubstanceType: ValueCell<string>,
|
||||
uSubstanceStrength: ValueCell<number>,
|
||||
}
|
||||
|
||||
export function applySubstanceMaterial(array: Uint8Array, start: number, end: number, material: Material) {
|
||||
@@ -54,6 +55,7 @@ export function createSubstance(count: number, type: SubstanceType, substanceDat
|
||||
uSubstanceGridDim: ValueCell.create(Vec3.create(1, 1, 1)),
|
||||
uSubstanceGridTransform: ValueCell.create(Vec4.create(0, 0, 0, 1)),
|
||||
dSubstanceType: ValueCell.create(type),
|
||||
uSubstanceStrength: ValueCell.create(1),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -74,6 +76,7 @@ export function createEmptySubstance(substanceData?: SubstanceData): SubstanceDa
|
||||
uSubstanceGridDim: ValueCell.create(Vec3.create(1, 1, 1)),
|
||||
uSubstanceGridTransform: ValueCell.create(Vec4.create(0, 0, 0, 1)),
|
||||
dSubstanceType: ValueCell.create('groupInstance'),
|
||||
uSubstanceStrength: ValueCell.create(1),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
import { ValueCell } from '../../../mol-util';
|
||||
import { Sphere3D } from '../../../mol-math/geometry';
|
||||
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
|
||||
import { LocationIterator } from '../../../mol-geo/util/location-iterator';
|
||||
import { LocationIterator, PositionLocation } from '../../../mol-geo/util/location-iterator';
|
||||
import { TransformData } from '../transform-data';
|
||||
import { createColors } from '../color-data';
|
||||
import { createMarkers } from '../marker-data';
|
||||
@@ -20,11 +20,12 @@ import { createEmptyTransparency } from '../transparency-data';
|
||||
import { TextureMeshValues } from '../../../mol-gl/renderable/texture-mesh';
|
||||
import { calculateTransformBoundingSphere } from '../../../mol-gl/renderable/util';
|
||||
import { createNullTexture, Texture } from '../../../mol-gl/webgl/texture';
|
||||
import { Vec2, Vec4 } from '../../../mol-math/linear-algebra';
|
||||
import { Vec2, Vec3, Vec4 } from '../../../mol-math/linear-algebra';
|
||||
import { createEmptyClipping } from '../clipping-data';
|
||||
import { NullLocation } from '../../../mol-model/location';
|
||||
import { createEmptySubstance } from '../substance-data';
|
||||
import { RenderableState } from '../../../mol-gl/renderable';
|
||||
import { WebGLContext } from '../../../mol-gl/webgl/context';
|
||||
|
||||
export interface TextureMesh {
|
||||
readonly kind: 'texture-mesh',
|
||||
@@ -43,7 +44,10 @@ export interface TextureMesh {
|
||||
|
||||
readonly boundingSphere: Sphere3D
|
||||
|
||||
readonly meta: { [k: string]: unknown }
|
||||
readonly meta: {
|
||||
webgl?: WebGLContext
|
||||
[k: string]: unknown
|
||||
}
|
||||
}
|
||||
|
||||
export namespace TextureMesh {
|
||||
@@ -131,9 +135,42 @@ export namespace TextureMesh {
|
||||
updateBoundingSphere,
|
||||
createRenderableState,
|
||||
updateRenderableState,
|
||||
createPositionIterator: () => LocationIterator(1, 1, 1, () => NullLocation)
|
||||
createPositionIterator,
|
||||
};
|
||||
|
||||
const TextureMeshName = 'texture-mesh';
|
||||
|
||||
function createPositionIterator(textureMesh: TextureMesh, transform: TransformData): LocationIterator {
|
||||
const webgl = textureMesh.meta.webgl;
|
||||
if (!webgl) return LocationIterator(1, 1, 1, () => NullLocation);
|
||||
|
||||
if (!webgl.namedFramebuffers[TextureMeshName]) {
|
||||
webgl.namedFramebuffers[TextureMeshName] = webgl.resources.framebuffer();
|
||||
}
|
||||
const framebuffer = webgl.namedFramebuffers[TextureMeshName];
|
||||
const [width, height] = textureMesh.geoTextureDim.ref.value;
|
||||
const vertices = new Float32Array(width * height * 4);
|
||||
framebuffer.bind();
|
||||
textureMesh.vertexTexture.ref.value.attachFramebuffer(framebuffer, 0);
|
||||
webgl.readPixels(0, 0, width, height, vertices);
|
||||
|
||||
const groupCount = textureMesh.vertexCount;
|
||||
const instanceCount = transform.instanceCount.ref.value;
|
||||
const location = PositionLocation();
|
||||
const p = location.position;
|
||||
const v = vertices;
|
||||
const m = transform.aTransform.ref.value;
|
||||
const getLocation = (groupIndex: number, instanceIndex: number) => {
|
||||
if (instanceIndex < 0) {
|
||||
Vec3.fromArray(p, v, groupIndex * 4);
|
||||
} else {
|
||||
Vec3.transformMat4Offset(p, v, m, 0, groupIndex * 4, instanceIndex * 16);
|
||||
}
|
||||
return location;
|
||||
};
|
||||
return LocationIterator(groupCount, instanceCount, 1, getLocation);
|
||||
}
|
||||
|
||||
function createValues(textureMesh: TextureMesh, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: PD.Values<Params>): TextureMeshValues {
|
||||
const { instanceCount, groupCount } = locationIt;
|
||||
const positionIt = Utils.createPositionIterator(textureMesh, transform);
|
||||
|
||||
@@ -21,6 +21,7 @@ export type TransparencyData = {
|
||||
uTransparencyGridDim: ValueCell<Vec3>,
|
||||
uTransparencyGridTransform: ValueCell<Vec4>,
|
||||
dTransparencyType: ValueCell<string>,
|
||||
uTransparencyStrength: ValueCell<number>,
|
||||
}
|
||||
|
||||
export function applyTransparencyValue(array: Uint8Array, start: number, end: number, value: number) {
|
||||
@@ -63,6 +64,7 @@ export function createTransparency(count: number, type: TransparencyType, transp
|
||||
uTransparencyGridDim: ValueCell.create(Vec3.create(1, 1, 1)),
|
||||
uTransparencyGridTransform: ValueCell.create(Vec4.create(0, 0, 0, 1)),
|
||||
dTransparencyType: ValueCell.create(type),
|
||||
uTransparencyStrength: ValueCell.create(1),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -84,6 +86,7 @@ export function createEmptyTransparency(transparencyData?: TransparencyData): Tr
|
||||
uTransparencyGridDim: ValueCell.create(Vec3.create(1, 1, 1)),
|
||||
uTransparencyGridTransform: ValueCell.create(Vec4.create(0, 0, 0, 1)),
|
||||
dTransparencyType: ValueCell.create('groupInstance'),
|
||||
uTransparencyStrength: ValueCell.create(1),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -204,8 +204,7 @@ export function createHistogramPyramid(ctx: WebGLContext, inputTexture: Texture,
|
||||
// return at least a count of one to avoid issues downstram
|
||||
const count = Math.max(1, getHistopyramidSum(ctx, levelTexturesFramebuffers[0].texture));
|
||||
const height = Math.ceil(count / Math.pow(2, levels));
|
||||
// const scale = Vec2.create(maxSize / inputTexture.width, maxSize / inputTexture.height);
|
||||
// console.log('height', height, 'finalCount', count, 'scale', scale);
|
||||
// console.log({ height, count, scale });
|
||||
|
||||
return { pyramidTex, count, height, levels, scale };
|
||||
}
|
||||
@@ -142,9 +142,7 @@ export function createIsosurfaceBuffers(ctx: WebGLContext, activeVoxelsBase: Tex
|
||||
|
||||
if (isWebGL2(gl)) {
|
||||
if (!vertexTexture) {
|
||||
vertexTexture = extensions.colorBufferHalfFloat && extensions.textureHalfFloat
|
||||
? resources.texture('image-float16', 'rgba', 'fp16', 'nearest')
|
||||
: resources.texture('image-float32', 'rgba', 'float', 'nearest');
|
||||
vertexTexture = resources.texture('image-float32', 'rgba', 'float', 'nearest');
|
||||
}
|
||||
|
||||
if (!groupTexture) {
|
||||
@@ -199,9 +197,9 @@ export function createIsosurfaceBuffers(ctx: WebGLContext, activeVoxelsBase: Tex
|
||||
gl.finish();
|
||||
if (isTimingMode) ctx.timer.markEnd('createIsosurfaceBuffers');
|
||||
|
||||
// printTextureImage(readTexture(ctx, vertexTexture, new Float32Array(width * height * 4)), { scale: 0.75 });
|
||||
// printTextureImage(readTexture(ctx, groupTexture, new Uint8Array(width * height * 4)), { scale: 0.75 });
|
||||
// printTextureImage(readTexture(ctx, normalTexture, new Float32Array(width * height * 4)), { scale: 0.75 });
|
||||
// printTextureImage(readTexture(ctx, vertexTexture, new Float32Array(width * height * 4)), { scale: 0.75, normalize: true });
|
||||
// printTextureImage(readTexture(ctx, groupTexture, new Uint8Array(width * height * 4)), { scale: 0.75, normalize: true });
|
||||
// printTextureImage(readTexture(ctx, normalTexture, new Float32Array(width * height * 4)), { scale: 0.75, normalize: true });
|
||||
|
||||
return { vertexTexture, groupTexture, normalTexture, vertexCount: count };
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ export const CylindersSchema = {
|
||||
dIgnoreLight: DefineSpec('boolean'),
|
||||
dXrayShaded: DefineSpec('boolean'),
|
||||
dTransparentBackfaces: DefineSpec('string', ['off', 'on', 'opaque']),
|
||||
dSolidInterior: DefineSpec('boolean'),
|
||||
uBumpFrequency: UniformSpec('f', 'material'),
|
||||
uBumpAmplitude: UniformSpec('f', 'material'),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
* @author Gianluca Tomasello <giagitom@gmail.com>
|
||||
@@ -152,9 +152,12 @@ export const GlobalUniformSchema = {
|
||||
|
||||
uHighlightColor: UniformSpec('v3'),
|
||||
uSelectColor: UniformSpec('v3'),
|
||||
uDimColor: UniformSpec('v3'),
|
||||
uHighlightStrength: UniformSpec('f'),
|
||||
uSelectStrength: UniformSpec('f'),
|
||||
uDimStrength: UniformSpec('f'),
|
||||
uMarkerPriority: UniformSpec('i'),
|
||||
uMarkerAverage: UniformSpec('f'),
|
||||
|
||||
uXrayEdgeFalloff: UniformSpec('f'),
|
||||
|
||||
@@ -229,6 +232,7 @@ export const OverpaintSchema = {
|
||||
uOverpaintGridTransform: UniformSpec('v4'),
|
||||
tOverpaintGrid: TextureSpec('texture', 'rgba', 'ubyte', 'linear'),
|
||||
dOverpaintType: DefineSpec('string', ['instance', 'groupInstance', 'volumeInstance']),
|
||||
uOverpaintStrength: UniformSpec('f', 'material'),
|
||||
} as const;
|
||||
export type OverpaintSchema = typeof OverpaintSchema
|
||||
export type OverpaintValues = Values<OverpaintSchema>
|
||||
@@ -242,7 +246,8 @@ export const TransparencySchema = {
|
||||
uTransparencyGridDim: UniformSpec('v3'),
|
||||
uTransparencyGridTransform: UniformSpec('v4'),
|
||||
tTransparencyGrid: TextureSpec('texture', 'alpha', 'ubyte', 'linear'),
|
||||
dTransparencyType: DefineSpec('string', ['instance', 'groupInstance', 'volumeInstance'])
|
||||
dTransparencyType: DefineSpec('string', ['instance', 'groupInstance', 'volumeInstance']),
|
||||
uTransparencyStrength: UniformSpec('f', 'material'),
|
||||
} as const;
|
||||
export type TransparencySchema = typeof TransparencySchema
|
||||
export type TransparencyValues = Values<TransparencySchema>
|
||||
@@ -256,6 +261,7 @@ export const SubstanceSchema = {
|
||||
uSubstanceGridTransform: UniformSpec('v4'),
|
||||
tSubstanceGrid: TextureSpec('texture', 'rgba', 'ubyte', 'linear'),
|
||||
dSubstanceType: DefineSpec('string', ['instance', 'groupInstance', 'volumeInstance']),
|
||||
uSubstanceStrength: UniformSpec('f', 'material'),
|
||||
} as const;
|
||||
export type SubstanceSchema = typeof SubstanceSchema
|
||||
export type SubstanceValues = Values<SubstanceSchema>
|
||||
|
||||
@@ -24,6 +24,7 @@ export const SpheresSchema = {
|
||||
dIgnoreLight: DefineSpec('boolean'),
|
||||
dXrayShaded: DefineSpec('boolean'),
|
||||
dTransparentBackfaces: DefineSpec('string', ['off', 'on', 'opaque']),
|
||||
dSolidInterior: DefineSpec('boolean'),
|
||||
uBumpFrequency: UniformSpec('f', 'material'),
|
||||
uBumpAmplitude: UniformSpec('f', 'material'),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
@@ -10,6 +10,10 @@ import { BoundaryHelper } from '../../mol-math/geometry/boundary-helper';
|
||||
import { TextureFilter } from '../webgl/texture';
|
||||
import { arrayMinMax } from '../../mol-util/array';
|
||||
|
||||
// avoiding namespace lookup improved performance in Chrome (Aug 2020)
|
||||
const v3fromArray = Vec3.fromArray;
|
||||
const v3transformMat4Offset = Vec3.transformMat4Offset;
|
||||
|
||||
export function calculateTextureInfo(n: number, itemSize: number) {
|
||||
n = Math.max(n, 2); // observed issues with 1 pixel textures
|
||||
const sqN = Math.sqrt(n);
|
||||
@@ -137,21 +141,21 @@ export function calculateInvariantBoundingSphere(position: Float32Array, positio
|
||||
|
||||
boundaryHelper.reset();
|
||||
for (let i = 0, _i = positionCount * 3; i < _i; i += step) {
|
||||
Vec3.fromArray(v, position, i);
|
||||
v3fromArray(v, position, i);
|
||||
boundaryHelper.includePosition(v);
|
||||
}
|
||||
boundaryHelper.finishedIncludeStep();
|
||||
for (let i = 0, _i = positionCount * 3; i < _i; i += step) {
|
||||
Vec3.fromArray(v, position, i);
|
||||
v3fromArray(v, position, i);
|
||||
boundaryHelper.radiusPosition(v);
|
||||
}
|
||||
|
||||
const sphere = boundaryHelper.getSphere();
|
||||
|
||||
if (positionCount <= 98) {
|
||||
if (positionCount <= 14) {
|
||||
const extrema: Vec3[] = [];
|
||||
for (let i = 0, _i = positionCount * 3; i < _i; i += step) {
|
||||
extrema.push(Vec3.fromArray(Vec3(), position, i));
|
||||
extrema.push(v3fromArray(Vec3(), position, i));
|
||||
}
|
||||
Sphere3D.setExtrema(sphere, extrema);
|
||||
}
|
||||
@@ -174,28 +178,28 @@ export function calculateTransformBoundingSphere(invariantBoundingSphere: Sphere
|
||||
const { center, radius, extrema } = invariantBoundingSphere;
|
||||
|
||||
// only use extrema if there are not too many transforms
|
||||
if (extrema && transformCount < 50) {
|
||||
if (extrema && transformCount <= 14) {
|
||||
for (let i = 0, _i = transformCount; i < _i; ++i) {
|
||||
for (const e of extrema) {
|
||||
Vec3.transformMat4Offset(v, e, transform, 0, 0, i * 16);
|
||||
v3transformMat4Offset(v, e, transform, 0, 0, i * 16);
|
||||
boundaryHelper.includePosition(v);
|
||||
}
|
||||
}
|
||||
boundaryHelper.finishedIncludeStep();
|
||||
for (let i = 0, _i = transformCount; i < _i; ++i) {
|
||||
for (const e of extrema) {
|
||||
Vec3.transformMat4Offset(v, e, transform, 0, 0, i * 16);
|
||||
v3transformMat4Offset(v, e, transform, 0, 0, i * 16);
|
||||
boundaryHelper.radiusPosition(v);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let i = 0, _i = transformCount; i < _i; ++i) {
|
||||
Vec3.transformMat4Offset(v, center, transform, 0, 0, i * 16);
|
||||
v3transformMat4Offset(v, center, transform, 0, 0, i * 16);
|
||||
boundaryHelper.includePositionRadius(v, radius);
|
||||
}
|
||||
boundaryHelper.finishedIncludeStep();
|
||||
for (let i = 0, _i = transformCount; i < _i; ++i) {
|
||||
Vec3.transformMat4Offset(v, center, transform, 0, 0, i * 16);
|
||||
v3transformMat4Offset(v, center, transform, 0, 0, i * 16);
|
||||
boundaryHelper.radiusPositionRadius(v, radius);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
* @author Gianluca Tomasello <giagitom@gmail.com>
|
||||
@@ -38,14 +38,14 @@ export interface RendererStats {
|
||||
instancedDrawCount: number
|
||||
}
|
||||
|
||||
export const enum PickType {
|
||||
export enum PickType {
|
||||
None = 0,
|
||||
Object = 1,
|
||||
Instance = 2,
|
||||
Group = 3,
|
||||
}
|
||||
|
||||
export const enum MarkingType {
|
||||
export enum MarkingType {
|
||||
None = 0,
|
||||
Depth = 1,
|
||||
Mask = 2,
|
||||
@@ -54,10 +54,11 @@ export const enum MarkingType {
|
||||
interface Renderer {
|
||||
readonly stats: RendererStats
|
||||
readonly props: Readonly<RendererProps>
|
||||
readonly light: Readonly<Light>
|
||||
|
||||
clear: (toBackgroundColor: boolean, ignoreTransparentBackground?: boolean) => void
|
||||
clearDepth: (packed?: boolean) => void
|
||||
update: (camera: ICamera) => void
|
||||
update: (camera: ICamera, scene: Scene) => void
|
||||
|
||||
renderPick: (group: Scene.Group, camera: ICamera, variant: 'pick' | 'depth', depthTexture: Texture | null, pickType: PickType) => void
|
||||
renderDepth: (group: Scene.Group, camera: ICamera, depthTexture: Texture | null) => void
|
||||
@@ -96,20 +97,22 @@ export const RendererParams = {
|
||||
colorMarker: PD.Boolean(true, { description: 'Enable color marker' }),
|
||||
highlightColor: PD.Color(Color.fromNormalizedRgb(1.0, 0.4, 0.6)),
|
||||
selectColor: PD.Color(Color.fromNormalizedRgb(0.2, 1.0, 0.1)),
|
||||
dimColor: PD.Color(Color.fromNormalizedRgb(1.0, 1.0, 1.0)),
|
||||
highlightStrength: PD.Numeric(0.3, { min: 0.0, max: 1.0, step: 0.1 }),
|
||||
selectStrength: PD.Numeric(0.3, { min: 0.0, max: 1.0, step: 0.1 }),
|
||||
dimStrength: PD.Numeric(0.0, { min: 0.0, max: 1.0, step: 0.1 }),
|
||||
markerPriority: PD.Select(1, [[1, 'Highlight'], [2, 'Select']]),
|
||||
|
||||
xrayEdgeFalloff: PD.Numeric(1, { min: 0.0, max: 3.0, step: 0.1 }),
|
||||
|
||||
light: PD.ObjectList({
|
||||
inclination: PD.Numeric(180, { min: 0, max: 180, step: 1 }),
|
||||
azimuth: PD.Numeric(0, { min: 0, max: 360, step: 1 }),
|
||||
inclination: PD.Numeric(150, { min: 0, max: 180, step: 1 }),
|
||||
azimuth: PD.Numeric(320, { min: 0, max: 360, step: 1 }),
|
||||
color: PD.Color(Color.fromNormalizedRgb(1.0, 1.0, 1.0)),
|
||||
intensity: PD.Numeric(0.6, { min: 0.0, max: 1.0, step: 0.01 }),
|
||||
}, o => Color.toHexString(o.color), { defaultValue: [{
|
||||
inclination: 180,
|
||||
azimuth: 0,
|
||||
inclination: 150,
|
||||
azimuth: 320,
|
||||
color: Color.fromNormalizedRgb(1.0, 1.0, 1.0),
|
||||
intensity: 0.6
|
||||
}] }),
|
||||
@@ -118,7 +121,7 @@ export const RendererParams = {
|
||||
};
|
||||
export type RendererProps = PD.Values<typeof RendererParams>
|
||||
|
||||
type Light = {
|
||||
export type Light = {
|
||||
count: number
|
||||
direction: number[]
|
||||
color: number[]
|
||||
@@ -231,9 +234,12 @@ namespace Renderer {
|
||||
|
||||
uHighlightColor: ValueCell.create(Color.toVec3Normalized(Vec3(), p.highlightColor)),
|
||||
uSelectColor: ValueCell.create(Color.toVec3Normalized(Vec3(), p.selectColor)),
|
||||
uDimColor: ValueCell.create(Color.toVec3Normalized(Vec3(), p.dimColor)),
|
||||
uHighlightStrength: ValueCell.create(p.highlightStrength),
|
||||
uSelectStrength: ValueCell.create(p.selectStrength),
|
||||
uDimStrength: ValueCell.create(p.dimStrength),
|
||||
uMarkerPriority: ValueCell.create(p.markerPriority),
|
||||
uMarkerAverage: ValueCell.create(0),
|
||||
|
||||
uXrayEdgeFalloff: ValueCell.create(p.xrayEdgeFalloff),
|
||||
};
|
||||
@@ -328,7 +334,7 @@ namespace Renderer {
|
||||
r.render(variant, sharedTexturesList.length);
|
||||
};
|
||||
|
||||
const update = (camera: ICamera) => {
|
||||
const update = (camera: ICamera, scene: Scene) => {
|
||||
ValueCell.update(globalUniforms.uView, camera.view);
|
||||
ValueCell.update(globalUniforms.uInvView, Mat4.invert(invView, camera.view));
|
||||
ValueCell.update(globalUniforms.uProjection, camera.projection);
|
||||
@@ -345,6 +351,8 @@ namespace Renderer {
|
||||
ValueCell.updateIfChanged(globalUniforms.uFogFar, camera.fogFar);
|
||||
ValueCell.updateIfChanged(globalUniforms.uFogNear, camera.fogNear);
|
||||
ValueCell.updateIfChanged(globalUniforms.uTransparentBackground, transparentBackground);
|
||||
|
||||
ValueCell.updateIfChanged(globalUniforms.uMarkerAverage, scene.markerAverage);
|
||||
};
|
||||
|
||||
const updateInternal = (group: Scene.Group, camera: ICamera, depthTexture: Texture | null, renderMask: Mask, markingDepthTest: boolean) => {
|
||||
@@ -754,6 +762,10 @@ namespace Renderer {
|
||||
p.selectColor = props.selectColor;
|
||||
ValueCell.update(globalUniforms.uSelectColor, Color.toVec3Normalized(globalUniforms.uSelectColor.ref.value, p.selectColor));
|
||||
}
|
||||
if (props.dimColor !== undefined && props.dimColor !== p.dimColor) {
|
||||
p.dimColor = props.dimColor;
|
||||
ValueCell.update(globalUniforms.uDimColor, Color.toVec3Normalized(globalUniforms.uDimColor.ref.value, p.dimColor));
|
||||
}
|
||||
if (props.highlightStrength !== undefined && props.highlightStrength !== p.highlightStrength) {
|
||||
p.highlightStrength = props.highlightStrength;
|
||||
ValueCell.update(globalUniforms.uHighlightStrength, p.highlightStrength);
|
||||
@@ -762,6 +774,10 @@ namespace Renderer {
|
||||
p.selectStrength = props.selectStrength;
|
||||
ValueCell.update(globalUniforms.uSelectStrength, p.selectStrength);
|
||||
}
|
||||
if (props.dimStrength !== undefined && props.dimStrength !== p.dimStrength) {
|
||||
p.dimStrength = props.dimStrength;
|
||||
ValueCell.update(globalUniforms.uDimStrength, p.dimStrength);
|
||||
}
|
||||
if (props.markerPriority !== undefined && props.markerPriority !== p.markerPriority) {
|
||||
p.markerPriority = props.markerPriority;
|
||||
ValueCell.update(globalUniforms.uMarkerPriority, p.markerPriority);
|
||||
@@ -827,6 +843,9 @@ namespace Renderer {
|
||||
instancedDrawCount: stats.instancedDrawCount,
|
||||
};
|
||||
},
|
||||
get light(): Light {
|
||||
return light;
|
||||
},
|
||||
dispose: () => {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
* @author David Sehnal <david.sehnal@gmail.com>
|
||||
@@ -105,6 +105,10 @@ namespace Scene {
|
||||
let boundingSphereDirty = true;
|
||||
let boundingSphereVisibleDirty = true;
|
||||
|
||||
let markerAverageDirty = true;
|
||||
let opacityAverageDirty = true;
|
||||
let hasOpaqueDirty = true;
|
||||
|
||||
let markerAverage = 0;
|
||||
let opacityAverage = 0;
|
||||
let hasOpaque = false;
|
||||
@@ -165,9 +169,9 @@ namespace Scene {
|
||||
}
|
||||
|
||||
renderables.sort(renderableSort);
|
||||
markerAverage = calculateMarkerAverage();
|
||||
opacityAverage = calculateOpacityAverage();
|
||||
hasOpaque = calculateHasOpaque();
|
||||
markerAverageDirty = true;
|
||||
opacityAverageDirty = true;
|
||||
hasOpaqueDirty = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -189,9 +193,9 @@ namespace Scene {
|
||||
const newVisibleHash = computeVisibleHash();
|
||||
if (newVisibleHash !== visibleHash) {
|
||||
boundingSphereVisibleDirty = true;
|
||||
markerAverage = calculateMarkerAverage();
|
||||
opacityAverage = calculateOpacityAverage();
|
||||
hasOpaque = calculateHasOpaque();
|
||||
markerAverageDirty = true;
|
||||
opacityAverageDirty = true;
|
||||
hasOpaqueDirty = true;
|
||||
visibleHash = newVisibleHash;
|
||||
return true;
|
||||
} else {
|
||||
@@ -268,9 +272,9 @@ namespace Scene {
|
||||
} else {
|
||||
syncVisibility();
|
||||
}
|
||||
markerAverage = calculateMarkerAverage();
|
||||
opacityAverage = calculateOpacityAverage();
|
||||
hasOpaque = calculateHasOpaque();
|
||||
markerAverageDirty = true;
|
||||
opacityAverageDirty = true;
|
||||
hasOpaqueDirty = true;
|
||||
},
|
||||
add: (o: GraphicsRenderObject) => commitQueue.add(o),
|
||||
remove: (o: GraphicsRenderObject) => commitQueue.remove(o),
|
||||
@@ -311,12 +315,24 @@ namespace Scene {
|
||||
return boundingSphereVisible;
|
||||
},
|
||||
get markerAverage() {
|
||||
if (markerAverageDirty) {
|
||||
markerAverage = calculateMarkerAverage();
|
||||
markerAverageDirty = false;
|
||||
}
|
||||
return markerAverage;
|
||||
},
|
||||
get opacityAverage() {
|
||||
if (opacityAverageDirty) {
|
||||
opacityAverage = calculateOpacityAverage();
|
||||
opacityAverageDirty = false;
|
||||
}
|
||||
return opacityAverage;
|
||||
},
|
||||
get hasOpaque() {
|
||||
if (hasOpaqueDirty) {
|
||||
hasOpaque = calculateHasOpaque();
|
||||
hasOpaqueDirty = false;
|
||||
}
|
||||
return hasOpaque;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@ export const apply_light_color = `
|
||||
gl_FragColor = material;
|
||||
#else
|
||||
#ifdef bumpEnabled
|
||||
if (uBumpFrequency > 0.0 && uBumpAmplitude > 0.0) {
|
||||
if (uBumpFrequency > 0.0 && uBumpAmplitude > 0.0 && bumpiness > 0.0) {
|
||||
normal = perturbNormal(-vViewPosition, normal, fbm(vModelPosition * uBumpFrequency), (uBumpAmplitude * bumpiness) / uBumpFrequency);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export const apply_marker_color = `
|
||||
|
||||
#if defined(dColorMarker)
|
||||
if (marker > 0.0) {
|
||||
if ((uMarkerPriority == 1 && marker != 2.0) || (uMarkerPriority != 1 && marker == 1.0)) {
|
||||
@@ -8,6 +9,9 @@ export const apply_marker_color = `
|
||||
gl_FragColor.rgb = mix(gl_FragColor.rgb, uSelectColor, uSelectStrength);
|
||||
gl_FragColor.a = max(gl_FragColor.a, uSelectStrength * 0.002); // for direct-volume rendering
|
||||
}
|
||||
} else if (uMarkerAverage > 0.0) {
|
||||
gl_FragColor.rgb = mix(gl_FragColor.rgb, uDimColor, uDimStrength);
|
||||
gl_FragColor.a = max(gl_FragColor.a, uDimStrength * 0.002); // for direct-volume rendering
|
||||
}
|
||||
#endif
|
||||
`;
|
||||
@@ -42,6 +42,7 @@ export const assign_color_varying = `
|
||||
#else
|
||||
vOverpaint.rgb = mix(vColor.rgb, vOverpaint.rgb, vOverpaint.a);
|
||||
#endif
|
||||
vOverpaint *= uOverpaintStrength;
|
||||
#endif
|
||||
|
||||
#ifdef dSubstance
|
||||
@@ -58,6 +59,7 @@ export const assign_color_varying = `
|
||||
|
||||
// pre-mix to avoid artifacts due to empty substance
|
||||
vSubstance.rgb = mix(vec3(uMetalness, uRoughness, uBumpiness), vSubstance.rgb, vSubstance.a);
|
||||
vSubstance *= uSubstanceStrength;
|
||||
#endif
|
||||
#elif defined(dRenderVariant_pick)
|
||||
#ifdef requiredDrawBuffers
|
||||
@@ -86,5 +88,6 @@ export const assign_color_varying = `
|
||||
vec3 tgridPos = (uTransparencyGridTransform.w * (vModelPosition - uTransparencyGridTransform.xyz)) / uTransparencyGridDim;
|
||||
vTransparency = texture3dFrom2dLinear(tTransparencyGrid, tgridPos, uTransparencyGridDim, uTransparencyTexDim).a;
|
||||
#endif
|
||||
vTransparency *= uTransparencyStrength;
|
||||
#endif
|
||||
`;
|
||||
@@ -1,12 +1,7 @@
|
||||
export const clip_instance = `
|
||||
#if defined(dClipVariant_instance) && dClipObjectCount != 0
|
||||
int flag = 0;
|
||||
#if defined(dClipping)
|
||||
flag = int(floor(vClipping * 255.0 + 0.5));
|
||||
#endif
|
||||
|
||||
vec4 mCenter = uModel * aTransform * vec4(uInvariantBoundingSphere.xyz, 1.0);
|
||||
if (clipTest(vec4(mCenter.xyz, uInvariantBoundingSphere.w), flag))
|
||||
if (clipTest(vec4(mCenter.xyz, uInvariantBoundingSphere.w)))
|
||||
// move out of [ -w, +w ] to 'discard' in vert shader
|
||||
gl_Position.z = 2.0 * gl_Position.w;
|
||||
#endif
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
export const clip_pixel = `
|
||||
#if defined(dClipVariant_pixel) && dClipObjectCount != 0
|
||||
#if defined(dClipping)
|
||||
int clippingFlag = int(floor(vClipping * 255.0 + 0.5));
|
||||
#else
|
||||
int clippingFlag = 0;
|
||||
#endif
|
||||
|
||||
if (clipTest(vec4(vModelPosition, 0.0), clippingFlag))
|
||||
if (clipTest(vec4(vModelPosition, 0.0)))
|
||||
discard;
|
||||
#endif
|
||||
`;
|
||||
@@ -39,6 +39,7 @@ uniform float uBumpiness;
|
||||
uniform vec4 uOverpaintGridTransform;
|
||||
uniform sampler2D tOverpaintGrid;
|
||||
#endif
|
||||
uniform float uOverpaintStrength;
|
||||
#endif
|
||||
|
||||
#ifdef dSubstance
|
||||
@@ -53,6 +54,7 @@ uniform float uBumpiness;
|
||||
uniform vec4 uSubstanceGridTransform;
|
||||
uniform sampler2D tSubstanceGrid;
|
||||
#endif
|
||||
uniform float uSubstanceStrength;
|
||||
#endif
|
||||
#elif defined(dRenderVariant_pick)
|
||||
#if __VERSION__ == 100 || !defined(dVaryingGroup)
|
||||
@@ -86,5 +88,6 @@ uniform float uBumpiness;
|
||||
uniform vec4 uTransparencyGridTransform;
|
||||
uniform sampler2D tTransparencyGrid;
|
||||
#endif
|
||||
uniform float uTransparencyStrength;
|
||||
#endif
|
||||
`;
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2020-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Ludovic Autin <autin@scripps.edu>
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
@@ -7,45 +7,45 @@
|
||||
|
||||
export const common_clip = `
|
||||
#if dClipObjectCount != 0
|
||||
vec3 quaternionTransform(vec4 q, vec3 v) {
|
||||
vec3 quaternionTransform(const in vec4 q, const in vec3 v) {
|
||||
vec3 t = 2.0 * cross(q.xyz, v);
|
||||
return v + q.w * t + cross(q.xyz, t);
|
||||
}
|
||||
|
||||
vec4 computePlane(vec3 normal, vec3 inPoint) {
|
||||
vec4 computePlane(const in vec3 normal, const in vec3 inPoint) {
|
||||
return vec4(normalize(normal), -dot(normal, inPoint));
|
||||
}
|
||||
|
||||
float planeSD(vec4 plane, vec3 center) {
|
||||
float planeSD(const in vec4 plane, const in vec3 center) {
|
||||
return -dot(plane.xyz, center - plane.xyz * -plane.w);
|
||||
}
|
||||
|
||||
float sphereSD(vec3 position, vec4 rotation, vec3 size, vec3 center) {
|
||||
float sphereSD(const in vec3 position, const in vec4 rotation, const in vec3 size, const in vec3 center) {
|
||||
return (
|
||||
length(quaternionTransform(vec4(-rotation.x, -rotation.y, -rotation.z, rotation.w), center - position) / size) - 1.0
|
||||
) * min(min(size.x, size.y), size.z);
|
||||
}
|
||||
|
||||
float cubeSD(vec3 position, vec4 rotation, vec3 size, vec3 center) {
|
||||
float cubeSD(const in vec3 position, const in vec4 rotation, const in vec3 size, const in vec3 center) {
|
||||
vec3 d = abs(quaternionTransform(vec4(-rotation.x, -rotation.y, -rotation.z, rotation.w), center - position)) - size;
|
||||
return min(max(d.x, max(d.y, d.z)), 0.0) + length(max(d, 0.0));
|
||||
}
|
||||
|
||||
float cylinderSD(vec3 position, vec4 rotation, vec3 size, vec3 center) {
|
||||
float cylinderSD(const in vec3 position, const in vec4 rotation, const in vec3 size, const in vec3 center) {
|
||||
vec3 t = quaternionTransform(vec4(-rotation.x, -rotation.y, -rotation.z, rotation.w), center - position);
|
||||
|
||||
vec2 d = abs(vec2(length(t.xz), t.y)) - size.xy;
|
||||
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0));
|
||||
}
|
||||
|
||||
float infiniteConeSD(vec3 position, vec4 rotation, vec3 size, vec3 center) {
|
||||
float infiniteConeSD(const in vec3 position, const in vec4 rotation, const in vec3 size, const in vec3 center) {
|
||||
vec3 t = quaternionTransform(vec4(-rotation.x, -rotation.y, -rotation.z, rotation.w), center - position);
|
||||
|
||||
float q = length(t.xy);
|
||||
return dot(size.xy, vec2(q, t.z));
|
||||
}
|
||||
|
||||
float getSignedDistance(vec3 center, int type, vec3 position, vec4 rotation, vec3 scale) {
|
||||
float getSignedDistance(const in vec3 center, const in int type, const in vec3 position, const in vec4 rotation, const in vec3 scale) {
|
||||
if (type == 1) {
|
||||
vec3 normal = quaternionTransform(rotation, vec3(0.0, 1.0, 0.0));
|
||||
vec4 plane = computePlane(normal, position);
|
||||
@@ -65,7 +65,7 @@ export const common_clip = `
|
||||
|
||||
#if __VERSION__ == 100
|
||||
// 8-bit
|
||||
int bitwiseAnd(int a, int b) {
|
||||
int bitwiseAnd(const in int a, const in int b) {
|
||||
int d = 128;
|
||||
int result = 0;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
@@ -78,17 +78,23 @@ export const common_clip = `
|
||||
return result;
|
||||
}
|
||||
|
||||
bool hasBit(int mask, int bit) {
|
||||
bool hasBit(const in int mask, const in int bit) {
|
||||
return bitwiseAnd(mask, bit) == 0;
|
||||
}
|
||||
#else
|
||||
bool hasBit(int mask, int bit) {
|
||||
bool hasBit(const in int mask, const in int bit) {
|
||||
return (mask & bit) == 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// flag is a bit-flag for clip-objects to ignore (note, object ids start at 1 not 0)
|
||||
bool clipTest(vec4 sphere, int flag) {
|
||||
bool clipTest(const in vec4 sphere) {
|
||||
// flag is a bit-flag for clip-objects to ignore (note, object ids start at 1 not 0)
|
||||
#if defined(dClipping)
|
||||
int flag = int(floor(vClipping * 255.0 + 0.5));
|
||||
#else
|
||||
int flag = 0;
|
||||
#endif
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for (int i = 0; i < dClipObjectCount; ++i) {
|
||||
if (flag == 0 || hasBit(flag, UNROLLED_LOOP_INDEX + 1)) {
|
||||
|
||||
@@ -25,9 +25,12 @@ uniform int uMarkingType;
|
||||
#if defined(dColorMarker)
|
||||
uniform vec3 uHighlightColor;
|
||||
uniform vec3 uSelectColor;
|
||||
uniform vec3 uDimColor;
|
||||
uniform float uHighlightStrength;
|
||||
uniform float uSelectStrength;
|
||||
uniform float uDimStrength;
|
||||
uniform int uMarkerPriority;
|
||||
uniform float uMarkerAverage;
|
||||
#endif
|
||||
|
||||
#if defined(dNeedsMarker)
|
||||
|
||||
@@ -28,12 +28,19 @@ uniform mat4 uInvView;
|
||||
#include light_frag_params
|
||||
#include common_clip
|
||||
|
||||
#ifdef dSolidInterior
|
||||
const bool solidInterior = true;
|
||||
#else
|
||||
const bool solidInterior = false;
|
||||
#endif
|
||||
|
||||
// adapted from https://www.shadertoy.com/view/4lcSRn
|
||||
// The MIT License, Copyright 2016 Inigo Quilez
|
||||
bool CylinderImpostor(
|
||||
in vec3 rayOrigin, in vec3 rayDir,
|
||||
in vec3 start, in vec3 end, in float radius,
|
||||
out vec4 intersection, out bool interior
|
||||
out vec3 cameraNormal, out bool interior,
|
||||
out vec3 modelPosition, out vec3 viewPosition, out float fragmentDepth
|
||||
){
|
||||
vec3 ba = end - start;
|
||||
vec3 oc = rayOrigin - start;
|
||||
@@ -42,7 +49,7 @@ bool CylinderImpostor(
|
||||
float bard = dot(ba, rayDir);
|
||||
float baoc = dot(ba, oc);
|
||||
|
||||
float k2 = baba - bard*bard;
|
||||
float k2 = baba - bard * bard;
|
||||
float k1 = baba * dot(oc, rayDir) - baoc * bard;
|
||||
float k0 = baba * dot(oc, oc) - baoc * baoc - radius * radius * baba;
|
||||
|
||||
@@ -52,71 +59,185 @@ bool CylinderImpostor(
|
||||
bool topCap = (vCap > 0.9 && vCap < 1.1) || vCap >= 2.9;
|
||||
bool bottomCap = (vCap > 1.9 && vCap < 2.1) || vCap >= 2.9;
|
||||
|
||||
#ifdef dSolidInterior
|
||||
bool topInterior = !topCap;
|
||||
bool bottomInterior = !bottomCap;
|
||||
topCap = true;
|
||||
bottomCap = true;
|
||||
#else
|
||||
bool topInterior = false;
|
||||
bool bottomInterior = false;
|
||||
#endif
|
||||
|
||||
bool clipped = false;
|
||||
bool objectClipped = false;
|
||||
|
||||
// body outside
|
||||
h = sqrt(h);
|
||||
float t = (-k1 - h) / k2;
|
||||
float y = baoc + t * bard;
|
||||
if (y > 0.0 && y < baba) {
|
||||
interior = false;
|
||||
intersection = vec4(t, (oc + t * rayDir - ba * y / baba) / radius);
|
||||
return true;
|
||||
cameraNormal = (oc + t * rayDir - ba * y / baba) / radius;
|
||||
modelPosition = rayOrigin + t * rayDir;
|
||||
viewPosition = (uView * vec4(modelPosition, 1.0)).xyz;
|
||||
fragmentDepth = calcDepth(viewPosition);
|
||||
#if defined(dClipVariant_pixel) && dClipObjectCount != 0
|
||||
if (clipTest(vec4(modelPosition, 0.0))) {
|
||||
objectClipped = true;
|
||||
fragmentDepth = -1.0;
|
||||
#ifdef dSolidInterior
|
||||
topCap = !topInterior;
|
||||
bottomCap = !bottomInterior;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
if (fragmentDepth > 0.0) return true;
|
||||
clipped = true;
|
||||
}
|
||||
|
||||
if (topCap && y < 0.0) {
|
||||
// top cap
|
||||
t = -baoc / bard;
|
||||
if (abs(k1 + k2 * t) < h) {
|
||||
interior = false;
|
||||
intersection = vec4(t, ba * sign(y) / baba);
|
||||
return true;
|
||||
}
|
||||
} else if(bottomCap && y >= 0.0) {
|
||||
// bottom cap
|
||||
t = (baba - baoc) / bard;
|
||||
if (abs(k1 + k2 * t) < h) {
|
||||
interior = false;
|
||||
intersection = vec4(t, ba * sign(y) / baba);
|
||||
return true;
|
||||
if (!clipped) {
|
||||
if (topCap && y < 0.0) {
|
||||
// top cap
|
||||
t = -baoc / bard;
|
||||
if (abs(k1 + k2 * t) < h) {
|
||||
interior = topInterior;
|
||||
cameraNormal = -ba / baba;
|
||||
modelPosition = rayOrigin + t * rayDir;
|
||||
viewPosition = (uView * vec4(modelPosition, 1.0)).xyz;
|
||||
fragmentDepth = calcDepth(viewPosition);
|
||||
#if defined(dClipVariant_pixel) && dClipObjectCount != 0
|
||||
if (clipTest(vec4(modelPosition, 0.0))) {
|
||||
objectClipped = true;
|
||||
fragmentDepth = -1.0;
|
||||
#ifdef dSolidInterior
|
||||
topCap = !topInterior;
|
||||
bottomCap = !bottomInterior;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
if (fragmentDepth > 0.0) {
|
||||
#ifdef dSolidInterior
|
||||
if (interior) cameraNormal = -rayDir;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (bottomCap && y >= 0.0) {
|
||||
// bottom cap
|
||||
t = (baba - baoc) / bard;
|
||||
if (abs(k1 + k2 * t) < h) {
|
||||
interior = bottomInterior;
|
||||
cameraNormal = ba / baba;
|
||||
modelPosition = rayOrigin + t * rayDir;
|
||||
viewPosition = (uView * vec4(modelPosition, 1.0)).xyz;
|
||||
fragmentDepth = calcDepth(viewPosition);
|
||||
#if defined(dClipVariant_pixel) && dClipObjectCount != 0
|
||||
if (clipTest(vec4(modelPosition, 0.0))) {
|
||||
objectClipped = true;
|
||||
fragmentDepth = -1.0;
|
||||
#ifdef dSolidInterior
|
||||
topCap = !topInterior;
|
||||
bottomCap = !bottomInterior;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
if (fragmentDepth > 0.0) {
|
||||
#ifdef dSolidInterior
|
||||
if (interior) cameraNormal = -rayDir;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (uDoubleSided) {
|
||||
if (uDoubleSided || solidInterior) {
|
||||
// body inside
|
||||
h = -h;
|
||||
t = (-k1 - h) / k2;
|
||||
y = baoc + t * bard;
|
||||
if (y > 0.0 && y < baba) {
|
||||
interior = true;
|
||||
intersection = vec4(t, (oc + t * rayDir - ba * y / baba) / radius);
|
||||
return true;
|
||||
cameraNormal = -(oc + t * rayDir - ba * y / baba) / radius;
|
||||
modelPosition = rayOrigin + t * rayDir;
|
||||
viewPosition = (uView * vec4(modelPosition, 1.0)).xyz;
|
||||
fragmentDepth = calcDepth(viewPosition);
|
||||
if (fragmentDepth > 0.0) {
|
||||
#ifdef dSolidInterior
|
||||
if (!objectClipped) {
|
||||
fragmentDepth = 0.0 + (0.0000002 / vSize);
|
||||
cameraNormal = -rayDir;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: handle inside caps???
|
||||
if (topCap && y < 0.0) {
|
||||
// top cap
|
||||
t = -baoc / bard;
|
||||
if (abs(k1 + k2 * t) < -h) {
|
||||
interior = true;
|
||||
cameraNormal = ba / baba;
|
||||
modelPosition = rayOrigin + t * rayDir;
|
||||
viewPosition = (uView * vec4(modelPosition, 1.0)).xyz;
|
||||
fragmentDepth = calcDepth(viewPosition);
|
||||
if (fragmentDepth > 0.0) {
|
||||
#ifdef dSolidInterior
|
||||
if (!objectClipped) {
|
||||
fragmentDepth = 0.0 + (0.0000002 / vSize);
|
||||
cameraNormal = -rayDir;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (bottomCap && y >= 0.0) {
|
||||
// bottom cap
|
||||
t = (baba - baoc) / bard;
|
||||
if (abs(k1 + k2 * t) < -h) {
|
||||
interior = true;
|
||||
cameraNormal = -ba / baba;
|
||||
modelPosition = rayOrigin + t * rayDir;
|
||||
viewPosition = (uView * vec4(modelPosition, 1.0)).xyz;
|
||||
fragmentDepth = calcDepth(viewPosition);
|
||||
if (fragmentDepth > 0.0) {
|
||||
#ifdef dSolidInterior
|
||||
if (!objectClipped) {
|
||||
fragmentDepth = 0.0 + (0.0000002 / vSize);
|
||||
cameraNormal = -rayDir;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void main() {
|
||||
#include clip_pixel
|
||||
|
||||
vec3 rayOrigin = vModelPosition;
|
||||
vec3 rayDir = mix(normalize(vModelPosition - uCameraPosition), uCameraDir, uIsOrtho);
|
||||
|
||||
vec4 intersection;
|
||||
bool interior;
|
||||
bool hit = CylinderImpostor(vModelPosition, rayDir, vStart, vEnd, vSize, intersection, interior);
|
||||
vec3 cameraNormal;
|
||||
vec3 modelPosition;
|
||||
vec3 viewPosition;
|
||||
float fragmentDepth;
|
||||
bool hit = CylinderImpostor(rayOrigin, rayDir, vStart, vEnd, vSize, cameraNormal, interior, modelPosition, viewPosition, fragmentDepth);
|
||||
if (!hit) discard;
|
||||
|
||||
vec3 vViewPosition = vModelPosition + intersection.x * rayDir;
|
||||
vViewPosition = (uView * vec4(vViewPosition, 1.0)).xyz;
|
||||
float fragmentDepth = calcDepth(vViewPosition);
|
||||
|
||||
if (fragmentDepth < 0.0) discard;
|
||||
if (fragmentDepth > 1.0) discard;
|
||||
|
||||
gl_FragDepthEXT = fragmentDepth;
|
||||
|
||||
vec3 vModelPosition = (uInvView * vec4(vViewPosition, 1.0)).xyz;
|
||||
vec3 vViewPosition = viewPosition;
|
||||
vec3 vModelPosition = modelPosition;
|
||||
|
||||
#include clip_pixel
|
||||
#include assign_material_color
|
||||
|
||||
#if defined(dRenderVariant_pick)
|
||||
@@ -135,7 +256,7 @@ void main() {
|
||||
gl_FragColor = material;
|
||||
#elif defined(dRenderVariant_color)
|
||||
mat3 normalMatrix = transpose3(inverse3(mat3(uView)));
|
||||
vec3 normal = normalize(normalMatrix * -normalize(intersection.yzw));
|
||||
vec3 normal = normalize(normalMatrix * -normalize(cameraNormal));
|
||||
#include apply_light_color
|
||||
|
||||
#include apply_interior_color
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2020-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
@@ -55,7 +55,9 @@ void main() {
|
||||
vec3 camDir = -mix(normalize(vModelPosition - uCameraPosition), uCameraDir, uIsOrtho);
|
||||
vec3 dir = vEnd - vStart;
|
||||
// ensure cylinder 'dir' is pointing towards the camera
|
||||
if(dot(camDir, dir) < 0.0) dir = -dir;
|
||||
if(dot(camDir, dir) < 0.0) {
|
||||
dir = -dir;
|
||||
}
|
||||
|
||||
vec3 left = cross(camDir, dir);
|
||||
vec3 up = cross(left, dir);
|
||||
@@ -69,6 +71,9 @@ void main() {
|
||||
vViewPosition = mvPosition.xyz;
|
||||
gl_Position = uProjection * mvPosition;
|
||||
|
||||
mvPosition.z -= 2.0 * (length(vEnd - vStart) + vSize); // avoid clipping
|
||||
gl_Position.z = (uProjection * mvPosition).z;
|
||||
|
||||
#include clip_instance
|
||||
}
|
||||
`;
|
||||
@@ -53,9 +53,12 @@ uniform int uGroupCount;
|
||||
#if defined(dColorMarker)
|
||||
uniform vec3 uHighlightColor;
|
||||
uniform vec3 uSelectColor;
|
||||
uniform vec3 uDimColor;
|
||||
uniform float uHighlightStrength;
|
||||
uniform float uSelectStrength;
|
||||
uniform float uDimStrength;
|
||||
uniform int uMarkerPriority;
|
||||
uniform float uMarkerAverage;
|
||||
|
||||
uniform float uMarker;
|
||||
uniform vec2 uMarkerTexDim;
|
||||
@@ -229,7 +232,7 @@ vec4 raymarch(vec3 startLoc, vec3 step, vec3 rayDir) {
|
||||
|
||||
#if defined(dClipVariant_pixel) && dClipObjectCount != 0
|
||||
vec3 vModelPosition = v3m4(unitPos * uGridDim, modelTransform);
|
||||
if (clipTest(vec4(vModelPosition, 0.0), 0)) {
|
||||
if (clipTest(vec4(vModelPosition, 0.0))) {
|
||||
prevValue = value;
|
||||
pos += step;
|
||||
continue;
|
||||
@@ -270,16 +273,16 @@ vec4 raymarch(vec3 startLoc, vec3 step, vec3 rayDir) {
|
||||
#elif defined(dColorType_groupInstance)
|
||||
material.rgb = readFromTexture(tColor, vInstance * float(uGroupCount) + group, uColorTexDim).rgb;
|
||||
#elif defined(dColorType_vertex)
|
||||
material.rgb = texture3dFrom1dTrilinear(tColor, isoPos, uGridDim, uColorTexDim, 0.0).rgb;
|
||||
material.rgb = texture3dFrom1dTrilinear(tColor, unitPos, uGridDim, uColorTexDim, 0.0).rgb;
|
||||
#elif defined(dColorType_vertexInstance)
|
||||
material.rgb = texture3dFrom1dTrilinear(tColor, isoPos, uGridDim, uColorTexDim, vInstance * float(uVertexCount)).rgb;
|
||||
material.rgb = texture3dFrom1dTrilinear(tColor, unitPos, uGridDim, uColorTexDim, vInstance * float(uVertexCount)).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef dOverpaint
|
||||
#if defined(dOverpaintType_groupInstance)
|
||||
overpaint = readFromTexture(tOverpaint, vInstance * float(uGroupCount) + group, uOverpaintTexDim);
|
||||
#elif defined(dOverpaintType_vertexInstance)
|
||||
overpaint = texture3dFrom1dTrilinear(tOverpaint, isoPos, uGridDim, uOverpaintTexDim, vInstance * float(uVertexCount));
|
||||
overpaint = texture3dFrom1dTrilinear(tOverpaint, unitPos, uGridDim, uOverpaintTexDim, vInstance * float(uVertexCount));
|
||||
#endif
|
||||
|
||||
material.rgb = mix(material.rgb, overpaint.rgb, overpaint.a);
|
||||
|
||||
@@ -6,6 +6,8 @@ uniform vec2 uTexSizeInv;
|
||||
uniform sampler2D tEdgeTexture;
|
||||
uniform vec3 uHighlightEdgeColor;
|
||||
uniform vec3 uSelectEdgeColor;
|
||||
uniform float uHighlightEdgeStrength;
|
||||
uniform float uSelectEdgeStrength;
|
||||
uniform float uGhostEdgeStrength;
|
||||
uniform float uInnerEdgeFactor;
|
||||
|
||||
@@ -16,6 +18,8 @@ void main() {
|
||||
vec3 edgeColor = edgeValue.b == 1.0 ? uHighlightEdgeColor : uSelectEdgeColor;
|
||||
gl_FragColor.rgb = edgeValue.g > 0.0 ? edgeColor : edgeColor * uInnerEdgeFactor;
|
||||
gl_FragColor.a = (edgeValue.r == 1.0 ? uGhostEdgeStrength : 1.0) * edgeValue.a;
|
||||
float edgeStrength = edgeValue.b == 1.0 ? uHighlightEdgeStrength : uSelectEdgeStrength;
|
||||
gl_FragColor.a *= edgeStrength;
|
||||
} else {
|
||||
gl_FragColor = vec4(0.0);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,11 @@ float getDepthOpaque(const in vec2 coords) {
|
||||
}
|
||||
|
||||
float getDepthTransparent(const in vec2 coords) {
|
||||
return unpackRGBAToDepth(texture2D(tDepthTransparent, coords));
|
||||
#ifdef dTransparentOutline
|
||||
return unpackRGBAToDepth(texture2D(tDepthTransparent, coords));
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool isBackground(const in float depth) {
|
||||
|
||||
@@ -14,6 +14,7 @@ uniform sampler2D tSsaoDepth;
|
||||
uniform sampler2D tColor;
|
||||
uniform sampler2D tDepthOpaque;
|
||||
uniform sampler2D tDepthTransparent;
|
||||
uniform sampler2D tShadows;
|
||||
uniform sampler2D tOutlines;
|
||||
uniform vec2 uTexSize;
|
||||
|
||||
@@ -50,7 +51,11 @@ float getDepthOpaque(const in vec2 coords) {
|
||||
}
|
||||
|
||||
float getDepthTransparent(const in vec2 coords) {
|
||||
return unpackRGBAToDepth(texture2D(tDepthTransparent, coords));
|
||||
#ifdef dTransparentOutline
|
||||
return unpackRGBAToDepth(texture2D(tDepthTransparent, coords));
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool isBackground(const in float depth) {
|
||||
@@ -120,7 +125,20 @@ void main(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// outline needs to be handled after occlusion to keep them clean
|
||||
#ifdef dShadowEnable
|
||||
if (!isBackground(opaqueDepth)) {
|
||||
viewDist = abs(getViewZ(opaqueDepth));
|
||||
fogFactor = smoothstep(uFogNear, uFogFar, viewDist);
|
||||
vec4 shadow = texture2D(tShadows, coords);
|
||||
if (!uTransparentBackground) {
|
||||
color.rgb = mix(mix(vec3(0), uFogColor, fogFactor), color.rgb, shadow.a);
|
||||
} else {
|
||||
color.rgb = mix(vec3(0) * (1.0 - fogFactor), color.rgb, shadow.a);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// outline needs to be handled after occlusion and shadow to keep them clean
|
||||
#ifdef dOutlineEnable
|
||||
float closestTexel;
|
||||
float outline = getOutline(coords, opaqueDepth, closestTexel);
|
||||
|
||||
131
src/mol-gl/shader/shadows.frag.ts
Normal file
131
src/mol-gl/shader/shadows.frag.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* Copyright (c) 2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Ludovic Autin <ludovic.autin@gmail.com>
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
|
||||
export const shadows_frag = `
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
precision highp sampler2D;
|
||||
|
||||
#include common
|
||||
|
||||
uniform sampler2D tDepth;
|
||||
uniform vec2 uTexSize;
|
||||
uniform vec4 uBounds;
|
||||
|
||||
uniform float uNear;
|
||||
uniform float uFar;
|
||||
|
||||
#if dLightCount != 0
|
||||
uniform vec3 uLightDirection[dLightCount];
|
||||
uniform vec3 uLightColor[dLightCount];
|
||||
#endif
|
||||
|
||||
uniform mat4 uProjection;
|
||||
uniform mat4 uInvProjection;
|
||||
|
||||
uniform float uMaxDistance;
|
||||
uniform float uTolerance;
|
||||
uniform float uBias;
|
||||
|
||||
bool isBackground(const in float depth) {
|
||||
return depth == 1.0;
|
||||
}
|
||||
|
||||
bool outsideBounds(const in vec2 p) {
|
||||
return p.x < uBounds.x || p.y < uBounds.y || p.x > uBounds.z || p.y > uBounds.w;
|
||||
}
|
||||
|
||||
float getViewZ(const in float depth) {
|
||||
#if dOrthographic == 1
|
||||
return orthographicDepthToViewZ(depth, uNear, uFar);
|
||||
#else
|
||||
return perspectiveDepthToViewZ(depth, uNear, uFar);
|
||||
#endif
|
||||
}
|
||||
|
||||
float getDepth(const in vec2 coords) {
|
||||
#ifdef depthTextureSupport
|
||||
return texture2D(tDepth, coords).r;
|
||||
#else
|
||||
return unpackRGBAToDepth(texture2D(tDepth, coords));
|
||||
#endif
|
||||
}
|
||||
|
||||
float screenFade(const in vec2 coords) {
|
||||
vec2 c = (coords - uBounds.xy) / (uBounds.zw - uBounds.xy);
|
||||
vec2 fade = max(12.0 * abs(c - 0.5) - 5.0, vec2(0.0));
|
||||
return saturate(1.0 - dot(fade, fade));
|
||||
}
|
||||
|
||||
// based on https://panoskarabelas.com/posts/screen_space_shadows/
|
||||
float screenSpaceShadow(const in vec3 position, const in vec3 lightDirection, const in float stepLength) {
|
||||
// Ray position and direction (in view-space)
|
||||
vec3 rayPos = position;
|
||||
vec3 rayDir = -lightDirection;
|
||||
|
||||
// Compute ray step
|
||||
vec3 rayStep = rayDir * stepLength;
|
||||
|
||||
// Ray march towards the light
|
||||
float occlusion = 0.0;
|
||||
vec4 rayCoords = vec4(0.0);
|
||||
for (int i = 0; i < dSteps; ++i) {
|
||||
// Step the ray
|
||||
rayPos += rayStep;
|
||||
|
||||
rayCoords = uProjection * vec4(rayPos, 1.0);
|
||||
rayCoords.xyz = (rayCoords.xyz / rayCoords.w) * 0.5 + 0.5;
|
||||
|
||||
if (outsideBounds(rayCoords.xy))
|
||||
return 1.0;
|
||||
|
||||
// Compute the difference between the ray's and the camera's depth
|
||||
float depth = getDepth(rayCoords.xy);
|
||||
float viewZ = getViewZ(depth);
|
||||
float zDelta = rayPos.z - viewZ;
|
||||
|
||||
if (zDelta < uTolerance) {
|
||||
occlusion = 1.0;
|
||||
|
||||
// Fade out as we approach the edges of the screen
|
||||
occlusion *= screenFade(rayCoords.xy);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 1.0 - (uBias * occlusion);
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
vec2 invTexSize = 1.0 / uTexSize;
|
||||
vec2 selfCoords = gl_FragCoord.xy * invTexSize;
|
||||
|
||||
float selfDepth = getDepth(selfCoords);
|
||||
|
||||
if (isBackground(selfDepth)) {
|
||||
gl_FragColor = vec4(0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
vec3 selfViewPos = screenSpaceToViewSpace(vec3(selfCoords, selfDepth), uInvProjection);
|
||||
float stepLength = uMaxDistance / float(dSteps);
|
||||
|
||||
float o = 1.0;
|
||||
#if dLightCount != 0
|
||||
float sh[dLightCount];
|
||||
#pragma unroll_loop_start
|
||||
for (int i = 0; i < dLightCount; ++i) {
|
||||
sh[i] = screenSpaceShadow(selfViewPos, uLightDirection[i], stepLength);
|
||||
o = min(o, sh[i]);
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4(o);
|
||||
}
|
||||
`;
|
||||
@@ -23,12 +23,14 @@ varying float vRadiusSq;
|
||||
varying vec3 vPoint;
|
||||
varying vec3 vPointViewPosition;
|
||||
|
||||
vec3 cameraPos;
|
||||
vec3 cameraNormal;
|
||||
#ifdef dSolidInterior
|
||||
const bool solidInterior = true;
|
||||
#else
|
||||
const bool solidInterior = false;
|
||||
#endif
|
||||
|
||||
bool Impostor(out vec3 cameraPos, out vec3 cameraNormal){
|
||||
bool SphereImpostor(out vec3 modelPos, out vec3 cameraPos, out vec3 cameraNormal, out bool interior, out float fragmentDepth){
|
||||
vec3 cameraSpherePos = -vPointViewPosition;
|
||||
cameraSpherePos.z += vRadius;
|
||||
|
||||
vec3 rayOrigin = mix(vec3(0.0, 0.0, 0.0), vPoint, uIsOrtho);
|
||||
vec3 rayDirection = mix(normalize(vPoint), vec3(0.0, 0.0, 1.0), uIsOrtho);
|
||||
@@ -37,50 +39,67 @@ bool Impostor(out vec3 cameraPos, out vec3 cameraNormal){
|
||||
float B = dot(rayDirection, cameraSphereDir);
|
||||
float det = B * B + vRadiusSq - dot(cameraSphereDir, cameraSphereDir);
|
||||
|
||||
if (det < 0.0){
|
||||
discard;
|
||||
return false;
|
||||
}
|
||||
if (det < 0.0) return false;
|
||||
|
||||
float sqrtDet = sqrt(det);
|
||||
float posT = mix(B + sqrtDet, B + sqrtDet, uIsOrtho);
|
||||
float negT = mix(B - sqrtDet, sqrtDet - B, uIsOrtho);
|
||||
float posT = mix(B + sqrtDet, B - sqrtDet, uIsOrtho);
|
||||
float negT = mix(B - sqrtDet, B + sqrtDet, uIsOrtho);
|
||||
|
||||
cameraPos = rayDirection * negT + rayOrigin;
|
||||
modelPos = (uInvView * vec4(cameraPos, 1.0)).xyz;
|
||||
fragmentDepth = calcDepth(cameraPos);
|
||||
|
||||
if (calcDepth(cameraPos) <= 0.0) {
|
||||
cameraPos = rayDirection * posT + rayOrigin;
|
||||
interior = true;
|
||||
} else {
|
||||
bool objectClipped = false;
|
||||
|
||||
#if defined(dClipVariant_pixel) && dClipObjectCount != 0
|
||||
if (clipTest(vec4(modelPos, 0.0))) {
|
||||
objectClipped = true;
|
||||
fragmentDepth = -1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fragmentDepth > 0.0) {
|
||||
cameraNormal = normalize(cameraPos - cameraSpherePos);
|
||||
interior = false;
|
||||
return true;
|
||||
} else if (uDoubleSided || solidInterior) {
|
||||
cameraPos = rayDirection * posT + rayOrigin;
|
||||
modelPos = (uInvView * vec4(cameraPos, 1.0)).xyz;
|
||||
fragmentDepth = calcDepth(cameraPos);
|
||||
cameraNormal = -normalize(cameraPos - cameraSpherePos);
|
||||
interior = true;
|
||||
if (fragmentDepth > 0.0) {
|
||||
#ifdef dSolidInterior
|
||||
if (!objectClipped) {
|
||||
fragmentDepth = 0.0 + (0.0000001 / vRadius);
|
||||
cameraNormal = -mix(normalize(vPoint), vec3(0.0, 0.0, 1.0), uIsOrtho);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
cameraNormal = normalize(cameraPos - cameraSpherePos);
|
||||
cameraNormal *= float(!interior) * 2.0 - 1.0;
|
||||
|
||||
return !interior;
|
||||
return false;
|
||||
}
|
||||
|
||||
void main(void){
|
||||
#include clip_pixel
|
||||
|
||||
bool flag = Impostor(cameraPos, cameraNormal);
|
||||
if (!uDoubleSided) {
|
||||
if (interior) discard;
|
||||
}
|
||||
|
||||
vec3 vViewPosition = cameraPos;
|
||||
float fragmentDepth = calcDepth(vViewPosition);
|
||||
if (!flag && fragmentDepth >= 0.0) {
|
||||
fragmentDepth = 0.0 + (0.0000001 / vRadius);
|
||||
}
|
||||
vec3 modelPos;
|
||||
vec3 cameraPos;
|
||||
vec3 cameraNormal;
|
||||
float fragmentDepth;
|
||||
bool clipped = false;
|
||||
bool hit = SphereImpostor(modelPos, cameraPos, cameraNormal, interior, fragmentDepth);
|
||||
if (!hit) discard;
|
||||
|
||||
if (fragmentDepth < 0.0) discard;
|
||||
if (fragmentDepth > 1.0) discard;
|
||||
|
||||
vec3 vViewPosition = cameraPos;
|
||||
vec3 vModelPosition = modelPos;
|
||||
|
||||
gl_FragDepthEXT = fragmentDepth;
|
||||
|
||||
vec3 vModelPosition = (uInvView * vec4(vViewPosition, 1.0)).xyz;
|
||||
#include clip_pixel
|
||||
#include assign_material_color
|
||||
|
||||
#if defined(dRenderVariant_pick)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
@@ -85,7 +85,6 @@ void main(void){
|
||||
|
||||
vec4 position4 = vec4(aPosition, 1.0);
|
||||
vec4 mvPosition = uModelView * aTransform * position4;
|
||||
mvPosition.z -= vRadius; // avoid clipping, added again in fragment shader
|
||||
|
||||
gl_Position = uProjection * vec4(mvPosition.xyz, 1.0);
|
||||
quadraticProjection(size, aPosition);
|
||||
@@ -97,6 +96,9 @@ void main(void){
|
||||
|
||||
vModelPosition = (uModel * aTransform * position4).xyz; // for clipping in frag shader
|
||||
|
||||
mvPosition.z -= 2.0 * vRadius; // avoid clipping
|
||||
gl_Position.z = (uProjection * vec4(mvPosition.xyz, 1.0)).z;
|
||||
|
||||
#include clip_instance
|
||||
}
|
||||
`;
|
||||
@@ -19,6 +19,9 @@ export function isWebGL2(gl: any): gl is WebGL2RenderingContext {
|
||||
return typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/ANGLE_instanced_arrays/
|
||||
*/
|
||||
export interface COMPAT_instanced_arrays {
|
||||
drawArraysInstanced(mode: number, first: number, count: number, primcount: number): void;
|
||||
drawElementsInstanced(mode: number, count: number, type: number, offset: number, primcount: number): void;
|
||||
@@ -46,6 +49,9 @@ export function getInstancedArrays(gl: GLRenderingContext): COMPAT_instanced_arr
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/OES_standard_derivatives/
|
||||
*/
|
||||
export interface COMPAT_standard_derivatives {
|
||||
readonly FRAGMENT_SHADER_DERIVATIVE_HINT: number;
|
||||
}
|
||||
@@ -60,6 +66,9 @@ export function getStandardDerivatives(gl: GLRenderingContext): COMPAT_standard_
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/OES_element_index_uint/
|
||||
*/
|
||||
export interface COMPAT_element_index_uint {
|
||||
}
|
||||
|
||||
@@ -67,6 +76,9 @@ export function getElementIndexUint(gl: GLRenderingContext): COMPAT_element_inde
|
||||
return isWebGL2(gl) ? {} : gl.getExtension('OES_element_index_uint');
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/OES_vertex_array_object/
|
||||
*/
|
||||
export interface COMPAT_vertex_array_object {
|
||||
readonly VERTEX_ARRAY_BINDING: number;
|
||||
bindVertexArray(arrayObject: WebGLVertexArrayObject | null): void;
|
||||
@@ -132,6 +144,9 @@ export function getTextureHalfFloatLinear(gl: GLRenderingContext): COMPAT_textur
|
||||
return gl.getExtension('OES_texture_half_float_linear');
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/EXT_blend_minmax/
|
||||
*/
|
||||
export interface COMPAT_blend_minmax {
|
||||
readonly MIN: number
|
||||
readonly MAX: number
|
||||
@@ -147,6 +162,9 @@ export function getBlendMinMax(gl: GLRenderingContext): COMPAT_blend_minmax | nu
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/EXT_frag_depth/
|
||||
*/
|
||||
export interface COMPAT_frag_depth {
|
||||
}
|
||||
|
||||
@@ -196,6 +214,9 @@ export function getColorBufferHalfFloat(gl: GLRenderingContext): COMPAT_color_bu
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/WEBGL_draw_buffers/
|
||||
*/
|
||||
export interface COMPAT_draw_buffers {
|
||||
drawBuffers(buffers: number[]): void;
|
||||
readonly COLOR_ATTACHMENT0: number;
|
||||
@@ -268,6 +289,73 @@ export function getDrawBuffers(gl: GLRenderingContext): COMPAT_draw_buffers | nu
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/OES_draw_buffers_indexed/
|
||||
*/
|
||||
export interface COMPAT_draw_buffers_indexed {
|
||||
/**
|
||||
* Enables blending for an individual draw buffer.
|
||||
*
|
||||
* @param target must be BLEND.
|
||||
* @param index is an integer i specifying the draw buffer associated with the symbolic constant DRAW_BUFFERi.
|
||||
*/
|
||||
enablei: (target: number, index: number) => void;
|
||||
/**
|
||||
* Disables blending for an individual draw buffer.
|
||||
*
|
||||
* @param target must be BLEND.
|
||||
* @param index is an integer i specifying the draw buffer associated with the symbolic constant DRAW_BUFFERi.
|
||||
*/
|
||||
disablei: (buf: number, mode: number) => void;
|
||||
/**
|
||||
* The buf argument is an integer i that indicates that the blend equations should be modified for DRAW_BUFFERi.
|
||||
*
|
||||
* mode accepts the same tokens as mode in blendEquation.
|
||||
*/
|
||||
blendEquationi: (target: number, index: number) => void;
|
||||
/**
|
||||
* The buf argument is an integer i that indicates that the blend equations should be modified for DRAW_BUFFERi.
|
||||
*
|
||||
* modeRGB and modeAlpha accept the same tokens as modeRGB and modeAlpha in blendEquationSeparate.
|
||||
*/
|
||||
blendEquationSeparatei: (buf: number, modeRGB: number, modeAlpha: number) => void;
|
||||
/**
|
||||
* The buf argument is an integer i that indicates that the blend functions should be modified for DRAW_BUFFERi.
|
||||
*
|
||||
* src and dst accept the same tokens as src and dst in blendFunc.
|
||||
*/
|
||||
blendFunci: (buf: number, src: number, dst: number) => void;
|
||||
/**
|
||||
* The buf argument is an integer i that indicates that the blend functions should be modified for DRAW_BUFFERi.
|
||||
*
|
||||
* srcRGB, dstRGB, srcAlpha, and dstAlpha accept the same tokens as srcRGB, dstRGB, srcAlpha, and dstAlpha parameters in blendEquationSeparate.
|
||||
*/
|
||||
blendFuncSeparatei: (buf: number, srcRGB: number, dstRGB: number, srcAlpha: number, dstAlpha: number) => void;
|
||||
/**
|
||||
* The buf argument is an integer i that indicates that the write mask should be modified for DRAW_BUFFERi.
|
||||
*
|
||||
* r, g, b, and a indicate whether R, G, B, or A values, respectively, are written or not (a value of TRUE means that the corresponding value is written).
|
||||
*/
|
||||
colorMaski: (buf: number, r: boolean, g: boolean, b: boolean, a: boolean) => void;
|
||||
}
|
||||
|
||||
export function getDrawBuffersIndexed(gl: GLRenderingContext): COMPAT_draw_buffers_indexed | null {
|
||||
const ext = gl.getExtension('OES_draw_buffers_indexed');
|
||||
if (ext === null) return null;
|
||||
return {
|
||||
enablei: ext.enableiOES.bind(ext),
|
||||
disablei: ext.disableiOES.bind(ext),
|
||||
blendEquationi: ext.blendEquationiOES.bind(ext),
|
||||
blendEquationSeparatei: ext.blendEquationSeparateiOES.bind(ext),
|
||||
blendFunci: ext.blendFunciOES.bind(ext),
|
||||
blendFuncSeparatei: ext.blendFuncSeparateiOES.bind(ext),
|
||||
colorMaski: ext.colorMaskiOES.bind(ext),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/EXT_shader_texture_lod/
|
||||
*/
|
||||
export interface COMPAT_shader_texture_lod {
|
||||
}
|
||||
|
||||
@@ -275,6 +363,9 @@ export function getShaderTextureLod(gl: GLRenderingContext): COMPAT_shader_textu
|
||||
return isWebGL2(gl) ? {} : gl.getExtension('EXT_shader_texture_lod');
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/WEBGL_depth_texture/
|
||||
*/
|
||||
export interface COMPAT_depth_texture {
|
||||
readonly UNSIGNED_INT_24_8: number;
|
||||
}
|
||||
@@ -293,6 +384,9 @@ export function getDepthTexture(gl: GLRenderingContext): COMPAT_depth_texture |
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/EXT_sRGB/
|
||||
*/
|
||||
export interface COMPAT_sRGB {
|
||||
readonly FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: number;
|
||||
readonly SRGB8_ALPHA8: number;
|
||||
@@ -320,6 +414,9 @@ export function getSRGB(gl: GLRenderingContext): COMPAT_sRGB | null {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/EXT_disjoint_timer_query/ and https://registry.khronos.org/webgl/extensions/EXT_disjoint_timer_query_webgl2/
|
||||
*/
|
||||
export interface COMPAT_disjoint_timer_query {
|
||||
/** A GLint indicating the number of bits used to hold the query result for the given target. */
|
||||
QUERY_COUNTER_BITS: number
|
||||
@@ -401,6 +498,31 @@ export function getDisjointTimerQuery(gl: GLRenderingContext): COMPAT_disjoint_t
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/KHR_parallel_shader_compile/
|
||||
*/
|
||||
export interface COMPAT_parallel_shader_compile {
|
||||
readonly COMPLETION_STATUS: number;
|
||||
}
|
||||
|
||||
export function getParallelShaderCompile(gl: GLRenderingContext): COMPAT_parallel_shader_compile | null {
|
||||
const ext = gl.getExtension('KHR_parallel_shader_compile');
|
||||
if (ext === null) return null;
|
||||
return {
|
||||
COMPLETION_STATUS: ext.COMPLETION_STATUS_KHR,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://registry.khronos.org/webgl/extensions/OES_fbo_render_mipmap/
|
||||
*/
|
||||
export interface COMPAT_fboRenderMipmap {
|
||||
}
|
||||
|
||||
export function getFboRenderMipmap(gl: GLRenderingContext): COMPAT_fboRenderMipmap | null {
|
||||
return isWebGL2(gl) ? {} : gl.getExtension('OES_fbo_render_mipmap');
|
||||
}
|
||||
|
||||
export function getNoNonInstancedActiveAttribs(gl: GLRenderingContext): boolean {
|
||||
if (!isWebGL2(gl)) return false;
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
|
||||
import { GLRenderingContext, COMPAT_instanced_arrays, COMPAT_standard_derivatives, COMPAT_vertex_array_object, getInstancedArrays, getStandardDerivatives, COMPAT_element_index_uint, getElementIndexUint, COMPAT_texture_float, getTextureFloat, COMPAT_texture_float_linear, getTextureFloatLinear, COMPAT_blend_minmax, getBlendMinMax, getFragDepth, COMPAT_frag_depth, COMPAT_color_buffer_float, getColorBufferFloat, COMPAT_draw_buffers, getDrawBuffers, getShaderTextureLod, COMPAT_shader_texture_lod, getDepthTexture, COMPAT_depth_texture, COMPAT_sRGB, getSRGB, getTextureHalfFloat, getTextureHalfFloatLinear, COMPAT_texture_half_float, COMPAT_texture_half_float_linear, COMPAT_color_buffer_half_float, getColorBufferHalfFloat, getVertexArrayObject, getDisjointTimerQuery, COMPAT_disjoint_timer_query, getNoNonInstancedActiveAttribs } from './compat';
|
||||
import { GLRenderingContext, COMPAT_instanced_arrays, COMPAT_standard_derivatives, COMPAT_vertex_array_object, getInstancedArrays, getStandardDerivatives, COMPAT_element_index_uint, getElementIndexUint, COMPAT_texture_float, getTextureFloat, COMPAT_texture_float_linear, getTextureFloatLinear, COMPAT_blend_minmax, getBlendMinMax, getFragDepth, COMPAT_frag_depth, COMPAT_color_buffer_float, getColorBufferFloat, COMPAT_draw_buffers, getDrawBuffers, getShaderTextureLod, COMPAT_shader_texture_lod, getDepthTexture, COMPAT_depth_texture, COMPAT_sRGB, getSRGB, getTextureHalfFloat, getTextureHalfFloatLinear, COMPAT_texture_half_float, COMPAT_texture_half_float_linear, COMPAT_color_buffer_half_float, getColorBufferHalfFloat, getVertexArrayObject, getDisjointTimerQuery, COMPAT_disjoint_timer_query, getNoNonInstancedActiveAttribs, getDrawBuffersIndexed, COMPAT_draw_buffers_indexed, getParallelShaderCompile, COMPAT_parallel_shader_compile, getFboRenderMipmap, COMPAT_fboRenderMipmap } from './compat';
|
||||
import { isDebugMode } from '../../mol-util/debug';
|
||||
|
||||
export type WebGLExtensions = {
|
||||
instancedArrays: COMPAT_instanced_arrays
|
||||
elementIndexUint: COMPAT_element_index_uint
|
||||
standardDerivatives: COMPAT_standard_derivatives
|
||||
|
||||
standardDerivatives: COMPAT_standard_derivatives | null
|
||||
textureFloat: COMPAT_texture_float | null
|
||||
textureFloatLinear: COMPAT_texture_float_linear | null
|
||||
textureHalfFloat: COMPAT_texture_half_float | null
|
||||
@@ -23,9 +23,12 @@ export type WebGLExtensions = {
|
||||
colorBufferFloat: COMPAT_color_buffer_float | null
|
||||
colorBufferHalfFloat: COMPAT_color_buffer_half_float | null
|
||||
drawBuffers: COMPAT_draw_buffers | null
|
||||
drawBuffersIndexed: COMPAT_draw_buffers_indexed | null
|
||||
shaderTextureLod: COMPAT_shader_texture_lod | null
|
||||
sRGB: COMPAT_sRGB | null
|
||||
disjointTimerQuery: COMPAT_disjoint_timer_query | null
|
||||
parallelShaderCompile: COMPAT_parallel_shader_compile | null
|
||||
fboRenderMipmap: COMPAT_fboRenderMipmap | null
|
||||
|
||||
noNonInstancedActiveAttribs: boolean
|
||||
}
|
||||
@@ -94,6 +97,10 @@ export function createExtensions(gl: GLRenderingContext): WebGLExtensions {
|
||||
if (isDebugMode && drawBuffers === null) {
|
||||
console.log('Could not find support for "draw_buffers"');
|
||||
}
|
||||
const drawBuffersIndexed = getDrawBuffersIndexed(gl);
|
||||
if (isDebugMode && drawBuffersIndexed === null) {
|
||||
console.log('Could not find support for "draw_buffers_indexed"');
|
||||
}
|
||||
const shaderTextureLod = getShaderTextureLod(gl);
|
||||
if (isDebugMode && shaderTextureLod === null) {
|
||||
console.log('Could not find support for "shader_texture_lod"');
|
||||
@@ -106,28 +113,39 @@ export function createExtensions(gl: GLRenderingContext): WebGLExtensions {
|
||||
if (isDebugMode && disjointTimerQuery === null) {
|
||||
console.log('Could not find support for "disjoint_timer_query"');
|
||||
}
|
||||
const parallelShaderCompile = getParallelShaderCompile(gl);
|
||||
if (isDebugMode && parallelShaderCompile === null) {
|
||||
console.log('Could not find support for "parallel_shader_compile"');
|
||||
}
|
||||
const fboRenderMipmap = getFboRenderMipmap(gl);
|
||||
if (isDebugMode && fboRenderMipmap === null) {
|
||||
console.log('Could not find support for "fbo_render_mipmap"');
|
||||
}
|
||||
|
||||
const noNonInstancedActiveAttribs = getNoNonInstancedActiveAttribs(gl);
|
||||
|
||||
return {
|
||||
instancedArrays,
|
||||
standardDerivatives,
|
||||
elementIndexUint,
|
||||
|
||||
textureFloat,
|
||||
textureFloatLinear,
|
||||
textureHalfFloat,
|
||||
textureHalfFloatLinear,
|
||||
elementIndexUint,
|
||||
depthTexture,
|
||||
|
||||
blendMinMax,
|
||||
vertexArrayObject,
|
||||
fragDepth,
|
||||
colorBufferFloat,
|
||||
colorBufferHalfFloat,
|
||||
drawBuffers,
|
||||
drawBuffersIndexed,
|
||||
shaderTextureLod,
|
||||
sRGB,
|
||||
disjointTimerQuery,
|
||||
parallelShaderCompile,
|
||||
fboRenderMipmap,
|
||||
|
||||
noNonInstancedActiveAttribs,
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ import { isDebugMode } from '../../mol-util/debug';
|
||||
|
||||
const getNextRenderbufferId = idFactory();
|
||||
|
||||
export type RenderbufferFormat = 'depth16' | 'stencil8' | 'rgba4' | 'depth-stencil' | 'depth32f'
|
||||
export type RenderbufferFormat = 'depth16' | 'stencil8' | 'rgba4' | 'depth-stencil' | 'depth24' | 'depth32f' | 'depth24-stencil8' | 'depth32f-stencil8'
|
||||
export type RenderbufferAttachment = 'depth' | 'stencil' | 'depth-stencil' | 'color0'
|
||||
|
||||
export function getFormat(gl: GLRenderingContext, format: RenderbufferFormat) {
|
||||
@@ -20,9 +20,18 @@ export function getFormat(gl: GLRenderingContext, format: RenderbufferFormat) {
|
||||
case 'stencil8': return gl.STENCIL_INDEX8;
|
||||
case 'rgba4': return gl.RGBA4;
|
||||
case 'depth-stencil': return gl.DEPTH_STENCIL;
|
||||
case 'depth24':
|
||||
if (isWebGL2(gl)) return gl.DEPTH_COMPONENT24;
|
||||
else throw new Error('WebGL2 needed for `depth24` renderbuffer format');
|
||||
case 'depth32f':
|
||||
if (isWebGL2(gl)) return gl.DEPTH_COMPONENT32F;
|
||||
else throw new Error('WebGL2 needed for `depth32f` renderbuffer format');
|
||||
case 'depth24-stencil8':
|
||||
if (isWebGL2(gl)) return gl.DEPTH24_STENCIL8;
|
||||
else throw new Error('WebGL2 needed for `depth24-stencil8` renderbuffer format');
|
||||
case 'depth32f-stencil8':
|
||||
if (isWebGL2(gl)) return gl.DEPTH32F_STENCIL8;
|
||||
else throw new Error('WebGL2 needed for `depth32f-stencil8` renderbuffer format');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,19 @@ export type WebGLState = {
|
||||
/** specifies the source and destination blending factors, clamped to [0, 1] */
|
||||
blendColor: (red: number, green: number, blue: number, alpha: number) => void
|
||||
|
||||
/** sets the front and back function and reference value for stencil testing */
|
||||
stencilFunc: (func: number, ref: number, mask: number) => void
|
||||
/** sets the front and/or back function and reference value for stencil testing */
|
||||
stencilFuncSeparate: (face: number, func: number, ref: number, mask: number) => void
|
||||
/** controls enabling and disabling of both the front and back writing of individual bits in the stencil planes */
|
||||
stencilMask: (mask: number) => void
|
||||
/** controls enabling and disabling of both the front and back writing of individual bits in the stencil planes */
|
||||
stencilMaskSeparate: (face: number, mask: number) => void
|
||||
/** sets both the front and back-facing stencil test actions */
|
||||
stencilOp: (fail: number, zfail: number, zpass: number) => void
|
||||
/** sets the front and/or back-facing stencil test actions */
|
||||
stencilOpSeparate: (face: number, fail: number, zfail: number, zpass: number) => void
|
||||
|
||||
enableVertexAttrib: (index: number) => void
|
||||
clearVertexAttribsState: () => void
|
||||
disableUnusedVertexAttribs: () => void
|
||||
@@ -91,10 +104,24 @@ export function createState(gl: GLRenderingContext): WebGLState {
|
||||
let currentBlendSrcAlpha = gl.getParameter(gl.BLEND_SRC_ALPHA);
|
||||
let currentBlendDstAlpha = gl.getParameter(gl.BLEND_DST_ALPHA);
|
||||
let currentBlendColor = gl.getParameter(gl.BLEND_COLOR);
|
||||
|
||||
let currentBlendEqRGB = gl.getParameter(gl.BLEND_EQUATION_RGB);
|
||||
let currentBlendEqAlpha = gl.getParameter(gl.BLEND_EQUATION_ALPHA);
|
||||
|
||||
let currentStencilFunc = gl.getParameter(gl.STENCIL_FUNC);
|
||||
let currentStencilValueMask = gl.getParameter(gl.STENCIL_VALUE_MASK);
|
||||
let currentStencilRef = gl.getParameter(gl.STENCIL_REF);
|
||||
let currentStencilBackFunc = gl.getParameter(gl.STENCIL_BACK_FUNC);
|
||||
let currentStencilBackValueMask = gl.getParameter(gl.STENCIL_BACK_VALUE_MASK);
|
||||
let currentStencilBackRef = gl.getParameter(gl.STENCIL_BACK_REF);
|
||||
let currentStencilWriteMask = gl.getParameter(gl.STENCIL_WRITEMASK);
|
||||
let currentStencilBackWriteMask = gl.getParameter(gl.STENCIL_BACK_WRITEMASK);
|
||||
let currentStencilFail = gl.getParameter(gl.STENCIL_FAIL);
|
||||
let currentStencilPassDepthPass = gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS);
|
||||
let currentStencilPassDepthFail = gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL);
|
||||
let currentStencilBackFail = gl.getParameter(gl.STENCIL_BACK_FAIL);
|
||||
let currentStencilBackPassDepthPass = gl.getParameter(gl.STENCIL_BACK_PASS_DEPTH_PASS);
|
||||
let currentStencilBackPassDepthFail = gl.getParameter(gl.STENCIL_BACK_PASS_DEPTH_FAIL);
|
||||
|
||||
let maxVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
||||
const vertexAttribsState: number[] = [];
|
||||
|
||||
@@ -217,6 +244,109 @@ export function createState(gl: GLRenderingContext): WebGLState {
|
||||
}
|
||||
},
|
||||
|
||||
stencilFunc: (func: number, ref: number, mask: number) => {
|
||||
if (func !== currentStencilFunc || ref !== currentStencilRef || mask !== currentStencilValueMask || func !== currentStencilBackFunc || ref !== currentStencilBackRef || mask !== currentStencilBackValueMask) {
|
||||
gl.stencilFunc(func, ref, mask);
|
||||
currentStencilFunc = func;
|
||||
currentStencilRef = ref;
|
||||
currentStencilValueMask = mask;
|
||||
currentStencilBackFunc = func;
|
||||
currentStencilBackRef = ref;
|
||||
currentStencilBackValueMask = mask;
|
||||
}
|
||||
},
|
||||
stencilFuncSeparate: (face: number, func: number, ref: number, mask: number) => {
|
||||
if (face === gl.FRONT) {
|
||||
if (func !== currentStencilFunc || ref !== currentStencilRef || mask !== currentStencilValueMask) {
|
||||
gl.stencilFuncSeparate(face, func, ref, mask);
|
||||
currentStencilFunc = func;
|
||||
currentStencilRef = ref;
|
||||
currentStencilValueMask = mask;
|
||||
}
|
||||
} else if (face === gl.BACK) {
|
||||
if (func !== currentStencilBackFunc || ref !== currentStencilBackRef || mask !== currentStencilBackValueMask) {
|
||||
gl.stencilFuncSeparate(face, func, ref, mask);
|
||||
currentStencilBackFunc = func;
|
||||
currentStencilBackRef = ref;
|
||||
currentStencilBackValueMask = mask;
|
||||
}
|
||||
} else if (face === gl.FRONT_AND_BACK) {
|
||||
if (func !== currentStencilFunc || ref !== currentStencilRef || mask !== currentStencilValueMask || func !== currentStencilBackFunc || ref !== currentStencilBackRef || mask !== currentStencilBackValueMask) {
|
||||
gl.stencilFuncSeparate(face, func, ref, mask);
|
||||
currentStencilFunc = func;
|
||||
currentStencilRef = ref;
|
||||
currentStencilValueMask = mask;
|
||||
currentStencilBackFunc = func;
|
||||
currentStencilBackRef = ref;
|
||||
currentStencilBackValueMask = mask;
|
||||
}
|
||||
}
|
||||
},
|
||||
stencilMask: (mask: number) => {
|
||||
if (mask !== currentStencilWriteMask || mask !== currentStencilBackWriteMask) {
|
||||
gl.stencilMask(mask);
|
||||
currentStencilWriteMask = mask;
|
||||
currentStencilBackWriteMask = mask;
|
||||
}
|
||||
},
|
||||
stencilMaskSeparate: (face: number, mask: number) => {
|
||||
if (face === gl.FRONT) {
|
||||
if (mask !== currentStencilWriteMask) {
|
||||
gl.stencilMaskSeparate(face, mask);
|
||||
currentStencilWriteMask = mask;
|
||||
}
|
||||
} else if (face === gl.BACK) {
|
||||
if (mask !== currentStencilBackWriteMask) {
|
||||
gl.stencilMaskSeparate(face, mask);
|
||||
currentStencilBackWriteMask = mask;
|
||||
}
|
||||
} else if (face === gl.FRONT_AND_BACK) {
|
||||
if (mask !== currentStencilWriteMask || mask !== currentStencilBackWriteMask) {
|
||||
gl.stencilMaskSeparate(face, mask);
|
||||
currentStencilWriteMask = mask;
|
||||
currentStencilBackWriteMask = mask;
|
||||
}
|
||||
}
|
||||
},
|
||||
stencilOp: (fail: number, zfail: number, zpass: number) => {
|
||||
if (fail !== currentStencilFail || zfail !== currentStencilPassDepthFail || zpass !== currentStencilPassDepthPass || fail !== currentStencilBackFail || zfail !== currentStencilBackPassDepthFail || zpass !== currentStencilBackPassDepthPass) {
|
||||
gl.stencilOp(fail, zfail, zpass);
|
||||
currentStencilFail = fail;
|
||||
currentStencilPassDepthFail = zfail;
|
||||
currentStencilPassDepthPass = zpass;
|
||||
currentStencilBackFail = fail;
|
||||
currentStencilBackPassDepthFail = zfail;
|
||||
currentStencilBackPassDepthPass = zpass;
|
||||
}
|
||||
},
|
||||
stencilOpSeparate: (face: number, fail: number, zfail: number, zpass: number) => {
|
||||
if (face === gl.FRONT) {
|
||||
if (fail !== currentStencilFail || zfail !== currentStencilPassDepthFail || zpass !== currentStencilPassDepthPass) {
|
||||
gl.stencilOpSeparate(face, fail, zfail, zpass);
|
||||
currentStencilFail = fail;
|
||||
currentStencilPassDepthFail = zfail;
|
||||
currentStencilPassDepthPass = zpass;
|
||||
}
|
||||
} else if (face === gl.BACK) {
|
||||
if (fail !== currentStencilBackFail || zfail !== currentStencilBackPassDepthFail || zpass !== currentStencilBackPassDepthPass) {
|
||||
gl.stencilOpSeparate(face, fail, zfail, zpass);
|
||||
currentStencilBackFail = fail;
|
||||
currentStencilBackPassDepthFail = zfail;
|
||||
currentStencilBackPassDepthPass = zpass;
|
||||
}
|
||||
} else if (face === gl.FRONT_AND_BACK) {
|
||||
if (fail !== currentStencilFail || zfail !== currentStencilPassDepthFail || zpass !== currentStencilPassDepthPass || fail !== currentStencilBackFail || zfail !== currentStencilBackPassDepthFail || zpass !== currentStencilBackPassDepthPass) {
|
||||
gl.stencilOpSeparate(face, fail, zfail, zpass);
|
||||
currentStencilFail = fail;
|
||||
currentStencilPassDepthFail = zfail;
|
||||
currentStencilPassDepthPass = zpass;
|
||||
currentStencilBackFail = fail;
|
||||
currentStencilBackPassDepthFail = zfail;
|
||||
currentStencilBackPassDepthPass = zpass;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
enableVertexAttrib: (index: number) => {
|
||||
gl.enableVertexAttribArray(index);
|
||||
vertexAttribsState[index] = 1;
|
||||
@@ -264,10 +394,24 @@ export function createState(gl: GLRenderingContext): WebGLState {
|
||||
currentBlendSrcAlpha = gl.getParameter(gl.BLEND_SRC_ALPHA);
|
||||
currentBlendDstAlpha = gl.getParameter(gl.BLEND_DST_ALPHA);
|
||||
currentBlendColor = gl.getParameter(gl.BLEND_COLOR);
|
||||
|
||||
currentBlendEqRGB = gl.getParameter(gl.BLEND_EQUATION_RGB);
|
||||
currentBlendEqAlpha = gl.getParameter(gl.BLEND_EQUATION_ALPHA);
|
||||
|
||||
currentStencilFunc = gl.getParameter(gl.STENCIL_FUNC);
|
||||
currentStencilValueMask = gl.getParameter(gl.STENCIL_VALUE_MASK);
|
||||
currentStencilRef = gl.getParameter(gl.STENCIL_REF);
|
||||
currentStencilBackFunc = gl.getParameter(gl.STENCIL_BACK_FUNC);
|
||||
currentStencilBackValueMask = gl.getParameter(gl.STENCIL_BACK_VALUE_MASK);
|
||||
currentStencilBackRef = gl.getParameter(gl.STENCIL_BACK_REF);
|
||||
currentStencilWriteMask = gl.getParameter(gl.STENCIL_WRITEMASK);
|
||||
currentStencilBackWriteMask = gl.getParameter(gl.STENCIL_BACK_WRITEMASK);
|
||||
currentStencilFail = gl.getParameter(gl.STENCIL_FAIL);
|
||||
currentStencilPassDepthPass = gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS);
|
||||
currentStencilPassDepthFail = gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL);
|
||||
currentStencilBackFail = gl.getParameter(gl.STENCIL_BACK_FAIL);
|
||||
currentStencilBackPassDepthPass = gl.getParameter(gl.STENCIL_BACK_PASS_DEPTH_PASS);
|
||||
currentStencilBackPassDepthFail = gl.getParameter(gl.STENCIL_BACK_PASS_DEPTH_FAIL);
|
||||
|
||||
maxVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
||||
vertexAttribsState.length = 0;
|
||||
for (let i = 0; i < maxVertexAttribs; ++i) {
|
||||
|
||||
@@ -57,7 +57,7 @@ export interface EncodedData {
|
||||
|
||||
export namespace Encoding {
|
||||
|
||||
export const enum IntDataType {
|
||||
export enum IntDataType {
|
||||
Int8 = 1,
|
||||
Int16 = 2,
|
||||
Int32 = 3,
|
||||
@@ -66,7 +66,7 @@ export namespace Encoding {
|
||||
Uint32 = 6,
|
||||
}
|
||||
|
||||
export const enum FloatDataType {
|
||||
export enum FloatDataType {
|
||||
Float32 = 32,
|
||||
Float64 = 33
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
|
||||
import { parseFloat as fastParseFloat, parseInt as fastParseInt, getNumberType, NumberType } from '../../../mol-io/reader/common/text/number-parser';
|
||||
import { parseFloat as fastParseFloat, parseInt as fastParseInt, getNumberType, NumberTypes } from '../../../mol-io/reader/common/text/number-parser';
|
||||
|
||||
describe('common', () => {
|
||||
it('number-parser fastParseFloat', () => {
|
||||
@@ -24,17 +24,17 @@ describe('common', () => {
|
||||
});
|
||||
|
||||
it('number-parser getNumberType', () => {
|
||||
expect(getNumberType('11')).toBe(NumberType.Int);
|
||||
expect(getNumberType('5E93')).toBe(NumberType.Scientific);
|
||||
expect(getNumberType('0.42')).toBe(NumberType.Float);
|
||||
expect(getNumberType('Foo123')).toBe(NumberType.NaN);
|
||||
expect(getNumberType('11.0829(23)')).toBe(NumberType.NaN);
|
||||
expect(getNumberType('1..2')).toBe(NumberType.NaN);
|
||||
expect(getNumberType('.')).toBe(NumberType.NaN);
|
||||
expect(getNumberType('-.')).toBe(NumberType.NaN);
|
||||
expect(getNumberType('e')).toBe(NumberType.NaN);
|
||||
expect(getNumberType('-e')).toBe(NumberType.NaN);
|
||||
expect(getNumberType('1e')).toBe(NumberType.Scientific);
|
||||
expect(getNumberType('-1e')).toBe(NumberType.Scientific);
|
||||
expect(getNumberType('11')).toBe(NumberTypes.Int);
|
||||
expect(getNumberType('5E93')).toBe(NumberTypes.Scientific);
|
||||
expect(getNumberType('0.42')).toBe(NumberTypes.Float);
|
||||
expect(getNumberType('Foo123')).toBe(NumberTypes.NaN);
|
||||
expect(getNumberType('11.0829(23)')).toBe(NumberTypes.NaN);
|
||||
expect(getNumberType('1..2')).toBe(NumberTypes.NaN);
|
||||
expect(getNumberType('.')).toBe(NumberTypes.NaN);
|
||||
expect(getNumberType('-.')).toBe(NumberTypes.NaN);
|
||||
expect(getNumberType('e')).toBe(NumberTypes.NaN);
|
||||
expect(getNumberType('-e')).toBe(NumberTypes.NaN);
|
||||
expect(getNumberType('1e')).toBe(NumberTypes.Scientific);
|
||||
expect(getNumberType('-1e')).toBe(NumberTypes.Scientific);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2017-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author David Sehnal <david.sehnal@gmail.com>
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
@@ -15,6 +15,7 @@ import { BIRD_Schema, BIRD_Database } from './cif/schema/bird';
|
||||
import { dic_Schema, dic_Database } from './cif/schema/dic';
|
||||
import { DensityServer_Data_Schema, DensityServer_Data_Database } from './cif/schema/density-server';
|
||||
import { CifCore_Database, CifCore_Schema, CifCore_Aliases } from './cif/schema/cif-core';
|
||||
import { Segmentation_Data_Database, Segmentation_Data_Schema } from './cif/schema/segmentation';
|
||||
|
||||
export const CIF = {
|
||||
parse: (data: string|Uint8Array) => typeof data === 'string' ? parseCifText(data) : parseCifBinary(data),
|
||||
@@ -29,6 +30,7 @@ export const CIF = {
|
||||
dic: (frame: CifFrame) => toDatabase<dic_Schema, dic_Database>(dic_Schema, frame),
|
||||
cifCore: (frame: CifFrame) => toDatabase<CifCore_Schema, CifCore_Database>(CifCore_Schema, frame, CifCore_Aliases),
|
||||
densityServer: (frame: CifFrame) => toDatabase<DensityServer_Data_Schema, DensityServer_Data_Database>(DensityServer_Data_Schema, frame),
|
||||
segmentation: (frame: CifFrame) => toDatabase<Segmentation_Data_Schema, Segmentation_Data_Database>(Segmentation_Data_Schema, frame),
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ export function Field(column: EncodedColumn): Data.CifField {
|
||||
|
||||
const str: Data.CifField['str'] = isNumeric
|
||||
? mask
|
||||
? row => mask[row] === Column.ValueKind.Present ? '' + data[row] : ''
|
||||
? row => mask[row] === Column.ValueKinds.Present ? '' + data[row] : ''
|
||||
: row => '' + data[row]
|
||||
: mask
|
||||
? row => mask[row] === Column.ValueKind.Present ? data[row] : ''
|
||||
? row => mask[row] === Column.ValueKinds.Present ? data[row] : ''
|
||||
: row => data[row];
|
||||
|
||||
const int: Data.CifField['int'] = isNumeric
|
||||
@@ -32,8 +32,8 @@ export function Field(column: EncodedColumn): Data.CifField {
|
||||
: row => { const v = data[row]; return fastParseFloat(v, 0, v.length); };
|
||||
|
||||
const valueKind: Data.CifField['valueKind'] = mask
|
||||
? row => mask[row]
|
||||
: row => Column.ValueKind.Present;
|
||||
? row => mask[row] as Column.ValueKind
|
||||
: row => Column.ValueKinds.Present;
|
||||
|
||||
const rowCount = data.length;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import { Column, ColumnHelpers, Table } from '../../../mol-data/db';
|
||||
import { Tensor } from '../../../mol-math/linear-algebra';
|
||||
import { getNumberType, NumberType, parseInt as fastParseInt, parseFloat as fastParseFloat } from '../common/text/number-parser';
|
||||
import { getNumberType, NumberTypes, parseInt as fastParseInt, parseFloat as fastParseFloat } from '../common/text/number-parser';
|
||||
import { Encoding } from '../../common/binary-cif';
|
||||
import { Tokens } from '../common/text/tokenizer';
|
||||
import { areValuesEqualProvider } from '../common/text/column/token';
|
||||
@@ -124,12 +124,12 @@ export namespace CifField {
|
||||
const float: CifField['float'] = row => { const v = values[row]; return fastParseFloat(v, 0, v.length) || 0; };
|
||||
const valueKind: CifField['valueKind'] = row => {
|
||||
const v = values[row], l = v.length;
|
||||
if (l > 1) return Column.ValueKind.Present;
|
||||
if (l === 0) return Column.ValueKind.NotPresent;
|
||||
if (l > 1) return Column.ValueKinds.Present;
|
||||
if (l === 0) return Column.ValueKinds.NotPresent;
|
||||
const c = v.charCodeAt(0);
|
||||
if (c === 46 /* . */) return Column.ValueKind.NotPresent;
|
||||
if (c === 63 /* ? */) return Column.ValueKind.Unknown;
|
||||
return Column.ValueKind.Present;
|
||||
if (c === 46 /* . */) return Column.ValueKinds.NotPresent;
|
||||
if (c === 63 /* ? */) return Column.ValueKinds.Unknown;
|
||||
return Column.ValueKinds.Present;
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -152,7 +152,7 @@ export namespace CifField {
|
||||
const rowCount = values.length;
|
||||
const str: CifField['str'] = row => { return '' + values[row]; };
|
||||
const float: CifField['float'] = row => values[row];
|
||||
const valueKind: CifField['valueKind'] = row => Column.ValueKind.Present;
|
||||
const valueKind: CifField['valueKind'] = row => Column.ValueKinds.Present;
|
||||
|
||||
const toFloatArray = (params: Column.ToArrayParams<number>) => {
|
||||
if (!params || params.array && values instanceof params.array) {
|
||||
@@ -197,12 +197,12 @@ export namespace CifField {
|
||||
|
||||
const valueKind: CifField['valueKind'] = row => {
|
||||
const s = indices[2 * row], l = indices[2 * row + 1] - s;
|
||||
if (l > 1) return Column.ValueKind.Present;
|
||||
if (l === 0) return Column.ValueKind.NotPresent;
|
||||
if (l > 1) return Column.ValueKinds.Present;
|
||||
if (l === 0) return Column.ValueKinds.NotPresent;
|
||||
const v = data.charCodeAt(s);
|
||||
if (v === 46 /* . */) return Column.ValueKind.NotPresent;
|
||||
if (v === 63 /* ? */) return Column.ValueKind.Unknown;
|
||||
return Column.ValueKind.Present;
|
||||
if (v === 46 /* . */) return Column.ValueKinds.NotPresent;
|
||||
if (v === 63 /* ? */) return Column.ValueKinds.Unknown;
|
||||
return Column.ValueKinds.Present;
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -328,13 +328,13 @@ export function getCifFieldType(field: CifField): Column.Schema.Int | Column.Sch
|
||||
let floatCount = 0, hasStringOrScientific = false, undefinedCount = 0;
|
||||
for (let i = 0, _i = field.rowCount; i < _i; i++) {
|
||||
const k = field.valueKind(i);
|
||||
if (k !== Column.ValueKind.Present) {
|
||||
if (k !== Column.ValueKinds.Present) {
|
||||
undefinedCount++;
|
||||
continue;
|
||||
}
|
||||
const type = getNumberType(field.str(i));
|
||||
if (type === NumberType.Int) continue;
|
||||
else if (type === NumberType.Float) floatCount++;
|
||||
if (type === NumberTypes.Int) continue;
|
||||
else if (type === NumberTypes.Float) floatCount++;
|
||||
else { hasStringOrScientific = true; break; }
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ function createListColumn<T extends number | string>(schema: Column.Schema.List<
|
||||
isDefined: !!f,
|
||||
rowCount: category.rowCount,
|
||||
value,
|
||||
valueKind: f ? f.valueKind : () => Column.ValueKind.NotPresent,
|
||||
valueKind: f ? f.valueKind : () => Column.ValueKinds.NotPresent,
|
||||
areValuesEqual: (rowA, rowB) => arrayEqual(value(rowA), value(rowB)),
|
||||
toArray
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Copyright (c) 2017-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* Code-generated 'BIRD' schema file. Dictionary versions: mmCIF 5.362, IHM 1.17, MA 1.4.3.
|
||||
* Code-generated 'BIRD' schema file. Dictionary versions: mmCIF 5.365, IHM 1.18, MA 1.4.4.
|
||||
*
|
||||
* @author molstar/ciftools package
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Copyright (c) 2017-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* Code-generated 'CCD' schema file. Dictionary versions: mmCIF 5.362, IHM 1.17, MA 1.4.3.
|
||||
* Code-generated 'CCD' schema file. Dictionary versions: mmCIF 5.365, IHM 1.18, MA 1.4.4.
|
||||
*
|
||||
* @author molstar/ciftools package
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Copyright (c) 2017-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* Code-generated 'mmCIF' schema file. Dictionary versions: mmCIF 5.362, IHM 1.17, MA 1.4.3.
|
||||
* Code-generated 'mmCIF' schema file. Dictionary versions: mmCIF 5.365, IHM 1.18, MA 1.4.4.
|
||||
*
|
||||
* @author molstar/ciftools package
|
||||
*/
|
||||
@@ -3470,7 +3470,7 @@ export const mmCIF_Schema = {
|
||||
/**
|
||||
* The clustering method used to obtain the ensemble, if applicable.
|
||||
*/
|
||||
ensemble_clustering_method: Aliased<'Hierarchical' | 'Partitioning (k-means)' | 'Other'>(str),
|
||||
ensemble_clustering_method: Aliased<'Hierarchical' | 'Partitioning (k-means)' | 'Density based threshold-clustering' | 'Other'>(str),
|
||||
/**
|
||||
* The parameter/feature used for clustering the models, if applicable.
|
||||
*/
|
||||
@@ -3628,7 +3628,7 @@ export const mmCIF_Schema = {
|
||||
/**
|
||||
* The type of data held in the dataset.
|
||||
*/
|
||||
data_type: Aliased<'NMR data' | '3DEM volume' | '2DEM class average' | 'EM raw micrographs' | 'X-ray diffraction data' | 'SAS data' | 'CX-MS data' | 'Mass Spectrometry data' | 'EPR data' | 'H/D exchange data' | 'Single molecule FRET data' | 'Experimental model' | 'Comparative model' | 'Integrative model' | 'De Novo model' | 'Predicted contacts' | 'Mutagenesis data' | 'DNA footprinting data' | 'Hydroxyl radical footprinting data' | 'Yeast two-hybrid screening data' | 'Quantitative measurements of genetic interactions' | 'Other'>(str),
|
||||
data_type: Aliased<'NMR data' | '3DEM volume' | '2DEM class average' | 'EM raw micrographs' | 'X-ray diffraction data' | 'SAS data' | 'CX-MS data' | 'Mass Spectrometry data' | 'EPR data' | 'H/D exchange data' | 'Single molecule FRET data' | 'Ensemble FRET data' | 'Experimental model' | 'Comparative model' | 'Integrative model' | 'De Novo model' | 'Predicted contacts' | 'Mutagenesis data' | 'DNA footprinting data' | 'Hydroxyl radical footprinting data' | 'Yeast two-hybrid screening data' | 'Quantitative measurements of genetic interactions' | 'Other'>(str),
|
||||
/**
|
||||
* A flag that indicates whether the dataset is archived in
|
||||
* an IHM related database or elsewhere.
|
||||
|
||||
26
src/mol-io/reader/cif/schema/segmentation.ts
Normal file
26
src/mol-io/reader/cif/schema/segmentation.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
|
||||
import { Column, Database } from '../../../../mol-data/db';
|
||||
import { DensityServer_Data_Schema } from './density-server';
|
||||
|
||||
import Schema = Column.Schema
|
||||
|
||||
const int = Schema.int;
|
||||
|
||||
export const Segmentation_Data_Schema = {
|
||||
volume_data_3d_info: DensityServer_Data_Schema.volume_data_3d_info,
|
||||
segmentation_data_table: {
|
||||
set_id: int,
|
||||
segment_id: int,
|
||||
},
|
||||
segmentation_data_3d: {
|
||||
values: int
|
||||
}
|
||||
};
|
||||
|
||||
export type Segmentation_Data_Schema = typeof Segmentation_Data_Schema;
|
||||
export interface Segmentation_Data_Database extends Database<Segmentation_Data_Schema> {}
|
||||
@@ -39,7 +39,7 @@ export function FixedColumn<T extends Column.Schema>(lines: Tokens, offset: numb
|
||||
isDefined: true,
|
||||
rowCount,
|
||||
value,
|
||||
valueKind: row => Column.ValueKind.Present,
|
||||
valueKind: row => Column.ValueKinds.Present,
|
||||
toArray: params => ColumnHelpers.createAndFillArray(rowCount, value, params),
|
||||
areValuesEqual: (rowA, rowB) => value(rowA) === value(rowB)
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ export function TokenColumn<T extends Column.Schema>(tokens: Tokens, schema: T):
|
||||
isDefined: true,
|
||||
rowCount,
|
||||
value,
|
||||
valueKind: row => Column.ValueKind.Present,
|
||||
valueKind: row => Column.ValueKinds.Present,
|
||||
toArray: params => ColumnHelpers.createAndFillArray(rowCount, value, params),
|
||||
areValuesEqual: areValuesEqualProvider(tokens)
|
||||
};
|
||||
|
||||
@@ -87,13 +87,21 @@ export function parseFloat(str: string, start: number, end: number) {
|
||||
return neg * ret;
|
||||
}
|
||||
|
||||
export const enum NumberType {
|
||||
Int,
|
||||
Float,
|
||||
Scientific,
|
||||
NaN
|
||||
export const enum NumberTypes {
|
||||
Int = 0,
|
||||
Float = 1,
|
||||
Scientific = 2,
|
||||
NaN = 3
|
||||
}
|
||||
|
||||
export const NumberType = {
|
||||
Int: NumberTypes.Int,
|
||||
Float: NumberTypes.Float,
|
||||
Scientific: NumberTypes.Scientific,
|
||||
NaN: NumberTypes.NaN
|
||||
} as const;
|
||||
export type NumberType = (typeof NumberType)[keyof typeof NumberType];
|
||||
|
||||
function isInt(str: string, start: number, end: number) {
|
||||
if (str.charCodeAt(start) === 45 /* - */) { start++; }
|
||||
for (; start < end; start++) {
|
||||
@@ -107,7 +115,7 @@ function isInt(str: string, start: number, end: number) {
|
||||
function getNumberTypeScientific(str: string, start: number, end: number) {
|
||||
// handle + in '1e+1' separately.
|
||||
if (str.charCodeAt(start) === 43 /* + */) start++;
|
||||
return isInt(str, start, end) ? NumberType.Scientific : NumberType.NaN;
|
||||
return isInt(str, start, end) ? NumberTypes.Scientific : NumberTypes.NaN;
|
||||
}
|
||||
|
||||
/** The whole range must match, otherwise returns NaN */
|
||||
@@ -121,7 +129,7 @@ export function getNumberType(str: string): NumberType {
|
||||
|
||||
// string is . or -.
|
||||
if (str.charCodeAt(start) === 46 && end - start === 1) {
|
||||
return NumberType.NaN;
|
||||
return NumberTypes.NaN;
|
||||
}
|
||||
|
||||
while (start < end) {
|
||||
@@ -139,18 +147,18 @@ export function getNumberType(str: string): NumberType {
|
||||
} else if (c === 53 || c === 21) { // 'e'/'E'
|
||||
return getNumberTypeScientific(str, start + 1, end);
|
||||
} else {
|
||||
return NumberType.NaN;
|
||||
return NumberTypes.NaN;
|
||||
}
|
||||
}
|
||||
return hasDigit ? NumberType.Float : NumberType.Int;
|
||||
return hasDigit ? NumberTypes.Float : NumberTypes.Int;
|
||||
} else if (c === 53 || c === 21) { // 'e'/'E'
|
||||
if (start === 0 || start === 1 && str.charCodeAt(0) === 45) {
|
||||
return NumberType.NaN; // string starts with e/E or -e/-E
|
||||
return NumberTypes.NaN; // string starts with e/E or -e/-E
|
||||
}
|
||||
return getNumberTypeScientific(str, start + 1, end);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return start === end ? NumberType.Int : NumberType.NaN;
|
||||
return start === end ? NumberTypes.Int : NumberTypes.NaN;
|
||||
}
|
||||
|
||||
@@ -184,8 +184,8 @@ function getFieldData(field: Field<any, any>, arrayCtor: ArrayCtor<string | numb
|
||||
const keys = data[_d].keys();
|
||||
while (keys.hasNext) {
|
||||
const key = keys.move();
|
||||
const p = valueKind ? valueKind(key, d) : Column.ValueKind.Present;
|
||||
if (p !== Column.ValueKind.Present) {
|
||||
const p = valueKind ? valueKind(key, d) : Column.ValueKinds.Present;
|
||||
if (p !== Column.ValueKinds.Present) {
|
||||
mask[offset] = p;
|
||||
if (isStr)
|
||||
array[offset] = '';
|
||||
@@ -193,10 +193,10 @@ function getFieldData(field: Field<any, any>, arrayCtor: ArrayCtor<string | numb
|
||||
} else {
|
||||
const value = getter(key, d, offset);
|
||||
if (typeof value === 'string' && !value) {
|
||||
mask[offset] = Column.ValueKind.NotPresent;
|
||||
mask[offset] = Column.ValueKinds.NotPresent;
|
||||
allPresent = false;
|
||||
} else {
|
||||
mask[offset] = Column.ValueKind.Present;
|
||||
mask[offset] = Column.ValueKinds.Present;
|
||||
}
|
||||
array[offset] = value;
|
||||
}
|
||||
|
||||
@@ -82,9 +82,9 @@ export class TextEncoder implements Encoder<string> {
|
||||
|
||||
function writeValue(builder: StringBuilder, data: any, key: any, f: Field<any, any>, floatPrecision: number, index: number): boolean {
|
||||
const kind = f.valueKind;
|
||||
const p = kind ? kind(key, data) : Column.ValueKind.Present;
|
||||
if (p !== Column.ValueKind.Present) {
|
||||
if (p === Column.ValueKind.NotPresent) writeNotPresent(builder);
|
||||
const p = kind ? kind(key, data) : Column.ValueKinds.Present;
|
||||
if (p !== Column.ValueKinds.Present) {
|
||||
if (p === Column.ValueKinds.NotPresent) writeNotPresent(builder);
|
||||
else writeUnknown(builder);
|
||||
} else {
|
||||
const val = f.value(key, data, index);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2020-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
@@ -13,6 +13,7 @@ import { Box3D } from './primitives/box3d';
|
||||
|
||||
export class BoundaryHelper {
|
||||
private dir: Vec3[];
|
||||
private dirLength: number;
|
||||
|
||||
private minDist: number[] = [];
|
||||
private maxDist: number[] = [];
|
||||
@@ -56,13 +57,13 @@ export class BoundaryHelper {
|
||||
}
|
||||
|
||||
includePosition(p: Vec3) {
|
||||
for (let i = 0, il = this.dir.length; i < il; ++i) {
|
||||
for (let i = 0; i < this.dirLength; ++i) {
|
||||
this.computeExtrema(i, p);
|
||||
}
|
||||
}
|
||||
|
||||
includePositionRadius(center: Vec3, radius: number) {
|
||||
for (let i = 0, il = this.dir.length; i < il; ++i) {
|
||||
for (let i = 0; i < this.dirLength; ++i) {
|
||||
this.computeSphereExtrema(i, center, radius);
|
||||
}
|
||||
}
|
||||
@@ -101,7 +102,7 @@ export class BoundaryHelper {
|
||||
}
|
||||
|
||||
reset() {
|
||||
for (let i = 0, il = this.dir.length; i < il; ++i) {
|
||||
for (let i = 0; i < this.dirLength; ++i) {
|
||||
this.minDist[i] = Infinity;
|
||||
this.maxDist[i] = -Infinity;
|
||||
this.extrema[i * 2] = Vec3();
|
||||
@@ -112,6 +113,7 @@ export class BoundaryHelper {
|
||||
|
||||
constructor(quality: EposQuality) {
|
||||
this.dir = getEposDir(quality);
|
||||
this.dirLength = this.dir.length;
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
* Copyright (c) 2017-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
||||
*
|
||||
* @author David Sehnal <david.sehnal@gmail.com>
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
|
||||
import { lerp as scalar_lerp } from '../../mol-math/interpolate';
|
||||
import { defaults } from '../../mol-util';
|
||||
import { Mat3 } from '../linear-algebra/3d/mat3';
|
||||
import { Mat4 } from '../linear-algebra/3d/mat4';
|
||||
import { Quat } from '../linear-algebra/3d/quat';
|
||||
@@ -29,11 +29,13 @@ interface SymmetryOperator {
|
||||
readonly hkl: Vec3,
|
||||
/** spacegroup symmetry operator index, -1 if not applicable */
|
||||
readonly spgrOp: number,
|
||||
/** unique (external) key, -1 if not available */
|
||||
readonly key: number,
|
||||
|
||||
readonly matrix: Mat4,
|
||||
// cache the inverse of the transform
|
||||
/** cache the inverse of the transform */
|
||||
readonly inverse: Mat4,
|
||||
// optimize the identity case
|
||||
/** optimize the identity case */
|
||||
readonly isIdentity: boolean,
|
||||
|
||||
/**
|
||||
@@ -51,19 +53,20 @@ namespace SymmetryOperator {
|
||||
|
||||
export const RotationTranslationEpsilon = 0.005;
|
||||
|
||||
export type CreateInfo = { assembly?: SymmetryOperator['assembly'], ncsId?: number, hkl?: Vec3, spgrOp?: number }
|
||||
export type CreateInfo = { assembly?: SymmetryOperator['assembly'], ncsId?: number, hkl?: Vec3, spgrOp?: number, key?: number }
|
||||
export function create(name: string, matrix: Mat4, info?: CreateInfo | SymmetryOperator): SymmetryOperator {
|
||||
let { assembly, ncsId, hkl, spgrOp } = info || { };
|
||||
let { assembly, ncsId, hkl, spgrOp, key } = info || { };
|
||||
const _hkl = hkl ? Vec3.clone(hkl) : Vec3();
|
||||
spgrOp = defaults(spgrOp, -1);
|
||||
spgrOp = spgrOp ?? -1;
|
||||
key = key ?? -1;
|
||||
ncsId = ncsId || -1;
|
||||
const isIdentity = Mat4.isIdentity(matrix);
|
||||
const suffix = getSuffix(info, isIdentity);
|
||||
if (isIdentity) return { name, assembly, matrix, inverse: Mat4.identity(), isIdentity: true, hkl: _hkl, spgrOp, ncsId, suffix };
|
||||
if (isIdentity) return { name, assembly, matrix, inverse: Mat4.identity(), isIdentity: true, hkl: _hkl, spgrOp, ncsId, suffix, key };
|
||||
if (!Mat4.isRotationAndTranslation(matrix, RotationTranslationEpsilon)) {
|
||||
console.warn(`Symmetry operator (${name}) should be a composition of rotation and translation.`);
|
||||
}
|
||||
return { name, assembly, matrix, inverse: Mat4.invert(Mat4(), matrix), isIdentity: false, hkl: _hkl, spgrOp, ncsId, suffix };
|
||||
return { name, assembly, matrix, inverse: Mat4.invert(Mat4(), matrix), isIdentity: false, hkl: _hkl, spgrOp, key, ncsId, suffix };
|
||||
}
|
||||
|
||||
function isSymmetryOperator(x: any): x is SymmetryOperator {
|
||||
@@ -174,11 +177,15 @@ namespace SymmetryOperator {
|
||||
|
||||
export interface Coordinates { x: ArrayLike<number>, y: ArrayLike<number>, z: ArrayLike<number> }
|
||||
|
||||
export function createMapping<T extends number>(operator: SymmetryOperator, coords: Coordinates, radius?: ((index: T) => number)): ArrayMapping<T> {
|
||||
const invariantPosition = SymmetryOperator.createCoordinateMapper(SymmetryOperator.Default, coords);
|
||||
const position = operator.isIdentity ? invariantPosition : SymmetryOperator.createCoordinateMapper(operator, coords);
|
||||
function _createMapping<T extends number>(operator: SymmetryOperator, coords: Coordinates, radius: ((index: T) => number)): ArrayMapping<T> {
|
||||
const invariantPosition = createCoordinateMapper(SymmetryOperator.Default, coords);
|
||||
const position = operator.isIdentity ? invariantPosition : createCoordinateMapper(operator, coords);
|
||||
const { x, y, z } = createProjections(operator, coords);
|
||||
return { operator, coordinates: coords, invariantPosition, position, x, y, z, r: radius ? radius : _zeroRadius };
|
||||
return { operator, coordinates: coords, invariantPosition, position, x, y, z, r: radius };
|
||||
}
|
||||
|
||||
export function createMapping<T extends number>(operator: SymmetryOperator, coords: Coordinates, radius: ((index: T) => number) = _zeroRadius) {
|
||||
return _createMapping(operator, coords, radius);
|
||||
}
|
||||
|
||||
export function createCoordinateMapper<T extends number>(t: SymmetryOperator, coords: Coordinates): CoordinateMapper<T> {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user