Renamed SurfaceMesh to just Mesh
This commit is contained in:
parent
da8f294847
commit
4aae00e4a8
@ -15,7 +15,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<CubicVertex<uint8_t> >& surfaceMesh)
|
void OpenGLWidget::setMeshToRender(const PolyVox::Mesh<CubicVertex<uint8_t> >& surfaceMesh)
|
||||||
{
|
{
|
||||||
//Convienient access to the vertices and indices
|
//Convienient access to the vertices and indices
|
||||||
const auto& vecIndices = surfaceMesh.getIndices();
|
const auto& vecIndices = surfaceMesh.getIndices();
|
||||||
|
@ -24,7 +24,7 @@ distribution.
|
|||||||
#ifndef __BasicExample_OpenGLWidget_H__
|
#ifndef __BasicExample_OpenGLWidget_H__
|
||||||
#define __BasicExample_OpenGLWidget_H__
|
#define __BasicExample_OpenGLWidget_H__
|
||||||
|
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
|
|
||||||
#include "glew/glew.h"
|
#include "glew/glew.h"
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ public:
|
|||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
|
||||||
// Convert a SurfaceMesh to OpenGL index/vertex buffers
|
// Convert a SurfaceMesh to OpenGL index/vertex buffers
|
||||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::CubicVertex<uint8_t> >& surfaceMesh);
|
void setMeshToRender(const PolyVox::Mesh<PolyVox::CubicVertex<uint8_t> >& surfaceMesh);
|
||||||
|
|
||||||
// The viewable region can be adjusted so that this example framework can be use for different volume sizes.
|
// The viewable region can be adjusted so that this example framework can be use for different volume sizes.
|
||||||
void setViewableRegion(PolyVox::Region viewableRegion);
|
void setViewableRegion(PolyVox::Region viewableRegion);
|
||||||
|
@ -25,7 +25,7 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
#include "PolyVoxCore/CubicSurfaceExtractor.h"
|
#include "PolyVoxCore/CubicSurfaceExtractor.h"
|
||||||
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
|
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
#include "PolyVoxCore/SimpleVolume.h"
|
#include "PolyVoxCore/SimpleVolume.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@ -85,9 +85,9 @@ int main(int argc, char *argv[])
|
|||||||
//auto mesh2 = extractCubicMesh(&volData, PolyVox::Region(Vector3DInt32(32, 32, 32), Vector3DInt32(63, 63, 63)));
|
//auto mesh2 = extractCubicMesh(&volData, PolyVox::Region(Vector3DInt32(32, 32, 32), Vector3DInt32(63, 63, 63)));
|
||||||
|
|
||||||
//Pass the surface to the OpenGL window
|
//Pass the surface to the OpenGL window
|
||||||
openGLWidget.setSurfaceMeshToRender(mesh);
|
openGLWidget.setMeshToRender(mesh);
|
||||||
openGLWidget.setViewableRegion(volData.getEnclosingRegion());
|
openGLWidget.setViewableRegion(volData.getEnclosingRegion());
|
||||||
//openGLWidget.setSurfaceMeshToRender(mesh2);
|
//openGLWidget.setMeshToRender(mesh2);
|
||||||
|
|
||||||
//Run the message pump.
|
//Run the message pump.
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
@ -24,12 +24,12 @@ freely, subject to the following restrictions:
|
|||||||
#include "OpenGLImmediateModeSupport.h"
|
#include "OpenGLImmediateModeSupport.h"
|
||||||
#include "OpenGLSupport.h"
|
#include "OpenGLSupport.h"
|
||||||
|
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
|
|
||||||
using namespace PolyVox;
|
using namespace PolyVox;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void renderRegionImmediateMode(PolyVox::SurfaceMesh<MarchingCubesVertex<MaterialDensityPair44> >& mesh, unsigned int uLodLevel)
|
void renderRegionImmediateMode(PolyVox::Mesh<MarchingCubesVertex<MaterialDensityPair44> >& mesh, unsigned int uLodLevel)
|
||||||
{
|
{
|
||||||
const vector<MarchingCubesVertex<MaterialDensityPair44> >& vecVertices = mesh.getVertices();
|
const vector<MarchingCubesVertex<MaterialDensityPair44> >& vecVertices = mesh.getVertices();
|
||||||
const vector<uint32_t>& vecIndices = mesh.getIndices();
|
const vector<uint32_t>& vecIndices = mesh.getIndices();
|
||||||
|
@ -29,6 +29,6 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
#include "glew/glew.h"
|
#include "glew/glew.h"
|
||||||
|
|
||||||
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> >& mesh, unsigned int uLodLevel);
|
void renderRegionImmediateMode(PolyVox::Mesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> >& mesh, unsigned int uLodLevel);
|
||||||
|
|
||||||
#endif //__OpenGLExample_OpenGLImmediateModeSupport_H__
|
#endif //__OpenGLExample_OpenGLImmediateModeSupport_H__
|
||||||
|
@ -25,15 +25,15 @@ freely, subject to the following restrictions:
|
|||||||
#include "OpenGLVertexBufferObjectSupport.h"
|
#include "OpenGLVertexBufferObjectSupport.h"
|
||||||
|
|
||||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
|
|
||||||
using namespace PolyVox;
|
using namespace PolyVox;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<MarchingCubesVertex<MaterialDensityPair44> >& mesh)
|
OpenGLMesh BuildOpenGLMesh(const Mesh<MarchingCubesVertex<MaterialDensityPair44> >& mesh)
|
||||||
{
|
{
|
||||||
//Represents our filled in OpenGL vertex and index buffer objects.
|
//Represents our filled in OpenGL vertex and index buffer objects.
|
||||||
OpenGLSurfaceMesh result;
|
OpenGLMesh result;
|
||||||
|
|
||||||
//The source
|
//The source
|
||||||
result.sourceMesh = &mesh;
|
result.sourceMesh = &mesh;
|
||||||
@ -102,23 +102,23 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<MarchingCubesVertex<M
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel)
|
void renderRegionVertexBufferObject(const OpenGLMesh& openGLMesh, unsigned int uLodLevel)
|
||||||
{
|
{
|
||||||
int beginIndex = openGLSurfaceMesh.sourceMesh->m_vecLodRecords[uLodLevel].beginIndex;
|
int beginIndex = openGLMesh.sourceMesh->m_vecLodRecords[uLodLevel].beginIndex;
|
||||||
int endIndex = openGLSurfaceMesh.sourceMesh->m_vecLodRecords[uLodLevel].endIndex;
|
int endIndex = openGLMesh.sourceMesh->m_vecLodRecords[uLodLevel].endIndex;
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, openGLSurfaceMesh.vertexBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, openGLMesh.vertexBuffer);
|
||||||
glVertexPointer(3, GL_FLOAT, 36, 0);
|
glVertexPointer(3, GL_FLOAT, 36, 0);
|
||||||
glNormalPointer(GL_FLOAT, 36, (GLvoid*)12);
|
glNormalPointer(GL_FLOAT, 36, (GLvoid*)12);
|
||||||
glColorPointer(3, GL_FLOAT, 36, (GLvoid*)24);
|
glColorPointer(3, GL_FLOAT, 36, (GLvoid*)24);
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, openGLSurfaceMesh.indexBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, openGLMesh.indexBuffer);
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_NORMAL_ARRAY);
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
//glDrawElements(GL_TRIANGLES, openGLSurfaceMesh.noOfIndices, GL_UNSIGNED_INT, 0);
|
//glDrawElements(GL_TRIANGLES, openGLMesh.noOfIndices, GL_UNSIGNED_INT, 0);
|
||||||
glDrawRangeElements(GL_TRIANGLES, beginIndex, endIndex-1, endIndex - beginIndex,/* openGLSurfaceMesh.noOfIndices,*/ GL_UNSIGNED_INT, 0);
|
glDrawRangeElements(GL_TRIANGLES, beginIndex, endIndex-1, endIndex - beginIndex,/* openGLMesh.noOfIndices,*/ GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
|
@ -28,15 +28,15 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
#include "glew/glew.h"
|
#include "glew/glew.h"
|
||||||
|
|
||||||
struct OpenGLSurfaceMesh
|
struct OpenGLMesh
|
||||||
{
|
{
|
||||||
GLulong noOfIndices;
|
GLulong noOfIndices;
|
||||||
GLuint indexBuffer;
|
GLuint indexBuffer;
|
||||||
GLuint vertexBuffer;
|
GLuint vertexBuffer;
|
||||||
const PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> >* sourceMesh;
|
const PolyVox::Mesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> >* sourceMesh;
|
||||||
};
|
};
|
||||||
|
|
||||||
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> >& mesh);
|
OpenGLMesh BuildOpenGLMesh(const PolyVox::Mesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> >& mesh);
|
||||||
void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel);
|
void renderRegionVertexBufferObject(const OpenGLMesh& openGLMesh, unsigned int uLodLevel);
|
||||||
|
|
||||||
#endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__
|
#endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__
|
||||||
|
@ -50,8 +50,8 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
|
|||||||
void OpenGLWidget::setVolume(PolyVox::LargeVolume<MaterialDensityPair44>* volData)
|
void OpenGLWidget::setVolume(PolyVox::LargeVolume<MaterialDensityPair44>* volData)
|
||||||
{
|
{
|
||||||
//First we free anything from the previous volume (if there was one).
|
//First we free anything from the previous volume (if there was one).
|
||||||
m_mapOpenGLSurfaceMeshes.clear();
|
m_mapOpenGLMeshes.clear();
|
||||||
m_mapSurfaceMeshes.clear();
|
m_mapMeshes.clear();
|
||||||
m_volData = volData;
|
m_volData = volData;
|
||||||
|
|
||||||
//If we have any volume data then generate the new surface patches.
|
//If we have any volume data then generate the new surface patches.
|
||||||
@ -87,7 +87,7 @@ void OpenGLWidget::setVolume(PolyVox::LargeVolume<MaterialDensityPair44>* volDat
|
|||||||
//Extract the surface for this region
|
//Extract the surface for this region
|
||||||
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
|
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
|
||||||
|
|
||||||
std::shared_ptr< SurfaceMesh<MarchingCubesVertex<MaterialDensityPair44> > > mesh(new SurfaceMesh<MarchingCubesVertex<MaterialDensityPair44> >);
|
std::shared_ptr< Mesh<MarchingCubesVertex<MaterialDensityPair44> > > mesh(new Mesh<MarchingCubesVertex<MaterialDensityPair44> >);
|
||||||
MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get());
|
MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get());
|
||||||
surfaceExtractor.execute();
|
surfaceExtractor.execute();
|
||||||
|
|
||||||
@ -105,12 +105,12 @@ void OpenGLWidget::setVolume(PolyVox::LargeVolume<MaterialDensityPair44>* volDat
|
|||||||
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
|
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
|
||||||
if(m_bUseOpenGLVertexBufferObjects)
|
if(m_bUseOpenGLVertexBufferObjects)
|
||||||
{
|
{
|
||||||
OpenGLSurfaceMesh openGLSurfaceMesh = BuildOpenGLSurfaceMesh(*(mesh.get()));
|
OpenGLMesh openGLMesh = BuildOpenGLMesh(*(mesh.get()));
|
||||||
m_mapOpenGLSurfaceMeshes.insert(make_pair(v3dRegPos, openGLSurfaceMesh));
|
m_mapOpenGLMeshes.insert(make_pair(v3dRegPos, openGLMesh));
|
||||||
}
|
}
|
||||||
//else
|
//else
|
||||||
//{
|
//{
|
||||||
m_mapSurfaceMeshes.insert(make_pair(v3dRegPos, mesh));
|
m_mapMeshes.insert(make_pair(v3dRegPos, mesh));
|
||||||
//}
|
//}
|
||||||
//delete meshCurrent;
|
//delete meshCurrent;
|
||||||
}
|
}
|
||||||
@ -191,13 +191,13 @@ void OpenGLWidget::paintGL()
|
|||||||
for(uint16_t uRegionX = 0; uRegionX < m_uVolumeWidthInRegions; ++uRegionX)
|
for(uint16_t uRegionX = 0; uRegionX < m_uVolumeWidthInRegions; ++uRegionX)
|
||||||
{
|
{
|
||||||
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
|
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
|
||||||
if(m_mapSurfaceMeshes.find(v3dRegPos) != m_mapSurfaceMeshes.end())
|
if(m_mapMeshes.find(v3dRegPos) != m_mapMeshes.end())
|
||||||
{
|
{
|
||||||
std::shared_ptr< SurfaceMesh<MarchingCubesVertex<MaterialDensityPair44> > > meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
|
std::shared_ptr< Mesh<MarchingCubesVertex<MaterialDensityPair44> > > meshCurrent = m_mapMeshes[v3dRegPos];
|
||||||
unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1;
|
unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1;
|
||||||
if(m_bUseOpenGLVertexBufferObjects)
|
if(m_bUseOpenGLVertexBufferObjects)
|
||||||
{
|
{
|
||||||
renderRegionVertexBufferObject(m_mapOpenGLSurfaceMeshes[v3dRegPos], uLodLevel);
|
renderRegionVertexBufferObject(m_mapOpenGLMeshes[v3dRegPos], uLodLevel);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@ freely, subject to the following restrictions:
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include "PolyVoxCore/LargeVolume.h"
|
#include "PolyVoxCore/LargeVolume.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
#include "PolyVoxCore/Impl/Utility.h"
|
#include "PolyVoxCore/Impl/Utility.h"
|
||||||
|
|
||||||
#include "OpenGLImmediateModeSupport.h"
|
#include "OpenGLImmediateModeSupport.h"
|
||||||
@ -87,8 +87,8 @@ class OpenGLWidget : public QGLWidget
|
|||||||
PolyVox::LargeVolume<PolyVox::MaterialDensityPair44>* m_volData;
|
PolyVox::LargeVolume<PolyVox::MaterialDensityPair44>* m_volData;
|
||||||
|
|
||||||
//Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
|
//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, OpenGLMesh, Vector3DUint8Compare> m_mapOpenGLMeshes;
|
||||||
std::map<PolyVox::Vector3DUint8, std::shared_ptr<PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> > >, Vector3DUint8Compare> m_mapSurfaceMeshes;
|
std::map<PolyVox::Vector3DUint8, std::shared_ptr<PolyVox::Mesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> > >, Vector3DUint8Compare> m_mapMeshes;
|
||||||
|
|
||||||
unsigned int m_uRegionSideLength;
|
unsigned int m_uRegionSideLength;
|
||||||
unsigned int m_uVolumeWidthInRegions;
|
unsigned int m_uVolumeWidthInRegions;
|
||||||
|
@ -27,7 +27,7 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxCore/LowPassFilter.h"
|
#include "PolyVoxCore/LowPassFilter.h"
|
||||||
#include "PolyVoxCore/RawVolume.h"
|
#include "PolyVoxCore/RawVolume.h"
|
||||||
#include "PolyVoxCore/RLEBlockCompressor.h"
|
#include "PolyVoxCore/RLEBlockCompressor.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
#include "PolyVoxCore/Impl/Utility.h"
|
#include "PolyVoxCore/Impl/Utility.h"
|
||||||
|
|
||||||
#include "OpenGLImmediateModeSupport.h"
|
#include "OpenGLImmediateModeSupport.h"
|
||||||
|
@ -15,7 +15,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<CubicVertex<MaterialDensityPair44> >& surfaceMesh)
|
void OpenGLWidget::setMeshToRender(const PolyVox::Mesh<CubicVertex<MaterialDensityPair44> >& surfaceMesh)
|
||||||
{
|
{
|
||||||
if((surfaceMesh.getNoOfIndices() == 0) || (surfaceMesh.getNoOfVertices() == 0))
|
if((surfaceMesh.getNoOfIndices() == 0) || (surfaceMesh.getNoOfVertices() == 0))
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ distribution.
|
|||||||
#define __BasicExample_OpenGLWidget_H__
|
#define __BasicExample_OpenGLWidget_H__
|
||||||
|
|
||||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
|
|
||||||
#include "glew/glew.h"
|
#include "glew/glew.h"
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public:
|
|||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
|
||||||
//Convert a SrfaceMesh to OpenGL index/vertex buffers
|
//Convert a SrfaceMesh to OpenGL index/vertex buffers
|
||||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::CubicVertex<PolyVox::MaterialDensityPair44> >& surfaceMesh);
|
void setMeshToRender(const PolyVox::Mesh<PolyVox::CubicVertex<PolyVox::MaterialDensityPair44> >& surfaceMesh);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//Qt OpenGL functions
|
//Qt OpenGL functions
|
||||||
|
@ -29,7 +29,7 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
|
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
|
||||||
#include "PolyVoxCore/Pager.h"
|
#include "PolyVoxCore/Pager.h"
|
||||||
#include "PolyVoxCore/RLEBlockCompressor.h"
|
#include "PolyVoxCore/RLEBlockCompressor.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
#include "PolyVoxCore/LargeVolume.h"
|
#include "PolyVoxCore/LargeVolume.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@ -185,12 +185,12 @@ int main(int argc, char *argv[])
|
|||||||
std::cout << "Memory usage: " << (volData.calculateSizeInBytes()/1024.0/1024.0) << "MB" << std::endl;
|
std::cout << "Memory usage: " << (volData.calculateSizeInBytes()/1024.0/1024.0) << "MB" << std::endl;
|
||||||
std::cout << "Compression ratio: 1 to " << (1.0/(volData.calculateCompressionRatio())) << std::endl;
|
std::cout << "Compression ratio: 1 to " << (1.0/(volData.calculateCompressionRatio())) << std::endl;
|
||||||
|
|
||||||
//Extract the surface
|
//Extract the surface
|
||||||
auto mesh = extractCubicMesh(&volData, reg);
|
auto mesh = extractCubicMesh(&volData, reg);
|
||||||
std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl;
|
std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl;
|
||||||
|
|
||||||
//Pass the surface to the OpenGL window
|
//Pass the surface to the OpenGL window
|
||||||
openGLWidget.setSurfaceMeshToRender(mesh);
|
openGLWidget.setMeshToRender(mesh);
|
||||||
|
|
||||||
//Run the message pump.
|
//Run the message pump.
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
@ -21,7 +21,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<MarchingCubesVertex<uint8_t> >& surfaceMesh)
|
void OpenGLWidget::setMeshToRender(const PolyVox::Mesh<MarchingCubesVertex<uint8_t> >& surfaceMesh)
|
||||||
{
|
{
|
||||||
//Convienient access to the vertices and indices
|
//Convienient access to the vertices and indices
|
||||||
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
|
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
|
||||||
@ -43,7 +43,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<MarchingCub
|
|||||||
m_uEndIndex = vecIndices.size();
|
m_uEndIndex = vecIndices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<MarchingCubesVertex<uint8_t> >& surfaceMesh)
|
void OpenGLWidget::setMeshToRenderLowLOD(const PolyVox::Mesh<MarchingCubesVertex<uint8_t> >& surfaceMesh)
|
||||||
{
|
{
|
||||||
//Convienient access to the vertices and indices
|
//Convienient access to the vertices and indices
|
||||||
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
|
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
|
||||||
|
@ -24,7 +24,7 @@ distribution.
|
|||||||
#ifndef __BasicExample_OpenGLWidget_H__
|
#ifndef __BasicExample_OpenGLWidget_H__
|
||||||
#define __BasicExample_OpenGLWidget_H__
|
#define __BasicExample_OpenGLWidget_H__
|
||||||
|
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
|
|
||||||
#include "glew/glew.h"
|
#include "glew/glew.h"
|
||||||
|
|
||||||
@ -41,8 +41,8 @@ public:
|
|||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
|
||||||
//Convert a SrfaceMesh to OpenGL index/vertex buffers
|
//Convert a SrfaceMesh to OpenGL index/vertex buffers
|
||||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex <uint8_t> >& surfaceMesh);
|
void setMeshToRender(const PolyVox::Mesh<PolyVox::MarchingCubesVertex <uint8_t> >& surfaceMesh);
|
||||||
void setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex<uint8_t> >& surfaceMesh);
|
void setMeshToRenderLowLOD(const PolyVox::Mesh<PolyVox::MarchingCubesVertex<uint8_t> >& surfaceMesh);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//Qt OpenGL functions
|
//Qt OpenGL functions
|
||||||
|
@ -25,7 +25,7 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
#include "PolyVoxCore/Density.h"
|
#include "PolyVoxCore/Density.h"
|
||||||
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
|
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
#include "PolyVoxCore/RawVolume.h"
|
#include "PolyVoxCore/RawVolume.h"
|
||||||
#include "PolyVoxCore/SimpleVolume.h"
|
#include "PolyVoxCore/SimpleVolume.h"
|
||||||
#include "PolyVoxCore/VolumeResampler.h"
|
#include "PolyVoxCore/VolumeResampler.h"
|
||||||
@ -89,17 +89,17 @@ int main(int argc, char *argv[])
|
|||||||
VolumeResampler< SimpleVolume<uint8_t>, RawVolume<uint8_t> > volumeResampler(&volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 63, 63)), &volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
VolumeResampler< SimpleVolume<uint8_t>, RawVolume<uint8_t> > volumeResampler(&volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 63, 63)), &volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
||||||
volumeResampler.execute();
|
volumeResampler.execute();
|
||||||
|
|
||||||
//Extract the surface
|
//Extract the surface
|
||||||
auto meshLowLOD = extractMarchingCubesMesh(&volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
auto meshLowLOD = extractMarchingCubesMesh(&volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
||||||
meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f);
|
meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f);
|
||||||
|
|
||||||
//Extract the surface
|
//Extract the surface
|
||||||
auto meshHighLOD = extractMarchingCubesMesh(&volData, PolyVox::Region(Vector3DInt32(30, 0, 0), Vector3DInt32(63, 63, 63)));
|
auto meshHighLOD = extractMarchingCubesMesh(&volData, PolyVox::Region(Vector3DInt32(30, 0, 0), Vector3DInt32(63, 63, 63)));
|
||||||
meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0));
|
meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0));
|
||||||
|
|
||||||
//Pass the surface to the OpenGL window
|
//Pass the surface to the OpenGL window
|
||||||
openGLWidget.setSurfaceMeshToRender(meshHighLOD);
|
openGLWidget.setMeshToRender(meshHighLOD);
|
||||||
openGLWidget.setSurfaceMeshToRenderLowLOD(meshLowLOD);
|
openGLWidget.setMeshToRenderLowLOD(meshLowLOD);
|
||||||
|
|
||||||
//Run the message pump.
|
//Run the message pump.
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
@ -84,8 +84,8 @@ SET(CORE_INC_FILES
|
|||||||
include/PolyVoxCore/SimpleVolume.inl
|
include/PolyVoxCore/SimpleVolume.inl
|
||||||
include/PolyVoxCore/SimpleVolumeBlock.inl
|
include/PolyVoxCore/SimpleVolumeBlock.inl
|
||||||
include/PolyVoxCore/SimpleVolumeSampler.inl
|
include/PolyVoxCore/SimpleVolumeSampler.inl
|
||||||
include/PolyVoxCore/SurfaceMesh.h
|
include/PolyVoxCore/Mesh.h
|
||||||
include/PolyVoxCore/SurfaceMesh.inl
|
include/PolyVoxCore/Mesh.inl
|
||||||
include/PolyVoxCore/UncompressedBlock.h
|
include/PolyVoxCore/UncompressedBlock.h
|
||||||
include/PolyVoxCore/UncompressedBlock.inl
|
include/PolyVoxCore/UncompressedBlock.inl
|
||||||
include/PolyVoxCore/Vector.h
|
include/PolyVoxCore/Vector.h
|
||||||
|
@ -31,7 +31,7 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxCore/Array.h"
|
#include "PolyVoxCore/Array.h"
|
||||||
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
|
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
|
||||||
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
|
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
@ -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
|
// 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?
|
// 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)
|
#if defined(_MSC_VER)
|
||||||
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
CubicSurfaceExtractor(VolumeType* volData, Region region, Mesh<CubicVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||||
#else
|
#else
|
||||||
CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
CubicSurfaceExtractor(VolumeType* volData, Region region, Mesh<CubicVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ namespace PolyVox
|
|||||||
Region m_regSizeInVoxels;
|
Region m_regSizeInVoxels;
|
||||||
|
|
||||||
//The surface patch we are currently filling.
|
//The surface patch we are currently filling.
|
||||||
SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> >* m_meshCurrent;
|
Mesh<CubicVertex<typename VolumeType::VoxelType> >* m_meshCurrent;
|
||||||
|
|
||||||
//Used to avoid creating duplicate vertices.
|
//Used to avoid creating duplicate vertices.
|
||||||
Array<3, IndexAndMaterial> m_previousSliceVertices;
|
Array<3, IndexAndMaterial> m_previousSliceVertices;
|
||||||
@ -159,9 +159,9 @@ namespace PolyVox
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
Mesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||||
{
|
{
|
||||||
SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> > result;
|
Mesh<CubicVertex<typename VolumeType::VoxelType> > result;
|
||||||
CubicSurfaceExtractor<VolumeType, IsQuadNeeded> extractor(volData, region, &result, eWrapMode, tBorderValue, bMergeQuads, isQuadNeeded);
|
CubicSurfaceExtractor<VolumeType, IsQuadNeeded> extractor(volData, region, &result, eWrapMode, tBorderValue, bMergeQuads, isQuadNeeded);
|
||||||
extractor.execute();
|
extractor.execute();
|
||||||
return result;
|
return result;
|
||||||
@ -171,9 +171,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
|
// 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?
|
// 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)
|
#if defined(_MSC_VER)
|
||||||
SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true)
|
Mesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true)
|
||||||
#else
|
#else
|
||||||
SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true)
|
Mesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
DefaultIsQuadNeeded<typename VolumeType::VoxelType> isQuadNeeded;
|
DefaultIsQuadNeeded<typename VolumeType::VoxelType> isQuadNeeded;
|
||||||
|
@ -36,7 +36,7 @@ namespace PolyVox
|
|||||||
const uint32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::MaxVerticesPerPosition = 8;
|
const uint32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::MaxVerticesPerPosition = 8;
|
||||||
|
|
||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, Mesh<CubicVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||||
:m_volData(volData)
|
:m_volData(volData)
|
||||||
,m_regSizeInVoxels(region)
|
,m_regSizeInVoxels(region)
|
||||||
,m_meshCurrent(result)
|
,m_meshCurrent(result)
|
||||||
|
@ -55,7 +55,7 @@ namespace PolyVox
|
|||||||
template<typename VolumeType>
|
template<typename VolumeType>
|
||||||
Vector3DFloat computeSmoothSobelGradient(typename VolumeType::Sampler& volIter);
|
Vector3DFloat computeSmoothSobelGradient(typename VolumeType::Sampler& volIter);
|
||||||
|
|
||||||
//POLYVOX_API void computeNormalsForVertices(VolumeType<uint8_t>* volumeData, SurfaceMesh<PositionMaterialNormal>& mesh, NormalGenerationMethod normalGenerationMethod);
|
//POLYVOX_API void computeNormalsForVertices(VolumeType<uint8_t>* volumeData, Mesh<PositionMaterialNormal>& mesh, NormalGenerationMethod normalGenerationMethod);
|
||||||
//POLYVOX_API Vector3DFloat computeNormal(VolumeType<uint8_t>* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod);
|
//POLYVOX_API Vector3DFloat computeNormal(VolumeType<uint8_t>* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
#include "PolyVoxCore/Array.h"
|
#include "PolyVoxCore/Array.h"
|
||||||
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
|
#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these?
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/Mesh.h"
|
||||||
#include "PolyVoxCore/DefaultMarchingCubesController.h"
|
#include "PolyVoxCore/DefaultMarchingCubesController.h"
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
@ -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
|
// 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?
|
// 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)
|
#if defined(_MSC_VER)
|
||||||
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), Controller controller = Controller());
|
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, Mesh<MarchingCubesVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), Controller controller = Controller());
|
||||||
#else
|
#else
|
||||||
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller());
|
MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, Mesh<MarchingCubesVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void execute();
|
void execute();
|
||||||
@ -193,7 +193,7 @@ namespace PolyVox
|
|||||||
uint32_t m_uNoOfOccupiedCells;
|
uint32_t m_uNoOfOccupiedCells;
|
||||||
|
|
||||||
//The surface patch we are currently filling.
|
//The surface patch we are currently filling.
|
||||||
SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> >* m_meshCurrent;
|
Mesh<MarchingCubesVertex<typename VolumeType::VoxelType> >* m_meshCurrent;
|
||||||
|
|
||||||
//Information about the region we are currently processing
|
//Information about the region we are currently processing
|
||||||
Region m_regSizeInVoxels;
|
Region m_regSizeInVoxels;
|
||||||
@ -212,9 +212,9 @@ namespace PolyVox
|
|||||||
};
|
};
|
||||||
|
|
||||||
template< typename VolumeType, typename Controller>
|
template< typename VolumeType, typename Controller>
|
||||||
SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller)
|
Mesh<MarchingCubesVertex<typename VolumeType::VoxelType> > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller)
|
||||||
{
|
{
|
||||||
SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> > result;
|
Mesh<MarchingCubesVertex<typename VolumeType::VoxelType> > result;
|
||||||
MarchingCubesSurfaceExtractor<VolumeType, Controller> extractor(volData, region, &result, eWrapMode, tBorderValue, controller);
|
MarchingCubesSurfaceExtractor<VolumeType, Controller> extractor(volData, region, &result, eWrapMode, tBorderValue, controller);
|
||||||
extractor.execute();
|
extractor.execute();
|
||||||
return result;
|
return result;
|
||||||
@ -224,9 +224,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
|
// 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?
|
// 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)
|
#if defined(_MSC_VER)
|
||||||
SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType())
|
Mesh<MarchingCubesVertex<typename VolumeType::VoxelType> > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType())
|
||||||
#else
|
#else
|
||||||
SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType())
|
Mesh<MarchingCubesVertex<typename VolumeType::VoxelType> > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType())
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
DefaultMarchingCubesController<typename VolumeType::VoxelType> controller;
|
DefaultMarchingCubesController<typename VolumeType::VoxelType> controller;
|
||||||
|
@ -25,8 +25,8 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
template<typename VolumeType, typename Controller>
|
template<typename VolumeType, typename Controller>
|
||||||
MarchingCubesSurfaceExtractor<VolumeType, Controller>::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller)
|
MarchingCubesSurfaceExtractor<VolumeType, Controller>::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, Mesh<MarchingCubesVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller)
|
||||||
:m_volData(volData)
|
:m_volData(volData)
|
||||||
,m_sampVolume(volData)
|
,m_sampVolume(volData)
|
||||||
,m_meshCurrent(result)
|
,m_meshCurrent(result)
|
||||||
@ -456,10 +456,10 @@ namespace PolyVox
|
|||||||
v3dNormal.normalise();
|
v3dNormal.normalise();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow the controller to decide how the material should be derived from the voxels.
|
// Allow the controller to decide how the material should be derived from the voxels.
|
||||||
const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v100, fInterp);
|
const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v100, fInterp);
|
||||||
|
|
||||||
const MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
|
const MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
|
||||||
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||||
m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
||||||
|
|
||||||
@ -485,11 +485,11 @@ namespace PolyVox
|
|||||||
v3dNormal.normalise();
|
v3dNormal.normalise();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow the controller to decide how the material should be derived from the voxels.
|
// Allow the controller to decide how the material should be derived from the voxels.
|
||||||
const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v010, fInterp);
|
const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v010, fInterp);
|
||||||
|
|
||||||
MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
|
MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
|
||||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||||
m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
||||||
|
|
||||||
m_sampVolume.moveNegativeY();
|
m_sampVolume.moveNegativeY();
|
||||||
@ -513,10 +513,10 @@ namespace PolyVox
|
|||||||
v3dNormal.normalise();
|
v3dNormal.normalise();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow the controller to decide how the material should be derived from the voxels.
|
// Allow the controller to decide how the material should be derived from the voxels.
|
||||||
const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v001, fInterp);
|
const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v001, fInterp);
|
||||||
|
|
||||||
const MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
|
const MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial);
|
||||||
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||||
m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex;
|
||||||
|
|
||||||
|
@ -1,104 +1,104 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
Copyright (c) 2005-2009 David Williams
|
Copyright (c) 2005-2009 David Williams
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
arising from the use of this software.
|
arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it
|
including commercial applications, and to alter it and redistribute it
|
||||||
freely, subject to the following restrictions:
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
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
|
claim that you wrote the original software. If you use this software
|
||||||
in a product, an acknowledgment in the product documentation would be
|
in a product, an acknowledgment in the product documentation would be
|
||||||
appreciated but is not required.
|
appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
misrepresented as being the original software.
|
misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#ifndef __PolyVox_SurfaceMesh_H__
|
#ifndef __PolyVox_Mesh_H__
|
||||||
#define __PolyVox_SurfaceMesh_H__
|
#define __PolyVox_Mesh_H__
|
||||||
|
|
||||||
#include "Impl/TypeDef.h"
|
#include "Impl/TypeDef.h"
|
||||||
|
|
||||||
#include "PolyVoxCore/Region.h"
|
#include "PolyVoxCore/Region.h"
|
||||||
#include "PolyVoxCore/VertexTypes.h" //Should probably do away with this on in the future...
|
#include "PolyVoxCore/VertexTypes.h" //Should probably do away with this on in the future...
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
class LodRecord
|
class LodRecord
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int beginIndex;
|
int beginIndex;
|
||||||
int endIndex; //Let's put it just past the end STL style
|
int endIndex; //Let's put it just past the end STL style
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
class SurfaceMesh
|
class Mesh
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SurfaceMesh();
|
Mesh();
|
||||||
~SurfaceMesh();
|
~Mesh();
|
||||||
|
|
||||||
const std::vector<uint32_t>& getIndices(void) const;
|
const std::vector<uint32_t>& getIndices(void) const;
|
||||||
uint32_t getNoOfIndices(void) const;
|
uint32_t getNoOfIndices(void) const;
|
||||||
uint32_t getNoOfNonUniformTrianges(void) const;
|
uint32_t getNoOfNonUniformTrianges(void) const;
|
||||||
uint32_t getNoOfUniformTrianges(void) const;
|
uint32_t getNoOfUniformTrianges(void) const;
|
||||||
uint32_t getNoOfVertices(void) const;
|
uint32_t getNoOfVertices(void) const;
|
||||||
std::vector<VertexType>& getRawVertexData(void); //FIXME - this should be removed
|
std::vector<VertexType>& getRawVertexData(void); //FIXME - this should be removed
|
||||||
const std::vector<VertexType>& getVertices(void) const;
|
const std::vector<VertexType>& getVertices(void) const;
|
||||||
|
|
||||||
void addTriangle(uint32_t index0, uint32_t index1, uint32_t index2);
|
void addTriangle(uint32_t index0, uint32_t index1, uint32_t index2);
|
||||||
void addTriangleCubic(uint32_t index0, uint32_t index1, uint32_t index2);
|
void addTriangleCubic(uint32_t index0, uint32_t index1, uint32_t index2);
|
||||||
uint32_t addVertex(const VertexType& vertex);
|
uint32_t addVertex(const VertexType& vertex);
|
||||||
void clear(void);
|
void clear(void);
|
||||||
bool isEmpty(void) const;
|
bool isEmpty(void) const;
|
||||||
|
|
||||||
void scaleVertices(float amount);
|
void scaleVertices(float amount);
|
||||||
void translateVertices(const Vector3DFloat& amount);
|
void translateVertices(const Vector3DFloat& amount);
|
||||||
|
|
||||||
//THESE FUNCTIONS TO BE REMOVED IN THE FUTURE. OR AT LEAST MOVED OUT OF THIS CLASS INTO FREE FUNCTIONS.
|
//THESE FUNCTIONS TO BE REMOVED IN THE FUTURE. OR AT LEAST MOVED OUT OF THIS CLASS INTO FREE FUNCTIONS.
|
||||||
//THEY ARE CAUSING PROBLEMS WITH THE SWIG BINDINGS. THE FUNCTIONS REGARDING NORMALS MAKE NO SENSE WHEN
|
//THEY ARE CAUSING PROBLEMS WITH THE SWIG BINDINGS. THE FUNCTIONS REGARDING NORMALS MAKE NO SENSE WHEN
|
||||||
//A VERTEX MIGHT NOT HAVE NORMALS. THE EXTRACT SUBSET FUNCTION SHOULD MAYBE BE APPLICATION CODE, AT ANY
|
//A VERTEX MIGHT NOT HAVE NORMALS. THE EXTRACT SUBSET FUNCTION SHOULD MAYBE BE APPLICATION CODE, AT ANY
|
||||||
//RATE THE STD::SET CAUSES PROBLEMS WITH SWIG. IF YOU UNCOMMENT ANY OF THESE FUNCTIONS, PLEASE POST ON
|
//RATE THE STD::SET CAUSES PROBLEMS WITH SWIG. IF YOU UNCOMMENT ANY OF THESE FUNCTIONS, PLEASE POST ON
|
||||||
//THE FORUM SO WE CAN KNOW THE FUNCTIONALITY IS STILL NEEDED IN SOME FORM.
|
//THE FORUM SO WE CAN KNOW THE FUNCTIONALITY IS STILL NEEDED IN SOME FORM.
|
||||||
//void sumNearbyNormals(bool bNormaliseResult = true);
|
//void sumNearbyNormals(bool bNormaliseResult = true);
|
||||||
//std::shared_ptr< SurfaceMesh<VertexType> > extractSubset(std::set<uint8_t> setMaterials);
|
//std::shared_ptr< Mesh<VertexType> > extractSubset(std::set<uint8_t> setMaterials);
|
||||||
//void generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices = false);
|
//void generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices = false);
|
||||||
|
|
||||||
int noOfDegenerateTris(void);
|
int noOfDegenerateTris(void);
|
||||||
void removeDegenerateTris(void);
|
void removeDegenerateTris(void);
|
||||||
void removeUnusedVertices(void);
|
void removeUnusedVertices(void);
|
||||||
|
|
||||||
Region m_Region;
|
Region m_Region;
|
||||||
|
|
||||||
int32_t m_iTimeStamp;
|
int32_t m_iTimeStamp;
|
||||||
|
|
||||||
int32_t m_iNoOfLod0Tris;
|
int32_t m_iNoOfLod0Tris;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<uint32_t> m_vecTriangleIndices;
|
std::vector<uint32_t> m_vecTriangleIndices;
|
||||||
std::vector<VertexType> m_vecVertices;
|
std::vector<VertexType> m_vecVertices;
|
||||||
|
|
||||||
std::vector<LodRecord> m_vecLodRecords;
|
std::vector<LodRecord> m_vecLodRecords;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
std::shared_ptr< SurfaceMesh<VertexType> > extractSubset(SurfaceMesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials);
|
std::shared_ptr< Mesh<VertexType> > extractSubset(Mesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "PolyVoxCore/SurfaceMesh.inl"
|
#include "PolyVoxCore/Mesh.inl"
|
||||||
|
|
||||||
#endif /* __SurfaceMesh_H__ */
|
#endif /* __Mesh_H__ */
|
@ -1,488 +1,488 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
Copyright (c) 2005-2009 David Williams
|
Copyright (c) 2005-2009 David Williams
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
arising from the use of this software.
|
arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it
|
including commercial applications, and to alter it and redistribute it
|
||||||
freely, subject to the following restrictions:
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
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
|
claim that you wrote the original software. If you use this software
|
||||||
in a product, an acknowledgment in the product documentation would be
|
in a product, an acknowledgment in the product documentation would be
|
||||||
appreciated but is not required.
|
appreciated but is not required.
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
misrepresented as being the original software.
|
misrepresented as being the original software.
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
3. This notice may not be removed or altered from any source
|
||||||
distribution.
|
distribution.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
SurfaceMesh<VertexType>::SurfaceMesh()
|
Mesh<VertexType>::Mesh()
|
||||||
{
|
{
|
||||||
m_iTimeStamp = -1;
|
m_iTimeStamp = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
SurfaceMesh<VertexType>::~SurfaceMesh()
|
Mesh<VertexType>::~Mesh()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
const std::vector<uint32_t>& SurfaceMesh<VertexType>::getIndices(void) const
|
const std::vector<uint32_t>& Mesh<VertexType>::getIndices(void) const
|
||||||
{
|
{
|
||||||
return m_vecTriangleIndices;
|
return m_vecTriangleIndices;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
uint32_t SurfaceMesh<VertexType>::getNoOfIndices(void) const
|
uint32_t Mesh<VertexType>::getNoOfIndices(void) const
|
||||||
{
|
{
|
||||||
return m_vecTriangleIndices.size();
|
return m_vecTriangleIndices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
uint32_t SurfaceMesh<VertexType>::getNoOfNonUniformTrianges(void) const
|
uint32_t Mesh<VertexType>::getNoOfNonUniformTrianges(void) const
|
||||||
{
|
{
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
|
for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
|
||||||
{
|
{
|
||||||
if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial())
|
if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial())
|
||||||
&& (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial()))
|
&& (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial()))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result++;
|
result++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
uint32_t SurfaceMesh<VertexType>::getNoOfUniformTrianges(void) const
|
uint32_t Mesh<VertexType>::getNoOfUniformTrianges(void) const
|
||||||
{
|
{
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
|
for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
|
||||||
{
|
{
|
||||||
if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial())
|
if((m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+1]].getMaterial())
|
||||||
&& (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial()))
|
&& (m_vecVertices[m_vecTriangleIndices[i]].getMaterial() == m_vecVertices[m_vecTriangleIndices[i+2]].getMaterial()))
|
||||||
{
|
{
|
||||||
result++;
|
result++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
uint32_t SurfaceMesh<VertexType>::getNoOfVertices(void) const
|
uint32_t Mesh<VertexType>::getNoOfVertices(void) const
|
||||||
{
|
{
|
||||||
return m_vecVertices.size();
|
return m_vecVertices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
std::vector<VertexType>& SurfaceMesh<VertexType>::getRawVertexData(void)
|
std::vector<VertexType>& Mesh<VertexType>::getRawVertexData(void)
|
||||||
{
|
{
|
||||||
return m_vecVertices;
|
return m_vecVertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
const std::vector<VertexType>& SurfaceMesh<VertexType>::getVertices(void) const
|
const std::vector<VertexType>& Mesh<VertexType>::getVertices(void) const
|
||||||
{
|
{
|
||||||
return m_vecVertices;
|
return m_vecVertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
void SurfaceMesh<VertexType>::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2)
|
void Mesh<VertexType>::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2)
|
||||||
{
|
{
|
||||||
//Make sure the specified indices correspond to valid vertices.
|
//Make sure the specified indices correspond to valid vertices.
|
||||||
POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
||||||
POLYVOX_ASSERT(index1 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
POLYVOX_ASSERT(index1 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
||||||
POLYVOX_ASSERT(index2 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
POLYVOX_ASSERT(index2 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
||||||
|
|
||||||
m_vecTriangleIndices.push_back(index0);
|
m_vecTriangleIndices.push_back(index0);
|
||||||
m_vecTriangleIndices.push_back(index1);
|
m_vecTriangleIndices.push_back(index1);
|
||||||
m_vecTriangleIndices.push_back(index2);
|
m_vecTriangleIndices.push_back(index2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
void SurfaceMesh<VertexType>::addTriangleCubic(uint32_t index0, uint32_t index1, uint32_t index2)
|
void Mesh<VertexType>::addTriangleCubic(uint32_t index0, uint32_t index1, uint32_t index2)
|
||||||
{
|
{
|
||||||
//Make sure the specified indices correspond to valid vertices.
|
//Make sure the specified indices correspond to valid vertices.
|
||||||
POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
||||||
POLYVOX_ASSERT(index1 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
POLYVOX_ASSERT(index1 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
||||||
POLYVOX_ASSERT(index2 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
POLYVOX_ASSERT(index2 < m_vecVertices.size(), "Index points at an invalid vertex.");
|
||||||
|
|
||||||
m_vecTriangleIndices.push_back(index0);
|
m_vecTriangleIndices.push_back(index0);
|
||||||
m_vecTriangleIndices.push_back(index1);
|
m_vecTriangleIndices.push_back(index1);
|
||||||
m_vecTriangleIndices.push_back(index2);
|
m_vecTriangleIndices.push_back(index2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
uint32_t SurfaceMesh<VertexType>::addVertex(const VertexType& vertex)
|
uint32_t Mesh<VertexType>::addVertex(const VertexType& vertex)
|
||||||
{
|
{
|
||||||
m_vecVertices.push_back(vertex);
|
m_vecVertices.push_back(vertex);
|
||||||
return m_vecVertices.size() - 1;
|
return m_vecVertices.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
void SurfaceMesh<VertexType>::clear(void)
|
void Mesh<VertexType>::clear(void)
|
||||||
{
|
{
|
||||||
m_vecVertices.clear();
|
m_vecVertices.clear();
|
||||||
m_vecTriangleIndices.clear();
|
m_vecTriangleIndices.clear();
|
||||||
m_vecLodRecords.clear();
|
m_vecLodRecords.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
bool SurfaceMesh<VertexType>::isEmpty(void) const
|
bool Mesh<VertexType>::isEmpty(void) const
|
||||||
{
|
{
|
||||||
return (getNoOfVertices() == 0) || (getNoOfIndices() == 0);
|
return (getNoOfVertices() == 0) || (getNoOfIndices() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// This function can help improve the visual appearance of a surface patch by
|
/// This function can help improve the visual appearance of a surface patch by
|
||||||
/// smoothing normals with other nearby normals. It iterates over each triangle
|
/// smoothing normals with other nearby normals. It iterates over each triangle
|
||||||
/// in the surface patch and determines the sum of its corners normals. For any
|
/// in the surface patch and determines the sum of its corners normals. For any
|
||||||
/// given vertex, these sums are in turn summed for any triangles which use the
|
/// given vertex, these sums are in turn summed for any triangles which use the
|
||||||
/// vertex. Usually, the resulting normals should be renormalised afterwards.
|
/// vertex. Usually, the resulting normals should be renormalised afterwards.
|
||||||
/// Note: This function can cause lighting discontinuities accross region boundaries.
|
/// Note: This function can cause lighting discontinuities accross region boundaries.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/*template <typename VertexType>
|
/*template <typename VertexType>
|
||||||
void SurfaceMesh<VertexType>::sumNearbyNormals(bool bNormaliseResult)
|
void Mesh<VertexType>::sumNearbyNormals(bool bNormaliseResult)
|
||||||
{
|
{
|
||||||
if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
|
if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Vector3DFloat> summedNormals(m_vecVertices.size());
|
std::vector<Vector3DFloat> summedNormals(m_vecVertices.size());
|
||||||
|
|
||||||
//Initialise all normals to zero. Should be ok as the vector should store all elements contiguously.
|
//Initialise all normals to zero. Should be ok as the vector should store all elements contiguously.
|
||||||
memset(&summedNormals[0], 0, summedNormals.size() * sizeof(Vector3DFloat));
|
memset(&summedNormals[0], 0, summedNormals.size() * sizeof(Vector3DFloat));
|
||||||
|
|
||||||
for(vector<uint32_t>::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();)
|
for(vector<uint32_t>::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();)
|
||||||
{
|
{
|
||||||
PositionMaterialNormal& v0 = m_vecVertices[*iterIndex];
|
PositionMaterialNormal& v0 = m_vecVertices[*iterIndex];
|
||||||
Vector3DFloat& v0New = summedNormals[*iterIndex];
|
Vector3DFloat& v0New = summedNormals[*iterIndex];
|
||||||
iterIndex++;
|
iterIndex++;
|
||||||
PositionMaterialNormal& v1 = m_vecVertices[*iterIndex];
|
PositionMaterialNormal& v1 = m_vecVertices[*iterIndex];
|
||||||
Vector3DFloat& v1New = summedNormals[*iterIndex];
|
Vector3DFloat& v1New = summedNormals[*iterIndex];
|
||||||
iterIndex++;
|
iterIndex++;
|
||||||
PositionMaterialNormal& v2 = m_vecVertices[*iterIndex];
|
PositionMaterialNormal& v2 = m_vecVertices[*iterIndex];
|
||||||
Vector3DFloat& v2New = summedNormals[*iterIndex];
|
Vector3DFloat& v2New = summedNormals[*iterIndex];
|
||||||
iterIndex++;
|
iterIndex++;
|
||||||
|
|
||||||
Vector3DFloat sumOfNormals = v0.getNormal() + v1.getNormal() + v2.getNormal();
|
Vector3DFloat sumOfNormals = v0.getNormal() + v1.getNormal() + v2.getNormal();
|
||||||
|
|
||||||
v0New += sumOfNormals;
|
v0New += sumOfNormals;
|
||||||
v1New += sumOfNormals;
|
v1New += sumOfNormals;
|
||||||
v2New += sumOfNormals;
|
v2New += sumOfNormals;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint32_t uIndex = 0; uIndex < summedNormals.size(); uIndex++)
|
for(uint32_t uIndex = 0; uIndex < summedNormals.size(); uIndex++)
|
||||||
{
|
{
|
||||||
if(bNormaliseResult)
|
if(bNormaliseResult)
|
||||||
{
|
{
|
||||||
summedNormals[uIndex].normalise();
|
summedNormals[uIndex].normalise();
|
||||||
}
|
}
|
||||||
m_vecVertices[uIndex].setNormal(summedNormals[uIndex]);
|
m_vecVertices[uIndex].setNormal(summedNormals[uIndex]);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/*template <typename VertexType>
|
/*template <typename VertexType>
|
||||||
void SurfaceMesh<VertexType>::generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices)
|
void Mesh<VertexType>::generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices)
|
||||||
{
|
{
|
||||||
Vector3DFloat offset = static_cast<Vector3DFloat>(m_Region.getLowerCorner());
|
Vector3DFloat offset = static_cast<Vector3DFloat>(m_Region.getLowerCorner());
|
||||||
|
|
||||||
//Initially zero the normals
|
//Initially zero the normals
|
||||||
for(vector<PositionMaterialNormal>::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++)
|
for(vector<PositionMaterialNormal>::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++)
|
||||||
{
|
{
|
||||||
if(m_Region.containsPoint(iterVertex->getPosition() + offset, 0.001))
|
if(m_Region.containsPoint(iterVertex->getPosition() + offset, 0.001))
|
||||||
{
|
{
|
||||||
iterVertex->setNormal(Vector3DFloat(0.0f,0.0f,0.0f));
|
iterVertex->setNormal(Vector3DFloat(0.0f,0.0f,0.0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(vector<uint32_t>::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();)
|
for(vector<uint32_t>::iterator iterIndex = m_vecTriangleIndices.begin(); iterIndex != m_vecTriangleIndices.end();)
|
||||||
{
|
{
|
||||||
PositionMaterialNormal& v0 = m_vecVertices[*iterIndex];
|
PositionMaterialNormal& v0 = m_vecVertices[*iterIndex];
|
||||||
iterIndex++;
|
iterIndex++;
|
||||||
PositionMaterialNormal& v1 = m_vecVertices[*iterIndex];
|
PositionMaterialNormal& v1 = m_vecVertices[*iterIndex];
|
||||||
iterIndex++;
|
iterIndex++;
|
||||||
PositionMaterialNormal& v2 = m_vecVertices[*iterIndex];
|
PositionMaterialNormal& v2 = m_vecVertices[*iterIndex];
|
||||||
iterIndex++;
|
iterIndex++;
|
||||||
|
|
||||||
Vector3DFloat triangleNormal = (v1.getPosition()-v0.getPosition()).cross(v2.getPosition()-v0.getPosition());
|
Vector3DFloat triangleNormal = (v1.getPosition()-v0.getPosition()).cross(v2.getPosition()-v0.getPosition());
|
||||||
|
|
||||||
if(m_Region.containsPoint(v0.getPosition() + offset, 0.001))
|
if(m_Region.containsPoint(v0.getPosition() + offset, 0.001))
|
||||||
{
|
{
|
||||||
v0.setNormal(v0.getNormal() + triangleNormal);
|
v0.setNormal(v0.getNormal() + triangleNormal);
|
||||||
}
|
}
|
||||||
if(m_Region.containsPoint(v1.getPosition() + offset, 0.001))
|
if(m_Region.containsPoint(v1.getPosition() + offset, 0.001))
|
||||||
{
|
{
|
||||||
v1.setNormal(v1.getNormal() + triangleNormal);
|
v1.setNormal(v1.getNormal() + triangleNormal);
|
||||||
}
|
}
|
||||||
if(m_Region.containsPoint(v2.getPosition() + offset, 0.001))
|
if(m_Region.containsPoint(v2.getPosition() + offset, 0.001))
|
||||||
{
|
{
|
||||||
v2.setNormal(v2.getNormal() + triangleNormal);
|
v2.setNormal(v2.getNormal() + triangleNormal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bNormalise)
|
if(bNormalise)
|
||||||
{
|
{
|
||||||
for(vector<PositionMaterialNormal>::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++)
|
for(vector<PositionMaterialNormal>::iterator iterVertex = m_vecVertices.begin(); iterVertex != m_vecVertices.end(); iterVertex++)
|
||||||
{
|
{
|
||||||
Vector3DFloat normal = iterVertex->getNormal();
|
Vector3DFloat normal = iterVertex->getNormal();
|
||||||
normal.normalise();
|
normal.normalise();
|
||||||
iterVertex->setNormal(normal);
|
iterVertex->setNormal(normal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/*template <typename VertexType>
|
/*template <typename VertexType>
|
||||||
std::shared_ptr< SurfaceMesh<VertexType> > SurfaceMesh<VertexType>::extractSubset(std::set<uint8_t> setMaterials)
|
std::shared_ptr< Mesh<VertexType> > Mesh<VertexType>::extractSubset(std::set<uint8_t> setMaterials)
|
||||||
{
|
{
|
||||||
std::shared_ptr< SurfaceMesh<VertexType> > result(new SurfaceMesh<VertexType>);
|
std::shared_ptr< Mesh<VertexType> > result(new Mesh<VertexType>);
|
||||||
|
|
||||||
if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
|
if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(m_vecLodRecords.size() == 1);
|
assert(m_vecLodRecords.size() == 1);
|
||||||
if(m_vecLodRecords.size() != 1)
|
if(m_vecLodRecords.size() != 1)
|
||||||
{
|
{
|
||||||
//If we have done progressive LOD then it's too late to split into subsets.
|
//If we have done progressive LOD then it's too late to split into subsets.
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int32_t> indexMap(m_vecVertices.size());
|
std::vector<int32_t> indexMap(m_vecVertices.size());
|
||||||
std::fill(indexMap.begin(), indexMap.end(), -1);
|
std::fill(indexMap.begin(), indexMap.end(), -1);
|
||||||
|
|
||||||
for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt += 3)
|
for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt += 3)
|
||||||
{
|
{
|
||||||
|
|
||||||
PositionMaterialNormal& v0 = m_vecVertices[m_vecTriangleIndices[triCt]];
|
PositionMaterialNormal& v0 = m_vecVertices[m_vecTriangleIndices[triCt]];
|
||||||
PositionMaterialNormal& v1 = m_vecVertices[m_vecTriangleIndices[triCt + 1]];
|
PositionMaterialNormal& v1 = m_vecVertices[m_vecTriangleIndices[triCt + 1]];
|
||||||
PositionMaterialNormal& v2 = m_vecVertices[m_vecTriangleIndices[triCt + 2]];
|
PositionMaterialNormal& v2 = m_vecVertices[m_vecTriangleIndices[triCt + 2]];
|
||||||
|
|
||||||
if(
|
if(
|
||||||
(setMaterials.find(v0.getMaterial()) != setMaterials.end()) ||
|
(setMaterials.find(v0.getMaterial()) != setMaterials.end()) ||
|
||||||
(setMaterials.find(v1.getMaterial()) != setMaterials.end()) ||
|
(setMaterials.find(v1.getMaterial()) != setMaterials.end()) ||
|
||||||
(setMaterials.find(v2.getMaterial()) != setMaterials.end()))
|
(setMaterials.find(v2.getMaterial()) != setMaterials.end()))
|
||||||
{
|
{
|
||||||
uint32_t i0;
|
uint32_t i0;
|
||||||
if(indexMap[m_vecTriangleIndices[triCt]] == -1)
|
if(indexMap[m_vecTriangleIndices[triCt]] == -1)
|
||||||
{
|
{
|
||||||
indexMap[m_vecTriangleIndices[triCt]] = result->addVertex(v0);
|
indexMap[m_vecTriangleIndices[triCt]] = result->addVertex(v0);
|
||||||
}
|
}
|
||||||
i0 = indexMap[m_vecTriangleIndices[triCt]];
|
i0 = indexMap[m_vecTriangleIndices[triCt]];
|
||||||
|
|
||||||
uint32_t i1;
|
uint32_t i1;
|
||||||
if(indexMap[m_vecTriangleIndices[triCt+1]] == -1)
|
if(indexMap[m_vecTriangleIndices[triCt+1]] == -1)
|
||||||
{
|
{
|
||||||
indexMap[m_vecTriangleIndices[triCt+1]] = result->addVertex(v1);
|
indexMap[m_vecTriangleIndices[triCt+1]] = result->addVertex(v1);
|
||||||
}
|
}
|
||||||
i1 = indexMap[m_vecTriangleIndices[triCt+1]];
|
i1 = indexMap[m_vecTriangleIndices[triCt+1]];
|
||||||
|
|
||||||
uint32_t i2;
|
uint32_t i2;
|
||||||
if(indexMap[m_vecTriangleIndices[triCt+2]] == -1)
|
if(indexMap[m_vecTriangleIndices[triCt+2]] == -1)
|
||||||
{
|
{
|
||||||
indexMap[m_vecTriangleIndices[triCt+2]] = result->addVertex(v2);
|
indexMap[m_vecTriangleIndices[triCt+2]] = result->addVertex(v2);
|
||||||
}
|
}
|
||||||
i2 = indexMap[m_vecTriangleIndices[triCt+2]];
|
i2 = indexMap[m_vecTriangleIndices[triCt+2]];
|
||||||
|
|
||||||
result->addTriangle(i0,i1,i2);
|
result->addTriangle(i0,i1,i2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result->m_vecLodRecords.clear();
|
result->m_vecLodRecords.clear();
|
||||||
LodRecord lodRecord;
|
LodRecord lodRecord;
|
||||||
lodRecord.beginIndex = 0;
|
lodRecord.beginIndex = 0;
|
||||||
lodRecord.endIndex = result->getNoOfIndices();
|
lodRecord.endIndex = result->getNoOfIndices();
|
||||||
result->m_vecLodRecords.push_back(lodRecord);
|
result->m_vecLodRecords.push_back(lodRecord);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
int SurfaceMesh<VertexType>::noOfDegenerateTris(void)
|
int Mesh<VertexType>::noOfDegenerateTris(void)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size();)
|
for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size();)
|
||||||
{
|
{
|
||||||
int v0 = m_vecTriangleIndices[triCt];
|
int v0 = m_vecTriangleIndices[triCt];
|
||||||
triCt++;
|
triCt++;
|
||||||
int v1 = m_vecTriangleIndices[triCt];
|
int v1 = m_vecTriangleIndices[triCt];
|
||||||
triCt++;
|
triCt++;
|
||||||
int v2 = m_vecTriangleIndices[triCt];
|
int v2 = m_vecTriangleIndices[triCt];
|
||||||
triCt++;
|
triCt++;
|
||||||
|
|
||||||
if((v0 == v1) || (v1 == v2) || (v2 == v0))
|
if((v0 == v1) || (v1 == v2) || (v2 == v0))
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
void SurfaceMesh<VertexType>::removeDegenerateTris(void)
|
void Mesh<VertexType>::removeDegenerateTris(void)
|
||||||
{
|
{
|
||||||
int noOfNonDegenerate = 0;
|
int noOfNonDegenerate = 0;
|
||||||
int targetCt = 0;
|
int targetCt = 0;
|
||||||
for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size();)
|
for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size();)
|
||||||
{
|
{
|
||||||
int v0 = m_vecTriangleIndices[triCt];
|
int v0 = m_vecTriangleIndices[triCt];
|
||||||
triCt++;
|
triCt++;
|
||||||
int v1 = m_vecTriangleIndices[triCt];
|
int v1 = m_vecTriangleIndices[triCt];
|
||||||
triCt++;
|
triCt++;
|
||||||
int v2 = m_vecTriangleIndices[triCt];
|
int v2 = m_vecTriangleIndices[triCt];
|
||||||
triCt++;
|
triCt++;
|
||||||
|
|
||||||
if((v0 != v1) && (v1 != v2) & (v2 != v0))
|
if((v0 != v1) && (v1 != v2) & (v2 != v0))
|
||||||
{
|
{
|
||||||
m_vecTriangleIndices[targetCt] = v0;
|
m_vecTriangleIndices[targetCt] = v0;
|
||||||
targetCt++;
|
targetCt++;
|
||||||
m_vecTriangleIndices[targetCt] = v1;
|
m_vecTriangleIndices[targetCt] = v1;
|
||||||
targetCt++;
|
targetCt++;
|
||||||
m_vecTriangleIndices[targetCt] = v2;
|
m_vecTriangleIndices[targetCt] = v2;
|
||||||
targetCt++;
|
targetCt++;
|
||||||
|
|
||||||
noOfNonDegenerate++;
|
noOfNonDegenerate++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_vecTriangleIndices.resize(noOfNonDegenerate * 3);
|
m_vecTriangleIndices.resize(noOfNonDegenerate * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
void SurfaceMesh<VertexType>::removeUnusedVertices(void)
|
void Mesh<VertexType>::removeUnusedVertices(void)
|
||||||
{
|
{
|
||||||
std::vector<bool> isVertexUsed(m_vecVertices.size());
|
std::vector<bool> isVertexUsed(m_vecVertices.size());
|
||||||
std::fill(isVertexUsed.begin(), isVertexUsed.end(), false);
|
std::fill(isVertexUsed.begin(), isVertexUsed.end(), false);
|
||||||
|
|
||||||
for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++)
|
for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++)
|
||||||
{
|
{
|
||||||
int v = m_vecTriangleIndices[triCt];
|
int v = m_vecTriangleIndices[triCt];
|
||||||
isVertexUsed[v] = true;
|
isVertexUsed[v] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int noOfUsedVertices = 0;
|
int noOfUsedVertices = 0;
|
||||||
std::vector<uint32_t> newPos(m_vecVertices.size());
|
std::vector<uint32_t> newPos(m_vecVertices.size());
|
||||||
for(uint32_t vertCt = 0; vertCt < m_vecVertices.size(); vertCt++)
|
for(uint32_t vertCt = 0; vertCt < m_vecVertices.size(); vertCt++)
|
||||||
{
|
{
|
||||||
if(isVertexUsed[vertCt])
|
if(isVertexUsed[vertCt])
|
||||||
{
|
{
|
||||||
m_vecVertices[noOfUsedVertices] = m_vecVertices[vertCt];
|
m_vecVertices[noOfUsedVertices] = m_vecVertices[vertCt];
|
||||||
newPos[vertCt] = noOfUsedVertices;
|
newPos[vertCt] = noOfUsedVertices;
|
||||||
noOfUsedVertices++;
|
noOfUsedVertices++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_vecVertices.resize(noOfUsedVertices);
|
m_vecVertices.resize(noOfUsedVertices);
|
||||||
|
|
||||||
for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++)
|
for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++)
|
||||||
{
|
{
|
||||||
m_vecTriangleIndices[triCt] = newPos[m_vecTriangleIndices[triCt]];
|
m_vecTriangleIndices[triCt] = newPos[m_vecTriangleIndices[triCt]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Currently a free function - think where this needs to go.
|
//Currently a free function - think where this needs to go.
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
std::shared_ptr< SurfaceMesh<VertexType> > extractSubset(SurfaceMesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials)
|
std::shared_ptr< Mesh<VertexType> > extractSubset(Mesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials)
|
||||||
{
|
{
|
||||||
std::shared_ptr< SurfaceMesh<VertexType> > result(new SurfaceMesh<VertexType>);
|
std::shared_ptr< Mesh<VertexType> > result(new Mesh<VertexType>);
|
||||||
|
|
||||||
result->m_Region = inputMesh.m_Region;
|
result->m_Region = inputMesh.m_Region;
|
||||||
|
|
||||||
if(inputMesh.m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
|
if(inputMesh.m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
POLYVOX_ASSERT(inputMesh.m_vecLodRecords.size() == 1, "Number of LOD records must equal one.");
|
POLYVOX_ASSERT(inputMesh.m_vecLodRecords.size() == 1, "Number of LOD records must equal one.");
|
||||||
if(inputMesh.m_vecLodRecords.size() != 1)
|
if(inputMesh.m_vecLodRecords.size() != 1)
|
||||||
{
|
{
|
||||||
//If we have done progressive LOD then it's too late to split into subsets.
|
//If we have done progressive LOD then it's too late to split into subsets.
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int32_t> indexMap(inputMesh.m_vecVertices.size());
|
std::vector<int32_t> indexMap(inputMesh.m_vecVertices.size());
|
||||||
std::fill(indexMap.begin(), indexMap.end(), -1);
|
std::fill(indexMap.begin(), indexMap.end(), -1);
|
||||||
|
|
||||||
for(uint32_t triCt = 0; triCt < inputMesh.m_vecTriangleIndices.size(); triCt += 3)
|
for(uint32_t triCt = 0; triCt < inputMesh.m_vecTriangleIndices.size(); triCt += 3)
|
||||||
{
|
{
|
||||||
|
|
||||||
VertexType& v0 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt]];
|
VertexType& v0 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt]];
|
||||||
VertexType& v1 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt + 1]];
|
VertexType& v1 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt + 1]];
|
||||||
VertexType& v2 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt + 2]];
|
VertexType& v2 = inputMesh.m_vecVertices[inputMesh.m_vecTriangleIndices[triCt + 2]];
|
||||||
|
|
||||||
if(
|
if(
|
||||||
(setMaterials.find(v0.getMaterial()) != setMaterials.end()) ||
|
(setMaterials.find(v0.getMaterial()) != setMaterials.end()) ||
|
||||||
(setMaterials.find(v1.getMaterial()) != setMaterials.end()) ||
|
(setMaterials.find(v1.getMaterial()) != setMaterials.end()) ||
|
||||||
(setMaterials.find(v2.getMaterial()) != setMaterials.end()))
|
(setMaterials.find(v2.getMaterial()) != setMaterials.end()))
|
||||||
{
|
{
|
||||||
uint32_t i0;
|
uint32_t i0;
|
||||||
if(indexMap[inputMesh.m_vecTriangleIndices[triCt]] == -1)
|
if(indexMap[inputMesh.m_vecTriangleIndices[triCt]] == -1)
|
||||||
{
|
{
|
||||||
indexMap[inputMesh.m_vecTriangleIndices[triCt]] = result->addVertex(v0);
|
indexMap[inputMesh.m_vecTriangleIndices[triCt]] = result->addVertex(v0);
|
||||||
}
|
}
|
||||||
i0 = indexMap[inputMesh.m_vecTriangleIndices[triCt]];
|
i0 = indexMap[inputMesh.m_vecTriangleIndices[triCt]];
|
||||||
|
|
||||||
uint32_t i1;
|
uint32_t i1;
|
||||||
if(indexMap[inputMesh.m_vecTriangleIndices[triCt+1]] == -1)
|
if(indexMap[inputMesh.m_vecTriangleIndices[triCt+1]] == -1)
|
||||||
{
|
{
|
||||||
indexMap[inputMesh.m_vecTriangleIndices[triCt+1]] = result->addVertex(v1);
|
indexMap[inputMesh.m_vecTriangleIndices[triCt+1]] = result->addVertex(v1);
|
||||||
}
|
}
|
||||||
i1 = indexMap[inputMesh.m_vecTriangleIndices[triCt+1]];
|
i1 = indexMap[inputMesh.m_vecTriangleIndices[triCt+1]];
|
||||||
|
|
||||||
uint32_t i2;
|
uint32_t i2;
|
||||||
if(indexMap[inputMesh.m_vecTriangleIndices[triCt+2]] == -1)
|
if(indexMap[inputMesh.m_vecTriangleIndices[triCt+2]] == -1)
|
||||||
{
|
{
|
||||||
indexMap[inputMesh.m_vecTriangleIndices[triCt+2]] = result->addVertex(v2);
|
indexMap[inputMesh.m_vecTriangleIndices[triCt+2]] = result->addVertex(v2);
|
||||||
}
|
}
|
||||||
i2 = indexMap[inputMesh.m_vecTriangleIndices[triCt+2]];
|
i2 = indexMap[inputMesh.m_vecTriangleIndices[triCt+2]];
|
||||||
|
|
||||||
result->addTriangle(i0,i1,i2);
|
result->addTriangle(i0,i1,i2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result->m_vecLodRecords.clear();
|
result->m_vecLodRecords.clear();
|
||||||
LodRecord lodRecord;
|
LodRecord lodRecord;
|
||||||
lodRecord.beginIndex = 0;
|
lodRecord.beginIndex = 0;
|
||||||
lodRecord.endIndex = result->getNoOfIndices();
|
lodRecord.endIndex = result->getNoOfIndices();
|
||||||
result->m_vecLodRecords.push_back(lodRecord);
|
result->m_vecLodRecords.push_back(lodRecord);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
void SurfaceMesh<VertexType>::scaleVertices(float amount)
|
void Mesh<VertexType>::scaleVertices(float amount)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++)
|
for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++)
|
||||||
{
|
{
|
||||||
//TODO: Should rethink accessors here to provide faster access
|
//TODO: Should rethink accessors here to provide faster access
|
||||||
Vector3DFloat position = m_vecVertices[ct].getPosition();
|
Vector3DFloat position = m_vecVertices[ct].getPosition();
|
||||||
position *= amount;
|
position *= amount;
|
||||||
m_vecVertices[ct].setPosition(position);
|
m_vecVertices[ct].setPosition(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType>
|
template <typename VertexType>
|
||||||
void SurfaceMesh<VertexType>::translateVertices(const Vector3DFloat& amount)
|
void Mesh<VertexType>::translateVertices(const Vector3DFloat& amount)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++)
|
for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++)
|
||||||
{
|
{
|
||||||
//TODO: Should rethink accessors here to provide faster access
|
//TODO: Should rethink accessors here to provide faster access
|
||||||
Vector3DFloat position = m_vecVertices[ct].getPosition();
|
Vector3DFloat position = m_vecVertices[ct].getPosition();
|
||||||
position += amount;
|
position += amount;
|
||||||
m_vecVertices[ct].setPosition(position);
|
m_vecVertices[ct].setPosition(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -160,9 +160,9 @@ namespace PolyVox
|
|||||||
template<typename VolumeType, typename Controller> class MarchingCubesSurfaceExtractor;
|
template<typename VolumeType, typename Controller> class MarchingCubesSurfaceExtractor;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// SurfaceMesh
|
// Mesh
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
template <typename VertexType> class SurfaceMesh;
|
template <typename VertexType> class Mesh;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Vector
|
// Vector
|
||||||
|
@ -130,7 +130,7 @@ void TestCubicSurfaceExtractor::testExecute()
|
|||||||
const static uint32_t uIndexToCheck = 2000;
|
const static uint32_t uIndexToCheck = 2000;
|
||||||
const static uint32_t uExpectedIndex = 1334;
|
const static uint32_t uExpectedIndex = 1334;
|
||||||
|
|
||||||
SurfaceMesh<CubicVertex> mesh;*/
|
Mesh<CubicVertex> mesh;*/
|
||||||
|
|
||||||
/*testForType<int8_t>(mesh);
|
/*testForType<int8_t>(mesh);
|
||||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||||
|
@ -102,7 +102,7 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel)
|
|||||||
|
|
||||||
// Runs the surface extractor for a given type.
|
// Runs the surface extractor for a given type.
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
SurfaceMesh<MarchingCubesVertex<VoxelType> > testForType(void) //I think we could avoid specifying this return type by using auto/decltype?
|
Mesh<MarchingCubesVertex<VoxelType> > testForType(void) //I think we could avoid specifying this return type by using auto/decltype?
|
||||||
{
|
{
|
||||||
const int32_t uVolumeSideLength = 32;
|
const int32_t uVolumeSideLength = 32;
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ SurfaceMesh<MarchingCubesVertex<VoxelType> > testForType(void) //I think we coul
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testCustomController(SurfaceMesh<MarchingCubesVertex<float> >& result)
|
void testCustomController(Mesh<MarchingCubesVertex<float> >& result)
|
||||||
{
|
{
|
||||||
const int32_t uVolumeSideLength = 32;
|
const int32_t uVolumeSideLength = 32;
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ void TestSurfaceExtractor::testExecute()
|
|||||||
const static float fExpectedMaterial = 42.0f;
|
const static float fExpectedMaterial = 42.0f;
|
||||||
const static float fNoMaterial = 1.0f;
|
const static float fNoMaterial = 1.0f;
|
||||||
|
|
||||||
SurfaceMesh<MarchingCubesVertex<int8_t> > mesh;
|
Mesh<MarchingCubesVertex<int8_t> > mesh;
|
||||||
//Run the test for various voxel types.
|
//Run the test for various voxel types.
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
mesh = testForType<int8_t>();
|
mesh = testForType<int8_t>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user