Rename all member variables to follow the style guidelines (prefixed with the 'm') - class AppMesh

This commit is contained in:
bank 2014-05-12 18:20:59 +04:00
parent cf3eb26e6f
commit aefa796056
5 changed files with 181 additions and 181 deletions

View file

@ -319,17 +319,17 @@ public:
ColladaAppMesh::ColladaAppMesh(const domInstance_geometry* instance, ColladaAppNode* node) ColladaAppMesh::ColladaAppMesh(const domInstance_geometry* instance, ColladaAppNode* node)
: instanceGeom(instance), instanceCtrl(0), appNode(node), geomExt(0) : instanceGeom(instance), instanceCtrl(0), appNode(node), geomExt(0)
{ {
flags = 0; mFlags = 0;
numFrames = 0; mNumFrames = 0;
numMatFrames = 0; mNumMatFrames = 0;
} }
ColladaAppMesh::ColladaAppMesh(const domInstance_controller* instance, ColladaAppNode* node) ColladaAppMesh::ColladaAppMesh(const domInstance_controller* instance, ColladaAppNode* node)
: instanceGeom(0), instanceCtrl(instance), appNode(node), geomExt(0) : instanceGeom(0), instanceCtrl(instance), appNode(node), geomExt(0)
{ {
flags = 0; mFlags = 0;
numFrames = 0; mNumFrames = 0;
numMatFrames = 0; mNumMatFrames = 0;
} }
const char* ColladaAppMesh::getName(bool allowFixed) const char* ColladaAppMesh::getName(bool allowFixed)
@ -367,8 +367,8 @@ bool ColladaAppMesh::animatesMatFrame(const AppSequence* appSeq)
// - by animating the morph weights for morph targets with different UVs // - by animating the morph weights for morph targets with different UVs
// Check if the MAYA profile texture transform is animated // Check if the MAYA profile texture transform is animated
for (S32 iMat = 0; iMat < appMaterials.size(); iMat++) { for (S32 iMat = 0; iMat < mAppMaterials.size(); iMat++) {
ColladaAppMaterial* appMat = static_cast<ColladaAppMaterial*>(appMaterials[iMat]); ColladaAppMaterial* appMat = static_cast<ColladaAppMaterial*>(mAppMaterials[iMat]);
if (appMat->effectExt && if (appMat->effectExt &&
appMat->effectExt->animatesTextureTransform(appSeq->getStart(), appSeq->getEnd())) appMat->effectExt->animatesTextureTransform(appSeq->getStart(), appSeq->getEnd()))
return true; return true;
@ -446,17 +446,17 @@ S32 ColladaAppMesh::addMaterial(const char* symbol)
// Find the index of the bound material in the shape global list // Find the index of the bound material in the shape global list
const domMaterial* mat = daeSafeCast<domMaterial>(matArray[iBind]->getTarget().getElement()); const domMaterial* mat = daeSafeCast<domMaterial>(matArray[iBind]->getTarget().getElement());
for (matIndex = 0; matIndex < appMaterials.size(); matIndex++) { for (matIndex = 0; matIndex < mAppMaterials.size(); matIndex++) {
if (static_cast<ColladaAppMaterial*>(appMaterials[matIndex])->mat == mat) if (static_cast<ColladaAppMaterial*>(mAppMaterials[matIndex])->mat == mat)
break; break;
} }
// Check if this material needs to be added to the shape global list // Check if this material needs to be added to the shape global list
if (matIndex == appMaterials.size()) { if (matIndex == mAppMaterials.size()) {
if (mat) if (mat)
appMaterials.push_back(new ColladaAppMaterial(mat)); mAppMaterials.push_back(new ColladaAppMaterial(mat));
else else
appMaterials.push_back(new ColladaAppMaterial(symbol)); mAppMaterials.push_back(new ColladaAppMaterial(symbol));
} }
break; break;
@ -466,7 +466,7 @@ S32 ColladaAppMesh::addMaterial(const char* symbol)
else else
{ {
// No Collada material is present for this symbol, so just create an empty one // No Collada material is present for this symbol, so just create an empty one
appMaterials.push_back(new ColladaAppMaterial(symbol)); mAppMaterials.push_back(new ColladaAppMaterial(symbol));
} }
// Add this symbol to the bound list for the mesh // Add this symbol to the bound list for the mesh
@ -477,7 +477,7 @@ S32 ColladaAppMesh::addMaterial(const char* symbol)
void ColladaAppMesh::getPrimitives(const domGeometry* geometry) void ColladaAppMesh::getPrimitives(const domGeometry* geometry)
{ {
// Only do this once // Only do this once
if (primitives.size()) if (mPrimitives.size())
return; return;
// Read the <geometry> extension // Read the <geometry> extension
@ -517,16 +517,16 @@ void ColladaAppMesh::getPrimitives(const domGeometry* geometry)
continue; continue;
// Create TSMesh primitive // Create TSMesh primitive
primitives.increment(); mPrimitives.increment();
TSDrawPrimitive& primitive = primitives.last(); TSDrawPrimitive& primitive = mPrimitives.last();
primitive.start = indices.size(); primitive.start = mIndices.size();
primitive.matIndex = (TSDrawPrimitive::Triangles | TSDrawPrimitive::Indexed) | primitive.matIndex = (TSDrawPrimitive::Triangles | TSDrawPrimitive::Indexed) |
addMaterial(meshPrims[iPrim]->getMaterial()); addMaterial(meshPrims[iPrim]->getMaterial());
// Get the AppMaterial associated with this primitive // Get the AppMaterial associated with this primitive
ColladaAppMaterial* appMat = 0; ColladaAppMaterial* appMat = 0;
if (!(primitive.matIndex & TSDrawPrimitive::NoMaterial)) if (!(primitive.matIndex & TSDrawPrimitive::NoMaterial))
appMat = static_cast<ColladaAppMaterial*>(appMaterials[primitive.matIndex & TSDrawPrimitive::MaterialMask]); appMat = static_cast<ColladaAppMaterial*>(mAppMaterials[primitive.matIndex & TSDrawPrimitive::MaterialMask]);
// Force the material to be double-sided if this geometry is double-sided. // Force the material to be double-sided if this geometry is double-sided.
if (geomExt->double_sided && appMat && appMat->effectExt) if (geomExt->double_sided && appMat && appMat->effectExt)
@ -534,8 +534,8 @@ void ColladaAppMesh::getPrimitives(const domGeometry* geometry)
// Pre-allocate triangle indices // Pre-allocate triangle indices
primitive.numElements = numTriangles * 3; primitive.numElements = numTriangles * 3;
indices.setSize(indices.size() + primitive.numElements); mIndices.setSize(mIndices.size() + primitive.numElements);
U32* dstIndex = indices.end() - primitive.numElements; U32* dstIndex = mIndices.end() - primitive.numElements;
// Determine the offset for each element type in the stream, and also the // Determine the offset for each element type in the stream, and also the
// maximum input offset, which will be the number of indices per vertex we // maximum input offset, which will be the number of indices per vertex we
@ -569,12 +569,12 @@ void ColladaAppMesh::getPrimitives(const domGeometry* geometry)
daeErrorHandler::get()->handleWarning(avar("Splitting primitive " daeErrorHandler::get()->handleWarning(avar("Splitting primitive "
"in %s: too many verts for 16-bit indices.", _GetNameOrId(geometry))); "in %s: too many verts for 16-bit indices.", _GetNameOrId(geometry)));
primitives.last().numElements -= indicesRemaining; mPrimitives.last().numElements -= indicesRemaining;
primitives.push_back(TSDrawPrimitive(primitives.last())); mPrimitives.push_back(TSDrawPrimitive(mPrimitives.last()));
} }
primitives.last().numElements = indicesRemaining; mPrimitives.last().numElements = indicesRemaining;
primitives.last().start = indices.size() - indicesRemaining; mPrimitives.last().start = mIndices.size() - indicesRemaining;
tupleMap.clear(); tupleMap.clear();
} }
@ -631,7 +631,7 @@ void ColladaAppMesh::getVertexData(const domGeometry* geometry, F32 time, const
Vector<Point2F>& v_uv2s, Vector<Point2F>& v_uv2s,
bool appendValues) bool appendValues)
{ {
if (!primitives.size()) if (!mPrimitives.size())
return; return;
MeshStreams streams; MeshStreams streams;
@ -676,7 +676,7 @@ void ColladaAppMesh::getVertexData(const domGeometry* geometry, F32 time, const
streams.readInputs(meshPrims[tuple.prim]->getInputs()); streams.readInputs(meshPrims[tuple.prim]->getInputs());
S32 matIndex = addMaterial(meshPrims[tuple.prim]->getMaterial()); S32 matIndex = addMaterial(meshPrims[tuple.prim]->getMaterial());
if (matIndex != TSDrawPrimitive::NoMaterial) if (matIndex != TSDrawPrimitive::NoMaterial)
appMat = static_cast<ColladaAppMaterial*>(appMaterials[matIndex]); appMat = static_cast<ColladaAppMaterial*>(mAppMaterials[matIndex]);
else else
appMat = 0; appMat = 0;
@ -923,10 +923,10 @@ void ColladaAppMesh::lockMesh(F32 t, const MatrixF& objectOffset)
// Now get the vertex data at the specified time // Now get the vertex data at the specified time
if (geometry->getElementType() == COLLADA_TYPE::GEOMETRY) { if (geometry->getElementType() == COLLADA_TYPE::GEOMETRY) {
getPrimitives(daeSafeCast<domGeometry>(geometry)); getPrimitives(daeSafeCast<domGeometry>(geometry));
getVertexData(daeSafeCast<domGeometry>(geometry), t, objectOffset, points, normals, colors, uvs, uv2s, true); getVertexData(daeSafeCast<domGeometry>(geometry), t, objectOffset, mPoints, mNormals, mColors, mUVs, mUV2s, true);
} }
else if (geometry->getElementType() == COLLADA_TYPE::MORPH) { else if (geometry->getElementType() == COLLADA_TYPE::MORPH) {
getMorphVertexData(daeSafeCast<domMorph>(geometry), t, objectOffset, points, normals, colors, uvs, uv2s); getMorphVertexData(daeSafeCast<domMorph>(geometry), t, objectOffset, mPoints, mNormals, mColors, mUVs, mUV2s);
} }
else { else {
daeErrorHandler::get()->handleWarning(avar("Unsupported geometry type " daeErrorHandler::get()->handleWarning(avar("Unsupported geometry type "
@ -937,7 +937,7 @@ void ColladaAppMesh::lockMesh(F32 t, const MatrixF& objectOffset)
void ColladaAppMesh::lookupSkinData() void ColladaAppMesh::lookupSkinData()
{ {
// Only lookup skin data once // Only lookup skin data once
if (!isSkin() || weight.size()) if (!isSkin() || mWeight.size())
return; return;
// Get the skin and vertex weight data // Get the skin and vertex weight data
@ -950,7 +950,7 @@ void ColladaAppMesh::lookupSkinData()
streams.readInputs(skin->getJoints()->getInput_array()); streams.readInputs(skin->getJoints()->getInput_array());
streams.readInputs(weightIndices.getInput_array()); streams.readInputs(weightIndices.getInput_array());
MatrixF invObjOffset(objectOffset); MatrixF invObjOffset(mObjectOffset);
invObjOffset.inverse(); invObjOffset.inverse();
// Get the bind shape matrix // Get the bind shape matrix
@ -971,7 +971,7 @@ void ColladaAppMesh::lookupSkinData()
// Set vertex weights // Set vertex weights
bool tooManyWeightsWarning = false; bool tooManyWeightsWarning = false;
for (S32 iVert = 0; iVert < vertsPerFrame; iVert++) { for (S32 iVert = 0; iVert < mVertsPerFrame; iVert++) {
const domUint* vcount = (domUint*)weights_vcount.getRaw(0); const domUint* vcount = (domUint*)weights_vcount.getRaw(0);
const domInt* vindices = (domInt*)weights_v.getRaw(0); const domInt* vindices = (domInt*)weights_v.getRaw(0);
vindices += vindicesOffset[vertTuples[iVert].vertex]; vindices += vindicesOffset[vertTuples[iVert].vertex];
@ -1002,25 +1002,25 @@ void ColladaAppMesh::lookupSkinData()
} }
// Too many weights => find and replace the smallest one // Too many weights => find and replace the smallest one
S32 minIndex = weight.size() - TSSkinMesh::BatchData::maxBonePerVert; S32 minIndex = mWeight.size() - TSSkinMesh::BatchData::maxBonePerVert;
F32 minWeight = weight[minIndex]; F32 minWeight = mWeight[minIndex];
for (S32 i = minIndex + 1; i < weight.size(); i++) for (S32 i = minIndex + 1; i < mWeight.size(); i++)
{ {
if (weight[i] < minWeight) if (mWeight[i] < minWeight)
{ {
minWeight = weight[i]; minWeight = mWeight[i];
minIndex = i; minIndex = i;
} }
} }
boneIndex[minIndex] = bIndex; mBoneIndex[minIndex] = bIndex;
weight[minIndex] = bWeight; mWeight[minIndex] = bWeight;
} }
else else
{ {
vertexIndex.push_back( iVert ); mVertexIndex.push_back( iVert );
boneIndex.push_back( bIndex ); mBoneIndex.push_back( bIndex );
weight.push_back( bWeight ); mWeight.push_back( bWeight );
nonZeroWeightCount++; nonZeroWeightCount++;
} }
} }
@ -1028,26 +1028,26 @@ void ColladaAppMesh::lookupSkinData()
// Normalize vertex weights (force weights for each vert to sum to 1) // Normalize vertex weights (force weights for each vert to sum to 1)
S32 iWeight = 0; S32 iWeight = 0;
while (iWeight < weight.size()) { while (iWeight < mWeight.size()) {
// Find the last weight with the same vertex number, and sum all weights for // Find the last weight with the same vertex number, and sum all weights for
// that vertex // that vertex
F32 invTotalWeight = 0; F32 invTotalWeight = 0;
S32 iLast; S32 iLast;
for (iLast = iWeight; iLast < weight.size(); iLast++) { for (iLast = iWeight; iLast < mWeight.size(); iLast++) {
if (vertexIndex[iLast] != vertexIndex[iWeight]) if (mVertexIndex[iLast] != mVertexIndex[iWeight])
break; break;
invTotalWeight += weight[iLast]; invTotalWeight += mWeight[iLast];
} }
// Then normalize the vertex weights // Then normalize the vertex weights
invTotalWeight = 1.0f / invTotalWeight; invTotalWeight = 1.0f / invTotalWeight;
for (; iWeight < iLast; iWeight++) for (; iWeight < iLast; iWeight++)
weight[iWeight] *= invTotalWeight; mWeight[iWeight] *= invTotalWeight;
} }
// Add dummy AppNodes to allow Collada joints to be mapped to 3space nodes // Add dummy AppNodes to allow Collada joints to be mapped to 3space nodes
bones.setSize(streams.joints.size()); mBones.setSize(streams.joints.size());
initialTransforms.setSize(streams.joints.size()); mInitialTransforms.setSize(streams.joints.size());
for (S32 iJoint = 0; iJoint < streams.joints.size(); iJoint++) for (S32 iJoint = 0; iJoint < streams.joints.size(); iJoint++)
{ {
const char* jointName = streams.joints.getStringValue(iJoint); const char* jointName = streams.joints.getStringValue(iJoint);
@ -1075,9 +1075,9 @@ void ColladaAppMesh::lookupSkinData()
"defaulting to instance_controller parent node '%s'", jointName, appNode->getName())); "defaulting to instance_controller parent node '%s'", jointName, appNode->getName()));
joint = appNode->getDomNode(); joint = appNode->getDomNode();
} }
bones[iJoint] = new ColladaAppNode(joint); mBones[iJoint] = new ColladaAppNode(joint);
initialTransforms[iJoint] = objectOffset; mInitialTransforms[iJoint] = mObjectOffset;
// Bone scaling is generally ignored during import, since 3space only // Bone scaling is generally ignored during import, since 3space only
// stores default node transform and rotation. Compensate for this by // stores default node transform and rotation. Compensate for this by
@ -1089,16 +1089,16 @@ void ColladaAppMesh::lookupSkinData()
invScale.x = invScale.x ? (1.0f / invScale.x) : 0; invScale.x = invScale.x ? (1.0f / invScale.x) : 0;
invScale.y = invScale.y ? (1.0f / invScale.y) : 0; invScale.y = invScale.y ? (1.0f / invScale.y) : 0;
invScale.z = invScale.z ? (1.0f / invScale.z) : 0; invScale.z = invScale.z ? (1.0f / invScale.z) : 0;
initialTransforms[iJoint].scale(invScale); mInitialTransforms[iJoint].scale(invScale);
} }
// Inverted node coordinate spaces (negative scale factor) are corrected // Inverted node coordinate spaces (negative scale factor) are corrected
// in ColladaAppNode::getNodeTransform, so need to apply the same operation // in ColladaAppNode::getNodeTransform, so need to apply the same operation
// here to match // here to match
if (m_matF_determinant(invBind) < 0.0f) if (m_matF_determinant(invBind) < 0.0f)
initialTransforms[iJoint].scale(Point3F(1, 1, -1)); mInitialTransforms[iJoint].scale(Point3F(1, 1, -1));
initialTransforms[iJoint].mul(invBind); mInitialTransforms[iJoint].mul(invBind);
initialTransforms[iJoint].mul(bindShapeMatrix); mInitialTransforms[iJoint].mul(bindShapeMatrix);
} }
} }

View file

@ -458,9 +458,9 @@ void updateMaterialsScript(const Torque::Path &path, bool copyTextures = false)
// First see what materials we need to update // First see what materials we need to update
PersistenceManager persistMgr; PersistenceManager persistMgr;
for ( U32 iMat = 0; iMat < AppMesh::appMaterials.size(); iMat++ ) for ( U32 iMat = 0; iMat < AppMesh::mAppMaterials.size(); iMat++ )
{ {
ColladaAppMaterial *mat = dynamic_cast<ColladaAppMaterial*>( AppMesh::appMaterials[iMat] ); ColladaAppMaterial *mat = dynamic_cast<ColladaAppMaterial*>( AppMesh::mAppMaterials[iMat] );
if ( mat ) if ( mat )
{ {
Material *mappedMat; Material *mappedMat;

View file

@ -23,10 +23,10 @@
#include "ts/loader/appMesh.h" #include "ts/loader/appMesh.h"
#include "ts/loader/tsShapeLoader.h" #include "ts/loader/tsShapeLoader.h"
Vector<AppMaterial*> AppMesh::appMaterials; Vector<AppMaterial*> AppMesh::mAppMaterials;
AppMesh::AppMesh() AppMesh::AppMesh()
: flags(0), numFrames(0), numMatFrames(0), vertsPerFrame(0) : mFlags(0), mNumFrames(0), mNumMatFrames(0), mVertsPerFrame(0)
{ {
} }
@ -44,43 +44,43 @@ void AppMesh::computeBounds(Box3F& bounds)
// Setup bone transforms // Setup bone transforms
Vector<MatrixF> boneTransforms; Vector<MatrixF> boneTransforms;
boneTransforms.setSize( nodeIndex.size() ); boneTransforms.setSize( mNodeIndex.size() );
for (S32 iBone = 0; iBone < boneTransforms.size(); iBone++) for (S32 iBone = 0; iBone < boneTransforms.size(); iBone++)
{ {
MatrixF nodeMat = bones[iBone]->getNodeTransform( TSShapeLoader::DefaultTime ); MatrixF nodeMat = mBones[iBone]->getNodeTransform( TSShapeLoader::DefaultTime );
TSShapeLoader::zapScale(nodeMat); TSShapeLoader::zapScale(nodeMat);
boneTransforms[iBone].mul( nodeMat, initialTransforms[iBone] ); boneTransforms[iBone].mul( nodeMat, mInitialTransforms[iBone] );
} }
// Multiply verts by weighted bone transforms // Multiply verts by weighted bone transforms
for (S32 iVert = 0; iVert < initialVerts.size(); iVert++) for (S32 iVert = 0; iVert < mInitialVerts.size(); iVert++)
points[iVert].set( Point3F::Zero ); mPoints[iVert].set( Point3F::Zero );
for (S32 iWeight = 0; iWeight < vertexIndex.size(); iWeight++) for (S32 iWeight = 0; iWeight < mVertexIndex.size(); iWeight++)
{ {
const S32& vertIndex = vertexIndex[iWeight]; const S32& vertIndex = mVertexIndex[iWeight];
const MatrixF& deltaTransform = boneTransforms[ boneIndex[iWeight] ]; const MatrixF& deltaTransform = boneTransforms[ mBoneIndex[iWeight] ];
Point3F v; Point3F v;
deltaTransform.mulP( initialVerts[vertIndex], &v ); deltaTransform.mulP( mInitialVerts[vertIndex], &v );
v *= weight[iWeight]; v *= mWeight[iWeight];
points[vertIndex] += v; mPoints[vertIndex] += v;
} }
// compute bounds for the skinned mesh // compute bounds for the skinned mesh
for (S32 iVert = 0; iVert < initialVerts.size(); iVert++) for (S32 iVert = 0; iVert < mInitialVerts.size(); iVert++)
bounds.extend( points[iVert] ); bounds.extend( mPoints[iVert] );
} }
else else
{ {
MatrixF transform = getMeshTransform(TSShapeLoader::DefaultTime); MatrixF transform = getMeshTransform(TSShapeLoader::DefaultTime);
TSShapeLoader::zapScale(transform); TSShapeLoader::zapScale(transform);
for (S32 iVert = 0; iVert < points.size(); iVert++) for (S32 iVert = 0; iVert < mPoints.size(); iVert++)
{ {
Point3F p; Point3F p;
transform.mulP(points[iVert], &p); transform.mulP(mPoints[iVert], &p);
bounds.extend(p); bounds.extend(p);
} }
} }
@ -89,39 +89,39 @@ void AppMesh::computeBounds(Box3F& bounds)
void AppMesh::computeNormals() void AppMesh::computeNormals()
{ {
// Clear normals // Clear normals
normals.setSize( points.size() ); mNormals.setSize( mPoints.size() );
for (S32 iNorm = 0; iNorm < normals.size(); iNorm++) for (S32 iNorm = 0; iNorm < mNormals.size(); iNorm++)
normals[iNorm] = Point3F::Zero; mNormals[iNorm] = Point3F::Zero;
// Sum triangle normals for each vertex // Sum triangle normals for each vertex
for (S32 iPrim = 0; iPrim < primitives.size(); iPrim++) for (S32 iPrim = 0; iPrim < mPrimitives.size(); iPrim++)
{ {
const TSDrawPrimitive& prim = primitives[iPrim]; const TSDrawPrimitive& prim = mPrimitives[iPrim];
for (S32 iInd = 0; iInd < prim.numElements; iInd += 3) for (S32 iInd = 0; iInd < prim.numElements; iInd += 3)
{ {
// Compute the normal for this triangle // Compute the normal for this triangle
S32 idx0 = indices[prim.start + iInd + 0]; S32 idx0 = mIndices[prim.start + iInd + 0];
S32 idx1 = indices[prim.start + iInd + 1]; S32 idx1 = mIndices[prim.start + iInd + 1];
S32 idx2 = indices[prim.start + iInd + 2]; S32 idx2 = mIndices[prim.start + iInd + 2];
const Point3F& v0 = points[idx0]; const Point3F& v0 = mPoints[idx0];
const Point3F& v1 = points[idx1]; const Point3F& v1 = mPoints[idx1];
const Point3F& v2 = points[idx2]; const Point3F& v2 = mPoints[idx2];
Point3F n; Point3F n;
mCross(v2 - v0, v1 - v0, &n); mCross(v2 - v0, v1 - v0, &n);
n.normalize(); // remove this to use 'weighted' normals (large triangles will have more effect) n.normalize(); // remove this to use 'weighted' normals (large triangles will have more effect)
normals[idx0] += n; mNormals[idx0] += n;
normals[idx1] += n; mNormals[idx1] += n;
normals[idx2] += n; mNormals[idx2] += n;
} }
} }
// Normalize the vertex normals (this takes care of averaging the triangle normals) // Normalize the vertex normals (this takes care of averaging the triangle normals)
for (S32 iNorm = 0; iNorm < normals.size(); iNorm++) for (S32 iNorm = 0; iNorm < mNormals.size(); iNorm++)
normals[iNorm].normalize(); mNormals[iNorm].normalize();
} }
TSMesh* AppMesh::constructTSMesh() TSMesh* AppMesh::constructTSMesh()
@ -133,13 +133,13 @@ TSMesh* AppMesh::constructTSMesh()
tsmesh = tsskin; tsmesh = tsskin;
// Copy skin elements // Copy skin elements
tsskin->weight = weight; tsskin->weight = mWeight;
tsskin->boneIndex = boneIndex; tsskin->boneIndex = mBoneIndex;
tsskin->vertexIndex = vertexIndex; tsskin->vertexIndex = mVertexIndex;
tsskin->batchData.nodeIndex = nodeIndex; tsskin->batchData.nodeIndex = mNodeIndex;
tsskin->batchData.initialTransforms = initialTransforms; tsskin->batchData.initialTransforms = mInitialTransforms;
tsskin->batchData.initialVerts = initialVerts; tsskin->batchData.initialVerts = mInitialVerts;
tsskin->batchData.initialNorms = initialNorms; tsskin->batchData.initialNorms = mInitialNorms;
} }
else else
{ {
@ -147,20 +147,20 @@ TSMesh* AppMesh::constructTSMesh()
} }
// Copy mesh elements // Copy mesh elements
tsmesh->verts = points; tsmesh->verts = mPoints;
tsmesh->norms = normals; tsmesh->norms = mNormals;
tsmesh->tverts = uvs; tsmesh->tverts = mUVs;
tsmesh->primitives = primitives; tsmesh->primitives = mPrimitives;
tsmesh->indices = indices; tsmesh->indices = mIndices;
tsmesh->colors = colors; tsmesh->colors = mColors;
tsmesh->tverts2 = uv2s; tsmesh->tverts2 = mUV2s;
// Finish initializing the shape // Finish initializing the shape
tsmesh->setFlags(flags); tsmesh->setFlags(mFlags);
tsmesh->computeBounds(); tsmesh->computeBounds();
tsmesh->numFrames = numFrames; tsmesh->numFrames = mNumFrames;
tsmesh->numMatFrames = numMatFrames; tsmesh->numMatFrames = mNumMatFrames;
tsmesh->vertsPerFrame = vertsPerFrame; tsmesh->vertsPerFrame = mVertsPerFrame;
tsmesh->createTangents(tsmesh->verts, tsmesh->norms); tsmesh->createTangents(tsmesh->verts, tsmesh->norms);
tsmesh->encodedNorms.set(NULL,0); tsmesh->encodedNorms.set(NULL,0);

