diff --git a/src/fgt/edit_texture/Container.h b/src/fgt/edit_texture/Container.h index be6797b61..4b85bc03a 100644 --- a/src/fgt/edit_texture/Container.h +++ b/src/fgt/edit_texture/Container.h @@ -3,6 +3,7 @@ #include #include +#include #include using namespace std; @@ -22,6 +23,7 @@ class Container face.push_back(f); wt.push_back(wtindex); count = 1; + imark.push_back(0); }; ~Container(){}; void SetVertex(QRect r) {rect = r;}; @@ -34,22 +36,22 @@ class Container bool IsV() {return marca;}; void SetV() {marca = true;}; void ClearV() {marca = false;}; - void AddAdj(int val) + void AddAdj(CVertexO* val) { unsigned i = 0; for(; i < adj.size(); i++) if (adj[i] == val) break; if (i == adj.size())adj.push_back(val); }; - int GetAdjAt(int index) {return adj[index];}; + CVertexO* GetAdjAt(int index) {return adj[index];}; int GetAdjSize() {return adj.size();}; - bool ContainAdj(int val) + bool ContainAdj(CVertexO* val) { for(unsigned i = 0; i < adj.size(); i++) if (adj[i] == val) return true; return false; } - void AddFace(CFaceO* f) {face.push_back(f); count++;}; + void AddFace(CFaceO* f) {face.push_back(f); count++; imark.push_back(0);}; CFaceO* GetFaceAt(int index) {return face[index];}; unsigned GetFaceSize() {return face.size();}; void SetCompID(int val) {idcomp = val;}; @@ -61,17 +63,20 @@ class Container unsigned GetCount() {return count;} void Decrease() {--count;}; void Reset() {count = adj.size()-1;}; + void Mark(unsigned i) {imark[i]++;}; + unsigned GetMark(unsigned i) {return imark[i];}; private: QRect rect; // Rectangle of the projected vertex float cu,cv; // Values of the coord bool marca; // Visit mark - vector adj; // Set of adjacent faces + vector adj; // Set of adjacent faces int idcomp; // Id of the component of the vertex CVertexO* punt; // Pointer to the real vertex vector face; // Set of faces that refer to the vertex vector wt; // Set of WT indexes of the faces unsigned count; + vector imark; }; #endif \ No newline at end of file diff --git a/src/fgt/edit_texture/edittexture.cpp b/src/fgt/edit_texture/edittexture.cpp index db73ee4fc..8371ff6ad 100644 --- a/src/fgt/edit_texture/edittexture.cpp +++ b/src/fgt/edit_texture/edittexture.cpp @@ -298,19 +298,21 @@ void EditTexturePlugin::InitTexture(MeshModel &m) if (!m.cm.textures.empty()) { // Procedure: - vector< vector > param; + vector< QHash > param; vector outofrange; int actualID = -1; // ID of the component for (unsigned i = 0; i < m.cm.textures.size(); i++) // init the vectors { vector tmp; - param.push_back(tmp); + param.push_back(QHash()); outofrange.push_back(false); } - vector Q; // Set of selected face + vector Q; // Set of selected face CMeshO::FaceIterator fi; vector V; // Set (3) of the vertex in the actual face + + vector> ver; unsigned i = 0; for(fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi) @@ -331,26 +333,6 @@ void EditTexturePlugin::InitTexture(MeshModel &m) V.push_back(Q[i]->V(1)); V.push_back(Q[i]->V(2)); - // Search for vertex indexes in the param vector, if a vertex isn't already visited it wille be the next - // added to the vector... - int nb[3]; nb[0] = -1; nb[1] = -1; nb[2] = -1; - int count = 0; - if (!V[0]->IsUserBit(visBit)) {nb[0] = param[Q[i]->WT(0).n()].size() + count; count++;} - if (!V[1]->IsUserBit(visBit)) {nb[1] = param[Q[i]->WT(1).n()].size() + count; count++;} - if (!V[2]->IsUserBit(visBit)) {nb[2] = param[Q[i]->WT(2).n()].size() + count; count++;} - for (unsigned y = 0; y < param[Q[i]->WT(0).n()].size(); y++) - { - if (nb[0] != -1 && nb[1] != -1 && nb[2] != -1) break; // I've find all the indexes - for (int yy = 0; yy < 3; yy++) - { - if (param[Q[i]->WT(0).n()][y].GetPointer() == V[yy] && param[Q[i]->WT(0).n()][y].GetCompID() == actualID) - { - nb[yy] = y; - break; - } - } - } - for (int j = 0; j < 3; j++) { CVertexO* pv = V[j]; @@ -365,17 +347,17 @@ void EditTexturePlugin::InitTexture(MeshModel &m) // but for the Y axis I must subtract the screen height for the conversion... QRect r = QRect(u * AREADIM - RADIUS/2, (AREADIM - (v * AREADIM)) - RADIUS/2, RADIUS, RADIUS); Container a = Container(actualID, u, v, r, pv, Q[i], j); - a.AddAdj(nb[(j+1)%3]); - a.AddAdj(nb[(j+2)%3]); - param[Q[i]->WT(0).n()].push_back(a); + a.AddAdj(V[(j+1)%3]); + a.AddAdj(V[(j+2)%3]); + param[Q[i]->WT(0).n()][pv] = a; pv->SetUserBit(visBit); } else // Add a new adj to the existing vertex { - param[Q[i]->WT(0).n()][nb[j]].AddAdj(nb[(j+1)%3]); - param[Q[i]->WT(0).n()][nb[j]].AddAdj(nb[(j+2)%3]); - param[Q[i]->WT(0).n()][nb[j]].AddFace(Q[i]); - param[Q[i]->WT(0).n()][nb[j]].AddWT(j); + param[Q[i]->WT(0).n()][pv].AddAdj(V[(j+1)%3]); + param[Q[i]->WT(0).n()][pv].AddAdj(V[(j+2)%3]); + param[Q[i]->WT(0).n()][pv].AddFace(Q[i]); + param[Q[i]->WT(0).n()][pv].AddWT(j); } } Q[i]->SetV(); diff --git a/src/fgt/edit_texture/edittexture.h b/src/fgt/edit_texture/edittexture.h index 19f635af7..ee34ea4ab 100644 --- a/src/fgt/edit_texture/edittexture.h +++ b/src/fgt/edit_texture/edittexture.h @@ -9,7 +9,7 @@ #include #include "textureeditor.h" #include "ui_textureeditor.h" -#include "container.h" +#include "Container.h" class EditTexturePlugin : public QObject, public MeshEditInterface { diff --git a/src/fgt/edit_texture/renderarea.cpp b/src/fgt/edit_texture/renderarea.cpp index ab1af86c1..1f428a0e5 100644 --- a/src/fgt/edit_texture/renderarea.cpp +++ b/src/fgt/edit_texture/renderarea.cpp @@ -2,7 +2,9 @@ #include "renderarea.h" #include "textureeditor.h" -RenderArea::RenderArea(QWidget *parent, QString textureName, vector uvmap, bool outRange) : QWidget(parent) +static unsigned COUNTER = 0; + +RenderArea::RenderArea(QWidget *parent, QString textureName, QHash uvmap, bool outRange) : QGLWidget(parent) { antialiased = true; setBackgroundRole(QPalette::Base); @@ -54,7 +56,7 @@ void RenderArea::setTexture(QString path) fileName = path; } -void RenderArea::SetUVMap(vector uv) +void RenderArea::SetUVMap(QHash uv) { map = uv; } @@ -93,40 +95,8 @@ void RenderArea::paintEvent(QPaintEvent * /* event */) if (map.size() > 0) { // Draw the selected component - if (highComp != -1 && mode == Face) - { - /* Visit the 'grid' of vertexes and step by step change the value of the counter. - If the counter reach 0 the vertex will not be drawn anymore. - */ - // <---- FIX - painter.setBrush(Qt::red); - painter.setOpacity(0.5); - for (unsigned y = 0; y < connected.size(); y++) - { - if (map[connected[y]].GetCount() > 0) - { - QVector p; - int y1 = 0, y2 = 1; - while (map[connected[y]].GetCount() > 0) - { - //if (map[map[connected[y]].GetAdjAt(y1)].GetCount() > 0 && map[map[connected[y]].GetAdjAt(y2)].GetCount() > 0) - { - p.push_back(map[connected[y]].GetVertex().center()); - p.push_back(map[map[connected[y]].GetAdjAt(y1)].GetVertex().center()); - p.push_back(map[map[connected[y]].GetAdjAt(y2)].GetVertex().center()); - map[connected[y]].Decrease(); - map[map[connected[y]].GetAdjAt(y1)].Decrease(); - map[map[connected[y]].GetAdjAt(y2)].Decrease(); - painter.drawPolygon(QPolygon(p)); - p.clear(); - if (!map[map[connected[y]].GetAdjAt(y1)].ContainAdj(map[connected[y]].GetAdjAt((y2+1)%map[connected[y]].GetAdjSize()))) y1 = y2; - y2 = (y2+1)%map[connected[y]].GetAdjSize(); - } - } - } - } - for (unsigned y = 0; y < connected.size(); y++) map[connected[y]].Reset(); - } + + /* // Draw the lines... for (unsigned i = 0; i < map.size(); i++) { @@ -136,14 +106,17 @@ void RenderArea::paintEvent(QPaintEvent * /* event */) if (d > i) painter.drawLine(map[i].GetVertex().center(),map[d].GetVertex().center()); } } + */ // ...and the vertexes (as a circle) - for (unsigned i = 0; i < map.size(); i++) + QHashIterator i(map); + while (i.hasNext()) { + i.next(); painter.setOpacity(1.0); painter.setBrush(Qt::yellow); - if ((i == highClick && mode == Point) || (i == highComp && mode == Face)) painter.setBrush(Qt::blue); - else if (i == highlightedPoint) painter.setBrush(Qt::red); - painter.drawEllipse(map[i].GetVertex()); + //if ((i == highClick && mode == Point) || (i == highComp && mode == Face)) painter.setBrush(Qt::blue); + //else if (i == highlightedPoint) painter.setBrush(Qt::red); + painter.drawEllipse((&(Container)i.value())->GetVertex()); } } painter.setPen(palette().dark().color()); @@ -153,6 +126,7 @@ void RenderArea::paintEvent(QPaintEvent * /* event */) void RenderArea::mousePressEvent(QMouseEvent *event) { + /* switch(mode) { case Point: @@ -189,18 +163,20 @@ void RenderArea::mousePressEvent(QMouseEvent *event) } this->update(); break; - } + }*/ } void RenderArea::mouseReleaseEvent(QMouseEvent *) { + /* isDragging = false; if(highlightedPoint != -1) this->update(map[highlightedPoint].GetVertex()); - if (mode == Face && moved) {UpdateUV(); moved = false;} + if (mode == Face && moved) {UpdateUV(); moved = false;}*/ } void RenderArea::mouseMoveEvent(QMouseEvent *event) { + /* if (isDragging) { QPoint tmp = event->pos(); @@ -258,10 +234,12 @@ void RenderArea::mouseMoveEvent(QMouseEvent *event) } } return; + */ } void RenderArea::RemapRepeat() { + /* // Remap the uv in 9 planes: the main plain is in the middle, the coordinates over // the border will be mapped in the other planes out = true; @@ -273,10 +251,12 @@ void RenderArea::RemapRepeat() map[i].SetVertex(GetRepeatVertex(u,v,i)); } this->update(); + */ } void RenderArea::RemapClamp() { + /* // Remap the uv coord out of border using clamp method out = false; for (unsigned i = 0; i < map.size(); i++) @@ -286,10 +266,12 @@ void RenderArea::RemapClamp() map[i].SetVertex(GetClampVertex(u, v, i)); } this->update(); + */ } void RenderArea::RemapMod() { + /* // Remap the uv coord out of border using mod function out = false; for (unsigned i = 0; i < map.size(); i++) @@ -304,10 +286,12 @@ void RenderArea::RemapMod() UpdateSingleUV(i, u, v); } this->update(); + */ } void RenderArea::UpdateVertex(float u, float v) { + /* // Update the position of the vertexes from user spin box input QRect r; if (!out) r = GetClampVertex(u, v, -1); @@ -316,10 +300,12 @@ void RenderArea::UpdateVertex(float u, float v) map[highClick].SetV(v); map[highClick].SetVertex(r); this->update(); + */ } void RenderArea::VisitConnected() { + /* // Visit the vertex-tree and initialize the vector 'connected' adding the index of the face with FF adjacency. connected.clear(); int id = map[highComp].GetCompID(); @@ -327,6 +313,7 @@ void RenderArea::VisitConnected() { if (map[i].GetCompID() == id) connected.push_back(i); } + */ } void RenderArea::ChangeMode(int index) @@ -347,8 +334,10 @@ void RenderArea::ChangeMode(int index) this->update(); } + void RenderArea::UpdateComponentPos(int x, int y) { + /* // Update the position of all vertexes of the connected component for (unsigned i = 0; i < connected.size(); i++) { @@ -359,10 +348,12 @@ void RenderArea::UpdateComponentPos(int x, int y) } this->update(); // The UV Coord will be updated after mouse-release event + */ } void RenderArea::RotateComponent(float alfa) { + /* // Calcolate the new position of the vertex of the selected component after a rotation. // The rotation is done around the selected vertex (= highComp) QPoint origin = map[highComp].GetVertex().center(); @@ -380,10 +371,12 @@ void RenderArea::RotateComponent(float alfa) (float)(AREADIM - map[connected[i]].GetVertex().center().y()) / AREADIM); } this->update(); + */ } void RenderArea::ScaleComponent(int perc) { + /* // Scale the selected component. The origin is set to the selected vertex ( = highComp) QPoint origin = map[highComp].GetVertex().center(); map[highComp].SetV(); @@ -402,10 +395,12 @@ void RenderArea::ScaleComponent(int perc) (float)(AREADIM - map[connected[i]].GetVertex().center().y()) / AREADIM); } this->update(); + */ } void RenderArea::UpdateUV() { + /* // After a move of component, re-calculate the new UV coordinates for (unsigned i = 0; i < connected.size(); i++) { @@ -413,10 +408,12 @@ void RenderArea::UpdateUV() float v = (float)(AREADIM - map[connected[i]].GetVertex().center().y()) / AREADIM; UpdateSingleUV(connected[i], u, v); } + */ } void RenderArea::UpdateSingleUV(int index, float u, float v) { + /* // Update the UV Coord of the vertex map[index] if (!out) { @@ -430,10 +427,12 @@ void RenderArea::UpdateSingleUV(int index, float u, float v) } map[index].SetU(u); map[index].SetV(v); + */ } QRect RenderArea::GetRepeatVertex(float u, float v, int index) { + /* // Return the new position of the vertex in the RenderArea space in 'Repeat' mode. // If the passed index is valid, also update the UV coord // The function is called from the Remap (--> change UV) and from the UpdateVertex @@ -478,10 +477,13 @@ QRect RenderArea::GetRepeatVertex(float u, float v, int index) map[index].SetV(realv); } return QRect(u - RADIUS/2, AREADIM - v - RADIUS/2, RADIUS, RADIUS); + */ + return QRect(); } QRect RenderArea::GetClampVertex(float u, float v, int index) { + /* // Return the new position of the vertex in the RenderArea space in 'Clamp' mode. // If the passed index is valid, also update the UV coord // The function is called from the Remap (--> change UV) and from the UpdateVertex @@ -491,4 +493,6 @@ QRect RenderArea::GetClampVertex(float u, float v, int index) else if (v > 1) v = 1; if (index != -1) UpdateSingleUV(index, u, v); return QRect(u * AREADIM - RADIUS/2, (AREADIM - (v * AREADIM)) - RADIUS/2, RADIUS, RADIUS); -} \ No newline at end of file + */ + return QRect(); +} diff --git a/src/fgt/edit_texture/renderarea.h b/src/fgt/edit_texture/renderarea.h index c38a9817a..f7b01fb6a 100644 --- a/src/fgt/edit_texture/renderarea.h +++ b/src/fgt/edit_texture/renderarea.h @@ -4,11 +4,12 @@ #include #include #include -#include -#include "container.h" +#include "Container.h" #include +#include + #define AREADIM 300 #define TEXTX 125 @@ -24,7 +25,7 @@ using namespace std; -class RenderArea : public QWidget +class RenderArea : public QGLWidget { Q_OBJECT @@ -32,11 +33,11 @@ public: enum Mode { Point, Face, Smooth }; RenderArea(QWidget *parent = 0, QString textureName = QString(), - vector map = vector(), + QHash map = QHash(), bool outOfRange = false); ~RenderArea(); - vector map; // Vector of UV Vertexes + QHash map; // Vector of UV Vertexes vector connected; // Vector of indexes of face connected selected by user bool isDragging; @@ -54,7 +55,7 @@ public: void setBrush(const QBrush &brush); void setAntialiased(bool antialiased); void setTexture(QString path); - void SetUVMap(vector uv); + void SetUVMap(QHash uv); void ChangeMode(int index); void RemapRepeat(); void RemapClamp(); diff --git a/src/fgt/edit_texture/textureeditor.cpp b/src/fgt/edit_texture/textureeditor.cpp index c1441e3d7..a012ca3a4 100644 --- a/src/fgt/edit_texture/textureeditor.cpp +++ b/src/fgt/edit_texture/textureeditor.cpp @@ -56,7 +56,7 @@ void TextureEditor::on_remapRB_toggled(bool t) } } -void TextureEditor::AddRenderArea(QString texture, vector map, bool outOfRange) +void TextureEditor::AddRenderArea(QString texture, QHash map, bool outOfRange) { // Add a RenderArea widget to the TabWidget QString name = QString(texture); @@ -94,12 +94,13 @@ void TextureEditor::AddEmptyRenderArea() void TextureEditor::on_applyButton_clicked() { // Change the uv coord of the model reading the RenderArea structure + /* ui.StatusLabel->setText(QString("Saving...")); int value = 0; ui.progressBar->setValue(value); for (int i = 0; i < ui.tabWidget->count(); i++) { - vector tmp = ((RenderArea*)ui.tabWidget->widget(i)->childAt(MARGIN,MARGIN))->map; + QHash tmp = ((RenderArea*)ui.tabWidget->widget(i)->childAt(MARGIN,MARGIN))->map; for (unsigned j = 0; j < tmp.size(); j++) { ui.progressBar->setValue(++value); @@ -115,6 +116,7 @@ void TextureEditor::on_applyButton_clicked() ui.progressBar->setValue(0); ui.StatusLabel->setText(QString("Idle")); area->update(); + */ } void TextureEditor::on_tabWidget_currentChanged(int) diff --git a/src/fgt/edit_texture/textureeditor.h b/src/fgt/edit_texture/textureeditor.h index 5ac0f10f8..f21cab2c0 100644 --- a/src/fgt/edit_texture/textureeditor.h +++ b/src/fgt/edit_texture/textureeditor.h @@ -7,7 +7,7 @@ #include #include "ui_textureeditor.h" #include "renderarea.h" -#include "container.h" +#include "Container.h" #define MARGIN 5 @@ -21,7 +21,7 @@ public: TextureEditor(QWidget *parent = 0); ~TextureEditor(); - void AddRenderArea(QString texture, vector map, bool outOfRange); + void AddRenderArea(QString texture, QHash map, bool outOfRange); void AddEmptyRenderArea(); void Reset(); void SetProgress(int val); diff --git a/src/fgt/edit_texture/ui_textureeditor.h b/src/fgt/edit_texture/ui_textureeditor.h index be561db81..86356390b 100644 --- a/src/fgt/edit_texture/ui_textureeditor.h +++ b/src/fgt/edit_texture/ui_textureeditor.h @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading ui file 'textureeditor.ui' ** -** Created: Fri 22. Feb 15:03:12 2008 +** Created: Sun 9. Mar 11:18:35 2008 ** by: Qt User Interface Compiler version 4.2.2 ** ** WARNING! All changes made in this file will be lost when recompiling ui file!