From 88048e8599a83beea1f77a02c4eed5ddf0c605c9 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 3 Dec 2014 12:47:32 -0800 Subject: [PATCH] Make sure the position of the heightfield/voxel brush is valid before acting. --- interface/src/ui/MetavoxelEditor.cpp | 14 ++++++++++---- interface/src/ui/MetavoxelEditor.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index b6b43c4baf..349a73b9c7 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -884,7 +884,8 @@ void ImportHeightfieldTool::updateSpanner() { } HeightfieldBrushTool::HeightfieldBrushTool(MetavoxelEditor* editor, const QString& name) : - MetavoxelTool(editor, name, false) { + MetavoxelTool(editor, name, false), + _positionValid(false) { QWidget* widget = new QWidget(); widget->setLayout(_form = new QFormLayout()); @@ -911,8 +912,10 @@ void HeightfieldBrushTool::render() { float distance; if (!Application::getInstance()->getMetavoxels()->findFirstRayHeightfieldIntersection(origin, direction, distance)) { + _positionValid = false; return; } + _positionValid = true; Application::getInstance()->getMetavoxels()->renderHeightfieldCursor( _position = origin + distance * direction, _radius->value()); } @@ -924,7 +927,7 @@ bool HeightfieldBrushTool::eventFilter(QObject* watched, QEvent* event) { _radius->setValue(_radius->value() * glm::pow(2.0f, angle * ANGLE_SCALE)); return true; - } else if (event->type() == QEvent::MouseButtonPress) { + } else if (event->type() == QEvent::MouseButtonPress && _positionValid) { MetavoxelEditMessage message = { createEdit(static_cast(event)->button() == Qt::RightButton) }; Application::getInstance()->getMetavoxels()->applyEdit(message, true); return true; @@ -1103,7 +1106,8 @@ void VoxelMaterialSpannerTool::applyEdit(const AttributePointer& attribute, cons } VoxelBrushTool::VoxelBrushTool(MetavoxelEditor* editor, const QString& name) : - MetavoxelTool(editor, name, false, true) { + MetavoxelTool(editor, name, false, true), + _positionValid(false) { QWidget* widget = new QWidget(); widget->setLayout(_form = new QFormLayout()); @@ -1132,8 +1136,10 @@ void VoxelBrushTool::render() { if (!(Application::getInstance()->getMetavoxels()->findFirstRayHeightfieldIntersection( origin, direction, heightfieldDistance) | Application::getInstance()->getMetavoxels()->findFirstRayVoxelIntersection(origin, direction, voxelDistance))) { + _positionValid = false; return; } + _positionValid = true; Application::getInstance()->getMetavoxels()->renderVoxelCursor( _position = origin + qMin(heightfieldDistance, voxelDistance) * direction, _radius->value()); } @@ -1145,7 +1151,7 @@ bool VoxelBrushTool::eventFilter(QObject* watched, QEvent* event) { _radius->setValue(_radius->value() * glm::pow(2.0f, angle * ANGLE_SCALE)); return true; - } else if (event->type() == QEvent::MouseButtonPress) { + } else if (event->type() == QEvent::MouseButtonPress && _positionValid) { MetavoxelEditMessage message = { createEdit(static_cast(event)->button() == Qt::RightButton) }; Application::getInstance()->getMetavoxels()->applyEdit(message, true); return true; diff --git a/interface/src/ui/MetavoxelEditor.h b/interface/src/ui/MetavoxelEditor.h index cccb41ecfc..15e731e2ee 100644 --- a/interface/src/ui/MetavoxelEditor.h +++ b/interface/src/ui/MetavoxelEditor.h @@ -326,6 +326,7 @@ protected: QDoubleSpinBox* _radius; glm::vec3 _position; + bool _positionValid; }; /// Allows raising or lowering parts of the heightfield. @@ -456,6 +457,7 @@ protected: QDoubleSpinBox* _radius; glm::vec3 _position; + bool _positionValid; }; /// Allows texturing parts of the voxel field.