Skip to content

Commit

Permalink
Update model AABB during scale operations
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 19, 2017
1 parent 5b00eed commit 432794d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 59 deletions.
11 changes: 10 additions & 1 deletion plugins/model/RenderablePicoModel.cpp
Expand Up @@ -310,6 +310,8 @@ void RenderablePicoModel::setModelPath(const std::string& modelPath)

void RenderablePicoModel::evaluateScale(const Vector3& scale)
{
_localAABB = AABB();

// Apply the scale to each surface
for (Surface& surf : _surfVec)
{
Expand All @@ -324,13 +326,20 @@ void RenderablePicoModel::evaluateScale(const Vector3& scale)
// Apply the scale, on top of the original surface, this should save us from
// reverting the transformation each time the scale changes
surf.surface->applyScale(scale, *(surf.originalSurface));

// Extend the model AABB to include the surface's AABB
_localAABB.includeAABB(surf.surface->getAABB());
}
}

// Freeze transform, move the applied scale to the original model
void RenderablePicoModel::freezeScale()
{
// TODO
// Apply the scale to each surface
for (Surface& surf : _surfVec)
{

}
}

} // namespace
5 changes: 5 additions & 0 deletions plugins/model/RenderablePicoSurface.cpp
Expand Up @@ -407,6 +407,8 @@ void RenderablePicoSurface::applyScale(const Vector3& scale, const RenderablePic
return;
}

_localAABB = AABB();

Matrix4 scaleMatrix = Matrix4::getScale(scale);
Matrix4 invTranspScale = Matrix4::getScale(Vector3(1/scale.x(), 1/scale.y(), 1/scale.z()));

Expand All @@ -416,6 +418,9 @@ void RenderablePicoSurface::applyScale(const Vector3& scale, const RenderablePic
{
_vertices[i].vertex = scaleMatrix.transformPoint(originalSurface._vertices[i].vertex);
_vertices[i].normal = invTranspScale.transformPoint(originalSurface._vertices[i].normal);

// Expand the AABB to include this new vertex
_localAABB.includePoint(_vertices[i].vertex);
}

calculateTangents();
Expand Down
58 changes: 0 additions & 58 deletions radiant/selection/manipulators/ModelScaleManipulator.cpp
Expand Up @@ -48,7 +48,6 @@ void ModelScaleManipulator::testSelect(const render::View& view, const Matrix4&
{
if (view.TestPoint(points[i]))
{
rMessage() << "Got the point " << points[i] << std::endl;
_curManipulatable = node;

// We use the opposite corner as scale pivot
Expand All @@ -57,61 +56,10 @@ void ModelScaleManipulator::testSelect(const render::View& view, const Matrix4&
_scaleComponent.setEntityNode(node);
_scaleComponent.setScalePivot(scalePivot);

rMessage() << "Got a node to manipulate: " << _curManipulatable << std::endl;

break;
}
#if 0
SelectionIntersection intersection;
volume.TestPoint(points[i], intersection);

if (intersection.isValid() && intersection < best)
{
best = intersection;
candidate = node;
}
#endif
}
});

#if 0
{
Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot2World._worldSpace));

{
SelectionIntersection best;
Line_BestPoint(local2view, &_arrowX.front(), best);
selector.addSelectable(best, &_selectableX);
}

{
SelectionIntersection best;
Line_BestPoint(local2view, &_arrowY.front(), best);
selector.addSelectable(best, &_selectableY);
}

{
SelectionIntersection best;
Line_BestPoint(local2view, &_arrowZ.front(), best);
selector.addSelectable(best, &_selectableZ);
}
}

{
Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot2World._viewpointSpace));

{
SelectionIntersection best;
Quad_BestPoint(local2view, eClipCullCW, &_quadScreen.front(), best);
selector.addSelectable(best, &_selectableScreen);
}
}

if (!selector.empty())
{
(*selector.begin()).second->setSelected(true);
}
#endif
}

void ModelScaleManipulator::setSelected(bool select)
Expand Down Expand Up @@ -159,12 +107,6 @@ void ModelScaleManipulator::render(RenderableCollector& collector, const VolumeT
collector.SetState(_pointShader, RenderableCollector::eFullMaterials);

collector.addRenderable(_renderableCornerPoints, Matrix4::getIdentity());

//collector.addRenderable(_arrowX, _pivot2World._worldSpace);
//collector.addRenderable(_arrowY, _pivot2World._worldSpace);
//collector.addRenderable(_arrowZ, _pivot2World._worldSpace);

//collector.addRenderable(_quadScreen, _pivot2World._viewpointSpace);
}

void ModelScaleManipulator::foreachSelectedTransformable(
Expand Down

0 comments on commit 432794d

Please sign in to comment.