Skip to content

Commit

Permalink
Always update the shape source when brush stroke ends
Browse files Browse the repository at this point in the history
  • Loading branch information
ousnius committed Jan 6, 2016
1 parent 8303f1f commit c63b261
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 151 deletions.
23 changes: 0 additions & 23 deletions OutfitProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,6 @@ string OutfitProject::OutfitName() {
return outfitName;
}

bool OutfitProject::IsDirty() {
return (shapeDirty.size() > 0);
}

void OutfitProject::Clean(const string& specificShape) {
shapeDirty.erase(specificShape);
}

void OutfitProject::SetDirty(const string& specificShape) {
shapeDirty[specificShape] = true;
}

bool OutfitProject::IsDirty(const string& specificShape) {
return (shapeDirty.find(specificShape) != shapeDirty.end());
}

bool OutfitProject::ValidSlider(int index) {
if (index >= 0 && index < activeSet.size())
return true;
Expand Down Expand Up @@ -1045,7 +1029,6 @@ void OutfitProject::UpdateShapeFromMesh(const string& shapeName, const mesh* m)
liveVerts.emplace_back(move(Vector3(m->verts[i].x * -10, m->verts[i].z * 10, m->verts[i].y * 10)));

workNif.SetVertsForShape(shapeName, liveVerts);
Clean(shapeName);
}

void OutfitProject::UpdateMorphResult(const string& shapeName, const string& sliderName, unordered_map<ushort, Vector3>& vertUpdates) {
Expand Down Expand Up @@ -1916,12 +1899,6 @@ void OutfitProject::RenameShape(const string& shapeName, const string& newShapeN
morpher.RenameShape(shapeName, newShapeName);

activeSet.RenameShape(shapeName, newShapeName);

if (shapeDirty.find(shapeName) != shapeDirty.end()) {
shapeDirty.erase(shapeName);
shapeDirty[newShapeName] = true;
}

wxLogMessage("Renamed shape '%s' to '%s'.", shapeName, newShapeName);
}

Expand Down
9 changes: 0 additions & 9 deletions OutfitProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class OutfitProject {
map<string, vector<Vector3>> boneScaleVerts;
map<string, unordered_map<ushort, float>> workWeights;

map<string, bool> shapeDirty;
unordered_map<string, string> shapeTextures;

// inOwner is meant to provide access to OutfitStudio for the purposes of reporting process status only.
Expand Down Expand Up @@ -86,14 +85,6 @@ class OutfitProject {
string SliderSetFileName();
string OutfitName();

bool IsDirty();
void Clean() {
shapeDirty.clear();
}
void Clean(const string& specificShape);
void SetDirty(const string& specificShape);
bool IsDirty(const string& specificShape);

bool ValidSlider(int index);
bool ValidSlider(const string& sliderName);
bool AllSlidersZero();
Expand Down
127 changes: 13 additions & 114 deletions OutfitStudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,46 +633,14 @@ void OutfitStudio::ActiveShapeUpdated(TweakStroke* refStroke, bool bIsUndo, bool
project->workWeights.clear();
}
}
else
project->SetDirty(activeItem->shapeName);
}
}

string OutfitStudio::GetActiveBone() {
return activeBone;
}

bool OutfitStudio::IsDirty() {
return project->IsDirty();
}

bool OutfitStudio::IsDirty(const string& shapeName) {
return project->IsDirty(shapeName);
}

void OutfitStudio::SetClean(const string& shapeName) {
project->Clean(shapeName);
}

void OutfitStudio::EnterSliderEdit(const string& sliderName) {
if (IsDirty(activeItem->shapeName)) {
int response = wxMessageBox("You have unsaved changes to the base mesh shape, do you wish to apply the changes? If you select NO, the changes will be lost.", wxMessageBoxCaptionStr, wxYES_NO | wxCANCEL, this);
if (response == wxCANCEL)
return;

if (response == wxYES) {
vector<string> shapes;
project->GetShapes(shapes);

for (auto &s : shapes) {
UpdateShapeSource(s);
project->RefreshMorphShape(s);
}
}
if (response == wxNO)
project->Clean();
}

bEditSlider = true;
activeSlider = sliderName;
SliderDisplay* d = sliderDisplays[activeSlider];
Expand Down Expand Up @@ -1294,19 +1262,9 @@ void OutfitStudio::OnSaveSliderSet(wxCommandEvent& event) {
vector<mesh*> shapeMeshes;
vector<string> shapes;
project->GetShapes(shapes);
for (auto &s : shapes){
if (project->IsBaseShape(s)) {
if (IsDirty(s))
UpdateShapeSource(s);
}
else {
if (IsDirty(s)) {
UpdateShapeSource(s);
project->RefreshMorphShape(s);
}
for (auto &s : shapes)
if (!project->IsBaseShape(s))
shapeMeshes.push_back(glView->GetMesh(s));
}
}

bool updateNormals = GetMenuBar()->IsChecked(XRCID("btnAutoNormals"));

Expand Down Expand Up @@ -1467,19 +1425,9 @@ void OutfitStudio::OnSaveSliderSetAs(wxCommandEvent& WXUNUSED(event)) {
vector<mesh*> shapeMeshes;
vector<string> shapes;
project->GetShapes(shapes);
for (auto &s : shapes){
if (project->IsBaseShape(s)) {
if (IsDirty(s))
UpdateShapeSource(s);
}
else {
if (IsDirty(s)) {
UpdateShapeSource(s);
project->RefreshMorphShape(s);
}
for (auto &s : shapes)
if (!project->IsBaseShape(s))
shapeMeshes.push_back(glView->GetMesh(s));
}
}

bool updateNormals = GetMenuBar()->IsChecked(XRCID("btnAutoNormals"));

Expand Down Expand Up @@ -2285,43 +2233,7 @@ void OutfitStudio::ZeroSliders() {
}
}

int OutfitStudio::PromptUpdateBase() {
int response;
response = wxMessageBox("You have unsaved changes to the base mesh shape, do you wish to apply the changes? If you select NO, the changes will be lost.", wxMessageBoxCaptionStr, wxYES_NO | wxCANCEL, this);

if (response == wxCANCEL)
return response;

if (response == wxYES) {
vector<string> shapes;
project->GetShapes(shapes);

for (auto &s : shapes) {
UpdateShapeSource(s);
project->RefreshMorphShape(s);
}

//OnSliderConform(wxCommandEvent());
//glView->GetStrokeManager()->InvalidateHistoricalBVH();
glView->GetStrokeManager()->Clear();
}

if (response == wxNO) {
project->Clean();
//glView->GetStrokeManager()->InvalidateHistoricalBVH();
glView->GetStrokeManager()->Clear();
}
return response;
}

void OutfitStudio::OnSlider(wxScrollEvent& event) {
int type = event.GetEventType();
static bool sentinel = false;

if (type == wxEVT_SCROLL_CHANGED)
if (sentinel)
return;

wxSlider* s = ((wxSlider*)event.GetEventObject());
if (!s)
return;
Expand All @@ -2336,13 +2248,6 @@ void OutfitStudio::OnSlider(wxScrollEvent& event) {
boneScale->SetValue(0);
}

if (IsDirty() && !bEditSlider) {
sentinel = true;
if (PromptUpdateBase() == wxCANCEL)
return;
sentinel = false;
}

if (outfitBones && sliderName == "boneScale") {
wxArrayTreeItemIds selItems;
outfitBones->GetSelections(selItems);
Expand Down Expand Up @@ -2373,10 +2278,6 @@ void OutfitStudio::OnLoadPreset(wxCommandEvent& WXUNUSED(event)) {
string choice;
bool hi = true;

if (IsDirty())
if (PromptUpdateBase() == wxCANCEL)
return;

presets.LoadPresets("SliderPresets", choice, names, true);
presets.GetPresetNames(names);

Expand Down Expand Up @@ -2961,10 +2862,6 @@ void OutfitStudio::OnSliderConform(wxCommandEvent& WXUNUSED(event)) {
UpdateProgress(1, "Initializing data...");
project->InitConform();

if (IsDirty(i->shapeName)) {
UpdateShapeSource(i->shapeName);
project->RefreshMorphShape(i->shapeName);
}
UpdateProgress(50, "Conforming: " + i->shapeName);

project->morpher.CopyMeshMask(glView->GetMesh(i->shapeName), i->shapeName);
Expand Down Expand Up @@ -4165,12 +4062,6 @@ bool wxGLPanel::StartBrushStroke(const wxPoint& screenPos) {
activeBrush = &smoothBrush;
}

if (activeBrush->Type() == TBT_WEIGHT && os->IsDirty()) {
os->PromptUpdateBase();
activeBrush = savedBrush;
return false;
}

activeStroke = strokeManager->CreateStroke(gls.GetActiveMesh(), activeBrush);
activeBrush->setConnected(bConnectedEdit);
activeBrush->setMirror(bXMirror);
Expand Down Expand Up @@ -4256,9 +4147,17 @@ void wxGLPanel::EndBrushStroke() {
}
}

if (activeStroke->BrushType() != TBT_MASK)
if (activeStroke->BrushType() != TBT_MASK) {
os->ActiveShapeUpdated(strokeManager->GetCurStateStroke());

vector<string> shapes;
os->project->GetShapes(shapes);
for (auto &s : shapes) {
os->UpdateShapeSource(s);
os->project->RefreshMorphShape(s);
}
}

activeStroke = nullptr;
activeBrush = savedBrush;
}
Expand Down
5 changes: 0 additions & 5 deletions OutfitStudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ class OutfitStudio : public wxFrame {
vector<string> GetShapeList();

void UpdateShapeSource(const string& shapeName);
int PromptUpdateBase();

void ActiveShapeUpdated(TweakStroke* refStroke, bool bIsUndo = false, bool setWeights = true);
void UpdateActiveShapeUI();
Expand All @@ -503,10 +502,6 @@ class OutfitStudio : public wxFrame {

bool NotifyStrokeStarting();

bool IsDirty();
bool IsDirty(const string& shapeName);
void SetClean(const string& shapeName);

void EnterSliderEdit(const string& sliderName);
void ExitSliderEdit();
void MenuEnterSliderEdit();
Expand Down

0 comments on commit c63b261

Please sign in to comment.