mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
added a volex-volume size member variable. drawing transform still isn't quite right
This commit is contained in:
parent
85171f033e
commit
2cb73b5430
4 changed files with 72 additions and 29 deletions
|
@ -65,7 +65,7 @@ private:
|
|||
|
||||
Model* _model;
|
||||
bool _needsInitialSimulation;
|
||||
bool _needsModelReload;
|
||||
bool _needsModelReload = true;
|
||||
EntityTreeRenderer* _myRenderer;
|
||||
QString _currentTextures;
|
||||
QStringList _originalTextures;
|
||||
|
|
|
@ -31,6 +31,24 @@ EntityItem* RenderablePolyVoxEntityItem::factory(const EntityItemID& entityID, c
|
|||
return new RenderablePolyVoxEntityItem(entityID, properties);
|
||||
}
|
||||
|
||||
RenderablePolyVoxEntityItem::~RenderablePolyVoxEntityItem() {
|
||||
delete _volData;
|
||||
}
|
||||
|
||||
void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) {
|
||||
PolyVoxEntityItem::setVoxelVolumeSize(voxelVolumeSize);
|
||||
|
||||
if (_volData) {
|
||||
delete _volData;
|
||||
}
|
||||
|
||||
PolyVox::Vector3DInt32 lowCorner(0, 0, 0);
|
||||
PolyVox::Vector3DInt32 highCorner(_voxelVolumeSize[0] - 1, // -1 because these corners are inclusive
|
||||
_voxelVolumeSize[1] - 1,
|
||||
_voxelVolumeSize[2] - 1);
|
||||
|
||||
_volData = new PolyVox::SimpleVolume<uint8_t>(PolyVox::Region(lowCorner, highCorner));
|
||||
}
|
||||
|
||||
void createSphereInVolume(PolyVox::SimpleVolume<uint8_t>& volData, float fRadius) {
|
||||
// This vector hold the position of the center of the volume
|
||||
|
@ -60,30 +78,46 @@ void createSphereInVolume(PolyVox::SimpleVolume<uint8_t>& volData, float fRadius
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void RenderablePolyVoxEntityItem::getModel() {
|
||||
PolyVox::SimpleVolume<uint8_t> volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0),
|
||||
PolyVox::Vector3DInt32(63, 63, 63)));
|
||||
createSphereInVolume(volData, 15);
|
||||
if (!_volData) {
|
||||
// this will cause the allocation of _volData
|
||||
setVoxelVolumeSize(_voxelVolumeSize);
|
||||
}
|
||||
|
||||
// PolyVox::SimpleVolume<uint8_t> volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0),
|
||||
// PolyVox::Vector3DInt32(63, 63, 63)));
|
||||
createSphereInVolume(*_volData, 15);
|
||||
|
||||
// A mesh object to hold the result of surface extraction
|
||||
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
|
||||
|
||||
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
|
||||
PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
|
||||
(&volData, volData.getEnclosingRegion(), &polyVoxMesh);
|
||||
// MarchingCubesSurfaceExtractor<SimpleVolume<uint8_t>> surfaceExtractor(&volData,
|
||||
// volData.getEnclosingRegion(),
|
||||
(_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
|
||||
// MarchingCubesSurfaceExtractor<SimpleVolume<uint8_t>> surfaceExtractor(_volData,
|
||||
// _volData->getEnclosingRegion(),
|
||||
// &polyVoxMesh);
|
||||
|
||||
//Execute the surface extractor.
|
||||
surfaceExtractor.execute();
|
||||
|
||||
|
||||
// find dimensions
|
||||
// AABox box;
|
||||
// const std::vector<PolyVox::PositionMaterialNormal>& vertices = polyVoxMesh.getVertices();
|
||||
// foreach (const PolyVox::PositionMaterialNormal vertexMaterialNormal, vertices) {
|
||||
// const PolyVox::Vector3DFloat& vertex = vertexMaterialNormal.position;
|
||||
// glm::vec3 v(vertex.getX(), vertex.getY(), vertex.getZ());
|
||||
// box += v;
|
||||
// }
|
||||
// glm::vec3 dimensions = box.getDimensions();
|
||||
// setDimensions(dimensions);
|
||||
|
||||
|
||||
// convert PolyVox mesh to a Sam mesh
|
||||
model::Mesh* mesh = new model::Mesh();
|
||||
model::MeshPointer meshPtr(mesh);
|
||||
|
||||
|
||||
const std::vector<uint32_t>& vecIndices = polyVoxMesh.getIndices();
|
||||
auto indexBuffer = new gpu::Buffer(vecIndices.size() * sizeof(uint32_t), (gpu::Byte*)vecIndices.data());
|
||||
auto indexBufferPtr = gpu::BufferPointer(indexBuffer);
|
||||
|
@ -98,15 +132,13 @@ void RenderablePolyVoxEntityItem::getModel() {
|
|||
0,
|
||||
vertexBufferPtr->getSize() - sizeof(float) * 3,
|
||||
sizeof(PolyVox::PositionMaterialNormal),
|
||||
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)
|
||||
));
|
||||
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)));
|
||||
mesh->addAttribute(gpu::Stream::NORMAL,
|
||||
gpu::BufferView(vertexBufferPtr,
|
||||
sizeof(float) * 3,
|
||||
vertexBufferPtr->getSize() - sizeof(float) * 3,
|
||||
sizeof(PolyVox::PositionMaterialNormal),
|
||||
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)
|
||||
));
|
||||
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)));
|
||||
|
||||
|
||||
qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------";
|
||||
|
@ -142,27 +174,35 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
|
|||
}
|
||||
|
||||
glm::vec3 position = getPosition();
|
||||
// glm::vec3 dimensions = getDimensions();
|
||||
glm::vec3 dimensions = getDimensions();
|
||||
glm::vec3 scale = dimensions / _voxelVolumeSize;
|
||||
glm::vec3 center = getCenter();
|
||||
glm::quat rotation = getRotation();
|
||||
glPushMatrix();
|
||||
// glm::vec3 positionToCenter = center - position;
|
||||
// glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||
// glm::vec3 axis = glm::axis(rotation);
|
||||
// glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
// glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
|
||||
gpu::Batch batch;
|
||||
glm::vec3 positionToCenter = center - position;
|
||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||
glScalef(scale.x, scale.y, scale.z);
|
||||
|
||||
auto mesh = _modelGeometry.getMesh();
|
||||
gpu::Batch batch;
|
||||
batch.setInputFormat(mesh->getVertexFormat());
|
||||
|
||||
batch.setInputBuffer(gpu::Stream::POSITION, mesh->getVertexBuffer());
|
||||
batch.setInputBuffer(gpu::Stream::NORMAL, mesh->getVertexBuffer()._buffer, sizeof(float) * 3, mesh->getVertexBuffer()._stride);
|
||||
|
||||
//batch.setInputStream(0, mesh->makeBufferStream());
|
||||
|
||||
batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0);
|
||||
batch.setInputBuffer(gpu::Stream::POSITION, mesh->getVertexBuffer());
|
||||
batch.setInputBuffer(gpu::Stream::NORMAL,
|
||||
mesh->getVertexBuffer()._buffer,
|
||||
sizeof(float) * 3,
|
||||
mesh->getVertexBuffer()._stride);
|
||||
batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0);
|
||||
batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0);
|
||||
gpu::GLBackend::renderBatch(batch);
|
||||
|
||||
glPopMatrix();
|
||||
RenderableDebugableEntityItem::render(this, args);
|
||||
}
|
||||
|
|
|
@ -24,16 +24,16 @@ public:
|
|||
RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||
PolyVoxEntityItem(entityItemID, properties) { }
|
||||
|
||||
virtual ~RenderablePolyVoxEntityItem();
|
||||
|
||||
void render(RenderArgs* args);
|
||||
virtual bool hasModel() const { return true; }
|
||||
void getModel();
|
||||
|
||||
private:
|
||||
// Model* _model = nullptr;
|
||||
// bool _needsInitialSimulation = true;
|
||||
// bool _needsModelReload = true;
|
||||
// EntityTreeRenderer* _myRenderer = nullptr;
|
||||
virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize);
|
||||
|
||||
private:
|
||||
PolyVox::SimpleVolume<uint8_t>* _volData = nullptr;
|
||||
model::Geometry _modelGeometry;
|
||||
bool _needsModelReload = true;
|
||||
};
|
||||
|
|
|
@ -61,8 +61,11 @@ class PolyVoxEntityItem : public EntityItem {
|
|||
|
||||
virtual void debugDump() const;
|
||||
|
||||
virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { _voxelVolumeSize = voxelVolumeSize; }
|
||||
|
||||
protected:
|
||||
rgbColor _color;
|
||||
glm::vec3 _voxelVolumeSize = glm::vec3(64, 64, 64);
|
||||
};
|
||||
|
||||
#endif // hifi_PolyVoxEntityItem_h
|
||||
|
|
Loading…
Reference in a new issue