Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

PolyVox Z value question
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=173
Page 1 of 3

Author:  Shanee [ Wed Mar 16, 2011 1:03 pm ]
Post subject:  PolyVox Z value question

Question,

For PolyVox, negative Z is minimum and positive Z is maximum for regions?

Because I been sometimes using cropTo (region) and been getting negative upperCorner while positive lowerCorner.

Author:  Shanee [ Wed Mar 16, 2011 1:21 pm ]
Post subject:  Re: PolyVox Z value question

Also I am getting assertion at setVoxelAt:
Code:
assert(m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));


x, y, z = 0 all, region lower = 0,0,0 - upper = 63, 63, 63

Author:  ker [ Wed Mar 16, 2011 2:32 pm ]
Post subject:  Re: PolyVox Z value question

Shanee wrote:
For PolyVox, negative Z is minimum and positive Z is maximum for regions?

Because I been sometimes using cropTo (region) and been getting negative upperCorner while positive lowerCorner.


what you are saying is only possible if you use Region::set*Corner and pass some bad values.
do you have code examples?

what do you mean by "negative Z is minimum"?

about your other question, Since the opengl example is working you must be doing something rather odd...
again: do you have a code example?

[edit] did you see the pretty new polyvox subforum? I think this belongs there, not here ;) [/edit]

Author:  David Williams [ Wed Mar 16, 2011 6:54 pm ]
Post subject:  Re: PolyVox Z value question

Shanee wrote:
Question,

For PolyVox, negative Z is minimum and positive Z is maximum for regions?

Because I been sometimes using cropTo (region) and been getting negative upperCorner while positive lowerCorner.


Can you give an example of where this is going wrong? What are the input and output values? Maybe you can create a code example in which you create two regions manually and reproduce this error?

Shanee wrote:
Also I am getting assertion at setVoxelAt:
Code:
assert(m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));


x, y, z = 0 all, region lower = 0,0,0 - upper = 63, 63, 63

I just tested the following code:

Code:
Region region(Vector3DInt32(0,0,0), Vector3DInt32(63,63,63));
Vector3DInt32 point(0,0,0);
bool result = region.containsPoint(point);
cout << result << std::endl;


The output is '1' (true) as expected. Can you step through in the debugger to see what's going wrong in your case?

Author:  Shanee [ Wed Mar 16, 2011 7:48 pm ]
Post subject:  Re: PolyVox Z value question

Just a moment with that, I have another weird problem.

In my editor I have this function:
Code:
void VoxelEntity::RebuildAllInBox(Vector3& min, Vector3 &max)
   {
      Vector3 meshMin, meshMax;
      for (int x = 0; x < m_NumPatchesX; x++)
         for (int y = 0; y < m_NumPatchesY; y++)
            for (int z = 0; z < m_NumPatchesZ; z++)
            {
               GetMeshBoundingBox(PolyVox::Vector3DInt32(x,y,z), meshMin, meshMax);

               if (IntersectBoxToBox(min, max, meshMin, meshMax))
                  m_Meshes[PolyVox::Vector3DInt32(x,y,z)]->Construct(*m_VolumeData.get(), PolyVox::Region(PolyVox::Vector3DInt32(x * m_PatchSizeX, y * m_PatchSizeY, z * m_PatchSizeZ), PolyVox::Vector3DInt32(m_PatchSizeX + x * m_PatchSizeX, m_PatchSizeY + y * m_PatchSizeY, m_PatchSizeZ + z * m_PatchSizeZ)));
            }
   }


Here is my Cosntruct function:
Code:
bool VoxelMesh::Construct(PolyVox::Volume<PolyVox::MaterialDensityPair44>& volume, PolyVox::Region region)
   {
      PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> mesh;
      PolyVox::SurfaceExtractor<PolyVox::MaterialDensityPair44> surfaceExtractor(&volume, region, &mesh);

      surfaceExtractor.execute();
      //mesh.smoothPositions(1, true);
      
      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);

      if (vecIndices.empty())
         return false;

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

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

      int count = 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;

      m_Region = region;

      m_WorldPosition.Move(region.getLowerCorner().getX(), region.getLowerCorner().getY(), region.getLowerCorner().getZ());
      m_WorldPosition.Update();

      return true;
   }


Now here is the strange part:

First of all I am having this hole, only at the first patch it seems:
Image

But here is another problem I have on every patch:
Image

I click to create the "bulge" close to me and it also created one in the patch next to it. The problem is not with the editor because it edits the volume itself, not the patches, just updates the patches with the above function.

Now when I move to the next patch and tried to create one at the border it create again on the next, but also around the same positino in the previous patch!

Again, it does not create them on patches other than neighbouring ones.
Image

This also happens when I edit the the edge at the very beginning (editing the next)

Author:  Shanee [ Wed Mar 16, 2011 7:58 pm ]
Post subject:  Re: PolyVox Z value question

Actually, this all might really be related to the errors I been getting with the cropTo.

