units-visual.ts 25 KB

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