diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 03c1544aab..3003e29f54 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -37,6 +37,7 @@ Model::Model(QObject* parent) : _scaleToFit(false), _scaleToFitLargestDimension(0.0f), _scaledToFit(false), + _simulationIndex(-1), _snapModelToCenter(false), _snappedToCenter(false), _rootIndex(-1), @@ -774,6 +775,34 @@ AnimationHandlePointer Model::createAnimationHandle() { return handle; } +quint8 BITS_FOR_SHAPE_INDEX = 15; +int MAX_SIMULATION_ID = 1 << (31 - BITS_FOR_SHAPE_INDEX); + +void Model::setSimulationIndex(int index) { + _simulationIndex = index; + + if (_simulationIndex < 0 || _simulationIndex > MAX_SIMULATION_ID) { + // clear simulation ID's of all the shapes + for (int i = 0; i < _jointShapes.size(); i++) { + Shape* shape = _jointShapes[i]; + if (shape) { + shape->setSimulationID(-1); + } + } + } else { + // update the simulation ID's of the shapes + // upper bits store this Model's index... + int shiftedIndex = _simulationIndex << BITS_FOR_SHAPE_INDEX; + for (int i = 0; i < _jointShapes.size(); i++) { + Shape* shape = _jointShapes[i]; + if (shape) { + // ... lower bits are for the shape's index + shape->setSimulationID(shiftedIndex + i); + } + } + } +} + void Model::clearShapes() { for (int i = 0; i < _jointShapes.size(); ++i) { delete _jointShapes[i]; diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index f8d4cf628b..aa0b34d750 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -134,9 +134,10 @@ public: QStringList getJointNames() const; AnimationHandlePointer createAnimationHandle(); - + const QList& getRunningAnimations() const { return _runningAnimations; } - + + void setSimulationIndex(int index); void clearShapes(); void rebuildShapes(); void resetShapePositions(); // DEBUG method @@ -177,6 +178,8 @@ protected: bool _scaleToFit; /// If you set scaleToFit, we will calculate scale based on MeshExtents float _scaleToFitLargestDimension; /// this is the dimension that scale to fit will use bool _scaledToFit; /// have we scaled to fit + + int _simulationIndex; // set by SimulationEngine (if any) bool _snapModelToCenter; /// is the model's offset automatically adjusted to center around 0,0,0 in model space bool _snappedToCenter; /// are we currently snapped to center diff --git a/libraries/shared/src/CollisionInfo.cpp b/libraries/shared/src/CollisionInfo.cpp index 32deb56cd1..a1c3f0b368 100644 --- a/libraries/shared/src/CollisionInfo.cpp +++ b/libraries/shared/src/CollisionInfo.cpp @@ -47,6 +47,8 @@ void CollisionList::clear() { //collision._intData = 0; //collision._floatDAta = 0.0f; //collision._vecData = glm::vec3(0.0f); + //collision._shapeA = -1; + //collision._shapeB = -1; //collision._damping; //collision._elasticity; //collision._contactPoint; diff --git a/libraries/shared/src/CollisionInfo.h b/libraries/shared/src/CollisionInfo.h index cf48701a2b..ff228e3863 100644 --- a/libraries/shared/src/CollisionInfo.h +++ b/libraries/shared/src/CollisionInfo.h @@ -33,6 +33,8 @@ public: CollisionInfo() : _data(NULL), _intData(0), + _shapeA(-1), + _shapeB(-1), _damping(0.f), _elasticity(1.f), _contactPoint(0.f), @@ -43,6 +45,8 @@ public: CollisionInfo(qint32 type) : _data(NULL), _intData(0), + _shapeA(-1), + _shapeB(-1), _damping(0.f), _elasticity(1.f), _contactPoint(0.f), @@ -58,6 +62,9 @@ public: float _floatData; glm::vec3 _vecData; + int _shapeA; // ID of shapeA in its SimulationEngine + int _shapeB; // ID of shapeB in its SimulationEngine + float _damping; // range [0,1] of friction coeficient float _elasticity; // range [0,1] of energy conservation glm::vec3 _contactPoint; // world-frame point on BodyA that is deepest into BodyB diff --git a/libraries/shared/src/Shape.h b/libraries/shared/src/Shape.h index 87b84ea73b..a9bddc00df 100644 --- a/libraries/shared/src/Shape.h +++ b/libraries/shared/src/Shape.h @@ -23,11 +23,10 @@ public: SPHERE_SHAPE, CAPSULE_SHAPE, PLANE_SHAPE, - BOX_SHAPE, LIST_SHAPE }; - Shape() : _type(UNKNOWN_SHAPE), _boundingRadius(0.f), _position(0.f), _rotation() { } + Shape() : _type(UNKNOWN_SHAPE), _simulationID(-1), _boundingRadius(0.f), _position(0.f), _rotation() { } virtual ~Shape() {} int getType() const { return _type; } @@ -38,6 +37,9 @@ public: virtual void setPosition(const glm::vec3& position) { _position = position; } virtual void setRotation(const glm::quat& rotation) { _rotation = rotation; } + void setSimulationID(int id) { _simulationID = id; } + int getSimulationID() const { return _simulationID; } + protected: // these ctors are protected (used by derived classes only) Shape(Type type) : _type(type), _boundingRadius(0.f), _position(0.f), _rotation() {} @@ -51,6 +53,7 @@ protected: void setBoundingRadius(float radius) { _boundingRadius = radius; } int _type; + int _simulationID; // shape's simulation ID in SimulationEngine float _boundingRadius; glm::vec3 _position; glm::quat _rotation;