Maybe someone else would notice if I am doing something very stupid with this code here?
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();
vector<uint32_t> problemVertices;
float mat1;
float mat2;
float mat3;
for (vector<uint32_t>::const_iterator iter = vecIndices.begin(); iter != vecIndices.end(); iter++)
{
mat1 = vecVertices[*iter].getMaterial();
mat2 = vecVertices[*(iter+1)].getMaterial();
mat3 = vecVertices[*(iter+2)].getMaterial();
if (floatComparsion(mat1, mat2) == false || floatComparsion(mat1, mat3) == false || floatComparsion(mat2, mat3) == false)
{
problemVertices.push_back(*iter);
problemVertices.push_back(*(iter+1));
problemVertices.push_back(*(iter+2));
}
iter++;
iter++;
}
m_VertexBuffer.Create(sizeof(PolyVox::PositionMaterialNormal) * (mesh.getNoOfVertices() + (problemVertices.size() * 2)));
m_IndexBuffer.Create((mesh.getNoOfIndices() + problemVertices.size() * 2) * 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]));
uint32_t count = 0;
memcpy((pVoid), pIndices, sizeof(uint32_t) * vecIndices.size());
uint32_t* indices = (uint32_t*)pVoid;
for (uint32_t i = 0; i < (problemVertices.size() * 2); i++)
{
indices[vecIndices.size() + i] = vecVertices.size() + i;
}
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());
PolyVox::PositionMaterialNormal* vert = (PolyVox::PositionMaterialNormal*)pVoid;
for (vector<uint32_t>::iterator iter = problemVertices.begin(); iter != problemVertices.end();)
{
vert[vecVertices.size() + count] = vert[*iter];
vert[vecVertices.size() + count + 1] = vert[(*iter+1)];
vert[vecVertices.size() + count + 1].setMaterial(300);
vert[vecVertices.size() + count + 2] = vert[(*iter+2)];
vert[vecVertices.size() + count + 2].setMaterial(300);
count +=3;
vert[vecVertices.size() + count] = vert[*iter];
vert[vecVertices.size() + count].setMaterial(300);
vert[vecVertices.size() + count + 1] = vert[(*iter+1)];
vert[vecVertices.size() + count + 2] = vert[(*iter+2)];
vert[vecVertices.size() + count + 2].setMaterial(300);
count +=3;
vert[*iter].setMaterial(300);
iter++;
vert[*iter].setMaterial(300);
iter++;
iter++;
}
m_VertexBuffer.Unlock();
m_NumVertices = vecVertices.size() + problemVertices.size() * 2;
m_NumFaces = vecIndices.size() / 3 + (problemVertices.size() * 2) / 3;
m_Region = region;
m_WorldPosition.Move(region.getLowerCorner().getX(), region.getLowerCorner().getY(), region.getLowerCorner().getZ());
m_WorldPosition.Update();
return true;
}
I am getting them all completely transparent.
I even tried to copy the vertices to one of the additional ones and not setting their material to 300 (transparent) but they still go transparent, as if only the first one really work.
I also noticed that sometimes it copied a vertex with material 300 but the only place I am setting the material to be possibly 300 is in that function, uff!