mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 06:23:06 +02:00
construct geometry for new shape types
This commit is contained in:
parent
431043e195
commit
33d732c446
1 changed files with 83 additions and 61 deletions
|
@ -423,7 +423,8 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
||||||
|
|
||||||
// check to see if when we added our models to the scene they were ready, if they were not ready, then
|
// check to see if when we added our models to the scene they were ready, if they were not ready, then
|
||||||
// fix them up in the scene
|
// fix them up in the scene
|
||||||
bool shouldShowCollisionHull = (args->_debugFlags & (int)RenderArgs::RENDER_DEBUG_HULLS) > 0;
|
bool shouldShowCollisionHull = (args->_debugFlags & (int)RenderArgs::RENDER_DEBUG_HULLS) > 0
|
||||||
|
&& getShapeType() == SHAPE_TYPE_COMPOUND;
|
||||||
if (_model->needsFixupInScene() || _showCollisionHull != shouldShowCollisionHull) {
|
if (_model->needsFixupInScene() || _showCollisionHull != shouldShowCollisionHull) {
|
||||||
_showCollisionHull = shouldShowCollisionHull;
|
_showCollisionHull = shouldShowCollisionHull;
|
||||||
render::PendingChanges pendingChanges;
|
render::PendingChanges pendingChanges;
|
||||||
|
@ -691,7 +692,13 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info.setParams(type, dimensions, _compoundShapeURL);
|
info.setParams(type, dimensions, _compoundShapeURL);
|
||||||
} else if (type == SHAPE_TYPE_STATIC_MESH) {
|
assert(pointCollection.size() > 0); // adebug
|
||||||
|
} else if (type >= SHAPE_TYPE_SIMPLE_HULL && type <= SHAPE_TYPE_STATIC_MESH) {
|
||||||
|
updateModelBounds();
|
||||||
|
|
||||||
|
// should never fall in here when model not fully loaded
|
||||||
|
assert(_model->isLoaded());
|
||||||
|
|
||||||
// compute meshPart local transforms
|
// compute meshPart local transforms
|
||||||
QVector<glm::mat4> localTransforms;
|
QVector<glm::mat4> localTransforms;
|
||||||
const FBXGeometry& geometry = _model->getFBXGeometry();
|
const FBXGeometry& geometry = _model->getFBXGeometry();
|
||||||
|
@ -716,30 +723,42 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateModelBounds();
|
auto& meshes = _model->getGeometry()->getGeometry()->getMeshes();
|
||||||
|
int32_t numMeshes = (int32_t)(meshes.size());
|
||||||
// should never fall in here when collision model not fully loaded
|
|
||||||
assert(_model->isLoaded());
|
|
||||||
|
|
||||||
ShapeInfo::PointCollection& pointCollection = info.getPointCollection();
|
ShapeInfo::PointCollection& pointCollection = info.getPointCollection();
|
||||||
pointCollection.clear();
|
pointCollection.clear();
|
||||||
|
if (type == SHAPE_TYPE_SIMPLE_COMPOUND) {
|
||||||
ShapeInfo::PointList points;
|
pointCollection.resize(numMeshes);
|
||||||
ShapeInfo::TriangleIndices& triangleIndices = info.getTriangleIndices();
|
} else {
|
||||||
auto& meshes = _model->getGeometry()->getGeometry()->getMeshes();
|
pointCollection.resize(1);
|
||||||
|
}
|
||||||
|
|
||||||
Extents extents;
|
Extents extents;
|
||||||
int meshCount = 0;
|
int meshCount = 0;
|
||||||
|
int pointListIndex = 0;
|
||||||
for (auto& mesh : meshes) {
|
for (auto& mesh : meshes) {
|
||||||
const gpu::BufferView& vertices = mesh->getVertexBuffer();
|
const gpu::BufferView& vertices = mesh->getVertexBuffer();
|
||||||
const gpu::BufferView& indices = mesh->getIndexBuffer();
|
const gpu::BufferView& indices = mesh->getIndexBuffer();
|
||||||
const gpu::BufferView& parts = mesh->getPartBuffer();
|
const gpu::BufferView& parts = mesh->getPartBuffer();
|
||||||
|
|
||||||
|
ShapeInfo::PointList& points = pointCollection[pointListIndex];
|
||||||
|
|
||||||
|
// reserve room
|
||||||
|
int32_t sizeToReserve = (int32_t)(vertices.getNumElements());
|
||||||
|
if (type == SHAPE_TYPE_SIMPLE_COMPOUND) {
|
||||||
|
// a list of points for each mesh
|
||||||
|
pointListIndex++;
|
||||||
|
} else {
|
||||||
|
// only one list of points
|
||||||
|
sizeToReserve += (int32_t)((gpu::Size)points.size());
|
||||||
|
}
|
||||||
|
points.reserve(sizeToReserve);
|
||||||
|
|
||||||
// copy points
|
// copy points
|
||||||
const glm::mat4& localTransform = localTransforms[meshCount];
|
|
||||||
uint32_t meshIndexOffset = (uint32_t)points.size();
|
uint32_t meshIndexOffset = (uint32_t)points.size();
|
||||||
|
const glm::mat4& localTransform = localTransforms[meshCount];
|
||||||
gpu::BufferView::Iterator<const glm::vec3> vertexItr = vertices.cbegin<const glm::vec3>();
|
gpu::BufferView::Iterator<const glm::vec3> vertexItr = vertices.cbegin<const glm::vec3>();
|
||||||
points.reserve((int32_t)((gpu::Size)points.size() + vertices.getNumElements()));
|
|
||||||
while (vertexItr != vertices.cend<const glm::vec3>()) {
|
while (vertexItr != vertices.cend<const glm::vec3>()) {
|
||||||
glm::vec3 point = extractTranslation(localTransform * glm::translate(*vertexItr));
|
glm::vec3 point = extractTranslation(localTransform * glm::translate(*vertexItr));
|
||||||
points.push_back(point);
|
points.push_back(point);
|
||||||
|
@ -747,55 +766,57 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
++vertexItr;
|
++vertexItr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy triangleIndices
|
if (type == SHAPE_TYPE_STATIC_MESH) {
|
||||||
triangleIndices.reserve((int32_t)((gpu::Size)(triangleIndices.size()) + indices.getNumElements()));
|
// copy into triangleIndices
|
||||||
gpu::BufferView::Iterator<const model::Mesh::Part> partItr = parts.cbegin<const model::Mesh::Part>();
|
ShapeInfo::TriangleIndices& triangleIndices = info.getTriangleIndices();
|
||||||
while (partItr != parts.cend<const model::Mesh::Part>()) {
|
triangleIndices.reserve((int32_t)((gpu::Size)(triangleIndices.size()) + indices.getNumElements()));
|
||||||
|
gpu::BufferView::Iterator<const model::Mesh::Part> partItr = parts.cbegin<const model::Mesh::Part>();
|
||||||
if (partItr->_topology == model::Mesh::TRIANGLES) {
|
while (partItr != parts.cend<const model::Mesh::Part>()) {
|
||||||
assert(partItr->_numIndices % 3 == 0);
|
if (partItr->_topology == model::Mesh::TRIANGLES) {
|
||||||
auto indexItr = indices.cbegin<const gpu::BufferView::Index>() + partItr->_startIndex;
|
assert(partItr->_numIndices % 3 == 0);
|
||||||
auto indexEnd = indexItr + partItr->_numIndices;
|
auto indexItr = indices.cbegin<const gpu::BufferView::Index>() + partItr->_startIndex;
|
||||||
while (indexItr != indexEnd) {
|
auto indexEnd = indexItr + partItr->_numIndices;
|
||||||
triangleIndices.push_back(*indexItr + meshIndexOffset);
|
while (indexItr != indexEnd) {
|
||||||
++indexItr;
|
|
||||||
}
|
|
||||||
} else if (partItr->_topology == model::Mesh::TRIANGLE_STRIP) {
|
|
||||||
assert(partItr->_numIndices > 2);
|
|
||||||
uint32_t approxNumIndices = 3 * partItr->_numIndices;
|
|
||||||
if (approxNumIndices > (uint32_t)(triangleIndices.capacity() - triangleIndices.size())) {
|
|
||||||
// we underestimated the final size of triangleIndices so we pre-emptively expand it
|
|
||||||
triangleIndices.reserve(triangleIndices.size() + approxNumIndices);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto indexItr = indices.cbegin<const gpu::BufferView::Index>() + partItr->_startIndex;
|
|
||||||
auto indexEnd = indexItr + (partItr->_numIndices - 2);
|
|
||||||
|
|
||||||
// first triangle uses the first three indices
|
|
||||||
triangleIndices.push_back(*(indexItr++) + meshIndexOffset);
|
|
||||||
triangleIndices.push_back(*(indexItr++) + meshIndexOffset);
|
|
||||||
triangleIndices.push_back(*(indexItr++) + meshIndexOffset);
|
|
||||||
|
|
||||||
// the rest use previous and next index
|
|
||||||
uint32_t triangleCount = 1;
|
|
||||||
while (indexItr != indexEnd) {
|
|
||||||
if ((*indexItr) != model::Mesh::PRIMITIVE_RESTART_INDEX) {
|
|
||||||
if (triangleCount % 2 == 0) {
|
|
||||||
// even triangles use first two indices in order
|
|
||||||
triangleIndices.push_back(*(indexItr - 2) + meshIndexOffset);
|
|
||||||
triangleIndices.push_back(*(indexItr - 1) + meshIndexOffset);
|
|
||||||
} else {
|
|
||||||
// odd triangles swap order of first two indices
|
|
||||||
triangleIndices.push_back(*(indexItr - 1) + meshIndexOffset);
|
|
||||||
triangleIndices.push_back(*(indexItr - 2) + meshIndexOffset);
|
|
||||||
}
|
|
||||||
triangleIndices.push_back(*indexItr + meshIndexOffset);
|
triangleIndices.push_back(*indexItr + meshIndexOffset);
|
||||||
++triangleCount;
|
++indexItr;
|
||||||
|
}
|
||||||
|
} else if (partItr->_topology == model::Mesh::TRIANGLE_STRIP) {
|
||||||
|
assert(partItr->_numIndices > 2);
|
||||||
|
uint32_t approxNumIndices = 3 * partItr->_numIndices;
|
||||||
|
if (approxNumIndices > (uint32_t)(triangleIndices.capacity() - triangleIndices.size())) {
|
||||||
|
// we underestimated the final size of triangleIndices so we pre-emptively expand it
|
||||||
|
triangleIndices.reserve(triangleIndices.size() + approxNumIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto indexItr = indices.cbegin<const gpu::BufferView::Index>() + partItr->_startIndex;
|
||||||
|
auto indexEnd = indexItr + (partItr->_numIndices - 2);
|
||||||
|
|
||||||
|
// first triangle uses the first three indices
|
||||||
|
triangleIndices.push_back(*(indexItr++) + meshIndexOffset);
|
||||||
|
triangleIndices.push_back(*(indexItr++) + meshIndexOffset);
|
||||||
|
triangleIndices.push_back(*(indexItr++) + meshIndexOffset);
|
||||||
|
|
||||||
|
// the rest use previous and next index
|
||||||
|
uint32_t triangleCount = 1;
|
||||||
|
while (indexItr != indexEnd) {
|
||||||
|
if ((*indexItr) != model::Mesh::PRIMITIVE_RESTART_INDEX) {
|
||||||
|
if (triangleCount % 2 == 0) {
|
||||||
|
// even triangles use first two indices in order
|
||||||
|
triangleIndices.push_back(*(indexItr - 2) + meshIndexOffset);
|
||||||
|
triangleIndices.push_back(*(indexItr - 1) + meshIndexOffset);
|
||||||
|
} else {
|
||||||
|
// odd triangles swap order of first two indices
|
||||||
|
triangleIndices.push_back(*(indexItr - 1) + meshIndexOffset);
|
||||||
|
triangleIndices.push_back(*(indexItr - 2) + meshIndexOffset);
|
||||||
|
}
|
||||||
|
triangleIndices.push_back(*indexItr + meshIndexOffset);
|
||||||
|
++triangleCount;
|
||||||
|
}
|
||||||
|
++indexItr;
|
||||||
}
|
}
|
||||||
++indexItr;
|
|
||||||
}
|
}
|
||||||
|
++partItr;
|
||||||
}
|
}
|
||||||
++partItr;
|
|
||||||
}
|
}
|
||||||
++meshCount;
|
++meshCount;
|
||||||
}
|
}
|
||||||
|
@ -808,12 +829,13 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
scaleToFit[i] = 1.0f;
|
scaleToFit[i] = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < points.size(); ++i) {
|
for (auto points : pointCollection) {
|
||||||
points[i] = (points[i] * scaleToFit);
|
for (int i = 0; i < points.size(); ++i) {
|
||||||
|
points[i] = (points[i] * scaleToFit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pointCollection.push_back(points);
|
info.setParams(type, 0.5f * dimensions, _modelURL);
|
||||||
info.setParams(SHAPE_TYPE_STATIC_MESH, 0.5f * dimensions, _modelURL);
|
|
||||||
} else {
|
} else {
|
||||||
ModelEntityItem::computeShapeInfo(info);
|
ModelEntityItem::computeShapeInfo(info);
|
||||||
info.setParams(type, 0.5f * dimensions);
|
info.setParams(type, 0.5f * dimensions);
|
||||||
|
|
Loading…
Reference in a new issue