-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
97 lines (87 loc) · 3.42 KB
/
Copy pathindex.js
File metadata and controls
97 lines (87 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Third party imports
// Local imports
import { useMeshPolygonsColorStyle } from "./color";
import { useMeshPolygonsCommonStyle } from "./common";
import { useMeshPolygonsPolygonAttributeStyle } from "./polygon";
import { useMeshPolygonsTexturesStyle } from "./textures";
import { useMeshPolygonsVertexAttributeStyle } from "./vertex";
import { useMeshPolygonsVisibilityStyle } from "./visibility";
// Local constants
function useMeshPolygonsColoringStyle() {
const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle();
const meshPolygonsColorStyle = useMeshPolygonsColorStyle();
const meshPolygonsTexturesStyle = useMeshPolygonsTexturesStyle();
const meshPolygonsVertexAttributeStyle = useMeshPolygonsVertexAttributeStyle();
const meshPolygonsPolygonAttributeStyle = useMeshPolygonsPolygonAttributeStyle();
function meshPolygonsColoring(id) {
return meshPolygonsCommonStyle.meshPolygonsColoring(id);
}
function meshPolygonsActiveColoring(id) {
return meshPolygonsColoring(id).active;
}
async function setMeshPolygonsActiveColoring(id, type) {
await meshPolygonsCommonStyle.mutateMeshPolygonsStyle(id, {
coloring: { active: type },
});
if (type === "constant") {
return meshPolygonsColorStyle.setMeshPolygonsColor(
id,
meshPolygonsColorStyle.meshPolygonsColor(id),
);
}
if (type === "textures") {
const textures = meshPolygonsTexturesStyle.meshPolygonsTextures(id);
return meshPolygonsTexturesStyle.setMeshPolygonsTextures(id, textures);
}
if (type === "vertex") {
const name = meshPolygonsVertexAttributeStyle.meshPolygonsVertexAttributeName(id);
const { colorMap } = meshPolygonsVertexAttributeStyle.meshPolygonsVertexAttributeStoredConfig(
id,
name,
);
return Promise.all([
meshPolygonsVertexAttributeStyle.setMeshPolygonsVertexAttributeName(id, name),
meshPolygonsVertexAttributeStyle.setMeshPolygonsVertexAttributeColorMap(id, colorMap),
]);
}
if (type === "polygon") {
const name = meshPolygonsPolygonAttributeStyle.meshPolygonsPolygonAttributeName(id);
const { colorMap } =
meshPolygonsPolygonAttributeStyle.meshPolygonsPolygonAttributeStoredConfig(id, name);
return Promise.all([
meshPolygonsPolygonAttributeStyle.setMeshPolygonsPolygonAttributeName(id, name),
meshPolygonsPolygonAttributeStyle.setMeshPolygonsPolygonAttributeColorMap(id, colorMap),
]);
}
throw new Error(`Unknown mesh polygons coloring type: ${type}`);
}
return {
meshPolygonsColoring,
meshPolygonsActiveColoring,
setMeshPolygonsActiveColoring,
...meshPolygonsColorStyle,
...meshPolygonsTexturesStyle,
...meshPolygonsVertexAttributeStyle,
...meshPolygonsPolygonAttributeStyle,
};
}
export function useMeshPolygonsStyle() {
const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle();
const meshPolygonsVisibility = useMeshPolygonsVisibilityStyle();
const coloringStyle = useMeshPolygonsColoringStyle();
function applyMeshPolygonsStyle(id) {
return Promise.all([
meshPolygonsVisibility.setMeshPolygonsVisibility(
id,
meshPolygonsVisibility.meshPolygonsVisibility(id),
),
coloringStyle.setMeshPolygonsActiveColoring(id, coloringStyle.meshPolygonsActiveColoring(id)),
]);
}
return {
...meshPolygonsCommonStyle,
...coloringStyle,
applyMeshPolygonsStyle,
...meshPolygonsVisibility,
};
}