Skip to content

Commit

Permalink
Added support to control initial visibility of elements prior to coll…
Browse files Browse the repository at this point in the history
…ision detection execution.

Signed-off-by: Tim Deubler <[email protected]>
  • Loading branch information
TerminalTim committed Dec 23, 2024
1 parent 9c91416 commit beaf79c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
10 changes: 4 additions & 6 deletions packages/display/src/displays/webgl/buffer/FeatureFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {addExtrude} from './addExtrude';
import {addIcon} from './addIcon';
import earcut from 'earcut';
import {calcBBox, getTextString, getValue, parseSizeValue, Style, StyleGroup} from '../../styleTools';
// import {calcBBox, getTextString, getValue as parseValue, parseSizeValue, Style, StyleGroup} from '../../styleTools';
import {defaultFont, wrapText} from '../../textUtils';
import {FontStyle, GlyphTexture} from '../GlyphTexture';
import {BBox, CollisionData, CollisionHandler} from '../CollisionHandler';
Expand Down Expand Up @@ -261,6 +260,7 @@ export class FeatureFactory {
rotationZ,
rotationY,
textAnchor
// !!this.collisionGroup
);
} else {
if (type == 'Model') {
Expand Down Expand Up @@ -334,14 +334,15 @@ export class FeatureFactory {
positionBuffer.data,
flexAttributes.a_texcoord.data,
rotationZ
// !!this.collisionGroup
);

groupBuffer.addUniform('u_texture', this.atlasManager.getTexture(src));
} else if (type == 'Circle' || type == 'Rect') {
const pointBuffer = ((group.buffer as PointBuffer) ||= new PointBuffer(isFlat));
positionBuffer = pointBuffer.flexAttributes.a_position;

addPoint(x, y, z, positionBuffer.data);
addPoint(x, y, z, positionBuffer.data /* !!this.collisionGroup*/);
} else if (type == 'Heatmap') {
const heatmapBuffer = ((group.buffer as HeatmapBuffer) ||= new HeatmapBuffer(isFlat));

Expand Down Expand Up @@ -400,6 +401,7 @@ export class FeatureFactory {
allowPointerEvents: boolean = true
): boolean {
const {tile, groups, tileSize} = this;
// this.collisionGroup = collisionGroup;
const level = this.z;
let flatPolyStart: number;
let flatPoly: FlatPolygon[];
Expand All @@ -411,11 +413,9 @@ export class FeatureFactory {
let font;
let fill;
let fillRGBA;
let fillAlpha;
let rotation;
let stroke;
let strokeRGBA;
let strokeAlpha;
let strokeWidth;
let strokeDasharray;
let strokeDashimage;
Expand Down Expand Up @@ -513,8 +513,6 @@ export class FeatureFactory {
stroke = UNDEF;
fillRGBA = UNDEF;
strokeRGBA = UNDEF;
fillAlpha = 1;
strokeAlpha = 1;
strokeWidth = UNDEF;
strokeDasharray = UNDEF;
strokeDashimage = UNDEF;
Expand Down
5 changes: 3 additions & 2 deletions packages/display/src/displays/webgl/buffer/addIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ export const addIcon = (
points: SimpleArray<number>, // number[],
vertex: number[],
texcoord: SimpleArray<number>, // number[],
rotation: number = 0
rotation: number = 0,
hide?: boolean
) => {
let {u1, u2, v1, v2} = atlas;

addPoint(x, y, z, vertex);
addPoint(x, y, z, vertex, hide);

// 10 bit rotation precision
rotation = Math.round(rotation * 1024 / 360);
Expand Down
8 changes: 5 additions & 3 deletions packages/display/src/displays/webgl/buffer/addPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import {FlexArray} from './templates/FlexArray';

const extentScale = 32;

export const addPoint = (x: number, y: number, z: number | boolean, vertex: number[]|FlexArray): number => {
export const addPoint = (x: number, y: number, z: number | boolean, vertex: number[]|FlexArray, hide?: boolean): number => {
let v = vertex.length;
const visible: number = hide === undefined ? 1 : Number(!hide);

// make room for direction vector bit1 and visibility bit0 (LSB)
x = x * extentScale << 2 | 1;
y = y * extentScale << 2 | 1;
x = x * extentScale << 2 | visible;
y = y * extentScale << 2 | visible;

// 0 ------ 1
// | `. |
Expand Down
9 changes: 6 additions & 3 deletions packages/display/src/displays/webgl/buffer/addText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const addText = (
glyphAtlas: GlyphAtlas,
rotationZ = 0,
rotationY: number | undefined,
textAnchor: ParsedStyleProperty<TextStyle['textAnchor']> | string = 'Center'
textAnchor: ParsedStyleProperty<TextStyle['textAnchor']> | string = 'Center',
hide?: boolean
) => {
const lineOffset = lines.length - 1;
const lineHeight = glyphAtlas.lineHeight;
Expand All @@ -60,9 +61,11 @@ const addText = (
let ty = glyphAtlas.baselineOffset + 0.5 * lineHeight * (lineOffset + lines.length * anchorOffset.y);
ty *= OFFSET_SCALE;

const visible: number = hide === undefined ? 1 : Number(!hide);

// LSB defines visibility, visible by default
cx = cx * EXTENT_SCALE << 1 | 1;
cy = cy * EXTENT_SCALE << 1 | 1;
cx = cx * EXTENT_SCALE << 1 | visible;
cy = cy * EXTENT_SCALE << 1 | visible;

// 10 bit rotation precision
rotationZ = Math.round(rotationZ * 1024 / 360);
Expand Down

0 comments on commit beaf79c

Please sign in to comment.