It is currently Wed Aug 12, 2020 2:45 pm


All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: why getIndices() always zero? I am using SurfaceExtractor
PostPosted: Thu Jun 16, 2011 7:02 am 

Joined: Fri Sep 10, 2010 5:38 am
Posts: 30
I am using SurfaceExtractor to get SurfaceMesh, and Using Ogre manualObject to get ogreMesh. I reference the code linked below:
http://www.thermite3d.org/dokuwiki/doku.php?id=rendering_a_volume_in_ogre
The problem is here:
Code:
unsigned int uLodLevel = 0;
int beginIndex = mesh->m_vecLodRecords[uLodLevel].beginIndex;
int endIndex = mesh->m_vecLodRecords[uLodLevel].endIndex;
for (int index = beginIndex; index < endIndex; ++index)


In my program, both beginIndex and endIndex are equel to zero. So I didn't get any vertex or normals in my ogre manual mesh. when I use ogre function convertToMesh, I get exception telling that no data defined.

How to solve this problem? Or can someone tell me what the quoted codes mean. In the Polyvox Manual, I get little information on this.


Last edited by pumpkin_zch2u on Thu Jun 23, 2011 6:16 am, edited 1 time in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: why m_vecLodRecords[uLodLevel].beginIndex and endIndex z
PostPosted: Thu Jun 16, 2011 7:29 am 

Joined: Sun Jan 23, 2011 6:06 am
Posts: 92
I didn't think lod was even working at the moment....?

I get the indices/vertices like this:

const std::vector<uint32_t>& indexVector = polyVoxMesh->getIndices();
const std::vector<PolyVox::PositionMaterial>& vertexVector = polyVoxMesh->getVertices();

Then when iterating through the vertices, use getX() etc to get the actual coordinates.

To create the Ogre mesh, iterate through the vertices first and set position, normal, color for each. Then afterward iterate through the indices.

That works for me, anyway.

I think LOD was on the list of things to eventually get fixed in PolyVox...


Top
Offline Profile  
Reply with quote  
 Post subject: Re: why m_vecLodRecords[uLodLevel].beginIndex and endIndex z
PostPosted: Thu Jun 16, 2011 8:59 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
The LOD record should have a single entry at the moment - if it doesn't then I suspect nothing was extracted. Can you look at the array of indices and vertices in the SurfaceMesh class to see how many are present?

Also, you said previsouly you were using the CubicSurfaceExtractor? Was this actually the CubicSurfaceExtractorWithNormals? What is the type of your voxels (Material8, MaterialDensityPair44, etc?)

If you determine that there are no vertices or indices in your mesh, maybe you can provide a simple example of the code you are using to build the volume and perform the extraction?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: why m_vecLodRecords[uLodLevel].beginIndex and endIndex z
PostPosted: Mon Jun 20, 2011 4:11 am 

Joined: Fri Sep 10, 2010 5:38 am
Posts: 30
In last version, I am Using CubicSurfaceExtractor without Noraml and MaterialDensityPair44. I rewrite my Ogre manualObject generating function with
Quote:
const std::vector<uint32_t>& indexVector = polyVoxMesh->getIndices();
const std::vector<PolyVox::PositionMaterial>& vertexVector = polyVoxMesh->getVertices();

But All I get is messed up mesh.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: why m_vecLodRecords[uLodLevel].beginIndex and endIndex z
PostPosted: Mon Jun 20, 2011 8:00 am 

Joined: Sun Jan 23, 2011 6:06 am
Posts: 92
Can you post your code? Hard to say more otherwise


Top
Offline Profile  
Reply with quote  
 Post subject: Re: why m_vecLodRecords[uLodLevel].beginIndex and endIndex z
PostPosted: Mon Jun 20, 2011 8:14 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Can you tell whether it is a problem with the data or with the rendering? If you look at indexVector and vertexVector in the debugger do you see valid data? Are there a large number of vertices, and do they all have positions within the region you tried to extract?

Maybe you can post here the first few vertices and indices if you are not sure?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: why m_vecLodRecords[uLodLevel].beginIndex and endIndex z
PostPosted: Thu Jun 23, 2011 6:11 am 

Joined: Fri Sep 10, 2010 5:38 am
Posts: 30
here is my code:
Code:
Ogre::ManualObject* VolumeStone::updateConvertPolyVoxMesh(Ogre::String materialName)
{

   oMO->begin("materialName", Ogre::RenderOperation::OT_TRIANGLE_LIST);
   {
      // prepare the buffers
      
      
      const std::vector<uint32_t>& vecIndices = mesh->getIndices();
      const std::vector<PolyVox::PositionMaterialNormal>& vecVertices = mesh->getVertices();
      


      oMO->estimateVertexCount(vecVertices.size());
      oMO->estimateIndexCount(vecIndices.size());


      for(uint32_t i = 0; i < vecVertices.size(); i++)
      {
         const PolyVox::PositionMaterialNormal& vertex = vecVertices.at(i);
      
         PolyVox::Vector3DFloat vertex_pos = vertex.getPosition() ;
         oMO->position(vertex_pos.getX(), vertex_pos.getY(), vertex_pos.getZ());
         oMO->normal(vertex.getNormal().getX(), vertex.getNormal().getY(), vertex.getNormal().getZ());
         
      
      }
      for (uint32_t i=0;i<vecIndices.size();i++)
      {
         oMO->index((Ogre::uint32)(vecIndices[i])); 
      }
   }
   oMO->end();

   return oMO;
}

The picture below:(should be a cube!)
Attachment:
shot.Png
shot.Png [ 231.55 KiB | Viewed 4330 times ]


Last edited by pumpkin_zch2u on Thu Jun 23, 2011 6:26 am, edited 1 time in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: why m_vecLodRecords[uLodLevel].beginIndex and endIndex z
PostPosted: Thu Jun 23, 2011 6:14 am 

Joined: Fri Sep 10, 2010 5:38 am
Posts: 30
I am Using SurfaceExtractor to have polyvox mesh,here is the code:
Code:
surfaceExtractor= new SurfaceExtractor<SimpleVolume, MaterialDensityPair44>(volData, volData->getEnclosingRegion(), mesh);
   surfaceExtractor->execute();


while I debuggine, it seems mesh->getIndices() function always to be zero.
Attachment:
error.Png
error.Png [ 97.91 KiB | Viewed 4329 times ]


why? I totally confused. Once before I use CubicSurfaceExtrator, no such problem!


Top
Offline Profile  
Reply with quote  
 Post subject: Re: why getIndices() always zero? I am using SurfaceExtracto
PostPosted: Thu Jun 23, 2011 9:09 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
I'd be more interested in the code where you generate the volume. Are you calling both setDensity() and setMaterial()? I guess you were using a Material8 before and were only calling setMaterial? Now that you are using MaterialDensityPair you have to call setDensity() as well.

If that's not the problem then post the code for where you create the volume and write the data into it.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: why getIndices() always zero? I am using SurfaceExtracto
PostPosted: Fri Jun 24, 2011 12:15 am 

Joined: Fri Sep 10, 2010 5:38 am
Posts: 30
David Williams wrote:
I'd be more interested in the code where you generate the volume. Are you calling both setDensity() and setMaterial()? I guess you were using a Material8 before and were only calling setMaterial? Now that you are using MaterialDensityPair you have to call setDensity() as well.

If that's not the problem then post the code for where you create the volume and write the data into it.

It seems not the case you mentioned above. the code for generation the volume and updating it is below:
Code:
VolumeStone::VolumeStone(Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, uint8_t uValue)//:volData(0)
{
   
   volData = new SimpleVolume<MaterialDensityPair44>(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 31, 31)));   
   createCubeVolume(lowerCorner, upperCorner, uValue);   
   mesh=new SurfaceMesh<PositionMaterialNormal>();
   oMO=NULL;
   surfaceExtractor=NULL;
}

VolumeStone::~VolumeStone(void)
{
}

void VolumeStone::createCubeVolume(Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, uint8_t uValue)
{
   
   //This three-level for loop iterates over every voxel between the specified corners
   for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++)
   {
      for (int y = lowerCorner.getY(); y <= upperCorner.getY(); y++)
      {
         for (int x = lowerCorner.getX() ; x <= upperCorner.getX(); x++)
         {
            volData->setVoxelAt(x,y,z, MaterialDensityPair44(uValue,MaterialDensityPair44::getMaxDensity()));            
         }
      }
   }   
}

SimpleVolume<MaterialDensityPair44>* VolumeStone::updateVolData(float fRadius, uint8_t uValue,Ogre::Vector3 position)
{
   //get the center of your knife!!
   Vector3DFloat v3dVolCenter(position.x,position.y,position.z);
      //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++)
         {
            if(volData->getVoxelAt(x,y,z).getDensity()!=MaterialDensityPair44::getMinDensity())
            {
               //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 more than 'radius' units from the center
            //then we make it solid, otherwise we make it empty space.
            if(fDistToCenter >= fRadius)
            {
               volData->setVoxelAt(x,y,z, MaterialDensityPair44(uValue,MaterialDensityPair44::getMaxDensity()));
            }
            else
               volData->setVoxelAt(x,y,z, MaterialDensityPair44(uValue,MaterialDensityPair44::getMinDensity()));
            }
         }
      }
   }
   //smoothRegion<SimpleVolume, MaterialDensityPair44>(*volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 31, 31)));   
   //smoothRegion<SimpleVolume, MaterialDensityPair44>(*volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 31, 31)));   
   //smoothRegion<SimpleVolume, MaterialDensityPair44>(*volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 31, 31)));   
   return volData;
   
}
Ogre::ManualObject*
   VolumeStone::updatePolyvox(Ogre::String materialName)
{
   //Extract the surface
   surfaceExtractor= new SurfaceExtractor<SimpleVolume,MaterialDensityPair44>(volData,  volData->getEnclosingRegion(), mesh);
   surfaceExtractor->execute();
   return updateConvertPolyVoxMesh(materialName);
}

Ogre::ManualObject*
    VolumeStone::initPolyvox(Ogre::String materialName,Ogre::SceneManager *sm)
{
   surfaceExtractor= new SurfaceExtractor<SimpleVolume, MaterialDensityPair44>(volData, volData->getEnclosingRegion(), mesh);
   surfaceExtractor->execute();   
   oMO = sm->createManualObject();   // create manual object
   oMO->setCastShadows(true);
   oMO->setDynamic(true);
   return updateConvertPolyVoxMesh(materialName);
}

And in my header file, I define variables as:
Code:
   Ogre::ManualObject* oMO;
   SimpleVolume<MaterialDensityPair44> *volData;
   SurfaceMesh<PositionMaterialNormal> *mesh;
   SurfaceExtractor<SimpleVolume, MaterialDensityPair44> *surfaceExtractor;


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 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