Model scripting
Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 11 files). Show all
Unified · Split
| @@ -8,6 +8,10 @@ · 7 unmodified lines | ||
| 8 | 8 | // Distributed under the Apache License, Version 2.0. |
| 9 | 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| 10 | 10 | // |
| 11 | + | |
| 12 | +#include <glm/gtc/matrix_transform.hpp> | |
| 13 | +#include <glm/gtx/transform.hpp> | |
| 14 | + | |
| 11 | 15 | #include "EntityScriptingInterface.h" |
| 12 | 16 | |
| 13 | 17 | #include <QFutureWatcher> |
| @@ -1039,13 +1043,20 @@ bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3 · 1025 unmodified lines | ||
| 1039 | 1043 | void EntityScriptingInterface::voxelsToMesh(QUuid entityID, QScriptValue callback) { |
| 1040 | 1044 | PROFILE_RANGE(script_entities, __FUNCTION__); |
| 1041 | 1045 | |
| 1042 | − polyVoxWorker(entityID, [callback](PolyVoxEntityItem& polyVoxEntity) mutable { | |
| 1043 | − QScriptValue mesh; | |
| 1044 | − polyVoxEntity.getMeshAsScriptValue(callback.engine(), mesh); | |
| 1045 | − QScriptValueList args { mesh }; | |
| 1046 | − callback.call(QScriptValue(), args); | |
| 1046 | + bool success { false }; | |
| 1047 | + QScriptValue mesh { false }; | |
| 1048 | + | |
| 1049 | + polyVoxWorker(entityID, [&](PolyVoxEntityItem& polyVoxEntity) mutable { | |
| 1050 | + if (polyVoxEntity.getOnCount() == 0) { | |
| 1051 | + success = true; | |
| 1052 | + } else { | |
| 1053 | + success = polyVoxEntity.getMeshAsScriptValue(callback.engine(), mesh); | |
| 1054 | + } | |
| 1047 | 1055 | return true; |
| 1048 | 1056 | }); |
| 1057 | + | |
| 1058 | + QScriptValueList args { mesh, success }; | |
| 1059 | + callback.call(QScriptValue(), args); | |
| 1049 | 1060 | } |
| 1050 | 1061 | |
| 1051 | 1062 | bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) { |
| @@ -1663,3 +1674,20 @@ bool EntityScriptingInterface::AABoxIntersectsCapsule(const glm::vec3& low, cons · 611 unmodified lines | ||
| 1663 | 1674 | AABox aaBox(low, dimensions); |
| 1664 | 1675 | return aaBox.findCapsulePenetration(start, end, radius, penetration); |
| 1665 | 1676 | } |
| 1677 | + | |
| 1678 | +glm::mat4 EntityScriptingInterface::getEntityTransform(const QUuid& entityID) { | |
| 1679 | + glm::mat4 result; | |
| 1680 | + if (_entityTree) { | |
| 1681 | + _entityTree->withReadLock([&] { | |
| 1682 | + EntityItemPointer entity = _entityTree->findEntityByEntityItemID(EntityItemID(entityID)); | |
| 1683 | + if (entity) { | |
| 1684 | + glm::mat4 translation = glm::translate(entity->getPosition()); | |
| 1685 | + glm::mat4 rotation = glm::mat4_cast(entity->getRotation()); | |
| 1686 | + glm::mat4 registration = glm::translate(ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - | |
| 1687 | + entity->getRegistrationPoint()); | |
| 1688 | + result = translation * rotation * registration; | |
| 1689 | + } | |
| 1690 | + }); | |
| 1691 | + } | |
| 1692 | + return result; | |
| 1693 | +} | |