r3658 - trunk/tools/ImgToMap/src/imgtomap

savagex at icculus.org savagex at icculus.org
Sat May 24 12:46:59 EDT 2008


Author: savagex
Date: 2008-05-24 12:46:57 -0400 (Sat, 24 May 2008)
New Revision: 3658

Modified:
   trunk/tools/ImgToMap/src/imgtomap/JFrameMain.form
   trunk/tools/ImgToMap/src/imgtomap/JFrameMain.java
   trunk/tools/ImgToMap/src/imgtomap/MapWriter.java
Log:
split terrain blocks either north-west to south-east *or* north-east to south-west depending on where the gradient is steeper. This mostly fixes jaggy "mountain-edges" seen when only splitting one way disregarding the gradient.
Also minor UI tweaks.

Modified: trunk/tools/ImgToMap/src/imgtomap/JFrameMain.form
===================================================================
--- trunk/tools/ImgToMap/src/imgtomap/JFrameMain.form	2008-05-24 16:22:19 UTC (rev 3657)
+++ trunk/tools/ImgToMap/src/imgtomap/JFrameMain.form	2008-05-24 16:46:57 UTC (rev 3658)
@@ -25,9 +25,9 @@
           <Group type="102" attributes="0">
               <EmptySpace max="-2" attributes="0"/>
               <Group type="103" groupAlignment="0" attributes="0">
+                  <Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
+                  <Component id="jPanel2" alignment="0" max="32767" attributes="0"/>
                   <Component id="jPanelSky" alignment="0" max="32767" attributes="0"/>
-                  <Component id="jPanel2" alignment="0" max="32767" attributes="0"/>
-                  <Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
                   <Component id="jButtonOK" alignment="0" min="-2" max="-2" attributes="0"/>
               </Group>
               <EmptySpace max="-2" attributes="0"/>
@@ -63,25 +63,24 @@
       <Layout>
         <DimensionLayout dim="0">
           <Group type="103" groupAlignment="0" attributes="0">
-              <Group type="102" attributes="0">
-                  <EmptySpace min="-2" max="-2" attributes="0"/>
+              <Group type="102" alignment="1" attributes="0">
+                  <EmptySpace max="-2" attributes="0"/>
                   <Group type="103" groupAlignment="1" attributes="0">
-                      <Component id="jTextFieldOutput" alignment="0" pref="278" max="32767" attributes="2"/>
-                      <Component id="jTextFieldInput" alignment="0" pref="278" max="32767" attributes="2"/>
+                      <Component id="jTextFieldOutput" alignment="0" pref="299" max="32767" attributes="2"/>
+                      <Component id="jTextFieldInput" alignment="0" pref="299" max="32767" attributes="2"/>
                   </Group>
                   <EmptySpace min="-2" max="-2" attributes="0"/>
-                  <Group type="103" groupAlignment="0" attributes="0">
-                      <Component id="jButtonInput" alignment="1" pref="120" max="32767" attributes="2"/>
-                      <Component id="jButtonOutput" alignment="1" max="32767" attributes="2"/>
+                  <Group type="103" groupAlignment="0" max="-2" attributes="0">
+                      <Component id="jButtonInput" alignment="1" pref="142" max="32767" attributes="1"/>
+                      <Component id="jButtonOutput" alignment="1" min="-2" pref="142" max="-2" attributes="1"/>
                   </Group>
-                  <EmptySpace min="-2" max="-2" attributes="0"/>
+                  <EmptySpace max="-2" attributes="0"/>
               </Group>
           </Group>
         </DimensionLayout>
         <DimensionLayout dim="1">
           <Group type="103" groupAlignment="0" attributes="0">
-              <Group type="102" attributes="0">
-                  <EmptySpace max="-2" attributes="0"/>
+              <Group type="102" alignment="0" attributes="0">
                   <Group type="103" groupAlignment="3" attributes="0">
                       <Component id="jButtonInput" alignment="3" min="-2" max="-2" attributes="0"/>
                       <Component id="jTextFieldInput" alignment="3" min="-2" pref="27" max="-2" attributes="0"/>
@@ -139,34 +138,41 @@
       <Layout>
         <DimensionLayout dim="0">
           <Group type="103" groupAlignment="0" attributes="0">
