Skip to content

Commit

Permalink
feat(front): add selectable items to highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Aug 12, 2024
1 parent f23e80a commit 68a0440
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/core/ShadowedScene/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export interface ShadowedSceneConfig extends SimpleSceneConfig {
}

// TODO: Implement multiple cascade shadow maps (the main problem to solve is the shadow camera rotation)
// A trick to do this is that the camera direction vector is one of the axis of the camera shadow frustum
// when projected to the near frustum plane. So now we have 2 vectors (the vector of the light direction
// and this vector), so the third vector is known (cross product) and the frustum direction can be built
// as a matrix

/**
* A scene that supports efficient cast shadows.
Expand Down
4 changes: 4 additions & 0 deletions packages/front/src/fragments/Highlighter/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ highlighter.events.select.onHighlight.add((data) => {
outliner.add("example", data);
});

highlighter.events.select.onClear.add(() => {
outliner.clear("example");
});

/* MD
### ⏱️ Measuring the performance (optional)
---
Expand Down
27 changes: 23 additions & 4 deletions packages/front/src/fragments/Highlighter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export class Highlighter
/** Styles with auto toggle will be unselected when selected twice. */
autoToggle = new Set<string>();

/** If defined, only the specified elements will be selected by the specified style. */
selectable: { [name: string]: FragmentIdMap } = {};

// Highlights the clipping fills of the fragments, if any
private _fills = new FillHighlighter();

Expand Down Expand Up @@ -325,6 +328,11 @@ export class Highlighter
) {
if (!this.enabled) return;

let previousSelection: FRAGS.FragmentIdMap = {};
if (this.selection[name]) {
previousSelection = { ...this.selection[name] };
}

if (removePrevious) {
this.clear(name);
}
Expand All @@ -343,12 +351,23 @@ export class Highlighter
const excludeFrag = exclude[fragID];

for (const id of ids) {
if (!excludeFrag || !excludeFrag.has(id)) {
if (!filtered[fragID]) {
filtered[fragID] = new Set();
// Is filtered by the parameter
if (excludeFrag && excludeFrag.has(id)) {
continue;
}

// Is filtered by the selectable property
if (this.selectable[name]) {
const map = this.selectable[name];
if (!map[fragID] || !map[fragID].has(id)) {
continue;
}
filtered[fragID].add(id);
}

if (!filtered[fragID]) {
filtered[fragID] = new Set();
}
filtered[fragID].add(id);
}
}

Expand Down

0 comments on commit 68a0440

Please sign in to comment.