Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cae9463

Browse files
committed
fix(pointcloud): Add SSE calculation for orthographic projections
1 parent 356e695 commit cae9463

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/Layer/PointCloudLayer.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function initBoundingBox(elt, layer) {
2626
elt.obj.boxHelper.updateMatrixWorld();
2727
}
2828

29-
function computeScreenSpaceError(context, pointSize, spacing, elt, distance) {
29+
function computeSSEPerspective(context, pointSize, spacing, elt, distance) {
3030
if (distance <= 0) {
3131
return Infinity;
3232
}
@@ -40,6 +40,30 @@ function computeScreenSpaceError(context, pointSize, spacing, elt, distance) {
4040
return Math.max(0.0, onScreenSpacing - pointSize);
4141
}
4242

43+
function computeSSEOrthographic(context, pointSize, spacing, elt) {
44+
const pointSpacing = spacing / 2 ** elt.depth;
45+
46+
// Given an identity view matrix, project pointSpacing from world space to
47+
// clip space. v' = vVP = vP
48+
const v = new THREE.Vector4(pointSpacing);
49+
v.applyMatrix4(context.camera.camera3D.projectionMatrix);
50+
51+
// We map v' to the screen space and calculate the distance to the origin.
52+
const dx = v.x * 0.5 * context.camera.width;
53+
const dy = v.y * 0.5 * context.camera.height;
54+
const distance = Math.sqrt(dx * dx + dy * dy);
55+
56+
return Math.max(0.0, distance - pointSize);
57+
}
58+
59+
function computeScreenSpaceError(context, pointSize, spacing, elt, distance) {
60+
if (context.camera.camera3D.isOrthographicCamera) {
61+
return computeSSEOrthographic(context, pointSize, spacing, elt);
62+
}
63+
64+
return computeSSEPerspective(context, pointSize, spacing, elt, distance);
65+
}
66+
4367
function markForDeletion(elt) {
4468
if (elt.obj) {
4569
elt.obj.visible = false;

0 commit comments

Comments
 (0)