Jump to content

Recommended Posts

Posted

I have two questions regarding terrain:

 

1) How can I access a terrain made in the editor from Lua script? Secondly, is there any way to create it programmatically / procedurally, ie. via scripting and not in the editor?

 

2) I see that a terrain is shaded, which is fine. However, I notice that it does not cast shadows, which is very unrealistic. Is there a way to make it cast shadows.

 

Thank you!

Posted

1. Probably not supported, since CountEntities and GetEntity are not dicumented, but here is a way

 

 --get world and terrain
local world=World:GetCurrent()
for i=0,world:CountEntities()-1 do
 if world:GetEntity(i):GetClass()==Object.TerrainClass then
		 self.terrain=world:GetEntity(i)
		 tolua.cast(self.terrain,"Terrain")
		 break
 end
end

 

2. Not that I know.

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Posted

Also, the terrain commands (not supported/documented) are exposed to lua.

 

example Main.lua:

window = Window:Create("terrain example",0,0,800,600)
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
camera:SetPosition(0,6,0)
camera:SetRotation(0,45,0)
camera:SetMultisampleMode(8)
skybox = Texture:Load("Materials/Sky/skybox_texture.tex")
camera:SetSkybox(skybox)
light = DirectionalLight:Create()
light:SetRotation(45,45,0)

terrain = Terrain:Create(128,true)
terrain:SetLayerTexture(0, Texture:Load("Materials/Nature/terrain_savannah_dirt.tex"), 0)
terrain:SetLayerTexture(0, Texture:Load("Materials/Nature/terrain_savannah_dirtdot3.tex"), 1)
terrain:SetScale(1,5,1)
for x = 0, 64 do
	for y = 64, 128 do
		height = Math:Random(0,1)+0.5
		height = Math:Min(height,1.0)
		terrain:SetHeight(x,y,height)
	end
end
terrain:UpdateNormals()

camrot = camera:GetRotation()
gx=Math:Round(context:GetWidth()/2)
gy=Math:Round(context:GetHeight()/2)
move = 0
strafe = 0

while window:KeyDown(Key.Escape)==false do
	if window:Closed() then break end
	local mouseposition = window:GetMousePosition()
	local dx = mouseposition.x - gx
	local dy = mouseposition.y - gy
	camrot.x = camrot.x + dy / 10.0
	camrot.y = camrot.y + dx / 10.0
	camera:SetRotation(camrot)
	window:SetMousePosition(gx,gy)
	move = Math:Curve(((window:KeyDown(Key.W)and 1 or 0) - (window:KeyDown(Key.S) and 1 or 0)),move,10)
	strafe = Math:Curve(((window:KeyDown(Key.D)and 1 or 0) - (window:KeyDown(Key.A) and 1 or 0)),strafe,10)
	camera:Move(strafe,0,move)
 
	Time:Update()
	world:Update()
	world:Render()
	
	
	context:Sync()
end

 

As for terrain shadows, I haven't seen those since LE2. I suspect it will be re-introduced once LE3 gets vegetation.

  • 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

Posted

Thank you for these excellent answers! I'm wandering, though, why those stay undocumented...

 

Btw, how do you know these things? From Visual Studio auto-complete, trial & error, and similar?

 

P.S. If they are there, why do you say that they are unsupported? Because they might change in the future, might disappear, or similar?

  • Upvote 1
Posted

I perform a global variable dump in lua since i do not have the c++ version of LE. I can see each command/member available for each class. This is the latest version:

globals.txt

 

Edit- and like shadmar suggests, if it is not documented, then Josh has repeatedly warned that it may be removed or stop working 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

Posted
I perform a global variable dump in lua since i do not have the c++ version of LE.

 

Maybe now it's the right time to get it if you need it:

 

n7PJAr2.png

 

P.S. How do you do a global variable dump?

  • 1 year later...
  • 8 months 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.

×
×
  • Create New...