Skip to content

Commit

Permalink
#5128: More interface definitions of methods we're going to need
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 15, 2021
1 parent a761636 commit e50ad5f
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 13 deletions.
6 changes: 6 additions & 0 deletions include/ibrush.h
Expand Up @@ -156,6 +156,12 @@ class IFace
// If possible, aligns the assigned texture at the given anchor edge
virtual void alignTexture(AlignEdge alignType) = 0;

// Reverts any transform that has been applied since the last time freezeTransform() was called
virtual void revertTransform() = 0;

// Promotes the current transformed state to the new base state
virtual void freezeTransform() = 0;

// Get access to the actual Winding object
virtual IWinding& getWinding() = 0;
virtual const IWinding& getWinding() const = 0;
Expand Down
18 changes: 15 additions & 3 deletions include/itexturetoolmodel.h
Expand Up @@ -24,10 +24,19 @@ namespace textool
class ITransformable
{
public:
/**
* Applies the given transform to all selected components of this node.
*/
// Let this object save a snapshot of its current texture state to have something
// to base the upcoming transformation on
virtual void beginTransformation() = 0;

// Move the state back to the base state we saved in beginTransformation()
// Is called right before applyTransformationToSelected() is invoked with a new transform
virtual void revertTransformation() = 0;

// Applies the given transform to all selected components of this node.
virtual void applyTransformToSelected(const Matrix3& transform) = 0;

// "Saves" the current transformed state as the new base state
virtual void commitTransformation() = 0;
};

// The base element of every node in the ITextureToolSceneGraph
Expand All @@ -41,6 +50,9 @@ class INode :
virtual ~INode() {}

using Ptr = std::shared_ptr<INode>;

// Renders this node, with all coords relative to UV space origin
virtual void render() = 0;
};

/**
Expand Down
31 changes: 26 additions & 5 deletions radiant/textool/TexTool.cpp
Expand Up @@ -586,11 +586,19 @@ Vector2 TexTool::getTextureCoords(const double& x, const double& y) {
return result;
}

void TexTool::drawUVCoords() {
void TexTool::drawUVCoords()
{
GlobalTextureToolSceneGraph().foreachNode([&](const textool::INode::Ptr& node)
{
node->render();
return true;
});
#if 0
// Cycle through the items and tell them to render themselves
for (std::size_t i = 0; i < _items.size(); i++) {
_items[i]->render();
}
}
#endif
}

textool::TexToolItemVec
Expand Down Expand Up @@ -1362,22 +1370,35 @@ Matrix4 TexTool::getPivot2World()

void TexTool::onManipulationStart()
{

GlobalTextureToolSceneGraph().foreachSelectedNode([&] (const textool::INode::Ptr& node)
{
node->beginTransformation();
return true;
});
}

void TexTool::onManipulationChanged()
{

}

void TexTool::onManipulationEnd()
{
GlobalTextureToolSceneGraph().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->commitTransformation();
return true;
});

_activeManipulator->setSelected(false);
}

void TexTool::onManipulationCancelled()
{

GlobalTextureToolSceneGraph().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->revertTransformation();
return true;
});
}


Expand Down
7 changes: 5 additions & 2 deletions radiantcore/brush/Face.cpp
Expand Up @@ -553,9 +553,12 @@ void Face::setTexDefFromPoints(const Vector3 points[3], const Vector2 uvs[3])

auto textureMatrix = uv * xyz.getFullInverse();

_texdef.setTransform(textureMatrix);
m_texdefTransformed.setTransform(textureMatrix);

texdefChanged();
EmitTextureCoordinates();

// Fire the signal to update the Texture Tools
signal_texdefChanged().emit();
}

void Face::shiftTexdef(float s, float t)
Expand Down
5 changes: 2 additions & 3 deletions radiantcore/brush/Face.h
Expand Up @@ -114,8 +114,8 @@ class Face :
void assign_planepts(const PlanePoints planepts);

/// \brief Reverts the transformable state of the brush to identity.
void revertTransform();
void freezeTransform();
void revertTransform() override;
void freezeTransform() override;

void update_move_planepts_vertex(std::size_t index, PlanePoints planePoints);

Expand Down Expand Up @@ -144,7 +144,6 @@ class Face :

// Constructs the texture projection matrix from the given (world) vertex and texture coords.
// Three vertices and their UV coordinates are enough to construct the texdef.
// Will fire texDefChanged() after assigning the new texture matrix.
void setTexDefFromPoints(const Vector3 points[3], const Vector2 uvs[3]);

ShiftScaleRotation getShiftScaleRotation() const override;
Expand Down
Expand Up @@ -46,6 +46,8 @@ void TextureRotator::transform(const Matrix4& pivot2world, const VolumeTest& vie
auto sign = _start.crossProduct(current) < 0 ? +1 : -1;
_curAngle *= sign;

rMessage() << "Current angle: " << _curAngle << std::endl;

_rotateFunctor(Vector2(pivot2world.tx(), pivot2world.ty()), _curAngle);
}

Expand Down Expand Up @@ -154,6 +156,7 @@ void TextureToolRotateManipulator::rotateSelected(const Vector2& pivot, double a

GlobalTextureToolSceneGraph().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
node->revertTransformation();
node->applyTransformToSelected(transform);
return true;
});
Expand Down
56 changes: 56 additions & 0 deletions radiantcore/selection/textool/FaceNode.h
Expand Up @@ -19,6 +19,16 @@ class FaceNode :
_face(face)
{}

void beginTransformation() override
{
_face.undoSave();
}

void revertTransformation() override
{
_face.revertTransform();
}

void applyTransformToSelected(const Matrix3& transform) override
{
for (auto& vertex : _face.getWinding())
Expand All @@ -32,6 +42,11 @@ class FaceNode :
_face.setTexDefFromPoints(vertices, texcoords);
}

void commitTransformation() override
{
_face.freezeTransform();
}

const AABB& localAABB() const
{
_bounds = AABB();
Expand Down Expand Up @@ -65,6 +80,47 @@ class FaceNode :
Selector_add(selector, *this);
}
}

void render() override
{
glEnable(GL_BLEND);
glBlendColor(0, 0, 0, 0.3f);
glBlendFunc(GL_CONSTANT_ALPHA_EXT, GL_ONE_MINUS_CONSTANT_ALPHA_EXT);

if (isSelected())
{
glColor3f(1, 0.5f, 0);
}
else {
glColor3f(0.8f, 0.8f, 0.8f);
}

glBegin(GL_TRIANGLE_FAN);

for (const auto& vertex : _face.getWinding())
{
glVertex2d(vertex.texcoord[0], vertex.texcoord[1]);
}

glEnd();
glDisable(GL_BLEND);

glPointSize(5);
glBegin(GL_POINTS);
/*for (Winding::const_iterator i = _winding.begin(); i != _winding.end(); ++i)
{
glVertex2f(i->texcoord[0], i->texcoord[1]);
}*/

//glColor3f(1, 1, 1);

//Vector2 centroid = _face.getWinding();
//glVertex2d(centroid[0], centroid[1]);

glEnd();

glDisable(GL_BLEND);
}
};

}
17 changes: 17 additions & 0 deletions radiantcore/selection/textool/PatchNode.h
Expand Up @@ -18,11 +18,23 @@ class PatchNode :
_patch(patch)
{}

void beginTransformation() override
{
}

void revertTransformation() override
{
}

void applyTransformToSelected(const Matrix3& transform) override
{
// TODO
}

void commitTransformation() override
{
}

const AABB& localAABB() const
{
_bounds = AABB();
Expand All @@ -41,7 +53,12 @@ class PatchNode :

void testSelect(Selector& selector, SelectionTest& test) override
{
// TODO
}

void render() override
{
// TODO
}
};

Expand Down

0 comments on commit e50ad5f

Please sign in to comment.