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 | 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 | 756 | if (!_entityTree) { |
| 756 | − return glm::vec3(0.0f); | |
| 757 | + return EntityItemPointer(); | |
| 757 | 758 | } |
| 758 | − | |
| 759 | + | |
| 759 | 760 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); |
| 760 | 761 | if (!entity) { |
| 761 | − qCDebug(entities) << "EntityScriptingInterface::voxelCoordsToWorldCoords no entity with ID" << entityID; | |
| 762 | − return glm::vec3(0.0f); | |
| 762 | + qDebug() << "EntityScriptingInterface::checkForTreeEntityAndTypeMatch - no entity with ID" << entityID; | |
| 763 | + return entity; | |
| 763 | 764 | } |
| 764 | − | |
| 765 | − EntityTypes::EntityType entityType = entity->getType(); | |
| 766 | − if (entityType != EntityTypes::PolyVox) { | |
| 767 | − return glm::vec3(0.0f); | |
| 765 | + | |
| 766 | + if (entityType != EntityTypes::Unknown && entity->getType() != entityType) { | |
| 767 | + return EntityItemPointer(); | |
| 768 | 768 | } |
| 769 | − | |
| 770 | − auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | |
| 771 | − return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords); | |
| 769 | + | |
| 770 | + return entity; | |
| 772 | 771 | } |
| 773 | 772 | |
| 774 | −glm::vec3 EntityScriptingInterface::worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords) { | |
| 775 | − if (!_entityTree) { | |
| 776 | − return glm::vec3(0.0f); | |
| 777 | − } | |
| 778 | − | |
| 779 | − EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | |
| 780 | − if (!entity) { | |
| 781 | − qCDebug(entities) << "EntityScriptingInterface::worldCoordsToVoxelCoords no entity with ID" << entityID; | |
| 773 | +glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) { | |
| 774 | + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { | |
| 775 | + auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | |
| 776 | + return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords); | |
| 777 | + } else { | |
| 782 | 778 | return glm::vec3(0.0f); |
| 783 | 779 | } |
| 780 | +} | |
| 784 | 781 | |
| 785 | − EntityTypes::EntityType entityType = entity->getType(); | |
| 786 | − if (entityType != EntityTypes::PolyVox) { | |
| 782 | +glm::vec3 EntityScriptingInterface::worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords) { | |
| 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 | 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 | 791 | glm::vec3 EntityScriptingInterface::voxelCoordsToLocalCoords(const QUuid& entityID, glm::vec3 voxelCoords) { |
| 795 | − if (!_entityTree) { | |
| 796 | − return glm::vec3(0.0f); | |
| 797 | − } | |
| 798 | − | |
| 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) { | |
| 792 | + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { | |
| 793 | + auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | |
| 794 | + return polyVoxEntity->voxelCoordsToLocalCoords(voxelCoords); | |
| 795 | + } else { | |
| 807 | 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 | 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 | 805 | return glm::vec3(0.0f); |
| 817 | 806 | } |
| 807 | +} | |
| 818 | 808 | |
| 819 | − EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | |
| 820 | − if (!entity) { | |
| 821 | − qCDebug(entities) << "EntityScriptingInterface::localCoordsToVoxelCoords no entity with ID" << entityID; | |
| 809 | +glm::vec3 EntityScriptingInterface::getJointTranslation(const QUuid& entityID, int jointIndex) { | |
| 810 | + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { | |
| 811 | + auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity); | |
| 812 | + return modelEntity->getJointTranslation(jointIndex); | |
| 813 | + } else { | |
| 822 | 814 | return glm::vec3(0.0f); |
| 823 | 815 | } |
| 816 | +} | |
| 824 | 817 | |
| 825 | − EntityTypes::EntityType entityType = entity->getType(); | |
| 826 | − if (entityType != EntityTypes::PolyVox) { | |
| 827 | − return glm::vec3(0.0f); | |
| 818 | +glm::quat EntityScriptingInterface::getJointRotation(const QUuid& entityID, int jointIndex) { | |
| 819 | + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { | |
| 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 | } |