History

Merge pull request #9946 from sethalves/model-scripting-1

Model scripting

Brad Hefta-Gaub committed 9 years ago

Commit ac309df2 parents 3f30909 b876d2211 files · +310 −20Browse files

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

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+33−5
@@ -8,6 +8,10 @@ · 7 unmodified lines
8// Distributed under the Apache License, Version 2.0.8// Distributed under the Apache License, Version 2.0.
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html9// 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#include "EntityScriptingInterface.h"15#include "EntityScriptingInterface.h"
12 16
13#include <QFutureWatcher>17#include <QFutureWatcher>
@@ -1039,13 +1043,20 @@ bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3 · 1025 unmodified lines
1039void EntityScriptingInterface::voxelsToMesh(QUuid entityID, QScriptValue callback) {1043void EntityScriptingInterface::voxelsToMesh(QUuid entityID, QScriptValue callback) {
1040 PROFILE_RANGE(script_entities, __FUNCTION__);1044 PROFILE_RANGE(script_entities, __FUNCTION__);
1041 1045
1042 polyVoxWorker(entityID, [callback](PolyVoxEntityItem& polyVoxEntity) mutable {1046 bool success { false };
1043 QScriptValue mesh;1047 QScriptValue mesh { false };
1044 polyVoxEntity.getMeshAsScriptValue(callback.engine(), mesh);1048
1045 QScriptValueList args { mesh };1049 polyVoxWorker(entityID, [&](PolyVoxEntityItem& polyVoxEntity) mutable {
1046 callback.call(QScriptValue(), args);1050 if (polyVoxEntity.getOnCount() == 0) {
1051 success = true;
1052 } else {
1053 success = polyVoxEntity.getMeshAsScriptValue(callback.engine(), mesh);
1054 }
1047 return true;1055 return true;
1048 });1056 });
1057
1058 QScriptValueList args { mesh, success };
1059 callback.call(QScriptValue(), args);
1049}1060}
1050 1061
1051bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) {1062bool 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 AABox aaBox(low, dimensions);1674 AABox aaBox(low, dimensions);
1664 return aaBox.findCapsulePenetration(start, end, radius, penetration);1675 return aaBox.findCapsulePenetration(start, end, radius, penetration);
1665}1676}
1677
1678glm::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}