@webviz/subsurface-viewer 0.2.3 → 0.3.1

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 (35) hide show
  1. package/dist/DashSubsurfaceViewer.d.ts +4 -0
  2. package/dist/DashSubsurfaceViewer.js +28 -0
  3. package/dist/DashSubsurfaceViewer.js.map +1 -0
  4. package/dist/components/ViewAnnotation.d.ts +1 -2
  5. package/dist/components/ViewFooter.d.ts +1 -2
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/layers/grid3d/grid3dLayer.d.ts +3 -1
  10. package/dist/layers/grid3d/grid3dLayer.js.map +1 -1
  11. package/dist/layers/grid3d/privateLayer.d.ts +1 -1
  12. package/dist/layers/grid3d/privateLayer.js +1 -24
  13. package/dist/layers/grid3d/privateLayer.js.map +1 -1
  14. package/dist/layers/map/fragment.fs.glsl.d.ts +1 -1
  15. package/dist/layers/map/fragment.fs.glsl.js +8 -10
  16. package/dist/layers/map/fragment.fs.glsl.js.map +1 -1
  17. package/dist/layers/map/fragment_lines.glsl.d.ts +1 -1
  18. package/dist/layers/map/fragment_lines.glsl.js +0 -7
  19. package/dist/layers/map/fragment_lines.glsl.js.map +1 -1
  20. package/dist/layers/map/mapLayer.d.ts +4 -2
  21. package/dist/layers/map/mapLayer.js +74 -65
  22. package/dist/layers/map/mapLayer.js.map +1 -1
  23. package/dist/layers/map/privateMapLayer.d.ts +6 -42
  24. package/dist/layers/map/privateMapLayer.js +17 -42
  25. package/dist/layers/map/privateMapLayer.js.map +1 -1
  26. package/dist/layers/map/utils.d.ts +5 -0
  27. package/dist/layers/map/utils.js +425 -0
  28. package/dist/layers/map/utils.js.map +1 -0
  29. package/dist/layers/utils/layerTools.d.ts +11 -0
  30. package/dist/layers/utils/layerTools.js +37 -0
  31. package/dist/layers/utils/layerTools.js.map +1 -1
  32. package/package.json +1 -1
  33. package/dist/layers/map/webworker.d.ts +0 -4
  34. package/dist/layers/map/webworker.js +0 -366
  35. package/dist/layers/map/webworker.js.map +0 -1
@@ -4,46 +4,6 @@ import type { LayerPickInfo } from "../utils/layerTools";
4
4
  import { Model } from "@luma.gl/engine";
5
5
  import type { DeckGLLayerContext } from "../../components/Map";
6
6
  import type { ExtendedLayerProps, colorMapFunctionType } from "../utils/layerTools";
