From c30981360c5756ed39f228eb7c21edd76d5f66c0 Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 8 Jan 2017 12:09:35 +0100 Subject: [PATCH] Add renderable bounding boxes to manipulator --- plugins/model/RenderablePicoSurface.cpp | 2 ++ radiant/selection/RadiantSelectionSystem.cpp | 1 + .../manipulators/ModelScaleManipulator.cpp | 36 ++++++++++++++++--- .../manipulators/ModelScaleManipulator.h | 13 +++++++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/plugins/model/RenderablePicoSurface.cpp b/plugins/model/RenderablePicoSurface.cpp index 92a5c634ad..ec522f27f0 100644 --- a/plugins/model/RenderablePicoSurface.cpp +++ b/plugins/model/RenderablePicoSurface.cpp @@ -418,6 +418,8 @@ void RenderablePicoSurface::applyScale(const Vector3& scale, const RenderablePic _vertices[i].normal = invTranspScale.transformPoint(originalSurface._vertices[i].normal); } + calculateTangents(); + glDeleteLists(_dlRegular, 1); glDeleteLists(_dlProgramNoVCol, 1); glDeleteLists(_dlProgramVcol, 1); diff --git a/radiant/selection/RadiantSelectionSystem.cpp b/radiant/selection/RadiantSelectionSystem.cpp index 6835356d2b..2d17a3c03a 100644 --- a/radiant/selection/RadiantSelectionSystem.cpp +++ b/radiant/selection/RadiantSelectionSystem.cpp @@ -798,6 +798,7 @@ void RadiantSelectionSystem::captureShaders() TranslateManipulator::_stateFill = GlobalRenderSystem().capture("$FLATSHADE_OVERLAY"); RotateManipulator::_stateOuter = GlobalRenderSystem().capture("$WIRE_OVERLAY"); RotateManipulator::_pivotPointShader = GlobalRenderSystem().capture("$POINT"); + ModelScaleManipulator::_lineShader = GlobalRenderSystem().capture("$WIRE_OVERLAY"); } void RadiantSelectionSystem::releaseShaders() diff --git a/radiant/selection/manipulators/ModelScaleManipulator.cpp b/radiant/selection/manipulators/ModelScaleManipulator.cpp index 873e39db8f..45527303bb 100644 --- a/radiant/selection/manipulators/ModelScaleManipulator.cpp +++ b/radiant/selection/manipulators/ModelScaleManipulator.cpp @@ -90,6 +90,21 @@ void ModelScaleManipulator::render(RenderableCollector& collector, const VolumeT { _pivot2World.update(_pivot.getMatrix4(), volume.GetModelview(), volume.GetProjection(), volume.GetViewport()); + collector.SetState(_lineShader, RenderableCollector::eWireframeOnly); + collector.SetState(_lineShader, RenderableCollector::eFullMaterials); + + _renderableAabbs.clear(); + + foreachSelectedTransformable([&](const scene::INodePtr& node, Entity* entity) + { + _renderableAabbs.push_back(RenderableSolidAABB(node->worldAABB())); + }); + + for (const RenderableSolidAABB& aabb : _renderableAabbs) + { + collector.addRenderable(aabb, Matrix4::getIdentity()); + } + //collector.addRenderable(_arrowX, _pivot2World._worldSpace); //collector.addRenderable(_arrowY, _pivot2World._worldSpace); //collector.addRenderable(_arrowZ, _pivot2World._worldSpace); @@ -101,20 +116,31 @@ void ModelScaleManipulator::scale(const Vector3& scaling) { rMessage() << "Scale: " << scaling << std::endl; + foreachSelectedTransformable([&](const scene::INodePtr& node, Entity* entity) + { + // Apply the scaling spawnarg to this entity + entity->setKeyValue("dr_model_scale", string::to_string(scaling)); + }); + + // Update the scene views + SceneChangeNotify(); +} + +void ModelScaleManipulator::foreachSelectedTransformable( + const std::function& functor) +{ GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node) { Entity* entity = Node_getEntity(node); if (entity && entity->isModel()) { - // Apply the scaling spawnarg to this entity - entity->setKeyValue("dr_model_scale", string::to_string(scaling)); + functor(node, entity); } }); - - // Update the scene views - SceneChangeNotify(); } +ShaderPtr ModelScaleManipulator::_lineShader; + } diff --git a/radiant/selection/manipulators/ModelScaleManipulator.h b/radiant/selection/manipulators/ModelScaleManipulator.h index 3738c196b3..acd21ac88e 100644 --- a/radiant/selection/manipulators/ModelScaleManipulator.h +++ b/radiant/selection/manipulators/ModelScaleManipulator.h @@ -1,5 +1,6 @@ #pragma once +#include #include "ManipulatorBase.h" #include "ManipulatorComponents.h" @@ -8,6 +9,10 @@ #include "selection/Pivot2World.h" #include "selection/BasicSelectable.h" +#include "entitylib.h" + +class Entity; + namespace selection { @@ -30,7 +35,11 @@ class ModelScaleManipulator : Pivot2World _pivot2World; + std::list _renderableAabbs; + public: + static ShaderPtr _lineShader; + ModelScaleManipulator(ManipulationPivot& pivot); Type getType() const override; @@ -41,6 +50,10 @@ class ModelScaleManipulator : void render(RenderableCollector& collector, const VolumeTest& volume) override; void scale(const Vector3& scaling) override; + +private: + void foreachSelectedTransformable( + const std::function& functor); }; }