Volumes Of Fun http://www.volumesoffun.com/phpBB3/ |
|
Strange mesh http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=582 |
Page 1 of 1 |
Author: | petersvp [ Wed Apr 16, 2014 11:18 pm ] | ||
Post subject: | Strange mesh | ||
Why Marching Cubes mesh have this bottom part? How can I remove it? (check the attachment) Or what am I doing wrong to get it?
|
Author: | David Williams [ Thu Apr 17, 2014 7:41 pm ] |
Post subject: | Re: Strange mesh |
It's a little hard to see in your image, but it looks like you have generated two surface (one above the other)? Polyvox will create surface wherever there is boundary between high and low density voxels. What does the code look like which fills the volume? |
Author: | petersvp [ Fri Apr 18, 2014 9:39 pm ] |
Post subject: | Re: Strange mesh [SOLVED] |
Hope this will help you: Code: HEADERS: //Voxel type struct SVT // Smooth Voxel Type { uint16_t density; // Density uint8_t material; // Material uint8_t light; // Light uint32_t color; // Color bool isSmooth; SVT(); SVT(uint8_t m, uint8_t d = 255); SVT &operator +(const SVT& other); SVT &operator -(const SVT& other); SVT &operator /(const int& other); SVT &operator +=(const SVT& other); SVT &operator -=(const SVT& other); SVT &operator /=(const int& other); }; class PGFMarchingCubesController { public: typedef uint8_t DensityType; typedef uint8_t MaterialType; PGFMarchingCubesController(void); DensityType convertToDensity(SVT voxel); MaterialType convertToMaterial(SVT voxel); DensityType getThreshold(void); void setThreshold(DensityType tThreshold); private: DensityType m_tThreshold; }; class PGFIsQuadNeeded { public: bool operator()(SVT back, SVT front, uint32_t& materialToUse); }; SOURCES: SVT::SVT(): density(0), material(0), light(0), isSmooth(true){} SVT& SVT::operator +(const SVT &other) { this->density += other.density; return *this; } SVT& SVT::operator -(const SVT &other) { this->density -= other.density; return *this; } SVT& SVT::operator /(const int &other) { this->density /= other; return *this; } /**/ SVT& SVT::operator +=(const SVT &other) { this->density += other.density; return *this; } SVT& SVT::operator -=(const SVT &other) { this->density -= other.density; return *this; } SVT& SVT::operator /=(const int &other) { this->density /= other; return *this; } ... PGFMarchingCubesController::PGFMarchingCubesController() :m_tThreshold(127) { } PGFMarchingCubesController::DensityType PGFMarchingCubesController::convertToDensity(SVT voxel) { return voxel.density; } PGFMarchingCubesController::MaterialType PGFMarchingCubesController::convertToMaterial(SVT voxel) { return voxel.material; } PGFMarchingCubesController::DensityType PGFMarchingCubesController::getThreshold() { return m_tThreshold; } void PGFMarchingCubesController::setThreshold(PGFMarchingCubesController::DensityType tThreshold) { m_tThreshold = tThreshold; } ..... The actual code: Actually a boolean cloud, setting densities either 0 or 255. ch->voxdata = new RawVolume<SVT>(Region(-1,-1,-1,ch->sx+1,ch->sy+1,ch->sz+1)); //Generate SOME data into them \paging test! chunk* c = ch; for(int xi=-1; xi<=ch->sx+1; ++xi) for(int yi=-1;yi<=ch->sy+1;++yi) { float pval = perlin.Get(float(xi+ch->x*ch->sx)/float(ch->sx), float(yi+ch->y*ch->sy)/float(ch->sy)); pval += 1.0; //0..2; pval /= 2.0; //0..1 pval *= ch->sz; //reach the z int zz = pval; //cout << zz << ", "; for(int zi=-1;zi<pval;++zi) { SVT vx; vx.density = 255; vx.material = 1; vx.color = Ogre::ColourValue(1,1,1,1).getAsRGBA(); vx.light = 255; ch->voxdata->setVoxelAt(xi,yi,zi,vx); } } .... LATER .... delete c->newmesh; c->newmesh = new SurfaceMesh<PositionMaterialNormal>(); //must DELETE it! //Smooth chunk RawVolume<SVT> tempVolume(Region(-1,-1,-1,c->sx+1,c->sy+1,c->sz+1)); LowPassFilter< RawVolume<SVT>, RawVolume<SVT>, SVT > lpf(c->voxdata, Region(-1,-1,-1,c->sx+1,c->sy+1,c->sz+1), &tempVolume, Region(-1,-1,-1,c->sx+1,c->sy+1,c->sz+1), 3); lpf.execute(); MarchingCubesSurfaceExtractor< RawVolume<SVT>, PGFMarchingCubesController > ext2(&tempVolume, Region(0,0,0,c->sx,c->sy,c->sz), c->newmesh); ext2.execute(); And that is... the full source code is uploaded here: https://sourceforge.net/p/kitten-platfo ... ree/trunk/ note that this repo is completely.... overused - 2 projects... |
Author: | petersvp [ Fri Apr 18, 2014 9:44 pm ] |
Post subject: | Re: Strange mesh |
Ops.... I found the mistake. Changing Code: class PGFMarchingCubesController { public: typedef uint8_t DensityType; typedef uint8_t MaterialType; to Code: class PGFMarchingCubesController { public: typedef uint16_t DensityType; typedef uint8_t MaterialType; FIXED THE PROBLEM! Anyway Thanks |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |