Commit 61986e36 authored by Human Gamer's avatar Human Gamer

OBJ->DIF Importer now supports collision

Fixed Bounds Calculation
Progress Dialog when importing OBJ files
parent 6fcb39e1
...@@ -1039,7 +1039,7 @@ public class Interior ...@@ -1039,7 +1039,7 @@ public class Interior
this.surfaces[i].setTexGenIndex(this.texGenEQs.indexOf(texGen)); this.surfaces[i].setTexGenIndex(this.texGenEQs.indexOf(texGen));
} }
//this.recalculateBounds(); this.recalculateBounds();
} }
public void recalculateBounds() public void recalculateBounds()
...@@ -1055,6 +1055,9 @@ public class Interior ...@@ -1055,6 +1055,9 @@ public class Interior
{ {
ConvexHull hull = this.convexHulls[i]; ConvexHull hull = this.convexHulls[i];
Point3F minHull = new Point3F((float)1e10, (float)1e10, (float)1e10);
Point3F maxHull = new Point3F((float)-1e10, (float)-1e10, (float)-1e10);
int surfaceStart = hull.getSurfaceStart(); int surfaceStart = hull.getSurfaceStart();
int surfaceCount = hull.getSurfaceCount(); int surfaceCount = hull.getSurfaceCount();
...@@ -1076,9 +1079,6 @@ public class Interior ...@@ -1076,9 +1079,6 @@ public class Interior
System.out.println("MinX: " + hull.getMinX() + ", MaxY: " + hull.getMaxY() + ", PX: " + plane.getX() + ", PY: " + plane.getY() + ", PD: " + plane.getD()); System.out.println("MinX: " + hull.getMinX() + ", MaxY: " + hull.getMaxY() + ", PX: " + plane.getX() + ", PY: " + plane.getY() + ", PD: " + plane.getD());
}*/ }*/
Point3F minHull = new Point3F((float)1e10, (float)1e10, (float)1e10);
Point3F maxHull = new Point3F((float)-1e10, (float)-1e10, (float)-1e10);
int windingStart = surface.getWindingStart(); int windingStart = surface.getWindingStart();
int windingCount = surface.getWindingCount(); int windingCount = surface.getWindingCount();
...@@ -1086,6 +1086,8 @@ public class Interior ...@@ -1086,6 +1086,8 @@ public class Interior
{ {
Point3F point = this.points[this.windings[k]].getPoint(); Point3F point = this.points[this.windings[k]].getPoint();
System.out.println("Point: " + point.toString());
minHull.setMin(point); minHull.setMin(point);
maxHull.setMax(point); maxHull.setMax(point);
} }
...@@ -1123,6 +1125,9 @@ public class Interior ...@@ -1123,6 +1125,9 @@ public class Interior
//minHull = new Point3F(0, 0, 0); //minHull = new Point3F(0, 0, 0);
//maxHull = new Point3F(0, 0, 0); //maxHull = new Point3F(0, 0, 0);
//minHull = new Point3F(-10, -10, -10);
//maxHull = new Point3F(10, 10, 10);
hull.setMinX(minHull.getX()); hull.setMinX(minHull.getX());
hull.setMinY(minHull.getY()); hull.setMinY(minHull.getY());
hull.setMinZ(minHull.getZ()); hull.setMinZ(minHull.getZ());
......
...@@ -16,6 +16,7 @@ import org.xml.sax.SAXException; ...@@ -16,6 +16,7 @@ import org.xml.sax.SAXException;
import com.dddviewr.collada.Collada; import com.dddviewr.collada.Collada;
import com.matt.difinspector.io.ReverseDataInputStream; import com.matt.difinspector.io.ReverseDataInputStream;
import com.matt.difinspector.io.ReverseDataOutputStream; import com.matt.difinspector.io.ReverseDataOutputStream;
import com.matt.difinspector.main.DifInspector;
import com.matt.difinspector.mesh.InteriorBuilder; import com.matt.difinspector.mesh.InteriorBuilder;
import com.matt.difinspector.models.OBJModel; import com.matt.difinspector.models.OBJModel;
import com.matt.difinspector.models.OBJModel.OBJIndex; import com.matt.difinspector.models.OBJModel.OBJIndex;
...@@ -498,6 +499,10 @@ public class InteriorResource ...@@ -498,6 +499,10 @@ public class InteriorResource
try try
{ {
DifInspector inspector = DifInspector.getInstance();
inspector.displayProgress(true);
inspector.displayProgress("Importing OBJ File", 0);
System.out.println("Importing OBJ File"); System.out.println("Importing OBJ File");
OBJModel model = new OBJModel(file); OBJModel model = new OBJModel(file);
......
...@@ -66,6 +66,8 @@ public class DifInspector ...@@ -66,6 +66,8 @@ public class DifInspector
private PointEditor pointEditor; private PointEditor pointEditor;
private PlaneEditor planeEditor; private PlaneEditor planeEditor;
private Selector selector; private Selector selector;
private ProgressDialog progressDialog;
public DifInspector() public DifInspector()
{ {
...@@ -84,6 +86,7 @@ public class DifInspector ...@@ -84,6 +86,7 @@ public class DifInspector
this.pointEditor = new PointEditor(); this.pointEditor = new PointEditor();
this.planeEditor = new PlaneEditor(); this.planeEditor = new PlaneEditor();
this.selector = new Selector(this.render); this.selector = new Selector(this.render);
this.progressDialog = new ProgressDialog(this.frame);
JMenu fileMenu = new JMenu("File"); JMenu fileMenu = new JMenu("File");
...@@ -300,7 +303,7 @@ public class DifInspector ...@@ -300,7 +303,7 @@ public class DifInspector
}); });
editMenu.add(selectMenu); editMenu.add(selectMenu);
JMenuItem boundsMenu = new JMenuItem("Recalculate Bounds"); /*JMenuItem boundsMenu = new JMenuItem("Recalculate Bounds");
boundsMenu.addActionListener(new ActionListener() { boundsMenu.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
...@@ -308,7 +311,7 @@ public class DifInspector ...@@ -308,7 +311,7 @@ public class DifInspector
DifInspector.this.recalculateBounds(); DifInspector.this.recalculateBounds();
} }
}); });
editMenu.add(boundsMenu); editMenu.add(boundsMenu);*/
/*JMenuItem addMaterialMenu = new JMenuItem("Add Material"); /*JMenuItem addMaterialMenu = new JMenuItem("Add Material");
addMaterialMenu.addActionListener(new ActionListener() { addMaterialMenu.addActionListener(new ActionListener() {
...@@ -434,14 +437,21 @@ public class DifInspector ...@@ -434,14 +437,21 @@ public class DifInspector
File file = chooser.getSelectedFile(); File file = chooser.getSelectedFile();
if (file != null && file.exists()) if (file != null && file.exists())
{ {
this.interior = new InteriorResource(); Thread objLoader = new Thread(new Runnable(){
if (this.interior.readOBJ(file)) @Override
{ public void run()
this.processInterior(); {
} else DifInspector.this.interior = new InteriorResource();
{ if (DifInspector.this.interior.readOBJ(file))
JOptionPane.showMessageDialog(this.frame, "Failed to load interior!"); {
} DifInspector.this.processInterior();
} else
{
JOptionPane.showMessageDialog(DifInspector.this.frame, "Failed to load interior!");
}
}
});
objLoader.start();
} }
String dir = chooser.getCurrentDirectory().toString(); String dir = chooser.getCurrentDirectory().toString();
...@@ -764,7 +774,7 @@ public class DifInspector ...@@ -764,7 +774,7 @@ public class DifInspector
this.processInterior(); this.processInterior();
} }
public void recalculateBounds() /*public void recalculateBounds()
{ {
if (this.interior == null) if (this.interior == null)
{ {
...@@ -778,6 +788,27 @@ public class DifInspector ...@@ -778,6 +788,27 @@ public class DifInspector
System.out.println("Recalculating Bounds"); System.out.println("Recalculating Bounds");
this.interior.recalculateBounds(); this.interior.recalculateBounds();
} }
}*/
public void displayProgress(boolean show)
{
if (show)
{
this.progressDialog.showDialog();
} else {
this.progressDialog.hideDialog();
}
}
public void displayProgress(int progress)
{
this.progressDialog.setProgress(progress);
}
public void displayProgress(String status, int progress)
{
this.progressDialog.setStatus(status);
this.progressDialog.setProgress(progress);
} }
/* /*
......
package com.matt.difinspector.main;
import java.awt.Dimension;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
public class ProgressDialog extends JDialog
{
private static final long serialVersionUID = 3325346180146941878L;
private JPanel panel;
private JLabel status;
private JProgressBar bar;
public ProgressDialog(JFrame parent)
{
super(parent, false);
this.setTitle("Loading...");
this.panel = new JPanel();
this.panel.setPreferredSize(new Dimension(300, 50));
this.status = new JLabel("Loading...");
this.status.setPreferredSize(new Dimension(290, 25));
this.bar = new JProgressBar(0, 100);
this.bar.setPreferredSize(new Dimension(290, 25));
this.panel.add(this.status);
this.panel.add(this.bar);
this.add(this.panel);
this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
this.setSize(320, 120);
this.setResizable(false);
this.setLocationRelativeTo(null);
}
public void showDialog()
{
this.getParent().setEnabled(false);
if (!this.isVisible())
this.setVisible(true);
}
public void hideDialog()
{
this.getParent().setEnabled(true);
this.setVisible(false);
this.setStatus("");
this.setProgress(0);
}
public void setStatus(String status)
{
if (!this.status.getText().equals(status))
this.status.setText(status);
}
public void setProgress(int value)
{
if (value >= 100)
{
this.hideDialog();
return;
}
if (this.bar.getValue() != value)
this.bar.setValue(value);
}
}
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