mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 05:53:10 +02:00
trying to get loaded callback for model hooked up to PhysicsEngine
This commit is contained in:
parent
a945421d9d
commit
89b58e2681
6 changed files with 73 additions and 33 deletions
|
@ -176,7 +176,8 @@ void EntityItemProperties::setLastEdited(quint64 usecTime) {
|
||||||
_lastEdited = usecTime > _created ? usecTime : _created;
|
_lastEdited = usecTime > _created ? usecTime : _created;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* shapeTypeNames[] = {"none", "box", "sphere"};
|
const char* shapeTypeNames[] = {"none", "box", "sphere", "ellipsoid", "convex-hull", "plane", "compound", "capsule-x",
|
||||||
|
"capsule-y", "capsule-z", "cylinder-x", "cylinder-y", "cylinder-z"};
|
||||||
|
|
||||||
QHash<QString, ShapeType> stringToShapeTypeLookup;
|
QHash<QString, ShapeType> stringToShapeTypeLookup;
|
||||||
|
|
||||||
|
@ -184,6 +185,16 @@ void buildStringToShapeTypeLookup() {
|
||||||
stringToShapeTypeLookup["none"] = SHAPE_TYPE_NONE;
|
stringToShapeTypeLookup["none"] = SHAPE_TYPE_NONE;
|
||||||
stringToShapeTypeLookup["box"] = SHAPE_TYPE_BOX;
|
stringToShapeTypeLookup["box"] = SHAPE_TYPE_BOX;
|
||||||
stringToShapeTypeLookup["sphere"] = SHAPE_TYPE_SPHERE;
|
stringToShapeTypeLookup["sphere"] = SHAPE_TYPE_SPHERE;
|
||||||
|
stringToShapeTypeLookup["ellipsoid"] = SHAPE_TYPE_ELLIPSOID;
|
||||||
|
stringToShapeTypeLookup["convex-hull"] = SHAPE_TYPE_CONVEX_HULL;
|
||||||
|
stringToShapeTypeLookup["plane"] = SHAPE_TYPE_PLANE;
|
||||||
|
stringToShapeTypeLookup["compound"] = SHAPE_TYPE_COMPOUND;
|
||||||
|
stringToShapeTypeLookup["capsule-x"] = SHAPE_TYPE_CAPSULE_X;
|
||||||
|
stringToShapeTypeLookup["capsule-y"] = SHAPE_TYPE_CAPSULE_Y;
|
||||||
|
stringToShapeTypeLookup["capsule-z"] = SHAPE_TYPE_CAPSULE_Z;
|
||||||
|
stringToShapeTypeLookup["cylinder-x"] = SHAPE_TYPE_CYLINDER_X;
|
||||||
|
stringToShapeTypeLookup["cylinder-y"] = SHAPE_TYPE_CYLINDER_Y;
|
||||||
|
stringToShapeTypeLookup["cylinder-z"] = SHAPE_TYPE_CYLINDER_Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EntityItemProperties::getShapeTypeAsString() const {
|
QString EntityItemProperties::getShapeTypeAsString() const {
|
||||||
|
|
|
@ -35,6 +35,8 @@ EntityItem* ModelEntityItem::factory(const EntityItemID& entityID, const EntityI
|
||||||
ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||||
EntityItem(entityItemID, properties)
|
EntityItem(entityItemID, properties)
|
||||||
{
|
{
|
||||||
|
_collisionNetworkGeometry = QSharedPointer<NetworkGeometry>(0);
|
||||||
|
|
||||||
_type = EntityTypes::Model;
|
_type = EntityTypes::Model;
|
||||||
setProperties(properties);
|
setProperties(properties);
|
||||||
_lastAnimated = usecTimestampNow();
|
_lastAnimated = usecTimestampNow();
|
||||||
|
@ -416,7 +418,7 @@ QString ModelEntityItem::getAnimationSettings() const {
|
||||||
|
|
||||||
|
|
||||||
void ModelEntityItem::getReadyToComputeShape() {
|
void ModelEntityItem::getReadyToComputeShape() {
|
||||||
qDebug() << "ModelEntityItem::getReadyToComputeShape for " << getID().toString();
|
qDebug() << "ModelEntityItem::getReadyToComputeShape for " << getID().toString() << _collisionModelURL;
|
||||||
|
|
||||||
if (_collisionModelURL != "") {
|
if (_collisionModelURL != "") {
|
||||||
if (! _collisionNetworkGeometry.isNull()) {
|
if (! _collisionNetworkGeometry.isNull()) {
|
||||||
|
@ -425,6 +427,7 @@ void ModelEntityItem::getReadyToComputeShape() {
|
||||||
_collisionNetworkGeometry =
|
_collisionNetworkGeometry =
|
||||||
DependencyManager::get<GeometryCache>()->getGeometry (_collisionModelURL, QUrl(), false);
|
DependencyManager::get<GeometryCache>()->getGeometry (_collisionModelURL, QUrl(), false);
|
||||||
connect(_collisionNetworkGeometry.data(), SIGNAL(Resource::loaded()), this, SLOT(collisionGeometryLoaded()));
|
connect(_collisionNetworkGeometry.data(), SIGNAL(Resource::loaded()), this, SLOT(collisionGeometryLoaded()));
|
||||||
|
connect(_collisionNetworkGeometry.data(), SIGNAL(Resource::loadingFailed()), this, SLOT(collisionGeometryLoaded()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
emit entityShapeReady(getID());
|
emit entityShapeReady(getID());
|
||||||
|
|
|
@ -278,6 +278,7 @@ void Resource::finishedLoading(bool success) {
|
||||||
emit loaded();
|
emit loaded();
|
||||||
} else {
|
} else {
|
||||||
_failedToLoad = true;
|
_failedToLoad = true;
|
||||||
|
emit loadingFailed();
|
||||||
}
|
}
|
||||||
_loadPriorities.clear();
|
_loadPriorities.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,7 @@ signals:
|
||||||
|
|
||||||
/// Fired when the resource has been loaded.
|
/// Fired when the resource has been loaded.
|
||||||
void loaded();
|
void loaded();
|
||||||
|
void loadingFailed();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
|
|
||||||
|
|
|
@ -57,42 +57,60 @@ void PhysicsEngine::updateEntitiesInternal(const quint64& now) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsEngine::addEntityInternal(EntityItem* entity) {
|
void PhysicsEngine::addEntityInternal(EntityItem* entity) {
|
||||||
|
lockBusyForRead();
|
||||||
|
|
||||||
|
qDebug() << "PhysicsEngine::addEntityInternal for " << entity->getID().toString()
|
||||||
|
<< "thread-id" << QThread::currentThreadId();
|
||||||
assert(entity);
|
assert(entity);
|
||||||
void* physicsInfo = entity->getPhysicsInfo();
|
void* physicsInfo = entity->getPhysicsInfo();
|
||||||
if (!physicsInfo && !_busyComputingShape.contains(entity->getID())) {
|
if (!physicsInfo) {
|
||||||
// qDebug() << "in addEntityInternal ID is" << entity->getID().toString();
|
qDebug() << " has no physicsInfo";
|
||||||
|
if (!_busyComputingShape.contains(entity->getID())) {
|
||||||
|
qDebug() << " calling getReadyToComputeShape";
|
||||||
QPointer<EntityItem> entityWptr(entity);
|
QPointer<EntityItem> entityWptr(entity);
|
||||||
_busyComputingShape[entity->getID()] = entityWptr;
|
_busyComputingShape[entity->getID()] = true;
|
||||||
connect(entity, SIGNAL(entityShapeReady(QUuid)), this, SLOT(entityShapeReady(QUuid)));
|
connect(entity, SIGNAL(entityShapeReady(QUuid)), this, SLOT(entityShapeReady(QUuid)));
|
||||||
entity->getReadyToComputeShape();
|
entity->getReadyToComputeShape();
|
||||||
}
|
} else {
|
||||||
}
|
if (_busyComputingShape[entity->getID()]) {
|
||||||
|
qDebug() << " still getting ready to compute shape";
|
||||||
void PhysicsEngine::entityShapeReady(QUuid entityId) {
|
} else {
|
||||||
// qDebug() << "PhysicsEngine::entityShapeReady for" << entityId.toString();
|
qDebug() << " it's ready to compute shape";
|
||||||
|
|
||||||
QPointer<EntityItem> entityPtr = _busyComputingShape[entityId];
|
|
||||||
_busyComputingShape.remove(entityId);
|
|
||||||
|
|
||||||
EntityItem &entity = *entityPtr;
|
|
||||||
|
|
||||||
ShapeInfo shapeInfo;
|
ShapeInfo shapeInfo;
|
||||||
entity.computeShapeInfo(shapeInfo);
|
entity->computeShapeInfo(shapeInfo);
|
||||||
|
|
||||||
btCollisionShape* shape = _shapeManager.getShape(shapeInfo);
|
btCollisionShape* shape = _shapeManager.getShape(shapeInfo);
|
||||||
|
if (shape) {
|
||||||
EntityMotionState* motionState = new EntityMotionState(&entity);
|
EntityMotionState* motionState = new EntityMotionState(entity);
|
||||||
entity.setPhysicsInfo(static_cast<void*>(motionState));
|
entity->setPhysicsInfo(static_cast<void*>(motionState));
|
||||||
|
_entityMotionStates.insert(motionState);
|
||||||
|
addObject(shapeInfo, shape, motionState);
|
||||||
|
} else if (entity->isMoving()) {
|
||||||
|
EntityMotionState* motionState = new EntityMotionState(entity);
|
||||||
|
entity->setPhysicsInfo(static_cast<void*>(motionState));
|
||||||
_entityMotionStates.insert(motionState);
|
_entityMotionStates.insert(motionState);
|
||||||
|
|
||||||
if (shape) {
|
|
||||||
addObject(shapeInfo, shape, motionState);
|
|
||||||
} else if (entity.isMoving()) {
|
|
||||||
motionState->setKinematic(true, _numSubsteps);
|
motionState->setKinematic(true, _numSubsteps);
|
||||||
_nonPhysicalKinematicObjects.insert(motionState);
|
_nonPhysicalKinematicObjects.insert(motionState);
|
||||||
// We failed to add the entity to the simulation. Probably because we couldn't create a shape for it.
|
// We failed to add the entity to the simulation. Probably because we couldn't create a shape for it.
|
||||||
//qDebug() << "failed to add entity " << entity.getEntityItemID() << " to physics engine";
|
//qDebug() << "failed to add entity " << entity->getEntityItemID() << " to physics engine";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_busyComputingShape.remove(entity->getID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << " already has physicsInfo";
|
||||||
|
}
|
||||||
|
unlockBusy();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsEngine::entityShapeReady(QUuid entityId) {
|
||||||
|
qDebug() << "PhysicsEngine::entityShapeReady for" << entityId.toString() << "thread-id" << QThread::currentThreadId();
|
||||||
|
lockBusyForWrite();
|
||||||
|
_busyComputingShape[entityId] = false;
|
||||||
|
unlockBusy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsEngine::removeEntityInternal(EntityItem* entity) {
|
void PhysicsEngine::removeEntityInternal(EntityItem* entity) {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
#include <QReadWriteLock>
|
||||||
#include <btBulletDynamicsCommon.h>
|
#include <btBulletDynamicsCommon.h>
|
||||||
#include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
|
#include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
|
||||||
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
|
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
|
||||||
|
@ -132,7 +133,12 @@ private:
|
||||||
class btPairCachingGhostObject* _avatarGhostObject = 0;
|
class btPairCachingGhostObject* _avatarGhostObject = 0;
|
||||||
AvatarData *_avatarData = 0;
|
AvatarData *_avatarData = 0;
|
||||||
|
|
||||||
QMap<QUuid, QPointer<EntityItem>> _busyComputingShape;
|
QReadWriteLock _busyLock;
|
||||||
|
void lockBusyForRead() { _busyLock.lockForRead(); }
|
||||||
|
void lockBusyForWrite() { _busyLock.lockForWrite(); }
|
||||||
|
void unlockBusy() { _busyLock.unlock(); }
|
||||||
|
|
||||||
|
QMap<QUuid, bool> _busyComputingShape;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_PhysicsEngine_h
|
#endif // hifi_PhysicsEngine_h
|
||||||
|
|
Loading…
Reference in a new issue