-              <Group type="102" attributes="0">
-                  <EmptySpace max="-2" attributes="0"/>
+              <Group type="102" alignment="0" attributes="0">
+                  <EmptySpace min="-2" max="-2" attributes="0"/>
                   <Group type="103" groupAlignment="0" attributes="0">
                       <Group type="102" alignment="0" attributes="0">
-                          <Group type="103" groupAlignment="1" attributes="0">
-                              <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
-                              <Component id="jLabel2" alignment="1" min="-2" max="-2" attributes="0"/>
-                          </Group>
+                          <Component id="jTextFieldTexture" pref="447" max="32767" attributes="1"/>
                           <EmptySpace max="-2" attributes="0"/>
-                          <Group type="103" groupAlignment="0" max="-2" attributes="0">
-                              <Component id="jSpinnerHeight" min="0" pref="0" max="32767" attributes="1"/>
-                              <Component id="jSpinnerUnits" alignment="0" max="32767" attributes="1"/>
+                      </Group>
+                      <Group type="102" alignment="0" max="-2" attributes="0">
+                          <Group type="103" groupAlignment="0" attributes="0">
+                              <Component id="jLabel3" alignment="0" min="-2" max="-2" attributes="0"/>
+                              <Group type="102" alignment="0" attributes="0">
+                                  <Component id="jCheckBoxDetail" min="-2" max="-2" attributes="0"/>
+                                  <EmptySpace type="separate" max="-2" attributes="0"/>
+                                  <Component id="jCheckBoxVisBlocker" min="-2" max="-2" attributes="0"/>
+                                  <EmptySpace max="-2" attributes="0"/>
+                              </Group>
+                              <Group type="102" alignment="0" attributes="0">
+                                  <Group type="103" groupAlignment="1" attributes="0">
+                                      <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
+                                      <Component id="jLabel2" alignment="1" min="-2" max="-2" attributes="0"/>
+                                  </Group>
+                                  <EmptySpace max="-2" attributes="0"/>
+                                  <Group type="103" groupAlignment="0" max="-2" attributes="0">
+                                      <Component id="jSpinnerHeight" min="0" pref="0" max="32767" attributes="1"/>
+                                      <Component id="jSpinnerUnits" alignment="0" max="32767" attributes="1"/>
+                                  </Group>
+                                  <EmptySpace max="-2" attributes="0"/>
+                                  <Component id="jLabel4" min="-2" max="-2" attributes="1"/>
+                                  <EmptySpace max="-2" attributes="0"/>
+                                  <Component id="jSpinnerTextureScale" min="-2" pref="89" max="-2" attributes="1"/>
+                              </Group>
                           </Group>
-                          <EmptySpace max="-2" attributes="0"/>
-                          <Component id="jLabel4" min="-2" max="-2" attributes="1"/>
-                          <EmptySpace max="-2" attributes="0"/>
-                          <Component id="jSpinnerTextureScale" pref="96" max="32767" attributes="1"/>
+                          <EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
                       </Group>
-                      <Component id="jLabel3" alignment="0" min="-2" max="-2" attributes="0"/>
-                      <Component id="jTextFieldTexture" alignment="1" pref="416" max="32767" attributes="0"/>
-                      <Group type="102" alignment="0" attributes="0">
-                          <Component id="jCheckBoxDetail" min="-2" max="-2" attributes="0"/>
-                          <EmptySpace type="separate" max="-2" attributes="0"/>
-                          <Component id="jCheckBoxVisBlocker" min="-2" max="-2" attributes="0"/>
-                          <EmptySpace max="-2" attributes="0"/>
-                      </Group>
                   </Group>
-                  <EmptySpace max="-2" attributes="0"/>
               </Group>
           </Group>
         </DimensionLayout>
@@ -277,7 +283,7 @@
               <Group type="102" alignment="0" attributes="0">
                   <EmptySpace max="-2" attributes="0"/>
                   <Group type="103" groupAlignment="0" attributes="0">
-                      <Component id="jTextFieldSkyTexture" alignment="0" pref="404" max="32767" attributes="0"/>
+                      <Component id="jTextFieldSkyTexture" alignment="0" pref="447" max="32767" attributes="0"/>
                       <Group type="102" alignment="0" attributes="0">
                           <Component id="jCheckBoxSky" min="-2" max="-2" attributes="0"/>
                           <EmptySpace min="18" pref="18" max="-2" attributes="0"/>

