Where have all the vertices gone?
by Chris Calef · in Torque Game Engine · 09/16/2005 (11:02 am) · 5 replies
This is a strange question, because the answer seems entirely obvious, except for the minor problem that it doesn't seem to.. work. I was checking out Toby Allen's problem with his player model, and it brought me into an issue I was already wanting to address, which is:
Given a TSShape pointer, where do I find the actual Point3F vertex data? In case I wanted to mess with them, scale/rotate, modify bone weights, etc.?
The answer which appears obvious is under meshes[n]->verts, but while I can find a number for meshes[n]->tverts.size() on some models that I know are functional, I seem to be getting meshes->verts.size() = 0 (or just a straight-up crash for even having the nerve to ask) everywhere I look. I'm checking this at the end of TSShape::read, after assembleShape has been called, and it seems like everything related to loading and setting up the shape is done at this point.
I gotta get back to work on other stuff, but I thought I'd throw it out there. Anybody ever mess with this or have any clues? Thanks!
Chris
[edit: grammar]
Given a TSShape pointer, where do I find the actual Point3F vertex data? In case I wanted to mess with them, scale/rotate, modify bone weights, etc.?
The answer which appears obvious is under meshes[n]->verts, but while I can find a number for meshes[n]->tverts.size() on some models that I know are functional, I seem to be getting meshes->verts.size() = 0 (or just a straight-up crash for even having the nerve to ask) everywhere I look. I'm checking this at the end of TSShape::read, after assembleShape has been called, and it seems like everything related to loading and setting up the shape is done at this point.
I gotta get back to work on other stuff, but I thought I'd throw it out there. Anybody ever mess with this or have any clues? Thanks!
Chris
[edit: grammar]
About the author
#2
It still behaves the same way for me, though... check this out. With the following print statement,
I get this for the orc:
That's the tverts, all right, but I wonder what happened to all the verts and norms? Was starting to suspect that I did something horrible to my models accidentally when I loaded them, so I went back and tested on a clean SDK and it does the same thing.
Hmmm
[EDIT] -- [I'm doing this at the end of TSStatic::onAdd(), right after addToScene().]
09/18/2005 (12:08 pm)
Hey Matt, thanks for the code!It still behaves the same way for me, though... check this out. With the following print statement,
Con::errorf("Accessing %s: %d verts, %d tverts, %d norms", name, mesh->verts.size(),mesh->tverts.size(),mesh->norms.size());I get this for the orc:
Quote:
Accessing bodymesh: 0 verts, 1587 tverts, 0 norms
Accessing bodymesh: 0 verts, 1487 tverts, 0 norms
Accessing bodymesh: 0 verts, 1441 tverts, 0 norms
Accessing bodymesh: 0 verts, 1121 tverts, 0 norms
Accessing bodymesh: 0 verts, 913 tverts, 0 norms
Accessing bodymesh: 0 verts, 572 tverts, 0 norms
Accessing bodymesh: 0 verts, 328 tverts, 0 norms
Accessing bodymesh: 0 verts, 133 tverts, 0 norms
That's the tverts, all right, but I wonder what happened to all the verts and norms? Was starting to suspect that I did something horrible to my models accidentally when I loaded them, so I went back and tested on a clean SDK and it does the same thing.
Hmmm
[EDIT] -- [I'm doing this at the end of TSStatic::onAdd(), right after addToScene().]
#3
09/18/2005 (4:12 pm)
If it is a TSSkinMesh you are going to want to access initialVerts and initialNorms.
#4
09/19/2005 (8:11 am)
AHA! Thank you Matt!!!!!
#5
09/19/2005 (8:28 am)
Much nicer...Quote:
Accessing bodymesh: 1587 verts, 1587 tverts, 1587 norms
Accessing bodymesh: 1487 verts, 1487 tverts, 1487 norms
Accessing bodymesh: 1441 verts, 1441 tverts, 1441 norms
Accessing bodymesh: 1121 verts, 1121 tverts, 1121 norms
Accessing bodymesh: 913 verts, 913 tverts, 913 norms
Accessing bodymesh: 572 verts, 572 tverts, 572 norms
Accessing bodymesh: 328 verts, 328 tverts, 328 norms
Accessing bodymesh: 133 verts, 133 tverts, 133 norms
Associate Matt Fairfax
PopCap
for (U32 i = 0; i < mShapeInstance->mShape->details.size(); i++) { const TSDetail * detail = &mShapeInstance->mShape->details[i]; S32 ss = detail->subShapeNum; S32 od = detail->objectDetailNum; S32 start = mShapeInstance->mShape->subShapeFirstObject[ss]; S32 end = mShapeInstance->mShape->subShapeNumObjects[ss] + start; for (U32 j = start; j < end; j++) { // Sometimes it is handy to know the name of the mesh it is accessing const char *name = mShapeInstance->mShape->names[mShapeInstance->mMeshObjects[j].object->nameIndex]; Con::errorf("Accessing %s", name); TSMesh * mesh = mShapeInstance->mMeshObjects[j].getMesh(od); for (U32 k = 0; k < mesh->verts.size(); k++) { Point3F vertex = mesh->verts[k]; Point2F texCoord = mesh->tverts[k]; Point3F normal = mesh->norms[k]; Con::warnf("vert[%d](%g, %g, %g) texCoord(%g, %g) normal(%g, %g, %g)", k, vertex.x, vertex.y, vertex.z, texCoord.x, texCoord.y, normal.x, normal.y, normal.z); } } }