Skip to content

Commit

Permalink
Add renderable bounding boxes to manipulator
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 8, 2017
1 parent d27a162 commit c309813
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
2 changes: 2 additions & 0 deletions plugins/model/RenderablePicoSurface.cpp
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions radiant/selection/RadiantSelectionSystem.cpp
Expand Up @@ -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()
Expand Down
36 changes: 31 additions & 5 deletions radiant/selection/manipulators/ModelScaleManipulator.cpp
Expand Up @@ -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);
Expand All @@ -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<void(const scene::INodePtr&, Entity*)>& 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;

}

13 changes: 13 additions & 0 deletions radiant/selection/manipulators/ModelScaleManipulator.h
@@ -1,5 +1,6 @@
#pragma once

#include <list>
#include "ManipulatorBase.h"
#include "ManipulatorComponents.h"

Expand All @@ -8,6 +9,10 @@
#include "selection/Pivot2World.h"
#include "selection/BasicSelectable.h"

#include "entitylib.h"

class Entity;

namespace selection
{

Expand All @@ -30,7 +35,11 @@ class ModelScaleManipulator :

Pivot2World _pivot2World;

std::list<RenderableSolidAABB> _renderableAabbs;

public:
static ShaderPtr _lineShader;

ModelScaleManipulator(ManipulationPivot& pivot);

Type getType() const override;
Expand All @@ -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<void(const scene::INodePtr&, Entity*)>& functor);
};

}

0 comments on commit c309813

Please sign in to comment.