Modified: trunk/tools/ImgToMap/src/imgtomap/JFrameMain.java
===================================================================
--- trunk/tools/ImgToMap/src/imgtomap/JFrameMain.java	2008-05-24 16:22:19 UTC (rev 3657)
+++ trunk/tools/ImgToMap/src/imgtomap/JFrameMain.java	2008-05-24 16:46:57 UTC (rev 3658)
@@ -87,21 +87,20 @@
         jPanel1.setLayout(jPanel1Layout);
         jPanel1Layout.setHorizontalGroup(
             jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
-            .add(jPanel1Layout.createSequentialGroup()
+            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                 .addContainerGap()
                 .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
-                    .add(org.jdesktop.layout.GroupLayout.LEADING, jTextFieldOutput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
-                    .add(org.jdesktop.layout.GroupLayout.LEADING, jTextFieldInput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE))
+                    .add(org.jdesktop.layout.GroupLayout.LEADING, jTextFieldOutput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)
+                    .add(org.jdesktop.layout.GroupLayout.LEADING, jTextFieldInput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE))
                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
-                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButtonInput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
-                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButtonOutput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
+                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButtonInput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
+                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButtonOutput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 142, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                 .addContainerGap())
         );
         jPanel1Layout.setVerticalGroup(
             jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
             .add(jPanel1Layout.createSequentialGroup()
-                .addContainerGap()
                 .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                     .add(jButtonInput)
                     .add(jTextFieldInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 27, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
@@ -156,25 +155,29 @@
                 .addContainerGap()
                 .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                     .add(jPanel2Layout.createSequentialGroup()
-                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
-                            .add(jLabel1)
-                            .add(jLabel2))
-                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
-                            .add(jSpinnerHeight, 0, 0, Short.MAX_VALUE)
-                            .add(jSpinnerUnits))
-                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-                        .add(jLabel4)
-                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-                        .add(jSpinnerTextureScale, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE))
-                    .add(jLabel3)
-                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jTextFieldTexture, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
+                        .add(jTextFieldTexture, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE)
+                        .addContainerGap())
                     .add(jPanel2Layout.createSequentialGroup()
-                        .add(jCheckBoxDetail)
-                        .add(18, 18, 18)
-                        .add(jCheckBoxVisBlocker)
-                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
-                .addContainerGap())
+                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                            .add(jLabel3)
+                            .add(jPanel2Layout.createSequentialGroup()
+                                .add(jCheckBoxDetail)
+                                .add(18, 18, 18)
+                                .add(jCheckBoxVisBlocker)
+                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
+                            .add(jPanel2Layout.createSequentialGroup()
+                                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
+                                    .add(jLabel1)
+                                    .add(jLabel2))
+                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+                                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
+                                    .add(jSpinnerHeight, 0, 0, Short.MAX_VALUE)
+                                    .add(jSpinnerUnits))
+                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+                                .add(jLabel4)
+                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+                                .add(jSpinnerTextureScale, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
+                        .add(0, 0, 0))))
         );
         jPanel2Layout.setVerticalGroup(
             jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
@@ -232,7 +235,7 @@
             .add(jPanelSkyLayout.createSequentialGroup()
                 .addContainerGap()
                 .add(jPanelSkyLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
-                    .add(jTextFieldSkyTexture, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)
+                    .add(jTextFieldSkyTexture, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE)
                     .add(jPanelSkyLayout.createSequentialGroup()
                         .add(jCheckBoxSky)
                         .add(18, 18, 18)
@@ -268,9 +271,9 @@
             .add(layout.createSequentialGroup()
                 .addContainerGap()
                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                    .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                     .add(jPanelSky, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-                    .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                     .add(jButtonOK))
                 .addContainerGap())
         );
@@ -313,7 +316,7 @@
     p.pixelsize = (Integer)jSpinnerUnits.getValue();
     p.height = (Integer)jSpinnerHeight.getValue();
     p.sky = jCheckBoxSky.isSelected();
-    p.skyfill = jCheckBoxSkyFill.isSelected();
+    p.skyfill = jCheckBoxSkyFill.isSelected() && p.sky;
     p.visblockers = jCheckBoxVisBlocker.isSelected();
     p.skyheight = (Integer)jSpinnerSkyHeight.getValue();
     p.texturescale = (Double)jSpinnerTextureScale.getValue();

Modified: trunk/tools/ImgToMap/src/imgtomap/MapWriter.java
===================================================================
--- trunk/tools/ImgToMap/src/imgtomap/MapWriter.java	2008-05-24 16:22:19 UTC (rev 3657)
+++ trunk/tools/ImgToMap/src/imgtomap/MapWriter.java	2008-05-24 16:46:57 UTC (rev 3658)
@@ -159,6 +159,13 @@
                      * 
                      */
 
+
+                    // delta a - d
+                    double grad1 = Math.abs(height[x][y] - height[x + 1][y + 1]);
+
+                    /// delta b - c
+                    double grad2 = Math.abs(height[x + 1][y] - height[x][y + 1]);
+
                     Vector3D a = new Vector3D(x * units, -y * units, height[x][y] * max);
                     Vector3D b = new Vector3D((x + 1) * units, -y * units, height[x + 1][y] * max);
                     Vector3D c = new Vector3D(x * units, -(y + 1) * units, height[x][y + 1] * max);
@@ -168,22 +175,43 @@
                     Vector3D g = new Vector3D(x * units, -(y + 1) * units, -16.0);
                     Vector3D h = new Vector3D((x + 1) * units, -(y + 1) * units, -16.0);
 
-                    pw.print("{\n");
-                    pw.print(getMapPlaneString(a, b, d, p.detail, p.texture, p.texturescale));
-                    pw.print(getMapPlaneString(d, b, f, p.detail, "common/caulk", p.texturescale));
-                    pw.print(getMapPlaneString(f, b, a, p.detail, "common/caulk", p.texturescale));
-                    pw.print(getMapPlaneString(a, d, h, p.detail, "common/caulk", p.texturescale));
-                    pw.print(getMapPlaneString(g, h, f, p.detail, "common/caulk", p.texturescale));
-                    pw.print("}\n");
+                    if (grad1 > grad2) {
+                        pw.print("{\n");
+                        pw.print(getMapPlaneString(a, b, c, p.detail, p.texture, p.texturescale));
+                        pw.print(getMapPlaneString(f, b, a, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(a, c, g, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(g, h, f, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(g, c, b, p.detail, "common/caulk", p.texturescale));
+                        pw.print("}\n");
 
 
-                    pw.print("{\n");
-                    pw.print(getMapPlaneString(d, c, a, p.detail, p.texture, p.texturescale));
-                    pw.print(getMapPlaneString(g, c, d, p.detail, "common/caulk", p.texturescale));
-                    pw.print(getMapPlaneString(c, g, a, p.detail, "common/caulk", p.texturescale));
-                    pw.print(getMapPlaneString(h, d, a, p.detail, "common/caulk", p.texturescale));
-                    pw.print(getMapPlaneString(g, h, f, p.detail, "common/caulk", p.texturescale));
-                    pw.print("}\n");
+                        pw.print("{\n");
+                        pw.print(getMapPlaneString(b, d, c, p.detail, p.texture, p.texturescale));
+                        pw.print(getMapPlaneString(d, h, g, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(d, b, f, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(f, b, c, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(g, h, f, p.detail, "common/caulk", p.texturescale));
+                        pw.print("}\n");
+
+                    } else {
+
+                        pw.print("{\n");
+                        pw.print(getMapPlaneString(a, b, d, p.detail, p.texture, p.texturescale));
+                        pw.print(getMapPlaneString(d, b, f, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(f, b, a, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(a, d, h, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(g, h, f, p.detail, "common/caulk", p.texturescale));
+                        pw.print("}\n");
+
+
+                        pw.print("{\n");
+                        pw.print(getMapPlaneString(d, c, a, p.detail, p.texture, p.texturescale));
+                        pw.print(getMapPlaneString(g, c, d, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(c, g, a, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(h, d, a, p.detail, "common/caulk", p.texturescale));
+                        pw.print(getMapPlaneString(g, h, f, p.detail, "common/caulk", p.texturescale));
+                        pw.print("}\n");
+                    }
                 }
             }
         }




More information about the nexuiz-commits mailing list