History

getLocalJointRotation getLocalJointTranslation, started on getLocalJointTranslation getLocalJointRotation

Seth Alves committed 10 years ago

Commit 339d6a51 parent ee9ed6d6 files · +112 −2Browse files

Unified · Split

6 files
  1. libraries/entities-renderer/src/RenderableModelEntityItem.cpp +34 −0
  2. libraries/entities-renderer/src/RenderableModelEntityItem.h +6 −0
  3. libraries/entities/src/EntityScriptingInterface.cpp +62 −0
  4. libraries/entities/src/EntityScriptingInterface.h +6 −0
  5. libraries/entities/src/ModelEntityItem.h +2 −2
  6. libraries/shared/src/SpatiallyNestable.h +2 −0
libraries/entities-renderer/src/RenderableModelEntityItem.cpp+34−0
@@ -1017,6 +1017,40 @@ glm::vec3 RenderableModelEntityItem::getAbsoluteJointTranslationInObjectFrame(in · 1016 unmodified lines
10171017 return glm::vec3(0.0f);
10181018 }
10191019
1020+bool RenderableModelEntityItem::setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) {
1021+ // TODO -- write this
1022+ assert(false);
1023+ abort();
1024+ return false;
1025+}
1026+
1027+bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) {
1028+ // TODO -- write this
1029+ assert(false);
1030+ abort();
1031+ return false;
1032+}
1033+
1034+glm::quat RenderableModelEntityItem::getLocalJointRotation(int index) const {
1035+ if (_model) {
1036+ glm::quat result;
1037+ if (_model->getJointRotation(index, result)) {
1038+ return result;
1039+ }
1040+ }
1041+ return glm::quat();
1042+}
1043+
1044+glm::vec3 RenderableModelEntityItem::getLocalJointTranslation(int index) const {
1045+ if (_model) {
1046+ glm::vec3 result;
1047+ if (_model->getJointTranslation(index, result)) {
1048+ return result;
1049+ }
1050+ }
1051+ return glm::vec3();
1052+}
1053+
10201054 bool RenderableModelEntityItem::setLocalJointRotation(int index, const glm::quat& rotation) {
10211055 bool result = false;
10221056 _jointDataLock.withWriteLock([&] {
libraries/entities-renderer/src/RenderableModelEntityItem.h+6−0
@@ -71,6 +71,12 @@ public: · 70 unmodified lines
7171 // these are in the frame of this object (model space)
7272 virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override;
7373 virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(int index) const override;
74+ virtual bool setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) override;
75+ virtual bool setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) override;
76+
77+
78+ virtual glm::quat getLocalJointRotation(int index) const override;
79+ virtual glm::vec3 getLocalJointTranslation(int index) const override;
7480 virtual bool setLocalJointRotation(int index, const glm::quat& rotation) override;
7581 virtual bool setLocalJointTranslation(int index, const glm::vec3& translation) override;
7682
libraries/entities/src/EntityScriptingInterface.cpp+62−0
@@ -1110,6 +1110,68 @@ glm::quat EntityScriptingInterface::getAbsoluteJointRotationInObjectFrame(const · 1109 unmodified lines
11101110 }
11111111 }
11121112
1113+bool EntityScriptingInterface::setAbsoluteJointTranslationInObjectFrame(const QUuid& entityID,
1114+ int jointIndex, glm::vec3 translation) {
1115+ if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) {
1116+ auto now = usecTimestampNow();
1117+ auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity);
1118+ bool result = modelEntity->setAbsoluteJointTranslationInObjectFrame(jointIndex, translation);
1119+ if (result) {
1120+ EntityItemProperties properties;
1121+ _entityTree->withWriteLock([&] {
1122+ properties = entity->getProperties();
1123+ entity->setLastBroadcast(now);
1124+ });
1125+
1126+ properties.setJointTranslationsDirty();
1127+ properties.setLastEdited(now);
1128+ queueEntityMessage(PacketType::EntityEdit, entityID, properties);
1129+ return true;
1130+ }
1131+ }
1132+ return false;
1133+}
1134+
1135+bool EntityScriptingInterface::setAbsoluteJointRotationInObjectFrame(const QUuid& entityID,
1136+ int jointIndex, glm::quat rotation) {
1137+ if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) {
1138+ auto now = usecTimestampNow();
1139+ auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity);
1140+ bool result = modelEntity->setAbsoluteJointRotationInObjectFrame(jointIndex, rotation);
1141+ if (result) {
1142+ EntityItemProperties properties;
1143+ _entityTree->withWriteLock([&] {
1144+ properties = entity->getProperties();
1145+ entity->setLastBroadcast(now);
1146+ });
1147+
1148+ properties.setJointRotationsDirty();
1149+ properties.setLastEdited(now);
1150+ queueEntityMessage(PacketType::EntityEdit, entityID, properties);
1151+ return true;
1152+ }
1153+ }
1154+ return false;
1155+}
1156+
1157+glm::vec3 EntityScriptingInterface::getLocalJointTranslation(const QUuid& entityID, int jointIndex) {
1158+ if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) {
1159+ auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity);
1160+ return modelEntity->getLocalJointTranslation(jointIndex);
1161+ } else {
1162+ return glm::vec3(0.0f);
1163+ }
1164+}
1165+
1166+glm::quat EntityScriptingInterface::getLocalJointRotation(const QUuid& entityID, int jointIndex) {
1167+ if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) {
1168+ auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity);
1169+ return modelEntity->getLocalJointRotation(jointIndex);
1170+ } else {
1171+ return glm::quat();
1172+ }
1173+}
1174+
11131175 bool EntityScriptingInterface::setLocalJointTranslation(const QUuid& entityID, int jointIndex, glm::vec3 translation) {
11141176 if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) {
11151177 auto now = usecTimestampNow();
libraries/entities/src/EntityScriptingInterface.h+6−0
@@ -184,8 +184,14 @@ public slots: · 183 unmodified lines
184184
185185 Q_INVOKABLE glm::vec3 getAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex);
186186 Q_INVOKABLE glm::quat getAbsoluteJointRotationInObjectFrame(const QUuid& entityID, int jointIndex);
187+ Q_INVOKABLE bool setAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex, glm::vec3 translation);
188+ Q_INVOKABLE bool setAbsoluteJointRotationInObjectFrame(const QUuid& entityID, int jointIndex, glm::quat rotation);
189+
190+ Q_INVOKABLE glm::vec3 getLocalJointTranslation(const QUuid& entityID, int jointIndex);
191+ Q_INVOKABLE glm::quat getLocalJointRotation(const QUuid& entityID, int jointIndex);
187192 Q_INVOKABLE bool setLocalJointTranslation(const QUuid& entityID, int jointIndex, glm::vec3 translation);
188193 Q_INVOKABLE bool setLocalJointRotation(const QUuid& entityID, int jointIndex, glm::quat rotation);
194+
189195 Q_INVOKABLE bool setLocalJointRotations(const QUuid& entityID, const QVector<glm::quat>& rotations);
190196 Q_INVOKABLE bool setLocalJointTranslations(const QUuid& entityID, const QVector<glm::vec3>& translations);
191197 Q_INVOKABLE bool setLocalJointsData(const QUuid& entityID,
libraries/entities/src/ModelEntityItem.h+2−2
@@ -117,8 +117,8 @@ public: · 116 unmodified lines
117117
118118 virtual bool shouldBePhysical() const override;
119119
120− virtual glm::vec3 getJointPosition(int jointIndex) const { return glm::vec3(); }
121− virtual glm::quat getJointRotation(int jointIndex) const { return glm::quat(); }
120+ // virtual glm::vec3 getJointPosition(int jointIndex) const { return glm::vec3(); }
121+ // virtual glm::quat getJointRotation(int jointIndex) const { return glm::quat(); }
122122
123123 virtual void setJointRotations(const QVector<glm::quat>& rotations);
124124 virtual void setJointRotationsSet(const QVector<bool>& rotationsSet);
libraries/shared/src/SpatiallyNestable.h+2−0
@@ -144,6 +144,8 @@ public: · 143 unmodified lines
144144 virtual bool setAbsoluteJointRotationInObjectFrame(int index, const glm::quat& rotation) { return false; }
145145 virtual bool setAbsoluteJointTranslationInObjectFrame(int index, const glm::vec3& translation) {return false; }
146146
147+ virtual glm::quat getLocalJointRotation(int index) const {return glm::quat(); }
148+ virtual glm::vec3 getLocalJointTranslation(int index) const {return glm::vec3(); }
147149 virtual bool setLocalJointRotation(int index, const glm::quat& rotation) { return false; }
148150 virtual bool setLocalJointTranslation(int index, const glm::vec3& translation) { return false; }
149151