diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 51ed66bb23..3bbd6ce8e6 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -84,28 +84,11 @@ void EntityItemProperties::setLastEdited(quint64 usecTime) { _lastEdited = usecTime > _created ? usecTime : _created; } -const char* shapeTypeNames[] = { - "none", - "box", - "sphere", - "capsule-x", - "capsule-y", - "capsule-z", - "cylinder-x", - "cylinder-y", - "cylinder-z", - "hull", - "plane", - "compound", - "simple-hull", - "simple-compound", - "static-mesh" -}; QHash stringToShapeTypeLookup; void addShapeType(ShapeType type) { - stringToShapeTypeLookup[shapeTypeNames[type]] = type; + stringToShapeTypeLookup[ShapeInfo::getNameForShapeType(type)] = type; } void buildStringToShapeTypeLookup() { @@ -180,9 +163,7 @@ void EntityItemProperties::setCollisionMaskFromString(const QString& maskString) } QString EntityItemProperties::getShapeTypeAsString() const { - if (_shapeType < sizeof(shapeTypeNames) / sizeof(char *)) - return QString(shapeTypeNames[_shapeType]); - return QString(shapeTypeNames[SHAPE_TYPE_NONE]); + return ShapeInfo::getNameForShapeType(_shapeType); } void EntityItemProperties::setShapeTypeFromString(const QString& shapeName) { diff --git a/libraries/entities/src/ShapeEntityItem.cpp b/libraries/entities/src/ShapeEntityItem.cpp index 8d68e0ab00..9a1a500a54 100644 --- a/libraries/entities/src/ShapeEntityItem.cpp +++ b/libraries/entities/src/ShapeEntityItem.cpp @@ -95,6 +95,7 @@ EntityItemProperties ShapeEntityItem::getProperties(EntityPropertyFlags desiredP } void ShapeEntityItem::setShape(const entity::Shape& shape) { + const entity::Shape prevShape = _shape; _shape = shape; switch (_shape) { case entity::Shape::Cube: @@ -107,6 +108,11 @@ void ShapeEntityItem::setShape(const entity::Shape& shape) { _type = EntityTypes::Shape; break; } + + if (_shape != prevShape) { + // Internally grabs writeLock + markDirtyFlags(Simulation::DIRTY_SHAPE); + } } bool ShapeEntityItem::setProperties(const EntityItemProperties& properties) { @@ -227,6 +233,7 @@ void ShapeEntityItem::debugDump() const { qCDebug(entities) << "SHAPE EntityItem id:" << getEntityItemID() << "---------------------------------------------"; qCDebug(entities) << " name:" << _name; qCDebug(entities) << " shape:" << stringFromShape(_shape) << " (EnumId: " << _shape << " )"; + qCDebug(entities) << " collisionShapeType:" << ShapeInfo::getNameForShapeType(getShapeType()); qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; qCDebug(entities) << " position:" << debugTreeVector(getPosition()); qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions()); diff --git a/libraries/shared/src/ShapeInfo.cpp b/libraries/shared/src/ShapeInfo.cpp index c56b722b61..592f692f5a 100644 --- a/libraries/shared/src/ShapeInfo.cpp +++ b/libraries/shared/src/ShapeInfo.cpp @@ -15,9 +15,38 @@ #include "NumericalConstants.h" // for MILLIMETERS_PER_METER +// Originally within EntityItemProperties.cpp +const char* shapeTypeNames[] = { + "none", + "box", + "sphere", + "capsule-x", + "capsule-y", + "capsule-z", + "cylinder-x", + "cylinder-y", + "cylinder-z", + "hull", + "plane", + "compound", + "simple-hull", + "simple-compound", + "static-mesh" +}; + +static const size_t SHAPETYPE_NAME_COUNT = (sizeof(shapeTypeNames) / sizeof((shapeTypeNames)[0])); + // Bullet doesn't support arbitrarily small shapes const float MIN_HALF_EXTENT = 0.005f; // 0.5 cm +QString ShapeInfo::getNameForShapeType(ShapeType type) { + if (((int)type <= 0) || ((int)type >= SHAPETYPE_NAME_COUNT)) { + type = (ShapeType)0; + } + + return shapeTypeNames[(int)type]; +} + void ShapeInfo::clear() { _url.clear(); _pointCollection.clear(); diff --git a/libraries/shared/src/ShapeInfo.h b/libraries/shared/src/ShapeInfo.h index cab487e07a..d658b936a3 100644 --- a/libraries/shared/src/ShapeInfo.h +++ b/libraries/shared/src/ShapeInfo.h @@ -58,6 +58,8 @@ public: using PointCollection = QVector; using TriangleIndices = QVector; + static QString getNameForShapeType(ShapeType type); + void clear(); void setParams(ShapeType type, const glm::vec3& halfExtents, QString url="");