I Need To Create Function To Load A Mesh

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
tharshan
Posts: 19
Joined: Sun Jun 17, 2007 1:39 am
Contact:

I Need To Create Function To Load A Mesh

Post by tharshan »

Hello,

i need help with creating my own function..
so it can be called later..

i am using : Microsoft Visual C++ 2005 Express Edition.

i need a function to load mesh.. without writing the addsceneNode ,addMesh ,etc commands again & again.

so..it will be like as : LoadObject(nodeName,"Model.X")

so i can use it like this.

LoadObject(player1,"player1.X")
LoadObject(enemy,"ghost.X")
LoadObject(player2,"opn.X")

PS : is it possible to do like this . can nodes be created at runtime ?

Thank You.
Venkadesan V Tharshan
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post by GuerillaSoftworks »

Am I mistaken in saying that

Code: Select all

ISceneNode* player1 = scenemgr->addAnimatedMeshSceneNode(
                scenemgr->getMesh("player1.X"));
Produces the same result as what you are trying to do and that you seem to be too used to a BASIC-style language?

If you were to use your 'own function' it would have to return the name of your node. Therefore why would 'nodeName' be a parameter in your function? Alternitvly you could have created the node names as global variables and then change there value within your function but this isnt a very clever thing to do.

I don't think I understand your logic here? Or have I misunderstood your question?
Last edited by GuerillaSoftworks on Tue Jun 19, 2007 6:16 pm, edited 2 times in total.
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
tharshan
Posts: 19
Joined: Sun Jun 17, 2007 1:39 am
Contact:

Post by tharshan »

thank you,

you are correct.
but.

ex: if i create the function / call it like this..

LoadObject(player1,"opn.X")

player1 : node name
opn.x (string) : file name to load..

if we create a function it will be easier than normal.
example :

if you want to assign the same materials for your meshes.
Or you can set the scale of mesh in function.


no need to write it like :


ISceneNode* player1 = scenemgr->addAnimatedMeshSceneNode(
scenemgr->getMesh("player1.X"));
player1->setScale(1,1,......
player1->setMaterialFlag.....
etc..

i want that function to do this thing automaticly.

Thank You.
Venkadesan V Tharshan
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post by GuerillaSoftworks »

Surely though, the nodes 'player1' and 'player2' would have different settings. So a function to automate this would be useless.

But if you would want to do this then the following should work if ive understood you correctly. It's untested though so I cant say i will just work.


function declaration:

Code: Select all

ISceneNode LoadObject(wchar_t fileName)
{

ISceneNode* node = scenemgr->addAnimatedMeshSceneNode(
                scenemgr->getMesh(fileName));

node->setScale(1,1,...... );
node->setMaterialFlag.....);

// ...other irrlicht functions follow as approiate...

return node;

};
function use (e.g. in 'int main()' function):

Code: Select all

ISceneNode *player1 = LoadObject("player1.x");
If you want it to look more BASIC-like, i.e. without 'ISceneNode *player1 = ' before the function call, then declare the node in a separate statement or use global variables for your nodes. If you use global variables then use this function instead.

Code: Select all

void LoadObject(nodeName, wchar_t fileName)
{

nodeName = scenemgr->addAnimatedMeshSceneNode(
                scenemgr->getMesh(fileName));

nodeName->setScale(1,1,...... );
nodeName->setMaterialFlag.....);

// ...other irrlicht functions follow as approiate...

};
And this function call.

Code: Select all

LoadObject(player1,"player1.x");
Note that you would have to declare all nodes you are going to use, globally before all this.

I'd would advise strongly against this method though.


Good luck.
Last edited by GuerillaSoftworks on Tue Jun 19, 2007 7:06 pm, edited 1 time in total.
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
tharshan
Posts: 19
Joined: Sun Jun 17, 2007 1:39 am
Contact:

Post by tharshan »

thank you for your reply & example..

its enough.

but i have a question..

ISceneNode *player1..

do we need to declare that node pointer in global.. ? before using the LoadObject() function ?

if yes.. its better to do it in normal way without functions..


cannot a node created from inside a function ?


void LoadObject(ISceneNode* nodeName, wchar_t fileName)
{

>>> nodeName = scenemgr->addAnimatedMeshSceneNode(
can we declare the Node pointer here ?


Thanks !! :D
Venkadesan V Tharshan
tharshan
Posts: 19
Joined: Sun Jun 17, 2007 1:39 am
Contact:

Post by tharshan »

when i use this iam getting error.. in the line where it point to sceneManager..

nodeName = smngr->addAnimatedMeshSceneNode(smngr->getMesh(fileName));

it says the smngr is not declared.

do i need to declare smngr as Global ?
Venkadesan V Tharshan
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post by GuerillaSoftworks »

Try changing

Code: Select all

nodeName = smngr->addAnimatedMeshSceneNode(smngr->getMesh(fileName));
to

Code: Select all

nodeName = scenemgr->addAnimatedMeshSceneNode(scenemgr->getMesh(fileName));
and make sure you have

Code: Select all

ISceneManager* scenemgr = device->getSceneManager();
at the beginning of your 'int main()' or further back if required.

Ill reply to your previous post soon.
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post by GuerillaSoftworks »

A node can be created from within a function but it is does not exist outside that function that's a pointer to the node is returned from the function.

However, if you must do it the global way, then I think you could declare a global from within a function like so:

Code: Select all

static ISceneNode node;
but im not sure about this as ive never tryed to do it.

Also I have changed some code i posted. Check the 'void LoadObject()' declaration.
Last edited by GuerillaSoftworks on Wed Jun 20, 2007 1:06 am, edited 1 time in total.
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
tharshan
Posts: 19
Joined: Sun Jun 17, 2007 1:39 am
Contact:

Post by tharshan »

Thanks a lot..

it really helped me ! :P
Venkadesan V Tharshan
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post by GuerillaSoftworks »

No problems.

It would be interesting to see just how your using this code. So if possible is there any chance you could post your project when complete. I'm interested in seeing what would require this somewhat uncommon method of doing things. Thanks.
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
tharshan
Posts: 19
Joined: Sun Jun 17, 2007 1:39 am
Contact:

yes.

Post by tharshan »

Yes.

Sure !


i will post that soon..

my idea is..

read a text file & create objects from that..

so it can be used as simple level data for games ,etc

Thank You For Your Support
Venkadesan V Tharshan
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

my idea is.. read a text file & create objects from that.. so it can be used as simple level data for games ,etc
Sounds a heck of a lot like what is done with smgr->loadScene() and smgr->saveScene(). In case you didn't know, you can generate XML files that describe an entire scene using irrEdit, and you can load them with a single line of code.

Travis
GuerillaSoftworks
Posts: 83
Joined: Wed May 23, 2007 6:11 pm

Post by GuerillaSoftworks »

@ vitek... yeh this is something I was wondering about also. There must be some reason why hes doing things this way. Though I cant see what Im sure itll become apparent when hes done.
Guerilla Softworks

New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
Post Reply