Updated basic example and associated documentation.
This commit is contained in:
@ -14,30 +14,24 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
|
||||
|
||||
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh& surfaceMesh)
|
||||
{
|
||||
//Sanity check that we have something to render.
|
||||
if(surfaceMesh.getVertices().empty() || surfaceMesh.getIndices().empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Convienient access to the vertices and indices
|
||||
vector<uint32_t>& vecIndices = const_cast<vector<uint32_t>&>(surfaceMesh.getIndices());
|
||||
vector<SurfaceVertex>& vecVertices = const_cast<vector<SurfaceVertex>&>(surfaceMesh.getVertices());
|
||||
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
|
||||
const vector<SurfaceVertex>& vecVertices = surfaceMesh.getVertices();
|
||||
|
||||
//Build an OpenGL index buffer
|
||||
glGenBuffers(1, &indexBuffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
|
||||
GLvoid* pIndices = static_cast<GLvoid*>(&(vecIndices[0]));
|
||||
const GLvoid* pIndices = static_cast<const GLvoid*>(&(vecIndices[0]));
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), pIndices, GL_STATIC_DRAW);
|
||||
|
||||
//Build an OpenGL vertex buffer
|
||||
glGenBuffers(1, &vertexBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||
GLvoid* pVertices = static_cast<GLvoid*>(&(vecVertices[0]));
|
||||
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
|
||||
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(SurfaceVertex), pVertices, GL_STATIC_DRAW);
|
||||
|
||||
m_uBeginIndex = surfaceMesh.m_vecLodRecords[0].beginIndex;
|
||||
m_uEndIndex = surfaceMesh.m_vecLodRecords[0].endIndex;
|
||||
m_uBeginIndex = 0;
|
||||
m_uEndIndex = vecIndices.size();
|
||||
}
|
||||
|
||||
void OpenGLWidget::initializeGL()
|
||||
|
@ -33,7 +33,7 @@ freely, subject to the following restrictions:
|
||||
//Use the PolyVox namespace
|
||||
using namespace PolyVox;
|
||||
|
||||
void createSphereInVolume(Volume<MaterialDensityPair44>& volData, float fRadius, uint8_t uValue)
|
||||
void createSphereInVolume(Volume<MaterialDensityPair44>& volData, float fRadius)
|
||||
{
|
||||
//This vector hold the position of the center of the volume
|
||||
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
|
||||
@ -50,20 +50,21 @@ void createSphereInVolume(Volume<MaterialDensityPair44>& volData, float fRadius,
|
||||
//And compute how far the current position is from the center of the volume
|
||||
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
|
||||
|
||||
//Default to values representing empty space.
|
||||
uint8_t uMaterial = 0;
|
||||
uint8_t uDensity = MaterialDensityPair44::getMinDensity();
|
||||
|
||||
//If the current voxel is less than 'radius' units from the center then we make it solid.
|
||||
if(fDistToCenter <= fRadius)
|
||||
{
|
||||
uMaterial = 1;
|
||||
uDensity = MaterialDensityPair44::getMaxDensity();
|
||||
}
|
||||
//Our new density value
|
||||
uint8_t uDensity = MaterialDensityPair44::getMaxDensity();
|
||||
|
||||
//Wrte the voxel value into the volume
|
||||
MaterialDensityPair44 voxel(uMaterial, uDensity);
|
||||
volData.setVoxelAt(x, y, z, voxel);
|
||||
//Get the old voxel
|
||||
MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z);
|
||||
|
||||
//Modify the density
|
||||
voxel.setDensity(uDensity);
|
||||
|
||||
//Wrte the voxel value into the volume
|
||||
volData.setVoxelAt(x, y, z, voxel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,7 +79,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
//Create an empty volume and then place a sphere in it
|
||||
Volume<MaterialDensityPair44> volData(64, 64, 64);
|
||||
createSphereInVolume(volData, 30, 1);
|
||||
createSphereInVolume(volData, 30);
|
||||
|
||||
//Extract the surface
|
||||
SurfaceExtractor<MaterialDensityPair44> surfaceExtractor(volData);
|
||||
|
Reference in New Issue
Block a user