ManualObject Woes

bharling

06-01-2008 16:27:24

Hi all,

have been converting the CaduneTree lib to python, and everything is now done as far as I can tell, only problem is I can't get a tree to appear. CaduneTree uses a ManualObject pointer passed in to generate the tree geometry. Here's the code I use to display it:

manObj = ogre.ManualObject("myTree")
bbs = ogre.BillboardSet("leaves", 50, False)

params = Parameters()
trunk = Stem( params )
trunk.grow( ogre.Quaternion.IDENTITY, ogre.Vector3.ZERO )
trunk.createGeometry( manObj )
trunk.createLeaves( bbs )

#ent = sceneManager.createEntity( "mrTree", "myTree" )
node = sceneManager.getRootSceneNode().createChildSceneNode()
node.attachObject( manObj )
node.setPosition( 0,0,0)


I've converted the lib to python, rather than wrapping it ( possibly a bad idea :) ). Which leads me to believe I have done something wrong in the manual object setup. Does it require uint16's for vertices / indexes? I have just been using standard python ints. If so, how would I go about that?

Trouble is, I get no errors whatsoever, everything seems to work (tree generation, leaf generation etc ), just no tree displayed. The whole code is too long to post here, i will try and sort out somewhere to upload it.

SirGolan

06-01-2008 16:53:45

Hi there,

I can probably help with ManualObject as I've been using them to create terrain in my app for a while. For verts, I just use 3 floats, and for indexes, 3 ints. Here's some code I pulled (and removed app specific stuff from):


msh = sceneManager.createManualObject(name)
verts = [ (1.0,0.0,0.0), (0.0,1.0,0.0), (1.0,1.0,0.0), (0.0,0.0,0.0) ]
tris = [ (0,1,2), (1,2,3) ]
uv = [ (1.0,0.0), (0.0,1.0), (1.0,1.0), (0.0,0.0) ]
norms = []
color = []

msh.begin("MaterialName")

for x in range(len(verts)):
msh.position(*verts[x])
if len(norms):
msh.normal(*norms[x])
if len(color):
msh.colour(*color[x])
if len(uv):
msh.textureCoord(*uv[x])

for x in range(len(tris)):
msh.triangle(*tris[x])

msh.end()
node = parent.createChildSceneNode("Manual")
node.attachObject(msh)


If you want to post the full code somewhere, I can also take a look. I do remember having some issues getting ManualObjects to work right the first time.

bharling

06-01-2008 17:06:25

Thanks, I'll try out some of that right now.

Forgive my ignorance,

msh.position(*verts[x])

what does the * before the verts signify? I thought that was a C++ pointer-type thingy

bharling

06-01-2008 17:10:15

Aha!

well, using sceneManager.createManualObject( .. ) rather than what I was doing has at least made the beast visible! hurrah!

however its a bit garbled, Looks like I need to go back to the tree generation a bit.

SirGolan

06-01-2008 17:52:17

That's great. I'm glad I could help! :)

*verts[x] will pass each float in verts[x] as a separate parameter. You can do the same with ** and a dict for keyword args. So basically, msh.position(*verts[x]) is the same as msh.position(verts[x][0], verts[x][1], verts[x][2]).

Mike

bharling

06-01-2008 21:15:20

Ah right, never knew that one! so its more like an iterator than passing a list object.

thanks very much for that :)

bharling

06-01-2008 21:26:57

Heres the whole code I have so far, its from CaduneTree


My python version ( just a straight conversion )
http://pastebin.com/m19ad05dd

SirGolan

06-01-2008 22:17:30

I just checked it out. There is definitely something going wrong. :) I didn't see anything obvious after playing around with it a while. If I get some time, I'll keep poking it because it would be very nice to be able to generate random trees.

bharling

07-01-2008 10:17:13

Yeah, the demo provided with caduneTree looks fantastic.

I think the parameter setup in the code I have is a bit wrong, I've looked over it and some of the settings dont seem to make sense. Although I think there must be something more serious going on, as its definitely looking properly wrong.

andy

08-01-2008 02:47:52

Your problem is in CTStem.py -- not sure yet what the issue is, however I wrapped the C++ library (in the SVN now) and that works very well..

Cheers

Andy

bharling

08-01-2008 11:09:57

Aha!

I had a feeling you'd say that sooner or later! Well thanks for doing that :) cant wait to give it a try

andy

08-01-2008 12:07:09

I'm going to put a snapshot up on Sourceforge tonight with all the latest modules..

Andy