diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index e3112c1265..ffd21d4f5c 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1759,12 +1759,11 @@ bool EntityItem::contains(const glm::vec3& point) const { ShapeType shapeType = getShapeType(); if (shapeType == SHAPE_TYPE_SPHERE) { - // SPHERE case is special: - // anything with shapeType == SPHERE must collide as a bounding sphere in the world-frame regardless of dimensions - // therefore we must do math using an unscaled localPoint relative to sphere center glm::vec3 dimensions = getScaledDimensions(); - glm::vec3 localPoint = point - (getWorldPosition() + getWorldOrientation() * (dimensions * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()) + getPivot())); - return glm::length2(localPoint) < glm::length2(0.5f * glm::max(dimensions.x, glm::max(dimensions.y, dimensions.z))); + if (dimensions.x == dimensions.y && dimensions.y == dimensions.z) { + glm::vec3 localPoint = point - (getWorldPosition() + getWorldOrientation() * (dimensions * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()) + getPivot())); + return glm::length2(localPoint) < glm::length2(0.5f * dimensions.x); + } } // we transform into the "normalized entity-frame" where the bounding box is centered on the origin @@ -1791,6 +1790,7 @@ bool EntityItem::contains(const glm::vec3& point) const { localPoint = glm::abs(localPoint); return glm::all(glm::lessThanEqual(localPoint, glm::vec3(NORMALIZED_HALF_SIDE))); } + case SHAPE_TYPE_SPHERE: case SHAPE_TYPE_ELLIPSOID: { // since we've transformed into the normalized space this is just a sphere-point intersection test return glm::length2(localPoint) <= NORMALIZED_RADIUS_SQUARED; diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index 3eabfb4f1e..abccdf7167 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -270,7 +270,6 @@ void ZoneEntityItem::debugDump() const { } void ZoneEntityItem::setShapeType(ShapeType type) { - ShapeType oldShapeType = _shapeType; switch(type) { case SHAPE_TYPE_NONE: case SHAPE_TYPE_CAPSULE_X: @@ -288,7 +287,12 @@ void ZoneEntityItem::setShapeType(ShapeType type) { default: break; } - _shapeType = type; + + ShapeType oldShapeType; + withWriteLock([&] { + oldShapeType = _shapeType; + _shapeType = type; + }); if (type == SHAPE_TYPE_COMPOUND) { if (type != oldShapeType) { @@ -300,16 +304,21 @@ void ZoneEntityItem::setShapeType(ShapeType type) { } ShapeType ZoneEntityItem::getShapeType() const { - return _shapeType; + return resultWithReadLock([&] { + return _shapeType; + }); } void ZoneEntityItem::setCompoundShapeURL(const QString& url) { - QString oldCompoundShapeURL = _compoundShapeURL; + QString oldCompoundShapeURL; + ShapeType shapeType; withWriteLock([&] { + oldCompoundShapeURL = _compoundShapeURL; _compoundShapeURL = url; + shapeType = _shapeType; }); if (oldCompoundShapeURL != url) { - if (_shapeType == SHAPE_TYPE_COMPOUND) { + if (shapeType == SHAPE_TYPE_COMPOUND) { fetchCollisionGeometryResource(); } else { _shapeResource.reset(); @@ -333,7 +342,7 @@ bool ZoneEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, c bool ZoneEntityItem::contains(const glm::vec3& point) const { GeometryResource::Pointer resource = _shapeResource; - if (_shapeType == SHAPE_TYPE_COMPOUND && resource) { + if (getShapeType() == SHAPE_TYPE_COMPOUND && resource) { if (resource->isLoaded()) { const HFMModel& hfmModel = resource->getHFMModel(); diff --git a/libraries/physics/src/ShapeFactory.cpp b/libraries/physics/src/ShapeFactory.cpp index ef5213df8f..5ac33f65bd 100644 --- a/libraries/physics/src/ShapeFactory.cpp +++ b/libraries/physics/src/ShapeFactory.cpp @@ -278,12 +278,6 @@ const btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) shape = new btBoxShape(glmToBullet(info.getHalfExtents())); } break; - case SHAPE_TYPE_SPHERE: { - glm::vec3 halfExtents = info.getHalfExtents(); - float radius = glm::max(halfExtents.x, glm::max(halfExtents.y, halfExtents.z)); - shape = new btSphereShape(radius); - } - break; case SHAPE_TYPE_MULTISPHERE: { std::vector positions; std::vector radiuses; @@ -297,6 +291,7 @@ const btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) shape->setMargin(MULTI_SPHERE_MARGIN); } break; + case SHAPE_TYPE_SPHERE: case SHAPE_TYPE_ELLIPSOID: { glm::vec3 halfExtents = info.getHalfExtents(); float radius = halfExtents.x; diff --git a/libraries/shared/src/ShapeInfo.cpp b/libraries/shared/src/ShapeInfo.cpp index c60d1c2574..f9d41022d7 100644 --- a/libraries/shared/src/ShapeInfo.cpp +++ b/libraries/shared/src/ShapeInfo.cpp @@ -115,12 +115,6 @@ void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QString case SHAPE_TYPE_HULL: case SHAPE_TYPE_MULTISPHERE: break; - case SHAPE_TYPE_SPHERE: { - float radius = glm::length(halfExtents) / SQUARE_ROOT_OF_3; - radius = glm::max(radius, MIN_HALF_EXTENT); - _halfExtents = glm::vec3(radius); - } - break; case SHAPE_TYPE_CIRCLE: { _halfExtents = glm::vec3(_halfExtents.x, MIN_HALF_EXTENT, _halfExtents.z); } @@ -228,6 +222,7 @@ float ShapeInfo::computeVolume() const { volume = 8.0f * _halfExtents.x * _halfExtents.y * _halfExtents.z; break; } + case SHAPE_TYPE_ELLIPSOID: case SHAPE_TYPE_SPHERE: { volume = 4.0f * PI * _halfExtents.x * _halfExtents.y * _halfExtents.z / 3.0f; break; diff --git a/scripts/system/create/entityProperties/html/js/entityProperties.js b/scripts/system/create/entityProperties/html/js/entityProperties.js index f9eb52a6bd..648b6a2bbc 100644 --- a/scripts/system/create/entityProperties/html/js/entityProperties.js +++ b/scripts/system/create/entityProperties/html/js/entityProperties.js @@ -281,7 +281,7 @@ const GROUPS = [ { label: "Shape Type", type: "dropdown", - options: { "box": "Box", "sphere": "Sphere", "ellipsoid": "Ellipsoid", + options: { "box": "Box", "sphere": "Sphere", "cylinder-y": "Cylinder", "compound": "Use Compound Shape URL" }, propertyID: "zoneShapeType", propertyName: "shapeType", // actual entity property name diff --git a/scripts/system/create/modules/entityShapeVisualizer.js b/scripts/system/create/modules/entityShapeVisualizer.js index 7a1cd74d25..8f218f3555 100644 --- a/scripts/system/create/modules/entityShapeVisualizer.js +++ b/scripts/system/create/modules/entityShapeVisualizer.js @@ -13,6 +13,7 @@ var SHAPETYPE_TO_SHAPE = { "box": "Cube", "ellipsoid": "Sphere", + "sphere": "Sphere", "cylinder-y": "Cylinder", }; @@ -35,14 +36,6 @@ function getEntityShapePropertiesForType(properties) { modelURL: properties.compoundShapeURL, localDimensions: properties.localDimensions }; - } else if (properties.shapeType === "sphere") { - var sphereDiameter = Math.max(properties.localDimensions.x, properties.localDimensions.y, - properties.localDimensions.z); - return { - type: "Sphere", - modelURL: properties.compoundShapeURL, - localDimensions: {x: sphereDiameter, y: sphereDiameter, z: sphereDiameter} - }; } break; }