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
88 // Distributed under the Apache License, Version 2.0.
99 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
1010 //
11+
12+#include <glm/gtc/matrix_transform.hpp>
13+#include <glm/gtx/transform.hpp>
14+
1115 #include "EntityScriptingInterface.h"
1216
1317 #include <QFutureWatcher>
@@ -1039,13 +1043,20 @@ bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3 · 1025 unmodified lines
10391043 void EntityScriptingInterface::voxelsToMesh(QUuid entityID, QScriptValue callback) {
10401044 PROFILE_RANGE(script_entities, __FUNCTION__);
10411045
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+ }
10471055 return true;
10481056 });
1057+
1058+ QScriptValueList args { mesh, success };
1059+ callback.call(QScriptValue(), args);
10491060 }
10501061
10511062 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
16631674 AABox aaBox(low, dimensions);
16641675 return aaBox.findCapsulePenetration(start, end, radius, penetration);
16651676 }
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+}