mirror of
https://github.com/lubosz/overte.git
synced 2025-04-19 12:24:01 +02:00
Trying to redner the collision geometry correctly but still an issue with the bounding box i get
This commit is contained in:
parent
1adf2cc8ba
commit
9eb40bcd65
6 changed files with 40 additions and 17 deletions
|
@ -92,7 +92,7 @@ void Mesh::setPartBuffer(const BufferView& buffer) {
|
|||
_partBuffer = buffer;
|
||||
}
|
||||
|
||||
const Box Mesh::evalPartBound(int partNum) const {
|
||||
Box Mesh::evalPartBound(int partNum) const {
|
||||
Box box;
|
||||
if (partNum < _partBuffer.getNum<Part>()) {
|
||||
const Part& part = _partBuffer.get<Part>(partNum);
|
||||
|
@ -111,7 +111,7 @@ const Box Mesh::evalPartBound(int partNum) const {
|
|||
return box;
|
||||
}
|
||||
|
||||
const Box Mesh::evalPartBounds(int partStart, int partEnd, Boxes& bounds) const {
|
||||
Box Mesh::evalPartBounds(int partStart, int partEnd, Boxes& bounds) const {
|
||||
Box totalBound;
|
||||
auto part = _partBuffer.cbegin<Part>() + partStart;
|
||||
auto partItEnd = _partBuffer.cbegin<Part>() + partEnd;
|
||||
|
|
|
@ -107,10 +107,10 @@ public:
|
|||
uint getNumParts() const { return _partBuffer.getNumElements(); }
|
||||
|
||||
// evaluate the bounding box of A part
|
||||
const Box evalPartBound(int partNum) const;
|
||||
Box evalPartBound(int partNum) const;
|
||||
// evaluate the bounding boxes of the parts in the range [start, end[ and fill the bounds parameter
|
||||
// the returned box is the bounding box of ALL the evaluated part bounds.
|
||||
const Box evalPartBounds(int partStart, int partEnd, Boxes& bounds) const;
|
||||
Box evalPartBounds(int partStart, int partEnd, Boxes& bounds) const;
|
||||
|
||||
static gpu::Primitive topologyToPrimitive(Topology topo) { return static_cast<gpu::Primitive>(topo); }
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace render {
|
|||
using namespace render;
|
||||
|
||||
MeshPartPayload::MeshPartPayload(Model* model, model::MeshPointer drawMesh, int meshIndex, int partIndex, int shapeIndex,
|
||||
glm::vec3 position, glm::quat orientation, bool applyMeshJoints) :
|
||||
glm::vec3 position, glm::quat orientation, bool isCollisionGeometry) :
|
||||
model(model),
|
||||
_drawMesh(drawMesh),
|
||||
meshIndex(meshIndex),
|
||||
|
@ -48,7 +48,7 @@ MeshPartPayload::MeshPartPayload(Model* model, model::MeshPointer drawMesh, int
|
|||
_shapeID(shapeIndex),
|
||||
_modelPosition(position),
|
||||
_modelOrientation(orientation),
|
||||
_applyMeshJoints(applyMeshJoints) {
|
||||
_isCollisionGeometry(isCollisionGeometry) {
|
||||
initCache();
|
||||
}
|
||||
|
||||
|
@ -58,9 +58,13 @@ void MeshPartPayload::initCache() {
|
|||
_hasColorAttrib = vertexFormat->hasAttribute(gpu::Stream::COLOR);
|
||||
_isSkinned = vertexFormat->hasAttribute(gpu::Stream::SKIN_CLUSTER_WEIGHT) && vertexFormat->hasAttribute(gpu::Stream::SKIN_CLUSTER_INDEX);
|
||||
|
||||
const FBXGeometry& geometry = model->_geometry->getFBXGeometry();
|
||||
const FBXMesh& mesh = geometry.meshes.at(meshIndex);
|
||||
_isBlendShaped = !mesh.blendshapes.isEmpty();
|
||||
if (!_isCollisionGeometry) {
|
||||
const FBXGeometry& geometry = model->_geometry->getFBXGeometry();
|
||||
const FBXMesh& mesh = geometry.meshes.at(meshIndex);
|
||||
_isBlendShaped = !mesh.blendshapes.isEmpty();
|
||||
} else {
|
||||
_isBlendShaped = false;
|
||||
}
|
||||
|
||||
_drawPart = _drawMesh->getPartBuffer().get<model::Mesh::Part>(partIndex);
|
||||
}
|
||||
|
@ -106,7 +110,19 @@ render::ItemKey MeshPartPayload::getKey() const {
|
|||
render::Item::Bound MeshPartPayload::getBound() const {
|
||||
// NOTE: we can't cache this bounds because we need to handle the case of a moving
|
||||
// entity or mesh part.
|
||||
return model->getPartBounds(meshIndex, partIndex, _modelPosition, _modelOrientation);
|
||||
if (_isCollisionGeometry) {
|
||||
if (_drawMesh && _drawBound.isNull()) {
|
||||
_drawBound = _drawMesh->evalPartBound(partIndex);
|
||||
}
|
||||
// If we not skinned use the bounds of the subMesh for all it's parts
|
||||
const FBXMesh& mesh = model->_collisionGeometry->getFBXGeometry().meshes.at(meshIndex);
|
||||
auto otherBound = model->calculateScaledOffsetExtents(mesh.meshExtents, _modelPosition, _modelOrientation);
|
||||
|
||||
return model->getPartBounds(0, 0, _modelPosition, _modelOrientation);
|
||||
|
||||
} else {
|
||||
return model->getPartBounds(meshIndex, partIndex, _modelPosition, _modelOrientation);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshPartPayload::drawCall(gpu::Batch& batch) const {
|
||||
|
@ -220,7 +236,7 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ModelRender::Locatio
|
|||
}
|
||||
|
||||
void MeshPartPayload::bindTransform(gpu::Batch& batch, const ModelRender::Locations* locations) const {
|
||||
if (_applyMeshJoints) {
|
||||
if (!_isCollisionGeometry) {
|
||||
// Still relying on the raw data from the model
|
||||
const Model::MeshState& state = model->_meshStates.at(meshIndex);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class Model;
|
|||
|
||||
class MeshPartPayload {
|
||||
public:
|
||||
MeshPartPayload(Model* model, model::MeshPointer drawMesh, int meshIndex, int partIndex, int shapeIndex, glm::vec3 position, glm::quat orientation, bool applyMeshJoints = true);
|
||||
MeshPartPayload(Model* model, model::MeshPointer drawMesh, int meshIndex, int partIndex, int shapeIndex, glm::vec3 position, glm::quat orientation, bool isCollisionGeometry = false);
|
||||
|
||||
typedef render::Payload<MeshPartPayload> Payload;
|
||||
typedef Payload::DataPointer Pointer;
|
||||
|
@ -60,10 +60,11 @@ public:
|
|||
model::MeshPointer _drawMesh;
|
||||
model::Mesh::Part _drawPart;
|
||||
model::MaterialPointer _drawMaterial;
|
||||
mutable model::Box _drawBound;
|
||||
bool _hasColorAttrib = false;
|
||||
bool _isSkinned = false;
|
||||
bool _isBlendShaped = false;
|
||||
bool _applyMeshJoints = true;
|
||||
bool _isCollisionGeometry = false;
|
||||
};
|
||||
|
||||
namespace render {
|
||||
|
|
|
@ -1120,9 +1120,13 @@ AABox Model::getPartBounds(int meshIndex, int partIndex, glm::vec3 modelPosition
|
|||
void Model::segregateMeshGroups() {
|
||||
QSharedPointer<NetworkGeometry> networkGeometry;
|
||||
bool showingCollisionHull = false;
|
||||
if (_showCollisionHull && _collisionGeometry && _collisionGeometry->isLoaded()) {
|
||||
networkGeometry = _collisionGeometry;
|
||||
showingCollisionHull = true;
|
||||
if (_showCollisionHull && _collisionGeometry) {
|
||||
if (_collisionGeometry->isLoaded()) {
|
||||
networkGeometry = _collisionGeometry;
|
||||
showingCollisionHull = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
networkGeometry = _geometry;
|
||||
}
|
||||
|
@ -1152,7 +1156,7 @@ void Model::segregateMeshGroups() {
|
|||
// Create the render payloads
|
||||
int totalParts = mesh.parts.size();
|
||||
for (int partIndex = 0; partIndex < totalParts; partIndex++) {
|
||||
auto renderItem = std::make_shared<MeshPartPayload>(this, networkMesh._mesh, i, partIndex, shapeID, _translation, _rotation, !showingCollisionHull);
|
||||
auto renderItem = std::make_shared<MeshPartPayload>(this, networkMesh._mesh, i, partIndex, shapeID, _translation, _rotation, showingCollisionHull);
|
||||
if (showingCollisionHull) {
|
||||
renderItem->updateDrawMaterial(ModelRender::getCollisionHullMaterial());
|
||||
}
|
||||
|
|
|
@ -287,6 +287,8 @@ model::MaterialPointer ModelRender::getCollisionHullMaterial() {
|
|||
if (!_collisionHullMaterial) {
|
||||
_collisionHullMaterial = std::make_shared<model::Material>();
|
||||
_collisionHullMaterial->setDiffuse(glm::vec3(1.0f, 0.5f, 0.0f));
|
||||
_collisionHullMaterial->setMetallic(0.02f);
|
||||
_collisionHullMaterial->setGloss(1.0f);
|
||||
}
|
||||
return _collisionHullMaterial;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue