Jump to content

Convert LOD View Frustrum percent to distance


Recommended Posts

Hello guys... Got another tough one form me, hopefully someone can help.

I am making a component for the BabylonJS toolkit to support LODGroup... to automatically build LOD support for meshes.

In unity, when setting up a LODGroup... the levels are specified in percent:

59931ed32c6b8_ScreenShot2017-08-15at6_18_07AM.png.b52537540fd320f7576d2a747459479a.png

The documentations says "The percentages in the LOD bars represent the fraction of the view frustum depth where that LOD level becomes active.

But in Babylon we apparently use actual distance values to setup LOD...

My question is how can I convert these percentage values to distance to mesh.addLODLevel ???

Yo @Deltakosh and @Sebavan or @Wingnut ... SOMEBODY :)

Please chime in here :)

Link to post
Share on other sites
1 hour ago, Deltakosh said:

Perhaps (camera.maxZ - camera.minZ) * percentage

Thanks @Deltakosh for responding ...

Unity does not seem to "Specify" a camera... just use these percentage values...

Should I ALWAYS use the Babylon.MainCamera (activeCamera) to do these calculations on the client side (since I don't have a way of saying a specific LOD Group is associated with a certain camera)...

And what is Camera minZ and maxZ... would these exists in Unity Camera (maybe called something else)... so I can calculate what the distance is on the unity side then serialize distance values for each LOD group ??? What do you think?//

Link to post
Share on other sites
1 minute ago, MackeyK24 said:

So in in unity... That would be the Near and far clipping planes... Right???

 

5993323cbe43b_ScreenShot2017-08-15at7_40_33AM.png.a0476fda9a482829d23703f6de35cdab.png

EDIT: Yep I guess so... thats what use in the Toolkit to setup a camera...

Unity: lodBias = 2.0

So you think I can get distance for each LOD by:

var distance = lodBias * ((farClip - nearClip) * percentage)

BabylonUniversalCamera babylonCamera = new BabylonUniversalCamera
{
name = camera.name,
id = GetID(camera.gameObject),
fov = camera.fieldOfView * (float)Math.PI / 180,
minZ = camera.nearClipPlane,
maxZ = camera.farClipPlane,
parentId = GetParentID(camera.transform),
position = camera.transform.localPosition.ToFloat()
};
 
Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...