Skip to content

Commit

Permalink
Resolve #4578: Added option to ignore light volume bounds when calcul…
Browse files Browse the repository at this point in the history
…ating the default pivot location. By default let's set this to active, feedback needed.
  • Loading branch information
codereader committed Jul 22, 2017
1 parent 69e5284 commit 1c46a76
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/version.h
Expand Up @@ -2,7 +2,7 @@
#include <config.h>
#define RADIANT_VERSION PACKAGE_VERSION
#else
#define RADIANT_VERSION "2.3.0pre4"
#define RADIANT_VERSION "2.3.0pre5"
#endif

#define RADIANT_APPNAME "DarkRadiant"
Expand Down
1 change: 1 addition & 0 deletions install/user.xml
Expand Up @@ -57,6 +57,7 @@
<rotateObjectsIndependently value="0" />
<rotationPivotIsOrigin value="0" />
<snapRotationPivotToGrid value="0" />
<defaultPivotLocationIgnoresLightVolumes value="1" />
<selectionEpsilon value="8.0" />
<dragResizeEntitiesSymmetrically value="1" />
<transientComponentSelection value="1" />
Expand Down
17 changes: 11 additions & 6 deletions radiant/selection/ManipulationPivot.cpp
Expand Up @@ -9,16 +9,15 @@
namespace selection
{

namespace
{
const std::string RKEY_ENTITY_PIVOT_IS_ORIGIN = "user/ui/rotationPivotIsOrigin";
const std::string RKEY_SNAP_ROTATION_PIVOT_TO_GRID = "user/ui/snapRotationPivotToGrid";
}
const std::string ManipulationPivot::RKEY_ENTITY_PIVOT_IS_ORIGIN = "user/ui/rotationPivotIsOrigin";
const std::string ManipulationPivot::RKEY_SNAP_ROTATION_PIVOT_TO_GRID = "user/ui/snapRotationPivotToGrid";
const std::string ManipulationPivot::RKEY_DEFAULT_PIVOT_LOCATION_IGNORES_LIGHT_VOLUMES = "user/ui/defaultPivotLocationIgnoresLightVolumes";

ManipulationPivot::ManipulationPivot() :
_entityPivotIsOrigin(false),
_snapPivotToGrid(false),
_needsRecalculation(true),
_defaultPivotLocationIgnoresLightVolumes(false),
_operationActive(false),
_userLocked(false)
{}
Expand All @@ -27,13 +26,17 @@ void ManipulationPivot::initialise()
{
_entityPivotIsOrigin = registry::getValue<bool>(RKEY_ENTITY_PIVOT_IS_ORIGIN);
_snapPivotToGrid = registry::getValue<bool>(RKEY_SNAP_ROTATION_PIVOT_TO_GRID);
_defaultPivotLocationIgnoresLightVolumes = registry::getValue<bool>(RKEY_DEFAULT_PIVOT_LOCATION_IGNORES_LIGHT_VOLUMES);

GlobalRegistry().signalForKey(RKEY_ENTITY_PIVOT_IS_ORIGIN).connect(
sigc::mem_fun(this, &ManipulationPivot::onRegistryKeyChanged)
);
GlobalRegistry().signalForKey(RKEY_SNAP_ROTATION_PIVOT_TO_GRID).connect(
sigc::mem_fun(this, &ManipulationPivot::onRegistryKeyChanged)
);
GlobalRegistry().signalForKey(RKEY_DEFAULT_PIVOT_LOCATION_IGNORES_LIGHT_VOLUMES).connect(
sigc::mem_fun(this, &ManipulationPivot::onRegistryKeyChanged)
);
}

// Returns the pivot-to-world transform
Expand Down Expand Up @@ -145,7 +148,8 @@ void ManipulationPivot::updateFromSelection()
}
else
{
bounds = algorithm::getCurrentSelectionBounds();
// Ignore light volumes for the pivot calculation
bounds = algorithm::getCurrentSelectionBounds(!_defaultPivotLocationIgnoresLightVolumes);
}

// the <bounds> variable now contains the AABB of the selection, retrieve the origin
Expand All @@ -165,6 +169,7 @@ void ManipulationPivot::onRegistryKeyChanged()
{
_entityPivotIsOrigin = registry::getValue<bool>(RKEY_ENTITY_PIVOT_IS_ORIGIN);
_snapPivotToGrid = registry::getValue<bool>(RKEY_SNAP_ROTATION_PIVOT_TO_GRID);
_defaultPivotLocationIgnoresLightVolumes = registry::getValue<bool>(RKEY_DEFAULT_PIVOT_LOCATION_IGNORES_LIGHT_VOLUMES);

GlobalSelectionSystem().pivotChanged();
}
Expand Down
7 changes: 7 additions & 0 deletions radiant/selection/ManipulationPivot.h
Expand Up @@ -33,13 +33,20 @@ class ManipulationPivot
// "dirty" flag
bool _needsRecalculation;

// Whether to consider light volumes when calculating the selection bounds
bool _defaultPivotLocationIgnoresLightVolumes;

// During operations, we want to block pivot recalculations
bool _operationActive;

// "User has modified pivot"-flag, used to block pivot recalculations
bool _userLocked;

public:
static const std::string RKEY_ENTITY_PIVOT_IS_ORIGIN;
static const std::string RKEY_SNAP_ROTATION_PIVOT_TO_GRID;
static const std::string RKEY_DEFAULT_PIVOT_LOCATION_IGNORES_LIGHT_VOLUMES;

ManipulationPivot();

void initialise();
Expand Down
7 changes: 7 additions & 0 deletions radiant/selection/RadiantSelectionSystem.cpp
Expand Up @@ -5,6 +5,7 @@
#include "iselectiongroup.h"
#include "iradiant.h"
#include "ieventmanager.h"
#include "ipreferencesystem.h"
#include "imousetoolmanager.h"
#include "SelectionPool.h"
#include "SelectionTest.h"
Expand Down Expand Up @@ -859,6 +860,7 @@ const StringSet& RadiantSelectionSystem::getDependencies() const
_dependencies.insert(MODULE_SCENEGRAPH);
_dependencies.insert(MODULE_MOUSETOOLMANAGER);
_dependencies.insert(MODULE_MAP);
_dependencies.insert(MODULE_PREFERENCESYSTEM);
}

return _dependencies;
Expand Down Expand Up @@ -918,6 +920,11 @@ void RadiantSelectionSystem::initialiseModule(const ApplicationContext& ctx)
GlobalCommandSystem().addCommand("UnSelectSelection", std::bind(&RadiantSelectionSystem::deselectCmd, this, std::placeholders::_1));
GlobalEventManager().addCommand("UnSelectSelection", "UnSelectSelection");

IPreferencePage& page = GlobalPreferenceSystem().getPage(_("Settings/Selection"));

page.appendCheckBox(_("Ignore light volume bounds when calculating default rotation pivot location"),
ManipulationPivot::RKEY_DEFAULT_PIVOT_LOCATION_IGNORES_LIGHT_VOLUMES);

// Connect the bounds changed caller
GlobalSceneGraph().signal_boundsChanged().connect(
sigc::mem_fun(this, &RadiantSelectionSystem::onSceneBoundsChanged)
Expand Down
30 changes: 27 additions & 3 deletions radiant/selection/algorithm/General.cpp
Expand Up @@ -647,18 +647,42 @@ AABB getCurrentComponentSelectionBounds()
return bounds;
}

AABB getCurrentSelectionBounds()
// This is the same as for selection
AABB getCurrentSelectionBounds(bool considerLightVolumes)
{
AABB bounds;

GlobalSelectionSystem().foreachSelected([&] (const scene::INodePtr& node)
GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node)
{
bounds.includeAABB(node->worldAABB());
if (considerLightVolumes)
{
bounds.includeAABB(node->worldAABB());
return;
}

// We were asked to ignore light volumes, so for lights we'll only
// sum up the small diamond AABB to calculate the selection bounds (#4578)
ILightNodePtr lightNode = Node_getLightNode(node);

if (lightNode)
{
bounds.includeAABB(lightNode->getSelectAABB());
}
else
{
bounds.includeAABB(node->worldAABB());
}
});

return bounds;
}

AABB getCurrentSelectionBounds()
{
// Consider light volumes by default
return getCurrentSelectionBounds(true);
}

Vector3 getCurrentSelectionCenter()
{
return getCurrentSelectionBounds().getOrigin().getSnapped();
Expand Down
6 changes: 6 additions & 0 deletions radiant/selection/algorithm/General.h
Expand Up @@ -97,6 +97,12 @@ namespace selection
Vector3 getCurrentSelectionCenter();

// Returns the AABB of the current selection (invalid bounds if nothing is selected).
// Use the bool to specify whether you want to have the light volumes calculated in
// in their entirety.
AABB getCurrentSelectionBounds(bool considerLightVolumes);

// Returns the AABB of the current selection (invalid bounds if nothing is selected).
// This will call getCurrentSelectionBounds(true) in its implementation.
AABB getCurrentSelectionBounds();

// Calculates the axis-aligned bounding box of the selection components.
Expand Down
6 changes: 3 additions & 3 deletions tools/innosetup/darkradiant.iss
Expand Up @@ -3,15 +3,15 @@

[Setup]
AppName=DarkRadiant
AppVerName=DarkRadiant 2.3.0pre4 x86
AppVerName=DarkRadiant 2.3.0pre5 x86
AppPublisher=The Dark Mod
AppPublisherURL=http://www.thedarkmod.com
AppSupportURL=http://www.thedarkmod.com
AppUpdatesURL=http://www.thedarkmod.com
DefaultDirName={pf}\DarkRadiant
DefaultGroupName=DarkRadiant 2.3.0pre4 x86
DefaultGroupName=DarkRadiant 2.3.0pre5 x86
OutputDir=.
OutputBaseFilename=darkradiant-2.3.0pre4-x86
OutputBaseFilename=darkradiant-2.3.0pre5-x86
Compression=lzma
SolidCompression=yes
;ArchitecturesAllowed=x64
Expand Down
6 changes: 3 additions & 3 deletions tools/innosetup/darkradiant.x64.iss
Expand Up @@ -3,15 +3,15 @@

[Setup]
AppName=DarkRadiant
AppVerName=DarkRadiant 2.3.0pre4 x64
AppVerName=DarkRadiant 2.3.0pre5 x64
AppPublisher=The Dark Mod
AppPublisherURL=http://www.thedarkmod.com
AppSupportURL=http://www.thedarkmod.com
AppUpdatesURL=http://www.thedarkmod.com
DefaultDirName={pf}\DarkRadiant
DefaultGroupName=DarkRadiant 2.3.0pre4 x64
DefaultGroupName=DarkRadiant 2.3.0pre5 x64
OutputDir=.
OutputBaseFilename=darkradiant-2.3.0pre4-x64
OutputBaseFilename=darkradiant-2.3.0pre5-x64
Compression=lzma
SolidCompression=yes
ArchitecturesAllowed=x64
Expand Down

0 comments on commit 1c46a76

Please sign in to comment.