mirror of
https://github.com/molstar/molstar.git
synced 2026-06-05 14:04:36 +08:00
Compare commits
6 Commits
v3.23.0
...
clamp-cube
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3667092327 | ||
|
|
842824057b | ||
|
|
6a32f85e60 | ||
|
|
f29c62ec33 | ||
|
|
d77981230b | ||
|
|
e2b92c15f0 |
@@ -6,6 +6,8 @@ Note that since we don't clearly distinguish between a public and private interf
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Make `PluginContext.initContainer` checkered canvas background optional
|
||||
|
||||
## [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
|
||||
|
||||
@@ -71,6 +71,7 @@ export function getFieldType(type: string, description: string, values?: string[
|
||||
case 'ec-type':
|
||||
case 'ucode-alphanum-csv':
|
||||
case 'id_list':
|
||||
case 'entity_id_list':
|
||||
return ListCol('str', ',', description);
|
||||
case 'id_list_spc':
|
||||
return ListCol('str', ' ', description);
|
||||
|
||||
@@ -57,7 +57,7 @@ export const apply_light_color = `
|
||||
RE_IndirectSpecular_Physical(radiance, iblIrradiance, clearcoatRadiance, geometry, physicalMaterial, reflectedLight);
|
||||
|
||||
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular;
|
||||
outgoingLight = clamp(outgoingLight, 0.0, 1.0); // prevents black artifacts on specular highlight with transparent background
|
||||
outgoingLight = clamp(outgoingLight, 0.01, 0.99); // prevents black artifacts on specular highlight with transparent background
|
||||
|
||||
gl_FragColor = vec4(outgoingLight, color.a);
|
||||
#endif
|
||||
|
||||
@@ -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.360, IHM 1.17, MA 1.4.2.
|
||||
* Code-generated 'BIRD' schema file. Dictionary versions: mmCIF 5.362, IHM 1.17, MA 1.4.3.
|
||||
*
|
||||
* @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.360, IHM 1.17, MA 1.4.2.
|
||||
* Code-generated 'CCD' schema file. Dictionary versions: mmCIF 5.362, IHM 1.17, MA 1.4.3.
|
||||
*
|
||||
* @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.360, IHM 1.17, MA 1.4.2.
|
||||
* Code-generated 'mmCIF' schema file. Dictionary versions: mmCIF 5.362, IHM 1.17, MA 1.4.3.
|
||||
*
|
||||
* @author molstar/ciftools package
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* 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 David Sehnal <david.sehnal@gmail.com>
|
||||
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
||||
*/
|
||||
|
||||
import { CubeFile } from '../../mol-io/reader/cube/parser';
|
||||
@@ -11,8 +12,9 @@ import { Task } from '../../mol-task';
|
||||
import { arrayMax, arrayMean, arrayMin, arrayRms } from '../../mol-util/array';
|
||||
import { ModelFormat } from '../format';
|
||||
import { CustomProperties } from '../../mol-model/custom-property';
|
||||
import { clamp } from '../../mol-math/interpolate';
|
||||
|
||||
export function volumeFromCube(source: CubeFile, params?: { dataIndex?: number, label?: string, entryId?: string }): Task<Volume> {
|
||||
export function volumeFromCube(source: CubeFile, params?: { dataIndex?: number, label?: string, entryId?: string, clamp?: { min: number, max: number } }): Task<Volume> {
|
||||
return Task.create<Volume>('Create Volume', async () => {
|
||||
const { header, values: sourceValues } = source;
|
||||
const space = Tensor.Space(header.dim, [0, 1, 2], Float64Array);
|
||||
@@ -24,6 +26,7 @@ export function volumeFromCube(source: CubeFile, params?: { dataIndex?: number,
|
||||
// get every nth value from the source values
|
||||
const [h, k, l] = header.dim;
|
||||
const nth = (params?.dataIndex || 0) + 1;
|
||||
const { min, max } = params?.clamp || { min: -Infinity, max: Infinity };
|
||||
|
||||
let o = 0, s = 0;
|
||||
|
||||
@@ -31,7 +34,7 @@ export function volumeFromCube(source: CubeFile, params?: { dataIndex?: number,
|
||||
for (let u = 0; u < h; u++) {
|
||||
for (let v = 0; v < k; v++) {
|
||||
for (let w = 0; w < l; w++) {
|
||||
values[o++] = sourceValues[s];
|
||||
values[o++] = clamp(sourceValues[s], min, max);
|
||||
s += nth;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,12 +88,24 @@ const VolumeFromCube = PluginStateTransform.BuiltIn({
|
||||
return {
|
||||
dataIndex,
|
||||
entryId: PD.Text(''),
|
||||
clamp: PD.MappedStatic('off', {
|
||||
'off': PD.EmptyGroup(),
|
||||
'on': PD.Group({
|
||||
min: PD.Numeric(-1024),
|
||||
max: PD.Numeric(1024),
|
||||
})
|
||||
}, { cycle: true })
|
||||
};
|
||||
}
|
||||
})({
|
||||
apply({ a, params }) {
|
||||
return Task.create('Create volume from Cube', async ctx => {
|
||||
const volume = await volumeFromCube(a.data, { ...params, label: a.data.name || a.label }).runInContext(ctx);
|
||||
const volume = await volumeFromCube(a.data, {
|
||||
dataIndex: params.dataIndex,
|
||||
label: a.data.name || a.label,
|
||||
entryId: params.entryId,
|
||||
clamp: params.clamp.name === 'on' ? params.clamp.params : undefined,
|
||||
}).runInContext(ctx);
|
||||
const props = { label: volume.label || 'Volume', description: `Volume ${a.data.header.dim[0]}\u00D7${a.data.header.dim[1]}\u00D7${a.data.header.dim[2]}` };
|
||||
return new SO.Volume.Data(volume, props);
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ export class ViewportCanvas extends PluginUIComponent<ViewportCanvasParams, View
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
if (!this.container.current || !this.plugin.mount(this.container.current!)) {
|
||||
if (!this.container.current || !this.plugin.mount(this.container.current!, { checkeredCanvasBackground: true })) {
|
||||
this.setState({ noWebGl: true });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ export class PluginContext {
|
||||
*/
|
||||
readonly customState: unknown = Object.create(null);
|
||||
|
||||
initContainer(canvas3dContext?: Canvas3DContext) {
|
||||
initContainer(options?: { canvas3dContext?: Canvas3DContext, checkeredCanvasBackground?: boolean }) {
|
||||
if (this.canvasContainer) return true;
|
||||
|
||||
const container = document.createElement('div');
|
||||
@@ -209,27 +209,33 @@ export class PluginContext {
|
||||
'-webkit-touch-callout': 'none',
|
||||
'touch-action': 'manipulation',
|
||||
});
|
||||
let canvas = canvas3dContext?.canvas;
|
||||
let canvas = options?.canvas3dContext?.canvas;
|
||||
if (!canvas) {
|
||||
canvas = document.createElement('canvas');
|
||||
Object.assign(canvas.style, {
|
||||
'background-image': 'linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%, lightgrey), linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%, lightgrey)',
|
||||
'background-size': '60px 60px',
|
||||
'background-position': '0 0, 30px 30px'
|
||||
});
|
||||
if (options?.checkeredCanvasBackground) {
|
||||
Object.assign(canvas.style, {
|
||||
'background-image': 'linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%, lightgrey), linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%, lightgrey)',
|
||||
'background-size': '60px 60px',
|
||||
'background-position': '0 0, 30px 30px'
|
||||
});
|
||||
}
|
||||
container.appendChild(canvas);
|
||||
}
|
||||
if (!this.initViewer(canvas, container, canvas3dContext)) {
|
||||
if (!this.initViewer(canvas, container, options?.canvas3dContext)) {
|
||||
return false;
|
||||
}
|
||||
this.canvasContainer = container;
|
||||
return true;
|
||||
}
|
||||
|
||||
mount(target: HTMLElement) {
|
||||
/**
|
||||
* Mount the plugin into the target element (assumes the target has "relative"-like positioninig).
|
||||
* If initContainer wasn't called separately before, initOptions will be passed to it.
|
||||
*/
|
||||
mount(target: HTMLElement, initOptions?: { canvas3dContext?: Canvas3DContext, checkeredCanvasBackground?: boolean }) {
|
||||
if (this.disposed) throw new Error('Cannot mount a disposed context');
|
||||
|
||||
if (!this.initContainer()) return false;
|
||||
if (!this.initContainer(initOptions)) return false;
|
||||
|
||||
if (this.canvasContainer!.parentElement !== target) {
|
||||
this.canvasContainer!.parentElement?.removeChild(this.canvasContainer!);
|
||||
|
||||
Reference in New Issue
Block a user