History

Merge branch 'master' of github.com:highfidelity/hifi into parents

Seth Alves committed 10 years ago

Commit 982e9862 parents f99812a 353fe7729 files · +1571 −293Browse files

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

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+43−50
@@ -751,82 +751,75 @@ QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, · 750 unmodified lines
751751 return result;
752752 }
753753
754−glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) {
754+EntityItemPointer EntityScriptingInterface::checkForTreeEntityAndTypeMatch(const QUuid& entityID,
755+ EntityTypes::EntityType entityType) {
755756 if (!_entityTree) {
756− return glm::vec3(0.0f);
757+ return EntityItemPointer();
757758 }
758−
759+
759760 EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
760761 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;
763764 }
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();
768768 }
769−
770− auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
771− return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords);
769+
770+ return entity;
772771 }
773772
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 {
782778 return glm::vec3(0.0f);
783779 }
780+}
784781
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 {
787787 return glm::vec3(0.0f);
788788 }
789−
790− auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
791− return polyVoxEntity->worldCoordsToVoxelCoords(worldCoords);
792789 }
793790
794791 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 {
807796 return glm::vec3(0.0f);
808797 }
809−
810− auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
811− return polyVoxEntity->voxelCoordsToLocalCoords(voxelCoords);
812798 }
813799
814800 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 {
816805 return glm::vec3(0.0f);
817806 }
807+}
818808
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 {
822814 return glm::vec3(0.0f);
823815 }
816+}
824817
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();
828824 }
829−
830− auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
831− return polyVoxEntity->localCoordsToVoxelCoords(localCoords);
832825 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t