MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/PhysX / createChunk

Method createChunk

physx/samples/samplelargeworld/ChunkLoader.cpp:341–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339}
340
341void SampleLargeWorld::createChunk(CoordType coordX, CoordType coordY, PxCollection& outCollection)
342{
343 CoordType dim = binData.mDim;
344
345 SampleArray<SampleArray<PxVec3> >& terrainVertices = binData.mTerrainVertices;
346
347 SampleArray<SampleArray<PxU32> >& terrainIndices = binData.mTerrainIndices;
348
349 SampleArray<PxVec3> tmpV;
350 SampleArray<PxU32> tmpI;
351
352 SampleArray<PxVec3>* vertices;
353 SampleArray<PxU32>* indices;
354 PxVec3 xAxis( (coordX / dim ) * CHUNK_WIDTH * dim - 0.5f * CHUNK_WIDTH, 0.0f, 0.0f );
355 PxVec3 zAxis( 0.0f, 0.0f, ( coordY / dim ) * CHUNK_WIDTH * dim - 0.5f * CHUNK_WIDTH );
356 CoordType x = coordX %( dim << 1 ), z = coordY % ( dim <<1 );
357 PxVec3 xRevert(1.0f), zRevert(1.0f);
358
359 bool needRevertMesh = false;
360 bool useRawDirectly = true;
361
362 //The terrain template is 16*16, if chunk is out of the range, use mirror to create new one
363 if(coordX >= dim || coordY >= dim)
364 useRawDirectly = false;
365
366 if( useRawDirectly )
367 {
368 vertices = &terrainVertices[coordY * dim + coordX];
369 indices = &terrainIndices[coordY * dim + coordX];
370 }
371 else //Just use mirror to create new terrain, so terrain can be expand to infinite size
372 {
373 if( x >= dim )
374 {
375 x = x % dim;
376 xRevert.x = -1.0f;
377 needRevertMesh = !needRevertMesh;
378 x = dim - x - 1;
379 }
380
381 if( z >= dim )
382 {
383 z = z % dim;
384 zRevert.z = -1.0f;
385 needRevertMesh = !needRevertMesh;
386 z = dim - z - 1;
387 }
388
389 SampleArray<PxVec3>& templateV = terrainVertices[z*dim + x];
390
391 for( PxU32 v = 0; v < templateV.size(); v++)
392 {
393 PxVec3 vert = templateV[v];
394 if(xRevert.x < 0.0f)
395 {
396 vert.x = CHUNK_WIDTH * dim - 0.5f * CHUNK_WIDTH - templateV[v].x + xAxis.x;
397 }
398 else

Callers 1

loadChunkMethod · 0.80

Calls 15

flattenChunkFunction · 0.85
PxCreateStaticFunction · 0.85
getShapeFunction · 0.85
fattenFastMethod · 0.80
PxTransformClass · 0.50
sizeMethod · 0.45
pushBackMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
includeMethod · 0.45
getCenterMethod · 0.45
getExtentsMethod · 0.45

Tested by

no test coverage detected