Jump to content

Simple LOD


Tommek
 Share

Recommended Posts

Hi Guys,

 

I've made myself a really simple LOD Script in Lua.

 

Script.Player = "" --entity "Player Entity"
Script.ViewDistanceMin = 10 --float "View Distance Min"
Script.ViewDistanceMax = 100 --float "View Distance Max"
function Script:Start()
self.entity:Hide()
end
function Script:UpdateWorld()
if (self.entity:GetDistance(self.Player) < self.ViewDistanceMax and self.entity:GetDistance(self.Player) > self.ViewDistanceMin) then
 self.entity:Show()
else
 self.entity:Hide()
end
end

 

So for an instance I want to use this, I create 3 different models (HD, SD, Low) and give them distances like: HD 0/9.0, SD 9.1/25.0, Low 25.1/2000.0

 

My problem here is the switchover that is not really smooth. Because if the player entity is slow you see the flickering. If I set the distances equal they overlap.

 

The overlapping is quite ok. But is there a possibility to make a smooth morph?

  • Upvote 1
Link to comment
Share on other sites

Yeah I will try to get some fading running. But as it seems It is not really usuable in LUA. My demo Level takes forever to start (17 entites with 3 detail levels), but after that it seems to run nice.

 

Could someone test this in C++? I'm just looking for the last push to buy myself a c++ License ;)

Link to comment
Share on other sites

Script.Player = "" --entity "Player Entity"
Script.ViewDistanceMin = 10 --float "View Distance Min"
Script.ViewDistanceMax = 100 --float "View Distance Max"
Script.DistancePollTime = 3 --int "Secs Poll Distance"
Script.PollTimer = 0
function Script:Start()
self.entity:Hide()
end
function Script:UpdateWorld()

self.PollTimer = self.PollTimer + (Time:GetSpeed()/100)
if (self.PollTimer > self.DistancePollTime) then
 self.Distance = self.entity:GetDistance(self.Player)
 if (self.Distance < self.ViewDistanceMax and self.Distance > self.ViewDistanceMin) then
  self.entity:Show()
 else
  self.entity:Hide()
 end

 self.PollTimer = 0
end
end

 

I've added Aggrors ideas, but now I get: 18 : error in function 'GetDistance'.; argument #2 is 'string'; 'Entity' expected.

 

Why did this change the context?

Link to comment
Share on other sites

You must not have filled in the Script.Player setting in the editor with anything. You init it as a string but call it an --entity. If I use --entity I usually init with a nil. Even so you'd then get a nil value for self.Player error but maybe that would make more sense to tell you that you forgot to assign an entity in the editor for that property.

Link to comment
Share on other sites

What is Player in your scene? Is it more csg or is it the actual player prefab that comes with Leadwerks? If it's just csg then without mass or a script attached csg gets collapsed (meaning you can't reference it anywhere), so that may make sense with the error as it wouldn't exist when you start it up and so it wouldn't be able to set Player which leaves it as it's initial value of an empty string.

 

If it is the player prefab then we have other issues and print out what it is like Aggror mentions

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...