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;
|
Model* _model;
|
||||||
bool _needsInitialSimulation;
|
bool _needsInitialSimulation;
|
||||||
bool _needsModelReload;
|
bool _needsModelReload = true;
|
||||||
EntityTreeRenderer* _myRenderer;
|
EntityTreeRenderer* _myRenderer;
|
||||||
QString _currentTextures;
|
QString _currentTextures;
|
||||||
QStringList _originalTextures;
|
QStringList _originalTextures;
|
||||||
|
|
|
@ -31,6 +31,24 @@ EntityItem* RenderablePolyVoxEntityItem::factory(const EntityItemID& entityID, c
|
||||||
return new RenderablePolyVoxEntityItem(entityID, properties);
|
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) {
|
void createSphereInVolume(PolyVox::SimpleVolume<uint8_t>& volData, float fRadius) {
|
||||||
// This vector hold the position of the center of the volume
|
// 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() {
|
void RenderablePolyVoxEntityItem::getModel() {
|
||||||
PolyVox::SimpleVolume<uint8_t> volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0),
|
if (!_volData) {
|
||||||
PolyVox::Vector3DInt32(63, 63, 63)));
|
// this will cause the allocation of _volData
|
||||||
createSphereInVolume(volData, 15);
|
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
|
// A mesh object to hold the result of surface extraction
|
||||||
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
|
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
|
||||||
|
|
||||||
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
|
//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
|
PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
|
||||||
(&volData, volData.getEnclosingRegion(), &polyVoxMesh);
|
(_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
|
||||||
// MarchingCubesSurfaceExtractor<SimpleVolume<uint8_t>> surfaceExtractor(&volData,
|
// MarchingCubesSurfaceExtractor<SimpleVolume<uint8_t>> surfaceExtractor(_volData,
|
||||||
// volData.getEnclosingRegion(),
|
// _volData->getEnclosingRegion(),
|
||||||
// &polyVoxMesh);
|
// &polyVoxMesh);
|
||||||
|
|
||||||
//Execute the surface extractor.
|
//Execute the surface extractor.
|
||||||
surfaceExtractor.execute();
|
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::Mesh* mesh = new model::Mesh();
|
||||||
model::MeshPointer meshPtr(mesh);
|
model::MeshPointer meshPtr(mesh);
|
||||||
|
|
||||||
|
|
||||||
const std::vector<uint32_t>& vecIndices = polyVoxMesh.getIndices();
|
const std::vector<uint32_t>& vecIndices = polyVoxMesh.getIndices();
|
||||||
auto indexBuffer = new gpu::Buffer(vecIndices.size() * sizeof(uint32_t), (gpu::Byte*)vecIndices.data());
|
auto indexBuffer = new gpu::Buffer(vecIndices.size() * sizeof(uint32_t), (gpu::Byte*)vecIndices.data());
|
||||||
auto indexBufferPtr = gpu::BufferPointer(indexBuffer);
|
auto indexBufferPtr = gpu::BufferPointer(indexBuffer);
|
||||||
|
@ -98,15 +132,13 @@ void RenderablePolyVoxEntityItem::getModel() {
|
||||||
0,
|
0,
|
||||||
vertexBufferPtr->getSize() - sizeof(float) * 3,
|
vertexBufferPtr->getSize() - sizeof(float) * 3,
|
||||||
sizeof(PolyVox::PositionMaterialNormal),
|
sizeof(PolyVox::PositionMaterialNormal),
|
||||||
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)
|
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)));
|
||||||
));
|
|
||||||
mesh->addAttribute(gpu::Stream::NORMAL,
|
mesh->addAttribute(gpu::Stream::NORMAL,
|
||||||
gpu::BufferView(vertexBufferPtr,
|
gpu::BufferView(vertexBufferPtr,
|
||||||
sizeof(float) * 3,
|
sizeof(float) * 3,
|
||||||
vertexBufferPtr->getSize() - sizeof(float) * 3,
|
vertexBufferPtr->getSize() - sizeof(float) * 3,
|
||||||
sizeof(PolyVox::PositionMaterialNormal),
|
sizeof(PolyVox::PositionMaterialNormal),
|
||||||
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)
|
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)));
|
||||||
));
|
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------";
|
qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------";
|
||||||
|
@ -142,27 +174,35 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 position = getPosition();
|
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();
|
glm::quat rotation = getRotation();
|
||||||
glPushMatrix();
|
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);
|
glTranslatef(position.x, position.y, position.z);
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
glm::vec3 positionToCenter = center - position;
|
||||||
gpu::Batch batch;
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
|
glScalef(scale.x, scale.y, scale.z);
|
||||||
|
|
||||||
auto mesh = _modelGeometry.getMesh();
|
auto mesh = _modelGeometry.getMesh();
|
||||||
|
gpu::Batch batch;
|
||||||
batch.setInputFormat(mesh->getVertexFormat());
|
batch.setInputFormat(mesh->getVertexFormat());
|
||||||
|
batch.setInputBuffer(gpu::Stream::POSITION, mesh->getVertexBuffer());
|
||||||
batch.setInputBuffer(gpu::Stream::POSITION, mesh->getVertexBuffer());
|
batch.setInputBuffer(gpu::Stream::NORMAL,
|
||||||
batch.setInputBuffer(gpu::Stream::NORMAL, mesh->getVertexBuffer()._buffer, sizeof(float) * 3, mesh->getVertexBuffer()._stride);
|
mesh->getVertexBuffer()._buffer,
|
||||||
|
sizeof(float) * 3,
|
||||||
//batch.setInputStream(0, mesh->makeBufferStream());
|
mesh->getVertexBuffer()._stride);
|
||||||
|
batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0);
|
||||||
batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0);
|
|
||||||
batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0);
|
batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0);
|
||||||
gpu::GLBackend::renderBatch(batch);
|
gpu::GLBackend::renderBatch(batch);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
RenderableDebugableEntityItem::render(this, args);
|
RenderableDebugableEntityItem::render(this, args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,16 +24,16 @@ public:
|
||||||
RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||||
PolyVoxEntityItem(entityItemID, properties) { }
|
PolyVoxEntityItem(entityItemID, properties) { }
|
||||||
|
|
||||||
|
virtual ~RenderablePolyVoxEntityItem();
|
||||||
|
|
||||||
void render(RenderArgs* args);
|
void render(RenderArgs* args);
|
||||||
virtual bool hasModel() const { return true; }
|
virtual bool hasModel() const { return true; }
|
||||||
void getModel();
|
void getModel();
|
||||||
|
|
||||||
private:
|
virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize);
|
||||||
// Model* _model = nullptr;
|
|
||||||
// bool _needsInitialSimulation = true;
|
|
||||||
// bool _needsModelReload = true;
|
|
||||||
// EntityTreeRenderer* _myRenderer = nullptr;
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
PolyVox::SimpleVolume<uint8_t>* _volData = nullptr;
|
||||||
model::Geometry _modelGeometry;
|
model::Geometry _modelGeometry;
|
||||||
bool _needsModelReload = true;
|
bool _needsModelReload = true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,8 +61,11 @@ class PolyVoxEntityItem : public EntityItem {
|
||||||
|
|
||||||
virtual void debugDump() const;
|
virtual void debugDump() const;
|
||||||
|
|
||||||
|
virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { _voxelVolumeSize = voxelVolumeSize; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
rgbColor _color;
|
rgbColor _color;
|
||||||
|
glm::vec3 _voxelVolumeSize = glm::vec3(64, 64, 64);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_PolyVoxEntityItem_h
|
#endif // hifi_PolyVoxEntityItem_h
|
||||||
|
|
Loading…
Reference in a new issue