-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cull labels when not readable #267
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Ticker } from 'pixi.js' | ||
import { DEFAULT_LABEL_CULLING_THRESHOLD } from '@/consts' | ||
import { waitForEvent } from '@/objects/events' | ||
import { waitForViewport } from '@/objects/viewport' | ||
import { LabelCull } from '@/services/labelCull' | ||
|
||
let instance: LabelCull | null = null | ||
let callback: (() => void) | null = null | ||
|
||
export async function startLabelCulling(): Promise<void> { | ||
const viewport = await waitForViewport() | ||
|
||
instance = new LabelCull() | ||
|
||
callback = (): void => { | ||
if (viewport.dirty) { | ||
const visible = viewport.scale.x > DEFAULT_LABEL_CULLING_THRESHOLD | ||
|
||
instance?.toggle(visible) | ||
} | ||
} | ||
|
||
Ticker.shared.add(callback) | ||
} | ||
|
||
export function stopLabelCulling(): void { | ||
if (callback) { | ||
Ticker.shared.remove(callback) | ||
} | ||
|
||
instance?.clear() | ||
instance = null | ||
callback = null | ||
} | ||
|
||
export async function waitForLabelCull(): Promise<LabelCull> { | ||
if (instance) { | ||
return instance | ||
} | ||
|
||
return await waitForEvent('labelCullCreated') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { DisplayObject } from 'pixi.js' | ||
|
||
type LabelCullStatus = 'hidden' | 'visible' | ||
|
||
// This label culler intentionally uses the `visible` property to show and hide labels | ||
// this is because the viewport culling uses the `renderable` property and will interfere | ||
// if the same property is used | ||
export class LabelCull { | ||
private status: LabelCullStatus = 'visible' | ||
private readonly labels = new Set<DisplayObject>() | ||
|
||
private get visible(): boolean { | ||
return this.status === 'visible' | ||
} | ||
|
||
private get hidden(): boolean { | ||
return this.status === 'hidden' | ||
} | ||
|
||
public show(): void { | ||
if (this.status === 'visible') { | ||
return | ||
} | ||
|
||
for (const label of this.labels) { | ||
label.visible = true | ||
} | ||
|
||
this.status = 'visible' | ||
} | ||
|
||
public hide(): void { | ||
if (this.status === 'hidden') { | ||
return | ||
} | ||
|
||
for (const label of this.labels) { | ||
label.visible = false | ||
} | ||
|
||
this.status = 'hidden' | ||
} | ||
|
||
public toggle(visible: boolean): void { | ||
if (visible) { | ||
this.show() | ||
} else { | ||
this.hide() | ||
} | ||
} | ||
|
||
public add(label: DisplayObject): void { | ||
this.labels.add(label) | ||
|
||
label.visible = this.visible | ||
} | ||
|
||
public clear(): void { | ||
this.labels.clear() | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed this wasn't working before. Need to wait until AFTER everything is rendered before calling
cull
This made me realize this is highly inefficient to render things and then cull them. But its working for now. It would be much more efficient to not render things initially and then render them if they are visible. Think we could accomplish that by setting
renderable = false
on nodes when creating them (before adding them as children). Might mess with that later but for now this works well. Just a bad fps drop when you open a sub node with a lot of nodes because they must all be rendered and then once they are culled the fps jumps back up.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that when a flow is first drawn, all nodes are made visible. I guess it does matter for labels in this case though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, its rendered and then culled. Which is my point here. Unless you're getting at something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Na at first I thought you may be thinking about the nodes, which will all be visible at first anyway. Ignore me, haha.