Commit b2432e9c authored by Human Gamer's avatar Human Gamer

SubObject Import and Export

parent 919ed318
......@@ -303,6 +303,16 @@ public class DifInspector
});
editMenu.add(selectMenu);
JMenuItem importSubMenu = new JMenuItem("Import SubObject");
importSubMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
DifInspector.this.importSubObject();
}
});
editMenu.add(importSubMenu);
/*JMenuItem boundsMenu = new JMenuItem("Recalculate Bounds");
boundsMenu.addActionListener(new ActionListener() {
@Override
......@@ -750,6 +760,43 @@ public class DifInspector
//this.render.setHighlight(true);
}
public void importSubObject()
{
if (this.interior == null)
{
JOptionPane.showMessageDialog(this.frame, "Operation Failed:\n" + "No Interior Loaded!");
return;
}
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(new FileNameExtensionFilter("Interior Files (.dif)", "dif"));
if (!Settings.getLastOpenDir().isEmpty())
chooser.setCurrentDirectory(new File(Settings.getLastOpenDir()));
int option = chooser.showOpenDialog(this.frame);
if (option != JFileChooser.APPROVE_OPTION)
return;
File file = chooser.getSelectedFile();
if (file != null && file.exists())
{
InteriorResource res = new InteriorResource();
if (res.read(file))
{
Interior it = res.getDetailLevels().get(0);
this.interior.getSubObjects().add(it);
this.processInterior();
} else
{
JOptionPane.showMessageDialog(this.frame, "Failed to load SubObject!");
}
}
String dir = chooser.getCurrentDirectory().toString();
Settings.setLastOpenDir(dir);
Settings.saveConfig();
}
public void renderSettings()
{
this.settings.setVisible(true);
......
package com.matt.difinspector.main;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.matt.difinspector.interior.Interior;
import com.matt.difinspector.interior.InteriorResource;
import com.matt.difinspector.util.Settings;
public class SubObjectsTab extends JPanel
{
......@@ -19,6 +28,7 @@ public class SubObjectsTab extends JPanel
private JComboBox<String> levels;
private JComboBox<String> menu;
private JButton export;
private SubPanel displayedPanel;
public SubObjectsTab()
......@@ -58,10 +68,20 @@ public class SubObjectsTab extends JPanel
}
});
this.export = new JButton("Export");
this.export.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
SubObjectsTab.this.doExport();
}
});
JPanel menus = new JPanel();
menus.add(this.levels);
menus.add(this.menu);
menus.add(this.export);
this.add(menus, BorderLayout.NORTH);
......@@ -115,4 +135,39 @@ public class SubObjectsTab extends JPanel
this.menu.setSelectedIndex(0);
this.setDisplay(this.menu.getSelectedItem().toString());
}
public void doExport()
{
int objectIndex = this.levels.getSelectedIndex();
Interior subObject = DifInspector.getInstance().getInterior().getSubObjects().get(objectIndex);
InteriorResource res = new InteriorResource();
res.getDetailLevels().add(subObject);
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(new FileNameExtensionFilter("Interior v" + 0 + " Files (.dif)", "dif"));
if (!Settings.getLastSaveDir().isEmpty())
chooser.setCurrentDirectory(new File(Settings.getLastSaveDir()));
int option = chooser.showSaveDialog(this);
if (option != JFileChooser.APPROVE_OPTION)
return;
File file = chooser.getSelectedFile();
if (file != null)
{
if (res.write(file, 0))
{
JOptionPane.showMessageDialog(this, "Successfully Exported!");
} else
{
JOptionPane.showMessageDialog(this, "Export Failed:\n" + res.getErrors().toString());
}
}
String dir = chooser.getCurrentDirectory().toString();
Settings.setLastSaveDir(dir);
Settings.saveConfig();
}
}
......@@ -46,7 +46,7 @@ public class MaterialList
for (int i = 0; i < this.materials.size(); i++)
{
dos.writeString(this.materials.get(i).getName());
dos.writeString(this.materials.get(i).getName());// + "_mbm");
}
return true;
......
......@@ -124,17 +124,20 @@ public class InteriorBuilder
Point2F uv = texCoords.getObject(i);
Point3F point = vertices.getObject(i);
Point3F normal = normals.getObject(i);
//System.out.println(normal);
//TexGenPlanes texGenPlanes = new TexGenPlanes(normal, point, uv);
String texture = mesh.getTextures()[textureIndices[i]];
Point2F scale = new Point2F(0.25f, 0.25f);
float rotation = 0;
if (texture.equalsIgnoreCase("edge_white") || texture.equalsIgnoreCase("edge_white_mbm"))
scale = new Point2F(0.125f, 0.125f);
TexData texData = new TexData(normal, new Point2F(0, 0), 0, scale);
if (texture.equalsIgnoreCase("stripe_caution") || texture.equalsIgnoreCase("stripe_caution_mbm"))
rotation = 45;
TexData texData = new TexData(normal, new Point2F(0, 0), rotation, scale);
ImageData imageData = images.get(texture);
TexGenPlanes texGenPlanes = new TexGenPlanes(normal, point, uv);
if (imageData != null)
texGenPlanes = Util.getTexGen(texData, imageData);
//TexGenPlanes texGenPlanes = new TexGenPlanes(normal, point, uv);
texGenEQs.add(texGenPlanes);
}
......
......@@ -27,6 +27,8 @@ public class MeshBuilder
this.textureCoordinates.add(uv);
if (texture.endsWith(".001"))
texture = texture.substring(0, texture.lastIndexOf(".001"));
else if (texture.endsWith(".002"))
texture = texture.substring(0, texture.lastIndexOf(".002"));
this.textures.add(texture);
}
......
......@@ -78,6 +78,58 @@ public class TexGenPlanes
public TexGenPlanes(Point3F normal, Point3F point, Point2F uv)
{
this();
/*float[][] vecs = Util.getTextureAxis(normal);
int sv;
int tv;
if (vecs[0][0] != 0.0f)
{
sv = 0;
} else if (vecs[0][1] != 0.0f)
{
sv = 1;
} else {
sv = 2;
}
if (vecs[1][0] != 0.0f)
{
tv = 0;
} else if (vecs[1][1] != 0.0f)
{
tv = 1;
} else {
tv = 2;
}
//vecs[0][sv] = uv.getX();
//vecs[1][tv] = uv.getY();
Point3F vec1 = new Point3F(vecs[0][0], vecs[0][1], vecs[0][2]);
Point3F vec2 = new Point3F(vecs[1][0], vecs[1][1], vecs[1][2]);
vec1 = vec1.mul(uv.getX() * 4);
vec2 = vec2.mul(uv.getY() * 8);
System.out.println("V1: " + vec1);
System.out.println("V2: " + vec2);
float ux = vec1.getX();
float uy = vec1.getY();
float uz = vec1.getZ();
float ud = 0;
this.planeX = new PlaneF(ux, uy, uz, ud);
float vx = vec2.getX();
float vy = vec2.getY();
float vz = vec2.getZ();
float vd = 0;
this.planeY = new PlaneF(vx, vy, vz, vd);
this.scaleDown(32);*/
//this(normal, uv, 0, new Point2F(0.25f, 0.25f));
//this.scaleDown(32);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment