gaussian-surface-mesh.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /**
  2. * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { ParamDefinition as PD } from '../../../mol-util/param-definition';
  7. import { UnitsMeshParams, UnitsTextureMeshParams, UnitsVisual, UnitsMeshVisual, UnitsTextureMeshVisual } from '../units-visual';
  8. import { GaussianDensityParams, computeUnitGaussianDensity, computeUnitGaussianDensityTexture2d, GaussianDensityProps, computeStructureGaussianDensity, computeStructureGaussianDensityTexture2d } from './util/gaussian';
  9. import { VisualContext } from '../../visual';
  10. import { Unit, Structure } from '../../../mol-model/structure';
  11. import { Theme } from '../../../mol-theme/theme';
  12. import { Mesh } from '../../../mol-geo/geometry/mesh/mesh';
  13. import { computeMarchingCubesMesh } from '../../../mol-geo/util/marching-cubes/algorithm';
  14. import { ElementIterator, getElementLoci, eachElement, getSerialElementLoci, eachSerialElement } from './util/element';
  15. import { VisualUpdateState } from '../../util';
  16. import { TextureMesh } from '../../../mol-geo/geometry/texture-mesh/texture-mesh';
  17. import { extractIsosurface } from '../../../mol-gl/compute/marching-cubes/isosurface';
  18. import { Sphere3D } from '../../../mol-math/geometry';
  19. import { ComplexVisual, ComplexMeshParams, ComplexMeshVisual, ComplexTextureMeshVisual, ComplexTextureMeshParams } from '../complex-visual';
  20. import { getVolumeSliceInfo, StructureGroup } from './util/common';
  21. import { WebGLContext } from '../../../mol-gl/webgl/context';
  22. import { MeshValues } from '../../../mol-gl/renderable/mesh';
  23. import { TextureMeshValues } from '../../../mol-gl/renderable/texture-mesh';
  24. import { Texture } from '../../../mol-gl/webgl/texture';
  25. import { applyMeshColorSmoothing } from '../../../mol-geo/geometry/mesh/color-smoothing';
  26. import { applyTextureMeshColorSmoothing } from '../../../mol-geo/geometry/texture-mesh/color-smoothing';
  27. import { ColorSmoothingParams, getColorSmoothingProps } from '../../../mol-geo/geometry/base';
  28. import { Vec3 } from '../../../mol-math/linear-algebra';
  29. import { isTimingMode } from '../../../mol-util/debug';
  30. import { ValueCell } from '../../../mol-util/value-cell';
  31. const SharedParams = {
  32. ...GaussianDensityParams,
  33. ...ColorSmoothingParams,
  34. ignoreHydrogens: PD.Boolean(false),
  35. tryUseGpu: PD.Boolean(true),
  36. includeParent: PD.Boolean(false, { isHidden: true }),
  37. };
  38. type SharedParams = typeof SharedParams
  39. export const GaussianSurfaceMeshParams = {
  40. ...UnitsMeshParams,
  41. ...UnitsTextureMeshParams,
  42. ...SharedParams,
  43. };
  44. export type GaussianSurfaceMeshParams = typeof GaussianSurfaceMeshParams
  45. export const StructureGaussianSurfaceMeshParams = {
  46. ...ComplexMeshParams,
  47. ...ComplexTextureMeshParams,
  48. ...SharedParams,
  49. };
  50. export type StructureGaussianSurfaceMeshParams = typeof StructureGaussianSurfaceMeshParams
  51. function gpuSupport(webgl: WebGLContext) {
  52. return webgl.extensions.colorBufferFloat && webgl.extensions.textureFloat && webgl.extensions.blendMinMax && webgl.extensions.drawBuffers;
  53. }
  54. function suitableForGpu(structure: Structure, props: PD.Values<SharedParams>, webgl: WebGLContext) {
  55. // lower resolutions are about as fast on CPU vs integrated GPU,
  56. // very low resolutions have artifacts when calculated on GPU
  57. if (props.resolution > 1) return false;
  58. // the GPU is much more memory contraint, especially true for integrated GPUs,
  59. // being conservative here still allows for small and medium sized assemblies
  60. const d = webgl.maxTextureSize / 3;
  61. const { areaCells, maxAreaCells } = getVolumeSliceInfo(structure.boundary.box, props.resolution, d * d);
  62. return areaCells < maxAreaCells;
  63. }
  64. export function GaussianSurfaceVisual(materialId: number, structure: Structure, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) {
  65. if (props.tryUseGpu && webgl && gpuSupport(webgl) && suitableForGpu(structure, props, webgl)) {
  66. return GaussianSurfaceTextureMeshVisual(materialId);
  67. }
  68. return GaussianSurfaceMeshVisual(materialId);
  69. }
  70. export function StructureGaussianSurfaceVisual(materialId: number, structure: Structure, props: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) {
  71. if (props.tryUseGpu && webgl && gpuSupport(webgl) && suitableForGpu(structure, props, webgl)) {
  72. return StructureGaussianSurfaceTextureMeshVisual(materialId);
  73. }
  74. return StructureGaussianSurfaceMeshVisual(materialId);
  75. }
  76. type GaussianSurfaceMeta = {
  77. resolution?: number
  78. colorTexture?: Texture
  79. }
  80. //
  81. async function createGaussianSurfaceMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: GaussianDensityProps, mesh?: Mesh): Promise<Mesh> {
  82. const { smoothness } = props;
  83. const { transform, field, idField, radiusFactor, resolution, maxRadius } = await computeUnitGaussianDensity(structure, unit, theme.size, props).runInContext(ctx.runtime);
  84. const params = {
  85. isoLevel: Math.exp(-smoothness) / radiusFactor,
  86. scalarField: field,
  87. idField
  88. };
  89. const surface = await computeMarchingCubesMesh(params, mesh).runAsChild(ctx.runtime);
  90. (surface.meta.resolution as GaussianSurfaceMeta['resolution']) = resolution;
  91. Mesh.transform(surface, transform);
  92. if (ctx.webgl && !ctx.webgl.isWebGL2) {
  93. Mesh.uniformTriangleGroup(surface);
  94. ValueCell.updateIfChanged(surface.varyingGroup, false);
  95. } else {
  96. ValueCell.updateIfChanged(surface.varyingGroup, true);
  97. }
  98. const sphere = Sphere3D.expand(Sphere3D(), unit.boundary.sphere, maxRadius);
  99. surface.setBoundingSphere(sphere);
  100. return surface;
  101. }
  102. export function GaussianSurfaceMeshVisual(materialId: number): UnitsVisual<GaussianSurfaceMeshParams> {
  103. return UnitsMeshVisual<GaussianSurfaceMeshParams>({
  104. defaultProps: PD.getDefaultValues(GaussianSurfaceMeshParams),
  105. createGeometry: createGaussianSurfaceMesh,
  106. createLocationIterator: ElementIterator.fromGroup,
  107. getLoci: getElementLoci,
  108. eachLocation: eachElement,
  109. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<GaussianSurfaceMeshParams>, currentProps: PD.Values<GaussianSurfaceMeshParams>) => {
  110. if (newProps.resolution !== currentProps.resolution) state.createGeometry = true;
  111. if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true;
  112. if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true;
  113. if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true;
  114. if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
  115. if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true;
  116. if (newProps.smoothColors.name !== currentProps.smoothColors.name) {
  117. state.updateColor = true;
  118. } else if (newProps.smoothColors.name === 'on' && currentProps.smoothColors.name === 'on') {
  119. if (newProps.smoothColors.params.resolutionFactor !== currentProps.smoothColors.params.resolutionFactor) state.updateColor = true;
  120. if (newProps.smoothColors.params.sampleStride !== currentProps.smoothColors.params.sampleStride) state.updateColor = true;
  121. }
  122. },
  123. mustRecreate: (structureGroup: StructureGroup, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
  124. return props.tryUseGpu && !!webgl && suitableForGpu(structureGroup.structure, props, webgl);
  125. },
  126. processValues: (values: MeshValues, geometry: Mesh, props: PD.Values<GaussianSurfaceMeshParams>, theme: Theme, webgl?: WebGLContext) => {
  127. const { resolution, colorTexture } = geometry.meta as GaussianSurfaceMeta;
  128. const csp = getColorSmoothingProps(props.smoothColors, theme.color.preferSmoothing, resolution);
  129. if (csp) {
  130. applyMeshColorSmoothing(values, csp.resolution, csp.stride, webgl, colorTexture);
  131. (geometry.meta.colorTexture as GaussianSurfaceMeta['colorTexture']) = values.tColorGrid.ref.value;
  132. }
  133. },
  134. dispose: (geometry: Mesh) => {
  135. (geometry.meta as GaussianSurfaceMeta).colorTexture?.destroy();
  136. }
  137. }, materialId);
  138. }
  139. //
  140. async function createStructureGaussianSurfaceMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: GaussianDensityProps, mesh?: Mesh): Promise<Mesh> {
  141. const { smoothness } = props;
  142. const { transform, field, idField, radiusFactor, resolution, maxRadius } = await computeStructureGaussianDensity(structure, theme.size, props).runInContext(ctx.runtime);
  143. const params = {
  144. isoLevel: Math.exp(-smoothness) / radiusFactor,
  145. scalarField: field,
  146. idField
  147. };
  148. const surface = await computeMarchingCubesMesh(params, mesh).runAsChild(ctx.runtime);
  149. (surface.meta.resolution as GaussianSurfaceMeta['resolution']) = resolution;
  150. Mesh.transform(surface, transform);
  151. if (ctx.webgl && !ctx.webgl.isWebGL2) {
  152. Mesh.uniformTriangleGroup(surface);
  153. ValueCell.updateIfChanged(surface.varyingGroup, false);
  154. } else {
  155. ValueCell.updateIfChanged(surface.varyingGroup, true);
  156. }
  157. const sphere = Sphere3D.expand(Sphere3D(), structure.boundary.sphere, maxRadius);
  158. surface.setBoundingSphere(sphere);
  159. return surface;
  160. }
  161. export function StructureGaussianSurfaceMeshVisual(materialId: number): ComplexVisual<StructureGaussianSurfaceMeshParams> {
  162. return ComplexMeshVisual<StructureGaussianSurfaceMeshParams>({
  163. defaultProps: PD.getDefaultValues(StructureGaussianSurfaceMeshParams),
  164. createGeometry: createStructureGaussianSurfaceMesh,
  165. createLocationIterator: ElementIterator.fromStructure,
  166. getLoci: getSerialElementLoci,
  167. eachLocation: eachSerialElement,
  168. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<GaussianSurfaceMeshParams>, currentProps: PD.Values<GaussianSurfaceMeshParams>) => {
  169. if (newProps.resolution !== currentProps.resolution) state.createGeometry = true;
  170. if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true;
  171. if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true;
  172. if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true;
  173. if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
  174. if (newProps.smoothColors.name !== currentProps.smoothColors.name) {
  175. state.updateColor = true;
  176. } else if (newProps.smoothColors.name === 'on' && currentProps.smoothColors.name === 'on') {
  177. if (newProps.smoothColors.params.resolutionFactor !== currentProps.smoothColors.params.resolutionFactor) state.updateColor = true;
  178. if (newProps.smoothColors.params.sampleStride !== currentProps.smoothColors.params.sampleStride) state.updateColor = true;
  179. }
  180. },
  181. mustRecreate: (structure: Structure, props: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
  182. return props.tryUseGpu && !!webgl && suitableForGpu(structure, props, webgl);
  183. },
  184. processValues: (values: MeshValues, geometry: Mesh, props: PD.Values<GaussianSurfaceMeshParams>, theme: Theme, webgl?: WebGLContext) => {
  185. const { resolution, colorTexture } = geometry.meta as GaussianSurfaceMeta;
  186. const csp = getColorSmoothingProps(props.smoothColors, theme.color.preferSmoothing, resolution);
  187. if (csp) {
  188. applyMeshColorSmoothing(values, csp.resolution, csp.stride, webgl, colorTexture);
  189. (geometry.meta.colorTexture as GaussianSurfaceMeta['colorTexture']) = values.tColorGrid.ref.value;
  190. }
  191. },
  192. dispose: (geometry: Mesh) => {
  193. (geometry.meta as GaussianSurfaceMeta).colorTexture?.destroy();
  194. }
  195. }, materialId);
  196. }
  197. //
  198. const GaussianSurfaceName = 'gaussian-surface';
  199. async function createGaussianSurfaceTextureMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: GaussianDensityProps, textureMesh?: TextureMesh): Promise<TextureMesh> {
  200. if (!ctx.webgl) throw new Error('webgl context required to create gaussian surface texture-mesh');
  201. if (isTimingMode) ctx.webgl.timer.mark('createGaussianSurfaceTextureMesh');
  202. const { namedTextures, resources, extensions: { colorBufferFloat, textureFloat, colorBufferHalfFloat, textureHalfFloat } } = ctx.webgl;
  203. if (!namedTextures[GaussianSurfaceName]) {
  204. namedTextures[GaussianSurfaceName] = colorBufferHalfFloat && textureHalfFloat
  205. ? resources.texture('image-float16', 'rgba', 'fp16', 'linear')
  206. : colorBufferFloat && textureFloat
  207. ? resources.texture('image-float32', 'rgba', 'float', 'linear')
  208. : resources.texture('image-uint8', 'rgba', 'ubyte', 'linear');
  209. }
  210. const densityTextureData = await computeUnitGaussianDensityTexture2d(structure, unit, theme.size, true, props, ctx.webgl, namedTextures[GaussianSurfaceName]).runInContext(ctx.runtime);
  211. const isoLevel = Math.exp(-props.smoothness) / densityTextureData.radiusFactor;
  212. const axisOrder = Vec3.create(0, 1, 2);
  213. const buffer = textureMesh?.doubleBuffer.get();
  214. const gv = extractIsosurface(ctx.webgl, densityTextureData.texture, densityTextureData.gridDim, densityTextureData.gridTexDim, densityTextureData.gridTexScale, densityTextureData.transform, isoLevel, false, true, axisOrder, true, buffer?.vertex, buffer?.group, buffer?.normal);
  215. if (isTimingMode) ctx.webgl.timer.markEnd('createGaussianSurfaceTextureMesh');
  216. const groupCount = unit.elements.length;
  217. const boundingSphere = Sphere3D.expand(Sphere3D(), unit.boundary.sphere, densityTextureData.maxRadius);
  218. const surface = TextureMesh.create(gv.vertexCount, groupCount, gv.vertexTexture, gv.groupTexture, gv.normalTexture, boundingSphere, textureMesh);
  219. (surface.meta as GaussianSurfaceMeta).resolution = densityTextureData.resolution;
  220. return surface;
  221. }
  222. export function GaussianSurfaceTextureMeshVisual(materialId: number): UnitsVisual<GaussianSurfaceMeshParams> {
  223. return UnitsTextureMeshVisual<GaussianSurfaceMeshParams>({
  224. defaultProps: PD.getDefaultValues(GaussianSurfaceMeshParams),
  225. createGeometry: createGaussianSurfaceTextureMesh,
  226. createLocationIterator: ElementIterator.fromGroup,
  227. getLoci: getElementLoci,
  228. eachLocation: eachElement,
  229. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<GaussianSurfaceMeshParams>, currentProps: PD.Values<GaussianSurfaceMeshParams>) => {
  230. if (newProps.resolution !== currentProps.resolution) state.createGeometry = true;
  231. if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true;
  232. if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true;
  233. if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true;
  234. if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
  235. if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true;
  236. if (newProps.smoothColors.name !== currentProps.smoothColors.name) {
  237. state.updateColor = true;
  238. } else if (newProps.smoothColors.name === 'on' && currentProps.smoothColors.name === 'on') {
  239. if (newProps.smoothColors.params.resolutionFactor !== currentProps.smoothColors.params.resolutionFactor) state.updateColor = true;
  240. if (newProps.smoothColors.params.sampleStride !== currentProps.smoothColors.params.sampleStride) state.updateColor = true;
  241. }
  242. },
  243. mustRecreate: (structureGroup: StructureGroup, props: PD.Values<GaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
  244. return !props.tryUseGpu || !webgl || !suitableForGpu(structureGroup.structure, props, webgl);
  245. },
  246. processValues: (values: TextureMeshValues, geometry: TextureMesh, props: PD.Values<GaussianSurfaceMeshParams>, theme: Theme, webgl?: WebGLContext) => {
  247. const { resolution, colorTexture } = geometry.meta as GaussianSurfaceMeta;
  248. const csp = getColorSmoothingProps(props.smoothColors, theme.color.preferSmoothing, resolution);
  249. if (csp && webgl) {
  250. applyTextureMeshColorSmoothing(values, csp.resolution, csp.stride, webgl, colorTexture);
  251. (geometry.meta as GaussianSurfaceMeta).colorTexture = values.tColorGrid.ref.value;
  252. }
  253. },
  254. dispose: (geometry: TextureMesh) => {
  255. geometry.vertexTexture.ref.value.destroy();
  256. geometry.groupTexture.ref.value.destroy();
  257. geometry.normalTexture.ref.value.destroy();
  258. geometry.doubleBuffer.destroy();
  259. (geometry.meta as GaussianSurfaceMeta).colorTexture?.destroy();
  260. }
  261. }, materialId);
  262. }
  263. //
  264. async function createStructureGaussianSurfaceTextureMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: GaussianDensityProps, textureMesh?: TextureMesh): Promise<TextureMesh> {
  265. if (!ctx.webgl) throw new Error('webgl context required to create structure gaussian surface texture-mesh');
  266. if (isTimingMode) ctx.webgl.timer.mark('createStructureGaussianSurfaceTextureMesh');
  267. const { namedTextures, resources, extensions: { colorBufferFloat, textureFloat, colorBufferHalfFloat, textureHalfFloat } } = ctx.webgl;
  268. if (!namedTextures[GaussianSurfaceName]) {
  269. namedTextures[GaussianSurfaceName] = colorBufferHalfFloat && textureHalfFloat
  270. ? resources.texture('image-float16', 'rgba', 'fp16', 'linear')
  271. : colorBufferFloat && textureFloat
  272. ? resources.texture('image-float32', 'rgba', 'float', 'linear')
  273. : resources.texture('image-uint8', 'rgba', 'ubyte', 'linear');
  274. }
  275. const densityTextureData = await computeStructureGaussianDensityTexture2d(structure, theme.size, true, props, ctx.webgl, namedTextures[GaussianSurfaceName]).runInContext(ctx.runtime);
  276. const isoLevel = Math.exp(-props.smoothness) / densityTextureData.radiusFactor;
  277. const axisOrder = Vec3.create(0, 1, 2);
  278. const buffer = textureMesh?.doubleBuffer.get();
  279. const gv = extractIsosurface(ctx.webgl, densityTextureData.texture, densityTextureData.gridDim, densityTextureData.gridTexDim, densityTextureData.gridTexScale, densityTextureData.transform, isoLevel, false, true, axisOrder, true, buffer?.vertex, buffer?.group, buffer?.normal);
  280. if (isTimingMode) ctx.webgl.timer.markEnd('createStructureGaussianSurfaceTextureMesh');
  281. const groupCount = structure.elementCount;
  282. const boundingSphere = Sphere3D.expand(Sphere3D(), structure.boundary.sphere, densityTextureData.maxRadius);
  283. const surface = TextureMesh.create(gv.vertexCount, groupCount, gv.vertexTexture, gv.groupTexture, gv.normalTexture, boundingSphere, textureMesh);
  284. (surface.meta as GaussianSurfaceMeta).resolution = densityTextureData.resolution;
  285. return surface;
  286. }
  287. export function StructureGaussianSurfaceTextureMeshVisual(materialId: number): ComplexVisual<StructureGaussianSurfaceMeshParams> {
  288. return ComplexTextureMeshVisual<StructureGaussianSurfaceMeshParams>({
  289. defaultProps: PD.getDefaultValues(StructureGaussianSurfaceMeshParams),
  290. createGeometry: createStructureGaussianSurfaceTextureMesh,
  291. createLocationIterator: ElementIterator.fromStructure,
  292. getLoci: getSerialElementLoci,
  293. eachLocation: eachSerialElement,
  294. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<StructureGaussianSurfaceMeshParams>, currentProps: PD.Values<StructureGaussianSurfaceMeshParams>) => {
  295. if (newProps.resolution !== currentProps.resolution) state.createGeometry = true;
  296. if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true;
  297. if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true;
  298. if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true;
  299. if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true;
  300. if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true;
  301. if (newProps.smoothColors.name !== currentProps.smoothColors.name) {
  302. state.updateColor = true;
  303. } else if (newProps.smoothColors.name === 'on' && currentProps.smoothColors.name === 'on') {
  304. if (newProps.smoothColors.params.resolutionFactor !== currentProps.smoothColors.params.resolutionFactor) state.updateColor = true;
  305. if (newProps.smoothColors.params.sampleStride !== currentProps.smoothColors.params.sampleStride) state.updateColor = true;
  306. }
  307. },
  308. mustRecreate: (structure: Structure, props: PD.Values<StructureGaussianSurfaceMeshParams>, webgl?: WebGLContext) => {
  309. return !props.tryUseGpu || !webgl || !suitableForGpu(structure, props, webgl);
  310. },
  311. processValues: (values: TextureMeshValues, geometry: TextureMesh, props: PD.Values<GaussianSurfaceMeshParams>, theme: Theme, webgl?: WebGLContext) => {
  312. const { resolution, colorTexture } = geometry.meta as GaussianSurfaceMeta;
  313. const csp = getColorSmoothingProps(props.smoothColors, theme.color.preferSmoothing, resolution);
  314. if (csp && webgl) {
  315. applyTextureMeshColorSmoothing(values, csp.resolution, csp.stride, webgl, colorTexture);
  316. (geometry.meta as GaussianSurfaceMeta).colorTexture = values.tColorGrid.ref.value;
  317. }
  318. },
  319. dispose: (geometry: TextureMesh) => {
  320. geometry.vertexTexture.ref.value.destroy();
  321. geometry.groupTexture.ref.value.destroy();
  322. geometry.normalTexture.ref.value.destroy();
  323. geometry.doubleBuffer.destroy();
  324. (geometry.meta as GaussianSurfaceMeta).colorTexture?.destroy();
  325. }
  326. }, materialId);
  327. }