It is currently Sat Aug 22, 2020 4:27 am


All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Strange mesh
PostPosted: Wed Apr 16, 2014 11:18 pm 

Joined: Tue Apr 08, 2014 5:10 pm
Posts: 124
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?


Attachments:
wt.jpg
wt.jpg [ 77.62 KiB | Viewed 3103 times ]
Top
Offline Profile  
Reply with quote  
 Post subject: Re: Strange mesh
PostPosted: Thu Apr 17, 2014 7:41 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Strange mesh [SOLVED]
PostPosted: Fri Apr 18, 2014 9:39 pm 

Joined: Tue Apr 08, 2014 5:10 pm
Posts: 124
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...


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Strange mesh
PostPosted: Fri Apr 18, 2014 9:44 pm 

Joined: Tue Apr 08, 2014 5:10 pm
Posts: 124
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


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net