Jump to content

Recommended Posts

Posted

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
Posted

I see obvious LOD switching in AAA games still.

 

A possible thing to look into is maybe fading out the old model and fading in the new one? Not sure how that would look, but it would be smoother.

Posted

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 ;)

Posted

You might want to add some frequency timer. 2 or 3 times a second to check the distance is more than a enough.

Also in your if statement you calculate the same distance twice. If you store it befor the if statement, you save another calculation.

  • Upvote 1
Posted

Nice Ideas!

 

EDIT: But as I said, after the start its working nice. I think it takes so lang to initialize the scripts mutiple times. is this correct?

Posted

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?

Posted

The scripts are are very simple and don't cost much. What costs a lot of time is the loading of all those models and textures.

 

THere was this unofficial function that allows to load textures dynamically. Can't find it right now.

Posted

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.

Posted

local Distance = self.entity:GetDistance(self.Player)

if (Distance < self.ViewDistanceMax and Distance > self.ViewDistanceMin) then

 

Same error. Do I have to call self.Player in a different way inside the if-statement?

Posted

Did you actually drag an entity in the editor over the Player property of that script? To me it sounds like you did not and so self.Player = "" which is the error you are getting (expecting entity got string)

Posted

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

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.

×
×
  • Create New...