@@ -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+
4367function markForDeletion ( elt ) {
4468 if ( elt . obj ) {
4569 elt . obj . visible = false ;
0 commit comments