units-visual.ts 23 KB

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