//----------------------------------------------------------------------------- // Torque Game Engine // Copyright (C) GarageGames.com, Inc. //----------------------------------------------------------------------------- #ifdef _MSC_VER #pragma warning(disable : 4786 4018) #endif #include "appMesh.h" #include "appTime.h" #include "dtsUtil.h" #include "appIfl.h" #include "appConfig.h" namespace DTS { AppMesh::AppMesh() { mLocked = false; mSkinDataFetched = false; } AppMesh::~AppMesh() { assert(!mLocked && "Mesh is locked"); S32 i; for (i=0; itype < face2->type) return -1; else if (face2->type < face1->type) return 1; else return 0; } void AppMesh::sortFaceList() { if (mFaces.size() != 0) qsort(&mFaces[0],mFaces.size(),sizeof(Primitive),compareFaces); } Box AppMesh::getBounds(const Matrix<4,4,F32> & objectOffset) { assert(!mLocked && "Mesh is locked"); AppMeshLock lock = lockMesh(AppTime::DefaultTime(),objectOffset); Box bounds(Point3D( 10E30f, 10E30f, 10E30f),Point3D(-10E30f,-10E30f,-10E30f)); const Point3D * verts = getVerts(); for (S32 i=0; i verts[i].x()) bounds.min.x(verts[i].x()); if (bounds.min.y() > verts[i].y()) bounds.min.y(verts[i].y()); if (bounds.min.z() > verts[i].z()) bounds.min.z(verts[i].z()); if (bounds.max.x() < verts[i].x()) bounds.max.x(verts[i].x()); if (bounds.max.y() < verts[i].y()) bounds.max.y(verts[i].y()); if (bounds.max.z() < verts[i].z()) bounds.max.z(verts[i].z()); } return bounds; } F32 AppMesh::getRadius(const Matrix<4,4,F32> & objectOffset) { Box bounds = getBounds(objectOffset); Point3D diameter = bounds.max-bounds.min; return diameter.length() * 0.5f; } F32 AppMesh::getTubeRadius(const Matrix<4,4,F32> & objectOffset) { Box bounds = getBounds(objectOffset); Point2D diameter(bounds.max.x()-bounds.min.x(),bounds.max.y()-bounds.min.y()); return diameter.length() * 0.5f; } bool AppMesh::isBillboard() { return !_strnicmp(getName(),"BB::",4) || !_strnicmp(getName(),"BB_",3) || !_strnicmp(getName(),"BBZ::",5) || !_strnicmp(getName(),"BBZ_",4); } bool AppMesh::isBillboardZAxis() { return !_strnicmp(getName(),"BBZ::",5) || !_strnicmp(getName(),"BBZ_",4); } bool AppMesh::isSorted() { return !_strnicmp(getName(),"SORT::",6) || !_strnicmp(getName(),"SORT_",5); } bool AppMesh::isDummy() { return !_strnicmp(getName(), "dummy", 5); } bool AppMesh::animatesVis(const AppSequenceData & seqData) { F32 defaultVis = getVisValue(AppTime::DefaultTime()); AppTime time = seqData.startTime; for (S32 frame=0; frame & faces, std::vector & verts, std::vector & tverts, std::vector & indices, std::vector & smooth, std::vector & normals, std::vector * vertId) { assert(mLocked && "Mesh isn't locked"); faces = mFaces; verts = mVerts; tverts = mTVerts; indices = mIndices; normals = mNormals; smooth = mSmooth; if (vertId) *vertId = mVertId; } AppMeshLock AppMesh::lockMesh(const AppTime & time, const Matrix<4,4,F32> & objectOffset) { assert(!mLocked && "Mesh is already locked"); time,objectOffset; // if more than one mat type, make mats consecutive sortFaceList(); mLocked = true; return AppMeshLock(this); } void AppMesh::unlockMesh() { assert(mLocked && "Mesh isn't locked"); mFaces.clear(); mVerts.clear(); mTVerts.clear(); mIndices.clear(); mNormals.clear(); mSmooth.clear(); mVertId.clear(); mLocked = false; } void AppMeshLock::doit() { if (mObj) mObj->unlockMesh(); } }; // namespace DTS