Jump to content

Lua Scripting


Swampdonkey
 Share

Recommended Posts

I'm attempting to explore the Lua scripting capabalites of the engine, interesting to say the least! My question is - how do I access things like the camera and such from a Update function inside a loaded model?

 

In my models script I have this function

 

function Update(world)

 

Just to keep this question simple - say the model is a plain and I want to rotate it to face the camera each world update? I'm following the structure of the scripting system just fine - just not sure how to reference the camera in the model script since im not running a base game script for the map. The camera pointer should be set as a global i understand but if theres no game script in my setup where does the camera pointer get created so that I may access it via the models Update script?

 

Thanks again guys, I never relaized the capablities LE had until trying out this Eval, it's qute an amazing language!

<-- gothasoft.com -->

Link to comment
Share on other sites

how do I access things like the camera and such from a Update function inside a loaded model?

fw.main.camera

 

say the model is a plain and I want to rotate it to face the camera each world update?

self.model:Point(fw.main.camera,3,0.1,0)

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Come on Lumooja thats to easy.. I dare not try that :)

 

So am I understanding correctly that theres a base.lua script being called and this base script is setting all the globals that other scripts can use? I must admit globals throughtout a scripting language is a new one to mean, I can definitely see the benefits of having such capabilites.

 

If I was to build a set of models and included scripts for some of the functionality would referencing this 'fw.main.camera' remain true for others loading the model into their LE sandbox?

 

 

Thanks mate.

<-- gothasoft.com -->

Link to comment
Share on other sites

Yes, fw.main.camera is always available, since fw is the global framework object, which Editor also uses for all the post-processing effects, water, etc....

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Lua scripts cannot be inside .pak files because the Lua dofile() function doesn't understand my own pak file system. DoFile() is the only way to execute a compiled script file, so I chose to use this method.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Are you wanting to compile for speed or to protect your scripts? There won't be much speed increase except for initial load because the scripts are compiled to bytecode as soon as they are loaded I think, so you'll get faster startup, but the same execution speed.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

Thanks again guys, I never relaized the capablities LE had until trying out this Eval

 

 

 

 

:)

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Thanks for the replies, yah day 3 evaluating and so far LE is very very promising, have got some great results thus far. Wasnt really worried about compiling for speed more for the protection of the script but I suppose at this point thats irrelevant. Maybe some more info on what I'm attmepting will be helpful - I decided to make a custom boned tree trunk and apply mini prongs to it ala Speed-tree, wrote a script to manually animate the trunk and branches based off a given wind value. Prongs attached to the trunk joints act independant of the tree but update their location based on the tree branch swaying factor so they appear to be 100% attached.

 

All working great so far but I still think I'm missing something with the scripting language as the script runs fine on one tree but as soon as I add a 2nd tree of the same kind to the scene the script seems to only run on the last tree I insert into the scene. Prongs are forced to face the camera per render so its obvisious the script is running a single instance only?

 

One tree working fine, although a screenshot hardly shows the problem here -

 

http://gothasoft.com/temp/atree1.jpg

 

Not the prettiest tree but tosed together rather quickly for testing the scripts.

<-- gothasoft.com -->

Link to comment
Share on other sites

Well I found two problems when going back through my script, globalizing and just some bad referencing on my part but all fixed.. screenie shows numerous trees all behaving to the script now.

 

http://gothasoft.com/temp/atree2.jpg

 

Now to work on some grass/foliage and terrain textures.. Thanks for the support. I'm going to have to buy a license now just for all the help I've been recieving - rather I choose to use LE or not heh.

 

PS: spec alpha layer is a bit hard on those prong textures - causing some see through holes but easily fixed.

<-- gothasoft.com -->

Link to comment
Share on other sites

Are you using billboards that point towards the camera, like SpeedTree does? If you are, it would be much more optimal to control this behavior in a vertex shader. It would be a little tricky, but the benefit is the GPU would handle everything at no cost, and you would not have to loop through and adjust entities in script. You would also be able to render all leave sections in a single pass, which is much more optimal. That might be something to think about, in the long term.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Ah yes I am pointing the smaller prong billboards tot he camera ala Speedtree - was just sitting here thinking of some optimizations. I Had wrote a shader for treeparty GDK that rotated the billboards to the camera. I'll see if I can salvage any of that shader code - if I recall it took quite awhile to make that shader so I hope some of it is reuseable.

 

I see no other way to adjust the trunk bones but to use the script but usually theres only 5 to 8 bones to sway so it should hurt to much there.. Im hoping.

 

 

Thanks for the pointer.

<-- gothasoft.com -->

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