Skip to content

Commit 5d055e3

Browse files
committed
Add support for displaying and configuring wireframe in LayerStyles for debugging
Signed-off-by: Tim Deubler <[email protected]>
1 parent 7d5a045 commit 5d055e3

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

packages/core/src/styles/LayerStyle.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,4 +446,21 @@ export interface LayerStyle {
446446
* If no `zLayer` is defined, the display layer order is used by default.
447447
*/
448448
zLayer?: number;
449+
450+
451+
/**
452+
* Specifies whether to display a wireframe for debugging purposes.
453+
* Currently only supported for `Model` styles.
454+
*
455+
* - If set to `true`, the wireframe will be shown with an automatically inverted color
456+
* relative to the main color of the layer.
457+
* - If set to a `Color`, the wireframe will be displayed in the specified color.
458+
* - If set to `false`, the wireframe will not be shown.
459+
*
460+
* Default is `false`.
461+
*
462+
* @hidden
463+
* @internal
464+
*/
465+
showWireframe?: boolean | Color;
449466
}

packages/display/src/displays/webgl/buffer/createBuffer.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20-
import {TaskManager} from '@here/xyz-maps-common';
20+
import {Color as Colors, TaskManager} from '@here/xyz-maps-common';
2121
import {GeometryBuffer} from './GeometryBuffer';
2222
import {getPolygonCenter, getValue} from '../../styleTools';
2323
import {
24-
Feature,
24+
Feature, LayerStyle,
2525
LinearGradient,
2626
StyleGroup,
2727
Tile,
@@ -101,7 +101,8 @@ type TaskData = {
101101
layer: Layer,
102102
zoom: number,
103103
collisions: null | CollisionGroup[],
104-
groups: GroupMap
104+
groups: GroupMap,
105+
showWireframe: LayerStyle['showWireframe']
105106
};
106107

107108

@@ -144,6 +145,8 @@ const createBuffer = (
144145

145146
factory.init(tile, groups, tileSize, zoom, layerStyles.zLayer, waitAndRefresh);
146147

148+
const {showWireframe} = layerStyles;
149+
147150
return {
148151
tile,
149152
data: tile.data || [],
@@ -153,7 +156,8 @@ const createBuffer = (
153156
layer: displayLayer,
154157
zoom,
155158
collisions: null,
156-
groups
159+
groups,
160+
showWireframe: (showWireframe && typeof showWireframe != 'boolean') ? Colors.toRGB(showWireframe): showWireframe
157161
};
158162
},
159163

@@ -363,6 +367,22 @@ const createBuffer = (
363367
geoBuffer.destroy = (grpBuffer as ModelBuffer).destroy || geoBuffer.destroy;
364368
geoBuffer.depth = true;
365369

370+
const {showWireframe}= taskData;
371+
if (showWireframe) {
372+
const wireFrame = geoBuffer.addGroup(
373+
(grpBuffer as ModelBuffer).generateWireframeIndices(),
374+
grpBuffer.i32,
375+
GeometryBuffer.MODE_GL_LINES
376+
);
377+
378+
wireFrame.uniforms = {
379+
// invert diffuse color for wireframe
380+
diffuse: <number[]>(showWireframe === true
381+
? geoBuffer.uniforms.diffuse
382+
: showWireframe).slice(0, 3).map((c)=>1-c)
383+
};
384+
}
385+
366386
if (geoBuffer.uniforms.pointSize) {
367387
geoBuffer.groups[0].mode = GeometryBuffer.MODE_GL_POINTS;
368388
}

packages/display/src/displays/webgl/buffer/templates/ModelBuffer.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,4 +582,35 @@ export class ModelBuffer extends TemplateBuffer {
582582
}
583583
}
584584
}
585+
586+
generateWireframeIndices(): Uint16Array | Uint32Array {
587+
const triangleIndices: ArrayLike<number> = this.index();
588+
const edgeSet = new Set<string>();
589+
const lines: number[] = [];
590+
591+
for (let i = 0; i < triangleIndices.length; i += 3) {
592+
const i0 = triangleIndices[i];
593+
const i1 = triangleIndices[i + 1];
594+
const i2 = triangleIndices[i + 2];
595+
596+
const edges: [number, number][] = [
597+
[i0, i1],
598+
[i1, i2],
599+
[i2, i0]
600+
];
601+
602+
for (const [a, b] of edges) {
603+
const key = a < b ? `${a};${b}` : `${b};${a}`;
604+
if (!edgeSet.has(key)) {
605+
edgeSet.add(key);
606+
lines.push(a, b);
607+
}
608+
}
609+
}
610+
611+
const IndexArrayConstructor =
612+
triangleIndices instanceof Uint32Array ? Uint32Array : Uint16Array;
613+
614+
return new IndexArrayConstructor(lines);
615+
}
585616
}

0 commit comments

Comments
 (0)