7
- export type MeshType = {
8
- drawMode?: number;
9
- attributes: {
10
- positions: {
11
- value: Float32Array;
12
- size: number;
13
- };
14
- TEXCOORD_0?: {
15
- value: Float32Array;
16
- size: number;
17
- };
18
- normals: {
19
- value: Float32Array;
20
- size: number;
21
- };
22
- properties: {
23
- value: Float32Array;
24
- size: number;
25
- };
26
- vertex_indexs: {
27
- value: Int32Array;
28
- size: number;
29
- };
30
- };
31
- vertexCount: number;
32
- indices: {
33
- value: Uint32Array;
34
- size: number;
35
- };
36
- };
37
- export type MeshTypeLines = {
38
- drawMode: number;
39
- attributes: {
40
- positions: {
41
- value: Float32Array;
42
- size: number;
43
- };
44
- };
45
- vertexCount: number;
46
- };
47
7
  export type Material = {
48
8
  ambient: number;
49
9
  diffuse: number;
@@ -51,8 +11,12 @@ export type Material = {
51
11
  specularColor: [number, number, number];
52
12
  } | boolean;
53
13
  export interface privateMapLayerProps extends ExtendedLayerProps {
54
- mesh: MeshType;
55
- meshLines: MeshTypeLines;
14
+ positions: Float32Array;
15
+ normals: Int8Array;
16
+ triangleIndices: Uint32Array;
17
+ vertexProperties: Float32Array;
18
+ vertexIndices: Int32Array;
19
+ lineIndices: Uint32Array;
56
20
  contours: [number, number];
57
21
  gridLines: boolean;
58
22
  isContoursDepth: boolean;
@@ -2,12 +2,11 @@ import { COORDINATE_SYSTEM, Layer, picking, project, } from "@deck.gl/core/typed
2
2
  import { localPhongLighting } from "../shader_modules";
3
3
  import { createPropertyData } from "../utils/layerTools";
4
4
  import { Model, Geometry } from "@luma.gl/engine";
5
+ import { getImageData } from "../utils/layerTools";
5
6
  import vsShader from "./vertex.glsl";
6
7
  import fsShader from "./fragment.fs.glsl";
7
8
  import vsLineShader from "./vertex_lines.glsl";
8
9
  import fsLineShader from "./fragment_lines.glsl";
9
- import { rgbValues } from "@emerson-eps/color-tables/";
10
- import { createDefaultContinuousColorScale } from "@emerson-eps/color-tables/dist/component/Utils/legendCommonFunction";
11
10
  import { Texture2D } from "@luma.gl/webgl";
12
11
  import GL from "@luma.gl/constants";
13
12
  const DEFAULT_TEXTURE_PARAMETERS = {
@@ -16,32 +15,6 @@ const DEFAULT_TEXTURE_PARAMETERS = {
16
15
  [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
17
16
  [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE,
18
17
  };
19
- function getImageData(colorMapName, colorTables, colorMapFunction) {
20
- const isColorMapFunctionDefined = typeof colorMapFunction !== "undefined";
21
- const isColorMapNameDefined = !!colorMapName;
22
- const defaultColorMap = createDefaultContinuousColorScale;
23
- let colorMap = defaultColorMap();
24
- if (isColorMapFunctionDefined) {
25
- colorMap =
26
- typeof colorMapFunction === "function"
27
- ? colorMapFunction
28
- : (() => colorMapFunction);
29
- }
30
- else if (isColorMapNameDefined) {
31
- colorMap = (value) => rgbValues(value, colorMapName, colorTables);
32
- }
33
- const data = new Uint8Array(256 * 3);
34
- for (let i = 0; i < 256; i++) {
35
- const value = i / 255.0;
36
- const color = colorMap ? colorMap(value) : [0, 0, 0];
37
- if (color) {
38
- data[3 * i + 0] = color[0];
39
- data[3 * i + 1] = color[1];
40
- data[3 * i + 2] = color[2];
41
- }
42
- }
43
- return data ? data : [0, 0, 0];
44
- }
45
18
  const defaultProps = {
46
19
  data: ["dummy"],
47
20
  contours: [-1, -1],
@@ -86,15 +59,11 @@ export default class privateMapLayer extends Layer {
86
59
  vs: vsShader,
87
60
  fs: fsShader,
88
61
  geometry: new Geometry({
89
- drawMode: this.props.mesh.drawMode,
90
- attributes: {
91
- positions: this.props.mesh.attributes.positions,
92
- normals: this.props.mesh.attributes.normals,
93
- properties: this.props.mesh.attributes.properties,
94
- vertex_indexs: this.props.mesh.attributes.vertex_indexs,
95
- },
96
- vertexCount: this.props.mesh.vertexCount,
97
- indices: this.props.mesh.indices,
62
+ drawMode: gl.TRIANGLES,
63
+ attributes: Object.assign(Object.assign({ positions: { value: this.props.positions, size: 3 } }, (this.props.normals.length > 0 && {
64
+ normals: { value: this.props.normals, size: 3 },
65
+ })), { properties: { value: this.props.vertexProperties, size: 1 }, vertex_indexs: { value: this.props.vertexIndices, size: 1 } }),
66
+ indices: { value: this.props.triangleIndices, size: 1 },
98
67
  }),
99
68
  modules: [project, picking, localPhongLighting],
100
69
  isInstanced: false, // This only works when set to false.
@@ -104,8 +73,14 @@ export default class privateMapLayer extends Layer {
104
73
  id: `${this.props.id}-lines`,
105
74
  vs: vsLineShader,
106
75
  fs: fsLineShader,
107
- geometry: new Geometry(this.props.meshLines),
108
- modules: [project, picking],
76
+ geometry: new Geometry({
77
+ drawMode: gl.LINES,
78
+ attributes: {
79
+ positions: { value: this.props.positions, size: 3 },
80
+ },
81
+ indices: { value: this.props.lineIndices, size: 1 },
82
+ }),
83
+ modules: [project],
109
84
  isInstanced: false,
110
85
  });
111
86
  return [mesh_model, mesh_lines_model];
@@ -140,7 +115,7 @@ export default class privateMapLayer extends Layer {
140
115
  // @ts-ignore
141
116
  colorMapClampColor = colorMapClampColor.map((x) => (x !== null && x !== void 0 ? x : 0) / 255);
142
117
  const isColorMapClampColorTransparent = this.props.colorMapClampColor === false;
143
- const smoothShading = this.props.smoothShading;
118
+ const smoothShading = this.props.normals.length == 0 ? false : this.props.smoothShading;
144
119
  gl.enable(GL.POLYGON_OFFSET_FILL);
145
120
  if (!this.props.depthTest) {
146
121
  gl.disable(GL.DEPTH_TEST);
@@ -189,10 +164,10 @@ export default class privateMapLayer extends Layer {
189
164
  const g = info.color[1];
190
165
  const b = info.color[2];
191
166
  const vertexIndex = 256 * 256 * r + 256 * g + b;
192
- const vertexs = this.props.mesh.attributes.positions.value;
167
+ const vertexs = this.props.positions;
193
168
  const depth = -vertexs[3 * vertexIndex + 2];
194
169
  layer_properties.push(createPropertyData("Depth", depth));
195
- const properties = this.props.mesh.attributes.properties.value;
170
+ const properties = this.props.vertexProperties;
196
171
  const property = properties[vertexIndex];
197
172
  layer_properties.push(createPropertyData("Property", property));
198
173
  return Object.assign(Object.assign({}, info), { properties: layer_properties });
@@ -1 +1 @@
1
- {"version":3,"file":"privateMapLayer.js","sourceRoot":"","sources":["../../../src/layers/map/privateMapLayer.ts"],"names":[],"mappings":"AACA,OAAO,EACH,iBAAiB,EACjB,KAAK,EACL,OAAO,EACP,OAAO,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAMlD,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAC/C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAGjD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,iCAAiC,EAAE,MAAM,qEAAqE,CAAC;AACxH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEpC,MAAM,0BAA0B,GAAG;IAC/B,CAAC,EAAE,CAAC,kBAAkB,CAAC,EAAE,EAAE,CAAC,oBAAoB;IAChD,CAAC,EAAE,CAAC,kBAAkB,CAAC,EAAE,EAAE,CAAC,MAAM;IAClC,CAAC,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,aAAa;IACrC,CAAC,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,aAAa;CACxC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I,EAAyB;QAC1C,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACb,OAAO,IAAI,CAAC;SACf;QAED,MAAM,gBAAgB,GAAuB,EAAE,CAAC;QAEhD,6CAA6C;QAC7C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAExB,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QAEhD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;QACrC,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC;QAC5C,gBAAgB,CAAC,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;QAE1D,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC;QAC/C,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;QACzC,gBAAgB,CAAC,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;QAEhE,uCACO,IAAI,KACP,UAAU,EAAE,gBAAgB,IAC9B;IACN,CAAC;CACJ;AAED,eAAe,CAAC,SAAS,GAAG,iBAAiB,CAAC;AAC9C,eAAe,CAAC,YAAY,GAAG,YAAY,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Params } from "./mapLayer";
2
+ /** Given the input data will build and return the attributes (vertices and indices for triangles and lines)
3
+ * that is used by WebGl. Using indice, lines and triangles share common vertices to save memory.
4
+ */
5
+ export declare function makeFullMesh(params: Params): (number[] | Float32Array | Int8Array | Int32Array | Uint32Array)[];
@@ -0,0 +1,425 @@
1
+ function getFloat32ArrayMinMax(data) {
2
+ let max = -99999999;
3
+ let min = 99999999;
4
+ for (let i = 0; i < data.length; i++) {
5
+ max = data[i] > max ? data[i] : max;
6
+ min = data[i] < min ? data[i] : min;
7
+ }
8
+ return [min, max];
9
+ }
10
+ function crossProduct(a, b) {
11
+ const c = [
12
+ a[1] * b[2] - a[2] * b[1],
13
+ a[2] * b[0] - a[0] * b[2],
14
+ a[0] * b[1] - a[1] * b[0],
15
+ ];
16
+ return c;
17
+ }
18
+ // Check if a number exists and has a defined value.
19
+ function isDefined(x) {
20
+ return typeof x === "number" && !isNaN(x);
21
+ }
22
+ function normalize(a) {
23
+ const L = Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
24
+ a[0] /= L;
25
+ a[1] /= L;
26
+ a[2] /= L;
27
+ }
28
+ function calcNormal(w, h, nx, ny, isMesh, smoothShading, meshData, ox, oy, dx, dy, multZ) {
29
+ if (!smoothShading) {
30
+ return [1, 1, 1];
31
+ }
32
+ if (!isMesh) {
33
+ return [0, 0, 1];
34
+ }
35
+ const i0 = h * nx + w;
36
+ const i1 = h * nx + (w - 1);
37
+ const i2 = (h + 1) * nx + w;
38
+ const i3 = h * nx + (w + 1);
39
+ const i4 = (h - 1) * nx + w;
40
+ const i0_act = isDefined(meshData[i0]); // eslint-disable-line
41
+ const i1_act = (w - 1) >= 0 && isDefined(meshData[i1]); // eslint-disable-line
42
+ const i2_act = (h + 1) < ny && isDefined(meshData[i2]); // eslint-disable-line
43
+ const i3_act = (w + 1) < nx && isDefined(meshData[i3]); // eslint-disable-line
44
+ const i4_act = (h - 1) >= 0 && isDefined(meshData[i4]); // eslint-disable-line
45
+ const noNormal = [0, 0, 0]; // signals a normal could not be calculated.
46
+ if (!i0_act) {
47
+ return noNormal;
48
+ }
49
+ const hh = ny - 1 - h; // Note use hh for h for getting y values.
50
+ const p0 = [ox + w * dx, oy + hh * dy, i0_act ? -meshData[i0] * multZ : 0]; // eslint-disable-line
51
+ const p1 = [ox + (w - 1) * dx, oy + hh * dy, i1_act ? -meshData[i1] * multZ : 0]; // eslint-disable-line
52
+ const p2 = [ox + w * dx, oy + (hh + 1) * dy, i2_act ? -meshData[i2] * multZ : 0]; // eslint-disable-line
53
+ const p3 = [ox + (w + 1) * dx, oy + hh * dy, i3_act ? -meshData[i3] * multZ : 0]; // eslint-disable-line
54
+ const p4 = [ox + w * dx, oy + (hh - 1) * dy, i4_act ? -meshData[i4] * multZ : 0]; // eslint-disable-line
55
+ const v1 = [p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]];
56
+ const v2 = [p2[0] - p0[0], p2[1] - p0[1], p2[2] - p0[2]];
57
+ const v3 = [p3[0] - p0[0], p3[1] - p0[1], p3[2] - p0[2]];
58
+ const v4 = [p4[0] - p0[0], p4[1] - p0[1], p4[2] - p0[2]];
59
+ // Estimating a normal vector at p0:
60
+ // Take cross product of vectors v1, v2,
61
+ // Do this for all 4 quadrants.
62
+ // The resulting normal will be the mean of these four normals.
63
+ // p2
64
+ // |
65
+ // p1 - p0 - p3
66
+ // |
67
+ // p4
68
+ const normals = [];
69
+ if (i1_act && i2_act) {
70
+ const normal = crossProduct(v2, v1);
71
+ normals.push(normal);
72
+ }
73
+ if (i2_act && i3_act) {
74
+ const normal = crossProduct(v3, v2);
75
+ normals.push(normal);
76
+ }
77
+ if (i3_act && i4_act) {
78
+ const normal = crossProduct(v4, v3);
79
+ normals.push(normal);
80
+ }
81
+ if (i4_act && i1_act) {
82
+ const normal = crossProduct(v1, v4);
83
+ normals.push(normal);
84
+ }
85
+ if (normals.length === 0) {
86
+ return noNormal;
87
+ }
88
+ const mean = normals[0];
89
+ for (let i = 1; i < normals.length; i++) {
90
+ mean[0] += normals[i][0];
91
+ mean[1] += normals[i][1];
92
+ mean[2] += normals[i][2];
93
+ }
94
+ normalize(mean);
95
+ return mean;
96
+ }
97
+ /** Given the input data will build and return the attributes (vertices and indices for triangles and lines)
98
+ * that is used by WebGl. Using indice, lines and triangles share common vertices to save memory.
99
+ */
100
+ export function makeFullMesh(params) {
101
+ // Keep
102
+ //const t0 = performance.now();
103
+ const meshData = params.meshData;
104
+ const propertiesData = params.propertiesData;
105
+ const isMesh = params.isMesh;
106
+ const frame = params.frame;
107
+ const smoothShading = params.smoothShading;
108
+ const gridLines = params.gridLines;
109
+ const ZIncreasingDownwards = params.ZIncreasingDownwards;
110
+ const multZ = ZIncreasingDownwards ? 1 : -1;
111
+ const meshZValueRange = getFloat32ArrayMinMax(meshData);
112
+ const propertyValueRange = getFloat32ArrayMinMax(propertiesData);
113
+ // Dimensions.
114
+ const ox = frame.origin[0];
115
+ const oy = frame.origin[1];
116
+ const dx = frame.increment[0];
117
+ const dy = frame.increment[1];
118
+ const nx = frame.count[0]; // number of nodes in x direction
119
+ const ny = frame.count[1];
120
+ const propLength = propertiesData.length;
121
+ const isCellCenteredProperties = propLength === (nx - 1) * (ny - 1);
122
+ if (propLength !== (nx - 1) * (ny - 1) && propLength !== nx * ny) {
123
+ console.error("There should be as many property values as nodes (nx*ny) OR as many as cells (nx - 1) * (ny - 1).");
124
+ }
125
+ const nNodes = nx * ny;
126
+ const nCells = (nx - 1) * (ny - 1);
127
+ const nTriangles = nCells * 2;
128
+ const positions = new Float32Array(isCellCenteredProperties ? nCells * 6 * 3 : nNodes * 3);
129
+ const normals = new Int8Array(isCellCenteredProperties || !smoothShading ? 0 : nNodes * 3);
130
+ const triangleIndices = new Uint32Array(nTriangles * 3);
131
+ const vertexProperties = new Float32Array(isCellCenteredProperties ? nCells * 6 : nNodes);
132
+ const vertexIndices = new Int32Array(isCellCenteredProperties ? nCells * 6 : nNodes);
133
+ let nLineIndices = 0;
134
+ if (gridLines) {
135
+ nLineIndices = isCellCenteredProperties
136
+ ? nTriangles * 2 * 2
137
+ : nCells * 4 + (nx - 1) * 2 + (ny - 1) * 2;
138
+ }
139
+ const lineIndices = new Uint32Array(nLineIndices);
140
+ // Note: Assumed layout of the incomming 2D array of data:
141
+ // First coloumn corresponds to lowest x value. Last column highest x value.
142
+ // First row corresponds to max y value. Last row corresponds to lowest y value.
143
+ // This must be taken into account when calculating vertex x,y values and texture coordinates.
144
+ if (!isCellCenteredProperties) {
145
+ // PROPERTIES IS SET INTERPOLATED OVER A CELL.
146
+ // Loop vertices.
147
+ let i = 0;
148
+ for (let h = 0; h < ny; h++) {
149
+ for (let w = 0; w < nx; w++) {
150
+ const i0 = h * nx + w;
151
+ const x0 = ox + w * dx;
152
+ const y0 = oy + (ny - 1 - h) * dy; // See note above.
153
+ const z = isMesh ? -meshData[i0] * multZ : 0;
154
+ const propertyValue = propertiesData[i0];
155
+ positions[3 * i + 0] = x0;
156
+ positions[3 * i + 1] = y0;
157
+ positions[3 * i + 2] = z;
158
+ if (smoothShading) {
159
+ const normal = calcNormal(w, h, nx, ny, isMesh, smoothShading, meshData, ox, oy, dx, dy, multZ); // eslint-disable-line
160
+ normals[3 * i + 0] = normal[0] * 127; // Normalize to signed 8 bit.
161
+ normals[3 * i + 1] = normal[1] * 127;
162
+ normals[3 * i + 2] = normal[2] * 127;
163
+ }
164
+ vertexProperties[i] = propertyValue;
165
+ vertexIndices[i] = i;
166
+ i++;
167
+ }
168
+ }
169
+ // Loop cells.
170
+ i = 0;
171
+ let j = 0;
172
+ for (let h = 0; h < ny - 1; h++) {
173
+ for (let w = 0; w < nx - 1; w++) {
174
+ const i0 = h * nx + w;
175
+ const i1 = h * nx + (w + 1);
176
+ const i2 = (h + 1) * nx + (w + 1);
177
+ const i3 = (h + 1) * nx + w;
178
+ const i0_act = !isMesh || (isDefined(meshData[i0]) && isDefined(propertiesData[i0])); // eslint-disable-line
179
+ const i1_act = !isMesh || (isDefined(meshData[i1]) && isDefined(propertiesData[i1])); // eslint-disable-line
180
+ const i2_act = !isMesh || (isDefined(meshData[i2]) && isDefined(propertiesData[i2])); // eslint-disable-line
181
+ const i3_act = !isMesh || (isDefined(meshData[i3]) && isDefined(propertiesData[i3])); // eslint-disable-line
182
+ // Triangles.
183
+ if (i1_act && i3_act) {
184
+ // diagonal i1, i3
185
+ if (i0_act) {
186
+ // t1 - i0 provoking index.
187
+ triangleIndices[i++] = i1;
188
+ triangleIndices[i++] = i3;
189
+ triangleIndices[i++] = i0;
190
+ }
191
+ if (i2_act) {
192
+ // t2 - i2 provoking index.
193
+ triangleIndices[i++] = i1;
194
+ triangleIndices[i++] = i3;
195
+ triangleIndices[i++] = i2;
196
+ }
197
+ }
198
+ else if (i0_act && i2_act) {
199
+ // diagonal i0, i2
200
+ if (i1_act) {
201
+ // t1 - i0 provoking index.
202
+ triangleIndices[i++] = i1;
203
+ triangleIndices[i++] = i2;
204
+ triangleIndices[i++] = i0;
205
+ }
206
+ if (i3_act) {
207
+ // t2 - i2 provoking index.
208
+ triangleIndices[i++] = i3;
209
+ triangleIndices[i++] = i0;
210
+ triangleIndices[i++] = i2;
211
+ }
212
+ }
213
+ // Lines.
214
+ if (gridLines) {
215
+ if (i0_act && i1_act) {
216
+ lineIndices[j++] = i0;
217
+ lineIndices[j++] = i1;
218
+ }
219
+ if (i0_act && i3_act) {
220
+ lineIndices[j++] = i0;
221
+ lineIndices[j++] = i3;
222
+ }
223
+ if (h == ny - 2 && i2_act && i3_act) {
224
+ lineIndices[j++] = i3;
225
+ lineIndices[j++] = i2;
226
+ }
227
+ if (w == nx - 2 && i1_act && i2_act) {
228
+ lineIndices[j++] = i1;
229
+ lineIndices[j++] = i2;
230
+ }
231
+ // diagonal
232
+ if ((i0_act && !i2_act) || (!i0_act && i2_act)) {
233
+ lineIndices[j++] = i1;
234
+ lineIndices[j++] = i3;
235
+ }
236
+ // diagonal
237
+ if ((i3_act && !i1_act) || (!i3_act && i1_act)) {
238
+ lineIndices[j++] = i0;
239
+ lineIndices[j++] = i2;
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }
245
+ else {
246
+ // PROPERTIES IS SET CONSTANT OVER A CELL.
247
+ // Loop cells.
248
+ let i = 0;
249
+ let j = 0;
250
+ let k = 0;
251
+ let l = 0;
252
+ for (let h = 0; h < ny - 1; h++) {
253
+ for (let w = 0; w < nx - 1; w++) {
254
+ const hh = ny - 1 - h; // See note above.
255
+ const i0 = h * nx + w;
256
+ const i1 = h * nx + (w + 1);
257
+ const i2 = (h + 1) * nx + (w + 1);
258
+ const i3 = (h + 1) * nx + w;
259
+ const i0_act = !isMesh || isDefined(meshData[i0]); // eslint-disable-line
260
+ const i1_act = !isMesh || isDefined(meshData[i1]); // eslint-disable-line
261
+ const i2_act = !isMesh || isDefined(meshData[i2]); // eslint-disable-line
262
+ const i3_act = !isMesh || isDefined(meshData[i3]); // eslint-disable-line
263
+ const x0 = ox + w * dx;
264
+ const y0 = oy + hh * dy;
265
+ const z0 = isMesh ? -meshData[i0] * multZ : 0;
266
+ const x1 = ox + (w + 1) * dx;
267
+ const y1 = oy + hh * dy;
268
+ const z1 = isMesh ? -meshData[i1] * multZ : 0;
269
+ const x2 = ox + (w + 1) * dx;
270
+ const y2 = oy + (hh - 1) * dy; // Note hh - 1 here.
271
+ const z2 = isMesh ? -meshData[i2] * multZ : 0;
272
+ const x3 = ox + w * dx;
273
+ const y3 = oy + (hh - 1) * dy; // Note hh - 1 here.
274
+ const z3 = isMesh ? -meshData[i3] * multZ : 0;
275
+ const propertyIndex = h * (nx - 1) + w; // (nx - 1) -> the width of the property 2D array is one less than for the nodes in this case.
276
+ const propertyValue = propertiesData[propertyIndex];
277
+ if (!isDefined(propertyValue)) {
278
+ // Inactive cell, dont draw.
279
+ continue;
280
+ }
281
+ // Triangles.
282
+ if (i1_act && i3_act) {
283
+ // diagonal i1, i3
284
+ if (i0_act) {
285
+ // t1 - i0 provoking index.
286
+ triangleIndices[i] = i;
287
+ const L1 = i;
288
+ i++;
289
+ positions[j++] = x1;
290
+ positions[j++] = y1;
291
+ positions[j++] = z1;
292
+ triangleIndices[i] = i;
293
+ const L2 = i;
294
+ i++;
295
+ positions[j++] = x3;
296
+ positions[j++] = y3;
297
+ positions[j++] = z3;
298
+ triangleIndices[i] = i;
299
+ const L3 = i;
300
+ i++;
301
+ positions[j++] = x0;
302
+ positions[j++] = y0;
303
+ positions[j++] = z0;
304
+ if (gridLines) {
305
+ lineIndices[l++] = L3;
306
+ lineIndices[l++] = L1;
307
+ lineIndices[l++] = L3;
308
+ lineIndices[l++] = L2;
309
+ }
310
+ vertexProperties[k++] = propertyValue;
311
+ vertexProperties[k++] = propertyValue;
312
+ vertexProperties[k++] = propertyValue;
313
+ }
314
+ if (i2_act) {
315
+ // t2 - i2 provoking index.
316
+ triangleIndices[i] = i;
317
+ const L1 = i;
318
+ i++;
319
+ positions[j++] = x1;
320
+ positions[j++] = y1;
321
+ positions[j++] = z1;
322
+ triangleIndices[i] = i;
323
+ const L2 = i;
324
+ i++;
325
+ positions[j++] = x3;
326
+ positions[j++] = y3;
327
+ positions[j++] = z3;
328
+ triangleIndices[i] = i;
329
+ const L3 = i;
330
+ i++;
331
+ positions[j++] = x2;
332
+ positions[j++] = y2;
333
+ positions[j++] = z2;
334
+ if (gridLines) {
335
+ lineIndices[l++] = L1;
336
+ lineIndices[l++] = L3;
337
+ lineIndices[l++] = L2;
338
+ lineIndices[l++] = L3;
339
+ }
340
+ vertexProperties[k++] = propertyValue;
341
+ vertexProperties[k++] = propertyValue;
342
+ vertexProperties[k++] = propertyValue;
343
+ }
344
+ }
345
+ else if (i0_act && i2_act) {
346
+ // diagonal i0, i2
347
+ if (i1_act) {
348
+ //t1 - i0 provoking index.
349
+ triangleIndices[i] = i;
350
+ const L1 = i;
351
+ i++;
352
+ positions[j++] = x1;
353
+ positions[j++] = y1;
354
+ positions[j++] = z1;
355
+ triangleIndices[i] = i;
356
+ const L2 = i;
357
+ i++;
358
+ positions[j++] = x2;
359
+ positions[j++] = y2;
360
+ positions[j++] = z2;
361
+ triangleIndices[i] = i;
362
+ const L3 = i;
363
+ i++;
364
+ positions[j++] = x0;
365
+ positions[j++] = y0;
366
+ positions[j++] = z0;
367
+ if (gridLines) {
368
+ lineIndices[l++] = L1;
369
+ lineIndices[l++] = L3;
370
+ lineIndices[l++] = L1;
371
+ lineIndices[l++] = L2;
372
+ }
373
+ vertexProperties[k++] = propertyValue;
374
+ vertexProperties[k++] = propertyValue;
375
+ vertexProperties[k++] = propertyValue;
376
+ }
377
+ if (i3_act) {
378
+ // t2 - i2 provoking index.
379
+ triangleIndices[i] = i;
380
+ const L1 = i;
381
+ i++;
382
+ positions[j++] = x3;
383
+ positions[j++] = y3;
384
+ positions[j++] = z3;
385
+ triangleIndices[i] = i;
386
+ const L2 = i;
387
+ i++;
388
+ positions[j++] = x0;
389
+ positions[j++] = y0;
390
+ positions[j++] = z0;
391
+ triangleIndices[i] = i;
392
+ const L3 = i;
393
+ i++;
394
+ positions[j++] = x2;
395
+ positions[j++] = y2;
396
+ positions[j++] = z2;
397
+ if (gridLines) {
398
+ lineIndices[l++] = L1;
399
+ lineIndices[l++] = L2;
400
+ lineIndices[l++] = L1;
401
+ lineIndices[l++] = L3;
402
+ }
403
+ vertexProperties[k++] = propertyValue;
404
+ vertexProperties[k++] = propertyValue;
405
+ vertexProperties[k++] = propertyValue;
406
+ }
407
+ }
408
+ }
409
+ }
410
+ }
411
+ // Keep this.
412
+ // const t1 = performance.now();
413
+ // console.debug(`Task makeMesh took ${(t1 - t0) * 0.001} seconds.`);
414
+ return [
415
+ positions,
416
+ normals,
417
+ triangleIndices,
418
+ vertexProperties,
419
+ vertexIndices,
420
+ lineIndices,
421
+ meshZValueRange,
422
+ propertyValueRange,
423
+ ];
424
+ }
425
+ //# sourceMappingURL=utils.js.map