mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:37:48 +02:00
some clean-ups and a bug fix in PolyVox to mesh code
This commit is contained in:
parent
9cdd85af05
commit
2682586c38
3 changed files with 22 additions and 16 deletions
|
@ -690,6 +690,8 @@ bool RenderablePolyVoxEntityItem::updateDependents() {
|
||||||
_voxelDataDirty = false;
|
_voxelDataDirty = false;
|
||||||
} else if (_volDataDirty) {
|
} else if (_volDataDirty) {
|
||||||
_volDataDirty = false;
|
_volDataDirty = false;
|
||||||
|
} else {
|
||||||
|
_meshReady = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (voxelDataDirty) {
|
if (voxelDataDirty) {
|
||||||
|
@ -707,7 +709,9 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
|
||||||
assert(getType() == EntityTypes::PolyVox);
|
assert(getType() == EntityTypes::PolyVox);
|
||||||
Q_ASSERT(args->_batch);
|
Q_ASSERT(args->_batch);
|
||||||
|
|
||||||
updateDependents();
|
if (_voxelDataDirty || _volDataDirty) {
|
||||||
|
updateDependents();
|
||||||
|
}
|
||||||
|
|
||||||
model::MeshPointer mesh;
|
model::MeshPointer mesh;
|
||||||
glm::vec3 voxelVolumeSize;
|
glm::vec3 voxelVolumeSize;
|
||||||
|
@ -769,6 +773,11 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
|
||||||
0,
|
0,
|
||||||
sizeof(PolyVox::PositionMaterialNormal));
|
sizeof(PolyVox::PositionMaterialNormal));
|
||||||
|
|
||||||
|
// batch.setInputBuffer(gpu::Stream::NORMAL, mesh->getVertexBuffer()._buffer,
|
||||||
|
// 12,
|
||||||
|
// sizeof(PolyVox::PositionMaterialNormal));
|
||||||
|
|
||||||
|
|
||||||
batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0);
|
batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0);
|
||||||
|
|
||||||
if (!_xTextureURL.isEmpty() && !_xTexture) {
|
if (!_xTextureURL.isEmpty() && !_xTexture) {
|
||||||
|
@ -1287,23 +1296,26 @@ void RenderablePolyVoxEntityItem::recomputeMesh() {
|
||||||
auto indexBuffer = std::make_shared<gpu::Buffer>(vecIndices.size() * sizeof(uint32_t),
|
auto indexBuffer = std::make_shared<gpu::Buffer>(vecIndices.size() * sizeof(uint32_t),
|
||||||
(gpu::Byte*)vecIndices.data());
|
(gpu::Byte*)vecIndices.data());
|
||||||
auto indexBufferPtr = gpu::BufferPointer(indexBuffer);
|
auto indexBufferPtr = gpu::BufferPointer(indexBuffer);
|
||||||
gpu::BufferView indexBufferView(indexBufferPtr, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW));
|
gpu::BufferView indexBufferView(indexBufferPtr, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::INDEX));
|
||||||
mesh->setIndexBuffer(indexBufferView);
|
mesh->setIndexBuffer(indexBufferView);
|
||||||
|
|
||||||
const std::vector<PolyVox::PositionMaterialNormal>& vecVertices = polyVoxMesh.getVertices();
|
const std::vector<PolyVox::PositionMaterialNormal>& vecVertices = polyVoxMesh.getRawVertexData();
|
||||||
auto vertexBuffer = std::make_shared<gpu::Buffer>(vecVertices.size() * sizeof(PolyVox::PositionMaterialNormal),
|
auto vertexBuffer = std::make_shared<gpu::Buffer>(vecVertices.size() * sizeof(PolyVox::PositionMaterialNormal),
|
||||||
(gpu::Byte*)vecVertices.data());
|
(gpu::Byte*)vecVertices.data());
|
||||||
auto vertexBufferPtr = gpu::BufferPointer(vertexBuffer);
|
auto vertexBufferPtr = gpu::BufferPointer(vertexBuffer);
|
||||||
gpu::BufferView vertexBufferView(vertexBufferPtr, 0,
|
gpu::BufferView vertexBufferView(vertexBufferPtr, 0,
|
||||||
vertexBufferPtr->getSize(),
|
vertexBufferPtr->getSize(),
|
||||||
sizeof(PolyVox::PositionMaterialNormal),
|
sizeof(PolyVox::PositionMaterialNormal),
|
||||||
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW));
|
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ));
|
||||||
mesh->setVertexBuffer(vertexBufferView);
|
mesh->setVertexBuffer(vertexBufferView);
|
||||||
|
|
||||||
|
|
||||||
mesh->addAttribute(gpu::Stream::NORMAL,
|
mesh->addAttribute(gpu::Stream::NORMAL,
|
||||||
gpu::BufferView(vertexBufferPtr, sizeof(float) * 3,
|
gpu::BufferView(vertexBufferPtr,
|
||||||
vertexBufferPtr->getSize() ,
|
sizeof(float) * 3, // polyvox mesh is packed: position, normal, material
|
||||||
|
vertexBufferPtr->getSize(),
|
||||||
sizeof(PolyVox::PositionMaterialNormal),
|
sizeof(PolyVox::PositionMaterialNormal),
|
||||||
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)));
|
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ)));
|
||||||
|
|
||||||
std::vector<model::Mesh::Part> parts;
|
std::vector<model::Mesh::Part> parts;
|
||||||
parts.emplace_back(model::Mesh::Part((model::Index)0, // startIndex
|
parts.emplace_back(model::Mesh::Part((model::Index)0, // startIndex
|
||||||
|
@ -1626,10 +1638,10 @@ bool RenderablePolyVoxEntityItem::getMeshes(MeshProxyList& result) {
|
||||||
// the mesh will be in voxel-space. transform it into object-space
|
// the mesh will be in voxel-space. transform it into object-space
|
||||||
meshProxy = new MeshProxy(
|
meshProxy = new MeshProxy(
|
||||||
_mesh->map([=](glm::vec3 position){ return glm::vec3(transform * glm::vec4(position, 1.0f)); },
|
_mesh->map([=](glm::vec3 position){ return glm::vec3(transform * glm::vec4(position, 1.0f)); },
|
||||||
[=](glm::vec3 normal){ return glm::vec3(transform * glm::vec4(normal, 0.0f)); },
|
[=](glm::vec3 normal){ return glm::normalize(glm::vec3(transform * glm::vec4(normal, 0.0f))); },
|
||||||
[&](uint32_t index){ return index; }));
|
[&](uint32_t index){ return index; }));
|
||||||
result << meshProxy;
|
result << meshProxy;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return meshProxy;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ bool writeOBJToTextStream(QTextStream& out, QList<MeshPointer> meshes) {
|
||||||
foreach (const MeshPointer& mesh, meshes) {
|
foreach (const MeshPointer& mesh, meshes) {
|
||||||
meshNormalStartOffset.append(currentNormalStartOffset);
|
meshNormalStartOffset.append(currentNormalStartOffset);
|
||||||
const gpu::BufferView& normalsBufferView = mesh->getAttributeBuffer(attributeTypeNormal);
|
const gpu::BufferView& normalsBufferView = mesh->getAttributeBuffer(attributeTypeNormal);
|
||||||
gpu::BufferView::Index numNormals = (gpu::BufferView::Index)normalsBufferView.getNumElements();
|
gpu::BufferView::Index numNormals = (gpu::BufferView::Index)normalsBufferView.getNumElements();
|
||||||
for (gpu::BufferView::Index i = 0; i < numNormals; i++) {
|
for (gpu::BufferView::Index i = 0; i < numNormals; i++) {
|
||||||
glm::vec3 normal = normalsBufferView.get<glm::vec3>(i);
|
glm::vec3 normal = normalsBufferView.get<glm::vec3>(i);
|
||||||
out << "vn ";
|
out << "vn ";
|
||||||
|
|
|
@ -26,14 +26,8 @@ QScriptValue meshesToScriptValue(QScriptEngine* engine, const MeshProxyList &in)
|
||||||
QScriptValue result = engine->newArray();
|
QScriptValue result = engine->newArray();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (MeshProxy* const meshProxy, in) {
|
foreach (MeshProxy* const meshProxy, in) {
|
||||||
qDebug() << "meshesToScriptValue adding mesh: " << (void*)meshProxy;
|
|
||||||
// result.setProperty(i++, QScriptValue(engine, meshProxy));
|
|
||||||
result.setProperty(i++, meshToScriptValue(engine, meshProxy));
|
result.setProperty(i++, meshToScriptValue(engine, meshProxy));
|
||||||
// result.setProperty(QString::number(i++), QScriptValue(meshProxy));
|
|
||||||
// result[i] = QScriptValue(meshProxy);
|
|
||||||
// result << QScriptValue(meshProxy);
|
|
||||||
}
|
}
|
||||||
// result.setProperty("length", i);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue