Sign in to follow this  
FloB

dynamic LOD via art controls LUA SCRIPT

Recommended Posts

Here is a short script that changes the LOD (of the 3D) dynamically depending on aircraft altitude. This helps with FPS on the ground and enhances the experience for higher altitude.

I didn't write the lua script - I just cut it down to my needs. The orginal script by MayDayC can be found here (see OP) and involves a lot more:

 

http://forum.aerosoft.com/index.php?/topic/80537-xp10-performance-tweak-fur-besserer-framerate-mit-dataref/

 

Although it works for me - this is HIGLY EXPERIMENTAL and may cause unknown side effects !!!

I just wanted to share the idea and outcome so far. Don't ask me about how it works - because I don't know. I'm just beginning to get my feet wet with this lua stuff.

 

Here's the script anyway:

 

 

 

 

 

----------------------------------------------------------------
-- Performance tweak and dynamic level of detail LOD adjustment script for X-Plane 10
-- Date: 15.04.2014
-- Version: 0.1
-- Author: MaydayC / Germany

---------------------------------------------------------------------

DataRef( "h_ind", "sim/flightmodel/misc/h_ind")    -- Altitude over ground
DataRef( "LOD_bias_rat", "sim/private/controls/reno/LOD_bias_rat")
DataRef( "air_alt", "sim/cockpit2/gauges/indicators/altitude_ft_pilot","readonly")


-- The following parameters are the important parts for a higher framerate !!!!
-- 0.0 = deactivate - 1.0 = activate

-- fade_start_rate: Fade in objects in distance. Default is 0.5. With 1.0 max. visibility in distance is reached
set( "sim/private/controls/terrain/fade_start_rat", 0.9 )    


newlod = 1.2
oldlod = newlod
lod_factor = 3.0                                    -- Personal preference. Higher value = lowers the LOD

-- Set the initial Level of Detail
set( "sim/private/controls/reno/LOD_bias_rat", lod_factor )

function round2(num, idp)
  return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end

function setLOD()
        
    -- calculate the level of detail     
    newlod = round2(math.abs(((h_ind) * 0.0010)-lod_factor),2)            -- Calculation could be changed.      
        
    if h_ind > 2500 or newlod < 1.2 then                -- Max altitude or higher = full LOD
     newlod = 1.2
    end
    
    if newlod < 1.2 then        
     newlod = 1.2                                        -- Max LOD
    end
    
    if newlod > lod_factor then                            
     newlod = lod_factor                                -- Lowest LOD
    end
    
        
    if oldlod ~= newlod then
     -- finaly set the LOD if there is a change since last run
     set( "sim/private/controls/reno/LOD_bias_rat", newlod )    
        end
    oldlod = newlod
    
end

function showLod()
    -- if needed display the LOD,
    -- pos = bubble(20, 20, "Status", "LOD: "..newlod)
end

do_every_draw("showLod()")
do_often('setLOD()')

 

 

 

Greetz

Flo

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Gave it a quick test.

Seems to work for me, too.

Nice!

 

Thank you for the heads up.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this