Here is the cropTo I used:
Code:
void VoxelEditor::smoothSphereRegion(PolyVox::Volume<VoxelType>& volData, Vector3& sphereCenter, float radius)
   {
      PolyVox::Region regionToSmooth(PolyVox::Vector3DInt32(sphereCenter.x - radius, sphereCenter.y - radius, sphereCenter.z - radius), PolyVox::Vector3DInt32(sphereCenter.x + radius, sphereCenter.y + radius, sphereCenter.z + radius));

      PolyVox::Region croppedRegion = regionToSmooth;
      croppedRegion.cropTo(volData.getEnclosingRegion());

Author:  Shanee [ Wed Mar 16, 2011 8:09 pm ]
Post subject:  Re: PolyVox Z value question

Ok, this has to be related!

Once I removed the smoothSphereRegion from my SphereBrush all works fine.

Edit: Another strange clue:

When I am creating my class like this:
VoxelEntity(64,64,64, 6, 1, 6) (patch size x y z, num patches x y z)

it is all fine

When I create 7,1,7 patches it suddenly starts happening.

Yet my code is just using a map and those normal calculations, so why would it suddenly break?

Author:  David Williams [ Wed Mar 16, 2011 9:01 pm ]
Post subject:  Re: PolyVox Z value question

Ok, your seeing some strange behaviour :) It hard for me to just say what's wrong, but there are a number of things you can try in order to simplify the problem.

  • It seems that even before you sart editing your extracted mesh is wrong. This is a concern - and there's not much point worrying about further problems until you have the base case working properly. The problems could all be related.
  • I assume you are trying to keep track of which voxels change so that you know which patches to regenerate? It is easy to make a mistake here - for example are you aware that changing a single voxel can require multiple patches to be regenerated if the voxel lies on a border? At any rate, it is worth having a 'reset' button which will regenerate all patches any time you want.
  • Next what if you have a single large patch instead of several small ones? Is the mesh still wrong? This helps determine wherther the issue is with PolyVox or you patch handling. Once that works, move up to just two patches, and so forth.
  • Add single feature at a time - don't worry about the smoothing until the mesh extraction works perfectly.
  • Are you woring on the RLE branch? Remember this is experimental and largely untested. I think it's probably not the issue, but you might want to try the trunk version of PolyVox which has been tested by more people. There are not many code changes required.

Author:  Shanee [ Wed Mar 16, 2011 9:37 pm ]
Post subject:  Re: PolyVox Z value question

Ok first of all it is unrelated to smoothing. But I am use the crop in the mesh editing too.

Once I set the numPatches to 6 (x,z.. y =1) (patchsize = 64 all) it is all fine!

Once I increase to 7 x/z it breaks. Everything like that, not sure why. (things lower than 6 also work fine, higher than 7 also broken)

Keeping track of what I edited is easy, when I use the brush I use it with a radius and position, then I call:
Code:
void VoxelEntity::RebuildAllInSphere(Vector3& pos, float radius)
   {
      Vector3 min, max;
      min.x = pos.x - radius;
      min.y = pos.y - radius;
      min.z = pos.z - radius;

      max.x = pos.x + radius;
      max.y = pos.y + radius;
      max.z = pos.z + radius;

      RebuildAllInBox(min,max);
}


There it just does this:
Code:
void VoxelEntity::RebuildAllInBox(Vector3& min, Vector3 &max)
   {
      Vector3 meshMin, meshMax;
      for (int32_t x = 0; x < m_NumPatchesX; x++)
         for (int32_t y = 0; y < m_NumPatchesY; y++)
            for (int32_t z = 0; z < m_NumPatchesZ; z++)
            {
               GetMeshBoundingBox(PolyVox::Vector3DInt32(x,y,z), meshMin, meshMax);

               if (IntersectBoxToBox(min, max, meshMin, meshMax))
                  m_Meshes[PolyVox::Vector3DInt32(x,y,z)]->Construct(*m_VolumeData.get(), PolyVox::Region(PolyVox::Vector3DInt32(x * m_PatchSizeX, y * m_PatchSizeY, z * m_PatchSizeZ), PolyVox::Vector3DInt32(m_PatchSizeX + x * m_PatchSizeX, m_PatchSizeY + y * m_PatchSizeY, m_PatchSizeZ + z * m_PatchSizeZ)));
            }
   }


GetMeshBounds does this:
Code:
min.x = (float)pos.getX() * (float)m_PatchSizeX - 1;
      min.y = (float)pos.getY() * (float)m_PatchSizeY - 1;
      min.z = (float)pos.getZ() * (float)m_PatchSizeZ - 1;

      max.x = min.x + (float)m_PatchSizeX + 2;
      max.y = min.y + (float)m_PatchSizeY + 2;
      max.z = min.z + (float)m_PatchSizeZ + 2;


The reason for the offsets is because if I edit 65 it may affect the form of voxel 64 so I want it to update too.

More in a moment.

Edit: Yes, I am using the RLE version.

P.S. I am also getting a crash at "mlock.c"
Code:
void __cdecl _unlock (
        int locknum
        )
{
        /*
         * leave the critical section.
         */
        LeaveCriticalSection( _locktable[locknum].lock );
}


I don't know what calls it, my call stack seems to be incomplete there.
http://pokit.etf.ba/get/518dd96de08fdd8 ... 00bcde.jpg

Author:  David Williams [ Wed Mar 16, 2011 9:58 pm ]
Post subject:  Re: PolyVox Z value question

Shanee wrote:
P.S. I am also getting a crash at "mlock.c"
Code:
void __cdecl _unlock (
        int locknum
        )
{
        /*
         * leave the critical section.
         */
        LeaveCriticalSection( _locktable[locknum].lock );
}


I don't know what calls it, my call stack seems to be incomplete there.
http://pokit.etf.ba/get/518dd96de08fdd8 ... 00bcde.jpg

That looks threading related... Are you accessing the volume from more than one thread? Be aware that it is not thread safe.

Page 1 of 3 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/