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, | |
| 826 | − std::function<bool(PolyVoxEntityItem&)> actor) { | |
| 825 | +bool EntityScriptingInterface::polyVoxWorker(QUuid entityID, std::function<bool(PolyVoxEntityItem&)> actor) { | |
| 827 | 826 | if (!_entityTree) { |
| 828 | 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 | 888 | bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { |
| 890 | − return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { | |
| 891 | − return polyVoxEntity.setSphere(center, radius, value); | |
| 892 | − }); | |
| 889 | + return polyVoxWorker(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { | |
| 890 | + return polyVoxEntity.setSphere(center, radius, value); | |
| 891 | + }); | |
| 893 | 892 | } |
| 894 | 893 | |
| 895 | 894 | bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) { |
| 896 | − return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) { | |
| 897 | − return polyVoxEntity.setVoxelInVolume(position, value); | |
| 898 | − }); | |
| 895 | + return polyVoxWorker(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) { | |
| 896 | + return polyVoxEntity.setVoxelInVolume(position, value); | |
| 897 | + }); | |
| 899 | 898 | } |
| 900 | 899 | |
| 901 | 900 | bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { |
| 902 | − return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) { | |
| 903 | − return polyVoxEntity.setAll(value); | |
| 904 | − }); | |
| 901 | + return polyVoxWorker(entityID, [value](PolyVoxEntityItem& polyVoxEntity) { | |
| 902 | + return polyVoxEntity.setAll(value); | |
| 903 | + }); | |
| 905 | 904 | } |
| 906 | 905 | |
| 907 | 906 | bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3& lowPosition, |
| 908 | 907 | const glm::vec3& cuboidSize, int value) { |
| 909 | − return setVoxels(entityID, [lowPosition, cuboidSize, value](PolyVoxEntityItem& polyVoxEntity) { | |
| 910 | − return polyVoxEntity.setCuboid(lowPosition, cuboidSize, value); | |
| 911 | − }); | |
| 908 | + return polyVoxWorker(entityID, [lowPosition, cuboidSize, value](PolyVoxEntityItem& polyVoxEntity) { | |
| 909 | + return polyVoxEntity.setCuboid(lowPosition, cuboidSize, value); | |
| 910 | + }); | |
| 912 | 911 | } |
| 913 | 912 | |
| 914 | −MeshProxy* EntityScriptingInterface::voxelsToMesh(QUuid entityID) { | |
| 915 | − return nullptr; | |
| 913 | +void EntityScriptingInterface::voxelsToMesh(QUuid entityID, QScriptValue callback) { | |
| 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 | 923 | bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) { |