Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -681,82 +681,75 @@ QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, · 680 unmodified lines | |||
| 681 | return result; | 681 | return result; |
| 682 | } | 682 | } |
| 683 | 683 | ||
| 684 | glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) { | 684 | EntityItemPointer EntityScriptingInterface::checkForTreeEntityAndTypeMatch(const QUuid& entityID, |
| 685 | EntityTypes::EntityType entityType) { | ||
| 685 | if (!_entityTree) { | 686 | if (!_entityTree) { |
| 686 | return glm::vec3(0.0f); | 687 | return EntityItemPointer(); |
| 687 | } | 688 | } |
| 688 | 689 | ||
| 689 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | 690 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); |
| 690 | if (!entity) { | 691 | if (!entity) { |
| 691 | qCDebug(entities) << "EntityScriptingInterface::voxelCoordsToWorldCoords no entity with ID" << entityID; | 692 | qDebug() << "EntityScriptingInterface::checkForTreeEntityAndTypeMatch - no entity with ID" << entityID; |
| 692 | return glm::vec3(0.0f); | 693 | return entity; |
| 693 | } | 694 | } |
| 694 | 695 | ||
| 695 | EntityTypes::EntityType entityType = entity->getType(); | 696 | if (entityType != EntityTypes::Unknown && entity->getType() != entityType) { |
| 696 | if (entityType != EntityTypes::PolyVox) { | 697 | return EntityItemPointer(); |
| 697 | return glm::vec3(0.0f); | ||
| 698 | } | 698 | } |
| 699 | 699 | ||
| 700 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | 700 | return entity; |
| 701 | return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords); | ||
| 702 | } | 701 | } |
| 703 | 702 | ||
| 704 | glm::vec3 EntityScriptingInterface::worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords) { | 703 | glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) { |
| 705 | if (!_entityTree) { | 704 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { |
| 706 | return glm::vec3(0.0f); | 705 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); |
| 707 | } | 706 | return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords); |
| 708 | 707 | } else { | |
| 709 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | ||
| 710 | if (!entity) { | ||
| 711 | qCDebug(entities) << "EntityScriptingInterface::worldCoordsToVoxelCoords no entity with ID" << entityID; | ||
| 712 | return glm::vec3(0.0f); | 708 | return glm::vec3(0.0f); |
| 713 | } | 709 | } |
| 710 | } | ||
| 714 | 711 | ||
| 715 | EntityTypes::EntityType entityType = entity->getType(); | 712 | glm::vec3 EntityScriptingInterface::worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords) { |
| 716 | if (entityType != EntityTypes::PolyVox) { | 713 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { |
| 714 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | ||
| 715 | return polyVoxEntity->worldCoordsToVoxelCoords(worldCoords); | ||
| 716 | } else { | ||
| 717 | return glm::vec3(0.0f); | 717 | return glm::vec3(0.0f); |
| 718 | } | 718 | } |
| 719 | |||
| 720 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | ||
| 721 | return polyVoxEntity->worldCoordsToVoxelCoords(worldCoords); | ||
| 722 | } | 719 | } |
| 723 | 720 | ||
| 724 | glm::vec3 EntityScriptingInterface::voxelCoordsToLocalCoords(const QUuid& entityID, glm::vec3 voxelCoords) { | 721 | glm::vec3 EntityScriptingInterface::voxelCoordsToLocalCoords(const QUuid& entityID, glm::vec3 voxelCoords) { |
| 725 | if (!_entityTree) { | 722 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { |
| 726 | return glm::vec3(0.0f); | 723 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); |
| 727 | } | 724 | return polyVoxEntity->voxelCoordsToLocalCoords(voxelCoords); |
| 728 | 725 | } else { | |
| 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) { | ||
| 737 | return glm::vec3(0.0f); | 726 | return glm::vec3(0.0f); |
| 738 | } | 727 | } |
| 739 | |||
| 740 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | ||
| 741 | return polyVoxEntity->voxelCoordsToLocalCoords(voxelCoords); | ||
| 742 | } | 728 | } |
| 743 | 729 | ||
| 744 | glm::vec3 EntityScriptingInterface::localCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 localCoords) { | 730 | 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 { | ||
| 746 | return glm::vec3(0.0f); | 735 | return glm::vec3(0.0f); |
| 747 | } | 736 | } |
| 737 | } | ||
| 748 | 738 | ||
| 749 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | 739 | glm::vec3 EntityScriptingInterface::getJointPosition(const QUuid& entityID, int jointIndex) { |
| 750 | if (!entity) { | 740 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { |
| 751 | qCDebug(entities) << "EntityScriptingInterface::localCoordsToVoxelCoords no entity with ID" << entityID; | 741 | auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity); |
| 742 | return modelEntity->getJointPosition(jointIndex); | ||
| 743 | } else { | ||
| 752 | return glm::vec3(0.0f); | 744 | return glm::vec3(0.0f); |
| 753 | } | 745 | } |
| 746 | } | ||
| 754 | 747 | ||
| 755 | EntityTypes::EntityType entityType = entity->getType(); | 748 | glm::quat EntityScriptingInterface::getJointRotation(const QUuid& entityID, int jointIndex) { |
| 756 | if (entityType != EntityTypes::PolyVox) { | 749 | if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { |
| 757 | return glm::vec3(0.0f); | 750 | auto modelEntity = std::dynamic_pointer_cast<ModelEntityItem>(entity); |
| 751 | return modelEntity->getJointRotation(jointIndex); | ||
| 752 | } else { | ||
| 753 | return glm::quat(); | ||
| 758 | } | 754 | } |
| 759 | |||
| 760 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | ||
| 761 | return polyVoxEntity->localCoordsToVoxelCoords(localCoords); | ||
| 762 | } | 755 | } |