It is currently Sat Aug 22, 2020 1:34 pm


All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Ogre mesh to PolyVox
PostPosted: Fri Aug 31, 2012 10:05 pm 

Joined: Fri Aug 31, 2012 9:42 pm
Posts: 9
Hello @ all
at first i want to thank you guys for this cool lib.

I have made it trough the tutorial(I Havn't written it) on how to render a polvox mesh with a ogre::manualobject.
I tryed out the tutorial funktion to draw a sphere and everything worked.
But then i tryed to Convert the OgreHead.mesh to a polyvox volume...

my question is , is it posible to get the vertex data of an ogre mesh and apply it to
the polyvox volume?

Sorry for my bad english i come from germany

thx in advanced


Last edited by Crash(Overwrite()) on Wed Sep 12, 2012 12:27 pm, edited 1 time in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: Ogre mesh to PolyVox
PostPosted: Sat Sep 01, 2012 7:52 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Hi, glad you like the library :-) Unfortunatly there is no functionality in PolyVox for converting a mesh into a volume. You could implement it yourself although the process isn't that easy in real time. You should start by Googling for 'Voxelization' and I think that should throw up some relevent links.

If you don't need it in real time but instead just want a way of initially building your volumes then there are offline conversion tools available. They don't directly work with PolyVox but could be adapted. For example, search for 'bin2vox' or 'poly2vox'.

If you want to implement it yourself though Ogre then I expect you can access the Ogre vertex data, but I don't know how this is done. With access to the vertices you can start by simply setting the voxels which contain those vertices to solid. Of course, you'll have gaps between the voxels (unless your mesh is very dense) and filling these in is one of the tricky problems in voxelization...


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Ogre mesh to PolyVox
PostPosted: Sat Sep 01, 2012 9:53 am 

Joined: Fri Aug 31, 2012 9:42 pm
Posts: 9
i alredy tryed to do that tonight , the proplem is when i try to go through the voxel grid and set the voxels i get an assertion error while the app runs....

Code:
Vector3 *vpos;
int ccc = getPosArraySize(ent);
vpos = new Vector3[ccc];
int count = 0;
getPositionArray(ent,vpos,count);


 for (int z = 0; z < volData.getWidth(); z++)
        {
                for (int y = 0; y < volData.getHeight(); y++)
                {
                        for (int x = 0; x < volData.getDepth(); x++)
                        {
                     for (int i = 0; i < ent->getMesh()->getSubMesh(0)->vertexData->vertexCount ; i++)
                             {
                         Vector3DFloat vol_pos;
                         vol_pos.setX(vpos[i].x);
                         vol_pos.setY(vpos[i].y);
                         vol_pos.setZ(vpos[i].z);

                         MaterialDensityPair44 voxel = volData.getVoxelAt(vol_pos.getX(),vol_pos.getY(),vol_pos.getZ());
                                 uint8_t uDensity = MaterialDensityPair44::getMaxDensity();
                                 voxel.setDensity(uDensity);
                          volData.setVoxelAt(vol_pos.getX(),vol_pos.getY(),vol_pos.getZ(),voxel);
                        
                             }
                  }
            }
        }

i don't realy know how to set the voxels in the right way and how to ensure that the dimensions are valid...

I think doing the conversion in real-time would be to slow therefore i would like to write my own converter ^^

but using this converter tools wouldn't siut my needs because i have to convert .blend or a .mesh
file and converting from blender to a 3ds format screws up the mesh ^^

maybe you can help pointing out whats wrong


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Ogre mesh to PolyVox
PostPosted: Sun Sep 02, 2012 7:37 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
You don't need to iterate over each voxel like that, you can just iterate over eaach vertex and set the voxel at the corresponding position. Untested code based on yours:

Code:
for (int i = 0; i < ent->getMesh()->getSubMesh(0)->vertexData->vertexCount ; i++)
{
   Vector3DFloat vol_pos;
   vol_pos.setX(vpos[i].x);
   vol_pos.setY(vpos[i].y);
   vol_pos.setZ(vpos[i].z);

   if(volData.getEnclosingRegion().containsPoint(vol_pos)) //Avoid a writing outside the volume
   {
      MaterialDensityPair44 voxel = volData.getVoxelAt(vol_pos.getX(),vol_pos.getY(),vol_pos.getZ());
      uint8_t uDensity = MaterialDensityPair44::getMaxDensity();
      voxel.setDensity(uDensity);
      volData.setVoxelAt(vol_pos.getX(),vol_pos.getY(),vol_pos.getZ(),voxel);
   }
}


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Ogre mesh to PolyVox
PostPosted: Sun Sep 02, 2012 7:56 am 

Joined: Fri Aug 31, 2012 9:42 pm
Posts: 9
OK thank you for the tip will try that Today...^^


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Ogre mesh to PolyVox
PostPosted: Sun Sep 02, 2012 9:03 am 

Joined: Fri Aug 31, 2012 9:42 pm
Posts: 9
The code Modified by you worked very well ^^ thx for that.
but now i have another little problem, the mesh isn't complete,
the funktion for getting vertex positions into an array is:

Code:
void getPositionArray(Ogre::Entity* tmp_mesh,Vector3* pos)
{
 
   
   SubMesh* pSubMesh = tmp_mesh->getMesh()->getSubMesh(0) ;
  // int count = pSubMesh->vertexData->vertexCount ;
   
   
   const Ogre::VertexElement* posElem = pSubMesh->vertexData->vertexDeclaration->findElementBySemantic( Ogre::VES_POSITION );
   
   
   Ogre::HardwareVertexBufferSharedPtr VertexBufPOS = pSubMesh->vertexData->vertexBufferBinding->getBuffer( posElem->getSource() );

   unsigned char*  VertexPtrPOS = static_cast<unsigned char*>( VertexBufPOS->lock( Ogre::HardwareBuffer::LockOptions::HBL_NORMAL ) );

   int VertSizePOS=VertexBufPOS->getVertexSize() ;

   float * pElementPOS=NULL ;

   for (int i = 0; i < tmp_mesh->getMesh()->getSubMesh(0)->vertexData->vertexCount; i++)
   {
   posElem->baseVertexPointerToElement( VertexPtrPOS, &pElementPOS );
   
   pos[i].x = pElementPOS[0];
   pos[i].y = pElementPOS[1];
   pos[i].z = pElementPOS[2];
     


   VertexPtrPOS+=VertSizePOS;
   }
 
   
   VertexBufPOS->unlock();
   
}

->This Funktion should fill pos with the Vertex-Position ([0] == first vertex and so on)
but thats the mesh that gets generated by polyvox:

http://imageshack.us/photo/my-images/191/incompmesh.jpg

i'm a bit confused right now????


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Ogre mesh to PolyVox
PostPosted: Sun Sep 02, 2012 10:39 am 

Joined: Fri Aug 31, 2012 9:42 pm
Posts: 9
I found out what the source of that error is.
An valid PolyVox Volume just Contains Positive Values,
That meens every negative value passed would lead to an non existing point
and that means it doesn't get applied or am i wrong ?

Here are The Vertex Values

Code:
12:31:50: RS::Vertex_Data: 0 X: 5.61572Y: 15.2486Z: 5.66475
12:31:50: RS::Vertex_Number_drawn: 0 X: 5.61572Y: 15.2486Z: 5.66475
12:31:50: RS::Vertex_Data: 1 X: 6.1485Y: 16.1399Z: 4.58445
12:31:50: RS::Vertex_Number_drawn: 1 X: 6.1485Y: 16.1399Z: 4.58445
12:31:50: RS::Vertex_Data: 2 X: 4.08621Y: 14.7806Z: 6.42355
12:31:50: RS::Vertex_Number_drawn: 2 X: 4.08621Y: 14.7806Z: 6.42355
12:31:50: RS::Vertex_Data: 3 X: 9.99759Y: 16.3372Z: 1.38245
12:31:50: RS::Vertex_Number_drawn: 3 X: 9.99759Y: 16.3372Z: 1.38245
12:31:50: RS::Vertex_Data: 4 X: 11.0235Y: 16.7644Z: -0.382347
12:31:50: RS::Vertex_Data: 5 X: 9.53412Y: 16.7757Z: 1.01385
12:31:50: RS::Vertex_Number_drawn: 5 X: 9.53412Y: 16.7757Z: 1.01385
12:31:50: RS::Vertex_Data: 6 X: 6.64199Y: 15.3338Z: 5.26825
12:31:50: RS::Vertex_Number_drawn: 6 X: 6.64199Y: 15.3338Z: 5.26825
12:31:50: RS::Vertex_Data: 7 X: 8.04471Y: 16.7872Z: 2.40995
12:31:50: RS::Vertex_Number_drawn: 7 X: 8.04471Y: 16.7872Z: 2.40995
12:31:50: RS::Vertex_Data: 8 X: 9.20213Y: 16.0201Z: 2.73255
12:31:50: RS::Vertex_Number_drawn: 8 X: 9.20213Y: 16.0201Z: 2.73255
12:31:50: RS::Vertex_Data: 9 X: 9.61759Y: 16.2108Z: 2.08195
12:31:50: RS::Vertex_Number_drawn: 9 X: 9.61759Y: 16.2108Z: 2.08195
12:31:50: RS::Vertex_Data: 10 X: 10.8396Y: 15.7626Z: 0.0694523
12:31:50: RS::Vertex_Number_drawn: 10 X: 10.8396Y: 15.7626Z: 0.0694523
12:31:50: RS::Vertex_Data: 11 X: 10.9023Y: 16.506Z: -0.424549
12:31:50: RS::Vertex_Data: 12 X: 10.737Y: 15.9536Z: 0.48085
12:31:50: RS::Vertex_Number_drawn: 12 X: 10.737Y: 15.9536Z: 0.48085
12:31:50: RS::Vertex_Data: 13 X: 5.16272Y: 14.7657Z: 6.00655
12:31:50: RS::Vertex_Number_drawn: 13 X: 5.16272Y: 14.7657Z: 6.00655
12:31:50: RS::Vertex_Data: 14 X: -4.08621Y: 14.7806Z: 6.42355
12:31:50: RS::Vertex_Data: 15 X: -6.1485Y: 16.1399Z: 4.58445
12:31:50: RS::Vertex_Data: 16 X: -5.61572Y: 15.2486Z: 5.66475
12:31:50: RS::Vertex_Data: 17 X: -9.53412Y: 16.7757Z: 1.01385
12:31:50: RS::Vertex_Data: 18 X: -11.0235Y: 16.7644Z: -0.382347
12:31:50: RS::Vertex_Data: 19 X: -9.99759Y: 16.3372Z: 1.38245
12:31:50: RS::Vertex_Data: 20 X: -4.60796Y: 14.4711Z: 6.32125
12:31:50: RS::Vertex_Data: 21 X: -6.79243Y: 14.472Z: 5.44375
12:31:50: RS::Vertex_Data: 22 X: -6.69781Y: 13.4952Z: 5.50875
12:31:50: RS::Vertex_Data: 23 X: -5.16272Y: 14.7657Z: 6.00655
12:31:50: RS::Vertex_Data: 24 X: -6.64199Y: 15.3338Z: 5.26825
12:31:50: RS::Vertex_Data: 25 X: -9.61759Y: 16.2108Z: 2.08195
12:31:50: RS::Vertex_Data: 26 X: -9.20213Y: 16.0201Z: 2.73255
12:31:50: RS::Vertex_Data: 27 X: -8.04471Y: 16.7872Z: 2.40995
12:31:50: RS::Vertex_Data: 28 X: -10.737Y: 15.9536Z: 0.48085
12:31:50: RS::Vertex_Data: 29 X: -10.9023Y: 16.506Z: -0.424549
12:31:50: RS::Vertex_Data: 30 X: -10.8396Y: 15.7626Z: 0.0694523
12:31:50: RS::Vertex_Data: 31 X: -3.89298Y: 14.9007Z: 6.73075
12:31:50: RS::Vertex_Data: 32 X: -7.35424Y: 15.3284Z: 4.76485
12:31:50: RS::Vertex_Data: 33 X: 3.89298Y: 14.9007Z: 6.73075
12:31:50: RS::Vertex_Number_drawn: 33 X: 3.89298Y: 14.9007Z: 6.73075
12:31:50: RS::Vertex_Data: 34 X: 7.35424Y: 15.3284Z: 4.76485
12:31:50: RS::Vertex_Number_drawn: 34 X: 7.35424Y: 15.3284Z: 4.76485
12:31:50: RS::Vertex_Data: 35 X: 4.60796Y: 14.4711Z: 6.32125
12:31:50: RS::Vertex_Number_drawn: 35 X: 4.60796Y: 14.4711Z: 6.32125
12:31:50: RS::Vertex_Data: 36 X: 6.79243Y: 14.472Z: 5.44375
12:31:50: RS::Vertex_Number_drawn: 36 X: 6.79243Y: 14.472Z: 5.44375
12:31:50: RS::Vertex_Data: 37 X: 8.05394Y: 14.3771Z: 4.71945
12:31:50: RS::Vertex_Number_drawn: 37 X: 8.05394Y: 14.3771Z: 4.71945
12:31:50: RS::Vertex_Data: 38 X: 9.7956Y: 15.0682Z: 2.60465
12:31:50: RS::Vertex_Number_drawn: 38 X: 9.7956Y: 15.0682Z: 2.60465
12:31:50: RS::Vertex_Data: 39 X: 10.402Y: 15.4253Z: 1.51755
12:31:50: RS::Vertex_Number_drawn: 39 X: 10.402Y: 15.4253Z: 1.51755
12:31:50: RS::Vertex_Data: 40 X: 6.69781Y: 13.4952Z: 5.50875
12:31:50: RS::Vertex_Number_drawn: 40 X: 6.69781Y: 13.4952Z: 5.50875
12:31:50: RS::Vertex_Data: 41 X: 10.6711Y: 14.6185Z: 0.875952
12:31:50: RS::Vertex_Number_drawn: 41 X: 10.6711Y: 14.6185Z: 0.875952
12:31:50: RS::Vertex_Data: 42 X: 10.1022Y: 13.7878Z: 2.15505
12:31:50: RS::Vertex_Number_drawn: 42 X: 10.1022Y: 13.7878Z: 2.15505
12:31:50: RS::Vertex_Data: 43 X: 9.26515Y: 13.4314Z: 3.32625
12:31:50: RS::Vertex_Number_drawn: 43 X: 9.26515Y: 13.4314Z: 3.32625
12:31:50: RS::Vertex_Data: 44 X: 7.92624Y: 13.2468Z: 4.72985
12:31:50: RS::Vertex_Number_drawn: 44 X: 7.92624Y: 13.2468Z: 4.72985
12:31:50: RS::Vertex_Data: 45 X: 9.0154Y: 14.7822Z: 3.75615
12:31:50: RS::Vertex_Number_drawn: 45 X: 9.0154Y: 14.7822Z: 3.75615
12:31:50: RS::Vertex_Data: 46 X: 7.09661Y: 16.4636Z: 3.49725
12:31:50: RS::Vertex_Number_drawn: 46 X: 7.09661Y: 16.4636Z: 3.49725
12:31:50: RS::Vertex_Data: 47 X: 8.36882Y: 15.7339Z: 3.84285
12:31:50: RS::Vertex_Number_drawn: 47 X: 8.36882Y: 15.7339Z: 3.84285
12:31:50: RS::Vertex_Data: 48 X: -8.05394Y: 14.3771Z: 4.71945
12:31:50: RS::Vertex_Data: 49 X: -9.7956Y: 15.0682Z: 2.60465
12:31:50: RS::Vertex_Data: 50 X: -10.402Y: 15.4253Z: 1.51755
12:31:50: RS::Vertex_Data: 51 X: -10.6711Y: 14.6185Z: 0.875952
12:31:50: RS::Vertex_Data: 52 X: -10.1022Y: 13.7878Z: 2.15505
12:31:50: RS::Vertex_Data: 53 X: -9.26515Y: 13.4314Z: 3.32625
12:31:50: RS::Vertex_Data: 54 X: -7.92624Y: 13.2468Z: 4.72985
12:31:50: RS::Vertex_Data: 55 X: -9.0154Y: 14.7822Z: 3.75615
12:31:50: RS::Vertex_Data: 56 X: -7.09661Y: 16.4636Z: 3.49725
12:31:50: RS::Vertex_Data: 57 X: -8.36882Y: 15.7339Z: 3.84285


does anyone has an idea what to do now?
at the moment i'am a bit lost.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Ogre mesh to PolyVox
PostPosted: Sun Sep 02, 2012 12:11 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
PolyVox does support negative voxel positions. You just need to specify an appropriate region in the constructor for your volume. Altrnatively, just add some fixed value like (100, 100, 100) to the vertex positions.

Also, it looks like you're only using the first submesh?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Ogre mesh to PolyVox
PostPosted: Sun Sep 02, 2012 2:49 pm 

Joined: Fri Aug 31, 2012 9:42 pm
Posts: 9
David Williams wrote:
PolyVox does support negative voxel positions. You just need to specify an appropriate region in the constructor for your volume. Altrnatively, just add some fixed value like (100, 100, 100) to the vertex positions.

Also, it looks like you're only using the first submesh?


Jep currently i only wan't to process the first submesh.

just wanted that it completely draws all positions of the first submesh
and if that works i process the rest of the submeshs .

as you can see in the post above not all positions are applied to the voxel grid
only 27 / 58 are applied...

I will try to add some fixed values to it thx aggain ^^


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Ogre mesh to PolyVox
PostPosted: Mon Sep 03, 2012 7:54 am 

Joined: Fri Aug 31, 2012 9:42 pm
Posts: 9
To use Fixed Values solved the problem and i modified my funktion to go trough
all submeshes and saving all vertex positions in to an array (Vector3) that worked untill vertex
1641 but after that i get only those strange values until the end of the array (09:41:33: RS::Vertex_Data: 1642 X: -4.31602e+008 Y: -4.31602e+008 Z: -4.31602e+008)
wich is at 2241.... hmm i'm wondering what i'am missing and by the way i try to draw ogrehead.mesh
it has 4 submeshes and should have 2241 verts

does anyone has an idea what the problem could be ?


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

All times are UTC


Who is online

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