From ccd5ef80b3c4b89b5b9cc6ce11b744ba20dd4f89 Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Mon, 9 Nov 2020 19:14:30 -0800 Subject: [PATCH] remove isActive, fix contains, maybe fix green box issue --- interface/src/Application.cpp | 2 +- .../src/avatars-renderer/Avatar.cpp | 6 ++-- .../src/avatars-renderer/SkeletonModel.cpp | 12 +++---- .../src/avatars-renderer/SkeletonModel.h | 4 +-- .../src/RenderableModelEntityItem.cpp | 31 +++++++++++++------ libraries/render-utils/src/Model.cpp | 18 +++++------ libraries/render-utils/src/Model.h | 2 -- 7 files changed, 43 insertions(+), 32 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4e6ed35d2c..8df5a17e58 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -8663,7 +8663,7 @@ void Application::notifyPacketVersionMismatch() { } void Application::checkSkeleton() const { - if (getMyAvatar()->getSkeletonModel()->isActive() && !getMyAvatar()->getSkeletonModel()->hasSkeleton()) { + if (getMyAvatar()->getSkeletonModel()->isLoaded() && !getMyAvatar()->getSkeletonModel()->hasSkeleton()) { qCDebug(interfaceapp) << "MyAvatar model has no skeleton"; QString message = "Your selected avatar body has no skeleton.\n\nThe default body will be loaded..."; diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 16dc99ab49..d859454a99 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1246,7 +1246,7 @@ glm::quat Avatar::getAbsoluteJointRotationInObjectFrame(int index) const { } case CAMERA_MATRIX_INDEX: { glm::quat rotation; - if (_skeletonModel && _skeletonModel->isActive()) { + if (_skeletonModel && _skeletonModel->isLoaded()) { int headJointIndex = getJointIndex("Head"); if (headJointIndex >= 0) { _skeletonModel->getAbsoluteJointRotationInRigFrame(headJointIndex, rotation); @@ -1298,7 +1298,7 @@ glm::vec3 Avatar::getAbsoluteJointTranslationInObjectFrame(int index) const { } case CAMERA_MATRIX_INDEX: { glm::vec3 translation; - if (_skeletonModel && _skeletonModel->isActive()) { + if (_skeletonModel && _skeletonModel->isLoaded()) { int headJointIndex = getJointIndex("Head"); if (headJointIndex >= 0) { _skeletonModel->getAbsoluteJointTranslationInRigFrame(headJointIndex, translation); @@ -1427,7 +1427,7 @@ void Avatar::withValidJointIndicesCache(std::function const& worker) con QWriteLocker writeLock(&_modelJointIndicesCacheLock); if (!_modelJointsCached) { _modelJointIndicesCache.clear(); - if (_skeletonModel && _skeletonModel->isActive()) { + if (_skeletonModel && _skeletonModel->isLoaded()) { _modelJointIndicesCache = _skeletonModel->getHFMModel().jointIndices; _modelJointsCached = true; } diff --git a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp index ccc87c28f3..4950b86f75 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp @@ -176,7 +176,7 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { updateRenderItems(); } - if (!isActive() || !_owningAvatar->isMyAvatar()) { + if (!isLoaded() || !_owningAvatar->isMyAvatar()) { return; // only simulate for own avatar } @@ -255,19 +255,19 @@ bool SkeletonModel::getRightHandPosition(glm::vec3& position) const { } bool SkeletonModel::getHeadPosition(glm::vec3& headPosition) const { - return isActive() && getJointPositionInWorldFrame(_rig.indexOfJoint("Head"), headPosition); + return isLoaded() && getJointPositionInWorldFrame(_rig.indexOfJoint("Head"), headPosition); } bool SkeletonModel::getNeckPosition(glm::vec3& neckPosition) const { - return isActive() && getJointPositionInWorldFrame(_rig.indexOfJoint("Neck"), neckPosition); + return isLoaded() && getJointPositionInWorldFrame(_rig.indexOfJoint("Neck"), neckPosition); } bool SkeletonModel::getLocalNeckPosition(glm::vec3& neckPosition) const { - return isActive() && getJointPosition(_rig.indexOfJoint("Neck"), neckPosition); + return isLoaded() && getJointPosition(_rig.indexOfJoint("Neck"), neckPosition); } bool SkeletonModel::getEyeModelPositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const { - if (!isActive()) { + if (!isLoaded()) { return false; } @@ -361,7 +361,7 @@ void SkeletonModel::renderBoundingCollisionShapes(RenderArgs* args, gpu::Batch& } bool SkeletonModel::hasSkeleton() { - return isActive() ? _rig.indexOfJoint("Hips") != -1 : false; + return isLoaded() ? _rig.indexOfJoint("Hips") != -1 : false; } void SkeletonModel::onInvalidate() { diff --git a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h index 6b0bd79f0b..e24d969461 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h +++ b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h @@ -44,10 +44,10 @@ public: bool getIsJointOverridden(int jointIndex) const; /// Returns the index of the left hand joint, or -1 if not found. - int getLeftHandJointIndex() const { return isActive() ? _rig.indexOfJoint("LeftHand") : -1; } + int getLeftHandJointIndex() const { return isLoaded() ? _rig.indexOfJoint("LeftHand") : -1; } /// Returns the index of the right hand joint, or -1 if not found. - int getRightHandJointIndex() const { return isActive() ? _rig.indexOfJoint("RightHand") : -1; } + int getRightHandJointIndex() const { return isLoaded() ? _rig.indexOfJoint("RightHand") : -1; } bool getLeftGrabPosition(glm::vec3& position) const; bool getRightGrabPosition(glm::vec3& position) const; diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index c9e7362e62..e7eddf70a3 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -90,7 +90,7 @@ bool RenderableModelEntityItem::needsUpdateModelBounds() const { return false; } - if (!_dimensionsInitialized || !model->isActive()) { + if (!_dimensionsInitialized || !model->isLoaded()) { return false; } @@ -699,10 +699,23 @@ int RenderableModelEntityItem::avatarJointIndex(int modelJointIndex) { bool RenderableModelEntityItem::contains(const glm::vec3& point) const { auto model = getModel(); - if (model && _collisionGeometryResource && _collisionGeometryResource->isLoaded() && _collisionGeometryResource->isHFMModelLoaded() && EntityItem::contains(point)) { - glm::mat4 worldToHFMMatrix = model->getWorldToHFMMatrix(); - glm::vec3 hfmPoint = worldToHFMMatrix * glm::vec4(point, 1.0f); - return _collisionGeometryResource->getHFMModel().convexHullContains(hfmPoint); + if (model && model->isLoaded()) { + auto shapeType = getShapeType(); + if (shapeType == SHAPE_TYPE_COMPOUND || shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) { + if (_collisionGeometryResource && _collisionGeometryResource->isLoaded() && _collisionGeometryResource->isHFMModelLoaded() && EntityItem::contains(point)) { + glm::mat4 worldToHFMMatrix = model->getWorldToHFMMatrix(); + glm::vec3 hfmPoint = worldToHFMMatrix * glm::vec4(point, 1.0f); + return _collisionGeometryResource->getHFMModel().convexHullContains(hfmPoint); + } + } else if (shapeType >= SHAPE_TYPE_SIMPLE_HULL && shapeType <= SHAPE_TYPE_STATIC_MESH) { + if (EntityItem::contains(point)) { + glm::mat4 worldToHFMMatrix = model->getWorldToHFMMatrix(); + glm::vec3 hfmPoint = worldToHFMMatrix * glm::vec4(point, 1.0f); + return model->getHFMModel().convexHullContains(hfmPoint); + } + } else { + return EntityItem::contains(point); + } } return false; @@ -919,13 +932,13 @@ void RenderableModelEntityItem::locationChanged(bool tellPhysics, bool tellChild int RenderableModelEntityItem::getJointIndex(const QString& name) const { auto model = getModel(); - return (model && model->isActive()) ? model->getRig().indexOfJoint(name) : -1; + return (model && model->isLoaded()) ? model->getRig().indexOfJoint(name) : -1; } QStringList RenderableModelEntityItem::getJointNames() const { QStringList result; auto model = getModel(); - if (model && model->isActive()) { + if (model && model->isLoaded()) { const Rig& rig = model->getRig(); int jointCount = rig.getJointStateCount(); for (int jointIndex = 0; jointIndex < jointCount; jointIndex++) { @@ -1012,7 +1025,7 @@ void RenderableModelEntityItem::copyAnimationJointDataToModel() { }); if (changed) { - locationChanged(true, true); + locationChanged(); } } @@ -1215,6 +1228,7 @@ void ModelEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPoint model = std::make_shared(nullptr, entity.get(), _created); connect(model.get(), &Model::requestRenderUpdate, this, &ModelEntityRenderer::requestRenderUpdate); connect(model.get(), &Model::setURLFinished, this, [&](bool didVisualGeometryRequestSucceed) { + _didLastVisualGeometryRequestSucceed = didVisualGeometryRequestSucceed; const render::ScenePointer& scene = AbstractViewStateInterface::instance()->getMain3DScene(); render::Transaction transaction; transaction.updateItem(_renderItemID, [&](PayloadProxyInterface& self) { @@ -1235,7 +1249,6 @@ void ModelEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPoint emit DependencyManager::get()-> modelAddedToScene(entity->getEntityItemID(), NestableType::Entity, model); } - _didLastVisualGeometryRequestSucceed = didVisualGeometryRequestSucceed; entity->_originalTexturesRead = false; entity->_needsJointSimulation = true; entity->_needsToRescaleModel = true; diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 7262664ddb..1015c87038 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -338,7 +338,7 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g bool intersectedSomething = false; // if we aren't active, we can't pick yet... - if (!isActive()) { + if (!isLoaded()) { return intersectedSomething; } @@ -493,7 +493,7 @@ bool Model::findParabolaIntersectionAgainstSubMeshes(const glm::vec3& origin, co bool intersectedSomething = false; // if we aren't active, we can't pick yet... - if (!isActive()) { + if (!isLoaded()) { return intersectedSomething; } @@ -1168,7 +1168,7 @@ void Model::renderDebugMeshBoxes(gpu::Batch& batch, bool forward) { } Extents Model::getBindExtents() const { - if (!isActive()) { + if (!isLoaded()) { return Extents(); } const Extents& bindExtents = getHFMModel().bindExtents; @@ -1182,7 +1182,7 @@ glm::vec3 Model::getNaturalDimensions() const { } Extents Model::getMeshExtents() const { - if (!isActive()) { + if (!isLoaded()) { return Extents(); } const Extents& extents = getHFMModel().meshExtents; @@ -1196,7 +1196,7 @@ Extents Model::getMeshExtents() const { } Extents Model::getUnscaledMeshExtents() const { - if (!isActive()) { + if (!isLoaded()) { return Extents(); } @@ -1228,7 +1228,7 @@ void Model::setJointTranslation(int index, bool valid, const glm::vec3& translat } int Model::getParentJointIndex(int jointIndex) const { - return (isActive() && jointIndex != -1) ? getHFMModel().joints.at(jointIndex).parentIndex : -1; + return (isLoaded() && jointIndex != -1) ? getHFMModel().joints.at(jointIndex).parentIndex : -1; } void Model::setTextures(const QVariantMap& textures) { @@ -1329,7 +1329,7 @@ QStringList Model::getJointNames() const { Q_RETURN_ARG(QStringList, result)); return result; } - return isActive() ? getHFMModel().getJointNames() : QStringList(); + return isLoaded() ? getHFMModel().getJointNames() : QStringList(); } void Model::setScaleToFit(bool scaleToFit, const glm::vec3& dimensions, bool forceRescale) { @@ -1345,7 +1345,7 @@ void Model::setScaleToFit(bool scaleToFit, float largestDimension, bool forceRes // mesh, and so we can't do the needed calculations for scaling to fit to a single largest dimension. In this // case we will record that we do want to do this, but we will stick our desired single dimension into the // first element of the vec3 for the non-fixed aspect ration dimensions - if (!isActive()) { + if (!isLoaded()) { _scaleToFit = scaleToFit; if (scaleToFit) { _scaleToFitDimensions = glm::vec3(largestDimension, FAKE_DIMENSION_PLACEHOLDER, FAKE_DIMENSION_PLACEHOLDER); @@ -1426,7 +1426,7 @@ void Model::simulate(float deltaTime, bool fullUpdate) { fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit) || (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint); - if (isActive() && fullUpdate) { + if (isLoaded() && fullUpdate) { onInvalidate(); // check for scale to fit diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 255d2bfc12..1e7ab55d5a 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -183,8 +183,6 @@ public: const HFMModel& getHFMModel() const { assert(isLoaded()); return _renderGeometry->getHFMModel(); } const MaterialMapping& getMaterialMapping() const { assert(isLoaded()); return _renderGeometry->getMaterialMapping(); } - bool isActive() const { return isLoaded(); } - bool didVisualGeometryRequestFail() const { return _visualGeometryRequestFailed; } glm::mat4 getWorldToHFMMatrix() const;