Jump to content

Problem with Skybox


burgelkat
 Share

Recommended Posts

I have a problem with my skybox.

 

After I was not satisfied with a created sphere with a sky texture (and then change it with show and hide) I wanted to create a skybox in the fpsplayer script . This works well so far . If I activate another script then the sky texture changes . but as you recognize the pictures I have now a problem with the reflection . What am I doing wrong?

 

If i look straight to the horiziont then it looks ok (1. picture)

If i look down or in the sky then the mirrow effect is away (2. picture)

 

This is the Code i put in the fpsPlayer Script

 

--Create skybox

sky = Model:Create()

--just render a plane and project cubemap onto it

local surface = sky:AddSurface()

surface:AddVertex(-0.5,-0.5,0, 0,0,-1)

surface:AddVertex(0.5,-0.5,0, 0,0,-1)

surface:AddVertex(0.5,0.5,0, 0,0,-1)

surface:AddVertex(-0.5,0.5,0, 0,0,-1)

surface:AddTriangle(2,1,0)

surface:AddTriangle(0,3,2)

 

--position in front of camera but far out to near camera clip plane

sky:SetPosition(self.camera:GetPosition())

sky:SetRotation(self.camera:GetRotation())

sky:Move(0,0,self.camera:GetRange().y-50)

sky:SetScale(self.camera:GetRange().y*10)

sky:SetParent(self.camera)

 

-- and paint it

skymat=Material:Load("Materials/Sky/Tropical.mat")

sky:SetMaterial(skymat)

 

 

And this is my script with this i change the (directional light, skytexture and ambientelight)

function Script:Show()--in

skymat=Material:Load("Materials/Sky/SunSet.mat")

sky:SetMaterial(skymat)

directionallight = DirectionalLight:Create()

directionallight:SetRotation(-18.83,-54.375,-118.364)

directionallight:SetColor(1.68,0.67,0)

world:SetAmbientLight(0.02,0.02,0.02)

return true

end

 

If you have a different solution especially how I change the texture of the scene-root ( skybox ) I would be very happy .

 

thanks for your help

post-13719-0-30811800-1463567384_thumb.jpg

post-13719-0-89630700-1463567437_thumb.jpg

Link to comment
Share on other sites

That was the only thing that worked well with the scripts. unsure.png

I know the link you postet.

 

But I did not know how to start here. I get error here.

Do I need to install this line of code in the Script FPSPlayer ?

 

Edit: ups my mistake!! The Texture has different Name as my Material.

 

!!Thanks a lot!!

 

 

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

 

In the FpsPlayer- Script:

 

--Create a camera

self.camera = Camera:Create()

self.skybox = Texture:Load("Materials/Sky/TropicakSunnyDay.tex")

self.camera:SetSkybox(self.skybox)

self.camera:SetFOV(70)

self.camera:SetRange(0.05,1000)

self.camera:SetMultisampleMode((System:GetProperty("multisample","1")))

 

 

________________________________

 

so far so good. Now I just have to change the additional load of a new texture in another script

Link to comment
Share on other sites

ok . And this is the other script

 

function Script:Show()--in

self.skybox = Texture:Load("Materials/Sky/SunSet.tex")

world:SetSkybox(self.skybox)

directionallight = DirectionalLight:Create()

directionallight:SetRotation(-18.83,-54.375,-118.364)

directionallight:SetColor(1.68,0.67,0)

world:SetAmbientLight(0.02,0.02,0.02)

return true

end

Link to comment
Share on other sites

Mhm, in the game engine everything seems ok and the skybox changes the texture.

 

But in the game launcher if i play it then i get a error

 

Lua Error: [string "xxxxxxxxevening.lua"]:17: attempt to call method 'SetSkybox' (a nil value)

 

what i do wrong?

 

(Edit: It seems i cant work with world:SetSkybox(self.skybox) in the game launcher.)

 

I build a test-scene. in this scene the script function. Wy not in the game-launcher?

 

i hope someone can help me :)

https://www.dropbox.com/s/lvat7payk7spd9f/TestSky.zip?dl=0

Link to comment
Share on other sites

You get the error message ":attempt to call method 'SetSkybox' (a nil value)" because 'the 'world' object you reference to doesn't have a SetSkybox method. 'SetSkybox' belongs to the 'Camera' class, so what you'll have to do is make a simple Lua function to find your player entity, for example using one of Rick's old snippets:

 

function Script:FindEntity(name) --Or you could make this a global function, in Main.lua or any file included on the global lua state.
for x=0, world:CountEntities()-1 do
if world:GetEntity(x):GetKeyValue("name", "") == name then
return world:GetEntity(x)
end
end
end

 

Then we use that function to find the player's object, and set the players cameras skybox.:

 

function Script:Show()
self.skybox = Texture:Load("Materials/Sky/SunSet.tex") --Should be no need to create this on 'Show', why couldn't you create it on 'Start', then just not release it on 'Hide'?
local player = self:FindEntity("fpsplayer") --"fpsplayer" in this case would have to be the name of the player in the editor.
if player ~= nil then player.script.camera:SetSkybox(self.skybox) end
directionallight = DirectionalLight:Create()
directionallight:SetRotation(-18.83,-54.375,-118.364)
directionallight:SetColor(1.68,0.67,0)
world:SetAmbientLight(0.02,0.02,0.02)
return true
end

 

I feel like you'd be better off loading the skybox textures, and setting them in the player itself maybe...

 

Edit:

Alternatively you could do something like:

function Script:GetPlayer()
for i = 0, world:CountEntities()-1 do
if world:GetEntity(i):GetKeyValue("type", "") == "player" then
return world:GetEntity(i)
end
end
end

  • Upvote 2
Link to comment
Share on other sites

You get the error message ":attempt to call method 'SetSkybox' (a nil value)" because 'the 'world' object you reference to doesn't have a SetSkybox method. 'SetSkybox' belongs to the 'Camera' class

 

Agree with your solution completely, except there are World:GetSkybox() and World:SetSkybox() commands. As with anything that is not in the official documentation though, it does not mean they work, or are supported, or could not disappear at any time. Honestly, I would have preferred that the skybox was set through World commands as it easier to just perform a World:GetCurrent() instead of cycling through the world's entities looking for your main camera.

 

Edit-- Now looking back at his code, I wonder if his 'world' is properly defined. He just has 'world:SetSkybox(self.skybox)' inside a Script function, but he doesn't show if he defined 'world' anywhere in this separate script. Perhaps a 'world = World:GetCurrent()' would solve his issue, assuming its still not an issue with undocumented commands sometimes not actually working.

  • Upvote 2

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

@Crazycarpet: Wow ...first, thank you very much for your feedback . Learned something again. I will try it. Your feedback definitely makes sense biggrin.png. Feedback later.

 

@Macklebee: Thanks for your Feedback too. You are right, because my entry with "world-Command" function in the stand alone version of the game and in the game engine without an error.... i did not thought about it to define world. (I hope you understand what i wrote).

 

I will try your booth solution.

 

By the way I am glad that there are someone like you who gives the right "food for thought" (Denkanstoß) happy.png. Whenever I think I understand something with Lua I notice that I know nothing rolleyes.gif

  • Upvote 1
Link to comment
Share on other sites

No problem! It comes with time, glad I could help. It really does come with time, and even if you're great at Lua switching between engines can be tough because everyone has things set up differently, for example in Leadwerks you have the global lua state - and every object with a script attached has it's own Lua state. So you have to be careful. My solution isn't the prettiest and could be made nicer but tracking player entities and entities via tables, it'd be faster to retrieve the player object to. The only reason I prefer my solution over the 'world' method (besides the fact it's undocumented and I never knew it existed.) is because in something like the multiplayer game I'm making, it's nice to have per-player control over these things.

 

If you ever need any help with Lua just shoot me a PM. I've been writing it for a long long time so I definitely don't mind helping with it.

 

Agree with your solution completely, except there are World:GetSkybox() and World:SetSkybox() commands.

 

Edit-- Now looking back at his code, I wonder if his 'world' is properly defined. He just has 'world:SetSkybox(self.skybox)' inside a Script function, but he doesn't show if he defined 'world' anywhere in this separate script. Perhaps a 'world = World:GetCurrent()' would solve his issue, assuming its still not an issue with undocumented commands sometimes not actually working.

 

Thanks! I never knew there were world skybox commands, but honestly I personally prefer the camera skybox methods because it allows you to have like per-player control of it in for example the project I'm making where it's a multiplayer game (Not that I plan on making players ever have different skyboxes, but it gives me the option to). You just have to have a few systems that keep track of entiteis, and player entites etc to make retrieval of the player object easier.

 

Not to mention the 'World::SetSkybox()' methods aren't exposed to Lua.

 

As for the 'world' implemntation, there's nothing wrong with what he did. If you look in "Main.lua" he defines 'world' globally using:

world = World:Create()

Since it's created in "Main.lua" which is executed on the 'Interpreter::L' Lua state, this will be safe, and will exist in the script file.

 

I know this because I checked, I wondered the exact same thing as you. tongue.png thanks for the reply though! especially for the info about 'World:SetSkybox' not to familiar with Leadwerks as is because I've only been working with it for a very short time.

  • Upvote 1
Link to comment
Share on other sites

I didn't see that he had posted a downloadable example, so I was going by the code he posted. But yes, if world was global in the main script, it should be useable elsewhere.

 

Not to mention the 'World::SetSkybox()' methods aren't exposed to Lua.

Actually they are - that's how I found them by performing a class dump of '_G'. Now whether or not they work properly is another discussion. I have not had an opportunity to test. Since they are undocumented, they may not work or could be removed at any time.

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Ok.. now it function in the game-launcher cool.png

 

in my player-script i put in:

--Create a camera

self.camera = Camera:Create()
self.skybox = Texture:Load("Materials/Sky/TropicakSunnyDay.tex")
self.camera:SetSkybox(self.skybox)
self.camera:SetFOV(70)
self.camera:SetRange(0.05,1000)
self.camera:SetMultisampleMode((System:GetProperty("multisample","1")))

 

and i changed this in my script with that i will change the sky-texture (instead of:

local player = self:FindEntity("fpsplayer")

 

i use

 

local player = self:GetPlayer("fpsplayer")

______________________________________________________________________

 

function Script:GetPlayer()
for i = 0, world:CountEntities()-1 do
if world:GetEntity(i):GetKeyValue("type", "") == "player" then
return world:GetEntity(i)
end
end
end


function Script:Change()--in
self.skybox = Texture:Load("Materials/Sky/SunSet.tex")
local player = self:GetPlayer("fpsplayer") --"fpsplayer" in this case would have to be the name of the player in the editor.
if player ~= nil then player.script.camera:SetSkybox(self.skybox) end
directionallight = DirectionalLight:Create()
directionallight:SetRotation(-18.83,-54.375,-118.364)
directionallight:SetColor(1.68,0.67,0)
world:SetAmbientLight(0.02,0.02,0.02)
return true
end

 

A upload of the correct version is now published.

 

thank you so much :)

  • Upvote 1
Link to comment
Share on other sites

Looks good! smile.png glad you got it working.

 

However, you don't need the "fpsplayer" argument in your Script:GetPlayer() function calls.

 

Change:

self:GetPlayer("fpsplayer")

 

to:

self:GetPlayer()

 

Because Script:GetPlayer() doesn't take any arguments, which also means it wouldn't work for a multiplayer game not that it'd matter for you.

 

"fpsplayer" was there because the other 'FindEntity' function searched for entities by name, where as GetPlayer() loops over all the entities in the world and returns the first one who's key value "type" is equal to "player".

 

 

Actually they are - that's how I found them by performing a class dump of '_G'. Now whether or not they work properly is another discussion. I have not had an opportunity to test. Since they are undocumented, they may not work or could be removed at any time.

 

Good to know, wonder why is was saying 'SetSkybox' was nil in the example file if it's exposed though.

Link to comment
Share on other sites

Good to know, wonder why is was saying 'SetSkybox' was nil in the example file if it's exposed though.

If I had to guess, I would say its not exposed or did not exist with the version of Leadwerks that the Game Launcher executable is using because it doesn't recognize it as a Leadwerks command. Just tested it in the editor, as a standalone, and in the Game Launcher. Only place it doesn't work is the Game Launcher. Again, not documented, so not supported and could go bye-bye at any time. Granted I would definitely prefer these to be supported.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

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...