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

add isComplex flag to location-iterator to handle multiple units per instance

parent a0e32005
No related branches found
No related tags found
No related merge requests found
...@@ -156,24 +156,24 @@ export async function StructureView(viewer: Viewer, models: ReadonlyArray<Model> ...@@ -156,24 +156,24 @@ export async function StructureView(viewer: Viewer, models: ReadonlyArray<Model>
async function createStructureRepr() { async function createStructureRepr() {
if (structure) { if (structure) {
console.log('createStructureRepr') console.log('createStructureRepr')
// await cartoon.createOrUpdate({ await cartoon.createOrUpdate({
// colorTheme: { name: 'unit-index' },
// sizeTheme: { name: 'uniform', value: 0.2 },
// useFog: false // TODO fog not working properly
// }, structure).run()
await point.createOrUpdate({
colorTheme: { name: 'unit-index' }, colorTheme: { name: 'unit-index' },
sizeTheme: { name: 'uniform', value: 0.2 }, sizeTheme: { name: 'uniform', value: 0.2 },
useFog: false // TODO fog not working properly useFog: false // TODO fog not working properly
}, structure).run() }, structure).run()
// await ballAndStick.createOrUpdate({ // await point.createOrUpdate({
// colorTheme: { name: 'unit-index' }, // colorTheme: { name: 'unit-index' },
// sizeTheme: { name: 'uniform', value: 0.1 }, // sizeTheme: { name: 'uniform', value: 0.2 },
// useFog: false // TODO fog not working properly // useFog: false // TODO fog not working properly
// }, structure).run() // }, structure).run()
await ballAndStick.createOrUpdate({
colorTheme: { name: 'unit-index' },
sizeTheme: { name: 'uniform', value: 0.1 },
useFog: false // TODO fog not working properly
}, structure).run()
// await carbohydrate.createOrUpdate({ // await carbohydrate.createOrUpdate({
// colorTheme: { name: 'carbohydrate-symbol' }, // colorTheme: { name: 'carbohydrate-symbol' },
// sizeTheme: { name: 'uniform', value: 1, factor: 1 }, // sizeTheme: { name: 'uniform', value: 1, factor: 1 },
......
...@@ -44,17 +44,18 @@ export function ComplexMeshVisual<P extends ComplexMeshProps>(builder: ComplexMe ...@@ -44,17 +44,18 @@ export function ComplexMeshVisual<P extends ComplexMeshProps>(builder: ComplexMe
let mesh: Mesh let mesh: Mesh
let currentStructure: Structure let currentStructure: Structure
let locationIt: LocationIterator let locationIt: LocationIterator
let conformationHashCode: number let conformationHash: number
async function create(ctx: RuntimeContext, structure: Structure, props: Partial<P> = {}) { async function create(ctx: RuntimeContext, structure: Structure, props: Partial<P> = {}) {
currentProps = Object.assign({}, defaultProps, props) currentProps = Object.assign({}, defaultProps, props)
currentStructure = structure currentStructure = structure
conformationHashCode = Structure.conformationHash(currentStructure) conformationHash = Structure.conformationHash(currentStructure)
mesh = await createMesh(ctx, currentStructure, currentProps, mesh) mesh = await createMesh(ctx, currentStructure, currentProps, mesh)
locationIt = createLocationIterator(structure) locationIt = createLocationIterator(structure)
renderObject = await createComplexMeshRenderObject(ctx, structure, mesh, locationIt, currentProps) renderObject = await createComplexMeshRenderObject(ctx, structure, mesh, locationIt, currentProps)
console.log(renderObject.values)
} }
async function update(ctx: RuntimeContext, props: Partial<P>) { async function update(ctx: RuntimeContext, props: Partial<P>) {
...@@ -66,9 +67,9 @@ export function ComplexMeshVisual<P extends ComplexMeshProps>(builder: ComplexMe ...@@ -66,9 +67,9 @@ export function ComplexMeshVisual<P extends ComplexMeshProps>(builder: ComplexMe
MeshUpdateState.reset(updateState) MeshUpdateState.reset(updateState)
setUpdateState(updateState, newProps, currentProps) setUpdateState(updateState, newProps, currentProps)
const newConformationHashCode = Structure.conformationHash(currentStructure) const newConformationHash = Structure.conformationHash(currentStructure)
if (newConformationHashCode !== conformationHashCode) { if (newConformationHash !== conformationHash) {
conformationHashCode = newConformationHashCode conformationHash = newConformationHash
updateState.createMesh = true updateState.createMesh = true
} }
......
...@@ -61,7 +61,6 @@ export function UnitsMeshVisual<P extends UnitsMeshProps>(builder: UnitsMeshVisu ...@@ -61,7 +61,6 @@ export function UnitsMeshVisual<P extends UnitsMeshProps>(builder: UnitsMeshVisu
// TODO create empty location iterator when not in unitKinds // TODO create empty location iterator when not in unitKinds
locationIt = createLocationIterator(group) locationIt = createLocationIterator(group)
renderObject = await createUnitsMeshRenderObject(ctx, group, mesh, locationIt, currentProps) renderObject = await createUnitsMeshRenderObject(ctx, group, mesh, locationIt, currentProps)
console.log(renderObject.values.uInstanceCount.ref.value, renderObject.values.uGroupCount.ref.value)
} }
async function update(ctx: RuntimeContext, props: Partial<P> = {}) { async function update(ctx: RuntimeContext, props: Partial<P> = {}) {
......
...@@ -100,7 +100,7 @@ function CarbohydrateLinkIterator(structure: Structure): LocationIterator { ...@@ -100,7 +100,7 @@ function CarbohydrateLinkIterator(structure: Structure): LocationIterator {
location.bIndex = indexB as StructureElement.UnitIndex location.bIndex = indexB as StructureElement.UnitIndex
return location return location
} }
return LocationIterator(groupCount, instanceCount, getLocation) return LocationIterator(groupCount, instanceCount, getLocation, true)
} }
function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) { function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) {
......
...@@ -172,7 +172,7 @@ function CarbohydrateElementIterator(structure: Structure): LocationIterator { ...@@ -172,7 +172,7 @@ function CarbohydrateElementIterator(structure: Structure): LocationIterator {
function isSecondary (elementIndex: number, instanceIndex: number) { function isSecondary (elementIndex: number, instanceIndex: number) {
return (elementIndex % 2) === 1 return (elementIndex % 2) === 1
} }
return LocationIterator(groupCount, instanceCount, getLocation, isSecondary) return LocationIterator(groupCount, instanceCount, getLocation, true, isSecondary)
} }
function getCarbohydrateLoci(pickingId: PickingId, structure: Structure, id: number) { function getCarbohydrateLoci(pickingId: PickingId, structure: Structure, id: number) {
......
...@@ -84,7 +84,7 @@ function CrossLinkRestraintIterator(structure: Structure): LocationIterator { ...@@ -84,7 +84,7 @@ function CrossLinkRestraintIterator(structure: Structure): LocationIterator {
location.bIndex = pair.indexB location.bIndex = pair.indexB
return location return location
} }
return LocationIterator(groupCount, instanceCount, getLocation) return LocationIterator(groupCount, instanceCount, getLocation, true)
} }
function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) { function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) {
......
...@@ -26,7 +26,9 @@ import { TransformData, createIdentityTransform, createTransforms } from '../../ ...@@ -26,7 +26,9 @@ import { TransformData, createIdentityTransform, createTransforms } from '../../
export function createColors(ctx: RuntimeContext, locationIt: LocationIterator, props: ColorThemeProps, colorData?: ColorData): Promise<ColorData> { export function createColors(ctx: RuntimeContext, locationIt: LocationIterator, props: ColorThemeProps, colorData?: ColorData): Promise<ColorData> {
const colorTheme = ColorTheme(props) const colorTheme = ColorTheme(props)
switch (colorTheme.kind) { // Always use 'group' kind for 'complex' location iterators, i.e. an instance may include multiple units
const kind = colorTheme.kind === 'instance' && locationIt.isComplex ? 'group' : colorTheme.kind
switch (kind) {
case 'uniform': return createUniformColor(ctx, locationIt, colorTheme.color, colorData) case 'uniform': return createUniformColor(ctx, locationIt, colorTheme.color, colorData)
case 'group': return createGroupColor(ctx, locationIt, colorTheme.color, colorData) case 'group': return createGroupColor(ctx, locationIt, colorTheme.color, colorData)
case 'groupInstance': return createGroupInstanceColor(ctx, locationIt, colorTheme.color, colorData) case 'groupInstance': return createGroupInstanceColor(ctx, locationIt, colorTheme.color, colorData)
......
...@@ -146,6 +146,6 @@ export namespace LinkIterator { ...@@ -146,6 +146,6 @@ export namespace LinkIterator {
location.bIndex = bond.indexB as StructureElement.UnitIndex location.bIndex = bond.indexB as StructureElement.UnitIndex
return location return location
} }
return LocationIterator(groupCount, instanceCount, getLocation) return LocationIterator(groupCount, instanceCount, getLocation, true)
} }
} }
\ No newline at end of file
...@@ -28,6 +28,8 @@ export interface LocationIterator extends Iterator<LocationValue> { ...@@ -28,6 +28,8 @@ export interface LocationIterator extends Iterator<LocationValue> {
readonly isNextNewInstance: boolean readonly isNextNewInstance: boolean
readonly groupCount: number readonly groupCount: number
readonly instanceCount: number readonly instanceCount: number
/** If true, may have multiple units per instance; if false one unit per instance */
readonly isComplex: boolean
move(): LocationValue move(): LocationValue
reset(): void reset(): void
skipInstance(): void skipInstance(): void
...@@ -36,7 +38,7 @@ export interface LocationIterator extends Iterator<LocationValue> { ...@@ -36,7 +38,7 @@ export interface LocationIterator extends Iterator<LocationValue> {
type LocationGetter = (groupIndex: number, instanceIndex: number) => Location type LocationGetter = (groupIndex: number, instanceIndex: number) => Location
type IsSecondaryGetter = (groupIndex: number, instanceIndex: number) => boolean type IsSecondaryGetter = (groupIndex: number, instanceIndex: number) => boolean
export function LocationIterator(groupCount: number, instanceCount: number, getLocation: LocationGetter, isSecondary: IsSecondaryGetter = () => false): LocationIterator { export function LocationIterator(groupCount: number, instanceCount: number, getLocation: LocationGetter, isComplex = false, isSecondary: IsSecondaryGetter = () => false): LocationIterator {
const value: LocationValue = { const value: LocationValue = {
location: NullLocation as Location, location: NullLocation as Location,
index: 0, index: 0,
...@@ -55,6 +57,7 @@ export function LocationIterator(groupCount: number, instanceCount: number, getL ...@@ -55,6 +57,7 @@ export function LocationIterator(groupCount: number, instanceCount: number, getL
get isNextNewInstance () { return isNextNewInstance }, get isNextNewInstance () { return isNextNewInstance },
get groupCount () { return groupCount }, get groupCount () { return groupCount },
get instanceCount () { return instanceCount }, get instanceCount () { return instanceCount },
isComplex,
move() { move() {
if (hasNext) { if (hasNext) {
value.groupIndex = groupIndex value.groupIndex = groupIndex
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment