Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 8 files). Show all
Unified · Split
| @@ -822,8 +822,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra · 821 unmodified lines | |||
| 822 | } | 822 | } |
| 823 | } | 823 | } |
| 824 | 824 | ||
| 825 | bool EntityScriptingInterface::setVoxels(QUuid entityID, | 825 | bool EntityScriptingInterface::polyVoxWorker(QUuid entityID, std::function<bool(PolyVoxEntityItem&)> actor) { |
| 826 | std::function<bool(PolyVoxEntityItem&)> actor) { | ||
| 827 | if (!_entityTree) { | 826 | if (!_entityTree) { |
| 828 | return false; | 827 | return false; |
| 829 | } | 828 | } |
| @@ -887,32 +886,38 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line · 57 unmodified lines | |||
| 887 | 886 | ||
| 888 | 887 | ||
| 889 | bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { | 888 | bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { |
| 890 | return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { | 889 | return polyVoxWorker(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { |
| 891 | return polyVoxEntity.setSphere(center, radius, value); | 890 | return polyVoxEntity.setSphere(center, radius, value); |
| 892 | }); | 891 | }); |
| 893 | } | 892 | } |
| 894 | 893 | ||
| 895 | bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) { | 894 | bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) { |
| 896 | return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) { | 895 | return polyVoxWorker(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) { |
| 897 | return polyVoxEntity.setVoxelInVolume(position, value); | 896 | return polyVoxEntity.setVoxelInVolume(position, value); |
| 898 | }); | 897 | }); |
| 899 | } | 898 | } |
| 900 | 899 | ||
| 901 | bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { | 900 | bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { |
| 902 | return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) { | 901 | return polyVoxWorker(entityID, [value](PolyVoxEntityItem& polyVoxEntity) { |
| 903 | return polyVoxEntity.setAll(value); | 902 | return polyVoxEntity.setAll(value); |
| 904 | }); | 903 | }); |
| 905 | } | 904 | } |
| 906 | 905 | ||
| 907 | bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3& lowPosition, | 906 | bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3& lowPosition, |
| 908 | const glm::vec3& cuboidSize, int value) { | 907 | const glm::vec3& cuboidSize, int value) { |
| 909 | return setVoxels(entityID, [lowPosition, cuboidSize, value](PolyVoxEntityItem& polyVoxEntity) { | 908 | return polyVoxWorker(entityID, [lowPosition, cuboidSize, value](PolyVoxEntityItem& polyVoxEntity) { |
| 910 | return polyVoxEntity.setCuboid(lowPosition, cuboidSize, value); | 909 | return polyVoxEntity.setCuboid(lowPosition, cuboidSize, value); |
| 911 | }); | 910 | }); |
| 912 | } | 911 | } |
| 913 | 912 | ||
| 914 | MeshProxy* EntityScriptingInterface::voxelsToMesh(QUuid entityID) { | 913 | void EntityScriptingInterface::voxelsToMesh(QUuid entityID, QScriptValue callback) { |
| 915 | return nullptr; | 914 | polyVoxWorker(entityID, [callback](PolyVoxEntityItem& polyVoxEntity) mutable { |
| 915 | QScriptValue mesh; | ||
| 916 | polyVoxEntity.getMeshAsScriptValue(callback.engine(), mesh); | ||
| 917 | QScriptValueList args { mesh }; | ||
| 918 | callback.call(QScriptValue(), args); | ||
| 919 | return true; | ||
| 920 | }); | ||
| 916 | } | 921 | } |
| 917 | 922 | ||
| 918 | bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) { | 923 | bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) { |