Skip to content

Commit

Permalink
skip forced reflows from HTMLSpriteGroup.render
Browse files Browse the repository at this point in the history
  • Loading branch information
sdumetz committed Oct 24, 2024
1 parent eb6975c commit f142b47
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions libs/ff-three/source/HTMLSpriteGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import HTMLSprite from "./HTMLSprite";

export { HTMLSprite };

interface IViewport{
x: number;
y: number;
width: number;
height: number;
overlay: HTMLElement;
}

/**
* THREE 3D object, grouping a number of HTML sprites.
*/
Expand Down Expand Up @@ -69,17 +77,17 @@ export default class HTMLSpriteGroup extends Object3D
* @param container HTML container element for the HTML elements.
* @param camera The camera used to render the 3D scene.
*/
render(container: HTMLElement, camera: Camera)
render(viewport: IViewport, camera: Camera)
{
if (!this.visible) {
return;
}
//Only get bounds once to prevent forced reflows while looping
const bounds = container.getBoundingClientRect();
const bounds = new DOMRect(viewport.x, viewport.y, viewport.width, viewport.height);
const children = this.children as HTMLSprite[];
for (let i = 0, n = children.length; i < n; ++i) {
const child = children[i];
const element = child.getHTMLElement(container);
const element = child.getHTMLElement(viewport.overlay);
if (element) {
child.renderHTMLElement(element, bounds, camera);
}
Expand Down
2 changes: 1 addition & 1 deletion source/client/components/CVAnnotationView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export default class CVAnnotationView extends CObject3D
}

const spriteGroup = this.object3D as HTMLSpriteGroup;
spriteGroup.render(viewport.overlay, context.camera);
spriteGroup.render(viewport, context.camera);

// Handle locking truncation for view animation only after
// the sprite has a chance to do an initial update.
Expand Down
2 changes: 1 addition & 1 deletion source/client/components/CVStaticAnnotationView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class CVStaticAnnotationView extends CObject3D
}

const spriteGroup = this.object3D as HTMLSpriteGroup;
spriteGroup.render(viewport.overlay, context.camera);
spriteGroup.render(viewport, context.camera);
}

dispose()
Expand Down

0 comments on commit f142b47

Please sign in to comment.