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 | 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 | 686 | if (!_entityTree) { |
| 686 | − return glm::vec3(0.0f); | |
| 687 | + return EntityItemPointer(); | |
| 687 | 688 | } |
| 688 | − | |
| 689 | + | |
| 689 | 690 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); |
| 690 | 691 | 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; | |
| 693 | 694 | } |
| 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(); | |
| 698 | 698 | } |
| 699 | − | |
| 700 | − auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | |
| 701 | − return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords); | |
| 699 | + | |
| 700 | + return entity; | |
| 702 | 701 | } |
| 703 | 702 | |
| 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 { | |
| 712 | 708 | return glm::vec3(0.0f); |
| 713 | 709 | } |
| 710 | +} | |
| 714 | 711 | |
| 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 { | |
| 717 | 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 | 721 | 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 { | |
| 737 | 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 | 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 | 735 | return glm::vec3(0.0f); |
| 747 | 736 | } |
| 737 | +} | |
| 748 | 738 | |
| 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 { | |
| 752 | 744 | return glm::vec3(0.0f); |
| 753 | 745 | } |
| 746 | +} | |
| 754 | 747 | |
| 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(); | |
| 758 | 754 | } |
| 759 | − | |
| 760 | − auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | |
| 761 | − return polyVoxEntity->localCoordsToVoxelCoords(localCoords); | |
| 762 | 755 | } |