mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 20:13:35 +02:00
fix ZoneEntityItem::contains() for model shapes
This commit is contained in:
parent
a642af23b7
commit
13a3982b5a
6 changed files with 20 additions and 40 deletions
|
@ -367,8 +367,6 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
|
|||
const uint32_t QUAD_STRIDE = 4;
|
||||
|
||||
ShapeType type = getShapeType();
|
||||
glm::vec3 dimensions = getScaledDimensions();
|
||||
auto model = getModel();
|
||||
if (type == SHAPE_TYPE_COMPOUND) {
|
||||
updateModelBounds();
|
||||
|
||||
|
@ -450,6 +448,11 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
|
|||
// to the visual model and apply them to the collision model (without regard for the
|
||||
// collision model's extents).
|
||||
|
||||
auto model = getModel();
|
||||
// assert we never fall in here when model not fully loaded
|
||||
assert(model && model->isLoaded());
|
||||
|
||||
glm::vec3 dimensions = getScaledDimensions();
|
||||
glm::vec3 scaleToFit = dimensions / model->getHFMModel().getUnscaledMeshExtents().size();
|
||||
// multiply each point by scale before handing the point-set off to the physics engine.
|
||||
// also determine the extents of the collision model.
|
||||
|
@ -461,11 +464,12 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
|
|||
}
|
||||
}
|
||||
shapeInfo.setParams(type, dimensions, getCompoundShapeURL());
|
||||
adjustShapeInfoByRegistration(shapeInfo);
|
||||
} else if (type >= SHAPE_TYPE_SIMPLE_HULL && type <= SHAPE_TYPE_STATIC_MESH) {
|
||||
// TODO: assert we never fall in here when model not fully loaded
|
||||
// assert(_model && _model->isLoaded());
|
||||
|
||||
updateModelBounds();
|
||||
auto model = getModel();
|
||||
// assert we never fall in here when model not fully loaded
|
||||
assert(model && model->isLoaded());
|
||||
model->updateGeometry();
|
||||
|
||||
// compute meshPart local transforms
|
||||
|
@ -473,6 +477,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
|
|||
const HFMModel& hfmModel = model->getHFMModel();
|
||||
int numHFMMeshes = hfmModel.meshes.size();
|
||||
int totalNumVertices = 0;
|
||||
glm::vec3 dimensions = getScaledDimensions();
|
||||
glm::mat4 invRegistraionOffset = glm::translate(dimensions * (getRegistrationPoint() - ENTITY_ITEM_DEFAULT_REGISTRATION_POINT));
|
||||
for (int i = 0; i < numHFMMeshes; i++) {
|
||||
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
||||
|
@ -695,12 +700,10 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
|
|||
}
|
||||
|
||||
shapeInfo.setParams(type, 0.5f * dimensions, getModelURL());
|
||||
adjustShapeInfoByRegistration(shapeInfo);
|
||||
} else {
|
||||
ModelEntityItem::computeShapeInfo(shapeInfo);
|
||||
shapeInfo.setParams(type, 0.5f * dimensions);
|
||||
EntityItem::computeShapeInfo(shapeInfo);
|
||||
}
|
||||
// finally apply the registration offset to the shapeInfo
|
||||
adjustShapeInfoByRegistration(shapeInfo);
|
||||
}
|
||||
|
||||
void RenderableModelEntityItem::setJointMap(std::vector<int> jointMap) {
|
||||
|
|
|
@ -546,22 +546,3 @@ void ZoneEntityRenderer::setProceduralUserData(const QString& userData) {
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool RenderableZoneEntityItem::contains(const glm::vec3& point) const {
|
||||
if (getShapeType() != SHAPE_TYPE_COMPOUND) {
|
||||
return EntityItem::contains(point);
|
||||
}
|
||||
const_cast<RenderableZoneEntityItem*>(this)->updateGeometry();
|
||||
|
||||
if (_model && _model->isActive() && EntityItem::contains(point)) {
|
||||
return _model->convexHullContains(point);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void RenderableZoneEntityItem::notifyBoundChanged() {
|
||||
notifyChangedRenderItem();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -345,11 +345,10 @@ bool ZoneEntityItem::contains(const glm::vec3& point) const {
|
|||
if (resource->isLoaded()) {
|
||||
const HFMModel& hfmModel = resource->getHFMModel();
|
||||
|
||||
glm::vec3 minimum = glm::vec3(hfmModel.offset * glm::vec4(hfmModel.meshExtents.minimum, 1.0f));
|
||||
glm::vec3 maximum = glm::vec3(hfmModel.offset * glm::vec4(hfmModel.meshExtents.maximum, 1.0f));
|
||||
glm::vec3 modelExtentsDiagonal = maximum - minimum;
|
||||
glm::vec3 offset = -minimum - (modelExtentsDiagonal * getRegistrationPoint());
|
||||
glm::vec3 scale(getScaledDimensions() / modelExtentsDiagonal);
|
||||
Extents meshExtents = hfmModel.getMeshExtents();
|
||||
glm::vec3 meshExtentsDiagonal = meshExtents.maximum - meshExtents.minimum;
|
||||
glm::vec3 offset = -meshExtents.minimum- (meshExtentsDiagonal * getRegistrationPoint());
|
||||
glm::vec3 scale(getScaledDimensions() / meshExtentsDiagonal);
|
||||
|
||||
glm::mat4 hfmToEntityMatrix = glm::scale(scale) * glm::translate(offset);
|
||||
glm::mat4 entityToWorldMatrix = getTransform().getMatrix();
|
||||
|
|
|
@ -189,20 +189,17 @@ bool HFMModel::hasBlendedMeshes() const {
|
|||
}
|
||||
|
||||
Extents HFMModel::getUnscaledMeshExtents() const {
|
||||
const Extents& extents = meshExtents;
|
||||
|
||||
// even though our caller asked for "unscaled" we need to include any fst scaling, translation, and rotation, which
|
||||
// is captured in the offset matrix
|
||||
glm::vec3 minimum = glm::vec3(offset * glm::vec4(extents.minimum, 1.0f));
|
||||
glm::vec3 maximum = glm::vec3(offset * glm::vec4(extents.maximum, 1.0f));
|
||||
glm::vec3 minimum = glm::vec3(offset * glm::vec4(meshExtents.minimum, 1.0f));
|
||||
glm::vec3 maximum = glm::vec3(offset * glm::vec4(meshExtents.maximum, 1.0f));
|
||||
Extents scaledExtents = { minimum, maximum };
|
||||
|
||||
return scaledExtents;
|
||||
}
|
||||
|
||||
// TODO: Move to graphics::Mesh when Sam's ready
|
||||
bool HFMModel::convexHullContains(const glm::vec3& point) const {
|
||||
if (!getUnscaledMeshExtents().containsPoint(point)) {
|
||||
if (!meshExtents.containsPoint(point)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -310,6 +310,7 @@ public:
|
|||
|
||||
/// Returns the unscaled extents of the model's mesh
|
||||
Extents getUnscaledMeshExtents() const;
|
||||
const Extents& getMeshExtents() const { return meshExtents; }
|
||||
|
||||
bool convexHullContains(const glm::vec3& point) const;
|
||||
|
||||
|
|
|
@ -91,7 +91,6 @@ EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer
|
|||
_serverRotation = localTransform.getRotation();
|
||||
_serverAcceleration = _entity->getAcceleration();
|
||||
_serverActionData = _entity->getDynamicData();
|
||||
|
||||
}
|
||||
|
||||
EntityMotionState::~EntityMotionState() {
|
||||
|
|
Loading…
Reference in a new issue