Skip to content
Browse files

Added Partio support for exporting raw particle data to Houdini/Maya/…

…etc.
  • Loading branch information...
1 parent 36219f9 commit 28164120071390e4aab6e69f8eb24184594cc061 @betajippity committed
View
3 CMakeLists.txt
@@ -42,6 +42,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin"
endif()
find_library(OPENVDB "openvdb")
+find_library(PARTIO "partio")
#OpenVDB dynamic links these, so we need to as well
find_library(TBB "tbb")
@@ -49,7 +50,7 @@ find_library(HALF "half")
find_library(LIBZ "z")
set(VDBLIBS ${HALF} ${LIBZ} ${TBB})
-set(CORELIBS ${GLFW_LIBRARY} ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${OPENVDB} ${VDBLIBS})
+set(CORELIBS ${GLFW_LIBRARY} ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${OPENVDB} ${VDBLIBS} ${PARTIO})
#Set up OpenMP stuff
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
View
3 src/grid/levelset.cpp
@@ -58,7 +58,8 @@ levelset::levelset(vector<particle*>& particles, float maxdimension){
raster.setRmin(.01f);
particleList plist(particles, maxdimension);
- raster.rasterizeSpheres(plist);
+ // raster.rasterizeSpheres(plist);
+ raster.rasterizeTrails(plist);
raster.finalize();
}
View
2 src/grid/levelset.hpp
@@ -48,6 +48,7 @@ class particleList{ //used for VDB particle to level set construction
pos = openvdb::Vec3f(particles[n]->p.x*maxdimension, particles[n]->p.y*maxdimension,
particles[n]->p.z*maxdimension);
rad = particles[n]->density;
+ rad = .5f;
if(particles[n]->invalid){
rad = 0.0f;
}
@@ -57,6 +58,7 @@ class particleList{ //used for VDB particle to level set construction
pos = openvdb::Vec3f(particles[n]->p.x*maxdimension, particles[n]->p.y*maxdimension,
particles[n]->p.z*maxdimension);
rad = particles[n]->density;
+ rad = .5f;
vel = openvdb::Vec3f(particles[n]->u.x, particles[n]->u.y, particles[n]->u.z);
if(particles[n]->invalid){
rad = 0.0f;
View
76 src/scene/scene.cpp
@@ -10,6 +10,7 @@
#include <openvdb/tools/MeshToVolume.h>
#include <openvdb/tools/LevelSetSphere.h>
#include <openvdb/tools/Composite.h>
+#include <partio/Partio.h>
using namespace sceneCore;
@@ -27,47 +28,78 @@ scene::~scene(){
delete liquidLevelSet;
}
-void scene::setPaths(const string& imagePath, const string& meshPath, const string& vdbPath){
+void scene::setPaths(const string& imagePath, const string& meshPath, const string& vdbPath,
+ const string& partioPath){
this->imagePath = imagePath;
this->meshPath = meshPath;
this->vdbPath = vdbPath;
+ this->partioPath = partioPath;
}
-void scene::exportParticles(vector<fluidCore::particle*> particles, float maxd, int frame,
- bool VDB, bool OBJ){
- vector<fluidCore::particle*> sdfparticles;
+void scene::exportParticles(vector<fluidCore::particle*> particles, const float& maxd, const int& frame,
+ const bool& VDB, const bool& OBJ, const bool& PARTIO){
int particlesCount = particles.size();
+
+ vector<fluidCore::particle*> sdfparticles;
for(int i=0; i<particlesCount; i++){
if(particles[i]->type==FLUID){
sdfparticles.push_back(particles[i]);
}
}
-
+ int sdfparticlesCount = sdfparticles.size();
+
string frameString = utilityCore::padString(4, utilityCore::convertIntToString(frame));
- string vdbfilename = vdbPath;
- utilityCore::replaceString(vdbfilename, ".vdb", "."+frameString+".vdb");
- string objfilename = meshPath;
- utilityCore::replaceString(objfilename, ".obj", "."+frameString+".obj");
+ if(PARTIO){
+ string partiofilename = partioPath;
+ vector<string> tokens = utilityCore::tokenizeString(partiofilename, ".");
+ string ext = "." + tokens[tokens.size()-1];
+
+ utilityCore::replaceString(partiofilename, ext, "."+frameString+ext);
+
+ Partio::ParticlesDataMutable* partioData = Partio::create();
+ partioData->addParticles(sdfparticlesCount);
+ Partio::ParticleAttribute positionAttr = partioData->addAttribute("position", Partio::VECTOR, 3);
+ Partio::ParticleAttribute velocityAttr = partioData->addAttribute("v", Partio::VECTOR, 3);
+ Partio::ParticleAttribute idAttr = partioData->addAttribute("id", Partio::INT, 1);
+
+ for(int i=0; i<sdfparticlesCount; i++){
+ float* pos = partioData->dataWrite<float>(positionAttr, i);
+ pos[0] = sdfparticles[i]->p.x * maxd;
+ pos[1] = sdfparticles[i]->p.y * maxd;
+ pos[2] = sdfparticles[i]->p.z * maxd;
+ float* vel = partioData->dataWrite<float>(velocityAttr, i);
+ vel[0] = sdfparticles[i]->u.x;
+ vel[1] = sdfparticles[i]->u.y;
+ vel[2] = sdfparticles[i]->u.z;
+ int* id = partioData->dataWrite<int>(idAttr, i);
+ id[0] = i;
+ }
- fluidCore::levelset* fluidSDF = new fluidCore::levelset(sdfparticles, maxd);
+ Partio::write(partiofilename.c_str() ,*partioData);
+ partioData->release();
+ }
- // openvdb::FloatGrid::Ptr
- // gridA = fluidSDF->getVDBGrid()->deepCopy(),
- // gridB = permaSolidLevelSet->getVDBGrid()->deepCopy();
- // openvdb::tools::csgDifference(gridA->tree(), gridB->tree(), false);
+ if(VDB || OBJ){
+ string vdbfilename = vdbPath;
+ utilityCore::replaceString(vdbfilename, ".vdb", "."+frameString+".vdb");
- // fluidSDF->getVDBGrid() = gridA;
+ string objfilename = meshPath;
+ utilityCore::replaceString(objfilename, ".obj", "."+frameString+".obj");
- if(VDB){
- fluidSDF->writeVDBGridToFile(vdbfilename);
- }
+ fluidCore::levelset* fluidSDF = new fluidCore::levelset(sdfparticles, maxd);
+
+ if(VDB){
+ fluidSDF->writeVDBGridToFile(vdbfilename);
+ }
- if(OBJ){
- fluidSDF->writeObjToFile(objfilename);
+ if(OBJ){
+ fluidSDF->writeObjToFile(objfilename);
+ }
+ delete fluidSDF;
}
- delete fluidSDF;
+
}
void scene::addSolidObject(objCore::objContainer* object, int startFrame, int endFrame){
@@ -177,6 +209,8 @@ void scene::buildLevelSets(const int& frame){
liquidLevelSet->merge(*permaLiquidLevelSet);
}
}
+
+ // permaSolidLevelSet->writeVDBGridToFile("test.vdb");
}
// void scene::rebuildLiquidLevelSet(vector<fluidCore::particle*>& particles){
View
8 src/scene/scene.hpp
@@ -39,19 +39,21 @@ class scene {
fluidCore::levelset* getLiquidLevelSet();
void buildLevelSets(const int& frame);
- void setPaths(const string& imagePath, const string& meshPath, const string& vdbPath);
+ void setPaths(const string& imagePath, const string& meshPath, const string& vdbPath,
+ const string& partioPath);
vec2 getSolidFrameRange(const int& index);
vec2 getLiquidFrameRange(const int& index);
void projectPointsToSolidSurface(vector<vec3>& points);
- void exportParticles(vector<fluidCore::particle*> particles, float maxd, int frame, bool VDB,
- bool OBJ);
+ void exportParticles(vector<fluidCore::particle*> particles, const float& maxd, const int& frame,
+ const bool& VDB, const bool& OBJ, const bool& PARTIO);
string imagePath;
string meshPath;
string vdbPath;
+ string partioPath;
private:
View
5 src/scene/sceneloader.cpp
@@ -38,7 +38,7 @@ sceneloader::sceneloader(string filename){
loadSim(root["sim"]);
}
- s->setPaths(imagePath, meshPath, vdbPath);
+ s->setPaths(imagePath, meshPath, vdbPath, partioPath);
cout << "Loaded scene from " << filename << ".\n" << endl;
}
@@ -87,6 +87,9 @@ void sceneloader::loadSettings(const Json::Value& jsonsettings){
if(jsonsettings.isMember("vdb_output")){
vdbPath = jsonsettings["vdb_output"].asString();
}
+ if(jsonsettings.isMember("partio_output")){
+ partioPath = jsonsettings["partio_output"].asString();
+ }
}
void sceneloader::loadSim(const Json::Value& jsonsim){
View
1 src/scene/sceneloader.hpp
@@ -42,6 +42,7 @@ class sceneloader {
string imagePath;
string meshPath;
string vdbPath;
+ string partioPath;
};
}
View
6 src/sim/flip.cpp
@@ -96,7 +96,7 @@ void flipsim::init(){
}
}
-void flipsim::step(bool saveVDB, bool saveOBJ){
+void flipsim::step(bool saveVDB, bool saveOBJ, bool savePARTIO){
frame++;
cout << "Simulating Step: " << frame << "..." << endl;
@@ -173,8 +173,8 @@ void flipsim::step(bool saveVDB, bool saveOBJ){
}
}
- if(saveVDB || saveOBJ){
- scene->exportParticles(particles, maxd, frame, saveVDB, saveOBJ);
+ if(saveVDB || saveOBJ || savePARTIO){
+ scene->exportParticles(particles, maxd, frame, saveVDB, saveOBJ, savePARTIO);
}
}
View
2 src/sim/flip.hpp
@@ -28,7 +28,7 @@ class flipsim{
~flipsim();
void init();
- void step(bool saveVDB, bool saveOBJ);
+ void step(bool saveVDB, bool saveOBJ, bool savePARTIO);
vector<particle*>* getParticles();
vec3 getDimensions();
View
12 src/viewer/viewer.cpp
@@ -74,7 +74,7 @@ bool viewer::launch(){
while(1){
if(!pause){
- sim->step(dumpVDB, dumpOBJ);
+ sim->step(dumpVDB, dumpOBJ, dumpPARTIO);
particles = sim->getParticles();
if(dumpFramebuffer && dumpReady){
omp_set_lock(&framebufferWriteLock);
@@ -327,6 +327,16 @@ void viewer::updateInputs(){
cout << "\nOBJ Export OFF.\n" << endl;
}
}
+ }else if(glfwGetKey(window, GLFW_KEY_G) == GLFW_PRESS){
+ if(cam.currentKey!=GLFW_KEY_G){
+ dumpPARTIO = !dumpPARTIO;
+ cam.currentKey = GLFW_KEY_G;
+ if(dumpPARTIO){
+ cout << "\nPARTIO Export ON.\n" << endl;
+ }else{
+ cout << "\nPARTIO Export OFF.\n" << endl;
+ }
+ }
}else{
cam.currentKey = 0;
}
View
1 src/viewer/viewer.hpp
@@ -115,6 +115,7 @@ class viewer{
bool dumpVDB;
bool dumpOBJ;
+ bool dumpPARTIO;
};
}

0 comments on commit 2816412

Please sign in to comment.
Something went wrong with that request. Please try again.