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
this.surfaces[i].setTexGenIndex(this.texGenEQs.indexOf(texGen));
}
//this.recalculateBounds();
this.recalculateBounds();
}
public void recalculateBounds()
......@@ -1055,6 +1055,9 @@ public class Interior
{
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 surfaceCount = hull.getSurfaceCount();
......@@ -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());
}*/
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 windingCount = surface.getWindingCount();
......@@ -1086,6 +1086,8 @@ public class Interior
{
Point3F point = this.points[this.windings[k]].getPoint();
System.out.println("Point: " + point.toString());
minHull.setMin(point);
maxHull.setMax(point);
}
......@@ -1123,6 +1125,9 @@ public class Interior
//minHull = 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.setMinY(minHull.getY());
hull.setMinZ(minHull.getZ());
......
......@@ -16,6 +16,7 @@ import org.xml.sax.SAXException;
import com.dddviewr.collada.Collada;
import com.matt.difinspector.io.ReverseDataInputStream;
import com.matt.difinspector.io.ReverseDataOutputStream;
import com.matt.difinspector.main.DifInspector;
import com.matt.difinspector.mesh.InteriorBuilder;
import com.matt.difinspector.models.OBJModel;
import com.matt.difinspector.models.OBJModel.OBJIndex;
......@@ -498,6 +499,10 @@ public class InteriorResource
try
{
DifInspector inspector = DifInspector.getInstance();
inspector.displayProgress(true);
inspector.displayProgress("Importing OBJ File", 0);
System.out.println("Importing OBJ File");
OBJModel model = new OBJModel(file);
......
......@@ -66,6 +66,8 @@ public class DifInspector
private PointEditor pointEditor;
private PlaneEditor planeEditor;
private Selector selector;
private ProgressDialog progressDialog;
public DifInspector()
{
......@@ -84,6 +86,7 @@ public class DifInspector
this.pointEditor = new PointEditor();
this.planeEditor = new PlaneEditor();
this.selector = new Selector(this.render);
this.progressDialog = new ProgressDialog(this.frame);
JMenu fileMenu = new JMenu("File");
......@@ -300,7 +303,7 @@ public class DifInspector
});
editMenu.add(selectMenu);
JMenuItem boundsMenu = new JMenuItem("Recalculate Bounds");
/*JMenuItem boundsMenu = new JMenuItem("Recalculate Bounds");
boundsMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
......@@ -308,7 +311,7 @@ public class DifInspector
DifInspector.this.recalculateBounds();
}
});
editMenu.add(boundsMenu);
editMenu.add(boundsMenu);*/
/*JMenuItem addMaterialMenu = new JMenuItem("Add Material");
addMaterialMenu.addActionListener(new ActionListener() {
......@@ -434,14 +437,21 @@ public class DifInspector
File file = chooser.getSelectedFile();
if (file != null && file.exists())
{
this.interior = new InteriorResource();
if (this.interior.readOBJ(file))
{
this.processInterior();
} else
{
JOptionPane.showMessageDialog(this.frame, "Failed to load interior!");
}
Thread objLoader = new Thread(new Runnable(){
@Override
public void run()
{
DifInspector.this.interior = new InteriorResource();
if (DifInspector.this.interior.readOBJ(file))
{
DifInspector.this.processInterior();
} else
{
JOptionPane.showMessageDialog(DifInspector.this.frame, "Failed to load interior!");
}
}
});
objLoader.start();
}
String dir = chooser.getCurrentDirectory().toString();
......@@ -764,7 +774,7 @@ public class DifInspector
this.processInterior();
}
public void recalculateBounds()
/*public void recalculateBounds()
{
if (this.interior == null)
{
......@@ -778,6 +788,27 @@ public class DifInspector
System.out.println("Recalculating Bounds");
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);
}
}
......@@ -7,6 +7,7 @@ import java.util.List;
import com.matt.difinspector.interior.Interior;
import com.matt.difinspector.interior.InteriorSimpleMesh;
import com.matt.difinspector.interior.InteriorSubObject;
import com.matt.difinspector.main.DifInspector;
import com.matt.difinspector.materials.MaterialList;
import com.matt.difinspector.materials.TexGenList;
import com.matt.difinspector.structures.AnimatedLight;
......@@ -58,18 +59,27 @@ public class InteriorBuilder
public Interior build()
{
DifInspector inspector = DifInspector.getInstance();
inspector.displayProgress("Building Mesh", 0);
Mesh mesh = builder.build();
Interior result = new Interior();
inspector.displayProgress("Adding Points", 1);
System.out.println("Adding Points");
ItrPaddedPoint[] points = new ItrPaddedPoint[mesh.getVertices().length];
for (int i = 0; i < points.length; i++)
points[i] = new ItrPaddedPoint(mesh.getVertices()[i]);
result.setPoints(points);
inspector.displayProgress("Adding Windings", 6);
System.out.println("Adding Windings");
result.setWindings(mesh.getIndices());
inspector.displayProgress("Adding MaterialList", 8);
System.out.println("Adding MaterialList");
MaterialList materialList = new MaterialList();
for (String texture : mesh.getTextures())
......@@ -78,6 +88,8 @@ public class InteriorBuilder
int[] textureIndices = mesh.getTextureIndices();
inspector.displayProgress("Adding TexGenEQs", 10);
System.out.println("Adding TexGenEQs");
OptimizedList<Point2F> texCoords = new OptimizedList<Point2F>(mesh.getTextureCoords(), mesh.getTexCoordIndices());
OptimizedList<TexGenPlanes> texGenEQs = new OptimizedList<TexGenPlanes>();
......@@ -93,6 +105,8 @@ public class InteriorBuilder
texGenList.add(planes);
result.setTexGenEQs(texGenList);
inspector.displayProgress("Processing Faces", 15);
System.out.println("Processing Faces");
OptimizedList<Point3F> vertices = new OptimizedList<Point3F>(mesh.getVertices(), mesh.getIndices());
OptimizedList<Face> faces = new OptimizedList<Face>();
......@@ -146,6 +160,8 @@ public class InteriorBuilder
}
System.out.println();*/
inspector.displayProgress("Adding Planes", 17);
System.out.println("Adding Planes");
List<Face> facesObjs = faces.getObjects();
OptimizedList<PlaneF> planes = new OptimizedList<PlaneF>();
......@@ -155,12 +171,16 @@ public class InteriorBuilder
}
result.setPlanes(planes.getObjects());
inspector.displayProgress("Adding Plane Normals", 20);
System.out.println("Adding Plane Normals");
Point3F[] planeNormals = new Point3F[planes.sizeIndices()];
for (int i = 0; i < planes.sizeIndices(); i++)
planeNormals[i] = planes.getObject(i);
result.setPlaneNormals(planeNormals);
inspector.displayProgress("Adding Surfaces", 21);
System.out.println("Adding Surfaces");
OptimizedList<Surface> surfaces = new OptimizedList<Surface>();
......@@ -193,6 +213,8 @@ public class InteriorBuilder
}
result.setSurfaces(surfaces.getObjects());
inspector.displayProgress("Adding PointVisibilities", 25);
System.out.println("Adding PointVisibilities");
byte[] pointVisibilities = new byte[points.length];
for (int i = 0; i < points.length; i++)
......@@ -201,29 +223,43 @@ public class InteriorBuilder
}
result.setPointVisibility(pointVisibilities);
inspector.displayProgress("Adding Winding Indices", 27);
System.out.println("Adding Winding Indices");
result.setWindingIndices(new TriFan[0]);
inspector.displayProgress("Adding Zones", 28);
System.out.println("Adding Zones");
Zone[] zones = new Zone[1];
zones[0] = new Zone((short)0, (short)0, 0, 0, (short)surfaces.sizeIndices(), (short)0, 0, 0, (short)0, (short)0);
result.setZones(zones);
inspector.displayProgress("Adding Zone Surfaces", 29);
System.out.println("Adding Zone Surfaces");
short[] zoneSurfaces = new short[surfaces.sizeIndices()];
for (short i = 0; i < surfaces.sizeIndices(); i++)
zoneSurfaces[i] = i;
result.setZoneSurfaces(zoneSurfaces);
inspector.displayProgress("Adding Zone Static Meshes", 30);
System.out.println("Adding Zone Static Meshes");
result.setZoneStaticMeshes(new int[0]);
inspector.displayProgress("Adding Zone Portal List", 31);
System.out.println("Adding Zone Portal List");
result.setZonePortalList(new short[0]);
inspector.displayProgress("Adding Portals", 32);
System.out.println("Adding Portals");
result.setPortals(new Portal[0]);
inspector.displayProgress("Adding NormalLMapIndices", 35);
System.out.println("Adding NormalLMapIndices");
// NormalLMapIndices may be more complicated
int[] normalLMapIndices = new int[surfaces.sizeIndices()];
......@@ -231,16 +267,22 @@ public class InteriorBuilder
normalLMapIndices[i] = 0;//i;
result.setNormalLMapIndices(normalLMapIndices);
inspector.displayProgress("Adding AlarmLMapIndices", 40);
System.out.println("Adding AlarmLMapIndices");
int[] alarmLMapIndices = new int[surfaces.sizeIndices()];
for (int i = 0; i < surfaces.sizeIndices(); i++)
alarmLMapIndices[i] = 255;
result.setAlarmLMapIndices(alarmLMapIndices);
inspector.displayProgress("Adding NullSurfaces", 45);
System.out.println("Adding NullSurfaces");
// TODO: Null Surfaces
result.setNullSurfaces(new NullSurface[0]);
inspector.displayProgress("Adding LightMaps", 46);
System.out.println("Adding LightMaps");
// TODO: Light Maps
BufferedImage lightMap = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
......@@ -255,6 +297,8 @@ public class InteriorBuilder
result.setLightDirMaps(new BufferedImage[]{lightMap});
result.setLightMapKeep(new boolean[]{false});
inspector.displayProgress("Adding Solid Leaf Surfaces", 50);
System.out.println("Adding Solid Leaf Surfaces");
// TODO: Solid Leaf Surfaces
int[] solidLeafSurfaces = new int[planes.sizeIndices()];
......@@ -262,53 +306,74 @@ public class InteriorBuilder
solidLeafSurfaces[i] = i;
result.setSolidLeafSurfaces(solidLeafSurfaces);
inspector.displayProgress("Adding Animated Lights", 51);
System.out.println("Adding Animated Lights");
result.setAnimatedLights(new AnimatedLight[0]);
inspector.displayProgress("Adding Light States", 52);
System.out.println("Adding Light States");
result.setLightStates(new LightState[0]);
inspector.displayProgress("Adding Light State Data", 53);
System.out.println("Adding Light State Data");
result.setLightStateData(new LightStateData[0]);
inspector.displayProgress("Adding State Data Buffer", 54);
System.out.println("Adding State Data Buffer");
result.setStateDataBuffer(new byte[0]);
inspector.displayProgress("Adding Name Buffer", 55);
System.out.println("Adding Name Buffer");
result.setNameBuffer(new char[0]);
inspector.displayProgress("Adding Sub Objects", 56);
System.out.println("Adding Sub Objects");
result.setSubObjects(new InteriorSubObject[0]);
inspector.displayProgress("Adding Convex Hulls", 57);
System.out.println("Adding Convex Hulls");
ConvexHull[] convexHulls = new ConvexHull[surfaces.sizeIndices()];
for (int i = 0; i < surfaces.sizeIndices(); i++)
{
ConvexHull[] convexHulls = new ConvexHull[1];//vertices.sizeIndices() / 8];//surfaces.sizeIndices()];
//for (int i = 0; i < surfaces.sizeIndices(); i++)
//{
//int inde = 0;
//for (int i = 0; i < vertices.sizeIndices()-8; i+=8)
//{
float minX = 0;
float maxX = 0;
float minY = 0;
float maxY = 0;
float minZ = 0;
float maxZ = 0;
int hullStart = surfaces.getObject(i).getWindingStart();
int surfaceStart = i;
int planeStart = surfaces.getObject(i).getPlaneIndex();
short hullCount = (short)surfaces.getObject(i).getWindingCount();
short surfaceCount = 1;
int polyListPlaneStart = i;
int polyListPointStart = i*3;
int hullStart = 0;//surfaces.getObject(i).getWindingStart();
int surfaceStart = 0;//i;
int planeStart = 0;//surfaces.getObject(i).getPlaneIndex();
short hullCount = (short)vertices.sizeIndices();//(short)vertices.sizeIndices();//8;//(short)surfaces.getObject(i).getWindingCount();
short surfaceCount = (short)surfaces.sizeIndices();//1;
int polyListPlaneStart = 0;//i;
int polyListPointStart = 0;//i*3;
int polyListStringStart = 0;
short searchTag = 0;
boolean staticMesh = false;
convexHulls[i] = new ConvexHull(minX, maxX, minY, maxY, minZ, maxZ, hullStart, surfaceStart, planeStart, hullCount, surfaceCount, polyListPlaneStart, polyListPointStart, polyListStringStart, searchTag, staticMesh);
}
convexHulls[0] = new ConvexHull(minX, maxX, minY, maxY, minZ, maxZ, hullStart, surfaceStart, planeStart, hullCount, surfaceCount, polyListPlaneStart, polyListPointStart, polyListStringStart, searchTag, staticMesh);
//inde++;
//}
result.setConvexHulls(convexHulls);
inspector.displayProgress("Adding Convex Hull Emit Strings", 65);
// TODO: Convex Hull Emit Strings
System.out.println("Adding Convex Hull Emit Strings");
// To inspect this further, I want to make a test DIF with a triangular prism in it. This would give me all the properties of a triangle. I should theoretically just be able to copy paste them.
List<Byte> convexHullByteStrings = new ArrayList<Byte>();
for (int i = 0; i < convexHulls.length; i++) {
/*for (int i = 0; i < convexHulls.length; i++) {
// the number of POINTS in this triangle minus one
convexHullByteStrings.add((byte)2);
// the point indices
......@@ -334,12 +399,15 @@ public class InteriorBuilder
convexHullByteStrings.add((byte)0);
convexHullByteStrings.add((byte)1);
convexHullByteStrings.add((byte)2);
}
}*/
byte[] convexHullEmitStrings = new byte[convexHullByteStrings.size()];
for (int i = 0; i < convexHullByteStrings.size(); i++) {
convexHullEmitStrings[i] = convexHullByteStrings.get(i);
}
result.setConvexHullEmitStrings(convexHullEmitStrings);
inspector.displayProgress("Adding Hull Indices", 70);
// TODO: Hull Indices
System.out.println("Adding Hull Indices");
// should be * 3 not 8, there are three vertices per shape
......@@ -349,6 +417,9 @@ public class InteriorBuilder
hullIndices[i] = i;
}
result.setHullIndices(hullIndices);
inspector.displayProgress("Adding Hull Plane Indices", 73);
// TODO: Hull Plane Indices
System.out.println("Adding Hull Plane Indices");
// just the planeIndexes in some order
......@@ -358,6 +429,9 @@ public class InteriorBuilder
result.setHullPlaneIndices(hullPlaneIndices);
// TODO: Hull Emit String Indices
// Each triangle uses 15 numbers in the convexHullEmitStrings. This makes sense - they are all the same shape.
inspector.displayProgress("Adding Hull Emit String Indices", 75);
System.out.println("Adding Hull Emit String Indices");
int[] hullEmitStringIndices = new int[convexHulls.length];
for (int i = 0; i < convexHulls.length; i++)
......@@ -366,6 +440,8 @@ public class InteriorBuilder
}
result.setHullEmitStringIndices(hullEmitStringIndices);
inspector.displayProgress("Adding Hull Surface Indices", 77);
System.out.println("Adding Hull Surface Indices");
int[] hullSurfaceIndices = new int[surfaces.sizeIndices()];
for (int i = 0; i < surfaces.sizeIndices(); i++)
......@@ -373,21 +449,30 @@ public class InteriorBuilder
result.setHullSurfaceIndices(hullSurfaceIndices);
// TODO: Poly List Planes
inspector.displayProgress("Adding Poly List Planes", 80);
System.out.println("Adding Poly List Planes");
short[] polyListPlanes = new short[planes.sizeIndices()];
for (short i = 0; i < planes.sizeIndices(); i++)
polyListPlanes[i] = i;
result.setPolyListPlanes(polyListPlanes);
// TODO: Poly List Points
inspector.displayProgress("Adding Poly List Points", 81);
System.out.println("Adding Poly List Points");
int[] polyListPoints = new int[points.length];
for (int i = 0; i < points.length; i++)
polyListPoints[i] = i;
result.setPolyListPoints(polyListPoints);
// TODO: Poly List Strings
inspector.displayProgress("Adding Poly List Strings", 82);
System.out.println("Adding Poly List Strings");
List<Byte> polyByteStrings = new ArrayList<Byte>();
for (int i = 0; i < convexHulls.length; i++) {
/*for (int i = 0; i < convexHulls.length; i++) {
// the number of PLANES in this convex hull, always 1 in a triangle
polyByteStrings.add((byte)1);
// a bunch of powers of two with one for each surface (we only have one surface - so just 1)
......@@ -423,7 +508,7 @@ public class InteriorBuilder
polyByteStrings.add((byte)0);
polyByteStrings.add((byte)mesh.getIndices()[2+(i*3)]);
convexHulls[i].setPolyListStringStart(i*19);
}
}*/
byte[] polyListStrings = new byte[polyByteStrings.size()];
for (int i = 0; i < polyByteStrings.size(); i++) {
polyListStrings[i] = polyByteStrings.get(i);
......@@ -433,43 +518,66 @@ public class InteriorBuilder
// TODO: CoordBins
// TODO: CoordBinIndices
inspector.displayProgress("Building CoordBins", 85);
System.out.println("Building CoordBins");
CoordBin[] coordBins = new CoordBin[256];
for (int i = 0; i < coordBins.length; i++)
coordBins[i] = new CoordBin(i, 1);
result.setCoordBins(coordBins);
inspector.displayProgress("Building CoordBin Indices", 86);
System.out.println("Building CoordBin Indices");
short[] coordBinIndices = new short[coordBins.length];
for (short i = 0; i < coordBins.length; i++)
coordBinIndices[i] = 0;//i;
result.setCoordBinIndices(coordBinIndices);
inspector.displayProgress("Adding CoordBinMode", 87);
System.out.println("Adding CoordBinMode");
result.setCoordBinMode(0);
inspector.displayProgress("Adding BaseAmbient", 88);
System.out.println("Adding BaseAmbient");
result.setBaseAmbient(new ColorI((byte)0, (byte)0, (byte)0, (byte)-1));
inspector.displayProgress("Adding AlarmAmbient", 89);
System.out.println("Adding AlarmAmbient");
result.setAlarmAmbient(new ColorI((byte)0, (byte)0, (byte)0, (byte)-1));
inspector.displayProgress("Adding Static Meshes", 90);
System.out.println("Adding Static Meshes");
result.setStaticMeshes(new InteriorSimpleMesh[0]);
inspector.displayProgress("Adding Normals", 91);
System.out.println("Adding Normals");
result.setNormals(new Point3F[0]);
inspector.displayProgress("Adding TexMatrices", 92);
System.out.println("Adding TexMatrices");
result.setTexMatrices(new TexMatrix[0]);
inspector.displayProgress("Adding TexMatIndices", 93);
System.out.println("Adding TexMatIndices");
result.setTexMatIndices(new int[0]);
inspector.displayProgress("Adding Light Map Border Size", 94);
System.out.println("Adding Light Map Border Size");
result.setLightMapBorderSize(2);
// TODO: BSPNodes
inspector.displayProgress("Adding BSPNodes", 95);
System.out.println("Adding BSPNodes");
BSPNode[] bspNodes = new BSPNode[surfaces.sizeIndices()];
for (int i = 0; i < surfaces.sizeIndices(); i++)
......@@ -484,20 +592,33 @@ public class InteriorBuilder
}
result.setBspNodes(bspNodes);
inspector.displayProgress("Adding BSPSolidLeaves", 96);
System.out.println("Adding BSPSolidLeaves");
BSPSolidLeaf[] bspSolidLeaves = new BSPSolidLeaf[surfaces.sizeIndices()];
for (int i = 0; i < surfaces.sizeIndices(); i++)
bspSolidLeaves[i] = new BSPSolidLeaf(i, (short)1);
result.setBspSolidLeaves(bspSolidLeaves);
inspector.displayProgress("Processing Data", 97);
System.out.println("Processing Data");
result.processData();
inspector.displayProgress("Preparing Data", 98);
System.out.println("Preparing Data");
result.prepareData();
inspector.displayProgress("Recalculating Bounds", 99);
System.out.println("Recalculating Bounds");
result.recalculateBounds();
//result.recalculateBounds();
result.setMinPixels(250);
inspector.displayProgress(100);
inspector.displayProgress(false);
return result;
}
......
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