Browse Source

shape loci bounding sphere for points and text geo

Alexander Rose 5 years ago
parent
commit
974a7d7520

+ 15 - 1
src/mol-geo/geometry/points/points.ts

@@ -6,7 +6,9 @@
 
 import { ValueCell } from '../../../mol-util'
 import { Mat4 } from '../../../mol-math/linear-algebra'
-import { transformPositionArray/* , transformDirectionArray, getNormalMatrix */ } from '../../util';
+import { transformPositionArray,/* , transformDirectionArray, getNormalMatrix */
+GroupMapping,
+createGroupMapping} from '../../util';
 import { GeometryUtils } from '../geometry';
 import { createColors } from '../color-data';
 import { createMarkers } from '../marker-data';
@@ -39,6 +41,8 @@ export interface Points {
 
     /** Bounding sphere of the points */
     readonly boundingSphere: Sphere3D
+    /** Maps group ids to point indices */
+    readonly groupMapping: GroupMapping
 }
 
 export namespace Points {
@@ -63,7 +67,10 @@ export namespace Points {
     function fromArrays(centers: Float32Array, groups: Float32Array, pointCount: number): Points {
 
         const boundingSphere = Sphere3D()
+        let groupMapping: GroupMapping
+
         let currentHash = -1
+        let currentGroup = -1
 
         const points = {
             kind: 'points' as const,
@@ -79,6 +86,13 @@ export namespace Points {
                 }
                 return boundingSphere
             },
+            get groupMapping() {
+                if (points.groupBuffer.ref.version !== currentGroup) {
+                    groupMapping = createGroupMapping(points.groupBuffer.ref.value, points.pointCount)
+                    currentGroup = points.groupBuffer.ref.version
+                }
+                return groupMapping
+            }
         }
         return points
     }

+ 13 - 0
src/mol-geo/geometry/text/text.ts

@@ -27,6 +27,7 @@ import { BaseGeometry } from '../base';
 import { createEmptyOverpaint } from '../overpaint-data';
 import { createEmptyTransparency } from '../transparency-data';
 import { hashFnv32a } from '../../../mol-data/util';
+import { GroupMapping, createGroupMapping } from '../../util';
 
 type TextAttachment = (
     'bottom-left' | 'bottom-center' | 'bottom-right' |
@@ -59,6 +60,8 @@ export interface Text {
 
     /** Bounding sphere of the text */
     readonly boundingSphere: Sphere3D
+    /** Maps group ids to text indices */
+    readonly groupMapping: GroupMapping
 }
 
 export namespace Text {
@@ -91,7 +94,10 @@ export namespace Text {
     function fromData(fontTexture: TextureImage<Uint8Array>, centers: Float32Array, mappings: Float32Array, depths: Float32Array, indices: Uint32Array, groups: Float32Array, tcoords: Float32Array, charCount: number): Text {
 
         const boundingSphere = Sphere3D()
+        let groupMapping: GroupMapping
+
         let currentHash = -1
+        let currentGroup = -1
 
         const text = {
             kind: 'text' as const,
@@ -112,6 +118,13 @@ export namespace Text {
                 }
                 return boundingSphere
             },
+            get groupMapping() {
+                if (text.groupBuffer.ref.version !== currentGroup) {
+                    groupMapping = createGroupMapping(text.groupBuffer.ref.value, text.charCount, 4)
+                    currentGroup = text.groupBuffer.ref.version
+                }
+                return groupMapping
+            }
         }
         return text
     }

+ 6 - 4
src/mol-model/shape/shape.ts

@@ -149,8 +149,10 @@ export namespace ShapeGroup {
 
         const { geometry, transforms } = loci.shape
 
-        if (geometry.kind === 'mesh') {
-            const positions = geometry.vertexBuffer.ref.value
+        if (geometry.kind === 'mesh' || geometry.kind === 'points') {
+            const positions = geometry.kind === 'mesh'
+                ? geometry.vertexBuffer.ref.value
+                : geometry.centerBuffer.ref.value
             sphereHelperInclude(loci.groups, geometry.groupMapping, positions, transforms)
             sphereHelper.finishedIncludeStep()
             sphereHelperRadius(loci.groups, geometry.groupMapping, positions, transforms)
@@ -162,7 +164,7 @@ export namespace ShapeGroup {
             sphereHelper.finishedIncludeStep()
             sphereHelperRadius(loci.groups, geometry.groupMapping, start, transforms)
             sphereHelperRadius(loci.groups, geometry.groupMapping, end, transforms)
-        } else if (geometry.kind === 'spheres') {
+        } else if (geometry.kind === 'spheres' || geometry.kind === 'text') {
             const positions = geometry.centerBuffer.ref.value
             sphereHelperInclude(loci.groups, geometry.groupMapping, positions, transforms)
             sphereHelper.finishedIncludeStep()
@@ -174,7 +176,7 @@ export namespace ShapeGroup {
                 })
             }
         } else {
-            // TODO implement for other geometry kinds
+            // use whole shape bounding-sphere for other geometry kinds
             return Sphere3D.copy(boundingSphere, geometry.boundingSphere)
         }