فهرست منبع

keep some original data after mesh processing

- processing in uniformTriangleGroup
- to be used in, e.g., geometry export
Alexander Rose 3 سال پیش
والد
کامیت
d96303627c

+ 14 - 2
src/mol-geo/geometry/mesh/mesh.ts

@@ -50,7 +50,7 @@ export interface Mesh {
 
     setBoundingSphere(boundingSphere: Sphere3D): void
 
-    meta?: unknown
+    readonly meta: { [k: string]: unknown }
 }
 
 export namespace Mesh {
@@ -111,7 +111,8 @@ export namespace Mesh {
             setBoundingSphere(sphere: Sphere3D) {
                 Sphere3D.copy(boundingSphere, sphere);
                 currentHash = hashCode(mesh);
-            }
+            },
+            meta: {}
         };
         return mesh;
     }
@@ -176,6 +177,12 @@ export namespace Mesh {
         ValueCell.update(mesh.vertexBuffer, v);
     }
 
+    type OriginalData = {
+        indexBuffer: Uint32Array
+        vertexCount: number
+        triangleCount: number
+    }
+
     /**
      * Ensure that each vertices of each triangle have the same group id.
      * Note that normals are copied over and can't be re-created from the new mesh.
@@ -324,6 +331,9 @@ export namespace Mesh {
         ValueCell.update(indexBuffer, newIb) as ValueCell<Uint32Array>;
         ValueCell.update(normalBuffer, newNb) as ValueCell<Float32Array>;
 
+        // keep some original data, e.g., for geometry export
+        (mesh.meta.originalData as OriginalData) = { indexBuffer: ib, vertexCount, triangleCount };
+
         return mesh;
     }
 
@@ -408,6 +418,8 @@ export namespace Mesh {
             dFlipSided: ValueCell.create(props.flipSided),
             dIgnoreLight: ValueCell.create(props.ignoreLight),
             dXrayShaded: ValueCell.create(props.xrayShaded),
+
+            meta: ValueCell.create(mesh.meta),
         };
     }
 

+ 2 - 1
src/mol-gl/renderable/mesh.ts

@@ -7,7 +7,7 @@
 import { Renderable, RenderableState, createRenderable } from '../renderable';
 import { WebGLContext } from '../webgl/context';
 import { createGraphicsRenderItem } from '../webgl/render-item';
-import { GlobalUniformSchema, BaseSchema, AttributeSpec, ElementsSpec, DefineSpec, Values, InternalSchema, InternalValues, GlobalTextureSchema } from './schema';
+import { GlobalUniformSchema, BaseSchema, AttributeSpec, ElementsSpec, DefineSpec, Values, InternalSchema, InternalValues, GlobalTextureSchema, ValueSpec } from './schema';
 import { MeshShaderCode } from '../shader-code';
 import { ValueCell } from '../../mol-util';
 
@@ -22,6 +22,7 @@ export const MeshSchema = {
     dFlipSided: DefineSpec('boolean'),
     dIgnoreLight: DefineSpec('boolean'),
     dXrayShaded: DefineSpec('boolean'),
+    meta: ValueSpec('any')
 } as const;
 export type MeshSchema = typeof MeshSchema
 export type MeshValues = Values<MeshSchema>

+ 4 - 4
src/mol-repr/structure/visual/gaussian-surface-mesh.ts

@@ -93,7 +93,7 @@ async function createGaussianSurfaceMesh(ctx: VisualContext, unit: Unit, structu
         idField
     };
     const surface = await computeMarchingCubesMesh(params, mesh).runAsChild(ctx.runtime);
-    (surface.meta as GaussianSurfaceMeta) = { resolution };
+    (surface.meta.resolution as GaussianSurfaceMeta['resolution']) = resolution;
 
     Mesh.transform(surface, transform);
     if (ctx.webgl && !ctx.webgl.isWebGL2) Mesh.uniformTriangleGroup(surface, false);
@@ -133,7 +133,7 @@ export function GaussianSurfaceMeshVisual(materialId: number): UnitsVisual<Gauss
             const csp = getColorSmoothingProps(props, theme, resolution, webgl);
             if (csp) {
                 applyMeshColorSmoothing(values, csp.resolution, csp.stride, csp.webgl, colorTexture);
-                (geometry.meta as GaussianSurfaceMeta).colorTexture = values.tColorGrid.ref.value;
+                (geometry.meta.colorTexture as GaussianSurfaceMeta['colorTexture']) = values.tColorGrid.ref.value;
             }
         },
         dispose: (geometry: Mesh) => {
@@ -154,7 +154,7 @@ async function createStructureGaussianSurfaceMesh(ctx: VisualContext, structure:
         idField
     };
     const surface = await computeMarchingCubesMesh(params, mesh).runAsChild(ctx.runtime);
-    (surface.meta as GaussianSurfaceMeta) = { resolution };
+    (surface.meta.resolution as GaussianSurfaceMeta['resolution']) = resolution;
 
     Mesh.transform(surface, transform);
     if (ctx.webgl && !ctx.webgl.isWebGL2) Mesh.uniformTriangleGroup(surface, false);
@@ -193,7 +193,7 @@ export function StructureGaussianSurfaceMeshVisual(materialId: number): ComplexV
             const csp = getColorSmoothingProps(props, theme, resolution, webgl);
             if (csp) {
                 applyMeshColorSmoothing(values, csp.resolution, csp.stride, csp.webgl, colorTexture);
-                (geometry.meta as GaussianSurfaceMeta).colorTexture = values.tColorGrid.ref.value;
+                (geometry.meta.colorTexture as GaussianSurfaceMeta['colorTexture']) = values.tColorGrid.ref.value;
             }
         },
         dispose: (geometry: Mesh) => {

+ 2 - 2
src/mol-repr/structure/visual/molecular-surface-mesh.ts

@@ -52,7 +52,7 @@ async function createMolecularSurfaceMesh(ctx: VisualContext, unit: Unit, struct
 
     const sphere = Sphere3D.expand(Sphere3D(), unit.boundary.sphere, props.probeRadius + getUnitExtraRadius(unit));
     surface.setBoundingSphere(sphere);
-    (surface.meta as MolecularSurfaceMeta) = { resolution };
+    (surface.meta.resolution as MolecularSurfaceMeta['resolution']) = resolution;
 
     return surface;
 }
@@ -83,7 +83,7 @@ export function MolecularSurfaceMeshVisual(materialId: number): UnitsVisual<Mole
             const csp = getColorSmoothingProps(props, theme, resolution, webgl);
             if (csp) {
                 applyMeshColorSmoothing(values, csp.resolution, csp.stride, csp.webgl, colorTexture);
-                (geometry.meta as MolecularSurfaceMeta).colorTexture = values.tColorGrid.ref.value;
+                (geometry.meta.colorTexture as MolecularSurfaceMeta['colorTexture']) = values.tColorGrid.ref.value;
             }
         },
         dispose: (geometry: Mesh) => {