The CubicSurfaceExtractor now generates vertices of type PositionMaterialNormal rather than PositionMaterial. The normal property is just a dummy and is not filled in, though conceptually we could put something in there in the future (average normal of surrounding faces?)

The point of this change is to move towards having a single vertex class with known properties (including normal). This makes it simpler to write code which uses the vertices because we always know which properties are present. This will probably be useful when working with vertex buffer objects.
This commit is contained in:
David Williams 2014-05-05 20:53:47 +02:00
parent 2da902d5f9
commit 5dfa7e2562
7 changed files with 12 additions and 12 deletions

View File

@ -14,7 +14,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
{
}
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterial>& surfaceMesh)
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh)
{
//Convienient access to the vertices and indices
const auto& vecIndices = surfaceMesh.getIndices();
@ -27,7 +27,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
//The GL_ARRAY_BUFFER will contain the list of vertex positions
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterial), vecVertices.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), vecVertices.data(), GL_STATIC_DRAW);
//and GL_ELEMENT_ARRAY_BUFFER will contain the indices
glGenBuffers(1, &indexBuffer);
@ -36,7 +36,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
//We need to tell OpenGL how to understand the format of the vertex data
glEnableVertexAttribArray(0); //We're talking about shader attribute '0'
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(PositionMaterial), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type)
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(PositionMaterialNormal), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type)
glBindVertexArray(0);

View File

@ -42,7 +42,7 @@ public:
void mousePressEvent(QMouseEvent* event);
//Convert a SurfaceMesh to OpenGL index/vertex buffers
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterial>& surfaceMesh);
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
protected:
//Qt OpenGL functions

View File

@ -78,7 +78,7 @@ int main(int argc, char *argv[])
createSphereInVolume(volData, 30);
//A mesh object to hold the result of surface extraction
SurfaceMesh<PositionMaterial> mesh;
SurfaceMesh<PositionMaterialNormal> mesh;
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
CubicSurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);

View File

@ -113,9 +113,9 @@ namespace PolyVox
// This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template
// Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC?
#if defined(_MSC_VER)
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
#else
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
#endif
@ -135,7 +135,7 @@ namespace PolyVox
Region m_regSizeInVoxels;
//The surface patch we are currently filling.
SurfaceMesh<PositionMaterial>* m_meshCurrent;
SurfaceMesh<PositionMaterialNormal>* m_meshCurrent;
//Used to avoid creating duplicate vertices.
Array<3, IndexAndMaterial> m_previousSliceVertices;

View File

@ -36,7 +36,7 @@ namespace PolyVox
const uint32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::MaxVerticesPerPosition = 8;
template<typename VolumeType, typename IsQuadNeeded>
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial>* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
:m_volData(volData)
,m_regSizeInVoxels(region)
,m_meshCurrent(result)
@ -214,7 +214,7 @@ namespace PolyVox
if(rEntry.iIndex == -1)
{
//No vertices matched and we've now hit an empty space. Fill it by creating a vertex. The 0.5f offset is because vertices set between voxels in order to build cubes around them.
rEntry.iIndex = m_meshCurrent->addVertex(PositionMaterial(Vector3DFloat(static_cast<float>(uX) - 0.5f, static_cast<float>(uY) - 0.5f, static_cast<float>(uZ) - 0.5f), uMaterialIn));
rEntry.iIndex = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(static_cast<float>(uX)-0.5f, static_cast<float>(uY)-0.5f, static_cast<float>(uZ)-0.5f), uMaterialIn));
rEntry.uMaterial = uMaterialIn;
return rEntry.iIndex;

View File

@ -106,7 +106,7 @@ uint32_t testForType(void)
{
for (int32_t x = 0; x < uVolumeSideLength; x += uRegionSideLength)
{
SurfaceMesh<PositionMaterial> result;
SurfaceMesh<PositionMaterialNormal> result;
Region regionToExtract(x, y, z, x + uRegionSideLength - 1, y + uRegionSideLength - 1, z + uRegionSideLength - 1);
CubicSurfaceExtractor< SimpleVolume<VoxelType> > extractor(&volData, regionToExtract, &result);
extractor.execute();

View File

@ -184,7 +184,7 @@ void TestVolumeSubclass::testExtractSurface()
}
}
SurfaceMesh<PositionMaterial> result;
SurfaceMesh<PositionMaterialNormal> result;
CubicSurfaceExtractor< VolumeSubclass<Material8> > cubicSurfaceExtractor(&volumeSubclass, volumeSubclass.getEnclosingRegion(), &result);
cubicSurfaceExtractor.execute();