From b7767b7971c72a06f841eea856c800fb509ce214 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 8 Aug 2014 15:12:57 -0700 Subject: [PATCH] get referentials compiling with new Entity ID changes --- interface/src/avatar/Avatar.cpp | 2 +- interface/src/avatar/ModelReferential.cpp | 52 ++++++++++++----------- interface/src/avatar/ModelReferential.h | 16 +++---- interface/src/avatar/MyAvatar.cpp | 8 ++-- interface/src/avatar/MyAvatar.h | 4 +- libraries/entities/src/EntityTree.cpp | 4 +- libraries/entities/src/EntityTree.h | 6 +-- libraries/entities/src/todo.txt | 12 +++++- 8 files changed, 56 insertions(+), 48 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index c9e03d15cc..af1917b34c 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -107,7 +107,7 @@ void Avatar::simulate(float deltaTime) { // update the avatar's position according to its referential if (_referential) { if (_referential->hasExtraData()) { - ModelTree* tree = Application::getInstance()->getModels()->getTree(); + EntityTree* tree = Application::getInstance()->getEntities()->getTree(); switch (_referential->type()) { case Referential::MODEL: _referential = new ModelReferential(_referential, diff --git a/interface/src/avatar/ModelReferential.cpp b/interface/src/avatar/ModelReferential.cpp index d38abae70a..6a8b8c8b9d 100644 --- a/interface/src/avatar/ModelReferential.cpp +++ b/interface/src/avatar/ModelReferential.cpp @@ -11,12 +11,12 @@ #include -#include "ModelTree.h" +#include #include "../renderer/Model.h" #include "ModelReferential.h" -ModelReferential::ModelReferential(Referential* referential, ModelTree* tree, AvatarData* avatar) : +ModelReferential::ModelReferential(Referential* referential, EntityTree* tree, AvatarData* avatar) : Referential(MODEL, avatar), _tree(tree) { _translation = referential->getTranslation(); @@ -30,21 +30,21 @@ ModelReferential::ModelReferential(Referential* referential, ModelTree* tree, Av return; } - const ModelItem* item = _tree->findModelByID(_modelID); + const EntityItem* item = _tree->findEntityByID(_entityID); if (item != NULL) { _refScale = item->getRadius(); - _refRotation = item->getModelRotation(); + _refRotation = item->getRotation(); _refPosition = item->getPosition() * (float)TREE_SCALE; update(); } } -ModelReferential::ModelReferential(uint32_t modelID, ModelTree* tree, AvatarData* avatar) : +ModelReferential::ModelReferential(const QUuid& entityID, EntityTree* tree, AvatarData* avatar) : Referential(MODEL, avatar), - _modelID(modelID), + _entityID(entityID), _tree(tree) { - const ModelItem* item = _tree->findModelByID(_modelID); + const EntityItem* item = _tree->findEntityByID(_entityID); if (!isValid() || item == NULL) { qDebug() << "ModelReferential::constructor(): Not Valid"; _isValid = false; @@ -52,7 +52,7 @@ ModelReferential::ModelReferential(uint32_t modelID, ModelTree* tree, AvatarData } _refScale = item->getRadius(); - _refRotation = item->getModelRotation(); + _refRotation = item->getRotation(); _refPosition = item->getPosition() * (float)TREE_SCALE; glm::quat refInvRot = glm::inverse(_refRotation); @@ -62,7 +62,7 @@ ModelReferential::ModelReferential(uint32_t modelID, ModelTree* tree, AvatarData } void ModelReferential::update() { - const ModelItem* item = _tree->findModelByID(_modelID); + const EntityItem* item = _tree->findEntityByID(_entityID); if (!isValid() || item == NULL || _avatar == NULL) { return; } @@ -73,8 +73,8 @@ void ModelReferential::update() { _avatar->setTargetScale(_refScale * _scale, true); somethingChanged = true; } - if (item->getModelRotation() != _refRotation) { - _refRotation = item->getModelRotation(); + if (item->getRotation() != _refRotation) { + _refRotation = item->getRotation(); _avatar->setOrientation(_refRotation * _rotation, true); somethingChanged = true; } @@ -85,16 +85,18 @@ void ModelReferential::update() { } int ModelReferential::packExtraData(unsigned char* destinationBuffer) const { - memcpy(destinationBuffer, &_modelID, sizeof(_modelID)); - return sizeof(_modelID); + QByteArray encodedEntityID = _entityID.toRfc4122(); + memcpy(destinationBuffer, encodedEntityID.constData(), encodedEntityID.size()); + return encodedEntityID.size(); } int ModelReferential::unpackExtraData(const unsigned char *sourceBuffer, int size) { - memcpy(&_modelID, sourceBuffer, sizeof(_modelID)); - return sizeof(_modelID); + QByteArray encodedEntityID((const char*)sourceBuffer, NUM_BYTES_RFC4122_UUID); + _entityID = QUuid::fromRfc4122(encodedEntityID); + return NUM_BYTES_RFC4122_UUID; } -JointReferential::JointReferential(Referential* referential, ModelTree* tree, AvatarData* avatar) : +JointReferential::JointReferential(Referential* referential, EntityTree* tree, AvatarData* avatar) : ModelReferential(referential, tree, avatar) { _type = JOINT; @@ -103,7 +105,7 @@ JointReferential::JointReferential(Referential* referential, ModelTree* tree, Av return; } - const ModelItem* item = _tree->findModelByID(_modelID); + const EntityItem* item = _tree->findEntityByID(_entityID); const Model* model = getModel(item); if (!isValid() || model == NULL || _jointIndex >= model->getJointStateCount()) { _refScale = item->getRadius(); @@ -113,12 +115,12 @@ JointReferential::JointReferential(Referential* referential, ModelTree* tree, Av update(); } -JointReferential::JointReferential(uint32_t jointIndex, uint32_t modelID, ModelTree* tree, AvatarData* avatar) : - ModelReferential(modelID, tree, avatar), +JointReferential::JointReferential(uint32_t jointIndex, const QUuid& entityID, EntityTree* tree, AvatarData* avatar) : + ModelReferential(entityID, tree, avatar), _jointIndex(jointIndex) { _type = JOINT; - const ModelItem* item = _tree->findModelByID(_modelID); + const EntityItem* item = _tree->findEntityByID(_entityID); const Model* model = getModel(item); if (!isValid() || model == NULL || _jointIndex >= model->getJointStateCount()) { qDebug() << "JointReferential::constructor(): Not Valid"; @@ -137,7 +139,7 @@ JointReferential::JointReferential(uint32_t jointIndex, uint32_t modelID, ModelT } void JointReferential::update() { - const ModelItem* item = _tree->findModelByID(_modelID); + const EntityItem* item = _tree->findEntityByID(_entityID); const Model* model = getModel(item); if (!isValid() || model == NULL || _jointIndex >= model->getJointStateCount()) { return; @@ -149,7 +151,7 @@ void JointReferential::update() { _avatar->setTargetScale(_refScale * _scale, true); somethingChanged = true; } - if (item->getModelRotation() != _refRotation) { + if (item->getRotation() != _refRotation) { model->getJointRotationInWorldFrame(_jointIndex, _refRotation); _avatar->setOrientation(_refRotation * _rotation, true); somethingChanged = true; @@ -160,10 +162,10 @@ void JointReferential::update() { } } -const Model* JointReferential::getModel(const ModelItem* item) { - ModelItemFBXService* fbxService = _tree->getFBXService(); +const Model* JointReferential::getModel(const EntityItem* item) { + EntityItemFBXService* fbxService = _tree->getFBXService(); if (item != NULL && fbxService != NULL) { - return fbxService->getModelForModelItem(*item); + return fbxService->getModelForEntityItem(item); } return NULL; } diff --git a/interface/src/avatar/ModelReferential.h b/interface/src/avatar/ModelReferential.h index b3a718d728..adb5783de2 100644 --- a/interface/src/avatar/ModelReferential.h +++ b/interface/src/avatar/ModelReferential.h @@ -14,31 +14,31 @@ #include -class ModelTree; +class EntityTree; class Model; class ModelReferential : public Referential { public: - ModelReferential(Referential* ref, ModelTree* tree, AvatarData* avatar); - ModelReferential(uint32_t modelID, ModelTree* tree, AvatarData* avatar); + ModelReferential(Referential* ref, EntityTree* tree, AvatarData* avatar); + ModelReferential(const QUuid& entityID, EntityTree* tree, AvatarData* avatar); virtual void update(); protected: virtual int packExtraData(unsigned char* destinationBuffer) const; virtual int unpackExtraData(const unsigned char* sourceBuffer, int size); - uint32_t _modelID; - ModelTree* _tree; + QUuid _entityID; + EntityTree* _tree; }; class JointReferential : public ModelReferential { public: - JointReferential(Referential* ref, ModelTree* tree, AvatarData* avatar); - JointReferential(uint32_t jointIndex, uint32_t modelID, ModelTree* tree, AvatarData* avatar); + JointReferential(Referential* ref, EntityTree* tree, AvatarData* avatar); + JointReferential(uint32_t jointIndex, const QUuid& entityID, EntityTree* tree, AvatarData* avatar); virtual void update(); protected: - const Model* getModel(const ModelItem* item); + const Model* getModel(const EntityItem* item); virtual int packExtraData(unsigned char* destinationBuffer) const; virtual int unpackExtraData(const unsigned char* sourceBuffer, int size); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index f59064732c..76230824fb 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -452,8 +452,8 @@ void MyAvatar::clearReferential() { changeReferential(NULL); } -bool MyAvatar::setModelReferential(int id) { - ModelTree* tree = Application::getInstance()->getModels()->getTree(); +bool MyAvatar::setModelReferential(const QUuid& id) { + EntityTree* tree = Application::getInstance()->getEntities()->getTree(); changeReferential(new ModelReferential(id, tree, this)); if (_referential->isValid()) { return true; @@ -463,8 +463,8 @@ bool MyAvatar::setModelReferential(int id) { } } -bool MyAvatar::setJointReferential(int id, int jointIndex) { - ModelTree* tree = Application::getInstance()->getModels()->getTree(); +bool MyAvatar::setJointReferential(const QUuid& id, int jointIndex) { + EntityTree* tree = Application::getInstance()->getEntities()->getTree(); changeReferential(new JointReferential(jointIndex, id, tree, this)); if (!_referential->isValid()) { return true; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 4f2802a35a..1e54e2f5b0 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -152,8 +152,8 @@ public slots: glm::vec3 getRightPalmPosition(); void clearReferential(); - bool setModelReferential(int id); - bool setJointReferential(int id, int jointIndex); + bool setModelReferential(const QUuid& id); + bool setJointReferential(const QUuid& id, int jointIndex); signals: void transformChanged(); diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 12ff3bfadb..8ea1a15a22 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -855,8 +855,7 @@ void EntityTree::findEntities(const AACube& cube, QVector foundEnti foundEntities.swap(args._foundEntities); } -#if 0 /////////////////////////////////// -EntityItem* EntityTree::findEntityByID(uint32_t id, bool alreadyLocked) /*const*/ { +EntityItem* EntityTree::findEntityByID(const QUuid& id) { EntityItemID entityID(id); bool wantDebug = false; @@ -869,7 +868,6 @@ EntityItem* EntityTree::findEntityByID(uint32_t id, bool alreadyLocked) /*const return findEntityByEntityItemID(entityID); } -#endif //////////////////////////// EntityItem* EntityTree::findEntityByEntityItemID(const EntityItemID& entityID) /*const*/ { EntityItem* foundEntity = NULL; diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 18e4283dec..75b93e9c1c 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -26,7 +26,7 @@ public: class EntityItemFBXService { public: virtual const FBXGeometry* getGeometryForEntity(const EntityItem* entityItem) = 0; - virtual const Model* getModelForForEntityItem(const EntityItem* entityItem) = 0; + virtual const Model* getModelForEntityItem(const EntityItem* entityItem) = 0; }; @@ -72,8 +72,8 @@ public: void deleteEntities(QSet entityIDs); const EntityItem* findClosestEntity(glm::vec3 position, float targetRadius); - EntityItem* findEntityByID(uint32_t id, bool alreadyLocked = false) /*const*/; - EntityItem* findEntityByEntityItemID(const EntityItemID& entityID) /*const*/; + EntityItem* findEntityByID(const QUuid& id); + EntityItem* findEntityByEntityItemID(const EntityItemID& entityID); EntityItemID assignEntityID(const EntityItemID& entityItemID); /// Assigns a known ID for a creator token ID diff --git a/libraries/entities/src/todo.txt b/libraries/entities/src/todo.txt index ebef0fc1b7..239c460d22 100644 --- a/libraries/entities/src/todo.txt +++ b/libraries/entities/src/todo.txt @@ -54,7 +54,16 @@ Model properties: DONE -- 22d) void ModelTree::findModelsInCube(const AACube& cube, QVector& foundModels)... DONE -- 22e) void ModelTreeElement::getModelsInside(const AACube& box, QVector& foundModels)... - 13) support sitpoints + 13) support sitpoints and referentials.... + Q) Referentials???? + + For sitting points and referentials you can kill two birds with one stone. + Put this model in world: http://highfidelity-public.s3-us-west-1.amazonaws.com/ozan/theater.fst + Launch sit.js + See sitting points + Sit somewhere + Move model with another avatar. + Observe first avatar moving. K) verify shadows work @@ -67,7 +76,6 @@ Model properties: 12a) make sure server is deleting items?? 12b) Use the delete message instead of shouldDelete property - Q) Referentials???? R) fix these!!! EntityItem::encodeEntityEditMessageDetails()