mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:08:00 +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;
|
_partBuffer = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Box Mesh::evalPartBound(int partNum) const {
|
Box Mesh::evalPartBound(int partNum) const {
|
||||||
Box box;
|
Box box;
|
||||||
if (partNum < _partBuffer.getNum<Part>()) {
|
if (partNum < _partBuffer.getNum<Part>()) {
|
||||||
const Part& part = _partBuffer.get<Part>(partNum);
|
const Part& part = _partBuffer.get<Part>(partNum);
|
||||||
|
@ -111,7 +111,7 @@ const Box Mesh::evalPartBound(int partNum) const {
|
||||||
return box;
|
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;
|
Box totalBound;
|
||||||
auto part = _partBuffer.cbegin<Part>() + partStart;
|
auto part = _partBuffer.cbegin<Part>() + partStart;
|
||||||
auto partItEnd = _partBuffer.cbegin<Part>() + partEnd;
|
auto partItEnd = _partBuffer.cbegin<Part>() + partEnd;
|
||||||
|
|
|
@ -107,10 +107,10 @@ public:
|
||||||
uint getNumParts() const { return _partBuffer.getNumElements(); }
|
uint getNumParts() const { return _partBuffer.getNumElements(); }
|
||||||
|
|
||||||
// evaluate the bounding box of A part
|
// 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
|
// 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.
|
// 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); }
|
static gpu::Primitive topologyToPrimitive(Topology topo) { return static_cast<gpu::Primitive>(topo); }
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace render {
|
||||||
using namespace render;
|
using namespace render;
|
||||||
|
|
||||||
MeshPartPayload::MeshPartPayload(Model* model, model::MeshPointer drawMesh, int meshIndex, int partIndex, int shapeIndex,
|
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),
|
model(model),
|
||||||
_drawMesh(drawMesh),
|
_drawMesh(drawMesh),
|
||||||
meshIndex(meshIndex),
|
meshIndex(meshIndex),
|
||||||
|
@ -48,7 +48,7 @@ MeshPartPayload::MeshPartPayload(Model* model, model::MeshPointer drawMesh, int
|
||||||
_shapeID(shapeIndex),
|
_shapeID(shapeIndex),
|
||||||
_modelPosition(position),
|
_modelPosition(position),
|
||||||
_modelOrientation(orientation),
|
_modelOrientation(orientation),
|
||||||
_applyMeshJoints(applyMeshJoints) {
|
_isCollisionGeometry(isCollisionGeometry) {
|
||||||
initCache();
|
initCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,9 +58,13 @@ void MeshPartPayload::initCache() {
|
||||||
_hasColorAttrib = vertexFormat->hasAttribute(gpu::Stream::COLOR);
|
_hasColorAttrib = vertexFormat->hasAttribute(gpu::Stream::COLOR);
|
||||||
_isSkinned = vertexFormat->hasAttribute(gpu::Stream::SKIN_CLUSTER_WEIGHT) && vertexFormat->hasAttribute(gpu::Stream::SKIN_CLUSTER_INDEX);
|
_isSkinned = vertexFormat->hasAttribute(gpu::Stream::SKIN_CLUSTER_WEIGHT) && vertexFormat->hasAttribute(gpu::Stream::SKIN_CLUSTER_INDEX);
|
||||||
|
|
||||||
const FBXGeometry& geometry = model->_geometry->getFBXGeometry();
|
if (!_isCollisionGeometry) {
|
||||||
const FBXMesh& mesh = geometry.meshes.at(meshIndex);
|
const FBXGeometry& geometry = model->_geometry->getFBXGeometry();
|
||||||
_isBlendShaped = !mesh.blendshapes.isEmpty();
|
const FBXMesh& mesh = geometry.meshes.at(meshIndex);
|
||||||
|
_isBlendShaped = !mesh.blendshapes.isEmpty();
|
||||||
|
} else {
|
||||||
|
_isBlendShaped = false;
|
||||||
|
}
|
||||||
|
|
||||||
_drawPart = _drawMesh->getPartBuffer().get<model::Mesh::Part>(partIndex);
|
_drawPart = _drawMesh->getPartBuffer().get<model::Mesh::Part>(partIndex);
|
||||||
}
|
}
|
||||||
|
@ -106,7 +110,19 @@ render::ItemKey MeshPartPayload::getKey() const {
|
||||||
render::Item::Bound MeshPartPayload::getBound() const {
|
render::Item::Bound MeshPartPayload::getBound() const {
|
||||||
// NOTE: we can't cache this bounds because we need to handle the case of a moving
|
// NOTE: we can't cache this bounds because we need to handle the case of a moving
|
||||||
// entity or mesh part.
|
// 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 {
|
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 {
|
void MeshPartPayload::bindTransform(gpu::Batch& batch, const ModelRender::Locations* locations) const {
|
||||||
if (_applyMeshJoints) {
|
if (!_isCollisionGeometry) {
|
||||||
// Still relying on the raw data from the model
|
// Still relying on the raw data from the model
|
||||||
const Model::MeshState& state = model->_meshStates.at(meshIndex);
|
const Model::MeshState& state = model->_meshStates.at(meshIndex);
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Model;
|
||||||
|
|
||||||
class MeshPartPayload {
|
class MeshPartPayload {
|
||||||
public:
|
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 render::Payload<MeshPartPayload> Payload;
|
||||||
typedef Payload::DataPointer Pointer;
|
typedef Payload::DataPointer Pointer;
|
||||||
|
@ -60,10 +60,11 @@ public:
|
||||||
model::MeshPointer _drawMesh;
|
model::MeshPointer _drawMesh;
|
||||||
model::Mesh::Part _drawPart;
|
model::Mesh::Part _drawPart;
|
||||||
model::MaterialPointer _drawMaterial;
|
model::MaterialPointer _drawMaterial;
|
||||||
|
mutable model::Box _drawBound;
|
||||||
bool _hasColorAttrib = false;
|
bool _hasColorAttrib = false;
|
||||||
bool _isSkinned = false;
|
bool _isSkinned = false;
|
||||||
bool _isBlendShaped = false;
|
bool _isBlendShaped = false;
|
||||||
bool _applyMeshJoints = true;
|
bool _isCollisionGeometry = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
|
@ -1120,9 +1120,13 @@ AABox Model::getPartBounds(int meshIndex, int partIndex, glm::vec3 modelPosition
|
||||||
void Model::segregateMeshGroups() {
|
void Model::segregateMeshGroups() {
|
||||||
QSharedPointer<NetworkGeometry> networkGeometry;
|
QSharedPointer<NetworkGeometry> networkGeometry;
|
||||||
bool showingCollisionHull = false;
|
bool showingCollisionHull = false;
|
||||||
if (_showCollisionHull && _collisionGeometry && _collisionGeometry->isLoaded()) {
|
if (_showCollisionHull && _collisionGeometry) {
|
||||||
networkGeometry = _collisionGeometry;
|
if (_collisionGeometry->isLoaded()) {
|
||||||
showingCollisionHull = true;
|
networkGeometry = _collisionGeometry;
|
||||||
|
showingCollisionHull = true;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
networkGeometry = _geometry;
|
networkGeometry = _geometry;
|
||||||
}
|
}
|
||||||
|
@ -1152,7 +1156,7 @@ void Model::segregateMeshGroups() {
|
||||||
// Create the render payloads
|
// Create the render payloads
|
||||||
int totalParts = mesh.parts.size();
|
int totalParts = mesh.parts.size();
|
||||||
for (int partIndex = 0; partIndex < totalParts; partIndex++) {
|
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) {
|
if (showingCollisionHull) {
|
||||||
renderItem->updateDrawMaterial(ModelRender::getCollisionHullMaterial());
|
renderItem->updateDrawMaterial(ModelRender::getCollisionHullMaterial());
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,6 +287,8 @@ model::MaterialPointer ModelRender::getCollisionHullMaterial() {
|
||||||
if (!_collisionHullMaterial) {
|
if (!_collisionHullMaterial) {
|
||||||
_collisionHullMaterial = std::make_shared<model::Material>();
|
_collisionHullMaterial = std::make_shared<model::Material>();
|
||||||
_collisionHullMaterial->setDiffuse(glm::vec3(1.0f, 0.5f, 0.0f));
|
_collisionHullMaterial->setDiffuse(glm::vec3(1.0f, 0.5f, 0.0f));
|
||||||
|
_collisionHullMaterial->setMetallic(0.02f);
|
||||||
|
_collisionHullMaterial->setGloss(1.0f);
|
||||||
}
|
}
|
||||||
return _collisionHullMaterial;
|
return _collisionHullMaterial;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue