Quellcode durchsuchen

more geometry fixes & tweaks

Alexander Rose vor 6 Jahren
Ursprung
Commit
8c53848a01

+ 4 - 2
src/mol-geo/geometry/lines/lines.ts

@@ -157,8 +157,10 @@ export namespace Lines {
     }
 
     function updateBoundingSphere(values: LinesValues, lines: Lines) {
-        const { boundingSphere, invariantBoundingSphere } = getBoundingSphere(values.aStart.ref.value, values.aEnd.ref.value, lines.lineCount,
-            values.aTransform.ref.value, values.instanceCount.ref.value)
+        const { boundingSphere, invariantBoundingSphere } = getBoundingSphere(
+            values.aStart.ref.value, values.aEnd.ref.value, lines.lineCount,
+            values.aTransform.ref.value, values.instanceCount.ref.value
+        )
         if (!Sphere3D.equals(boundingSphere, values.boundingSphere.ref.value)) {
             ValueCell.update(values.boundingSphere, boundingSphere)
         }

+ 2 - 2
src/mol-geo/geometry/size-data.ts

@@ -11,7 +11,7 @@ import { LocationIterator } from '../util/location-iterator';
 import { Location, NullLocation } from 'mol-model/location';
 import { SizeTheme } from 'mol-theme/size';
 import { Geometry } from './geometry';
-import { encodeFloatLog } from 'mol-util/float-packing';
+import { encodeFloatLog, decodeFloatLog } from 'mol-util/float-packing';
 
 export type SizeType = 'uniform' | 'instance' | 'group' | 'groupInstance'
 
@@ -42,7 +42,7 @@ export function getMaxSize(sizeData: SizeData): number {
             let maxSize = 0
             const array = sizeData.tSize.ref.value.array
             for (let i = 0, il = array.length; i < il; ++i) {
-                const value = array[i]
+                const value = decodeFloatLog(array[i] / 255)
                 if (maxSize < value) maxSize = value
             }
             return maxSize

+ 1 - 0
src/mol-geo/geometry/spheres/spheres.ts

@@ -132,5 +132,6 @@ export namespace Spheres {
         if (!Sphere3D.equals(invariantBoundingSphere, values.invariantBoundingSphere.ref.value)) {
             ValueCell.update(values.invariantBoundingSphere, invariantBoundingSphere)
         }
+        ValueCell.update(values.padding, padding)
     }
 }

+ 1 - 1
src/mol-geo/geometry/text/font-atlas.ts

@@ -74,7 +74,7 @@ export class FontAtlas {
         this.props = p
 
         // create measurements
-        const fontSize = 32 * p.fontQuality
+        const fontSize = 32 * (p.fontQuality + 1)
         this.buffer = fontSize / 8
         this.radius = fontSize / 3
         this.lineHeight = Math.round(fontSize + 2 * this.buffer + this.radius)

+ 3 - 1
src/mol-geo/geometry/text/text-builder.ts

@@ -22,6 +22,8 @@ export interface TextBuilder {
 
 export namespace TextBuilder {
     export function create(props: Partial<PD.Values<Text.Params>> = {}, initialCount = 2048, chunkSize = 1024, text?: Text): TextBuilder {
+        initialCount *= 2
+        chunkSize *= 2
         const centers = ChunkedArray.create(Float32Array, 3, chunkSize, text ? text.centerBuffer.ref.value : initialCount);
         const mappings = ChunkedArray.create(Float32Array, 2, chunkSize, text ? text.mappingBuffer.ref.value : initialCount);
         const indices = ChunkedArray.create(Uint32Array, 3, chunkSize, text ? text.indexBuffer.ref.value : initialCount);
@@ -120,7 +122,7 @@ export namespace TextBuilder {
                 const ft = fontAtlas.texture
                 return {
                     kind: 'text',
-                    charCount: centers.elementCount / 4,
+                    charCount: indices.elementCount / 2,
                     fontTexture: text ? ValueCell.update(text.fontTexture, ft) : ValueCell.create(ft),
                     centerBuffer: text ? ValueCell.update(text.centerBuffer, cb) : ValueCell.create(cb),
                     mappingBuffer: text ? ValueCell.update(text.mappingBuffer, mb) : ValueCell.create(mb),

+ 23 - 8
src/mol-geo/geometry/text/text.ts

@@ -25,7 +25,11 @@ import { clamp } from 'mol-math/interpolate';
 import { createRenderObject as _createRenderObject } from 'mol-gl/render-object';
 import { BaseGeometry } from '../base';
 
-type TextAttachment = 'bottom-left' | 'bottom-center' | 'bottom-right' | 'middle-left' | 'middle-center' | 'middle-right' | 'top-left' | 'top-center' | 'top-right'
+type TextAttachment = (
+    'bottom-left' | 'bottom-center' | 'bottom-right' |
+    'middle-left' | 'middle-center' | 'middle-right' |
+    'top-left' | 'top-center' | 'top-right'
+)
 
 /** Text */
 export interface Text {
@@ -83,7 +87,11 @@ export namespace Text {
         backgroundColor: PD.Color(ColorNames.grey),
         backgroundOpacity: PD.Numeric(1, { min: 0, max: 1, step: 0.01 }),
 
-        attachment: PD.Select('normal', [['bottom-left', 'bottom-left'], ['bottom-center', 'bottom-center'], ['bottom-right', 'bottom-right'], ['middle-left', 'middle-left'], ['top-left', 'top-left'], ['top-center', 'top-center'], ['top-right', 'top-right']] as [TextAttachment, string][]),
+        attachment: PD.Select('middle-center', [
+            ['bottom-left', 'bottom-left'], ['bottom-center', 'bottom-center'], ['bottom-right', 'bottom-right'],
+            ['middle-left', 'middle-left'], ['middle-center', 'middle-center'], ['middle-right', 'middle-right'],
+            ['top-left', 'top-left'], ['top-center', 'top-center'], ['top-right', 'top-right'],
+        ] as [TextAttachment, string][]),
     }
     export type Params = typeof Params
 
@@ -96,7 +104,6 @@ export namespace Text {
         updateBoundingSphere,
         createRenderableState,
         updateRenderableState,
-        // createRenderObject
     }
 
     function createValues(text: Text, transform: TransformData, locationIt: LocationIterator, theme: Theme, props: PD.Values<Params>): TextValues {
@@ -111,7 +118,7 @@ export namespace Text {
 
         const counts = { drawCount: text.charCount * 2 * 3, groupCount, instanceCount }
 
-        const padding = getMaxSize(size)
+        const padding = getPadding(text.mappingBuffer.ref.value, text.charCount, getMaxSize(size))
         const { boundingSphere, invariantBoundingSphere } = calculateBoundingSphere(
             text.centerBuffer.ref.value, text.charCount * 4,
             transform.aTransform.ref.value, instanceCount, padding
@@ -158,7 +165,7 @@ export namespace Text {
     }
 
     function updateBoundingSphere(values: TextValues, text: Text) {
-        const padding = getMaxSize(values)
+        const padding = getPadding(values.aMapping.ref.value, text.charCount, getMaxSize(values))
         const { boundingSphere, invariantBoundingSphere } = calculateBoundingSphere(
             values.aPosition.ref.value, text.charCount * 4,
             values.aTransform.ref.value, values.instanceCount.ref.value, padding
@@ -169,6 +176,7 @@ export namespace Text {
         if (!Sphere3D.equals(invariantBoundingSphere, values.invariantBoundingSphere.ref.value)) {
             ValueCell.update(values.invariantBoundingSphere, invariantBoundingSphere)
         }
+        ValueCell.update(values.padding, padding)
     }
 
     function createRenderableState(props: PD.Values<Params>): RenderableState {
@@ -181,8 +189,15 @@ export namespace Text {
         BaseGeometry.updateRenderableState(state, props)
         state.opaque = false
     }
+}
 
-    // function createRenderObject(values: TextValues, state: RenderableState) {
-    //     return _createRenderObject('text', values, state)
-    // }
+function getPadding(mapping: Float32Array, charCount: number, maxSize: number) {
+    let maxOffset = 0
+    for (let i = 0, il = charCount * 4; i < il; ++i) {
+        const ox = Math.abs(mapping[i])
+        if (ox > maxOffset) maxOffset = ox
+        const oy = Math.abs(mapping[i + 1])
+        if (oy > maxOffset) maxOffset = oy
+    }
+    return maxSize + maxSize * maxOffset
 }