Hi again, sorry to bother you again with this, but I’ve modified the code now, to the way I feel is what you have told me, but I’m still running into some issues.
I made a 1x1m plane with 2 tri faces.
When I export I get this:
Info: optverts [0] point x y z : 0.500000 , -0.500000, 0.000000
Info: optverts [1] point x y z : -0.500000 , 0.500000, 0.000000
Info: optverts [2] point x y z : -0.500000 , -0.500000, 0.000000
Info: optverts [3] point x y z : 0.500000 , 0.500000, 0.000000
Info: optverts normal = 0 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 1 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 2 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 3 , x y z : 0.000000 , 0.000000, -1.000000
vi[0] = 2 1 3
vi[1] = 1 3 3
vi[2] = 3 3 0
vi[3] = 3 0 2
vi[4] = 0 2 1055150183
vi[5] = 2 1055150183 -2147477663
which produces this :
http://bullet4max.com/owncloud/index.php/s/yvETbPZbQA7OGcM
a 1x1x1 cube turns into this:
http://bullet4max.com/owncloud/index.php/s/7MVGYLghj5gzEsN
As you can see the
optverts [3]
has wrong point3 which is causing the face to 'disappear' since two of the values are the same.
Also, the vertice index is throwing some garbage at the end.
and one of the face indicies gets:
vi[1] = 1 3 3
which also would be wrong, since it set's two of the vertices to the same index?
The code I use is this:
int rawcount = p_trimesh->numFaces * 3;
int optcount = 0;
vertexPtr rawverts = CollectRawVerts(*p_trimesh, rawcount);
vertexPtr optverts = CreateOptimizeVertexList(rawverts, rawcount, optcount);
unsigned int* indices = CreateOptimizeFaceIndices(rawverts, rawcount, optverts, optcount);
mprintf(L"Info: optcount is now: %i
", optcount);
int numTriangles = p_trimesh->getNumFaces();
int numVis = numTriangles* 3;
Point *p = Scene::AllocVerticesBuffer(optcount);
Triangle *vi = Scene::AllocTrianglesBuffer(numVis);
Normal *n = new Normal[optcount];
for (int vert = 0; vert < optcount; vert++)
{
mprintf(L"Info: optverts [%i] point x y z : %f , %f, %f
",vert, optverts[vert].p.x, optverts[vert].p.y, optverts[vert].p.z);
p[vert] = Point(optverts[vert].p);
}
for (int norm = 0; norm < optcount; norm++)
{
mprintf(L"Info: optverts normal = %i , x y z : %f , %f, %f
",norm, optverts[norm].n.x, optverts[norm].n.y, optverts[norm].n.z);
n[norm].x = optverts[norm].n.x;
n[norm].y = optverts[norm].n.y;
n[norm].z = optverts[norm].n.z;
}
for (int i = 0; i < numVis; ++i)
{
vi[i] = Triangle(
int(indices[i]),
int(indices[i + 1]),
int(indices[i + 2]));
mprintf(L"vi[%i] = %i %i %i
",
i,
int (indices[i]),
int (indices[i + 1]),
int (indices[i + 2]));
}
These are the array's I'm putting the data into to send into the renderer api (just so you know).
Point *p = Scene::AllocVerticesBuffer(optcount);
Triangle *vi = Scene::AllocTrianglesBuffer(numVis);
Normal *n = new Normal[optcount];
try it like this…
for (int i = 0, fi = 0; fi < numVis ; i += 3, ++fi)
{
vi[fi] = Triangle(int(indices[i]), int(indices[i + 1]), int(indices[i + 2]));
}
you need to step 3 in the indices while 1 in the face
Unfortunately it gives the same type of result:
Info: optverts [0] point x y z : 0.500000 , -0.500000, 0.000000
Info: optverts [1] point x y z : -0.500000 , 0.500000, 0.000000
Info: optverts [2] point x y z : -0.500000 , -0.500000, 0.000000
Info: optverts [3] point x y z : 0.500000 , 0.500000, 0.000000
Info: optverts normal = 0 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 1 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 2 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 3 , x y z : 0.000000 , 0.000000, -1.000000
vi[0] = 2 1 3
vi[3] = 3 0 2
vi[6] = 1688969509 -2013192267 1
vi[9] = 6619236 1291059064 0
vi[12] = 100 0 1688969511
vi[15] = -1878974283 0 4
render:
try this
int rawcount = p_trimesh->numFaces * 3;
int optcount = 0;
vertexPtr rawverts = CollectRawVerts(*p_trimesh, rawcount);
vertexPtr optverts = CreateOptimizeVertexList(rawverts, rawcount, optcount);
unsigned int* indices = CreateOptimizeFaceIndices(rawverts, rawcount, optverts, optcount);
mprintf(L"Info: optcount is now: %i
", optcount);
int numTriangles = p_trimesh->getNumFaces();
//int numVis = numTriangles* 3;
Point *p = Scene::AllocVerticesBuffer(optcount);
Triangle *vi = Scene::AllocTrianglesBuffer(numTriangles);
Normal *n = new Normal[optcount];
for (int vert = 0; vert < optcount; vert++)
{
mprintf(L"Info: optverts [%i] point x y z : %f , %f, %f
",vert, optverts[vert].p.x, optverts[vert].p.y, optverts[vert].p.z);
p[vert] = Point(optverts[vert].p);
}
for (int norm = 0; norm < optcount; norm++)
{
mprintf(L"Info: optverts normal = %i , x y z : %f , %f, %f
",norm, optverts[norm].n.x, optverts[norm].n.y, optverts[norm].n.z);
n[norm].x = optverts[norm].n.x;
n[norm].y = optverts[norm].n.y;
n[norm].z = optverts[norm].n.z;
}
for (int i = 0, fi = 0 ; fi < numTriangles; i += 3, ++fi)
{
vi[fi] = Triangle(
int(indices[i]),
int(indices[i + 1]),
int(indices[i + 2]));
mprintf(L"vi[%i] = %i %i %i
",
fi,
int (indices[i]),
int (indices[i + 1]),
int (indices[i + 2]));
}
Getting closer, indicies looks good,but I’m still missing a face due to the vertices being a bit weird.
See the two last vertices in optverts array:
Info: optverts [0] point x y z : 0.500000 , -0.500000, 0.000000
Info: optverts [1] point x y z : -0.500000 , 0.500000, 0.000000
Info: optverts [2] point x y z : -0.500000 , -0.500000, 0.000000
Info: optverts [3] point x y z : 0.500000 , 0.500000, 0.000000
Info: optverts normal = 0 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 1 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 2 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 3 , x y z : 0.000000 , 0.000000, -1.000000
vi[0] = 2 1 3
vi[1] = 3 0 2
I did some more debugging,
the face #2 I thought was wrong – is there ,but the face is flipped, It seems in the output that the normal is fine, but I think it’s the indicie that is shifted so that it appears flipped?
Info: optverts [0] point x y z : 0.500000 , -0.500000, 0.000000
Info: optverts [1] point x y z : -0.500000 , 0.500000, 0.000000
Info: optverts [2] point x y z : -0.500000 , -0.500000, 0.000000
Info: optverts [3] point x y z : 0.500000 , 0.500000, 0.000000
Info: optverts normal = 0 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 1 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 2 , x y z : 0.000000 , 0.000000, -1.000000
Info: optverts normal = 3 , x y z : 0.000000 , 0.000000, -1.000000
vi[0] = 2 1 3
vi[1] = 3 0 2
here is a render:
http://bullet4max.com/owncloud/index.php/s/RjAQOhvxhrz95Ws
here is a screenshot of the mesh (in c++ it’s 0-based, in the screenshot I took the vertex number from the mesh selection) , the edge between them goes from 4-1 (3-0 in c++)
try it on a plane with the all the verts shifted a bit.
though I have the indexing as
2,1,0 && 3,0,1
I now tested with a plane (the previous mesh was faces I had extracted from a cube).
1x1x1m plane, no height\width segs.
So, the indicies the debugger says is:
Info: optverts [0] point x y z : -0.500000 , -0.500000, 0.000000
Info: optverts [1] point x y z : 0.500000 , 0.500000, 0.000000
Info: optverts [2] point x y z : 0.500000 , -0.500000, 0.000000
Info: optverts [3] point x y z : -0.500000 , 0.500000, 0.000000
Info: optverts normal = 0 , x y z : 0.000000 , 0.000000, 1.000000
Info: optverts normal = 1 , x y z : 0.000000 , 0.000000, 1.000000
Info: optverts normal = 2 , x y z : 0.000000 , 0.000000, 1.000000
Info: optverts normal = 3 , x y z : 0.000000 , 0.000000, 1.000000
vi[0] = 3 0 1
vi[1] = 2 1 0
I have attached a image of how the indexes is (0 based) in the max mesh.
If you look at it and the output above you see it’s wrong.
the last one should go between 0 2 3 .
I have trouble finding out through the code exactly what\where it is going wrong…
there’s not point comparing to the original order as the verts are sorted by their hash output. The output data looks correct to me should produce 2 face plane
try running it through the buildmesh routine i posted at the bottom of the previous page using this
TriObject* tobj = CreateNewTriObject();
INode* node = NULL;
if(tobj)
{
node = GetCOREInterface()->CreateObjectNode(tobj);
if(!node)
tobj->DeleteThis();
else
BuildMesh(tobj->GetMesh(),optverts.Get(),optcount,indices.Get(),mesh->numFaces);
}
Well, now it works, I found the bug, and it was my fault, I had (stupidly) not double checked the size I send into my own array when I send in the indcies.
When I saw that – I fixed it, and now all meshes renders perfectly fine…
I appreciate the help you have given me, I cannot stress that enough, been banging my head against the walls for so many days now, and your answers and help was way beyond what I expected. So thank you!
Here is a render that shows that everything now works perfectly.