Rendering lines with thickness -- using BillboardChain


03-11-2009 11:14:54

Hi all,

this is a follow-up on my recent post, entitled 'DynamicLines - Mogre version':

In short: I want to render lines (2D & 3D curves). A way to do this was kindly provided by PantheR in the previous post.

However, there appears to be no easy way to set the line thickness in this scenario:

It has been suggested that line thickness could be achieved by using BillboardChains:

So this is what I set out to do. Unfortunately, I have no experience with BillboardChains, and I can't seem to find a lot of information about them. I'm stuck at the _NativePtr-bit of a BillboardChain.Element. Here's the code:

public MovableObject MakeLineBBC(ArrayList ALv3, string name, string matname)
BillboardChain rvbbc = null;
rvbbc = sceneMgr.GetBillboardChain(name);
if (rvbbc != null) sceneMgr.DestroyBillboardChain(rvbbc);
catch { }
rvbbc = sceneMgr.CreateBillboardChain(name);
rvbbc.MaxChainElements = (uint)ALv3.Count;
rvbbc.MaterialName = matname;
catch { throw new Exception("Failed to CreateBillboardChain()"); }

Vector3 cv3;
BillboardChain.Element_NativePtr bbcel;
for (int i = 0; i < ALv3.Count - 1; i++)
cv3 = Tools.Vector3((Vertex3)ALv3[i]);
bbcel = new BillboardChain.Element_NativePtr();
bbcel.position = cv3;
bbcel.width = 3.0f;
rvbbc.AddChainElement((uint)i, bbcel);

return rvbbc;

It throws an exception (can't write to protected memory) when I try to set the position of the element, so this is obviously not the way to go.

Does anyone know how to do this correctly?
How do I create a BillboardChainElement?
Do I need a BillboardSet as well?



05-11-2009 13:38:08

Hope this helps -

bbc = GraphicState.Instance.SceneManager.CreateBillboardChain(sys.Uid + ".Laser");

bbc.NumberOfChains = 1;
bbc.MaxChainElements = 2;

bbc.AddChainElement(0, BillboardChain.Element_NativePtr.Create(
new Vector3((float)usRend.Position.x,
(float)usRend.Position.z + 50.0f,
(float)usRend.Position.y), 10.0f * wd, 0.0f, ColourValue.White));

bbc.AddChainElement(0, BillboardChain.Element_NativePtr.Create(
new Vector3((float)themRend.Position.x,
(float)themRend.Position.z + 30.0f,
(float)themRend.Position.y), 10.0f * wd, 1.0f, ColourValue.White));

bbc.MaterialName = "Laser";



05-11-2009 20:13:08

Hi kierenj,

yes, that helped a lot!
Thanks for posting this.

One thing comes to mind, though: it seems that the ColourValue given in Element_NativePtr.Create() overrides the colors defined in the material that's assigned to the BBC. I mean, is there any use to assigning a material to the BBC as a whole?

And oh yes, one more thing: the BBC-solution doesn't really meet my requirements, I'm afraid -- perhaps I should have made those clearer in my OP. The problem (or the feature, if you like) is that the lines get thicker as you get closer to them, which isn't really what I had in mind. I thought that this line thickness parameter would behave more like the point_size parameter in an Ogre Material -- ie, measured in pixel space, rather than in world space, and so not affected by zooming.

Never mind, though, I'm very happy to be using BBC's as they are; it's a nice step forward from what I had until about an hour ago. So, again, many thanks for your valuable input.


PS: maybe I could adjust the thickness of the BBC's according to distance from camera. Seems like a lot of work, though..