From 9304477233369fb88a11b0061b8b41cfaf7b1021 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 4 Jan 2016 15:29:06 -0800 Subject: [PATCH] split out calls for rotation and translation --- .../example/avatarcontrol/doppelganger.js | 7 ++-- .../entities/src/EntityScriptingInterface.cpp | 35 +++++++++++++------ .../entities/src/EntityScriptingInterface.h | 4 +++ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/examples/example/avatarcontrol/doppelganger.js b/examples/example/avatarcontrol/doppelganger.js index f918dd85e9..ffd24f09b2 100644 --- a/examples/example/avatarcontrol/doppelganger.js +++ b/examples/example/avatarcontrol/doppelganger.js @@ -48,10 +48,11 @@ function getJointData(avatar) { } function setJointData(doppelganger, allJointData) { + var jointRotations = []; allJointData.forEach(function(jointData, index) { - Entities.setAbsoluteJointTranslationInObjectFrame(doppelganger.id, index, jointData.translation); - Entities.setAbsoluteJointRotationInObjectFrame(doppelganger.id, index, jointData.rotation); + jointRotations.push(jointData.rotation); }); + Entities.setAbsoluteJointRotationsInObjectFrame(doppelganger.id, jointRotations); return true; } @@ -86,7 +87,7 @@ function rotateDoppelgangerTowardAvatar(doppelganger, avatar) { function connectDoppelgangerUpdates() { // Script.update.connect(updateDoppelganger); - Script.setInterval(updateDoppelganger, 500); + Script.setInterval(updateDoppelganger, 100); } function disconnectDoppelgangerUpdates() { diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 4f4b801ac1..4f10139372 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -874,23 +874,21 @@ bool EntityScriptingInterface::setAbsoluteJointRotationInObjectFrame(const QUuid } -bool EntityScriptingInterface::setAbsoluteJointsDataInObjectFrame(const QUuid& entityID, - const QVector& rotations, - const QVector& translations) { + +bool EntityScriptingInterface::setAbsoluteJointRotationsInObjectFrame(const QUuid& entityID, + const QVector& rotations) { if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { auto now = usecTimestampNow(); auto modelEntity = std::dynamic_pointer_cast(entity); - int count = glm::max(rotations.size(), translations.size()); bool result = false; - for (int index = 0; index < count; index++) { + for (int index = 0; index < rotations.size(); index++) { result |= modelEntity->setAbsoluteJointRotationInObjectFrame(index, rotations[index]); } if (result) { EntityItemProperties properties; _entityTree->withWriteLock([&] { properties = entity->getProperties(); - // entity->setLastEdited(now); entity->setLastBroadcast(now); }); @@ -899,17 +897,25 @@ bool EntityScriptingInterface::setAbsoluteJointsDataInObjectFrame(const QUuid& e queueEntityMessage(PacketType::EntityEdit, entityID, properties); return true; } + } + return false; +} - result = false; - for (int index = 0; index < count; index++) { + +bool EntityScriptingInterface::setAbsoluteJointTranslationsInObjectFrame(const QUuid& entityID, + const QVector& translations) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { + auto now = usecTimestampNow(); + auto modelEntity = std::dynamic_pointer_cast(entity); + + bool result = false; + for (int index = 0; index < translations.size(); index++) { result |= modelEntity->setAbsoluteJointTranslationInObjectFrame(index, translations[index]); } - now = usecTimestampNow(); if (result) { EntityItemProperties properties; _entityTree->withWriteLock([&] { properties = entity->getProperties(); - // entity->setLastEdited(now); entity->setLastBroadcast(now); }); @@ -921,3 +927,12 @@ bool EntityScriptingInterface::setAbsoluteJointsDataInObjectFrame(const QUuid& e } return false; } + + +bool EntityScriptingInterface::setAbsoluteJointsDataInObjectFrame(const QUuid& entityID, + const QVector& rotations, + const QVector& translations) { + // for a model with 80 joints, sending both these in one edit packet causes the packet to be too large. + return setAbsoluteJointRotationsInObjectFrame(entityID, rotations) || + setAbsoluteJointTranslationsInObjectFrame(entityID, translations); +} diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index f0751d74b6..5c22d7f6b8 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -153,6 +153,10 @@ public slots: Q_INVOKABLE glm::quat getAbsoluteJointRotationInObjectFrame(const QUuid& entityID, int jointIndex); Q_INVOKABLE bool setAbsoluteJointTranslationInObjectFrame(const QUuid& entityID, int jointIndex, glm::vec3 translation); Q_INVOKABLE bool setAbsoluteJointRotationInObjectFrame(const QUuid& entityID, int jointIndex, glm::quat rotation); + Q_INVOKABLE bool setAbsoluteJointRotationsInObjectFrame(const QUuid& entityID, + const QVector& rotations); + Q_INVOKABLE bool setAbsoluteJointTranslationsInObjectFrame(const QUuid& entityID, + const QVector& translations); Q_INVOKABLE bool setAbsoluteJointsDataInObjectFrame(const QUuid& entityID, const QVector& rotations, const QVector& translations);