Extracting renderable mesh data from TSShapeInstance
by Demolishun · in Torque 3D Professional · 02/04/2013 (10:50 am) · 0 replies
...
TSShapeInstance* mGeomShapeInstance; // defined in class
...
void AudioTextureObject::drawLineShape( F32 x1, F32 y1, F32 x2, F32 y2, const ColorI &color, F32 thickness)
{
static U32 err = 0;
static U32 last = 0;
// check for meshes
if(!mGeomShapeInstance)
return;
TSShape* tmpShape = mGeomShapeInstance->getShape();
TSMesh* lineEnd=NULL;
TSMesh* lineSegment=NULL;
mGeomShapeInstance->setCurrentDetail(0);
if(tmpShape){
lineEnd = findShape(String("LineEnd0"));
lineSegment = findShape(String("LineEnd0"));
}else{
//Con::warnf("no shape");
return;
}
if(!lineEnd || !lineSegment){
//Con::warnf("no meshes");
err = -1;
//return;
}else{
err = 1;
}
if(err == -1 && last != err){
last = err;
Con::warnf("no meshes");
}
if(err < 0)
return;
if(err == 1 && last != err){
last = err;
Con::warnf("meshes found");
}
GFXVertexBufferHandle<GFXVertexPCT> verts( GFX, totalverts, GFXBufferTypeVolatile );
//Con::warnf("num verts %d",verts->mNumVerts);
F32 offset = thickness/2.0f;
F32 xdiff = x2-x1;
F32 ydiff = y2-y1;
Point3F vect(xdiff,ydiff,0.0f);
vect = mNormalize(vect);
Point2F ovect(offset*vect.x,offset*vect.y);
verts.lock();
for(U32 i = 0; i < lineEnd->mNumVerts; i++){
verts[i].point = lineEnd->mVertexData[i].vert()*0.1f+Point3F(x1,y1,0.0f);
//Con::printf("point: %d:%.4f,%.4f,%.4f",i,verts[i].point.x,verts[i].point.y,verts[i].point.z);
verts[i].color = color;
//verts[i].color = lineEnd->mVertexData[i].color();
verts[i].texCoord = lineEnd->mVertexData[i].tvert();
}
verts.unlock();
GFX->setVertexBuffer( verts );
GFX->drawPrimitive( GFXTriangleStrip, 0, 2 );
}The problem with this code is that the vertices I get are not wound correctly. If I set winding to CW it show on triangle, and if I set it to CCW it shows the other. So by default the vertices returned are not in an order that will draw a triangle strip.
The question I have is: How do I convert them to a suitable triangle strip for rendering?
About the author
I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67