@@ -89,23 +89,7 @@ class Mesh extends Object {
8989 return ;
9090 }
9191
92- var absPos = getAbsPos ();
93- var worldCenter = absPos .getPosition ();
94- var worldScale = absPos .getScale ();
95- var worldRadius = bounds .dimension () * hxd. Math .max ( worldScale .x , hxd. Math .max (worldScale .y , worldScale .z ) ) / 2.0 ;
96-
97- var cameraRight = ctx .camera .getRight ();
98- var cameraUp = ctx .camera .getUp ();
99- var cameraTopLeft = (cameraUp - cameraRight ).normalized ();
100- var worldTopLeft = worldCenter + cameraTopLeft * worldRadius ;
101- var worldBottomRight = worldCenter - cameraTopLeft * worldRadius ;
102-
103- var screenTopLeft = ctx .camera .projectInline ( worldTopLeft .x , worldTopLeft .y , worldTopLeft .z , 1.0 , 1.0 , false );
104- var screenBottomRight = ctx .camera .projectInline ( worldBottomRight .x , worldBottomRight .y , worldBottomRight .z , 1.0 , 1.0 , false );
105-
106- var screenArea = hxd. Math .max ( screenBottomRight .x - screenTopLeft .x , screenBottomRight .y - screenTopLeft .y );
107-
108- curScreenRatio = screenArea * screenArea ;
92+ curScreenRatio = screenRatio (getAbsPos (), bounds , ctx .camera );
10993
11094 if ( inheritLod )
11195 ctx .forcedScreenRatio = curScreenRatio ;
@@ -148,4 +132,22 @@ class Mesh extends Object {
148132 return this .primitive = prim ;
149133 }
150134
135+ public static function screenRatio (absPos : h3d. Matrix , bounds : h3d.col. Bounds , camera : h3d. Camera ) {
136+ var worldCenter = absPos .getPosition ();
137+ var worldScale = absPos .getScale ();
138+ var worldRadius = bounds .dimension () * hxd. Math .max ( worldScale .x , hxd. Math .max (worldScale .y , worldScale .z ) ) / 2.0 ;
139+
140+ var cameraRight = camera .getRight ();
141+ var cameraUp = camera .getUp ();
142+ var cameraTopLeft = (cameraUp - cameraRight ).normalized ();
143+ var worldTopLeft = worldCenter + cameraTopLeft * worldRadius ;
144+ var worldBottomRight = worldCenter - cameraTopLeft * worldRadius ;
145+
146+ var screenTopLeft = camera .projectInline ( worldTopLeft .x , worldTopLeft .y , worldTopLeft .z , 1.0 , 1.0 , false );
147+ var screenBottomRight = camera .projectInline ( worldBottomRight .x , worldBottomRight .y , worldBottomRight .z , 1.0 , 1.0 , false );
148+
149+ var screenArea = hxd. Math .max ( screenBottomRight .x - screenTopLeft .x , screenBottomRight .y - screenTopLeft .y );
150+
151+ return screenArea * screenArea ;
152+ }
151153}
0 commit comments