r2131 - tools/ObjToMap/objtomap
savagex at icculus.org
savagex at icculus.org
Thu Jan 18 13:22:48 EST 2007
Author: savagex
Date: 2007-01-18 13:22:48 -0500 (Thu, 18 Jan 2007)
New Revision: 2131
Added:
tools/ObjToMap/objtomap/AutoTexturingEntry.java
Modified:
tools/ObjToMap/objtomap/Configuration.java
tools/ObjToMap/objtomap/JFrameMain.form
tools/ObjToMap/objtomap/JFrameMain.java
tools/ObjToMap/objtomap/ObjToMap.java
Log:
new: autotexturing (texture faces according to the angle against the
xy-plane)
Added: tools/ObjToMap/objtomap/AutoTexturingEntry.java
===================================================================
--- tools/ObjToMap/objtomap/AutoTexturingEntry.java (rev 0)
+++ tools/ObjToMap/objtomap/AutoTexturingEntry.java 2007-01-18 18:22:48 UTC (rev 2131)
@@ -0,0 +1,11 @@
+package objtomap;
+
+public class AutoTexturingEntry {
+ public double angle;
+ public String texturename;
+
+ public AutoTexturingEntry() {
+ angle = 0.0;
+ texturename = "common/caulk";
+ }
+}
Modified: tools/ObjToMap/objtomap/Configuration.java
===================================================================
--- tools/ObjToMap/objtomap/Configuration.java 2007-01-18 12:21:04 UTC (rev 2130)
+++ tools/ObjToMap/objtomap/Configuration.java 2007-01-18 18:22:48 UTC (rev 2131)
@@ -1,11 +1,14 @@
package objtomap;
+import java.util.Vector;
+
public class Configuration {
public double brush_thickness, scale, texture_scale;
public boolean detail, autotexture;
public String objfile, mapfile;
+ public Vector autotexturing;
/** Creates a new instance of Configuration */
public Configuration() {
@@ -13,6 +16,7 @@
texture_scale = 0.5;
scale = 128.0;
detail = true;
+ autotexturing = new Vector();
}
}
Modified: tools/ObjToMap/objtomap/JFrameMain.form
===================================================================
--- tools/ObjToMap/objtomap/JFrameMain.form 2007-01-18 12:21:04 UTC (rev 2130)
+++ tools/ObjToMap/objtomap/JFrameMain.form 2007-01-18 18:22:48 UTC (rev 2131)
@@ -22,6 +22,7 @@
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
+ <Component id="jPanel4" alignment="0" max="32767" attributes="0"/>
<Component id="jPanel3" alignment="0" max="32767" attributes="0"/>
<Component id="jPanel2" alignment="0" max="32767" attributes="0"/>
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
@@ -39,8 +40,10 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
- <Component id="jPanel3" max="32767" attributes="0"/>
+ <Component id="jPanel3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
+ <Component id="jPanel4" max="32767" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
<Component id="jButtonStart" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
@@ -196,7 +199,7 @@
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jTextFieldScale" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
- <EmptySpace pref="21" max="32767" attributes="0"/>
+ <EmptySpace pref="19" max="32767" attributes="0"/>
<Component id="jCheckDetail" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
@@ -260,5 +263,86 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonStartActionPerformed"/>
</Events>
</Component>
+ <Container class="javax.swing.JPanel" name="jPanel4">
+ <Properties>
+ <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
+ <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
+ <TitledBorder title="Auto-texturing"/>
+ </Border>
+ </Property>
+ </Properties>
+
+ <Layout>
+ <DimensionLayout dim="0">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" alignment="1" attributes="0">
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="jScrollPane1" pref="473" max="32767" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="1" max="-2" attributes="0">
+ <Component id="jButtonAdd" max="32767" attributes="1"/>
+ <Component id="jButtonDelte" alignment="1" pref="104" max="32767" attributes="1"/>
+ </Group>
+ <EmptySpace max="-2" attributes="0"/>
+ </Group>
+ </Group>
+ </DimensionLayout>
+ <DimensionLayout dim="1">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" attributes="0">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" attributes="0">
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="jButtonAdd" min="-2" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="jButtonDelte" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <Component id="jScrollPane1" alignment="1" pref="167" max="32767" attributes="0"/>
+ </Group>
+ <EmptySpace max="-2" attributes="0"/>
+ </Group>
+ </Group>
+ </DimensionLayout>
+ </Layout>
+ <SubComponents>
+ <Container class="javax.swing.JScrollPane" name="jScrollPane1">
+ <AuxValues>
+ <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JTable" name="jTableTexturing">
+ <Properties>
+ <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
+ <Table columnCount="4" rowCount="4">
+ <Column editable="true" title="Title 1" type="java.lang.Object"/>
+ <Column editable="true" title="Title 2" type="java.lang.Object"/>
+ <Column editable="true" title="Title 3" type="java.lang.Object"/>
+ <Column editable="true" title="Title 4" type="java.lang.Object"/>
+ </Table>
+ </Property>
+ </Properties>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Component class="javax.swing.JButton" name="jButtonAdd">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="New"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonAddActionPerformed"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="jButtonDelte">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Remove"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonDelteActionPerformed"/>
+ </Events>
+ </Component>
+ </SubComponents>
+ </Container>
</SubComponents>
</Form>
Modified: tools/ObjToMap/objtomap/JFrameMain.java
===================================================================
--- tools/ObjToMap/objtomap/JFrameMain.java 2007-01-18 12:21:04 UTC (rev 2130)
+++ tools/ObjToMap/objtomap/JFrameMain.java 2007-01-18 18:22:48 UTC (rev 2131)
@@ -7,7 +7,9 @@
package objtomap;
import java.io.IOException;
+import java.util.Vector;
import javax.swing.JFileChooser;
+import javax.swing.table.AbstractTableModel;
/**
*
@@ -32,9 +34,21 @@
jTextFieldTextureScale.setText(Double.toString(config.texture_scale));
jTextFieldThickness.setText(Double.toString(config.brush_thickness));
jCheckDetail.setSelected(config.detail);
+
+ jTableTexturing.setModel(new AutoTexturingTableModel(config.autotexturing));
+
+ /*try {
+ jTableRelations.setDefaultEditor(Class.forName("businesslearner.Letter"), new DefaultCellEditor(comboBoxLetters));
+ jTableRelations.setDefaultEditor("".getClass(), new DefaultCellEditor(comboBoxRelations));
+ } catch (ClassNotFoundException ex) {
+ ex.printStackTrace();
+ }*/
+
}
+
+
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
@@ -57,6 +71,11 @@
jLabel3 = new javax.swing.JLabel();
jTextFieldTextureScale = new javax.swing.JTextField();
jButtonStart = new javax.swing.JButton();
+ jPanel4 = new javax.swing.JPanel();
+ jScrollPane1 = new javax.swing.JScrollPane();
+ jTableTexturing = new javax.swing.JTable();
+ jButtonAdd = new javax.swing.JButton();
+ jButtonDelte = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("ObjToMap");
@@ -196,7 +215,7 @@
.add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(jTextFieldScale, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 21, Short.MAX_VALUE)
+ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 19, Short.MAX_VALUE)
.add(jCheckDetail)
.addContainerGap())
);
@@ -208,6 +227,60 @@
}
});
+ jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Auto-texturing"));
+ jTableTexturing.setModel(new javax.swing.table.DefaultTableModel(
+ new Object [][] {
+ {null, null, null, null},
+ {null, null, null, null},
+ {null, null, null, null},
+ {null, null, null, null}
+ },
+ new String [] {
+ "Title 1", "Title 2", "Title 3", "Title 4"
+ }
+ ));
+ jScrollPane1.setViewportView(jTableTexturing);
+
+ jButtonAdd.setText("New");
+ jButtonAdd.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jButtonAddActionPerformed(evt);
+ }
+ });
+
+ jButtonDelte.setText("Remove");
+ jButtonDelte.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jButtonDelteActionPerformed(evt);
+ }
+ });
+
+ org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
+ jPanel4.setLayout(jPanel4Layout);
+ jPanel4Layout.setHorizontalGroup(
+ jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+ .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
+ .addContainerGap()
+ .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
+ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+ .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
+ .add(jButtonAdd, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .add(jButtonDelte, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))
+ .addContainerGap())
+ );
+ jPanel4Layout.setVerticalGroup(
+ jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+ .add(jPanel4Layout.createSequentialGroup()
+ .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+ .add(jPanel4Layout.createSequentialGroup()
+ .addContainerGap()
+ .add(jButtonAdd)
+ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+ .add(jButtonDelte))
+ .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE))
+ .addContainerGap())
+ );
+
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
@@ -215,6 +288,7 @@
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
+ .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
@@ -229,31 +303,45 @@
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
- .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+ .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButtonStart)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
+ private void jButtonDelteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDelteActionPerformed
+ int index = jTableTexturing.getSelectedRow();
+ if(index < 0) return;
+ config.autotexturing.remove(index);
+ updateForms();
+ }//GEN-LAST:event_jButtonDelteActionPerformed
+
+ private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed
+ config.autotexturing.add(new AutoTexturingEntry());
+ updateForms();
+ }//GEN-LAST:event_jButtonAddActionPerformed
+
private void jTextFieldOutputFileFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldOutputFileFocusLost
config.mapfile = jTextFieldOutputFile.getText();
updateForms();
}//GEN-LAST:event_jTextFieldOutputFileFocusLost
-
+
private void jTextFieldInputFileFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldInputFileFocusLost
config.objfile = jTextFieldInputFile.getText();
updateForms();
}//GEN-LAST:event_jTextFieldInputFileFocusLost
-
+
private void jTextFieldTextureScaleFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldTextureScaleFocusLost
try {
config.texture_scale = Double.parseDouble(jTextFieldTextureScale.getText());
} catch(Exception e) {}
updateForms();
}//GEN-LAST:event_jTextFieldTextureScaleFocusLost
-
+
private void jButtonSelectOutputFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectOutputFileActionPerformed
JFileChooser fc = new JFileChooser();
int returnval = fc.showSaveDialog(this);
@@ -262,7 +350,7 @@
}
updateForms();
}//GEN-LAST:event_jButtonSelectOutputFileActionPerformed
-
+
private void jButtonSelectInputFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectInputFileActionPerformed
JFileChooser fc = new JFileChooser();
int returnval = fc.showOpenDialog(this);
@@ -271,20 +359,20 @@
}
updateForms();
}//GEN-LAST:event_jButtonSelectInputFileActionPerformed
-
+
private void jButtonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStartActionPerformed
config.objfile = jTextFieldInputFile.getText();
config.mapfile = jTextFieldOutputFile.getText();
ObjToMap converter = new ObjToMap(config);
try {
- converter.parseOBJ();
- converter.writeMap();
+ converter.parseOBJ();
+ converter.writeMap();
} catch(Exception e) {
e.printStackTrace();
}
}//GEN-LAST:event_jButtonStartActionPerformed
-
+
private void jCheckDetailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckDetailActionPerformed
config.detail = jCheckDetail.isSelected();
updateForms();
@@ -306,6 +394,8 @@
// Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton jButtonAdd;
+ private javax.swing.JButton jButtonDelte;
private javax.swing.JButton jButtonSelectInputFile;
private javax.swing.JButton jButtonSelectOutputFile;
private javax.swing.JButton jButtonStart;
@@ -316,6 +406,9 @@
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
+ private javax.swing.JPanel jPanel4;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JTable jTableTexturing;
private javax.swing.JTextField jTextFieldInputFile;
private javax.swing.JTextField jTextFieldOutputFile;
private javax.swing.JTextField jTextFieldScale;
@@ -323,4 +416,60 @@
private javax.swing.JTextField jTextFieldThickness;
// End of variables declaration//GEN-END:variables
+ private class AutoTexturingTableModel extends AbstractTableModel {
+
+ Vector texturing;
+
+ public AutoTexturingTableModel(Vector t) {
+ texturing = t;
+ }
+
+ private String[] columnNames = {"Starting angle (against xy plane)","Texture name"};
+
+
+ public int getColumnCount() {
+ return 2;
+ }
+
+ public int getRowCount() {
+ return texturing.size();
+ }
+
+ public String getColumnName(int col) {
+ return columnNames[col];
+ }
+
+ public Object getValueAt(int row, int col) {
+ if(row < 0 | row > texturing.size()) return null;
+
+ AutoTexturingEntry e = (AutoTexturingEntry)texturing.get(row);
+ if(col == 0)
+ return new Double(e.angle);
+ else
+ return e.texturename;
+ }
+
+ public Class getColumnClass(int c) {
+ return getValueAt(0, c).getClass();
+ }
+
+ public boolean isCellEditable(int row, int col) {
+ return true;
+ }
+
+ public void setValueAt(Object value, int row, int col) {
+
+ AutoTexturingEntry e = (AutoTexturingEntry)texturing.get(row);
+
+ if(col == 0) {
+ Double angle = (Double)value;
+ e.angle = angle.doubleValue();
+ } else {
+ e.texturename = (String)value;
+ }
+
+ fireTableCellUpdated(row, col);
+ }
+ }
+
}
Modified: tools/ObjToMap/objtomap/ObjToMap.java
===================================================================
--- tools/ObjToMap/objtomap/ObjToMap.java 2007-01-18 12:21:04 UTC (rev 2130)
+++ tools/ObjToMap/objtomap/ObjToMap.java 2007-01-18 18:22:48 UTC (rev 2131)
@@ -224,9 +224,21 @@
p2_ = p2.substract(normal);
p3_ = p3.substract(normal);
+ String mat = material;
+ if(config.autotexturing.size() > 0) {
+ double maxangle = -1.0;
+ for(int i = 0; i < config.autotexturing.size(); i++) {
+ AutoTexturingEntry e = (AutoTexturingEntry)config.autotexturing.get(i);
+ if(angle_xy >= e.angle && e.angle > maxangle) {
+ mat = e.texturename;
+ maxangle = e.angle;
+ }
+ }
+ }
+
// top face, apply texture here
- result += getMapPlaneString(p3, p2, p1, material);
+ result += getMapPlaneString(p3, p2, p1, mat);
// bottom face
result += getMapPlaneString(p1_, p2_, p3_, "common/caulk");
More information about the nexuiz-commits
mailing list