Skip to content
Snippets Groups Projects
Commit de093b54 authored by Alexander Rose's avatar Alexander Rose
Browse files

support origin and model as reference for model unitcell representation

parent 88cd9184
No related branches found
No related tags found
No related merge requests found
...@@ -702,7 +702,7 @@ const ModelUnitcell3D = PluginStateTransform.BuiltIn({ ...@@ -702,7 +702,7 @@ const ModelUnitcell3D = PluginStateTransform.BuiltIn({
return Task.create('Model Unit Cell', async ctx => { return Task.create('Model Unit Cell', async ctx => {
const symmetry = ModelSymmetry.Provider.get(a.data); const symmetry = ModelSymmetry.Provider.get(a.data);
if (!symmetry) return StateObject.Null; if (!symmetry) return StateObject.Null;
const data = getUnitcellData(a.data, symmetry); const data = getUnitcellData(a.data, symmetry, params);
const repr = UnitcellRepresentation({ webgl: plugin.canvas3d?.webgl, ...plugin.representation.structure.themes }, () => UnitcellParams); const repr = UnitcellRepresentation({ webgl: plugin.canvas3d?.webgl, ...plugin.representation.structure.themes }, () => UnitcellParams);
await repr.createOrUpdate(params, data).runInContext(ctx); await repr.createOrUpdate(params, data).runInContext(ctx);
return new SO.Shape.Representation3D({ repr, source: a }, { label: `Unit Cell`, description: symmetry.spacegroup.name }); return new SO.Shape.Representation3D({ repr, source: a }, { label: `Unit Cell`, description: symmetry.spacegroup.name });
...@@ -713,7 +713,7 @@ const ModelUnitcell3D = PluginStateTransform.BuiltIn({ ...@@ -713,7 +713,7 @@ const ModelUnitcell3D = PluginStateTransform.BuiltIn({
const symmetry = ModelSymmetry.Provider.get(a.data); const symmetry = ModelSymmetry.Provider.get(a.data);
if (!symmetry) return StateTransformer.UpdateResult.Null; if (!symmetry) return StateTransformer.UpdateResult.Null;
const props = { ...b.data.repr.props, ...newParams }; const props = { ...b.data.repr.props, ...newParams };
const data = getUnitcellData(a.data, symmetry); const data = getUnitcellData(a.data, symmetry, props);
await b.data.repr.createOrUpdate(props, data).runInContext(ctx); await b.data.repr.createOrUpdate(props, data).runInContext(ctx);
b.data.source = a; b.data.source = a;
return StateTransformer.UpdateResult.Updated; return StateTransformer.UpdateResult.Updated;
......
...@@ -29,10 +29,16 @@ interface UnitcellData { ...@@ -29,10 +29,16 @@ interface UnitcellData {
ref: Vec3 ref: Vec3
} }
const CellRef = {
origin: 'Origin',
model: 'Model'
};
const CellParams = { const CellParams = {
...Mesh.Params, ...Mesh.Params,
cellColor: PD.Color(ColorNames.orange), cellColor: PD.Color(ColorNames.orange),
cellScale: PD.Numeric(2, { min: 0.1, max: 5, step: 0.1 }) cellScale: PD.Numeric(2, { min: 0.1, max: 5, step: 0.1 }),
ref: PD.Select('model', PD.objectToOptions(CellRef), { isEssential: true })
}; };
type MeshParams = typeof CellParams type MeshParams = typeof CellParams
...@@ -98,11 +104,12 @@ function getUnitcellShape(ctx: RuntimeContext, data: UnitcellData, props: Unitce ...@@ -98,11 +104,12 @@ function getUnitcellShape(ctx: RuntimeContext, data: UnitcellData, props: Unitce
// //
export function getUnitcellData(model: Model, symmetry: Symmetry) { export function getUnitcellData(model: Model, symmetry: Symmetry, props: UnitcellProps) {
return { const ref = Vec3();
symmetry, if (props.ref === 'model') {
ref: Vec3.transformMat4(Vec3(), Model.getCenter(model), symmetry.spacegroup.cell.toFractional) Vec3.transformMat4(ref, Model.getCenter(model), symmetry.spacegroup.cell.toFractional);
}; }
return { symmetry, ref };
} }
export type UnitcellRepresentation = Representation<UnitcellData, UnitcellParams> export type UnitcellRepresentation = Representation<UnitcellData, UnitcellParams>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment