[2.1] Help with manual object building collision mesh

Problems building or running the engine, queries about how to use features etc.
Post Reply
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

[2.1] Help with manual object building collision mesh

Post by Lax »

Hi folks,

I really need some help here. No matter what I try, I cannot get a collision mesh built correctly. I'm using the ManualObject implementation from "OgreManualObject2.h".
In my simple test scenario, I want to create a collision representation for a cube.
I get data from newton dynamics. The vertexArray is as follows:

Code: Select all

vertexArray,24
		[0]	1.00000000	float
		[1]	0.000000000	float
		[2]	-1.00000000	float
		[3]	1.00000000	float
		[4]	0.000000000	float
		[5]	-1.00000000	float
		[6]	1.00000000	float
		[7]	0.000000000	float
		[8]	-1.00000000	float
		[9]	1.00000000	float
		[10]	0.000000000	float
		[11]	1.00000000	float
		[12]	1.00000000	float
		[13]	0.000000000	float
		[14]	1.00000000	float
		[15]	1.00000000	float
		[16]	0.000000000	float
		[17]	1.00000000	float
		[18]	-1.00000000	float
		[19]	0.000000000	float
		[20]	-1.00000000	float
		[21]	-1.00000000	float
		[22]	0.000000000	float
		[23]	-1.00000000	float
The index array:

Code: Select all

indexArray,36
		[0]	0	unsigned int
		[1]	4	unsigned int
		[2]	10	unsigned int
		[3]	0	unsigned int
		[4]	10	unsigned int
		[5]	6	unsigned int
		[6]	1	unsigned int
		[7]	8	unsigned int
		[8]	17	unsigned int
		[9]	1	unsigned int
		[10]	17	unsigned int
		[11]	18	unsigned int
		[12]	2	unsigned int
		[13]	20	unsigned int
		[14]	21	unsigned int
		[15]	2	unsigned int
		[16]	21	unsigned int
		[17]	3	unsigned int
		[18]	5	unsigned int
		[19]	22	unsigned int
		[20]	12	unsigned int
		[21]	5	unsigned int
		[22]	12	unsigned int
		[23]	9	unsigned int
		[24]	7	unsigned int
		[25]	11	unsigned int
		[26]	13	unsigned int
		[27]	7	unsigned int
		[28]	13	unsigned int
		[29]	15	unsigned int
		[30]	14	unsigned int
		[31]	23	unsigned int
		[32]	19	unsigned int
		[33]	14	unsigned int
		[34]	19	unsigned int
		[35]	16	unsigned int
I think the vertexArray and the indexArray is correct. In the past everything worked fine, because the ManualObject was different and there was no need to call manualObject->index[..]. But that has changed. What I tried:

Code: Select all

object->begin("BlueNoLightning", Ogre::OperationType::OT_LINE_LIST);
int idx = 0;
int connectIdx = 0;
for (int i = 0; i < indexCount; i++)
{
	idx = i;
	object->position(vertexArray[(idx * 3) + 0], vertexArray[(idx * 3) + 1], vertexArray[(idx * 3) + 2]);
	++idx;
	object->position(vertexArray[(idx * 3) + 0], vertexArray[(idx * 3) + 1], vertexArray[(idx * 3) + 2]);
	connectIdx = i;
	object->line(connectIdx++, connectIdx++);
}
object->end();
The result looks like in Sample 1 of the picture.

When I changed:

Code: Select all

object->line(connectIdx++, connectIdx++);
to

Code: Select all

object->line(indexArray[connectIdx++], indexArray[connectIdx++]);
The result looks like in Sample 2 of the picture.
Image

I tried thousands of variations, but without success.

I hope somebody can help me out here.

Regards and Thanks in advance
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1] Help with manual object building collision mesh

Post by al2950 »

I am very busy so this answer will be a bit rough around the edges, but firstly DONT USE MANUAL OBJECT! But if you must the way you are going about is a little confusing using index count to add vertex data. Code speaks a thousand words!

Code: Select all

object->begin("BlueNoLightning", Ogre::OperationType::OT_LINE_LIST);
for (int vert = 0; vert < vertCount ; vert++)
{
	object->position(vertexArray[(vert * 3) + 0], vertexArray[(vert * 3) + 1], vertexArray[(vert * 3) + 2]);
}
for (int index= 0; index < indexCount ; index++)
{
	//could use object->line here but all that does is call index twice
	object->index(indexArray[index]);
}

object->end();
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Help with manual object building collision mesh

Post by Lax »

Thanks for the response!

Believe me, that I tried so many ways of set the data correctly, that I even forgot, what was actually the correct usage of vertex and index data :( .

Your code example looks much more promising.
This is now the result:

Image

But still there are some connections missing. I really do not know whats going on here. If your code is correct, then the data, I get from newton must be incomplete...

Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1] Help with manual object building collision mesh

Post by al2950 »

Got out of work and now have had a chance to look over your example. Your vertex buffer does not make any sense, atleast with the index buffer as context!

Your example shows that you have assumed the following
Vertex 0 = x
Vertex 1 = y
Vertex 2 = z

Vertex 3 = x
Vertex 4 = y
etc...

However your index buffere references vertex as high as 23, however according to your buffers you only have 24/3 verticies (8). Which makes sense for a wireframe cube. So what the hell is your index buffer about!?
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Help with manual object building collision mesh

Post by Lax »

Yeah, its really strange, what I get out of newton. I thought, since the index array indices go up to 23 and the highest vertexArray index is also 23, I thought I could reference each component (x, y, z) by the index array like that:

Code: Select all

for (int index = 0; index < indexCount / 3; index++)
{
    int index0 = indexArray[(index * 3) + 0];
    int index1 = indexArray[(index * 3) + 1];
    int index2 = indexArray[(index * 3) + 2];
    object->position(vertexArray[index0], vertexArray[index1], vertexArray[index2]);
}
But that did not work either.

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1] Help with manual object building collision mesh

Post by al2950 »

ok I am curious, can you point me to the newton docs and code for where you extract those buffers!?
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Help with manual object building collision mesh

Post by Lax »

This is the whole code I'm using:

Code: Select all

int vertexCount = NewtonMeshGetPointCount(mesh);
object->estimateVertexCount(vertexCount);
dFloat* vertexArray = new dFloat[3 * vertexCount];
memset(vertexArray, 0, 3 * vertexCount * sizeof(dFloat));

NewtonMeshGetVertexChannel(mesh, 3 * sizeof(dFloat), (dFloat*)vertexArray);

void* const geometryHandle = NewtonMeshBeginHandle(mesh);
for (int handle = NewtonMeshFirstMaterial(mesh, geometryHandle); handle != -1; handle = NewtonMeshNextMaterial(mesh, geometryHandle, handle))
{
   int material = NewtonMeshMaterialGetMaterial(mesh, geometryHandle, handle);
   int indexCount = NewtonMeshMaterialGetIndexCount(mesh, geometryHandle, handle);
   object->estimateIndexCount(indexCount);
   unsigned int* indexArray = new unsigned[indexCount];

   NewtonMeshMaterialGetIndexStream(mesh, geometryHandle, handle, (int*)indexArray);

   object->begin("BlueNoLightning", Ogre::OperationType::OT_LINE_LIST);
   for (int vert = 0; vert < vertCount ; vert++)
   {
      object->position(vertexArray[(vert * 3) + 0], vertexArray[(vert * 3) + 1], vertexArray[(vert * 3) + 2]);
   }
   for (int index= 0; index < indexCount ; index++)
   {
      object->index(indexArray[index]);
   }
}
object->end();
I think the way I'm getting data back from newton does not suffice for Ogre. Strange is, that the vertexArray has only 8 (x,y,z) coordinates, whereas Ogre would need for displaying a cube 24 (x,y,z) coordinates and 24 indices.

See newton api, but there not really a description:
http://newtondynamics.com/wiki/index.ph ... _reference

See my discussion on the newton forum (shame on my, that I spam the Ogre forum and the newton forum), but I'm really desperate with this topic :(

http://newtondynamics.com/forum/viewtop ... 828#p61828

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1] Help with manual object building collision mesh

Post by al2950 »

Its your vertex buffer.

If you look at the first three verticies;
1,0,-1
1,0,-1
1,0,-1

They are exactly the same, which means it is representing the cube with 3 vertices per 'corner'. Which means its using a vertex per face, which you would have to do if you where doing solid shading. Anyway this means there should be 24 vertices, and so your vertexArray should be 72. If you look at the numbers its very obvious as its completely missing a number of the cube corners!
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Help with manual object building collision mesh

Post by Lax »

Hi,

you are right, it must be 72 points. I will make further tests.
Thanks

Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: [2.1] Help with manual object building collision mesh

Post by Lax »

Hi al2950,

in fact, I missed the function:

Code: Select all

NewtonMeshTriangulate(mesh);
So now I get 72 points:

[0] 1.00000000 float
[1] 0.000000000 float
[2] -1.00000000 float
[3] 1.00000000 float
[4] 0.000000000 float
[5] -1.00000000 float
[6] 1.00000000 float
[7] 0.000000000 float
[8] -1.00000000 float
[9] 1.00000000 float
[10] 0.000000000 float
[11] 1.00000000 float
[12] 1.00000000 float
[13] 0.000000000 float
[14] 1.00000000 float
[15] 1.00000000 float
[16] 0.000000000 float
[17] 1.00000000 float
[18] -1.00000000 float
[19] 0.000000000 float
[20] -1.00000000 float
[21] -1.00000000 float
[22] 0.000000000 float
[23] -1.00000000 float
[24] -1.00000000 float
[25] 0.000000000 float
[26] -1.00000000 float
[27] -1.00000000 float
[28] 0.000000000 float
[29] 1.00000000 float
[30] -1.00000000 float
[31] 0.000000000 float
[32] 1.00000000 float
[33] -1.00000000 float
[34] 0.000000000 float
[35] 1.00000000 float
[36] -1.00000000 float
[37] 2.00000000 float
[38] 1.00000000 float
[39] -1.00000000 float
[40] 2.00000000 float
[41] 1.00000000 float
[42] -1.00000000 float
[43] 2.00000000 float
[44] 1.00000000 float
[45] -1.00000000 float
[46] 2.00000000 float
[47] -1.00000000 float
[48] -1.00000000 float
[49] 2.00000000 float
[50] -1.00000000 float
[51] -1.00000000 float
[52] 2.00000000 float
[53] -1.00000000 float
[54] 1.00000000 float
[55] 2.00000000 float
[56] -0.999998987 float
[57] 1.00000000 float
[58] 2.00000000 float
[59] -0.999998987 float
[60] 1.00000000 float
[61] 2.00000000 float
[62] -0.999998987 float
[63] 0.999998987 float
[64] 2.00000000 float
[65] 1.00000000 float
[66] 0.999998987 float
[67] 2.00000000 float
[68] 1.00000000 float
[69] 0.999998987 float
[70] 2.00000000 float
[71] 1.00000000 float

and 36 indices:
[0] 10 unsigned int
[1] 6 unsigned int
[2] 0 unsigned int
[3] 10 unsigned int
[4] 0 unsigned int
[5] 4 unsigned int
[6] 9 unsigned int
[7] 5 unsigned int
[8] 22 unsigned int
[9] 9 unsigned int
[10] 22 unsigned int
[11] 12 unsigned int
[12] 11 unsigned int
[13] 13 unsigned int
[14] 7 unsigned int
[15] 8 unsigned int
[16] 17 unsigned int
[17] 1 unsigned int
[18] 7 unsigned int
[19] 13 unsigned int
[20] 15 unsigned int
[21] 2 unsigned int
[22] 20 unsigned int
[23] 3 unsigned int
[24] 1 unsigned int
[25] 17 unsigned int
[26] 18 unsigned int
[27] 3 unsigned int
[28] 20 unsigned int
[29] 21 unsigned int
[30] 23 unsigned int
[31] 19 unsigned int
[32] 14 unsigned int
[33] 19 unsigned int
[34] 16 unsigned int
[35] 14 unsigned int

But still something is not right here. But still there is geometry missing.

Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

Post Reply