History

add getJointPosition and getJointRotation for entities

Stephen Birarda committed 11 years ago

Commit 4f6da681 parent 06872a66 files · +125 −62Browse files

Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 6 files). Show all

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+43−50
@@ -681,82 +681,75 @@ QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, · 680 unmodified lines
681681 return result;
682682 }
683683
684−glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) {
684+EntityItemPointer EntityScriptingInterface::checkForTreeEntityAndTypeMatch(const QUuid& entityID,
685+ EntityTypes::EntityType entityType) {
685686 if (!_entityTree) {
686− return glm::vec3(0.0f);
687+ return EntityItemPointer();
687688 }
688−
689+
689690 EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
690691 if (!entity) {
691− qCDebug(entities) << "EntityScriptingInterface::voxelCoordsToWorldCoords no entity with ID" << entityID;
692− return glm::vec3(0.0f);
692+ qDebug() << "EntityScriptingInterface::checkForTreeEntityAndTypeMatch - no entity with ID" << entityID;
693+ return entity;
693694 }
694−
695− EntityTypes::EntityType entityType = entity->getType();
696− if (entityType != EntityTypes::PolyVox) {
697− return glm::vec3(0.0f);
695+
696+ if (entityType != EntityTypes::Unknown && entity->getType() != entityType) {
697+ return EntityItemPointer();
698698 }
699−
700− auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
701− return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords);
699+
700+ return entity;
702701 }
703702
704−glm::vec3 EntityScriptingInterface::worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords) {
705− if (!_entityTree) {
706− return glm::vec3(0.0f);
707− }
708−
709− EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
710− if (!entity) {
711− qCDebug(entities) << "EntityScriptingInterface::worldCoordsToVoxelCoords no entity with ID" << entityID;
703+glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) {
704+ if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) {
705+ auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
706+ return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords);
707+ } else {
712708 return glm::vec3(0.0f);
713709 }
710+}
714711
715− EntityTypes::EntityType entityType = entity->getType();
716− if (entityType != EntityTypes::PolyVox) {
712+glm::vec3 EntityScriptingInterface::worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords) {
713+ if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) {
714+ auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
715+ return polyVoxEntity->worldCoordsToVoxelCoords(worldCoords);
716+ } else {
717717 return glm::vec3(0.0f);
718718 }
719−
720− auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
721− return polyVoxEntity->worldCoordsToVoxelCoords(worldCoords);
722719 }
723720
724721 glm::vec3 EntityScriptingInterface::voxelCoordsToLocalCoords(const QUuid& entityID, glm::vec3 voxelCoords) {
725− if (!_entityTree) {
726− return glm::vec3(0.0f);
727− }
728−
729− EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
730− if (!entity) {
731− qCDebug(entities) << "EntityScriptingInterface::voxelCoordsToLocalCoords no entity with ID" << entityID;
732− return glm::vec3(0.0f);
733− }
734−
735− EntityTypes::EntityType entityType = entity->getType();
736− if (entityType != EntityTypes::PolyVox) {
722+ if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) {
723+ auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
724+ return polyVoxEntity->voxelCoordsToLocalCoords(voxelCoords);
725+ } else {
737726 return glm::vec3(0.0f);
738727 }
739−
740− auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
741− return polyVoxEntity->voxelCoordsToLocalCoords(voxelCoords);
742728 }
743729
744730 glm::vec3 EntityScriptingInterface::localCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 localCoords) {
745− if (!_entityTree) {
731+ if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) {
732+ auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
733+ return polyVoxEntity->localCoordsToVoxelCoords(localCoords);
734+ } else {
746735 return glm::vec3(0.0f);
747736 }
737+}
748738
749− EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
750− if (!entity) {
751− qCDebug(entities) << "EntityScriptingInterface::localCoordsToVoxelCoords no entity with ID" << entityID;
739+glm::vec3 EntityScriptingInterface::getJointPosition(const QUuid& entityID, int jointIndex) {
740+ if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) {
741+ auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity);
742+ return modelEntity->getJointPosition(jointIndex);
743+ } else {
752744 return glm::vec3(0.0f);
753745 }
746+}
754747
755− EntityTypes::EntityType entityType = entity->getType();
756− if (entityType != EntityTypes::PolyVox) {
757− return glm::vec3(0.0f);
748+glm::quat EntityScriptingInterface::getJointRotation(const QUuid& entityID, int jointIndex) {
749+ if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) {
750+ auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity);
751+ return modelEntity->getJointRotation(jointIndex);
752+ } else {
753+ return glm::quat();
758754 }
759−
760− auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
761− return polyVoxEntity->localCoordsToVoxelCoords(localCoords);
762755 }