Custom mesh loading and vertex colour manipulation

Problems building or running the engine, queries about how to use features etc.
Post Reply
pratty70
Gnome
Posts: 341
Joined: Thu May 13, 2004 4:52 pm
Location: Wales - UK

Custom mesh loading and vertex colour manipulation

Post by pratty70 »

Just wondering if anyone has any thoughts on the following.

Have been posting requests regarding a flat panel of lit areas recently and pondering over the way of dealing with it. After much deliberation, vertex colours springs up as the most efficient and effective means of doing it.

So, I have been playing with different ways of loading in and was toying with the idea of generating a derived mesh class which has a separate colour vertex buffer which can be DYNAMIC and this will allow me to load meshes through the standard serializer and then manipulate the vertex buffer to modify colours on the fly. The standard serializer implements vertex colour loading to a static buffer - so will change this on the derived class to be dynamic and have some manipulation functions to modify it.

Does this sound like a sensible approach? :?

Also - milkshape doesn't handle vertex colours, so I played with wings, which handles them superbly - but the exporter doesn't handle them at all. I was thinking of creating a util to add vertex colour info with a default value and then ogre will pull it in on loading and I won't need to derive from the serializer to produce a custom one. Are there any other cheap options to adding/exporting vertex colour info. my Python knowlege is non-existant, so adding it to the exporter would be a no-no.

Any help greatly appreciated.

Thanks
pratty70
Gnome
Posts: 341
Joined: Thu May 13, 2004 4:52 pm
Location: Wales - UK

Post by pratty70 »

There had also been some deliberation over using a simplerenderable and custom loading it. I didn't really want to reinvent the wheel and copy the mesh loading routines when the only difference to a normal mesh is being able to manipulate the vertex colour info.

Have I missed something and there are methods already in mesh to be able to modify the buffer usage of the colour vertex buffer and hence achieve what I require?

Many thanks again, sorry for the ramblings
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

Right now in Mesh you can only influence the type of buffer usage for all buffers in the mesh at load time (see MeshManager::load). I didn't include mesh usage flags in .mesh because no modellers let you set that kind of information and I didn't think artists would really use it; however I guess this kind of information could be added later through some kind of tool. Hmm.

One option is to use MeshManager::load, using the most common usage option, then construct new vertex buffers for the ones you want to change (changing the usage) and use copyData() to move the information across, then re-bind the new buffers. That doesn't require a subclass, just a 'mesh tweaker' method somewhere in your initialisation code.
pratty70
Gnome
Posts: 341
Joined: Thu May 13, 2004 4:52 pm
Location: Wales - UK

Post by pratty70 »

Thanks Sinbad,

I had posted that message just before I left work and on the hour long drive home constructed a plan to load a mesh and then copy over the data from the loaded mesh to a manually created mesh with an additional colour buffer, but if I can create a new buffer and then rebind the buffers - that sounds even better.

Sounds like a plan for feet up in front of the TV with the laptop tonight - yipeee!

Once again - many thanks
pratty70
Gnome
Posts: 341
Joined: Thu May 13, 2004 4:52 pm
Location: Wales - UK

Post by pratty70 »

To follow on from this old thread.

I managed to achieve what was discussed in the original post with excellent effect - it is very very effective (screenshots to follow sometime soon when the project is released commercially).

I am having a little niggle at the moment however, where on one mesh (might extend to more) when I update the vertex buffer of a mesh with new colour info, if the camera is more than a certain distance from the mesh, the colours are not updated. Even if I update them and then move close to the mesh, they do not appear as I get closer, they ONLY update when I am close up.

Any thoughts?
User avatar
Cyberdigitus
Halfling
Posts: 55
Joined: Thu Mar 04, 2004 7:08 pm
Location: Belgium
Contact:

Post by Cyberdigitus »

can't help with the specific problem you are having, but i'm really looking forward to how the end result has turned out!

For those who don't know what this was about, here's the original thread.
. . .
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

@pratty70: that's extremely weird; distance shouldn't have any effect at all since the underlying mesh data is the same no matter how far away from you it is, updating it will always work even if it's not in the scene at the time.

The only potential ambiguity is if you're using manual mesh LOD, and you happen to have read the mesh pointer based on that rather than just updating the mesh in place. A fairly improbable set of events I think but I thought I'd mention it.

Are you sure it's not a symptom of some other bug?
pratty70
Gnome
Posts: 341
Joined: Thu May 13, 2004 4:52 pm
Location: Wales - UK

Post by pratty70 »

@cyberdigitus: many thanks for following the thread, has been an interesting development, as soon as I can (commercially), I will upload some images.

@sinbad: many thanks again Sinbad - you were quite right - bug in the code :oops:

I am running a script parser (of sorts (emulation!)) between frames and to avoid locking/unlocking buffers all the time, I was "stack"ing the vertices to update and then calling a global update at the end of the emulation time. Working fine - except my head was in the shed and I needed queue rather than stack - LIFO not so good when a lamp was turning on then off - but being parsed in reverse order ! :oops:

Two lines of code later (stack -> queue and top() -> front()) and the whole thing works a treat!

Looking forward to upload images when the product goes out.
pratty70
Gnome
Posts: 341
Joined: Thu May 13, 2004 4:52 pm
Location: Wales - UK

Post by pratty70 »

Just to add to this, I actually modified the milkshape exporter code to add a check box to export vertex colours and it creates an additional COLOUR buffer on the mesh when it exports from milkshape - means I can just pull it in to the environment. Seems to work fine, with a bit more testing I will supply the code patch to the exporter should anyone be interested.

Cheers
Post Reply