History

hook up a way to get mesh out of polyvox

Seth Alves committed 9 years ago

Commit d158f6a1 parent d6b22168 files · +60 −30Browse files

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

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+21−16
@@ -822,8 +822,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra · 821 unmodified lines
822822 }
823823 }
824824
825−bool EntityScriptingInterface::setVoxels(QUuid entityID,
826− std::function<bool(PolyVoxEntityItem&)> actor) {
825+bool EntityScriptingInterface::polyVoxWorker(QUuid entityID, std::function<bool(PolyVoxEntityItem&)> actor) {
827826 if (!_entityTree) {
828827 return false;
829828 }
@@ -887,32 +886,38 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line · 57 unmodified lines
887886
888887
889888 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+ });
893892 }
894893
895894 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+ });
899898 }
900899
901900 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+ });
905904 }
906905
907906 bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3& lowPosition,
908907 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+ });
912911 }
913912
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+ });
916921 }
917922
918923 bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) {