@geode/opengeodeweb-front 10.44.0-rc.7 → 10.44.0-rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/.build/server/utils/scripts.js +34 -23
  2. package/app/components/MissingFilesSelector.vue +30 -17
  3. package/app/components/ObjectSelector.vue +34 -23
  4. package/app/composables/overlapping_picker_menu.ts +43 -0
  5. package/app/composables/project_manager_helpers/restore.ts +20 -11
  6. package/app/composables/use_overlapping_picker.ts +23 -37
  7. package/app/composables/virtual_tree_flatten.ts +66 -43
  8. package/app/stores/app_helpers/extension.ts +90 -51
  9. package/app/stores/infra.ts +26 -21
  10. package/app/utils/color_picker.ts +18 -15
  11. package/internal/database/database.ts +47 -32
  12. package/internal/stores/data_style/mesh/base_style.ts +74 -0
  13. package/internal/stores/data_style/mesh/index.ts +2 -57
  14. package/internal/stores/data_style/model/blocks/color.ts +58 -57
  15. package/internal/stores/data_style/model/blocks/polyhedron.ts +88 -44
  16. package/internal/stores/data_style/model/blocks/vertex.ts +88 -44
  17. package/internal/stores/data_style/model/color.ts +25 -26
  18. package/internal/stores/data_style/model/corners/index.ts +85 -78
  19. package/internal/stores/data_style/model/corners/vertex.ts +83 -39
  20. package/internal/stores/data_style/model/lines/color.ts +53 -40
  21. package/internal/stores/data_style/model/lines/edge.ts +88 -44
  22. package/internal/stores/data_style/model/lines/vertex.ts +88 -44
  23. package/internal/stores/data_style/model/surfaces/color.ts +68 -56
  24. package/internal/stores/data_style/model/surfaces/polygon.ts +80 -36
  25. package/internal/stores/data_style/model/surfaces/vertex.ts +80 -36
  26. package/internal/stores/data_style/model/visibility_dispatch.ts +49 -99
  27. package/internal/stores/hybrid_viewer/highlight.ts +70 -54
  28. package/internal/stores/hybrid_viewer/scene.ts +31 -25
  29. package/package.json +1 -1
  30. package/server/api/local/extensions/upload.put.ts +47 -20
  31. package/server/utils/scripts.ts +35 -30
@@ -26,6 +26,85 @@ interface ExtensionData {
26
26
  enabled: boolean;
27
27
  }
28
28
 
29
+ async function transformBlobUrl(
30
+ path: string,
31
+ transformer: ((code: string) => string) | undefined,
32
+ ): Promise<string> {
33
+ if (!transformer || !path.startsWith("blob:")) {
34
+ return path;
35
+ }
36
+ const response = await fetch(path);
37
+ const code = await response.text();
38
+ const transformedCode = transformer(code);
39
+
40
+ const newBlob = new Blob([transformedCode], {
41
+ type: "application/javascript",
42
+ });
43
+ return URL.createObjectURL(newBlob);
44
+ }
45
+
46
+ async function importExtensionModule(
47
+ path: string,
48
+ transformer: ((code: string) => string) | undefined,
49
+ extensionPort: string,
50
+ serverPort?: string,
51
+ ): Promise<ExtensionModule> {
52
+ const finalURL = await transformBlobUrl(path, transformer);
53
+ // oxlint-disable-next-line no-inline-comments, no-unsafe-assignment
54
+ const extensionModule: ExtensionModule = await import(/* @vite-ignore */ finalURL);
55
+ const store = extensionModule.metadata.store();
56
+ store.$patch?.({
57
+ default_local_port: extensionPort,
58
+ ...(serverPort !== undefined && { nitro_port: serverPort }),
59
+ });
60
+
61
+ if (finalURL !== path && finalURL.startsWith("blob:")) {
62
+ URL.revokeObjectURL(finalURL);
63
+ }
64
+ return extensionModule;
65
+ }
66
+
67
+ function validateExtensionModule(
68
+ extensionModule: ExtensionModule,
69
+ api: unknown,
70
+ loaded: Map<string, ExtensionData>,
71
+ ): void {
72
+ if (!extensionModule.metadata?.id) {
73
+ throw new Error("Extension must have metadata.id");
74
+ }
75
+
76
+ const extensionId = extensionModule.metadata.id;
77
+
78
+ if (loaded.has(extensionId)) {
79
+ consola.warn(`[AppStore] Extension "${extensionId}" is already loaded`);
80
+ throw new Error(`Extension "${extensionId}" is already loaded.`);
81
+ }
82
+
83
+ if (api === undefined) {
84
+ throw new Error("Extension API not initialized");
85
+ }
86
+
87
+ if (typeof extensionModule.install !== "function") {
88
+ throw new TypeError("Extension must export an install function");
89
+ }
90
+ }
91
+
92
+ function createExtensionData(
93
+ extensionModule: ExtensionModule,
94
+ path: string,
95
+ backendPath: string | undefined,
96
+ ): ExtensionData {
97
+ return {
98
+ module: extensionModule,
99
+ id: extensionModule.metadata.id,
100
+ path,
101
+ backendPath,
102
+ loadedAt: new Date().toISOString(),
103
+ metadata: extensionModule.metadata,
104
+ enabled: true,
105
+ };
106
+ }
107
+
29
108
  // oxlint-disable-next-line max-lines-per-function, max-statements
30
109
  export function useAppExtensions(): {
31
110
  loadedExtensions: typeof loadedExtensions;
@@ -63,61 +142,21 @@ export function useAppExtensions(): {
63
142
  backendPath?: string,
64
143
  ): Promise<ExtensionModule> {
65
144
  try {
66
- let finalURL = path;
67
-
68
- if (codeTransformer.value && path.startsWith("blob:")) {
69
- const response = await fetch(path);
70
- const code = await response.text();
71
- const transformedCode = codeTransformer.value(code);
72
-
73
- const newBlob = new Blob([transformedCode], {
74
- type: "application/javascript",
75
- });
76
- finalURL = URL.createObjectURL(newBlob);
77
- }
78
- // oxlint-disable-next-line no-inline-comments, no-unsafe-assignment
79
- const extensionModule: ExtensionModule = await import(/* @vite-ignore */ finalURL);
80
- const store = extensionModule.metadata.store();
81
- store.$patch?.({
82
- default_local_port: extensionPort,
83
- ...(serverPort !== undefined && { nitro_port: serverPort }),
84
- });
85
-
86
- if (finalURL !== path && finalURL.startsWith("blob:")) {
87
- URL.revokeObjectURL(finalURL);
88
- }
89
-
90
- if (!extensionModule.metadata?.id) {
91
- throw new Error("Extension must have metadata.id");
92
- }
93
-
145
+ const extensionModule = await importExtensionModule(
146
+ path,
147
+ codeTransformer.value,
148
+ extensionPort,
149
+ serverPort,
150
+ );
151
+ validateExtensionModule(extensionModule, extensionAPI.value, loadedExtensions.value);
94
152
  const extensionId = extensionModule.metadata.id;
95
153
 
96
- if (loadedExtensions.value.has(extensionId)) {
97
- consola.warn(`[AppStore] Extension "${extensionId}" is already loaded`);
98
- throw new Error(`Extension "${extensionId}" is already loaded.`);
99
- }
100
-
101
- if (extensionAPI.value === undefined) {
102
- throw new Error("Extension API not initialized");
103
- }
104
-
105
- if (typeof extensionModule.install !== "function") {
106
- throw new TypeError("Extension must export an install function");
107
- }
108
-
109
154
  await extensionModule.install(extensionAPI.value, backendPath);
110
155
 
111
- const extensionData: ExtensionData = {
112
- module: extensionModule,
113
- id: extensionId,
114
- path,
115
- backendPath,
116
- loadedAt: new Date().toISOString(),
117
- metadata: extensionModule.metadata,
118
- enabled: true,
119
- };
120
- loadedExtensions.value.set(extensionId, extensionData);
156
+ loadedExtensions.value.set(
157
+ extensionId,
158
+ createExtensionData(extensionModule, path, backendPath),
159
+ );
121
160
 
122
161
  consola.info(`[AppStore] Extension loaded successfully: ${extensionId}`);
123
162
  return extensionModule;
@@ -14,6 +14,31 @@ declare global {
14
14
  var electronAPI: ElectronApi["electronAPI"];
15
15
  }
16
16
 
17
+ async function launchLocalServices(
18
+ currentMode: string,
19
+ microservices: readonly Microservice[],
20
+ ): Promise<void> {
21
+ const { useAppStore } = await import("@ogw_front/stores/app");
22
+ const appStore = useAppStore();
23
+ await appStore.createProjectFolder();
24
+ if (currentMode === appMode.DESKTOP) {
25
+ globalThis.electronAPI.project_folder_path({
26
+ projectFolderPath: appStore.projectFolderPath,
27
+ });
28
+ }
29
+ await setAppBaseUrl(appStore.base_url);
30
+ const microservices_with_launch = microservices.filter((store: Microservice) => store.launch);
31
+ const launch_promises = microservices_with_launch.map(async (store: Microservice) => {
32
+ const result = await store.launch?.({
33
+ projectFolderPath: appStore.projectFolderPath,
34
+ });
35
+ return result;
36
+ });
37
+ const { registerRunningExtensions } = await import("@ogw_front/utils/extension");
38
+ launch_promises.push(registerRunningExtensions());
39
+ await Promise.all(launch_promises);
40
+ }
41
+
17
42
  export const useInfraStore = defineStore("infra", {
18
43
  state: () => ({
19
44
  app_mode: useRuntimeConfig().public.MODE,
@@ -63,27 +88,7 @@ export const useInfraStore = defineStore("infra", {
63
88
  throw error;
64
89
  }
65
90
  } else {
66
- const { useAppStore } = await import("@ogw_front/stores/app");
67
- const appStore = useAppStore();
68
- await appStore.createProjectFolder();
69
- if (this.app_mode === appMode.DESKTOP) {
70
- globalThis.electronAPI.project_folder_path({
71
- projectFolderPath: appStore.projectFolderPath,
72
- });
73
- }
74
- await setAppBaseUrl(appStore.base_url);
75
- const microservices_with_launch = this.microservices.filter(
76
- (store: Microservice) => store.launch,
77
- );
78
- const launch_promises = microservices_with_launch.map(async (store: Microservice) => {
79
- const result = await store.launch?.({
80
- projectFolderPath: appStore.projectFolderPath,
81
- });
82
- return result;
83
- });
84
- const { registerRunningExtensions } = await import("@ogw_front/utils/extension");
85
- launch_promises.push(registerRunningExtensions());
86
- await Promise.all(launch_promises);
91
+ await launchLocalServices(this.app_mode, this.microservices);
87
92
  }
88
93
  this.status = Status.CREATED;
89
94
  return this.create_connection();
@@ -10,6 +10,20 @@ function parseComponent(val: string, max = RGB_MAX): number {
10
10
  return Number(val);
11
11
  }
12
12
 
13
+ function clampChannel(value: number): number {
14
+ return Math.min(RGB_MAX, Math.max(0, Math.round(value)));
15
+ }
16
+
17
+ function parseAlpha(alphaText: string | undefined): number {
18
+ if (alphaText === undefined) {
19
+ return 1;
20
+ }
21
+ const rawAlpha = parseComponent(alphaText, 1);
22
+ const calculatedAlpha = rawAlpha > 1 ? rawAlpha / RGB_MAX : rawAlpha;
23
+ const roundedAlpha = Number(calculatedAlpha.toFixed(2));
24
+ return Math.min(1, Math.max(0, roundedAlpha));
25
+ }
26
+
13
27
  function parseColorString(colorText: string): RGBAColor | undefined {
14
28
  if (colorText === "") {
15
29
  return undefined;
@@ -21,21 +35,10 @@ function parseColorString(colorText: string): RGBAColor | undefined {
21
35
  }
22
36
 
23
37
  const [redText = "", greenText = "", blueText = "", alphaText] = numbersMatch;
24
- const rawRed = parseComponent(redText);
25
- const rawGreen = parseComponent(greenText);
26
- const rawBlue = parseComponent(blueText);
27
-
28
- const red = Math.min(RGB_MAX, Math.max(0, Math.round(rawRed)));
29
- const green = Math.min(RGB_MAX, Math.max(0, Math.round(rawGreen)));
30
- const blue = Math.min(RGB_MAX, Math.max(0, Math.round(rawBlue)));
31
-
32
- let alpha = 1;
33
- if (alphaText !== undefined) {
34
- const rawAlpha = parseComponent(alphaText, 1);
35
- const calculatedAlpha = rawAlpha > 1 ? rawAlpha / RGB_MAX : rawAlpha;
36
- const roundedAlpha = Number(calculatedAlpha.toFixed(2));
37
- alpha = Math.min(1, Math.max(0, roundedAlpha));
38
- }
38
+ const red = clampChannel(parseComponent(redText));
39
+ const green = clampChannel(parseComponent(greenText));
40
+ const blue = clampChannel(parseComponent(blueText));
41
+ const alpha = parseAlpha(alphaText);
39
42
 
40
43
  if (Number.isNaN(red) || Number.isNaN(green) || Number.isNaN(blue) || Number.isNaN(alpha)) {
41
44
  return undefined;
@@ -8,6 +8,51 @@ interface DatabaseContainer {
8
8
 
9
9
  const databaseContainer: DatabaseContainer = { instance: undefined };
10
10
 
11
+ interface CurrentSchema {
12
+ currentVersion: number;
13
+ currentStores: Record<string, string>;
14
+ }
15
+
16
+ function tableStoreDefinition(table: Table): string {
17
+ const keyPath = table.schema.primKey.src;
18
+ const indexes = table.schema.indexes.map((index) => index.src);
19
+ if (keyPath) {
20
+ return [keyPath, ...indexes].join(",");
21
+ }
22
+ return indexes.join(",");
23
+ }
24
+
25
+ async function readCurrentSchema(): Promise<CurrentSchema> {
26
+ const currentStores: Record<string, string> = { ...BaseDatabase.initialStores };
27
+ if (!(await Dexie.exists("Database"))) {
28
+ return { currentVersion: 1, currentStores };
29
+ }
30
+ const tempDb = new Dexie("Database");
31
+ await tempDb.open();
32
+ const currentVersion = tempDb.verno;
33
+ for (const table of tempDb.tables) {
34
+ currentStores[table.name] = tableStoreDefinition(table);
35
+ }
36
+ tempDb.close();
37
+ return { currentVersion, currentStores };
38
+ }
39
+
40
+ async function openExistingDatabase(
41
+ currentVersion: number,
42
+ currentStores: Record<string, string>,
43
+ ): Promise<Dexie> {
44
+ const existingDb = new Dexie("Database");
45
+ for (let version = 1; version <= currentVersion; version += 1) {
46
+ if (version === 1) {
47
+ existingDb.version(1).stores(BaseDatabase.initialStores);
48
+ } else {
49
+ existingDb.version(version).stores(currentStores);
50
+ }
51
+ }
52
+ await existingDb.open();
53
+ return existingDb;
54
+ }
55
+
11
56
  class Database extends BaseDatabase {
12
57
  public constructor() {
13
58
  super("Database");
@@ -20,28 +65,7 @@ class Database extends BaseDatabase {
20
65
  }
21
66
 
22
67
  public static async addTables(newTables: Record<string, string>): Promise<void> {
23
- let currentVersion = 1;
24
- let currentStores: Record<string, string> = { ...BaseDatabase.initialStores };
25
-
26
- if (await Dexie.exists("Database")) {
27
- const tempDb = new Dexie("Database");
28
- await tempDb.open();
29
-
30
- currentVersion = tempDb.verno;
31
- currentStores = { ...BaseDatabase.initialStores };
32
-
33
- for (const table of tempDb.tables) {
34
- const keyPath = table.schema.primKey.src;
35
- const indexes = table.schema.indexes.map((index) => index.src);
36
- let parts = indexes;
37
- if (keyPath) {
38
- parts = [keyPath, ...indexes];
39
- }
40
- currentStores[table.name] = parts.join(",");
41
- }
42
-
43
- tempDb.close();
44
- }
68
+ const { currentVersion, currentStores } = await readCurrentSchema();
45
69
 
46
70
  const allExisting = Object.keys(newTables).every(
47
71
  (tableName) => currentStores[tableName] !== undefined,
@@ -51,16 +75,7 @@ class Database extends BaseDatabase {
51
75
  databaseContainer.instance?.close();
52
76
 
53
77
  if (allExisting) {
54
- const existingDb = new Dexie("Database");
55
- for (let version = 1; version <= currentVersion; version += 1) {
56
- if (version === 1) {
57
- existingDb.version(1).stores(BaseDatabase.initialStores);
58
- } else {
59
- existingDb.version(version).stores(currentStores);
60
- }
61
- }
62
- await existingDb.open();
63
- databaseContainer.instance = existingDb;
78
+ databaseContainer.instance = await openExistingDatabase(currentVersion, currentStores);
64
79
  } else {
65
80
  const newDb = new ExtendedDatabase(currentVersion, currentStores, newTables);
66
81
  await newDb.open();
@@ -0,0 +1,74 @@
1
+ import type { RGBAColor } from "@ogw_front/utils/default_styles/constants";
2
+ // Third party imports
3
+ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
4
+
5
+ // Local imports
6
+ import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
7
+ import { useViewerStore } from "@ogw_front/stores/viewer";
8
+
9
+ import { useDataStyleState } from "@ogw_internal/stores/data_style/state";
10
+
11
+ // Local constants
12
+ const meshSchemas = viewer_schemas.opengeodeweb_viewer.mesh;
13
+
14
+ interface MeshBaseStyle {
15
+ meshVisibility: (id: string) => boolean | undefined;
16
+ setMeshVisibility: (id: string, visibility: boolean) => Promise<unknown>;
17
+ meshColor: (id: string) => RGBAColor | undefined;
18
+ setMeshColor: (id: string, color: RGBAColor) => Promise<unknown>;
19
+ }
20
+
21
+ export function useMeshBaseStyle(): MeshBaseStyle {
22
+ const hybridViewerStore = useHybridViewerStore();
23
+ const viewerStore = useViewerStore();
24
+ const dataStyleState = useDataStyleState();
25
+
26
+ function meshVisibility(id: string): boolean | undefined {
27
+ return dataStyleState.getStyle(id).visibility;
28
+ }
29
+ async function setMeshVisibility(id: string, visibility: boolean): Promise<unknown> {
30
+ const schema = meshSchemas.visibility;
31
+ const params = { id, visibility };
32
+ const result = await viewerStore.request(
33
+ {
34
+ schema,
35
+ params,
36
+ },
37
+ {
38
+ response_function: async () => {
39
+ if (visibility !== undefined) {
40
+ hybridViewerStore.setVisibility(id, visibility);
41
+ }
42
+ const mutatedId = await dataStyleState.mutateStyle(id, { visibility });
43
+ return mutatedId;
44
+ },
45
+ },
46
+ );
47
+ return result;
48
+ }
49
+
50
+ function meshColor(id: string): RGBAColor | undefined {
51
+ // oxlint-disable-next-line no-unsafe-type-assertion -- color shape is defined by the data style schema.
52
+ return dataStyleState.getStyle(id).color as RGBAColor | undefined;
53
+ }
54
+
55
+ async function setMeshColor(id: string, color: RGBAColor): Promise<unknown> {
56
+ const schema = meshSchemas.color;
57
+ const params = { id, color };
58
+ const result = await viewerStore.request(
59
+ {
60
+ schema,
61
+ params,
62
+ },
63
+ {
64
+ response_function: async () => {
65
+ const mutatedId = await dataStyleState.mutateStyle(id, { color });
66
+ return mutatedId;
67
+ },
68
+ },
69
+ );
70
+ return result;
71
+ }
72
+
73
+ return { meshVisibility, setMeshVisibility, meshColor, setMeshColor };
74
+ }
@@ -1,12 +1,8 @@
1
1
  import type { RGBAColor } from "@ogw_front/utils/default_styles/constants";
2
- // Third party imports
3
- import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
4
2
 
5
3
  // Local imports
6
- import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
7
- import { useViewerStore } from "@ogw_front/stores/viewer";
8
-
9
4
  import { useDataStyleState } from "@ogw_internal/stores/data_style/state";
5
+ import { useMeshBaseStyle } from "./base_style";
10
6
  import { useMeshCellsStyle } from "./cells";
11
7
  import { useMeshEdgesStyle } from "./edges";
12
8
  import { useMeshPointsStyle } from "./points";
@@ -14,9 +10,6 @@ import { useMeshPolygonsStyle } from "./polygons";
14
10
  import { useMeshPolyhedraStyle } from "./polyhedra";
15
11
  import { whenDefined } from "@ogw_internal/stores/data_style/when_defined";
16
12
 
17
- // Local constants
18
- const meshSchemas = viewer_schemas.opengeodeweb_viewer.mesh;
19
-
20
13
  // oxlint-disable-next-line max-lines-per-function
21
14
  export function useMeshStyle(): {
22
15
  meshVisibility: (id: string) => boolean | undefined;
@@ -29,62 +22,14 @@ export function useMeshStyle(): {
29
22
  ReturnType<typeof useMeshCellsStyle> &
30
23
  ReturnType<typeof useMeshPolygonsStyle> &
31
24
  ReturnType<typeof useMeshPolyhedraStyle> {
32
- const hybridViewerStore = useHybridViewerStore();
33
- const viewerStore = useViewerStore();
34
25
  const dataStyleState = useDataStyleState();
26
+ const { meshVisibility, setMeshVisibility, meshColor, setMeshColor } = useMeshBaseStyle();
35
27
  const meshPointsStyle = useMeshPointsStyle();
36
28
  const meshEdgesStyle = useMeshEdgesStyle();
37
29
  const meshCellsStyle = useMeshCellsStyle();
38
30
  const meshPolygonsStyle = useMeshPolygonsStyle();
39
31
  const meshPolyhedraStyle = useMeshPolyhedraStyle();
40
32
 
41
- function meshVisibility(id: string): boolean | undefined {
42
- return dataStyleState.getStyle(id).visibility;
43
- }
44
- async function setMeshVisibility(id: string, visibility: boolean): Promise<unknown> {
45
- const schema = meshSchemas.visibility;
46
- const params = { id, visibility };
47
- const result = await viewerStore.request(
48
- {
49
- schema,
50
- params,
51
- },
52
- {
53
- response_function: async () => {
54
- if (visibility !== undefined) {
55
- hybridViewerStore.setVisibility(id, visibility);
56
- }
57
- const mutatedId = await dataStyleState.mutateStyle(id, { visibility });
58
- return mutatedId;
59
- },
60
- },
61
- );
62
- return result;
63
- }
64
-
65
- function meshColor(id: string): RGBAColor | undefined {
66
- // oxlint-disable-next-line no-unsafe-type-assertion -- color shape is defined by the data style schema.
67
- return dataStyleState.getStyle(id).color as RGBAColor | undefined;
68
- }
69
-
70
- async function setMeshColor(id: string, color: RGBAColor): Promise<unknown> {
71
- const schema = meshSchemas.color;
72
- const params = { id, color };
73
- const result = await viewerStore.request(
74
- {
75
- schema,
76
- params,
77
- },
78
- {
79
- response_function: async () => {
80
- const mutatedId = await dataStyleState.mutateStyle(id, { color });
81
- return mutatedId;
82
- },
83
- },
84
- );
85
- return result;
86
- }
87
-
88
33
  const pointsCard = {
89
34
  key: "points",
90
35
  name: meshPointsStyle.meshPointsVertexAttributeName,
@@ -68,6 +68,62 @@ export function useModelBlocksColor(): {
68
68
  return modelBlockColoring(id, block_id).active;
69
69
  }
70
70
 
71
+ async function applyVertexColoring(modelId: string, blocks_ids: string[]): Promise<void> {
72
+ const name = modelBlocksVertexAttribute.modelBlocksVertexAttributeName(modelId, blocks_ids[0]);
73
+ const item = modelBlocksVertexAttribute.modelBlocksVertexAttributeItem(modelId, blocks_ids[0]);
74
+ const [minimum, maximum] = modelBlocksVertexAttribute.modelBlocksVertexAttributeRange(
75
+ modelId,
76
+ blocks_ids[0],
77
+ );
78
+ const colorMap = modelBlocksVertexAttribute.modelBlocksVertexAttributeColorMap(
79
+ modelId,
80
+ blocks_ids[0],
81
+ );
82
+ const no_data_color = modelBlocksVertexAttribute.modelBlocksVertexAttributeNoDataColor(
83
+ modelId,
84
+ blocks_ids[0],
85
+ );
86
+ const attribute = { name, item, minimum, maximum, colorMap, no_data_color };
87
+ if (isModelBlocksVertexAttributeValid(attribute)) {
88
+ await modelBlocksVertexAttribute.setModelBlocksVertexAttribute(
89
+ modelId,
90
+ blocks_ids,
91
+ attribute,
92
+ );
93
+ }
94
+ }
95
+
96
+ async function applyPolyhedronColoring(modelId: string, blocks_ids: string[]): Promise<void> {
97
+ const name = modelBlocksPolyhedronAttribute.modelBlocksPolyhedronAttributeName(
98
+ modelId,
99
+ blocks_ids[0],
100
+ );
101
+ const item = modelBlocksPolyhedronAttribute.modelBlocksPolyhedronAttributeItem(
102
+ modelId,
103
+ blocks_ids[0],
104
+ );
105
+ const [minimum, maximum] = modelBlocksPolyhedronAttribute.modelBlocksPolyhedronAttributeRange(
106
+ modelId,
107
+ blocks_ids[0],
108
+ );
109
+ const colorMap = modelBlocksPolyhedronAttribute.modelBlocksPolyhedronAttributeColorMap(
110
+ modelId,
111
+ blocks_ids[0],
112
+ );
113
+ const no_data_color = modelBlocksPolyhedronAttribute.modelBlocksPolyhedronAttributeNoDataColor(
114
+ modelId,
115
+ blocks_ids[0],
116
+ );
117
+ const attribute = { name, item, minimum, maximum, colorMap, no_data_color };
118
+ if (isModelBlocksPolyhedronAttributeValid(attribute)) {
119
+ await modelBlocksPolyhedronAttribute.setModelBlocksPolyhedronAttribute(
120
+ modelId,
121
+ blocks_ids,
122
+ attribute,
123
+ );
124
+ }
125
+ }
126
+
71
127
  async function setModelBlocksActiveColoring(
72
128
  modelId: string,
73
129
  blocks_ids: string[],
@@ -90,64 +146,9 @@ export function useModelBlocksColor(): {
90
146
  }
91
147
 
92
148
  if (activeColoring === "vertex") {
93
- const name = modelBlocksVertexAttribute.modelBlocksVertexAttributeName(
94
- modelId,
95
- blocks_ids[0],
96
- );
97
- const item = modelBlocksVertexAttribute.modelBlocksVertexAttributeItem(
98
- modelId,
99
- blocks_ids[0],
100
- );
101
- const [minimum, maximum] = modelBlocksVertexAttribute.modelBlocksVertexAttributeRange(
102
- modelId,
103
- blocks_ids[0],
104
- );
105
- const colorMap = modelBlocksVertexAttribute.modelBlocksVertexAttributeColorMap(
106
- modelId,
107
- blocks_ids[0],
108
- );
109
- const no_data_color = modelBlocksVertexAttribute.modelBlocksVertexAttributeNoDataColor(
110
- modelId,
111
- blocks_ids[0],
112
- );
113
- const attribute = { name, item, minimum, maximum, colorMap, no_data_color };
114
- if (isModelBlocksVertexAttributeValid(attribute)) {
115
- await modelBlocksVertexAttribute.setModelBlocksVertexAttribute(
116
- modelId,
117
- blocks_ids,
118
- attribute,
119
- );
120
- }
149
+ await applyVertexColoring(modelId, blocks_ids);
121
150
  } else if (activeColoring === "polyhedron") {
122
- const name = modelBlocksPolyhedronAttribute.modelBlocksPolyhedronAttributeName(
123
- modelId,
124
- blocks_ids[0],
125
- );
126
- const item = modelBlocksPolyhedronAttribute.modelBlocksPolyhedronAttributeItem(
127
- modelId,
128
- blocks_ids[0],
129
- );
130
- const [minimum, maximum] = modelBlocksPolyhedronAttribute.modelBlocksPolyhedronAttributeRange(
131
- modelId,
132
- blocks_ids[0],
133
- );
134
- const colorMap = modelBlocksPolyhedronAttribute.modelBlocksPolyhedronAttributeColorMap(
135
- modelId,
136
- blocks_ids[0],
137
- );
138
- const no_data_color =
139
- modelBlocksPolyhedronAttribute.modelBlocksPolyhedronAttributeNoDataColor(
140
- modelId,
141
- blocks_ids[0],
142
- );
143
- const attribute = { name, item, minimum, maximum, colorMap, no_data_color };
144
- if (isModelBlocksPolyhedronAttributeValid(attribute)) {
145
- await modelBlocksPolyhedronAttribute.setModelBlocksPolyhedronAttribute(
146
- modelId,
147
- blocks_ids,
148
- attribute,
149
- );
150
- }
151
+ await applyPolyhedronColoring(modelId, blocks_ids);
151
152
  }
152
153
  }
153
154