View file

@ -42,33 +42,33 @@ class AppMesh
{ {
public: public:
// Mesh and skin elements // Mesh and skin elements
Vector<Point3F> points; Vector<Point3F> mPoints;
Vector<Point3F> normals; Vector<Point3F> mNormals;
Vector<Point2F> uvs; Vector<Point2F> mUVs;
Vector<Point2F> uv2s; Vector<Point2F> mUV2s;
Vector<ColorI> colors; Vector<ColorI> mColors;
Vector<TSDrawPrimitive> primitives; Vector<TSDrawPrimitive> mPrimitives;
Vector<U32> indices; Vector<U32> mIndices;
// Skin elements // Skin elements
Vector<F32> weight; Vector<F32> mWeight;
Vector<S32> boneIndex; Vector<S32> mBoneIndex;
Vector<S32> vertexIndex; Vector<S32> mVertexIndex;
Vector<S32> nodeIndex; Vector<S32> mNodeIndex;
Vector<MatrixF> initialTransforms; Vector<MatrixF> mInitialTransforms;
Vector<Point3F> initialVerts; Vector<Point3F> mInitialVerts;
Vector<Point3F> initialNorms; Vector<Point3F> mInitialNorms;
U32 flags; U32 mFlags;
U32 vertsPerFrame; U32 mVertsPerFrame;
S32 numFrames; S32 mNumFrames;
S32 numMatFrames; S32 mNumMatFrames;
// Loader elements (can be discarded after loading) // Loader elements (can be discarded after loading)
S32 detailSize; S32 mDetailSize;
MatrixF objectOffset; MatrixF mObjectOffset;
Vector<AppNode*> bones; Vector<AppNode*> mBones;
static Vector<AppMaterial*> appMaterials; static Vector<AppMaterial*> mAppMaterials;
public: public:
AppMesh(); AppMesh();

View file

@ -377,7 +377,7 @@ bool cmpMeshNameAndSize(const String& key, const Vector<String>& names, void* ar
{ {
if (names[i].compare(key, 0, String::NoCase) == 0) if (names[i].compare(key, 0, String::NoCase) == 0)
{ {
if (meshes[i]->detailSize == meshSize) if (meshes[i]->mDetailSize == meshSize)
return false; return false;
} }
} }
@ -396,17 +396,17 @@ void TSShapeLoader::generateObjects()
for (S32 iMesh = 0; iMesh < subshape->objMeshes.size(); iMesh++) for (S32 iMesh = 0; iMesh < subshape->objMeshes.size(); iMesh++)
{ {
AppMesh* mesh = subshape->objMeshes[iMesh]; AppMesh* mesh = subshape->objMeshes[iMesh];
mesh->detailSize = 2; mesh->mDetailSize = 2;
String name = String::GetTrailingNumber( mesh->getName(), mesh->detailSize ); String name = String::GetTrailingNumber( mesh->getName(), mesh->mDetailSize );
name = getUniqueName( name, cmpMeshNameAndSize, meshNames, &(subshape->objMeshes), (void*)mesh->detailSize ); name = getUniqueName( name, cmpMeshNameAndSize, meshNames, &(subshape->objMeshes), (void*)mesh->mDetailSize );
meshNames.push_back( name ); meshNames.push_back( name );
// Fix up any collision details that don't have a negative detail level. // Fix up any collision details that don't have a negative detail level.
if ( dStrStartsWith(meshNames[iMesh], "Collision") || if ( dStrStartsWith(meshNames[iMesh], "Collision") ||
dStrStartsWith(meshNames[iMesh], "LOSCol") ) dStrStartsWith(meshNames[iMesh], "LOSCol") )
{ {
if (mesh->detailSize > 0) if (mesh->mDetailSize > 0)
mesh->detailSize = -mesh->detailSize; mesh->mDetailSize = -mesh->mDetailSize;
} }
} }
@ -421,7 +421,7 @@ void TSShapeLoader::generateObjects()
{ {
if ((meshNames[i].compare(meshNames[j]) < 0) || if ((meshNames[i].compare(meshNames[j]) < 0) ||
((meshNames[i].compare(meshNames[j]) == 0) && ((meshNames[i].compare(meshNames[j]) == 0) &&
(subshape->objMeshes[i]->detailSize < subshape->objMeshes[j]->detailSize))) (subshape->objMeshes[i]->mDetailSize < subshape->objMeshes[j]->mDetailSize)))
{ {
{ {
AppMesh* tmp = subshape->objMeshes[i]; AppMesh* tmp = subshape->objMeshes[i];
@ -463,17 +463,17 @@ void TSShapeLoader::generateObjects()
shape->objects.last().numMeshes++; shape->objects.last().numMeshes++;
// Set mesh flags // Set mesh flags
mesh->flags = 0; mesh->mFlags = 0;
if (mesh->isBillboard()) if (mesh->isBillboard())
{ {
mesh->flags |= TSMesh::Billboard; mesh->mFlags |= TSMesh::Billboard;
if (mesh->isBillboardZAxis()) if (mesh->isBillboardZAxis())
mesh->flags |= TSMesh::BillboardZAxis; mesh->mFlags |= TSMesh::BillboardZAxis;
} }
// Set the detail name... do fixups for collision details. // Set the detail name... do fixups for collision details.
const char* detailName = "detail"; const char* detailName = "detail";
if ( mesh->detailSize < 0 ) if ( mesh->mDetailSize < 0 )
{ {
if ( dStrStartsWith(meshNames[iMesh], "Collision") || if ( dStrStartsWith(meshNames[iMesh], "Collision") ||
dStrStartsWith(meshNames[iMesh], "Col") ) dStrStartsWith(meshNames[iMesh], "Col") )
@ -484,11 +484,11 @@ void TSShapeLoader::generateObjects()
// Attempt to add the detail (will fail if it already exists) // Attempt to add the detail (will fail if it already exists)
S32 oldNumDetails = shape->details.size(); S32 oldNumDetails = shape->details.size();
shape->addDetail(detailName, mesh->detailSize, iSub); shape->addDetail(detailName, mesh->mDetailSize, iSub);
if (shape->details.size() > oldNumDetails) if (shape->details.size() > oldNumDetails)
{ {
Con::warnf("Object mesh \"%s\" has no matching detail (\"%s%d\" has" Con::warnf("Object mesh \"%s\" has no matching detail (\"%s%d\" has"
" been added automatically)", mesh->getName(false), detailName, mesh->detailSize); " been added automatically)", mesh->getName(false), detailName, mesh->mDetailSize);
} }
} }
@ -519,30 +519,30 @@ void TSShapeLoader::generateSkins()
skin->lookupSkinData(); skin->lookupSkinData();
// Just copy initial verts and norms for now // Just copy initial verts and norms for now
skin->initialVerts.set(skin->points.address(), skin->vertsPerFrame); skin->mInitialVerts.set(skin->mPoints.address(), skin->mVertsPerFrame);
skin->initialNorms.set(skin->normals.address(), skin->vertsPerFrame); skin->mInitialNorms.set(skin->mNormals.address(), skin->mVertsPerFrame);
// Map bones to nodes // Map bones to nodes
skin->nodeIndex.setSize(skin->bones.size()); skin->mNodeIndex.setSize(skin->mBones.size());
for (S32 iBone = 0; iBone < skin->bones.size(); iBone++) for (S32 iBone = 0; iBone < skin->mBones.size(); iBone++)
{ {
// Find the node that matches this bone // Find the node that matches this bone
skin->nodeIndex[iBone] = -1; skin->mNodeIndex[iBone] = -1;
for (S32 iNode = 0; iNode < appNodes.size(); iNode++) for (S32 iNode = 0; iNode < appNodes.size(); iNode++)
{ {
if (appNodes[iNode]->isEqual(skin->bones[iBone])) if (appNodes[iNode]->isEqual(skin->mBones[iBone]))
{ {
delete skin->bones[iBone]; delete skin->mBones[iBone];
skin->bones[iBone] = appNodes[iNode]; skin->mBones[iBone] = appNodes[iNode];
skin->nodeIndex[iBone] = iNode; skin->mNodeIndex[iBone] = iNode;
break; break;
} }
} }
if (skin->nodeIndex[iBone] == -1) if (skin->mNodeIndex[iBone] == -1)
{ {
Con::warnf("Could not find bone %d. Defaulting to first node", iBone); Con::warnf("Could not find bone %d. Defaulting to first node", iBone);
skin->nodeIndex[iBone] = 0; skin->mNodeIndex[iBone] = 0;
} }
} }
} }
@ -569,7 +569,7 @@ void TSShapeLoader::generateDefaultStates()
zapScale(nodeMat); zapScale(nodeMat);
appMesh->objectOffset = nodeMat.inverse() * meshMat; appMesh->mObjectOffset = nodeMat.inverse() * meshMat;
} }
generateObjectState(shape->objects[iObject], DefaultTime, true, true); generateObjectState(shape->objects[iObject], DefaultTime, true, true);
@ -603,8 +603,8 @@ void TSShapeLoader::generateObjectState(TSShape::Object& obj, F32 t, bool addFra
generateFrame(obj, t, addFrame, addMatFrame); generateFrame(obj, t, addFrame, addMatFrame);
// set the frame number for the object state // set the frame number for the object state
state.frameIndex = appMeshes[obj.startMeshIndex]->numFrames - 1; state.frameIndex = appMeshes[obj.startMeshIndex]->mNumFrames - 1;
state.matFrameIndex = appMeshes[obj.startMeshIndex]->numMatFrames - 1; state.matFrameIndex = appMeshes[obj.startMeshIndex]->mNumMatFrames - 1;
} }
} }
@ -614,45 +614,45 @@ void TSShapeLoader::generateFrame(TSShape::Object& obj, F32 t, bool addFrame, bo
{ {
AppMesh* appMesh = appMeshes[obj.startMeshIndex + iMesh]; AppMesh* appMesh = appMeshes[obj.startMeshIndex + iMesh];
U32 oldNumPoints = appMesh->points.size(); U32 oldNumPoints = appMesh->mPoints.size();
U32 oldNumUvs = appMesh->uvs.size(); U32 oldNumUvs = appMesh->mUVs.size();
// Get the mesh geometry at time, 't' // Get the mesh geometry at time, 't'
// Geometry verts, normals and tverts can be animated (different set for // Geometry verts, normals and tverts can be animated (different set for
// each frame), but the TSDrawPrimitives stay the same, so the way lockMesh // each frame), but the TSDrawPrimitives stay the same, so the way lockMesh
// works is that it will only generate the primitives once, then after that // works is that it will only generate the primitives once, then after that
// will just append verts, normals and tverts each time it is called. // will just append verts, normals and tverts each time it is called.
appMesh->lockMesh(t, appMesh->objectOffset); appMesh->lockMesh(t, appMesh->mObjectOffset);
// Calculate vertex normals if required // Calculate vertex normals if required
if (appMesh->normals.size() != appMesh->points.size()) if (appMesh->mNormals.size() != appMesh->mPoints.size())
appMesh->computeNormals(); appMesh->computeNormals();
// If this is the first call, set the number of points per frame // If this is the first call, set the number of points per frame
if (appMesh->numFrames == 0) if (appMesh->mNumFrames == 0)
{ {
appMesh->vertsPerFrame = appMesh->points.size(); appMesh->mVertsPerFrame = appMesh->mPoints.size();
} }
else else
{ {
// Check frame topology => ie. that the right number of points, normals // Check frame topology => ie. that the right number of points, normals
// and tverts was added // and tverts was added
if ((appMesh->points.size() - oldNumPoints) != appMesh->vertsPerFrame) if ((appMesh->mPoints.size() - oldNumPoints) != appMesh->mVertsPerFrame)
{ {
Con::warnf("Wrong number of points (%d) added at time=%f (expected %d)", Con::warnf("Wrong number of points (%d) added at time=%f (expected %d)",
appMesh->points.size() - oldNumPoints, t, appMesh->vertsPerFrame); appMesh->mPoints.size() - oldNumPoints, t, appMesh->mVertsPerFrame);
addFrame = false; addFrame = false;
} }
if ((appMesh->normals.size() - oldNumPoints) != appMesh->vertsPerFrame) if ((appMesh->mNormals.size() - oldNumPoints) != appMesh->mVertsPerFrame)
{ {
Con::warnf("Wrong number of normals (%d) added at time=%f (expected %d)", Con::warnf("Wrong number of normals (%d) added at time=%f (expected %d)",
appMesh->normals.size() - oldNumPoints, t, appMesh->vertsPerFrame); appMesh->mNormals.size() - oldNumPoints, t, appMesh->mVertsPerFrame);
addFrame = false; addFrame = false;
} }
if ((appMesh->uvs.size() - oldNumUvs) != appMesh->vertsPerFrame) if ((appMesh->mUVs.size() - oldNumUvs) != appMesh->mVertsPerFrame)
{ {
Con::warnf("Wrong number of tverts (%d) added at time=%f (expected %d)", Con::warnf("Wrong number of tverts (%d) added at time=%f (expected %d)",
appMesh->uvs.size() - oldNumUvs, t, appMesh->vertsPerFrame); appMesh->mUVs.size() - oldNumUvs, t, appMesh->mVertsPerFrame);
addMatFrame = false; addMatFrame = false;
} }
} }
@ -663,21 +663,21 @@ void TSShapeLoader::generateFrame(TSShape::Object& obj, F32 t, bool addFrame, bo
// points/normals/tverts are already in place! // points/normals/tverts are already in place!
if (addFrame) if (addFrame)
{ {
appMesh->numFrames++; appMesh->mNumFrames++;
} }
else else
{ {
appMesh->points.setSize(oldNumPoints); appMesh->mPoints.setSize(oldNumPoints);
appMesh->normals.setSize(oldNumPoints); appMesh->mNormals.setSize(oldNumPoints);
} }
if (addMatFrame) if (addMatFrame)
{ {
appMesh->numMatFrames++; appMesh->mNumMatFrames++;
} }
else else
{ {
appMesh->uvs.setSize(oldNumPoints); appMesh->mUVs.setSize(oldNumPoints);
} }
} }
} }
@ -690,11 +690,11 @@ void TSShapeLoader::generateMaterialList()
{ {
// Install the materials into the material list // Install the materials into the material list
shape->materialList = new TSMaterialList; shape->materialList = new TSMaterialList;
for (S32 iMat = 0; iMat < AppMesh::appMaterials.size(); iMat++) for (S32 iMat = 0; iMat < AppMesh::mAppMaterials.size(); iMat++)
{ {
updateProgress(Load_GenerateMaterials, "Generating materials...", AppMesh::appMaterials.size(), iMat); updateProgress(Load_GenerateMaterials, "Generating materials...", AppMesh::mAppMaterials.size(), iMat);
AppMaterial* appMat = AppMesh::appMaterials[iMat]; AppMaterial* appMat = AppMesh::mAppMaterials[iMat];
shape->materialList->push_back(appMat->getName(), appMat->getFlags(), U32(-1), U32(-1), U32(-1), 1.0f, appMat->getReflectance()); shape->materialList->push_back(appMat->getName(), appMat->getFlags(), U32(-1), U32(-1), U32(-1), 1.0f, appMat->getReflectance());
} }
} }
@ -1119,7 +1119,7 @@ void TSShapeLoader::sortDetails()
// object does not already have a mesh with an equal or higher detail) // object does not already have a mesh with an equal or higher detail)
S32 meshIndex = (iDet < object.numMeshes) ? iDet : object.numMeshes-1; S32 meshIndex = (iDet < object.numMeshes) ? iDet : object.numMeshes-1;
if (appMeshes[object.startMeshIndex + meshIndex]->detailSize < shape->details[iDet].size) if (appMeshes[object.startMeshIndex + meshIndex]->mDetailSize < shape->details[iDet].size)
{ {
// Add a NULL mesh // Add a NULL mesh
appMeshes.insert(object.startMeshIndex + iDet, NULL); appMeshes.insert(object.startMeshIndex + iDet, NULL);
@ -1256,9 +1256,9 @@ TSShapeLoader::~TSShapeLoader()
clearNodeTransformCache(); clearNodeTransformCache();
// Clear shared AppMaterial list // Clear shared AppMaterial list
for (S32 iMat = 0; iMat < AppMesh::appMaterials.size(); iMat++) for (S32 iMat = 0; iMat < AppMesh::mAppMaterials.size(); iMat++)
delete AppMesh::appMaterials[iMat]; delete AppMesh::mAppMaterials[iMat];
AppMesh::appMaterials.clear(); AppMesh::mAppMaterials.clear();
// Delete Subshapes // Delete Subshapes
delete boundsNode; delete boundsNode;