Delgine 3D Tools & Content DeleD Community Edition
Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Lua Plugin System Tutorials

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Tutorials
View previous topic :: View next topic  
Author Message
Il Buzzo
DeleD PRO user


Joined: 12 Aug 2004
Posts: 271
Location: Italy

PostPosted: Sun Mar 19, 2006 10:59 am    Post subject: Lua Plugin System Tutorials Reply with quote

Hi Guys,
I've thinked to start this thread, to help all want to use Lua Plugin system but doesn't know from where!!!
So I'll post in this thread some new complete examples with explanation (not line by line , but for noticeable things).
So I think you'll like this idea, then let's go with the first plugin script.
Read further.
Bye Wink.
Back to top
View user's profile Send private message Visit poster's website
Il Buzzo
DeleD PRO user


Joined: 12 Aug 2004
Posts: 271
Location: Italy

PostPosted: Sun Mar 19, 2006 11:46 am    Post subject: Reply with quote

FIRST PASS: LUA PLUGIN SYSTEM INSTALLATION
Well, if you haven't done yet, please install Lua Plugin System, as pointed out in documentation, you can download two version actually that just differs from documentation.
I'll explain better, in the light version, you'll have full plugin system documentation but no documentation on IUP ( a graphic library included that makes you create windows and controls etc....) and other third party libs used, but is smaller.
While the full version have included IUP and all third party libs documentation.
So please download choosen one from:
http://www.ilbuzzo.net/downloads/LuaPluginSys.zip(FULL VERSION)
http://www.ilbuzzo.net/downloads/LuaPluginSysLV.zip(LIGHT VERSION)
or from DeleD main site download zone.
At this point unzip all contents of package to DeleD main plugins folder and if you'll start DeleD you'll see Lua Plugin system is now present.

SECOND PASS: HOW TO USE
Lua plugin system comes with some examples, so you can try them before writing your own.
Use is the of others plugins, with just one difference, Lua Plugin system will open a Window where you'll see an output log, and an error log (so you can debug your scripts) and a script chooser window.
So from script chooser window select wanted script and start it, and the game is done.
Play a little with plugin and when you are ready pass to next pass.

THIRD PASS: I'M READY FOR LUA
Well, at this point let's start the dance.
First of all, you must know that a lua script can be written with any test editor (so choose your preferred), the only important thing is to save it with .lua extension in lua_plugins directory precedently created in DeleD plugins folder.
First of all, open your editor, and give your plugin a name this way in the first line:
Code:

--PLUGIN NAME:Modify an Object Tag

So what does this mean?
In lua "--" identify a comment line, but Lua Plugin system reads the first line and if it finds a comment with "PLUGIN NAME:" takes the string after just like title of plugin, elsewhere it takes filename.

FOURTH PASS: MORE ON LUA
So now let's start interesting stuff.
Code:

--This file is intented to show some basic functionalities

--let's initialize a scene class
scene=Scene:new();
print("Scene Created..");

Apart comments that are obvious, what are we doing?
In DeleD Lua plugin system there is a root structure called "Scene" that is a basic rapresentation of DeleD scene, so to take DeleD's object you need first of all to create a new Scene and you can do with the first line (comments are not counted). Note that in lua, there is no need to declare a variable. Now "scene" is created and can be used at your wish (To know more on Scene structure give a look to help provided).
After this we'll print some infos to output log (just for clarity).

FIFTH PASS: GETTING DATA FROM DELED
Well, now it's time to get all data from DeleD with the following code:
Code:

--get all materials and copy to scene
GetMaterials(false,scene);
--get all objects
GetObjects(false,scene);

This functions get respectively all materials and all objects from DeleD to pass to scene object.
These functions have the following definition:
GetMaterials(boolean value[true for selected material(s);false for all],a scene object);
GetObjects(boolean value[true for selected object(s);false for all],a scene object);
So now, we have passed all objects presented in current DeleD scene to our scene object, now we are ready to modify some things and pass back to DeleD.

SIXTH PASS: SOME SIMPLE MODIFICATIONS
Code:

--if you have more than one object
--I'll modify first object tag and then I'll send it back to DeleD
if scene:getObjectsSize()>0 then
myobj=scene:getObject(0);
--tag before
print("tag before:",myobj.tag);
myobj.tag="Hey this are my data, so keep your hands off :)"
print("tag after:",myobj.tag);
--pass object back to DeleD
SetObjects(myobj);
end

This is the last pass, notice that you can access a function of a class (Scene, Object ....) with ":" in lua, so if you have some objects (scene:getObjectsSize()>0) then you'll take one of them, in this case the first one, calling it "myobj" (myobj=scene:getObject(0)), then you print user tag before and after modify (myobj.tag="Hey this are my data, so keep your hands off Smile"), you can note that you can access Data Fields with ".".
Note that the same convention of C++ is used, list index go from 0 to N-1, where N stays for total number of elements (so 0 is the first etc...).
At this point you've modified your object and you can pass it back to DeleD with "SetObjects(myobj);".
Your script is finished this way, save it and start plugin after the creation of some objects and if you select the modified object in DeleD you'll see in properties the changed user tag.
Just a note on print(...), you can see that this function takes a variable number of args (this is a lua function) separated by commas, it just print to a line a concatenation of these args (also integers etc... will be converted and printed).

SEVENTH PASS: FULL CODE
Here you are the full script code:
Code:

--PLUGIN NAME:Modify an Object Tag
--This file is intented to show some basic functionalities

--let's initialize a scene class
scene=Scene:new();
print("Scene Created..");
--get all materials and copy to scene
GetMaterials(false,scene);
--get all objects
GetObjects(false,scene);
--if you have more than one object
--I'll modify first object tag and then I'll send it back to DeleD
if scene:getObjectsSize()>0 then
myobj=scene:getObject(0);
--tag before
print("tag before:",myobj.tag);
myobj.tag="Hey this are my data, so keep your hands off :)"
print("tag after:",myobj.tag);
--pass object back to DeleD
SetObjects(myobj);
end


I hope you enjoy this, bye all Wink
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum