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


All times are UTC




Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Two problems!
PostPosted: Sat Feb 19, 2011 8:44 am 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
Hello! I am having some difficulty getting the demo to work, maybe someone could help me.

Ok, first, with a side note, including some hearts causes all my shared_ptr become ambiguous calls.

Now for the real deal, I followed the OpenGL demo and did just about the same but with DirectX in a simple way just to test, here we go:
Code:
PolyVox::Volume<PolyVox::MaterialDensityPair44> m_VolumeData(64, 64, 64);

       Vector3 v3dVolCenter(m_VolumeData.getWidth() / 2, m_VolumeData.getHeight() / 2, m_VolumeData.getDepth() / 2);

       //This three-level for loop iterates over every voxel in the volume
       for (int z = 0; z < m_VolumeData.getWidth(); z++)
       {
          for (int y = 0; y < m_VolumeData.getHeight(); y++)
          {
             for (int x = 0; x < m_VolumeData.getDepth(); x++)
             {
                //Store our current position as a vector...
                Vector3 v3dCurrentPos(x,y,z);
                //And compute how far the current position is from the center of the volume
                if (IsInRange(v3dCurrentPos, v3dCurrentPos, 5))
                {
                   //Our new density value
                   uint8_t uDensity = PolyVox::MaterialDensityPair44::getMaxDensity();

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

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

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

        PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> mesh;
       PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::MaterialDensityPair44> surfaceExtractor(&m_VolumeData, m_VolumeData.getEnclosingRegion(), &mesh);

       surfaceExtractor.execute();

       const vector<uint32_t>& vecIndices = mesh.getIndices();
       const vector<PolyVox::PositionMaterialNormal>& vecVertices = mesh.getVertices();

       m_VertexBuffer.Create(sizeof(PolyVox::PositionMaterialNormal) * mesh.getNoOfVertices());

       m_IndexBuffer.Create(mesh.getNoOfIndices() * sizeof(DWORD), 8UL, D3DFMT_INDEX32);

       void* pVoid;
       m_IndexBuffer.Lock(&pVoid);

       const void* pIndices = static_cast<const void*>(&(vecIndices[0]));      

   

      memcpy((pVoid), pIndices, sizeof(uint32_t) * vecIndices.size());
   

       m_IndexBuffer.Unlock();

       const void* pVertices = static_cast<const void*>(&(vecVertices[0]));   

       m_VertexBuffer.Lock(&pVoid);

       count = 0;

       memcpy((pVoid), pVertices, sizeof(PolyVox::PositionMaterialNormal) * vecVertices.size());



       m_VertexBuffer.Unlock();

       m_NumVertices = vecVertices.size();
       m_NumFaces = vecIndices.size() / 3;


The problems: the returning std::vector for indices and vectors are empty.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Two problems!
PostPosted: Sat Feb 19, 2011 9:02 am 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
Follow up:

I tried SurfaceExtractor instead of CubicSurfaceExtractorWithNormals now, I am getting triangles but not indices... what could be the problem?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Two problems!
PostPosted: Sat Feb 19, 2011 3:35 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Hi, I tried to test you code but actually you didn't post your IsInRange() function. For testing purposes, lets leave rendering aside and focus what data is in the vertex/index buffers. If your example compiles without Direct3D that would be easiest...

Shanee wrote:
I tried SurfaceExtractor instead of CubicSurfaceExtractorWithNormals now, I am getting triangles but not indices... what could be the problem?


Not sure, in the example you can switch these two interchangebly. But I'm sure it will become slear when we solve the first problem :-)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Two problems!
PostPosted: Sat Feb 19, 2011 3:42 pm 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
Hey David, thank you for the reply, again :)

I did test I am actually getting the statement to work there and voxels being added so I should get something even if my function was broken, but hey:
Code:
bool IsInRange(CONST D3DXVECTOR3& pos1, CONST D3DXVECTOR3& pos2, float range)
   {
      Vector3 diffVec = pos2 - pos1;

      float distance = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z;

      range = range * range;

      if (distance <= range)
         return true;

      return false;
   }


I am really baffled! tried downloading the zipped (older) source instead of using the SVN, still not working. Also tried to use smoothPositions to see if it might magically get indices working but I ended with an error on that part:
Quote:
Error 14 error C2039: 'isOnGeometryEdge' : is not a member of 'PolyVox::PositionMaterialNormal' d:\programming\mimiluna - svn\engine\libs\polyvoxcore\SurfaceMesh.inl 222


Something seems to be broken somehow, maybe I messed the build somehow on both versions I built?

Edit: putting renderer APIs aside, I am looking into the mesh (PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> mesh) in debug, that's where I see there are some vertices (quite a bit even) but the index vector is empty (size = 0, as well as lack of content)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Two problems!
PostPosted: Sat Feb 19, 2011 3:48 pm 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
Not sure if this spam will help much:

Code:
-      mesh   {m_Region={...} m_iTimeStamp=-1 m_iNoOfLod0Tris=-858993460 ...}   PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>
-      m_Region   {m_v3dLowerCorner={...} m_v3dUpperCorner={...} dummy='d' }   PolyVox::Region
-      m_v3dLowerCorner   {m_tElements=0x006ae504 }   PolyVox::Vector<3,short>
-      m_tElements   0x006ae504   short [3]
      [0]   0   short
      [1]   0   short
      [2]   0   short
-      m_v3dUpperCorner   {m_tElements=0x006ae50a }   PolyVox::Vector<3,short>
-      m_tElements   0x006ae50a   short [3]
      [0]   63   short
      [1]   63   short
      [2]   63   short
      dummy   100 'd'   unsigned char
      m_iTimeStamp   -1   int
      m_iNoOfLod0Tris   -858993460   int
+      m_vecTriangleIndices   [0]()   std::vector<unsigned int,std::allocator<unsigned int> >
+      m_vecVertices   [12288]({position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=0.00000000 },{position={...} normal={...} material=??? },...,...)   std::vector<PolyVox::PositionMaterialNormal,std::allocator<PolyVox::PositionMaterialNormal> >
-      m_vecLodRecords   [1]({beginIndex=0 endIndex=0 })   std::vector<PolyVox::LodRecord,std::allocator<PolyVox::LodRecord> >
      [size]   1   unsigned long
      [capacity]   1   unsigned long
+      [0]   {beginIndex=0 endIndex=0 }   PolyVox::LodRecord
-      m_mapUsedMaterials   [0]()   std::set<unsigned char,std::less<unsigned char>,std::allocator<unsigned char> >
      [comp]   less   std::less<unsigned char>
      pIndices   0xcccccccc   const void *
      count   -858993460   int


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Two problems!
PostPosted: Sat Feb 19, 2011 3:58 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
The error is in this line:

Code:
if (IsInRange(v3dCurrentPos, v3dCurrentPos, 5))


You're using 'v3dCurrentPos' twice, one of those values should be v3dVolCenter :-) I guess this means it's always true and the volume gets filled solid, so no surface to extract.

However, it's strange that the SurfaceExtractor gives vetiecs but no indices in this case. It could be a bug.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Two problems!
PostPosted: Sat Feb 19, 2011 4:01 pm 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
Haha! Always fall on the most trivial of mistakes. Fast copy pasting and writing of code at 3 at night is never good :)

Testing now...
Image

Yay! Thank you :) silly ^^

But hey, at least I might have found an actual bug there? ;)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Two problems!
PostPosted: Sat Feb 19, 2011 4:10 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
No problem, I'm glad it's working. And yes, I'll have to look into that bug.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Two problems!
PostPosted: Sat Feb 19, 2011 4:37 pm 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
I must congratulate you, you know ;) This library seems to be very useful and flexible, most important - efficient and easy to use. Downloading, building, adding to my engine and getting it to work took but 10-15 minutes (if we ignore the silly mistake I had there) with little useful consciousness at late night. Very easy to use so far! And it is very generous of you to let everyone use it for free even in commercial products (hope you won't change that policy :))


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Two problems!
PostPosted: Sat Feb 19, 2011 5:52 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Thanks, people appriciating the library is one of the main things that insipres me to keep working on it :-)
Shanee wrote:
And it is very generous of you to let everyone use it for free even in commercial products (hope you won't change that policy :))

I can't change that policy for the code that has already been released, so everything you've got is free forever. The worst case is that I could decide that future versions of the library would be under a different license, but I have no intention of doing that.


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

All times are UTC


Who is online

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