| 194 | }; |
| 195 | |
| 196 | void SampleLargeWorld::BinData::serialize( SampleLargeWorld* parent, const char* terrainFile) |
| 197 | { |
| 198 | PxBinFile binFile(terrainFile); |
| 199 | |
| 200 | if( !binFile.isValid()) |
| 201 | { |
| 202 | char errMsg[256]; |
| 203 | Ps::snprintf(errMsg, 256, "Couldn't load %s\n", terrainFile); |
| 204 | parent->fatalError(errMsg); |
| 205 | |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | PxU32 nbMeshes = binFile.LoadDword(); |
| 210 | |
| 211 | //Suppose the terrain is N*N |
| 212 | mDim = (CoordType)PxSqrt((PxF32)nbMeshes); |
| 213 | |
| 214 | PxU32 totalNbTris = 0; |
| 215 | PxU32 totalNbVerts = 0; |
| 216 | |
| 217 | mTerrainVertices.resize( nbMeshes ); |
| 218 | mTerrainIndices.resize( nbMeshes ); |
| 219 | |
| 220 | for(PxU32 i = 0; i < nbMeshes; ++i) |
| 221 | { |
| 222 | binFile.LoadDword(); |
| 223 | binFile.LoadDword(); |
| 224 | |
| 225 | const PxU32 nbVerts = binFile.LoadDword(); |
| 226 | const PxU32 nbFaces = binFile.LoadDword(); |
| 227 | |
| 228 | totalNbTris += nbFaces; |
| 229 | totalNbVerts += nbVerts; |
| 230 | |
| 231 | SampleArray<PxVec3>& vertices = mTerrainVertices[i]; |
| 232 | vertices.resize(nbVerts); |
| 233 | |
| 234 | for(PxU32 j = 0; j < nbVerts; ++j) |
| 235 | { |
| 236 | vertices[j].x = binFile.LoadFloat(); |
| 237 | vertices[j].y = binFile.LoadFloat(); |
| 238 | vertices[j].z = binFile.LoadFloat(); |
| 239 | } |
| 240 | |
| 241 | SampleArray<PxU32>& indices = mTerrainIndices[i]; |
| 242 | indices.resize(nbFaces * 3); |
| 243 | |
| 244 | for(PxU32 j = 0; j < nbFaces * 3; ++j) |
| 245 | { |
| 246 | indices[j] = binFile.LoadDword(); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | //Hardcoded terrain.bin terrain. |
| 252 | void SampleLargeWorld::onInit() |