bool Gu::EdgeList::Load(const PxStream& stream) { // Import header PxU32 Version; bool Mismatch; if(!ReadHeader('E', 'D', 'G', 'E', Version, Mismatch, stream)) return false; // Import edges mData.mNbEdges = ReadDword(Mismatch, stream); //mEdges = ICE_NEW_MEM(Edge[mNbEdges],Edge); mData.mEdges = (Gu::EdgeData*)PX_ALLOC(sizeof(Gu::EdgeData)*mData.mNbEdges); stream.readBuffer(mData.mEdges, sizeof(Gu::EdgeData)*mData.mNbEdges); mData.mNbFaces = ReadDword(Mismatch, stream); //mEdgeFaces = ICE_NEW_MEM(EdgeTriangle[mNbFaces],EdgeTriangle); mData.mEdgeFaces = (Gu::EdgeTriangleData*)PX_ALLOC(sizeof(Gu::EdgeTriangleData)*mData.mNbFaces); stream.readBuffer(mData.mEdgeFaces, sizeof(Gu::EdgeTriangleData)*mData.mNbFaces); //mEdgeToTriangles = ICE_NEW_MEM(EdgeDesc[mNbEdges],EdgeDesc); mData.mEdgeToTriangles = (Gu::EdgeDescData*)PX_ALLOC(sizeof(Gu::EdgeDescData)*mData.mNbEdges); stream.readBuffer(mData.mEdgeToTriangles, sizeof(Gu::EdgeDescData)*mData.mNbEdges); PxU32 LastOffset = mData.mEdgeToTriangles[mData.mNbEdges-1].Offset + mData.mEdgeToTriangles[mData.mNbEdges-1].Count; mData.mFacesByEdges = (PxU32*)PX_ALLOC(sizeof(PxU32)*LastOffset); stream.readBuffer(mData.mFacesByEdges, sizeof(PxU32)*LastOffset); return true; }
bool Adjacencies::Load(const PxStream& stream) { // Import header PxU32 Version; bool Mismatch; if(!ReadHeader('A', 'D', 'J', 'A', Version, Mismatch, stream)) return false; // Import adjacencies mNbFaces = ReadDword(Mismatch, stream); mFaces = PX_NEW(AdjTriangle)[mNbFaces]; stream.readBuffer(mFaces, sizeof(AdjTriangle)*mNbFaces); return true; }
bool Gu::TriangleMesh::load(const PxStream& stream) { mesh.release(); // Import header PxU32 version; bool mismatch; if(!readHeader('M', 'E', 'S', 'H', version, mismatch, stream)) return false; // Check if old (incompatible) mesh format is loaded if (version < 1) { Ps::getFoundation().error(PxErrorCode::eINTERNAL_ERROR, __FILE__, __LINE__, "Loading triangle mesh failed: " "Deprecated mesh cooking format. Please install and run the mesh converter tool to convert your mesh to the new cooking format."); return false; } // Import serialization flags PxU32 serialFlags = readDword(mismatch, stream); // Import misc values mesh.mConvexEdgeThreshold = readFloat(mismatch, stream); if (version < 2) { readDword(mismatch, stream); // Used to be heightFieldVerticalAxis readFloat(mismatch, stream); // Used to be heightFieldVerticalExtent } // Import mesh PxVec3* verts = mesh.allocateVertices(readDword(mismatch, stream)); void* tris = mesh.allocateTriangles(readDword(mismatch, stream)); stream.readBuffer(verts, sizeof(PxVec3)*mesh.getNumVertices()); if(mismatch) { for(PxU32 i=0;i<mesh.getNumVertices();i++) { #if defined(PX_WII) *(PxU32*)&verts[i].x = flip((PxU32*)&verts[i].x); *(PxU32*)&verts[i].y = flip((PxU32*)&verts[i].y); *(PxU32*)&verts[i].z = flip((PxU32*)&verts[i].z); #else verts[i].x = flip(&verts[i].x); verts[i].y = flip(&verts[i].y); verts[i].z = flip(&verts[i].z); #endif } } //TODO: stop support for format conversion on load!! if(serialFlags & IMSF_8BIT_INDICES) { if (mesh.has16BitIndices()) { PxU16* tris16 = reinterpret_cast<PxU16*>(tris); for(PxU32 i=0;i<3*mesh.getNumTriangles();i++) *tris16++ = stream.readByte(); } else { PxU32* tris32 = reinterpret_cast<PxU32*>(tris); for(PxU32 i=0;i<3*mesh.getNumTriangles();i++) *tris32++ = stream.readByte(); } } else if(serialFlags & IMSF_16BIT_INDICES) { PxU16 x; if (mesh.has16BitIndices()) { PxU16* tris16 = reinterpret_cast<PxU16*>(tris); if (mismatch) for(PxU32 i=0;i<3*mesh.getNumTriangles();i++) x = stream.readWord(), *tris16++ = flip(&x); else stream.readBuffer(tris16, 3*sizeof(PxU16)*mesh.getNumTriangles()); //for(PxU32 i=0;i<3*mesh.getNumTriangles();i++) // *tris16++ = stream.readWord(); } else { PxU32* tris32 = reinterpret_cast<PxU32*>(tris); if (mismatch) for(PxU32 i=0;i<3*mesh.getNumTriangles();i++) x = stream.readWord(), *tris32++ = flip(&x); else for(PxU32 i=0;i<3*mesh.getNumTriangles();i++) *tris32++ = stream.readWord(); } } else { PxU32 x; if (mesh.has16BitIndices()) { PxU16* tris16 = reinterpret_cast<PxU16*>(tris); if (mismatch) for(PxU32 i=0;i<3*mesh.getNumTriangles();i++) { x = stream.readDword(); PX_ASSERT(x <= 0xffff); *tris16++ = (PxU16)flip(&x); } else for(PxU32 i=0;i<3*mesh.getNumTriangles();i++) { x = stream.readDword(); PX_ASSERT(x <= 0xffff); *tris16++ = (PxU16)x; } } else { PxU32* tris32 = reinterpret_cast<PxU32*>(tris); if (mismatch) for(PxU32 i=0;i<3*mesh.getNumTriangles();i++) x = stream.readDword(), *tris32++ = flip(&x); else stream.readBuffer(tris32, 3*sizeof(PxU32)*mesh.getNumTriangles()); //for(PxU32 i=0;i<3*mesh.getNumTriangles();i++) // *tris32++ = stream.readDword(); } } if(serialFlags & IMSF_MATERIALS) { PxU16* materials = mesh.allocateMaterials(); stream.readBuffer(materials, sizeof(PxU16)*mesh.getNumTriangles()); if(mismatch) { for(PxU32 i=0;i<mesh.getNumTriangles();i++) materials[i] = flip(&materials[i]); } } if(serialFlags & IMSF_FACE_REMAP) { PxU32* remap = mesh.allocateFaceRemap(); /* stream.readBuffer(remap, sizeof(PxU32)*mesh.getNumTriangles()); if(mismatch) { for(PxU32 i=0;i<mesh.getNumTriangles();i++) remap[i] = flip(&remap[i]); }*/ readIndices(readDword(mismatch, stream), mesh.getNumTriangles(), remap, stream, mismatch); } if(version <= 6) { PxU32 dummy0 = readDword(mismatch, stream); PxU32 dummy1 = readDword(mismatch, stream); if(dummy0) { PxU16* convexParts = PX_NEW_TEMP(PxU16)[mesh.getNumTriangles()]; stream.readBuffer(convexParts, sizeof(PxU16)*mesh.getNumTriangles()); PX_DELETE_POD(convexParts); } if(dummy1) { if(dummy1<256) { PxU8* flatParts8 = PX_NEW_TEMP(PxU8)[mesh.getNumTriangles()]; stream.readBuffer(flatParts8, sizeof(PxU8)*mesh.getNumTriangles()); PX_DELETE_POD(flatParts8); } else { PxU16* flatParts16 = PX_NEW_TEMP(PxU16)[mesh.getNumTriangles()]; stream.readBuffer(flatParts16, sizeof(PxU16)*mesh.getNumTriangles()); PX_DELETE_POD(flatParts16); } } } // Import Opcode model { PxU32 modelSize = readDword(mismatch, stream); if(!mesh.loadOpcodeModel(stream, version)) return false; } // Import local bounds mesh.mData.mOpcodeModel.mGeomEpsilon = readFloat(mismatch, stream); if(version<4) { Gu::Sphere localSphere; // PT: not needed anymore localSphere.center.x = readFloat(mismatch, stream); localSphere.center.y = readFloat(mismatch, stream); localSphere.center.z = readFloat(mismatch, stream); localSphere.radius = readFloat(mismatch, stream); } mesh.mData.mAABB.minimum.x = readFloat(mismatch, stream); mesh.mData.mAABB.minimum.y = readFloat(mismatch, stream); mesh.mData.mAABB.minimum.z = readFloat(mismatch, stream); mesh.mData.mAABB.maximum.x = readFloat(mismatch, stream); mesh.mData.mAABB.maximum.y = readFloat(mismatch, stream); mesh.mData.mAABB.maximum.z = readFloat(mismatch, stream); // Import mass info if(version<3) { PxReal mass = readFloat(mismatch, stream); if(mass!=-1.0f) { float b[9]; readFloatBuffer(b, 9, mismatch, stream); readFloatBuffer(b, 3, mismatch, stream); } } PxU32 nb = readDword(mismatch, stream); if(nb) { PX_ASSERT(nb==mesh.getNumTriangles()); mesh.mData.mExtraTrigData = PX_NEW(PxU8)[nb]; // No need to convert those bytes stream.readBuffer(mesh.mData.mExtraTrigData, nb*sizeof(PxU8)); } return true; }