Problem with generated mesh.
by Lukas Joergensen · in Torque 3D Professional · 07/21/2012 (1:10 am) · 2 replies
Hey guys, I am trying to generate a tube with a variable resolution.
But I am having trouble rendering it properly I am just beginning to understand this DX9 interface, so it can quite possibly just be a rookie mistake.


I am rendering it with this line:
And this I generate vertices and primitives like this:
Any help is greatly appreciated! Thanks
But I am having trouble rendering it properly I am just beginning to understand this DX9 interface, so it can quite possibly just be a rookie mistake.
The tube rendered as a trianglestrip

The tube rendered as a linestrip

I am rendering it with this line:
GFX->drawIndexedPrimitive(GFXLineStrip, 0, 0, smVertexBuffer->mNumVerts, 0, smPrimitiveBuffer->mIndexCount);
And this I generate vertices and primitives like this:
GFXStateBlockDesc d;
d.cullDefined = true;
d.cullMode = GFXCullNone;
smStateBlock = GFX->createStateBlock(d);
int numOfArrows = 4;
int resolution = 4;
smVertexBuffer.set(GFX, numOfArrows*resolution, GFXBufferTypeStatic);
GFXVertexPC* verts = smVertexBuffer.lock();
for(int i = 0; i < numOfArrows; i++)
{
for(int resI = 0; resI < resolution; resI++)
{
F32 x = cos((360/(resolution)*resI)*M_PI/180);
F32 y = i;
F32 z = sin(((360/(resolution))*resI)*M_PI/180);
verts[resolution*i+resI].point = Point3F(x,y,z);
verts[resolution*i+resI].color = GFXVertexColor(ColorI(255, 255, 0, 255));
if( resolution*i+resI == 0 || resolution*i+resI == 4 )
verts[resolution*i+resI].color = GFXVertexColor(ColorI(255, 0, 0, 255));
else if( resolution*i+resI == 1 || resolution*i+resI == 5 )
verts[resolution*i+resI].color = GFXVertexColor(ColorI(0, 255, 0, 255));
else if( resolution*i+resI == 3 || resolution*i+resI == 7 )
verts[resolution*i+resI].color = GFXVertexColor(ColorI(0, 0, 255, 255));
else if( resolution*i+resI == 2 || resolution*i+resI == 6 )
verts[resolution*i+resI].color = GFXVertexColor(ColorI(255, 0, 255, 255));
}
}
//verts[0].color = verts[1].color = verts[2].color = verts[3].color = GFXVertexColor(ColorI(0, 255, 0, 255));
smVertexBuffer.unlock();
smPrimitiveBuffer.set(GFX, (numOfArrows-1)*resolution*12, (numOfArrows-1)*resolution*2, GFXBufferTypeStatic);
U16* prims;
smPrimitiveBuffer.lock(&prims);
for(int meshIndex = 0; meshIndex < (numOfArrows-1); meshIndex++)
{
for(int vertIndex = 0; vertIndex < resolution; vertIndex++)
{
int lowleft = meshIndex*resolution+vertIndex;
int lowright = meshIndex*resolution+vertIndex+1;
if(lowright >= (meshIndex*resolution)+resolution)
lowright = meshIndex*resolution;
int upperleft = (meshIndex+1)*resolution+vertIndex;
int upperright = (meshIndex+1)*resolution+vertIndex+1;
if(upperright >= ((meshIndex+1)*resolution)+resolution)
upperright = (meshIndex+1)*resolution;
int index = (meshIndex*resolution*12) + vertIndex*12;
prims[index+0] = lowleft;
prims[index+1] = lowright;
prims[index+2] = lowright;
prims[index+3] = upperleft;
prims[index+4] = upperleft;
prims[index+5] = lowleft;
prims[index+6] = lowright;
prims[index+7] = upperright;
prims[index+8] = upperright;
prims[index+9] = upperleft;
prims[index+10] = upperleft;
prims[index+11] = lowright;
}
}
smPrimitiveBuffer.unlock();Any help is greatly appreciated! Thanks
About the author
IPS Bundle available at: https://www.winterleafentertainment.com/Products/IPS.aspx
#2
07/21/2012 (2:49 am)
I believe I fixed it! It is a logical error because the linelist takes indices in pairs of two while it should be pairs of three.. In other words I messed up ;)
Torque Owner Lukas Joergensen
WinterLeaf Entertainment