Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 29 files). Show all
Unified · Split
| @@ -751,82 +751,75 @@ QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, · 750 unmodified lines | |||
| 751 | return result; | 751 | return result; |
| 752 | } | 752 | } |
| 753 | 753 | ||
| 754 | glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) { | 754 | EntityItemPointer EntityScriptingInterface::checkForTreeEntityAndTypeMatch(const QUuid& entityID, |
| 755 | EntityTypes::EntityType entityType) { | ||
| 755 | if (!_entityTree) { | 756 | if (!_entityTree) { |
| 756 | return glm::vec3(0.0f); | 757 | return EntityItemPointer(); |
| 757 | } | 758 | } |
| 758 | 759 | ||
| 759 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | 760 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); |
| 760 | if (!entity) { | 761 | if (!entity) { |
| 761 | qCDebug(entities) << "EntityScriptingInterface::voxelCoordsToWorldCoords no entity with ID" << entityID; | 762 | qDebug() << "EntityScriptingInterface::checkForTreeEntityAndTypeMatch - no entity with ID" << entityID; |
| 762 | return glm::vec3(0.0f); | 763 | return entity; |
| 763 | } | 764 | } |
| 764 | 765 | ||
| 765 | EntityTypes::EntityType entityType = entity->getType(); | 766 | if (entityType != EntityTypes::Unknown && entity->getType() != entityType) { |
| 766 | if (entityType != EntityTypes::PolyVox) { | 767 | return EntityItemPointer(); |
| 767 | return glm::vec3(0.0f); | ||
| 768 | } | 768 | } |
| 769 | 769 | ||
| 770 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | 770 | return entity; |
| 771 | return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords); | ||
| 772 | } | 771 | } |
| 773 | 772 | ||
| 774 | glm::vec3 EntityScriptingInterface::worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords) { | 773 | glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) { |
| 775 | if (!_entityTree) { | 774 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { |
| 776 | return glm::vec3(0.0f); | 775 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); |
| 777 | } | 776 | return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords); |
| 778 | 777 | } else { | |
| 779 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | ||
| 780 | if (!entity) { | ||
| 781 | qCDebug(entities) << "EntityScriptingInterface::worldCoordsToVoxelCoords no entity with ID" << entityID; | ||
| 782 | return glm::vec3(0.0f); | 778 | return glm::vec3(0.0f); |
| 783 | } | 779 | } |
| 780 | } | ||
| 784 | 781 | ||
| 785 | EntityTypes::EntityType entityType = entity->getType(); | 782 | glm::vec3 EntityScriptingInterface::worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords) { |
| 786 | if (entityType != EntityTypes::PolyVox) { | 783 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { |
| 784 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | ||
| 785 | return polyVoxEntity->worldCoordsToVoxelCoords(worldCoords); | ||
| 786 | } else { | ||
| 787 | return glm::vec3(0.0f); | 787 | return glm::vec3(0.0f); |
| 788 | } | 788 | } |
| 789 | |||
| 790 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | ||
| 791 | return polyVoxEntity->worldCoordsToVoxelCoords(worldCoords); | ||
| 792 | } | 789 | } |
| 793 | 790 | ||
| 794 | glm::vec3 EntityScriptingInterface::voxelCoordsToLocalCoords(const QUuid& entityID, glm::vec3 voxelCoords) { | 791 | glm::vec3 EntityScriptingInterface::voxelCoordsToLocalCoords(const QUuid& entityID, glm::vec3 voxelCoords) { |
| 795 | if (!_entityTree) { | 792 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { |
| 796 | return glm::vec3(0.0f); | 793 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); |
| 797 | } | 794 | return polyVoxEntity->voxelCoordsToLocalCoords(voxelCoords); |
| 798 | 795 | } else { | |
| 799 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | ||
| 800 | if (!entity) { | ||
| 801 | qCDebug(entities) << "EntityScriptingInterface::voxelCoordsToLocalCoords no entity with ID" << entityID; | ||
| 802 | return glm::vec3(0.0f); | ||
| 803 | } | ||
| 804 | |||
| 805 | EntityTypes::EntityType entityType = entity->getType(); | ||
| 806 | if (entityType != EntityTypes::PolyVox) { | ||
| 807 | return glm::vec3(0.0f); | 796 | return glm::vec3(0.0f); |
| 808 | } | 797 | } |
| 809 | |||
| 810 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | ||
| 811 | return polyVoxEntity->voxelCoordsToLocalCoords(voxelCoords); | ||
| 812 | } | 798 | } |
| 813 | 799 | ||
| 814 | glm::vec3 EntityScriptingInterface::localCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 localCoords) { | 800 | glm::vec3 EntityScriptingInterface::localCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 localCoords) { |
| 815 | if (!_entityTree) { | 801 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { |
| 802 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | ||
| 803 | return polyVoxEntity->localCoordsToVoxelCoords(localCoords); | ||
| 804 | } else { | ||
| 816 | return glm::vec3(0.0f); | 805 | return glm::vec3(0.0f); |
| 817 | } | 806 | } |
| 807 | } | ||
| 818 | 808 | ||
| 819 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | 809 | glm::vec3 EntityScriptingInterface::getJointTranslation(const QUuid& entityID, int jointIndex) { |
| 820 | if (!entity) { | 810 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { |
| 821 | qCDebug(entities) << "EntityScriptingInterface::localCoordsToVoxelCoords no entity with ID" << entityID; | 811 | auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity); |
| 812 | return modelEntity->getJointTranslation(jointIndex); | ||
| 813 | } else { | ||
| 822 | return glm::vec3(0.0f); | 814 | return glm::vec3(0.0f); |
| 823 | } | 815 | } |
| 816 | } | ||
| 824 | 817 | ||
| 825 | EntityTypes::EntityType entityType = entity->getType(); | 818 | glm::quat EntityScriptingInterface::getJointRotation(const QUuid& entityID, int jointIndex) { |
| 826 | if (entityType != EntityTypes::PolyVox) { | 819 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { |
| 827 | return glm::vec3(0.0f); | 820 | auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity); |
| 821 | return modelEntity->getJointRotation(jointIndex); | ||
| 822 | } else { | ||
| 823 | return glm::quat(); | ||
| 828 | } | 824 | } |
| 829 | |||
| 830 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | ||
| 831 | return polyVoxEntity->localCoordsToVoxelCoords(localCoords); | ||
| 832 | } | 825 | } |