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


All times are UTC




Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Trouble creating a Irrlicht mesh from CubicSurfaceExtractor
PostPosted: Mon Oct 10, 2011 7:42 pm 

Joined: Sat Oct 08, 2011 7:03 pm
Posts: 5
I'm using CubicSurfaceExtractorWithNormals to extract the vertices and indices. Then converting to an irrlicht SMesh with the following code
Code:
SMesh* TerrainManager::generateCubicMesh(SimpleVolume<MaterialDensityPair44>& volData)
{
      SMesh* sMesh = new SMesh();
      SurfaceMesh<PositionMaterial> vMesh;

//get the vertices and indices
     PolyVox::CubicSurfaceExtractor<SimpleVolume, MaterialDensityPair44 > surfaceEx(&volData, volData.getEnclosingRegion(), &vMesh,true);
     surfaceEx.execute();

     const std::vector<uint32_t>& vecIndices = vMesh.getIndices();
          const std::vector<PositionMaterial>& vecVertices = vMesh.getVertices();

//put the indices into an array

     u16 *arrIndices = new u16[vecIndices.size()];
     for(int i =0; i < vMesh.getNoOfIndices();i++)
     {
      arrIndices[i] =(u16)vecIndices[i];
     }

//put the vertices into an array of 3dvectors

     irr::core::vector3df *arrVertices = new irr::core::vector3df[vecVertices.size() ];
     for(int i =0; i < vecVertices.size();i++)
     {
       
        arrVertices[i] = irr::core::vector3df((f32)vecVertices[i].getPosition().getX(),
        (f32)vecVertices[i].getPosition().getY(),
        (f32)vecVertices[i].getPosition().getZ());
      
     }

    //add the vertices and indices to a buffer and add them to the mesh
     SMeshBuffer *buf = new SMeshBuffer();
     buf->append(arrVertices,vecVertices.size(),arrIndices,vecIndices.size());
     sMesh->addMeshBuffer(buf);
     return sMesh;
}


The odd thing is that I create a spherical shape(using create sphere in volume code), the polygons are just completely messed up(jagged and definitely not cubic) and invisible from certain angles.

If noone feels like dissecting my code( I wouldn't), How would I properly load the indices and vertexes? I feel like I'm doing it correctly, but I'm obviously not.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Trouble creating a Irrlicht mesh from CubicSurfaceExtrac
PostPosted: Tue Oct 11, 2011 1:39 am 

Joined: Sat Sep 18, 2010 9:45 pm
Posts: 189
can you post a screenshot also? One thing I noticed is that you are using SurfaceExtractor and not SurfaceExtractorWithNormal as you indicated in your post. Other than that I don't see anything wrong.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Trouble creating a Irrlicht mesh from CubicSurfaceExtrac
PostPosted: Tue Oct 11, 2011 2:13 am 

Joined: Sat Oct 08, 2011 7:03 pm
Posts: 5
http://www.youtube.com/watch?v=-_QzyOaLF0c
that is supposed to be a sphere with a radius of 4. Sorry for the low quality btw.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Trouble creating a Irrlicht mesh from CubicSurfaceExtrac
PostPosted: Tue Oct 11, 2011 5:20 am 

Joined: Sun Sep 25, 2011 7:36 am
Posts: 13
I don't see anything shocking either, but Irrlicht's API is not protecting you from doing bad things so much, imho.

You could try doing this way, it works at least here:
http://thermite3d.org/phpBB3/viewtopic.php?f=14&t=185&start=10


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Trouble creating a Irrlicht mesh from CubicSurfaceExtrac
PostPosted: Tue Oct 11, 2011 5:52 pm 

Joined: Sat Sep 18, 2010 9:45 pm
Posts: 189
can you post the volume creation code? From that video alone it looks like you have the vertex and index buffer wrong, especially since the mesh disappears viewed from certain angles. Or you have incorrect world transforms so everything is bunched up together. I don't think it's the latter, though. Also make sure you mesh appending code is correct.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Trouble creating a Irrlicht mesh from CubicSurfaceExtrac
PostPosted: Tue Oct 11, 2011 7:39 pm 

Joined: Sat Oct 08, 2011 7:03 pm
Posts: 5
This is the code I'm using to generate the volume(same as in the example). Thanks Gnu I'll be sure to check out that link tonight.

Code:
void TerrainManager::createSphereInVolume(SimpleVolume<MaterialDensityPair44>& volData, float fRadius)
{
      //This vector hold the position of the center of the volume
        Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);

        //This three-level for loop iterates over every voxel in the volume
        for (int z = 0; z < volData.getWidth(); z++)
        {
                for (int y = 0; y < volData.getHeight(); y++)
                {
                        for (int x = 0; x < volData.getDepth(); x++)
                        {
                                //Store our current position as a vector...
                                Vector3DFloat v3dCurrentPos(x,y,z);
                                //And compute how far the current position is from the center of the volume
                                float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();

                                //If the current voxel is less than 'radius' units from the center then we make it solid.
                                if(fDistToCenter <= fRadius)
                                {
                                        //Our new density value
                                        uint8_t uDensity = MaterialDensityPair44::getMaxDensity();

                                        //Get the old voxel
                                        MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z);

                                        //Modify the density
                                        voxel.setDensity(uDensity);

                                        //Wrte the voxel value into the volume
                                        volData.setVoxelAt(x, y, z, voxel);
                                }
                        }
                }
        }
}


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Trouble creating a Irrlicht mesh from CubicSurfaceExtrac
PostPosted: Tue Oct 11, 2011 9:34 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
I don't know anything about Irrlicht but I notice you don't appear to define a vertex format anywhere. How does irrlicht know that each vertex has a position but no normal? Maybe it thinks that half the values are normals and therefore you only have half as many vertices as you think?

This could also explain why the indicies appear strange as beyzend observed? Note that Gnurfos's code references 'EVT_STANDARD' which I guess is a vertex type.

Also, i doubt if it the problem but watch out for casting the 32 bit indices to 16 bits.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Trouble creating a Irrlicht mesh from CubicSurfaceExtrac
PostPosted: Tue Oct 11, 2011 10:26 pm 

Joined: Sat Oct 08, 2011 7:03 pm
Posts: 5
Alright! I took the vertices and indices convert code gnu linked to and the mesh generated properly! I'm betting that the error was with the Vertex array like david said. I thought by vertex type they meant that you could pass vertices as different data types, I'll take the time to look at EVT_STANDARD tonight. The mesh still isn't drawn at certain angles, could this be because of a culling issue?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Trouble creating a Irrlicht mesh from CubicSurfaceExtrac
PostPosted: Wed Oct 12, 2011 2:59 am 

Joined: Sat Oct 08, 2011 7:03 pm
Posts: 5
Awesome guys It's working perfectly, thanks so much! It was a culling issue btw, if anyone is experiencing bizarre clipping with irrlicht turn off the culling for the node.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Trouble creating a Irrlicht mesh from CubicSurfaceExtrac
PostPosted: Wed Oct 12, 2011 4:48 am 

Joined: Sun Sep 25, 2011 7:36 am
Posts: 13
gamegezer wrote:
Awesome guys It's working perfectly, thanks so much! It was a culling issue btw, if anyone is experiencing bizarre clipping with irrlicht turn off the culling for the node.

This is not a solution, but a workaround that has drawbacks.
I had the same problem, and it was solved by calling recalculateBoundingBox() on the created mesh (doing it on the meshbuffer is not enough, I'm not sure it is even needed). You can display bounding boxes to confirm this is the problem (call setDebugDataVisible(irr::scene::EDS_BBOX) on the scene node).


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

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