From 901e14571211dd2a769aa4cdf96996838603ad26 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 26 Oct 2017 22:57:33 -0700 Subject: [PATCH 1/5] remove redundant dimensionsChanged() --- libraries/entities/src/EntityItem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 008ec9769f..059e6bf151 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1754,7 +1754,6 @@ void EntityItem::updateDimensions(const glm::vec3& value) { setDimensions(value); markDirtyFlags(Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS); _queryAACubeSet = false; - dimensionsChanged(); } } From 474609dabf1cab9d65c886281dfa49e56b14f9f6 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 26 Oct 2017 22:58:24 -0700 Subject: [PATCH 2/5] enforce dimensions of Circles and Quads --- libraries/entities/src/ShapeEntityItem.cpp | 44 ++++++++++++---------- libraries/entities/src/ShapeEntityItem.h | 2 + 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/libraries/entities/src/ShapeEntityItem.cpp b/libraries/entities/src/ShapeEntityItem.cpp index 9a1a500a54..8c7d1576e1 100644 --- a/libraries/entities/src/ShapeEntityItem.cpp +++ b/libraries/entities/src/ShapeEntityItem.cpp @@ -104,6 +104,14 @@ void ShapeEntityItem::setShape(const entity::Shape& shape) { case entity::Shape::Sphere: _type = EntityTypes::Sphere; break; + case entity::Shape::Circle: + // Circle is implicitly flat so we enforce flat dimensions + setDimensions(getDimensions()); + break; + case entity::Shape::Quad: + // Quad is implicitly flat so we enforce flat dimensions + setDimensions(getDimensions()); + break; default: _type = EntityTypes::Shape; break; @@ -196,6 +204,18 @@ void ShapeEntityItem::setColor(const QColor& value) { setAlpha(value.alpha()); } +void ShapeEntityItem::setDimensions(const glm::vec3& value) { + const float MAX_FLAT_DIMENSION = 0.0001f; + if ((_shape == entity::Shape::Circle || _shape == entity::Shape::Quad) && value.y > MAX_FLAT_DIMENSION) { + // enforce flatness in Y + glm::vec3 newDimensions = value; + newDimensions.y = MAX_FLAT_DIMENSION; + EntityItem::setDimensions(newDimensions); + } else { + EntityItem::setDimensions(value); + } +} + bool ShapeEntityItem::supportsDetailedRayIntersection() const { return _shape == entity::Sphere; } @@ -249,13 +269,8 @@ void ShapeEntityItem::computeShapeInfo(ShapeInfo& info) { const glm::vec3 entityDimensions = getDimensions(); switch (_shape){ - case entity::Shape::Quad: { - // Not in GeometryCache::buildShapes, unsupported. - _collisionShapeType = SHAPE_TYPE_ELLIPSOID; - //TODO WL21389: Add a SHAPE_TYPE_QUAD ShapeType and treat - // as a special box (later if desired support) - } - break; + case entity::Shape::Quad: + // Quads collide like flat Cubes case entity::Shape::Cube: { _collisionShapeType = SHAPE_TYPE_BOX; } @@ -275,19 +290,10 @@ void ShapeEntityItem::computeShapeInfo(ShapeInfo& info) { } } break; - case entity::Shape::Circle: { - _collisionShapeType = SHAPE_TYPE_CIRCLE; - } - break; + case entity::Shape::Circle: + // Circles collide like flat Cylinders case entity::Shape::Cylinder: { _collisionShapeType = SHAPE_TYPE_CYLINDER_Y; - // TODO WL21389: determine if rotation is axis-aligned - //const Transform::Quat & rot = _transform.getRotation(); - - // TODO WL21389: some way to tell apart SHAPE_TYPE_CYLINDER_Y, _X, _Z based on rotation and - // hull ( or dimensions, need circular cross section) - // Should allow for minor variance along axes? - } break; case entity::Shape::Cone: { @@ -330,7 +336,7 @@ void ShapeEntityItem::computeShapeInfo(ShapeInfo& info) { case entity::Shape::Torus: { // Not in GeometryCache::buildShapes, unsupported. _collisionShapeType = SHAPE_TYPE_ELLIPSOID; - //TODO WL21389: SHAPE_TYPE_SIMPLE_HULL and pointCollection (later if desired support) + //TODO handle this shape more correctly } break; default: { diff --git a/libraries/entities/src/ShapeEntityItem.h b/libraries/entities/src/ShapeEntityItem.h index a88a2098e9..20e36c88e6 100644 --- a/libraries/entities/src/ShapeEntityItem.h +++ b/libraries/entities/src/ShapeEntityItem.h @@ -80,6 +80,8 @@ public: const rgbColor& getColor() const { return _color; } void setColor(const rgbColor& value); + void setDimensions(const glm::vec3& value) override; + xColor getXColor() const; void setColor(const xColor& value); From 2710dca37c70fa331f10ee80ad1232155d113961 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 26 Oct 2017 22:58:50 -0700 Subject: [PATCH 3/5] fix rendering of Circles and Quads --- libraries/render-utils/src/GeometryCache.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index f35fb9f830..fa00737e3c 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -482,8 +482,10 @@ void GeometryCache::buildShapes() { using namespace geometry; auto vertexBuffer = std::make_shared(); auto indexBuffer = std::make_shared(); - // Cube + // Cube setupFlatShape(_shapes[Cube], geometry::cube(), _shapeVertices, _shapeIndices); + //Quad renders as flat Cube + setupFlatShape(_shapes[Quad], geometry::cube(), _shapeVertices, _shapeIndices); // Tetrahedron setupFlatShape(_shapes[Tetrahedron], geometry::tetrahedron(), _shapeVertices, _shapeIndices); // Icosahedron @@ -524,12 +526,10 @@ void GeometryCache::buildShapes() { extrudePolygon<64>(_shapes[Cylinder], _shapeVertices, _shapeIndices); //Cone, extrudePolygon<64>(_shapes[Cone], _shapeVertices, _shapeIndices, true); - //Circle - drawCircle(_shapes[Circle], _shapeVertices, _shapeIndices); + // Circle renders as flat Cylinder + extrudePolygon<64>(_shapes[Circle], _shapeVertices, _shapeIndices); // Not implemented yet: - //Quad, - //Torus, - + //Torus, } const GeometryCache::ShapeData * GeometryCache::getShapeData(const Shape shape) const { From 5ed58d5e5dc6012ed054f72ba3b60f6d0c3a7900 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 26 Oct 2017 22:59:25 -0700 Subject: [PATCH 4/5] enable Quad in ShapeEntityItem properties --- scripts/system/html/entityProperties.html | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index 2d5dd35e66..d2c33984ff 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -59,6 +59,7 @@ +
From 2c4d4373dc87d4a76030c3690180c712d266936d Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 27 Oct 2017 10:41:16 -0700 Subject: [PATCH 5/5] support asymmetrical cross section Cylinder --- libraries/entities/src/ShapeEntityItem.cpp | 37 ++++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/libraries/entities/src/ShapeEntityItem.cpp b/libraries/entities/src/ShapeEntityItem.cpp index 8c7d1576e1..4115a606df 100644 --- a/libraries/entities/src/ShapeEntityItem.cpp +++ b/libraries/entities/src/ShapeEntityItem.cpp @@ -51,12 +51,12 @@ namespace entity { } } -// shapeCalculator is a hook for external code that knows how to configure a ShapeInfo +// hullShapeCalculator is a hook for external code that knows how to configure a ShapeInfo // for given entity::Shape and dimensions -ShapeEntityItem::ShapeInfoCalculator shapeCalculator = nullptr; +ShapeEntityItem::ShapeInfoCalculator hullShapeCalculator = nullptr; void ShapeEntityItem::setShapeInfoCalulator(ShapeEntityItem::ShapeInfoCalculator callback) { - shapeCalculator = callback; + hullShapeCalculator = callback; } ShapeEntityItem::Pointer ShapeEntityItem::baseFactory(const EntityItemID& entityID, const EntityItemProperties& properties) { @@ -276,7 +276,6 @@ void ShapeEntityItem::computeShapeInfo(ShapeInfo& info) { } break; case entity::Shape::Sphere: { - float diameter = entityDimensions.x; const float MIN_DIAMETER = 0.001f; const float MIN_RELATIVE_SPHERICAL_ERROR = 0.001f; @@ -293,13 +292,25 @@ void ShapeEntityItem::computeShapeInfo(ShapeInfo& info) { case entity::Shape::Circle: // Circles collide like flat Cylinders case entity::Shape::Cylinder: { - _collisionShapeType = SHAPE_TYPE_CYLINDER_Y; + float diameter = entityDimensions.x; + const float MIN_DIAMETER = 0.001f; + const float MIN_RELATIVE_SPHERICAL_ERROR = 0.001f; + if (diameter > MIN_DIAMETER + && fabsf(diameter - entityDimensions.z) / diameter < MIN_RELATIVE_SPHERICAL_ERROR) { + _collisionShapeType = SHAPE_TYPE_SPHERE; + } else if (hullShapeCalculator) { + hullShapeCalculator(this, info); + _collisionShapeType = SHAPE_TYPE_SIMPLE_HULL; + } else { + // woops, someone forgot to hook up the hullShapeCalculator()! + // final fallback is ellipsoid + _collisionShapeType = SHAPE_TYPE_ELLIPSOID; + } } break; case entity::Shape::Cone: { - if (shapeCalculator) { - shapeCalculator(this, info); - // shapeCalculator only supports convex shapes (e.g. SHAPE_TYPE_HULL) + if (hullShapeCalculator) { + hullShapeCalculator(this, info); _collisionShapeType = SHAPE_TYPE_SIMPLE_HULL; } else { _collisionShapeType = SHAPE_TYPE_ELLIPSOID; @@ -310,9 +321,8 @@ void ShapeEntityItem::computeShapeInfo(ShapeInfo& info) { case entity::Shape::Triangle: case entity::Shape::Hexagon: case entity::Shape::Octagon: { - if (shapeCalculator) { - shapeCalculator(this, info); - // shapeCalculator only supports convex shapes (e.g. SHAPE_TYPE_HULL) + if (hullShapeCalculator) { + hullShapeCalculator(this, info); _collisionShapeType = SHAPE_TYPE_SIMPLE_HULL; } else { _collisionShapeType = SHAPE_TYPE_ELLIPSOID; @@ -324,9 +334,8 @@ void ShapeEntityItem::computeShapeInfo(ShapeInfo& info) { case entity::Shape::Octahedron: case entity::Shape::Dodecahedron: case entity::Shape::Icosahedron: { - if ( shapeCalculator ) { - shapeCalculator(this, info); - // shapeCalculator only supports convex shapes (e.g. SHAPE_TYPE_HULL) + if ( hullShapeCalculator ) { + hullShapeCalculator(this, info); _collisionShapeType = SHAPE_TYPE_SIMPLE_HULL; } else { _collisionShapeType = SHAPE_TYPE_ELLIPSOID;