Commits

Andrew Fenn  committed 4ed60ee Draft

Added normal and diffuse texture selection to heightmap import
Heightmap import with the inverted option now works correctly
Cleaned up the code base surrounding the heightmap importing

  • Participants
  • Parent commits 6e7a741

Comments (0)

Files changed (7)

File Ogitor/src/TerrainGroupEditor.cpp

     {
         Ogre::NameValuePairList params;
 
-        params["title"] = "Scale/Offset values";
-        params["input1"] = "Scale";
-        params["input2"] = "Offset";
-
         if(!mSystem->DisplayImportHeightMapDialog(params))
             return;
 
-        Ogre::Real fScale = Ogre::StringConverter::parseReal(params["input1"]);
-        Ogre::Real fOffset = Ogre::StringConverter::parseReal(params["input2"]);
+        Ogre::Real fScale = Ogre::StringConverter::parseReal(params["scale"]);
+        Ogre::Real fOffset = Ogre::StringConverter::parseReal(params["bias"]);
 
         _modifyHeights(fScale, fOffset);
     }

File Ogitor/src/TerrainGroupEditorImportExport.cpp

 void CTerrainGroupEditor::importFullTerrainFromHeightMap()
 {
     UTFStringVector extlist;
+    extlist.push_back(OTR("PNG Grayscale"));
+    extlist.push_back("*.png");
     extlist.push_back(OTR("Raw 32bit Float File"));
     extlist.push_back("*.raw;*.ohm;*.f32;*.r32");
-    extlist.push_back(OTR("PNG Grayscale"));
-    extlist.push_back("*.png");
 
     Ogre::UTFString defaultPath = mSystem->GetSetting("system", "ExportTerrainPath", "");
 
     mSystem->SetSetting("system", "ExportTerrainPath", OgitorsUtils::ExtractFilePath(filename));
 
     Ogre::NameValuePairList params;
-    params["check1"] = "true";
-    params["input1"] = "Scale";
-    params["input2"] = "Offset";
-
     if(!mSystem->DisplayImportHeightMapDialog(params))
         return;
     
-    Ogre::Real fScale = Ogre::StringConverter::parseReal(params["input1"]);
-    Ogre::Real fBias = Ogre::StringConverter::parseReal(params["input2"]);
-
-    bool flipV = Ogre::StringConverter::parseBool(params["inputCheckV"]);
+    Ogre::Real fScale = Ogre::StringConverter::parseReal(params["scale"]);
+    Ogre::Real fBias = Ogre::StringConverter::parseReal(params["bias"]);
+    Ogre::String normal = params["normal"];
+    Ogre::String diffuse = params["diffuse"];
+    bool flipV = Ogre::StringConverter::parseBool(params["inverted"]);
 
     float *data = 0;
     float *flipBV = 0;
         imgW = imgH = sqrt((float)vertexNum);
     }
 
-    if(flipV)
-    {
-        flipBV = OGRE_ALLOC_T(float, imgW, Ogre::MEMCATEGORY_GEOMETRY);
-
-        int linelength = imgW * sizeof(float);
-
-        for(int fj = 0;fj < imgH;fj++)
-        {
-            memcpy(flipBV, data + (fj * linelength), linelength);
-            memcpy(data + (fj * linelength), data + ((imgH - fj - 1) * linelength), linelength);
-            memcpy(data + ((imgH - fj - 1) * linelength), flipBV, linelength);
-        }
-
-        OGRE_FREE(flipBV, Ogre::MEMCATEGORY_GEOMETRY);
-    }
-
     int msize = mMapSize->get() - 1;
     int XCount = (imgW - 1) / msize;
     int YCount = (imgH - 1) / msize;
             pvalue.val = Ogre::Any(y - (YCount / 2));
             creationparams["pagey"] = pvalue;
             pvalue.propType = PROP_STRING;
-            pvalue.val = Ogre::Any(Ogre::String("dirt_grayrocky_diffusespecular.dds"));
+            pvalue.val = diffuse;
             creationparams["layer0::diffusespecular"] = pvalue;
             pvalue.propType = PROP_STRING;
-            pvalue.val = Ogre::Any(Ogre::String("dirt_grayrocky_normalheight.dds"));
+            pvalue.val = normal;
             creationparams["layer0::normalheight"] = pvalue;
             pvalue.propType = PROP_REAL;
             pvalue.val = Ogre::Any((Ogre::Real)100.0f);
                 for(int ix = 0;ix <= msize;ix++)
                 {
                     cval = data[(((y * msize) + iy) * imgW) + (x * msize) + ix];
+                    if (flipV)
+                        cval *= -1;
+
                     dataptr[(iy * (msize + 1)) + ix] = fBias + (cval * fScale);
                 }
             }

