Extract mesh data from buffers


25-11-2011 14:08:17

Hi all,
I have to extract data from index and vertex buffers in vb.net.
Now, I have found for example this function in C#:
private unsafe uint ReadVertexData(uint vertexOffset, VertexData vertexData)
VertexElement posElem = vertexData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.VES_POSITION);
HardwareVertexBufferSharedPtr vertexBuffer = vertexData.vertexBufferBinding.GetBuffer(posElem.Source);
byte* vertexMemory = (byte*)vertexBuffer.Lock(HardwareBuffer.LockOptions.HBL_READ_ONLY);
float* pElem;

for (uint i = 0; i < vertexData.vertexCount; i++)
posElem.BaseVertexPointerToElement(vertexMemory, &pElem);

Vector3 point = new Vector3(pElem[0], pElem[1], pElem[2]);
vertices[vertexOffset] = point * this.scale;
vertexMemory += vertexBuffer.VertexSize;

return vertexOffset;

..but there's a problem.. in vb.net there aren't pointers!! :(
Is there another way to access the buffers?


27-11-2011 11:28:48

I have no VB knowledge.
My suggestion: Go to a pure VB or .NET forum and ask there. It's a general question and I suppose there are more people who can give you a hint.

An other way:
You can create a library (dll file) from C# code (as an own project in your VisualStudio solution map). Then you add a link from your VB project to the created dll file and you can use its functionality.
It's an advantage of .NET that languages can be mixed.

Related to your code snippet:
Be aware that this code can cause problems, because it doesn't make differences between the 6 possible rendering types. Without this knowledge, you don't know what to do with the indices and vertices.
Also you should make a difference between 16 and 32 bit indices. Other wise you could have problems, too.

The last weeks I looked deeply to this topic and will publish related code (C#).
Until then you can look here:

Code for raycasting to polygon level.
It shows some details, although there are bugs inside. (e.g. rendering type checks)
The page also contains the method GetMeshInformation() which grabbs indices and vertices. But it only works for meshes, which only contains triangles, which uses rendering type "Triangle list". If it also contains other rendering types, the result is rubbish.
http://www.ogre3d.org/tikiwiki/Raycasti ... el+-+Mogre

It's for ManualObject, but it's similar to mesh.
In this (my) code you see the important differentiation between rendering types.
http://www.ogre3d.org/tikiwiki/Read+raw ... ct+-+MOGRE

General information about Ogre rendering types I published here:
http://www.ogre3d.org/tikiwiki/ManualOb ... ring_Types

My completely rewritten code I will publish in the near future.
It's specialized for ray casting on polygon level, but if there an interest, maybe I will modify it to grabb common mesh information.
Go to this topic, scroll down to the bottom and click to "suscribe topic". Then you will get a notice, when I publish my code.


25-12-2011 19:47:32

I had the same problem and you are right, there is now way to use pointers in vb.net so far. I have a "helper" c# project for this kind of "problems" and it is working perfectly with my vb.net main project.