units-visual.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /**
  2. * Copyright (c) 2018-2020 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 { Structure, Unit, StructureElement } from '../../mol-model/structure';
  8. import { RepresentationProps } from '../representation';
  9. import { Visual, VisualContext } from '../visual';
  10. import { Geometry, GeometryUtils } from '../../mol-geo/geometry/geometry';
  11. import { LocationIterator } from '../../mol-geo/util/location-iterator';
  12. import { Theme } from '../../mol-theme/theme';
  13. import { createUnitsTransform, includesUnitKind } from './visual/util/common';
  14. import { createRenderObject, GraphicsRenderObject, RenderObjectValues } from '../../mol-gl/render-object';
  15. import { PickingId } from '../../mol-geo/geometry/picking';
  16. import { Loci, isEveryLoci, EmptyLoci } from '../../mol-model/loci';
  17. import { Interval } from '../../mol-data/int';
  18. import { VisualUpdateState } from '../util';
  19. import { ColorTheme } from '../../mol-theme/color';
  20. import { createMarkers } from '../../mol-geo/geometry/marker-data';
  21. import { MarkerAction } from '../../mol-util/marker-action';
  22. import { ValueCell, deepEqual } from '../../mol-util';
  23. import { createSizes } from '../../mol-geo/geometry/size-data';
  24. import { createColors } from '../../mol-geo/geometry/color-data';
  25. import { Mat4 } from '../../mol-math/linear-algebra';
  26. import { Overpaint } from '../../mol-theme/overpaint';
  27. import { Transparency } from '../../mol-theme/transparency';
  28. import { Mesh } from '../../mol-geo/geometry/mesh/mesh';
  29. import { SizeTheme } from '../../mol-theme/size';
  30. import { Spheres } from '../../mol-geo/geometry/spheres/spheres';
  31. import { Cylinders } from '../../mol-geo/geometry/cylinders/cylinders';
  32. import { Points } from '../../mol-geo/geometry/points/points';
  33. import { Lines } from '../../mol-geo/geometry/lines/lines';
  34. import { Text } from '../../mol-geo/geometry/text/text';
  35. import { DirectVolume } from '../../mol-geo/geometry/direct-volume/direct-volume';
  36. import { TextureMesh } from '../../mol-geo/geometry/texture-mesh/texture-mesh';
  37. import { SizeValues } from '../../mol-gl/renderable/schema';
  38. import { StructureParams, StructureMeshParams, StructureSpheresParams, StructurePointsParams, StructureLinesParams, StructureTextParams, StructureDirectVolumeParams, StructureTextureMeshParams, StructureCylindersParams } from './params';
  39. import { Clipping } from '../../mol-theme/clipping';
  40. import { WebGLContext } from '../../mol-gl/webgl/context';
  41. import { isPromiseLike } from '../../mol-util/type-helpers';
  42. export type StructureGroup = { structure: Structure, group: Unit.SymmetryGroup }
  43. export interface UnitsVisual<P extends RepresentationProps = {}> extends Visual<StructureGroup, P> { }
  44. function createUnitsRenderObject<G extends Geometry>(group: Unit.SymmetryGroup, geometry: G, locationIt: LocationIterator, theme: Theme, props: PD.Values<Geometry.Params<G>>, materialId: number) {
  45. const { createValues, createRenderableState } = Geometry.getUtils(geometry);
  46. const transform = createUnitsTransform(group);
  47. const values = createValues(geometry, transform, locationIt, theme, props);
  48. const state = createRenderableState(props);
  49. return createRenderObject(geometry.kind, values, state, materialId);
  50. }
  51. interface UnitsVisualBuilder<P extends StructureParams, G extends Geometry> {
  52. defaultProps: PD.Values<P>
  53. createGeometry(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: PD.Values<P>, geometry?: G): Promise<G> | G
  54. createLocationIterator(structureGroup: StructureGroup): LocationIterator
  55. getLoci(pickingId: PickingId, structureGroup: StructureGroup, id: number): Loci
  56. eachLocation(loci: Loci, structureGroup: StructureGroup, apply: (interval: Interval) => boolean, isMarking: boolean): boolean
  57. setUpdateState(state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructureGroup: StructureGroup, currentStructureGroup: StructureGroup): void
  58. mustRecreate?: (structureGroup: StructureGroup, props: PD.Values<P>) => boolean
  59. processValues?: (values: RenderObjectValues<G['kind']>, geometry: G, props: PD.Values<P>, theme: Theme, webgl?: WebGLContext) => void
  60. dispose?: (geometry: G) => void
  61. }
  62. interface UnitsVisualGeometryBuilder<P extends StructureParams, G extends Geometry> extends UnitsVisualBuilder<P, G> {
  63. geometryUtils: GeometryUtils<G>
  64. }
  65. export function UnitsVisual<G extends Geometry, P extends StructureParams & Geometry.Params<G>>(builder: UnitsVisualGeometryBuilder<P, G>, materialId: number): UnitsVisual<P> {
  66. const { defaultProps, createGeometry, createLocationIterator, getLoci, eachLocation, setUpdateState, mustRecreate, processValues, dispose } = builder;
  67. const { createEmpty: createEmptyGeometry, updateValues, updateBoundingSphere, updateRenderableState, createPositionIterator } = builder.geometryUtils;
  68. const updateState = VisualUpdateState.create();
  69. let renderObject: GraphicsRenderObject<G['kind']> | undefined;
  70. let newProps: PD.Values<P> = Object.assign({}, defaultProps);
  71. let newTheme: Theme = Theme.createEmpty();
  72. let newStructureGroup: StructureGroup;
  73. let currentProps: PD.Values<P>;
  74. let currentTheme: Theme;
  75. let currentStructureGroup: StructureGroup;
  76. let geometry: G;
  77. let locationIt: LocationIterator;
  78. let positionIt: LocationIterator;
  79. function prepareUpdate(theme: Theme, props: PD.Values<P>, structureGroup: StructureGroup) {
  80. if (!structureGroup && !currentStructureGroup) {
  81. throw new Error('missing structureGroup');
  82. }
  83. newProps = props;
  84. newTheme = theme;
  85. newStructureGroup = structureGroup;
  86. VisualUpdateState.reset(updateState);
  87. if (!renderObject || !currentStructureGroup) {
  88. // console.log('create new');
  89. updateState.createNew = true;
  90. updateState.createGeometry = true;
  91. return;
  92. }
  93. setUpdateState(updateState, newProps, currentProps, newTheme, currentTheme, newStructureGroup, currentStructureGroup);
  94. if (!Structure.areHierarchiesEqual(currentStructureGroup.structure, newStructureGroup.structure)) {
  95. // console.log('new hierarchy');
  96. updateState.updateTransform = true;
  97. updateState.updateColor = true;
  98. updateState.updateSize = true;
  99. }
  100. if (!ColorTheme.areEqual(newTheme.color, currentTheme.color)) {
  101. // console.log('new colorTheme');
  102. updateState.updateColor = true;
  103. }
  104. if (!deepEqual(newProps.unitKinds, currentProps.unitKinds)) {
  105. // console.log('new unitKinds');
  106. updateState.createGeometry = true;
  107. }
  108. if (newStructureGroup.group.transformHash !== currentStructureGroup.group.transformHash) {
  109. // console.log('new transformHash');
  110. if (newStructureGroup.group.units.length !== currentStructureGroup.group.units.length || updateState.updateColor) {
  111. updateState.updateTransform = true;
  112. } else {
  113. updateState.updateMatrix = true;
  114. }
  115. }
  116. // check if the operator or conformation of unit has changed
  117. const newUnit = newStructureGroup.group.units[0];
  118. const currentUnit = currentStructureGroup.group.units[0];
  119. if (!Unit.areOperatorsEqual(newUnit, currentUnit)) {
  120. // console.log('new operators');
  121. updateState.updateTransform = true;
  122. }
  123. if (!Unit.areConformationsEqual(newUnit, currentUnit)) {
  124. // console.log('new conformation');
  125. updateState.createGeometry = true;
  126. }
  127. if (updateState.updateTransform) {
  128. updateState.updateMatrix = true;
  129. }
  130. if (updateState.updateSize && !('uSize' in renderObject.values)) {
  131. updateState.createGeometry = true;
  132. }
  133. if (updateState.createGeometry || updateState.updateTransform) {
  134. if (currentStructureGroup.structure.hashCode !== newStructureGroup.structure.hashCode) {
  135. // console.log('new hashCode');
  136. updateState.updateColor = true;
  137. updateState.updateSize = true;
  138. }
  139. if (newTheme.color.granularity.startsWith('vertex') ||
  140. renderObject.values.dColorType.ref.value.startsWith('vertex') ||
  141. newTheme.color.granularity.startsWith('volume') ||
  142. renderObject.values.dColorType.ref.value.startsWith('volume')
  143. ) {
  144. updateState.updateColor = true;
  145. }
  146. }
  147. }
  148. function update(newGeometry?: G) {
  149. if (updateState.createNew) {
  150. locationIt = createLocationIterator(newStructureGroup);
  151. if (newGeometry) {
  152. renderObject = createUnitsRenderObject(newStructureGroup.group, newGeometry, locationIt, newTheme, newProps, materialId);
  153. positionIt = createPositionIterator(newGeometry, renderObject.values);
  154. } else {
  155. throw new Error('expected geometry to be given');
  156. }
  157. } else {
  158. if (!renderObject) {
  159. throw new Error('expected renderObject to be available');
  160. }
  161. if (updateState.updateTransform) {
  162. // console.log('update transform');
  163. locationIt = createLocationIterator(newStructureGroup);
  164. const { instanceCount, groupCount } = locationIt;
  165. createMarkers(instanceCount * groupCount, renderObject.values);
  166. }
  167. if (updateState.updateMatrix) {
  168. // console.log('update matrix');
  169. createUnitsTransform(newStructureGroup.group, renderObject.values);
  170. }
  171. if (updateState.createGeometry) {
  172. // console.log('update geometry');
  173. if (newGeometry) {
  174. ValueCell.updateIfChanged(renderObject.values.drawCount, Geometry.getDrawCount(newGeometry));
  175. ValueCell.updateIfChanged(renderObject.values.uVertexCount, Geometry.getVertexCount(newGeometry));
  176. } else {
  177. throw new Error('expected geometry to be given');
  178. }
  179. }
  180. if (updateState.updateTransform || updateState.createGeometry) {
  181. updateBoundingSphere(renderObject.values, newGeometry || geometry);
  182. positionIt = createPositionIterator(newGeometry || geometry, renderObject.values);
  183. }
  184. if (updateState.updateSize) {
  185. // not all geometries have size data, so check here
  186. if ('uSize' in renderObject.values) {
  187. // console.log('update size');
  188. createSizes(locationIt, newTheme.size, renderObject.values as SizeValues);
  189. }
  190. }
  191. if (updateState.updateColor) {
  192. // console.log('update color');
  193. createColors(locationIt, positionIt, newTheme.color, renderObject.values);
  194. }
  195. updateValues(renderObject.values, newProps);
  196. updateRenderableState(renderObject.state, newProps);
  197. }
  198. currentProps = newProps;
  199. currentTheme = newTheme;
  200. currentStructureGroup = newStructureGroup;
  201. if (newGeometry) geometry = newGeometry;
  202. }
  203. function _createGeometry(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: PD.Values<P>, geometry?: G) {
  204. return includesUnitKind(props.unitKinds, unit)
  205. ? createGeometry(ctx, unit, structure, theme, props, geometry)
  206. : createEmptyGeometry(geometry);
  207. }
  208. function lociIsSuperset(loci: Loci) {
  209. if (isEveryLoci(loci)) return true;
  210. if (Structure.isLoci(loci) && Structure.areRootsEquivalent(loci.structure, currentStructureGroup.structure)) return true;
  211. if (StructureElement.Loci.is(loci) && Structure.areRootsEquivalent(loci.structure, currentStructureGroup.structure)) {
  212. if (StructureElement.Loci.isWholeStructure(loci)) return true;
  213. }
  214. return false;
  215. }
  216. function lociApply(loci: Loci, apply: (interval: Interval) => boolean, isMarking: boolean) {
  217. if (lociIsSuperset(loci)) {
  218. return apply(Interval.ofBounds(0, locationIt.groupCount * locationIt.instanceCount));
  219. } else {
  220. return eachLocation(loci, currentStructureGroup, apply, isMarking);
  221. }
  222. }
  223. function finalize(ctx: VisualContext) {
  224. if (renderObject) {
  225. processValues?.(renderObject.values, geometry, currentProps, currentTheme, ctx.webgl);
  226. }
  227. }
  228. return {
  229. get groupCount() { return locationIt ? locationIt.count : 0; },
  230. get renderObject () { return locationIt && locationIt.count ? renderObject : undefined; },
  231. createOrUpdate(ctx: VisualContext, theme: Theme, props: PD.Values<P>, structureGroup?: StructureGroup) {
  232. prepareUpdate(theme, props, structureGroup || currentStructureGroup);
  233. if (updateState.createGeometry) {
  234. const newGeometry = _createGeometry(ctx, newStructureGroup.group.units[0], newStructureGroup.structure, newTheme, newProps, geometry);
  235. if (isPromiseLike(newGeometry)) {
  236. return newGeometry.then(g => {
  237. update(g);
  238. finalize(ctx);
  239. });
  240. }
  241. update(newGeometry);
  242. } else {
  243. update();
  244. }
  245. finalize(ctx);
  246. },
  247. getLoci(pickingId: PickingId) {
  248. return renderObject ? getLoci(pickingId, currentStructureGroup, renderObject.id) : EmptyLoci;
  249. },
  250. mark(loci: Loci, action: MarkerAction) {
  251. return Visual.mark(renderObject, loci, action, lociApply);
  252. },
  253. setVisibility(visible: boolean) {
  254. Visual.setVisibility(renderObject, visible);
  255. },
  256. setAlphaFactor(alphaFactor: number) {
  257. Visual.setAlphaFactor(renderObject, alphaFactor);
  258. },
  259. setPickable(pickable: boolean) {
  260. Visual.setPickable(renderObject, pickable);
  261. },
  262. setColorOnly(colorOnly: boolean) {
  263. Visual.setColorOnly(renderObject, colorOnly);
  264. },
  265. setTransform(matrix?: Mat4, instanceMatrices?: Float32Array | null) {
  266. Visual.setTransform(renderObject, matrix, instanceMatrices);
  267. },
  268. setOverpaint(overpaint: Overpaint) {
  269. Visual.setOverpaint(renderObject, overpaint, lociApply, true);
  270. },
  271. setTransparency(transparency: Transparency) {
  272. Visual.setTransparency(renderObject, transparency, lociApply, true);
  273. },
  274. setClipping(clipping: Clipping) {
  275. Visual.setClipping(renderObject, clipping, lociApply, true);
  276. },
  277. destroy() {
  278. dispose?.(geometry);
  279. if (renderObject) {
  280. renderObject.state.disposed = true;
  281. renderObject = undefined;
  282. }
  283. },
  284. mustRecreate
  285. };
  286. }
  287. // mesh
  288. export const UnitsMeshParams = { ...StructureMeshParams, ...StructureParams };
  289. export type UnitsMeshParams = typeof UnitsMeshParams
  290. export interface UnitsMeshVisualBuilder<P extends UnitsMeshParams> extends UnitsVisualBuilder<P, Mesh> { }
  291. export function UnitsMeshVisual<P extends UnitsMeshParams>(builder: UnitsMeshVisualBuilder<P>, materialId: number): UnitsVisual<P> {
  292. return UnitsVisual<Mesh, P>({
  293. ...builder,
  294. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructureGroup: StructureGroup, currentStructureGroup: StructureGroup) => {
  295. builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme, newStructureGroup, currentStructureGroup);
  296. if (!SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.createGeometry = true;
  297. },
  298. geometryUtils: Mesh.Utils
  299. }, materialId);
  300. }
  301. // spheres
  302. export const UnitsSpheresParams = { ...StructureSpheresParams, ...StructureParams };
  303. export type UnitsSpheresParams = typeof UnitsSpheresParams
  304. export interface UnitsSpheresVisualBuilder<P extends UnitsSpheresParams> extends UnitsVisualBuilder<P, Spheres> { }
  305. export function UnitsSpheresVisual<P extends UnitsSpheresParams>(builder: UnitsSpheresVisualBuilder<P>, materialId: number): UnitsVisual<P> {
  306. return UnitsVisual<Spheres, P>({
  307. ...builder,
  308. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructureGroup: StructureGroup, currentStructureGroup: StructureGroup) => {
  309. builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme, newStructureGroup, currentStructureGroup);
  310. if (!SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.updateSize = true;
  311. },
  312. geometryUtils: Spheres.Utils
  313. }, materialId);
  314. }
  315. // cylinders
  316. export const UnitsCylindersParams = { ...StructureCylindersParams, ...StructureParams };
  317. export type UnitsCylindersParams = typeof UnitsCylindersParams
  318. export interface UnitsCylindersVisualBuilder<P extends UnitsCylindersParams> extends UnitsVisualBuilder<P, Cylinders> { }
  319. export function UnitsCylindersVisual<P extends UnitsCylindersParams>(builder: UnitsCylindersVisualBuilder<P>, materialId: number): UnitsVisual<P> {
  320. return UnitsVisual<Cylinders, P>({
  321. ...builder,
  322. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructureGroup: StructureGroup, currentStructureGroup: StructureGroup) => {
  323. builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme, newStructureGroup, currentStructureGroup);
  324. if (!SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.updateSize = true;
  325. },
  326. geometryUtils: Cylinders.Utils
  327. }, materialId);
  328. }
  329. // points
  330. export const UnitsPointsParams = { ...StructurePointsParams, ...StructureParams };
  331. export type UnitsPointsParams = typeof UnitsPointsParams
  332. export interface UnitsPointVisualBuilder<P extends UnitsPointsParams> extends UnitsVisualBuilder<P, Points> { }
  333. export function UnitsPointsVisual<P extends UnitsPointsParams>(builder: UnitsPointVisualBuilder<P>, materialId: number): UnitsVisual<P> {
  334. return UnitsVisual<Points, P>({
  335. ...builder,
  336. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructureGroup: StructureGroup, currentStructureGroup: StructureGroup) => {
  337. builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme, newStructureGroup, currentStructureGroup);
  338. if (!SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.updateSize = true;
  339. },
  340. geometryUtils: Points.Utils
  341. }, materialId);
  342. }
  343. // lines
  344. export const UnitsLinesParams = { ...StructureLinesParams, ...StructureParams };
  345. export type UnitsLinesParams = typeof UnitsLinesParams
  346. export interface UnitsLinesVisualBuilder<P extends UnitsLinesParams> extends UnitsVisualBuilder<P, Lines> { }
  347. export function UnitsLinesVisual<P extends UnitsLinesParams>(builder: UnitsLinesVisualBuilder<P>, materialId: number): UnitsVisual<P> {
  348. return UnitsVisual<Lines, P>({
  349. ...builder,
  350. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructureGroup: StructureGroup, currentStructureGroup: StructureGroup) => {
  351. builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme, newStructureGroup, currentStructureGroup);
  352. if (!SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.updateSize = true;
  353. },
  354. geometryUtils: Lines.Utils
  355. }, materialId);
  356. }
  357. // text
  358. export const UnitsTextParams = { ...StructureTextParams, ...StructureParams };
  359. export type UnitsTextParams = typeof UnitsTextParams
  360. export interface UnitsTextVisualBuilder<P extends UnitsTextParams> extends UnitsVisualBuilder<P, Text> { }
  361. export function UnitsTextVisual<P extends UnitsTextParams>(builder: UnitsTextVisualBuilder<P>, materialId: number): UnitsVisual<P> {
  362. return UnitsVisual<Text, P>({
  363. ...builder,
  364. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructureGroup: StructureGroup, currentStructureGroup: StructureGroup) => {
  365. builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme, newStructureGroup, currentStructureGroup);
  366. if (!SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.updateSize = true;
  367. if (newProps.background !== currentProps.background) state.createGeometry = true;
  368. if (newProps.backgroundMargin !== currentProps.backgroundMargin) state.createGeometry = true;
  369. if (newProps.tether !== currentProps.tether) state.createGeometry = true;
  370. if (newProps.tetherLength !== currentProps.tetherLength) state.createGeometry = true;
  371. if (newProps.tetherBaseWidth !== currentProps.tetherBaseWidth) state.createGeometry = true;
  372. if (newProps.attachment !== currentProps.attachment) state.createGeometry = true;
  373. if (newProps.fontFamily !== currentProps.fontFamily) state.createGeometry = true;
  374. if (newProps.fontQuality !== currentProps.fontQuality) state.createGeometry = true;
  375. if (newProps.fontStyle !== currentProps.fontStyle) state.createGeometry = true;
  376. if (newProps.fontVariant !== currentProps.fontVariant) state.createGeometry = true;
  377. if (newProps.fontWeight !== currentProps.fontWeight) state.createGeometry = true;
  378. },
  379. geometryUtils: Text.Utils
  380. }, materialId);
  381. }
  382. // direct-volume
  383. export const UnitsDirectVolumeParams = { ...StructureDirectVolumeParams, ...StructureParams };
  384. export type UnitsDirectVolumeParams = typeof UnitsDirectVolumeParams
  385. export interface UnitsDirectVolumeVisualBuilder<P extends UnitsDirectVolumeParams> extends UnitsVisualBuilder<P, DirectVolume> { }
  386. export function UnitsDirectVolumeVisual<P extends UnitsDirectVolumeParams>(builder: UnitsDirectVolumeVisualBuilder<P>, materialId: number): UnitsVisual<P> {
  387. return UnitsVisual<DirectVolume, P>({
  388. ...builder,
  389. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructureGroup: StructureGroup, currentStructureGroup: StructureGroup) => {
  390. builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme, newStructureGroup, currentStructureGroup);
  391. if (!SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.createGeometry = true;
  392. },
  393. geometryUtils: DirectVolume.Utils
  394. }, materialId);
  395. }
  396. // texture-mesh
  397. export const UnitsTextureMeshParams = { ...StructureTextureMeshParams, ...StructureParams };
  398. export type UnitsTextureMeshParams = typeof UnitsTextureMeshParams
  399. export interface UnitsTextureMeshVisualBuilder<P extends UnitsTextureMeshParams> extends UnitsVisualBuilder<P, TextureMesh> { }
  400. export function UnitsTextureMeshVisual<P extends UnitsTextureMeshParams>(builder: UnitsTextureMeshVisualBuilder<P>, materialId: number): UnitsVisual<P> {
  401. return UnitsVisual<TextureMesh, P>({
  402. ...builder,
  403. setUpdateState: (state: VisualUpdateState, newProps: PD.Values<P>, currentProps: PD.Values<P>, newTheme: Theme, currentTheme: Theme, newStructureGroup: StructureGroup, currentStructureGroup: StructureGroup) => {
  404. builder.setUpdateState(state, newProps, currentProps, newTheme, currentTheme, newStructureGroup, currentStructureGroup);
  405. if (!SizeTheme.areEqual(newTheme.size, currentTheme.size)) state.createGeometry = true;
  406. },
  407. geometryUtils: TextureMesh.Utils
  408. }, materialId);
  409. }