mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 17:00:13 +02:00
fix static mesh for model with per-mesh transforms
This commit is contained in:
parent
5484b6fbb7
commit
f22a5613bd
1 changed files with 23 additions and 7 deletions
|
@ -707,6 +707,22 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
|
|
||||||
info.setParams(type, dimensions, _compoundShapeURL);
|
info.setParams(type, dimensions, _compoundShapeURL);
|
||||||
} else if (type == SHAPE_TYPE_MESH) {
|
} else if (type == SHAPE_TYPE_MESH) {
|
||||||
|
// compute meshPart local transforms
|
||||||
|
QVector<glm::mat4> localTransforms;
|
||||||
|
const FBXGeometry& geometry = _model->getFBXGeometry();
|
||||||
|
int numberOfMeshes = geometry.meshes.size();
|
||||||
|
for (int i = 0; i < numberOfMeshes; i++) {
|
||||||
|
const FBXMesh& mesh = geometry.meshes.at(i);
|
||||||
|
if (mesh.clusters.size() > 0) {
|
||||||
|
const FBXCluster& cluster = mesh.clusters.at(0);
|
||||||
|
auto jointMatrix = _model->getRig()->getJointTransform(cluster.jointIndex);
|
||||||
|
localTransforms.push_back(jointMatrix * cluster.inverseBindMatrix);
|
||||||
|
} else {
|
||||||
|
glm::mat4 identity;
|
||||||
|
localTransforms.push_back(identity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateModelBounds();
|
updateModelBounds();
|
||||||
|
|
||||||
// should never fall in here when collision model not fully loaded
|
// should never fall in here when collision model not fully loaded
|
||||||
|
@ -720,19 +736,21 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
auto& meshes = _model->getGeometry()->getGeometry()->getMeshes();
|
auto& meshes = _model->getGeometry()->getGeometry()->getMeshes();
|
||||||
|
|
||||||
Extents extents;
|
Extents extents;
|
||||||
glm::vec3 scaledModelOffset = _model->getOffset() * _model->getScale();
|
int meshCount = 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();
|
||||||
|
|
||||||
// copy points
|
// copy points
|
||||||
|
const glm::mat4& localTransform = localTransforms[meshCount];
|
||||||
uint32_t meshIndexOffset = (uint32_t)points.size();
|
uint32_t meshIndexOffset = (uint32_t)points.size();
|
||||||
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()));
|
points.reserve((int32_t)((gpu::Size)points.size() + vertices.getNumElements()));
|
||||||
while (vertexItr != vertices.cend<const glm::vec3>()) {
|
while (vertexItr != vertices.cend<const glm::vec3>()) {
|
||||||
points.push_back(*vertexItr);
|
glm::vec3 point = extractTranslation(localTransform * glm::translate(*vertexItr));
|
||||||
extents.addPoint(*vertexItr);
|
points.push_back(point);
|
||||||
|
extents.addPoint(point);
|
||||||
++vertexItr;
|
++vertexItr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -783,12 +801,10 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
}
|
}
|
||||||
++indexItr;
|
++indexItr;
|
||||||
}
|
}
|
||||||
} else if (partItr->_topology == model::Mesh::QUADS) {
|
|
||||||
// TODO: support model::Mesh::QUADS
|
|
||||||
}
|
}
|
||||||
// TODO? support model::Mesh::QUAD_STRIP?
|
|
||||||
++partItr;
|
++partItr;
|
||||||
}
|
}
|
||||||
|
++meshCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// scale and shift
|
// scale and shift
|
||||||
|
@ -800,7 +816,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < points.size(); ++i) {
|
for (int i = 0; i < points.size(); ++i) {
|
||||||
points[i] = (points[i] * scaleToFit) + scaledModelOffset;
|
points[i] = (points[i] * scaleToFit);
|
||||||
}
|
}
|
||||||
|
|
||||||
pointCollection.push_back(points);
|
pointCollection.push_back(points);
|
||||||
|
|
Loading…
Reference in a new issue