Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "BlastFracture.h"
- #include "Fracture.h"
- using namespace Nv::Blast;
- void loggingCallback(int type, const char* msg, const char* file, int line)
- {
- (void)type;
- std::cout << msg << " FILE:" << file << " Line: " << line << "\n";
- }
- static Nv::Blast::Mesh* pMesh = NULL;
- static FractureSettings settings;
- static Nv::Blast::FractureTool fTool;
- static std::vector<std::vector<Nv::Blast::Triangle> > chunkMeshes;
- std::vector<physx::PxVec3> pos;
- std::vector<physx::PxVec3> norm;
- std::vector<physx::PxVec2> tex;
- std::vector<int> indexs;
- extern "C" {
- DllExport void SetMesh(int vertexCount, void* sourceVertices, void* sourceNormals, void* sourceUVs,void* sourceIndices, int indicesCount)
- {
- pMesh = new Nv::Blast::Mesh((physx::PxVec3*)sourceVertices, (physx::PxVec3*)sourceNormals, (physx::PxVec2*)sourceUVs, vertexCount, (uint32_t*)sourceIndices, indicesCount);
- printf("SetMesh: isValid:%i\n", pMesh->isValid());
- printf("V:%i F:%i E:%i\n", pMesh->getVerticesCount(), pMesh->getFacetCount(), pMesh->getEdgesCount());
- settings.cellsCount = 5;
- settings.clusterCount = 5;
- settings.clusterRadius = 1;
- settings.offsetVariation = 0;
- settings.slicingX = 0;
- settings.slicingY = 0;
- settings.slicingZ = 0;
- }
- DllExport void Fracture(int count)
- {
- fTool.setSourceMesh(pMesh);
- SimpleRandomGenerator rnd;
- rnd.seed((int32_t)time(nullptr)); // Keep the same seed to have reproducible results.
- std::cout << "Fracturing...\n" << std::endl;
- VoronoiSitesGenerator stGenerator(pMesh, &rnd);
- stGenerator.uniformlyGenerateSitesInMesh(count);
- fTool.voronoiFracturing(0, stGenerator.getVoronoiSites(), false);
- std::cout << "Creating geometry" << std::endl;
- fTool.finalizeFracturing();
- chunkMeshes.resize(fTool.getChunkList().size());
- //isSupport.resize(fTool.getChunkList().size());
- for (uint32_t i = 0; i < fTool.getChunkList().size(); ++i)
- {
- fTool.getBaseMesh(i, chunkMeshes[i]);
- //isSupport[i] = fTool.getChunkList()[i].isLeaf;
- }
- }
- DllExport int Chunks()
- {
- //return chunkMeshes.size();
- return fTool.getChunkList().size();
- }
- DllExport int GetChunkCount(int idx)
- {
- if (idx >= chunkMeshes.size()) return NULL;
- return chunkMeshes[idx].size();
- }
- DllExport void* GetChunkVertex(int idx)
- {
- if (idx >= chunkMeshes.size()) return NULL;
- pos.clear();
- std::vector<Triangle>& chunk = chunkMeshes[idx];
- for (uint32_t i = 0; i < chunk.size(); ++i)
- {
- pos.push_back(chunk[i].a.p);
- pos.push_back(chunk[i].b.p);
- pos.push_back(chunk[i].c.p);
- }
- return &pos[0];
- }
- DllExport void* GetChunkIndex(int idx)
- {
- if (idx >= chunkMeshes.size()) return NULL;
- indexs.clear();
- int index = 0;
- std::vector<Triangle>& chunk = chunkMeshes[idx];
- for (uint32_t i = 0; i < chunk.size(); ++i)
- {
- indexs.push_back(index++);
- indexs.push_back(index++);
- indexs.push_back(index++);
- }
- return &indexs[0];
- }
- DllExport void* GetChunkNormal(int idx)
- {
- if (idx >= chunkMeshes.size()) return NULL;
- norm.clear();
- int index = 0;
- std::vector<Triangle>& chunk = chunkMeshes[idx];
- for (uint32_t i = 0; i < chunk.size(); ++i)
- {
- norm.push_back(chunk[i].a.n);
- norm.push_back(chunk[i].b.n);
- norm.push_back(chunk[i].c.n);
- }
- return &norm[0];
- }
- DllExport void* GetChunkUV(int idx)
- {
- if (idx >= chunkMeshes.size()) return NULL;
- tex.clear();
- int index = 0;
- std::vector<Triangle>& chunk = chunkMeshes[idx];
- for (uint32_t i = 0; i < chunk.size(); ++i)
- {
- tex.push_back(chunk[i].a.uv[0]);
- tex.push_back(chunk[i].b.uv[0]);
- tex.push_back(chunk[i].c.uv[0]);
- }
- return &tex[0];
- }
- DllExport int GetChunk(int idx,void* V,void* N,void* U,void* I)
- {
- printf("Triangles: %i\n", chunkMeshes[idx].size());
- pos.clear();
- norm.clear();
- tex.clear();
- indexs.clear();
- int index = 0;
- std::vector<Triangle>& chunk = chunkMeshes[idx];
- for (uint32_t i = 0; i < chunk.size(); ++i)
- {
- pos.push_back(chunk[i].a.p);
- pos.push_back(chunk[i].b.p);
- pos.push_back(chunk[i].c.p);
- norm.push_back(chunk[i].a.n);
- norm.push_back(chunk[i].b.n);
- norm.push_back(chunk[i].c.n);
- tex.push_back(chunk[i].a.uv[0]);
- tex.push_back(chunk[i].b.uv[0]);
- tex.push_back(chunk[i].c.uv[0]);
- indexs.push_back(index++);
- indexs.push_back(index++);
- indexs.push_back(index++);
- }
- V = &pos[0];
- N = &norm[0];
- U = &tex[0];
- I = &indexs[0];
- return chunk.size();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement