Skip to content

Commit

Permalink
Merge pull request #1694 from xeokit/XCD-153-compensate-canvas-plugin…
Browse files Browse the repository at this point in the history
…-offset-snapshot

XCD-153 Compensate canvas offset when snapshotting a plugin
  • Loading branch information
xeolabs authored Oct 14, 2024
2 parents 5a3f897 + 99a9693 commit 6768d87
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {CameraControl} from "./scene/CameraControl/CameraControl.js";
import {MetaScene} from "./metadata/MetaScene.js";
import {LocaleService} from "./localization/LocaleService.js";
import html2canvas from 'html2canvas/dist/html2canvas.esm.js';
import {math} from "./scene/math/math.js";
import {transformToNode} from "../plugins/lib/ui/index.js";

/**
* The 3D Viewer at the heart of the xeokit SDK.
Expand Down Expand Up @@ -495,9 +497,13 @@ class Viewer {
//for all others keep the scale 1 otherwise it will keep multiplying the scale with the base scale of canvas
//resulting in increase/decreased size for the the canvas that is being overlapped
const scale = i == 0 ? snapshotCanvas.width / containerElement.clientWidth : 1;
const off = math.vec2([ 0, 0 ]);
transformToNode(canvas, containerElement, off);
await html2canvas(containerElement, {
canvas: snapshotCanvas,
backgroundColor: null,
x: off[0],
y: off[1],
scale
});
}
Expand Down

0 comments on commit 6768d87

Please sign in to comment.