File Ogitor/src/TerrainPageEditor.cpp

     PROPERTY_PTR(mTempModified, "tempmodified", bool, false, 0, 0);
     PROPERTY_PTR(mTempDensityModified, "tempdensitymodified", bool, false, 0, 0);
     PROPERTY_PTR(mLayerWorldSize[0], "layer0::worldsize", Ogre::Real, 10.0f, 0, SETTER(Ogre::Real, CTerrainPageEditor, _setLayerWorldSize));
-    PROPERTY_PTR(mLayerDiffuse[0], "layer0::diffusespecular", Ogre::String, "dirt_grayrocky_diffusespecular.dds", 0, SETTER(Ogre::String, CTerrainPageEditor, _setLayerDiffuseMap));
-    PROPERTY_PTR(mLayerNormal[0], "layer0::normalheight", Ogre::String, "dirt_grayrocky_normalheight.dds", 0, SETTER(Ogre::String, CTerrainPageEditor, _setLayerNormalMap));
+    PROPERTY_PTR(mLayerDiffuse[0], "layer0::diffusespecular", Ogre::String, "", 0, SETTER(Ogre::String, CTerrainPageEditor, _setLayerDiffuseMap));
+    PROPERTY_PTR(mLayerNormal[0], "layer0::normalheight", Ogre::String, "", 0, SETTER(Ogre::String, CTerrainPageEditor, _setLayerNormalMap));
 
     int count = 0;
     OgitorsPropertyValueMap::const_iterator it = params.find("layercount");

File qtOgitor/importheightmapdialog.ui

    <rect>
     <x>0</x>
     <y>0</y>
-    <width>198</width>
-    <height>154</height>
+    <width>339</width>
+    <height>283</height>
    </rect>
   </property>
   <property name="windowTitle">
   <property name="modal">
    <bool>true</bool>
   </property>
-  <widget class="QDialogButtonBox" name="buttonBox">
-   <property name="geometry">
-    <rect>
-     <x>20</x>
-     <y>110</y>
-     <width>151</width>
-     <height>31</height>
-    </rect>
-   </property>
-   <property name="orientation">
-    <enum>Qt::Horizontal</enum>
-   </property>
-   <property name="standardButtons">
-    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
-   </property>
-  </widget>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeType">
+      <enum>QSizePolicy::Fixed</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>300</width>
+       <height>120</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <widget class="QLabel" name="diffuseLabel">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="maximumSize">
+      <size>
+       <width>16777215</width>
+       <height>20</height>
+      </size>
+     </property>
+     <property name="text">
+      <string>Default Diffuse Texture</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QComboBox" name="mDiffuseCombo">
+     <property name="enabled">
+      <bool>true</bool>
+     </property>
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="normalLabel">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="maximumSize">
+      <size>
+       <width>16777215</width>
+       <height>20</height>
+      </size>
+     </property>
+     <property name="text">
+      <string>Default Normal Texture</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QComboBox" name="mNormalCombo">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
   <widget class="QWidget" name="gridLayoutWidget">
    <property name="geometry">
     <rect>
      <x>30</x>
      <y>10</y>
-     <width>132</width>
+     <width>211</width>
      <height>71</height>
     </rect>
    </property>
    <layout class="QGridLayout" name="gridLayout" columnstretch="0,0">
+    <property name="sizeConstraint">
+     <enum>QLayout::SetDefaultConstraint</enum>
+    </property>
     <item row="0" column="0">
      <widget class="QLabel" name="input1label">
       <property name="text">
-       <string>Input Scale</string>
+       <string>Terrain Scale</string>
       </property>
      </widget>
     </item>
     <item row="1" column="0">
      <widget class="QLabel" name="input2label">
       <property name="text">
-       <string>Input Bias</string>
+       <string>Heightmap Offset</string>
       </property>
      </widget>
     </item>
    </layout>
   </widget>
-  <widget class="QCheckBox" name="checkV">
+  <widget class="QCheckBox" name="mInverted">
    <property name="geometry">
     <rect>
      <x>30</x>

File qtOgitor/src/createterraindialog.cpp

 #include "OgitorsSystem.h"
 #include "BaseEditor.h"
 #include "OgitorsRoot.h"
-#include "OgitorsSystem.h"
 #include "CameraEditor.h"
 #include "ViewportEditor.h"
 #include "TerrainEditor.h"
 
     unsigned int i, index = 1;
     Ogitors::PropertyOptionsVector *mapDiffuse = Ogitors::OgitorsRoot::GetTerrainDiffuseTextureNames();
-    if(mapDiffuse->size() == 0)
-        mapDiffuse = Ogitors::OgitorsRoot::GetTerrainDiffuseTextureNames();
     for(i = 0;i < mapDiffuse->size();i++)
     {
         if (lastUsedDiffuse == (*mapDiffuse)[i].mKey)
 
     index = 1;
     Ogitors::PropertyOptionsVector *mapNormal = Ogitors::OgitorsRoot::GetTerrainNormalTextureNames();
-    if(mapNormal->size() == 0)
-        mapNormal = Ogitors::OgitorsRoot::GetTerrainNormalTextureNames();
     for(i = 0;i < mapNormal->size();i++)
     {
         if (lastUsedNormal == (*mapNormal)[i].mKey)

File qtOgitor/src/importheightmapdialog.cpp

 /// THE SOFTWARE.
 ////////////////////////////////////////////////////////////////////////////////*/
 
+#include <QtCore/QtCore>
 #include <QtGui/QFileDialog>
 #include "importheightmapdialog.hxx"
+#include "Ogitors.h"
 
 ImportHeightMapDialog::ImportHeightMapDialog(QWidget *parent) :
     QDialog(parent, Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint)
 {
     setupUi(this);
-    mInputScale->setText("1");
+    mInputScale->setText("256");
     mInputBias->setText("0");
+
+    QSettings settings(QSettings::UserScope, "preferences/terrainmanager");
+
+    Ogitors::OgitorsRoot *ogitorRoot = Ogitors::OgitorsRoot::getSingletonPtr();
+    Ogitors::PropertyOptionsVector* diffuseList = ogitorRoot->GetTerrainDiffuseTextureNames();
+    Ogre::String lastUsedDiffuse = settings.value("lastDiffuseUsed", "").toString().toStdString();
+
+    unsigned int i, index = 1;
+    for(i = 0;i < diffuseList->size(); i++)
+    {
+        if (lastUsedDiffuse == (*diffuseList)[i].mKey)
+            index = i;
+
+        mDiffuseCombo->addItem((*diffuseList)[i].mKey.c_str());
+    }
+
+    if (lastUsedDiffuse.empty())
+        index = 1;
+
+    if(diffuseList->size())
+        mDiffuseCombo->setCurrentIndex(index);
+
+    index = 1;
+    Ogre::String lastNormalUsed = settings.value("lastNormalUsed", "").toString().toStdString();
+    Ogitors::PropertyOptionsVector* normalList = ogitorRoot->GetTerrainNormalTextureNames();
+    for(i = 0;i < normalList->size(); i++)
+    {
+        if (lastNormalUsed == (*normalList)[i].mKey)
+            index = i;
+
+        mNormalCombo->addItem((*normalList)[i].mKey.c_str());
+    }
+
+    if (lastNormalUsed.empty())
+        index = 1;
+
+    if(normalList->size())
+        mNormalCombo->setCurrentIndex(index);
 }
 
 ImportHeightMapDialog::~ImportHeightMapDialog()
 {
-}
+}

File qtOgitor/src/qtogitorsystem.cpp

 bool QtOgitorSystem::DisplayImportHeightMapDialog(Ogre::NameValuePairList &params)
 {
     ImportHeightMapDialog dlg(QApplication::activeWindow());
-
-    Ogre::NameValuePairList::iterator it;
-
-    if((it = params.find("title")) != params.end())
-        dlg.setWindowTitle(params["title"].c_str());
-
-    if((it = params.find("input1")) != params.end())
-        dlg.input1label->setText(params["input1"].c_str());
-
-    if((it = params.find("input2")) != params.end())
-        dlg.input2label->setText(params["input2"].c_str());
-
-    if((it = params.find("check1")) != params.end())
-        dlg.checkV->setVisible(true);
-    else
-        dlg.checkV->setVisible(false);
-
-    if((it = params.find("input1value")) != params.end())
-        dlg.mInputScale->setText(params["input1value"].c_str());
-
-    if((it = params.find("input2value")) != params.end())
-        dlg.mInputBias->setText(params["input2value"].c_str());
-
     params.clear();
 
     if(dlg.exec() == QDialog::Accepted)
     {
-        params["input1"] = dlg.mInputScale->text().toStdString();
-        params["input2"] = dlg.mInputBias->text().toStdString();
-        params["inputCheckV"] = "false";
+        params["scale"] = dlg.mInputScale->text().toStdString();
+        params["bias"] = dlg.mInputBias->text().toStdString();
+        params["diffuse"] = dlg.mDiffuseCombo->itemText(dlg.mDiffuseCombo->currentIndex()).toStdString();
+        params["normal"] = dlg.mNormalCombo->itemText(dlg.mNormalCombo->currentIndex()).toStdString();
+        params["inverted"] = Ogre::StringConverter::toString(dlg.mInverted->isChecked());
         return true;
     }
     else