This commit templatizes the vertex classes on voxel types. This was the main change which was made for Cubiquity and it's very messy at the moment. However, this will improve when we make more use of 'auto' to hide the template madness.
This commit is contained in:
parent
4c2aea3db1
commit
b0a8ca8a64
@ -14,7 +14,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
|
||||
{
|
||||
}
|
||||
|
||||
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh)
|
||||
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal<uint8_t> >& 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(PositionMaterialNormal), vecVertices.data(), GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal<uint8_t>), 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(PositionMaterialNormal), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type)
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(PositionMaterialNormal<uint8_t>), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type)
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
|
||||
//Convert a SurfaceMesh to OpenGL index/vertex buffers
|
||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
|
||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<uint8_t> >& surfaceMesh);
|
||||
|
||||
protected:
|
||||
//Qt OpenGL functions
|
||||
|
@ -78,7 +78,7 @@ int main(int argc, char *argv[])
|
||||
createSphereInVolume(volData, 30);
|
||||
|
||||
//A mesh object to hold the result of surface extraction
|
||||
SurfaceMesh<PositionMaterialNormal> mesh;
|
||||
SurfaceMesh<PositionMaterialNormal<uint8_t> > 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);
|
||||
|
@ -29,9 +29,9 @@ freely, subject to the following restrictions:
|
||||
using namespace PolyVox;
|
||||
using namespace std;
|
||||
|
||||
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal>& mesh, unsigned int uLodLevel)
|
||||
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >& mesh, unsigned int uLodLevel)
|
||||
{
|
||||
const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
|
||||
const vector<PositionMaterialNormal<MaterialDensityPair44> >& vecVertices = mesh.getVertices();
|
||||
const vector<uint32_t>& vecIndices = mesh.getIndices();
|
||||
|
||||
int beginIndex = mesh.m_vecLodRecords[uLodLevel].beginIndex;
|
||||
@ -41,7 +41,7 @@ void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal>& mes
|
||||
//for(vector<PolyVox::uint32_t>::const_iterator iterIndex = vecIndices.begin(); iterIndex != vecIndices.end(); ++iterIndex)
|
||||
for(int index = beginIndex; index < endIndex; ++index)
|
||||
{
|
||||
const PositionMaterialNormal& vertex = vecVertices[vecIndices[index]];
|
||||
const PositionMaterialNormal<MaterialDensityPair44> & vertex = vecVertices[vecIndices[index]];
|
||||
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
|
||||
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
|
||||
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());
|
||||
@ -49,7 +49,9 @@ void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal>& mes
|
||||
|
||||
|
||||
|
||||
uint8_t material = static_cast<uint8_t>(vertex.getMaterial() + 0.5);
|
||||
//uint8_t material = static_cast<uint8_t>(static_cast<double>(vertex.getMaterial()) + 0.5);
|
||||
uint8_t material = 1;
|
||||
|
||||
|
||||
OpenGLColour colour = convertMaterialIDToColour(material);
|
||||
|
||||
|
@ -24,10 +24,11 @@ freely, subject to the following restrictions:
|
||||
#ifndef __OpenGLExample_OpenGLImmediateModeSupport_H__
|
||||
#define __OpenGLExample_OpenGLImmediateModeSupport_H__
|
||||
|
||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include "glew/glew.h"
|
||||
|
||||
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& mesh, unsigned int uLodLevel);
|
||||
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >& mesh, unsigned int uLodLevel);
|
||||
|
||||
#endif //__OpenGLExample_OpenGLImmediateModeSupport_H__
|
||||
|
@ -24,12 +24,13 @@ freely, subject to the following restrictions:
|
||||
#include "OpenGLSupport.h"
|
||||
#include "OpenGLVertexBufferObjectSupport.h"
|
||||
|
||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||
#include "PolyVoxCore/SurfaceMesh.h"
|
||||
|
||||
using namespace PolyVox;
|
||||
using namespace std;
|
||||
|
||||
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNormal>& mesh)
|
||||
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >& mesh)
|
||||
{
|
||||
//Represents our filled in OpenGL vertex and index buffer objects.
|
||||
OpenGLSurfaceMesh result;
|
||||
@ -38,7 +39,7 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNorma
|
||||
result.sourceMesh = &mesh;
|
||||
|
||||
//Convienient access to the vertices and indices
|
||||
const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
|
||||
const vector<PositionMaterialNormal<MaterialDensityPair44> >& vecVertices = mesh.getVertices();
|
||||
const vector<uint32_t>& vecIndices = mesh.getIndices();
|
||||
|
||||
//If we have any indices...
|
||||
@ -62,9 +63,9 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNorma
|
||||
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(GLfloat) * 9, 0, GL_STATIC_DRAW);
|
||||
GLfloat* ptr = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
|
||||
|
||||
for(vector<PositionMaterialNormal>::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
|
||||
for (vector<PositionMaterialNormal<MaterialDensityPair44> >::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
|
||||
{
|
||||
const PositionMaterialNormal& vertex = *iterVertex;
|
||||
const PositionMaterialNormal<MaterialDensityPair44> & vertex = *iterVertex;
|
||||
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
|
||||
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
|
||||
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());
|
||||
@ -83,7 +84,8 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNorma
|
||||
*ptr = vertex.getNormal().getZ();
|
||||
ptr++;
|
||||
|
||||
uint8_t material = static_cast<uint8_t>(vertex.getMaterial() + 0.5);
|
||||
//uint8_t material = static_cast<uint8_t>(vertex.getMaterial() + 0.5);
|
||||
uint8_t material = 1;
|
||||
|
||||
OpenGLColour colour = convertMaterialIDToColour(material);
|
||||
|
||||
|
@ -33,10 +33,10 @@ struct OpenGLSurfaceMesh
|
||||
GLulong noOfIndices;
|
||||
GLuint indexBuffer;
|
||||
GLuint vertexBuffer;
|
||||
const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>* sourceMesh;
|
||||
const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >* sourceMesh;
|
||||
};
|
||||
|
||||
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& mesh);
|
||||
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >& mesh);
|
||||
void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel);
|
||||
|
||||
#endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__
|
||||
|
@ -87,7 +87,7 @@ void OpenGLWidget::setVolume(PolyVox::LargeVolume<MaterialDensityPair44>* volDat
|
||||
//Extract the surface for this region
|
||||
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
|
||||
|
||||
std::shared_ptr< SurfaceMesh<PositionMaterialNormal> > mesh(new SurfaceMesh<PositionMaterialNormal>);
|
||||
std::shared_ptr< SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> > > mesh(new SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >);
|
||||
MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get());
|
||||
surfaceExtractor.execute();
|
||||
|
||||
@ -193,7 +193,7 @@ void OpenGLWidget::paintGL()
|
||||
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
|
||||
if(m_mapSurfaceMeshes.find(v3dRegPos) != m_mapSurfaceMeshes.end())
|
||||
{
|
||||
std::shared_ptr< SurfaceMesh<PositionMaterialNormal> > meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
|
||||
std::shared_ptr< SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> > > meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
|
||||
unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1;
|
||||
if(m_bUseOpenGLVertexBufferObjects)
|
||||
{
|
||||
|
@ -88,7 +88,7 @@ class OpenGLWidget : public QGLWidget
|
||||
|
||||
//Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
|
||||
std::map<PolyVox::Vector3DUint8, OpenGLSurfaceMesh, Vector3DUint8Compare> m_mapOpenGLSurfaceMeshes;
|
||||
std::map<PolyVox::Vector3DUint8, std::shared_ptr<PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> >, Vector3DUint8Compare> m_mapSurfaceMeshes;
|
||||
std::map<PolyVox::Vector3DUint8, std::shared_ptr<PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> > >, Vector3DUint8Compare> m_mapSurfaceMeshes;
|
||||
|
||||
unsigned int m_uRegionSideLength;
|
||||
unsigned int m_uVolumeWidthInRegions;
|
||||
|
@ -15,7 +15,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
|
||||
{
|
||||
}
|
||||
|
||||
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh)
|
||||
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >& surfaceMesh)
|
||||
{
|
||||
if((surfaceMesh.getNoOfIndices() == 0) || (surfaceMesh.getNoOfVertices() == 0))
|
||||
{
|
||||
@ -25,7 +25,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
|
||||
|
||||
//Convienient access to the vertices and indices
|
||||
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
|
||||
const vector<PositionMaterialNormal>& vecVertices = surfaceMesh.getVertices();
|
||||
const vector<PositionMaterialNormal<MaterialDensityPair44> >& vecVertices = surfaceMesh.getVertices();
|
||||
|
||||
//Build an OpenGL index buffer
|
||||
glGenBuffers(1, &indexBuffer);
|
||||
@ -37,7 +37,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
|
||||
glGenBuffers(1, &vertexBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
|
||||
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal<MaterialDensityPair44>), pVertices, GL_STATIC_DRAW);
|
||||
|
||||
m_uBeginIndex = 0;
|
||||
m_uEndIndex = vecIndices.size();
|
||||
@ -69,7 +69,7 @@ void OpenGLWidget::initializeGL()
|
||||
|
||||
//We'll be rendering with index/vertex arrays
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
//glEnableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
|
||||
void OpenGLWidget::resizeGL(int w, int h)
|
||||
@ -109,8 +109,8 @@ void OpenGLWidget::paintGL()
|
||||
|
||||
//Bind the vertex buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0);
|
||||
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal<MaterialDensityPair44>), 0);
|
||||
//glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal<MaterialDensityPair44>), (GLvoid*)12);
|
||||
|
||||
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ distribution.
|
||||
#ifndef __BasicExample_OpenGLWidget_H__
|
||||
#define __BasicExample_OpenGLWidget_H__
|
||||
|
||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||
#include "PolyVoxCore/SurfaceMesh.h"
|
||||
|
||||
#include "glew/glew.h"
|
||||
@ -41,7 +42,7 @@ public:
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
|
||||
//Convert a SrfaceMesh to OpenGL index/vertex buffers
|
||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
|
||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >& surfaceMesh);
|
||||
|
||||
protected:
|
||||
//Qt OpenGL functions
|
||||
|
@ -186,7 +186,7 @@ int main(int argc, char *argv[])
|
||||
std::cout << "Compression ratio: 1 to " << (1.0/(volData.calculateCompressionRatio())) << std::endl;
|
||||
|
||||
//Extract the surface
|
||||
SurfaceMesh<PositionMaterialNormal> mesh;
|
||||
SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> > mesh;
|
||||
CubicSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(&volData, reg, &mesh);
|
||||
//MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(&volData, reg, &mesh);
|
||||
//CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, reg, &mesh);
|
||||
|
@ -21,11 +21,11 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
|
||||
{
|
||||
}
|
||||
|
||||
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh)
|
||||
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal<uint8_t> >& surfaceMesh)
|
||||
{
|
||||
//Convienient access to the vertices and indices
|
||||
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
|
||||
const vector<PositionMaterialNormal>& vecVertices = surfaceMesh.getVertices();
|
||||
const vector<PositionMaterialNormal<uint8_t> >& vecVertices = surfaceMesh.getVertices();
|
||||
|
||||
//Build an OpenGL index buffer
|
||||
glGenBuffers(1, &indexBuffer);
|
||||
@ -37,17 +37,17 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
|
||||
glGenBuffers(1, &vertexBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
|
||||
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal<uint8_t>), pVertices, GL_STATIC_DRAW);
|
||||
|
||||
m_uBeginIndex = 0;
|
||||
m_uEndIndex = vecIndices.size();
|
||||
}
|
||||
|
||||
void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh)
|
||||
void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PositionMaterialNormal<uint8_t> >& surfaceMesh)
|
||||
{
|
||||
//Convienient access to the vertices and indices
|
||||
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
|
||||
const vector<PositionMaterialNormal>& vecVertices = surfaceMesh.getVertices();
|
||||
const vector<PositionMaterialNormal<uint8_t> >& vecVertices = surfaceMesh.getVertices();
|
||||
|
||||
//Build an OpenGL index buffer
|
||||
glGenBuffers(1, &indexBufferLow);
|
||||
@ -59,7 +59,7 @@ void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<Posit
|
||||
glGenBuffers(1, &vertexBufferLow);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferLow);
|
||||
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
|
||||
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal<uint8_t>), pVertices, GL_STATIC_DRAW);
|
||||
|
||||
m_uBeginIndexLow = 0;
|
||||
m_uEndIndexLow = vecIndices.size();
|
||||
@ -152,8 +152,8 @@ void OpenGLWidget::paintGL()
|
||||
|
||||
//Bind the vertex buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0);
|
||||
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal<uint8_t>), 0);
|
||||
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal<uint8_t>), (GLvoid*)12);
|
||||
|
||||
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
|
||||
|
||||
@ -162,8 +162,8 @@ void OpenGLWidget::paintGL()
|
||||
|
||||
//Bind the vertex buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferLow);
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0);
|
||||
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal<uint8_t>), 0);
|
||||
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal<uint8_t>), (GLvoid*)12);
|
||||
|
||||
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndexLow, m_uEndIndexLow-1, m_uEndIndexLow - m_uBeginIndexLow, GL_UNSIGNED_INT, 0);
|
||||
|
||||
|
@ -41,8 +41,8 @@ public:
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
|
||||
//Convert a SrfaceMesh to OpenGL index/vertex buffers
|
||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
|
||||
void setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
|
||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal <uint8_t> >& surfaceMesh);
|
||||
void setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<uint8_t> >& surfaceMesh);
|
||||
|
||||
protected:
|
||||
//Qt OpenGL functions
|
||||
|
@ -90,13 +90,13 @@ int main(int argc, char *argv[])
|
||||
volumeResampler.execute();
|
||||
|
||||
//Extract the surface
|
||||
SurfaceMesh<PositionMaterialNormal> meshLowLOD;
|
||||
SurfaceMesh<PositionMaterialNormal<uint8_t> > meshLowLOD;
|
||||
MarchingCubesSurfaceExtractor< RawVolume<uint8_t> > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD);
|
||||
surfaceExtractor.execute();
|
||||
meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f);
|
||||
|
||||
//Extract the surface
|
||||
SurfaceMesh<PositionMaterialNormal> meshHighLOD;
|
||||
SurfaceMesh<PositionMaterialNormal<uint8_t> > meshHighLOD;
|
||||
MarchingCubesSurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(30,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD);
|
||||
surfaceExtractorHigh.execute();
|
||||
meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0));
|
||||
|
@ -82,7 +82,7 @@ namespace PolyVox
|
||||
struct IndexAndMaterial
|
||||
{
|
||||
int32_t iIndex;
|
||||
int32_t uMaterial; //Should actually use the material type here, but this is ok for now.
|
||||
typename VolumeType::VoxelType uMaterial;
|
||||
};
|
||||
|
||||
enum FaceNames
|
||||
@ -113,16 +113,16 @@ 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<PositionMaterialNormal>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||
#else
|
||||
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());
|
||||
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||
#endif
|
||||
|
||||
|
||||
void execute();
|
||||
|
||||
private:
|
||||
int32_t addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, uint32_t uMaterial, Array<3, IndexAndMaterial>& existingVertices);
|
||||
int32_t addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType uMaterial, Array<3, IndexAndMaterial>& existingVertices);
|
||||
bool performQuadMerging(std::list<Quad>& quads);
|
||||
bool mergeQuads(Quad& q1, Quad& q2);
|
||||
|
||||
@ -135,7 +135,7 @@ namespace PolyVox
|
||||
Region m_regSizeInVoxels;
|
||||
|
||||
//The surface patch we are currently filling.
|
||||
SurfaceMesh<PositionMaterialNormal>* m_meshCurrent;
|
||||
SurfaceMesh<PositionMaterialNormal<typename VolumeType::VoxelType> >* m_meshCurrent;
|
||||
|
||||
//Used to avoid creating duplicate vertices.
|
||||
Array<3, IndexAndMaterial> m_previousSliceVertices;
|
||||
|
@ -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<PositionMaterialNormal>* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||
:m_volData(volData)
|
||||
,m_regSizeInVoxels(region)
|
||||
,m_meshCurrent(result)
|
||||
@ -88,7 +88,7 @@ namespace PolyVox
|
||||
{
|
||||
uint32_t regX = x - m_regSizeInVoxels.getLowerX();
|
||||
|
||||
uint32_t material; //Filled in by callback
|
||||
typename VolumeType::VoxelType material; //Filled in by callback
|
||||
typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel();
|
||||
typename VolumeType::VoxelType negXVoxel = volumeSampler.peekVoxel1nx0py0pz();
|
||||
typename VolumeType::VoxelType negYVoxel = volumeSampler.peekVoxel0px1ny0pz();
|
||||
@ -205,7 +205,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template<typename VolumeType, typename IsQuadNeeded>
|
||||
int32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, uint32_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
||||
int32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
||||
{
|
||||
for(uint32_t ct = 0; ct < MaxVerticesPerPosition; ct++)
|
||||
{
|
||||
@ -214,14 +214,14 @@ 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(PositionMaterialNormal(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<typename VolumeType::VoxelType>(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;
|
||||
}
|
||||
|
||||
//If we have an existing vertex and the material matches then we can return it.
|
||||
if(rEntry.uMaterial == static_cast<int32_t>(uMaterialIn))
|
||||
if(rEntry.uMaterial == uMaterialIn)
|
||||
{
|
||||
return rEntry.iIndex;
|
||||
}
|
||||
@ -268,7 +268,7 @@ namespace PolyVox
|
||||
{
|
||||
//All four vertices of a given quad have the same material,
|
||||
//so just check that the first pair of vertices match.
|
||||
if(std::abs(m_meshCurrent->getVertices()[q1.vertices[0]].getMaterial() - m_meshCurrent->getVertices()[q2.vertices[0]].getMaterial()) < 0.001)
|
||||
if(m_meshCurrent->getVertices()[q1.vertices[0]].getMaterial() == m_meshCurrent->getVertices()[q2.vertices[0]].getMaterial())
|
||||
{
|
||||
//Now check whether quad 2 is adjacent to quad one by comparing vertices.
|
||||
//Adjacent quads must share two vertices, and the second quad could be to the
|
||||
|
@ -34,11 +34,11 @@ namespace PolyVox
|
||||
class DefaultIsQuadNeeded
|
||||
{
|
||||
public:
|
||||
bool operator()(VoxelType back, VoxelType front, uint32_t& materialToUse)
|
||||
bool operator()(VoxelType back, VoxelType front, VoxelType& materialToUse)
|
||||
{
|
||||
if((back > 0) && (front == 0))
|
||||
{
|
||||
materialToUse = static_cast<uint32_t>(back);
|
||||
materialToUse = static_cast<VoxelType>(back);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -64,10 +64,8 @@ namespace PolyVox
|
||||
public:
|
||||
/// Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing densities.
|
||||
typedef VoxelType DensityType;
|
||||
/// Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing materials. We're using a float here
|
||||
/// because this implementation always returns a constant value off 1.0f. PolyVox also uses floats to store the materials in the mesh vertices
|
||||
/// but this is not really desirable on modern hardware. We'll probably come back to material representation in the future.
|
||||
typedef float MaterialType;
|
||||
/// Used to inform the MarchingCubesSurfaceExtractor about which type it should use for representing materials.
|
||||
typedef VoxelType MaterialType;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -41,9 +41,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)
|
||||
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), Controller controller = Controller());
|
||||
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), Controller controller = Controller());
|
||||
#else
|
||||
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller());
|
||||
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller());
|
||||
#endif
|
||||
|
||||
void execute();
|
||||
@ -193,7 +193,7 @@ namespace PolyVox
|
||||
uint32_t m_uNoOfOccupiedCells;
|
||||
|
||||
//The surface patch we are currently filling.
|
||||
SurfaceMesh<PositionMaterialNormal>* m_meshCurrent;
|
||||
SurfaceMesh<PositionMaterialNormal<typename VolumeType::VoxelType> >* m_meshCurrent;
|
||||
|
||||
//Information about the region we are currently processing
|
||||
Region m_regSizeInVoxels;
|
||||
|
@ -26,7 +26,7 @@ freely, subject to the following restrictions:
|
||||
namespace PolyVox
|
||||
{
|
||||
template<typename VolumeType, typename Controller>
|
||||
MarchingCubesSurfaceExtractor<VolumeType, Controller>::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller)
|
||||
MarchingCubesSurfaceExtractor<VolumeType, Controller>::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller)
|
||||
:m_volData(volData)
|
||||
,m_sampVolume(volData)
|
||||
,m_meshCurrent(result)
|
||||
@ -457,9 +457,9 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
// Allow the controller to decide how the material should be derived from the voxels.
|
||||
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v100, fInterp);
|
||||
const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v100, fInterp);
|
||||
|
||||
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||
const PositionMaterialNormal<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
|
||||
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
||||
|
||||
@ -486,10 +486,10 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
// Allow the controller to decide how the material should be derived from the voxels.
|
||||
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v010, fInterp);
|
||||
const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v010, fInterp);
|
||||
|
||||
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
PositionMaterialNormal<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
|
||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
||||
|
||||
m_sampVolume.moveNegativeY();
|
||||
@ -514,9 +514,9 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
// Allow the controller to decide how the material should be derived from the voxels.
|
||||
const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(v000, v001, fInterp);
|
||||
const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v001, fInterp);
|
||||
|
||||
const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||
const PositionMaterialNormal<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
|
||||
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
||||
|
||||
|
@ -73,11 +73,11 @@ namespace PolyVox
|
||||
class DefaultIsQuadNeeded< Material<Type> >
|
||||
{
|
||||
public:
|
||||
bool operator()(Material<Type> back, Material<Type> front, uint32_t& materialToUse)
|
||||
bool operator()(Material<Type> back, Material<Type> front, Material<Type>& materialToUse)
|
||||
{
|
||||
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
|
||||
{
|
||||
materialToUse = static_cast<uint32_t>(back.getMaterial());
|
||||
materialToUse = back;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -90,11 +90,11 @@ namespace PolyVox
|
||||
class DefaultIsQuadNeeded< MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> >
|
||||
{
|
||||
public:
|
||||
bool operator()(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> back, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> front, uint32_t& materialToUse)
|
||||
bool operator()(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> back, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> front, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& materialToUse)
|
||||
{
|
||||
if((back.getMaterial() > 0) && (front.getMaterial() == 0))
|
||||
{
|
||||
materialToUse = static_cast<uint32_t>(back.getMaterial());
|
||||
materialToUse = back;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -132,15 +132,15 @@ namespace PolyVox
|
||||
return voxel.getMaterial();
|
||||
}
|
||||
|
||||
MaterialType blendMaterials(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> a, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> b, float /*weight*/)
|
||||
MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> blendMaterials(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> a, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> b, float /*weight*/)
|
||||
{
|
||||
if(convertToDensity(a) > convertToDensity(b))
|
||||
{
|
||||
return convertToMaterial(a);
|
||||
return a;
|
||||
}
|
||||
else
|
||||
{
|
||||
return convertToMaterial(b);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ namespace PolyVox
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// PositionMaterialNormal
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
class PositionMaterialNormal;
|
||||
template<typename MaterialType> class PositionMaterialNormal;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// RawVolume
|
||||
|
@ -33,31 +33,110 @@ freely, subject to the following restrictions:
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
#ifdef SWIG
|
||||
class PositionMaterial
|
||||
#else
|
||||
template<typename MaterialType>
|
||||
class POLYVOX_API PositionMaterial
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
PositionMaterial()
|
||||
{
|
||||
}
|
||||
|
||||
PositionMaterial(Vector3DFloat positionToSet, MaterialType materialToSet)
|
||||
:position(positionToSet)
|
||||
,material(materialToSet)
|
||||
{
|
||||
}
|
||||
|
||||
MaterialType getMaterial(void) const
|
||||
{
|
||||
return material;
|
||||
}
|
||||
|
||||
const Vector3DFloat& getPosition(void) const
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
void setMaterial(MaterialType materialToSet)
|
||||
{
|
||||
material = materialToSet;
|
||||
}
|
||||
|
||||
void setPosition(const Vector3DFloat& positionToSet)
|
||||
{
|
||||
position = positionToSet;
|
||||
}
|
||||
public:
|
||||
//Nicely fits into four floats.
|
||||
Vector3DFloat position;
|
||||
MaterialType material;
|
||||
};
|
||||
|
||||
#ifdef SWIG
|
||||
class PositionMaterialNormal
|
||||
#else
|
||||
template<typename MaterialType>
|
||||
class POLYVOX_API PositionMaterialNormal
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
PositionMaterialNormal();
|
||||
PositionMaterialNormal(Vector3DFloat positionToSet, float materialToSet);
|
||||
PositionMaterialNormal(Vector3DFloat positionToSet, Vector3DFloat normalToSet, float materialToSet);
|
||||
PositionMaterialNormal()
|
||||
{
|
||||
}
|
||||
|
||||
float getMaterial(void) const;
|
||||
const Vector3DFloat& getNormal(void) const;
|
||||
const Vector3DFloat& getPosition(void) const;
|
||||
PositionMaterialNormal(Vector3DFloat positionToSet, MaterialType materialToSet)
|
||||
:position(positionToSet)
|
||||
,material(materialToSet)
|
||||
{
|
||||
}
|
||||
|
||||
void setMaterial(float materialToSet);
|
||||
void setNormal(const Vector3DFloat& normalToSet);
|
||||
void setPosition(const Vector3DFloat& positionToSet);
|
||||
PositionMaterialNormal(Vector3DFloat positionToSet, Vector3DFloat normalToSet, MaterialType materialToSet)
|
||||
:position(positionToSet)
|
||||
,normal(normalToSet)
|
||||
,material(materialToSet)
|
||||
{
|
||||
}
|
||||
|
||||
MaterialType getMaterial(void) const
|
||||
{
|
||||
return material;
|
||||
}
|
||||
|
||||
const Vector3DFloat& getNormal(void) const
|
||||
{
|
||||
return normal;
|
||||
}
|
||||
|
||||
const Vector3DFloat& getPosition(void) const
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
void setMaterial(MaterialType materialToSet)
|
||||
{
|
||||
material = materialToSet;
|
||||
}
|
||||
|
||||
void setNormal(const Vector3DFloat& normalToSet)
|
||||
{
|
||||
normal = normalToSet;
|
||||
}
|
||||
|
||||
void setPosition(const Vector3DFloat& positionToSet)
|
||||
{
|
||||
position = positionToSet;
|
||||
}
|
||||
|
||||
public:
|
||||
//Nicely fits into seven floats, meaning we
|
||||
//can squeeze in one more for material blending.
|
||||
Vector3DFloat position;
|
||||
Vector3DFloat normal;
|
||||
float material; //FIXME: This shouldn't be float on CPU?
|
||||
MaterialType material; //FIXME: This shouldn't be float on CPU?
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,75 +0,0 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PolyVoxCore/VertexTypes.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
PositionMaterialNormal::PositionMaterialNormal()
|
||||
{
|
||||
}
|
||||
|
||||
PositionMaterialNormal::PositionMaterialNormal(Vector3DFloat positionToSet, float materialToSet)
|
||||
:position(positionToSet)
|
||||
,material(materialToSet)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PositionMaterialNormal::PositionMaterialNormal(Vector3DFloat positionToSet, Vector3DFloat normalToSet, float materialToSet)
|
||||
:position(positionToSet)
|
||||
,normal(normalToSet)
|
||||
,material(materialToSet)
|
||||
{
|
||||
}
|
||||
|
||||
float PositionMaterialNormal::getMaterial(void) const
|
||||
{
|
||||
return material;
|
||||
}
|
||||
|
||||
const Vector3DFloat& PositionMaterialNormal::getNormal(void) const
|
||||
{
|
||||
return normal;
|
||||
}
|
||||
|
||||
const Vector3DFloat& PositionMaterialNormal::getPosition(void) const
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
void PositionMaterialNormal::setMaterial(float materialToSet)
|
||||
{
|
||||
material = materialToSet;
|
||||
}
|
||||
|
||||
void PositionMaterialNormal::setNormal(const Vector3DFloat& normalToSet)
|
||||
{
|
||||
normal = normalToSet;
|
||||
}
|
||||
|
||||
void PositionMaterialNormal::setPosition(const Vector3DFloat& positionToSet)
|
||||
{
|
||||
position = positionToSet;
|
||||
}
|
||||
}
|
@ -106,7 +106,7 @@ uint32_t testForType(void)
|
||||
{
|
||||
for (int32_t x = 0; x < uVolumeSideLength; x += uRegionSideLength)
|
||||
{
|
||||
SurfaceMesh<PositionMaterialNormal> result;
|
||||
SurfaceMesh<PositionMaterialNormal<VoxelType> > result;
|
||||
Region regionToExtract(x, y, z, x + uRegionSideLength - 1, y + uRegionSideLength - 1, z + uRegionSideLength - 1);
|
||||
CubicSurfaceExtractor< SimpleVolume<VoxelType> > extractor(&volData, regionToExtract, &result);
|
||||
extractor.execute();
|
||||
|
@ -102,7 +102,7 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel)
|
||||
|
||||
// Runs the surface extractor for a given type.
|
||||
template <typename VoxelType>
|
||||
void testForType(SurfaceMesh<PositionMaterialNormal>& result)
|
||||
void testForType(SurfaceMesh<PositionMaterialNormal<VoxelType> >& result)
|
||||
{
|
||||
const int32_t uVolumeSideLength = 32;
|
||||
|
||||
@ -131,7 +131,7 @@ void testForType(SurfaceMesh<PositionMaterialNormal>& result)
|
||||
extractor.execute();
|
||||
}
|
||||
|
||||
void testCustomController(SurfaceMesh<PositionMaterialNormal>& result)
|
||||
void testCustomController(SurfaceMesh<PositionMaterialNormal<float> >& result)
|
||||
{
|
||||
const int32_t uVolumeSideLength = 32;
|
||||
|
||||
@ -163,66 +163,74 @@ void TestSurfaceExtractor::testExecute()
|
||||
const static float fExpectedMaterial = 42.0f;
|
||||
const static float fNoMaterial = 1.0f;
|
||||
|
||||
SurfaceMesh<PositionMaterialNormal> mesh;
|
||||
|
||||
SurfaceMesh<PositionMaterialNormal<int8_t> > int8Mesh;
|
||||
//Run the test for various voxel types.
|
||||
QBENCHMARK {
|
||||
testForType<int8_t>(mesh);
|
||||
testForType<int8_t>(int8Mesh);
|
||||
}
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
QCOMPARE(int8Mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(int8Mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(int8Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<int8_t>(fNoMaterial));
|
||||
|
||||
testForType<uint8_t>(mesh);
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
SurfaceMesh<PositionMaterialNormal<uint8_t> > uint8Mesh;
|
||||
testForType<uint8_t>(uint8Mesh);
|
||||
QCOMPARE(uint8Mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(uint8Mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(uint8Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint8_t>(fNoMaterial));
|
||||
|
||||
testForType<int16_t>(mesh);
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
SurfaceMesh<PositionMaterialNormal<int16_t> > int16Mesh;
|
||||
testForType<int16_t>(int16Mesh);
|
||||
QCOMPARE(int16Mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(int16Mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(int16Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<int16_t>(fNoMaterial));
|
||||
|
||||
testForType<uint16_t>(mesh);
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
SurfaceMesh<PositionMaterialNormal<uint16_t> > uint16Mesh;
|
||||
testForType<uint16_t>(uint16Mesh);
|
||||
QCOMPARE(uint16Mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(uint16Mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(uint16Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint16_t>(fNoMaterial));
|
||||
|
||||
testForType<int32_t>(mesh);
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
SurfaceMesh<PositionMaterialNormal<int32_t> > int32Mesh;
|
||||
testForType<int32_t>(int32Mesh);
|
||||
QCOMPARE(int32Mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(int32Mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(int32Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<int32_t>(fNoMaterial));
|
||||
|
||||
testForType<uint32_t>(mesh);
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
SurfaceMesh<PositionMaterialNormal<uint32_t> > uint32Mesh;
|
||||
testForType<uint32_t>(uint32Mesh);
|
||||
QCOMPARE(uint32Mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(uint32Mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(uint32Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint32_t>(fNoMaterial));
|
||||
|
||||
testForType<float>(mesh);
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
SurfaceMesh<PositionMaterialNormal<float> > floatMesh;
|
||||
testForType<float>(floatMesh);
|
||||
QCOMPARE(floatMesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(floatMesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(floatMesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
|
||||
testForType<double>(mesh);
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
SurfaceMesh<PositionMaterialNormal<double> > doubleMesh;
|
||||
testForType<double>(doubleMesh);
|
||||
QCOMPARE(doubleMesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(doubleMesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(doubleMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<double>(fNoMaterial));
|
||||
|
||||
testForType<Density8>(mesh);
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
SurfaceMesh<PositionMaterialNormal<Density8> > densityMesh;
|
||||
testForType<Density8>(densityMesh);
|
||||
QCOMPARE(densityMesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(densityMesh.getNoOfIndices(), uExpectedIndices);
|
||||
//QCOMPARE(densityMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint8_t>(fNoMaterial));
|
||||
|
||||
testForType<MaterialDensityPair88>(mesh);
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fExpectedMaterial);
|
||||
SurfaceMesh<PositionMaterialNormal<MaterialDensityPair88> > materialDensityMesh;
|
||||
testForType<MaterialDensityPair88>(materialDensityMesh);
|
||||
QCOMPARE(materialDensityMesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(materialDensityMesh.getNoOfIndices(), uExpectedIndices);
|
||||
//QCOMPARE(materialDensityMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint8_t>(fNoMaterial));
|
||||
|
||||
//Test whether the CustomSurfaceExtractor works.
|
||||
testCustomController(mesh);
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
testCustomController(floatMesh);
|
||||
QCOMPARE(floatMesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(floatMesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(floatMesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestSurfaceExtractor)
|
||||
|
@ -184,7 +184,7 @@ void TestVolumeSubclass::testExtractSurface()
|
||||
}
|
||||
}
|
||||
|
||||
SurfaceMesh<PositionMaterialNormal> result;
|
||||
SurfaceMesh<PositionMaterialNormal<Material8> > result;
|
||||
CubicSurfaceExtractor< VolumeSubclass<Material8> > cubicSurfaceExtractor(&volumeSubclass, volumeSubclass.getEnclosingRegion(), &result);
|
||||
cubicSurfaceExtractor.execute();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user