Commit 76438271 authored by Human Gamer's avatar Human Gamer

Vertex and Plane Editing WIP

parent 0d74380a
Pipeline #1774180 skipped
......@@ -34,7 +34,6 @@ import com.matt.difinspector.structures.LightState;
import com.matt.difinspector.structures.LightStateData;
import com.matt.difinspector.structures.NullSurface;
import com.matt.difinspector.structures.PlaneF;
import com.matt.difinspector.structures.PlaneIndex;
import com.matt.difinspector.structures.Point3F;
import com.matt.difinspector.structures.Portal;
import com.matt.difinspector.structures.SphereF;
......@@ -469,10 +468,6 @@ public class Interior
{
normalIndices.add(dis.readShort());
}
if (i == 1)
{
System.out.println(normalIndices.get(i));
}
}
}
......@@ -480,7 +475,6 @@ public class Interior
// boolean readNormalLMapIndicesAlt = false;
// byte numNormalLMapIndicesAlt = 0;
int numNormalLMapIndices = dis.readInt();
System.out.println(numNormalLMapIndices);
if ((numNormalLMapIndices & 0x80000000) != 0)
{
numNormalLMapIndices ^= 0x80000000;
......@@ -1027,6 +1021,82 @@ public class Interior
this.surfaces[i].setTexGenIndex(this.texGenEQs.indexOf(texGen));
}
for (int i = 0; i < this.convexHulls.length; i++)
{
ConvexHull hull = this.convexHulls[i];
int surfaceStart = hull.getSurfaceStart();
int surfaceCount = hull.getSurfaceCount();
for (int j = surfaceStart; j < surfaceStart + surfaceCount; j++)
{
int surfaceWinding = this.hullSurfaceIndices[j];
Surface surface = this.surfaces[surfaceWinding];
int planeIndex = surface.getPlaneIndex();
PlaneF plane = this.planes[planeIndex];
if (plane.getX() > 0 && plane.getD() * -1 > hull.getMaxX())
{
hull.setMaxX(plane.getD() * -1);
} else if (plane.getX() < 0 && plane.getD() < hull.getMinX())
{
hull.setMinX(plane.getD());
}
if (plane.getY() > 0 && plane.getY() * -1 > hull.getMaxY())
{
hull.setMaxY(plane.getD() * -1);
} else if (plane.getY() < 0 && plane.getD() < hull.getMinY())
{
hull.setMinY(plane.getD());
}
if (plane.getZ() > 0 && plane.getD() * -1 > hull.getMaxZ())
{
hull.setMaxZ(plane.getD() * -1);
} else if (plane.getZ() < 0 && plane.getD() < hull.getMinZ())
{
hull.setMinZ(plane.getD());
}
}
if (hull.getMaxX() > this.boundingBox.getMax().getX())
{
this.boundingBox.getMax().setX(hull.getMaxX());
} else if (hull.getMinX() < this.boundingBox.getMin().getX())
{
this.boundingBox.getMin().setX(hull.getMinX());
}
if (hull.getMaxY() > this.boundingBox.getMax().getY())
{
this.boundingBox.getMax().setY(hull.getMaxY());
} else if (hull.getMinY() < this.boundingBox.getMin().getY())
{
this.boundingBox.getMin().setY(hull.getMinY());
}
if (hull.getMaxZ() > this.boundingBox.getMax().getZ())
{
this.boundingBox.getMax().setZ(hull.getMaxZ());
} else if (hull.getMinZ() < this.boundingBox.getMin().getZ())
{
this.boundingBox.getMin().setZ(hull.getMinZ());
}
this.boundingSphere.setCenter(this.boundingBox.getMax().abs().sub(this.boundingBox.getMin().abs()));
float max = this.boundingBox.getMax().absMax();
float min = this.boundingBox.getMin().absMax();
float diamater = Math.max(max, min);
this.boundingSphere.setRadius(diamater);
}
}
public void readPlaneVector(ReverseDataInputStream dis) throws IOException
......@@ -1240,7 +1310,7 @@ public class Interior
return null;
short planeIndex = dis.readShort();
boolean flipped = (planeIndex >> 15 != 0);
//boolean flipped = (planeIndex >> 15 != 0);
//planeIndex &= ~0x8000;
if ((int) (planeIndex & ~0x8000) >= this.planes.length) // this.planeIndices.length)
......@@ -1306,7 +1376,7 @@ public class Interior
}
return new Surface(windingStart, planeIndex, textureIndex, texGenIndex, lightCount, surfaceFlags, windingCount,
fanMask, lightStateInfoStart, mapOffsetX, mapOffsetY, mapSizeX, mapSizeY, unused, brushId, flipped);
fanMask, lightStateInfoStart, mapOffsetX, mapOffsetY, mapSizeX, mapSizeY, unused, brushId);//, flipped);
}
public boolean readVehicleCollision(ReverseDataInputStream dis) throws IOException
......
......@@ -60,6 +60,8 @@ public class DifInspector
private GLRender render;
private RenderSettings settings;
private SurfaceEditor surfaceEditor;
private PointEditor pointEditor;
private PlaneEditor planeEditor;
private Selector selector;
public DifInspector()
......@@ -76,6 +78,8 @@ public class DifInspector
this.render = new GLRender(60, 800, 600);
this.settings = new RenderSettings(this.render);
this.surfaceEditor = new SurfaceEditor();
this.pointEditor = new PointEditor();
this.planeEditor = new PlaneEditor();
this.selector = new Selector(this.render);
JMenu fileMenu = new JMenu("File");
......@@ -346,6 +350,8 @@ public class DifInspector
{
this.render.setInterior(this.interior);
this.surfaceEditor.setInterior(this.interior);
this.pointEditor.setInterior(this.interior);
this.planeEditor.setInterior(this.interior);
this.settings.refresh();
this.selector.refresh();
this.infoTab.update();
......@@ -638,6 +644,18 @@ public class DifInspector
this.surfaceEditor.setVisible(true);
}
public void editPoint(int pointId)
{
this.pointEditor.setPoint(pointId);
this.pointEditor.setVisible(true);
}
public void editPlane(int planeId)
{
this.planeEditor.setPlane(planeId);
this.planeEditor.setVisible(true);
}
public void select()
{
this.selector.setVisible(true);
......
package com.matt.difinspector.main;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.matt.difinspector.interior.InteriorResource;
import com.matt.difinspector.structures.PlaneF;
public class PlaneEditor extends JFrame
{
private static final long serialVersionUID = -2746362797227228710L;
private InteriorResource interior;
private JPanel panel;
private JPanel dataPanel;
private PlaneField planeField;
private JButton applyButton;
private int planeId;
public PlaneEditor()
{
this.setTitle("Plane Editor");
this.setSize(200, 200);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
this.panel = new JPanel();
this.dataPanel = new JPanel();
this.planeField = new PlaneField("Plane: ");
this.applyButton = new JButton("Apply");
this.applyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
PlaneEditor.this.apply();
}
});
this.dataPanel.setPreferredSize(new Dimension(200, 45));
this.dataPanel.add(this.planeField);
this.setLayout(new FlowLayout());
this.add(this.panel);
this.add(this.dataPanel);
this.add(this.applyButton);
this.setLocationRelativeTo(null);
this.planeId = 0;
}
public void setInterior(InteriorResource interior)
{
this.interior = interior;
//Interior detail = interior.getDetailLevels().get(0);
/*
* this.surfaceSelection.removeAllItems(); for (int i = 0; i < detail.getSurfaces().length; i++) {
* this.surfaceSelection.addItem("Surface: " + i); }
*
* if (this.surfaceSelection.getItemCount() > 0) this.surfaceSelection.setSelectedIndex(0);
*/
updateDisplay();
}
public void updateDisplay()
{
int planeIndex = this.planeId;
PlaneF plane = this.interior.getDetailLevels().get(0).getPlanes()[planeIndex];
this.planeField.setPlane(plane);
}
private void apply()
{
int planeIndex = this.planeId;
this.interior.getDetailLevels().get(0).getPlanes()[planeIndex] = this.planeField.getPlane();
this.updateDisplay();
}
public void setPlane(int planeId)
{
this.planeId = planeId;
this.updateDisplay();
}
}
package com.matt.difinspector.main;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.matt.difinspector.interior.InteriorResource;
import com.matt.difinspector.structures.ItrPaddedPoint;
public class PointEditor extends JFrame
{
private static final long serialVersionUID = -1593084289155588387L;
private InteriorResource interior;
private JPanel panel;
private JPanel dataPanel;
private Point3Field pointField;
private JButton applyButton;
private int pointId;
public PointEditor()
{
this.setTitle("Point Editor");
this.setSize(200, 200);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
this.panel = new JPanel();
this.dataPanel = new JPanel();
this.pointField = new Point3Field("Position: ");
this.applyButton = new JButton("Apply");
this.applyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
PointEditor.this.apply();
}
});
this.dataPanel.setPreferredSize(new Dimension(200, 45));
this.dataPanel.add(this.pointField);
this.setLayout(new FlowLayout());
this.add(this.panel);
this.add(this.dataPanel);
this.add(this.applyButton);
this.setLocationRelativeTo(null);
this.pointId = 0;
}
public void setInterior(InteriorResource interior)
{
this.interior = interior;
//Interior detail = interior.getDetailLevels().get(0);
/*
* this.surfaceSelection.removeAllItems(); for (int i = 0; i < detail.getSurfaces().length; i++) {
* this.surfaceSelection.addItem("Surface: " + i); }
*
* if (this.surfaceSelection.getItemCount() > 0) this.surfaceSelection.setSelectedIndex(0);
*/
updateDisplay();
}
public void updateDisplay()
{
int pointIndex = this.pointId;
ItrPaddedPoint point = this.interior.getDetailLevels().get(0).getPoints()[pointIndex];
this.pointField.setPoint(point.getPoint());
}
private void apply()
{
int pointIndex = this.pointId;
ItrPaddedPoint point = this.interior.getDetailLevels().get(0).getPoints()[pointIndex];
point.setPoint(this.pointField.getPoint());
this.updateDisplay();
}
public void setPoint(int pointId)
{
this.pointId = pointId;
this.updateDisplay();
}
}
......@@ -2,13 +2,18 @@ package com.matt.difinspector.main;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import com.matt.difinspector.interior.Interior;
import com.matt.difinspector.interior.InteriorResource;
import com.matt.difinspector.render.EnumSelectionMode;
import com.matt.difinspector.render.GLRender;
public class Selector extends JFrame
......@@ -20,16 +25,81 @@ public class Selector extends JFrame
private IntField indexField;
private JButton selectButton;
private EnumSelectionMode mode;
private JRadioButton surfacesRadio;
private JRadioButton pointsRadio;
private JRadioButton hullsRadio;
private JRadioButton planesRadio;
public Selector(GLRender render)
{
this.mode = EnumSelectionMode.SURFACES;
this.render = render;
this.setTitle("Select Surface");
this.setSize(320, 65);
this.setSize(320, 120);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
this.panel = new JPanel();
this.surfacesRadio = new JRadioButton("Surfaces", true);
this.surfacesRadio.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e)
{
if (e.getStateChange() == ItemEvent.SELECTED)
{
Selector.this.mode = EnumSelectionMode.SURFACES;
Selector.this.refresh();
}
}
});
this.pointsRadio = new JRadioButton("Points");
this.pointsRadio.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e)
{
if (e.getStateChange() == ItemEvent.SELECTED)
{
Selector.this.mode = EnumSelectionMode.POINTS;
Selector.this.refresh();
}
}
});
this.hullsRadio = new JRadioButton("Hulls");
this.hullsRadio.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e)
{
if (e.getStateChange() == ItemEvent.SELECTED)
{
Selector.this.mode = EnumSelectionMode.HULLS;
Selector.this.refresh();
}
}
});
this.planesRadio = new JRadioButton("Planes");
this.planesRadio.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e)
{
if (e.getStateChange() == ItemEvent.SELECTED)
{
Selector.this.mode = EnumSelectionMode.PLANES;
Selector.this.refresh();
}
}
});
ButtonGroup group = new ButtonGroup();
group.add(this.surfacesRadio);
group.add(this.pointsRadio);
group.add(this.hullsRadio);
group.add(this.planesRadio);
this.indexField = new IntField(0);
this.indexField.addValueChangedListener(new ValueChangedListener() {
......@@ -49,6 +119,10 @@ public class Selector extends JFrame
}
});
this.panel.add(this.surfacesRadio);
this.panel.add(this.pointsRadio);
this.panel.add(this.hullsRadio);
this.panel.add(this.planesRadio);
this.panel.add(this.indexField);
this.panel.add(this.selectButton);
......@@ -59,7 +133,12 @@ public class Selector extends JFrame
@Override
public void setVisible(boolean b)
{
this.render.setHighlight(b);
if (b)
{
this.render.setSelected(mode, this.indexField.getValue());
} else {
this.render.setSelected(EnumSelectionMode.NONE, 0);
}
super.setVisible(b);
}
......@@ -67,7 +146,7 @@ public class Selector extends JFrame
{
int highlightIndex = this.indexField.getValue();
//this.render.setHighlight(true, false, true, highlightIndex);
this.render.setSelected(highlightIndex);
this.render.setSelected(mode, highlightIndex);
}
public void updateRange()
......@@ -75,7 +154,14 @@ public class Selector extends JFrame
InteriorResource res = DifInspector.getInstance().getInterior();
Interior interior = res.getDetailLevels().get(0);
this.indexField.setMax(interior.getSurfaces().length - 1);
if (this.mode == EnumSelectionMode.SURFACES)
this.indexField.setMax(interior.getSurfaces().length - 1);
else if (this.mode == EnumSelectionMode.POINTS)
this.indexField.setMax(interior.getPoints().length - 1);
else if (this.mode == EnumSelectionMode.HULLS)
this.indexField.setMax(interior.getConvexHulls().length - 1);
else if (this.mode == EnumSelectionMode.PLANES)
this.indexField.setMax(interior.getPlanes().length - 1);
}
public void refresh()
......@@ -87,8 +173,13 @@ public class Selector extends JFrame
public void select()
{
int selectedIndex = this.indexField.getValue();
DifInspector.getInstance().editSurface(selectedIndex);
if (this.mode == EnumSelectionMode.SURFACES)
DifInspector.getInstance().editSurface(selectedIndex);
else if (this.mode == EnumSelectionMode.POINTS)
DifInspector.getInstance().editPoint(selectedIndex);
else if (this.mode == EnumSelectionMode.PLANES)
DifInspector.getInstance().editPlane(selectedIndex);
this.setVisible(false);
}
......
......@@ -6,6 +6,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
......@@ -46,6 +47,8 @@ public class SurfaceEditor extends JFrame
private PlaneField planeYField;
private int surfaceId;
private JCheckBox surfaceFlipped;
public SurfaceEditor()
{
......@@ -101,6 +104,8 @@ public class SurfaceEditor extends JFrame
* this.add(this.surfaceSelection);
*/
this.surfaceFlipped = new JCheckBox("No Collision");
this.panel.add(this.textureIndexLabel);
this.texturePanel.setPreferredSize(new Dimension(200, 125));
// this.texturePanel.add(this.decIndex);
......@@ -114,6 +119,7 @@ public class SurfaceEditor extends JFrame
this.setLayout(new FlowLayout());
this.add(this.panel);
this.add(this.texturePanel);
this.add(this.surfaceFlipped);
this.add(this.applyButton);
this.setLocationRelativeTo(null);
......@@ -158,6 +164,8 @@ public class SurfaceEditor extends JFrame
this.planeXField.setPlane(planes.getPlaneX());
this.planeYField.setPlane(planes.getPlaneY());
this.surfaceFlipped.setSelected(surface.isPlaneFlipped());
// DifInspector.getInstance().getRender().setHighlight(true, false, true, surfaceIndex);
/*
* } catch (NumberFormatException e) { e.printStackTrace(); } }
......@@ -215,9 +223,17 @@ public class SurfaceEditor extends JFrame
TexGenPlanes planes = surface.getTexGen();//this.interior.getDetailLevels().get(0).getTexGenEQs().get(surface.getTexGenIndex());
planes.set(planeX, planeY);
if (this.surfaceFlipped.isSelected() != surface.isPlaneFlipped())
{
surface.flip();
}
/*
* } catch (NumberFormatException e) { e.printStackTrace(); } }
*/
this.updateDisplay();
}
public void setCoords()
......
......@@ -34,6 +34,16 @@ public class Camera extends SceneObject
//this.transform.setPosition(this.transform.getPosition().add(new Point3F(1, 0, 0)));
}
if (Input.getKeyHeld(Keyboard.KEY_SPACE))
{
this.move(new Point3F(0, 0, 1));
//this.transform.setPosition(this.transform.getPosition().add(new Point3F(-1, 0, 0)));
} else if (Input.getKeyHeld(Keyboard.KEY_LSHIFT))
{
this.move(new Point3F(0, 0, -1));
//this.transform.setPosition(this.transform.getPosition().add(new Point3F(1, 0, 0)));
}
if (Input.getKeyHeld(Keyboard.KEY_UP))
{
this.transform.setRotation(this.transform.getRotation().add(new Point3F(-1, 0, 0)));
......
package com.matt.difinspector.render;
import com.matt.difinspector.structures.ColorF;
import com.matt.difinspector.structures.Point3F;
import static org.lwjgl.opengl.GL11.*;
import static com.matt.difinspector.render.GLUtil.*;
public class Cube
{
protected Point3F pos;
protected Point3F scale;
protected ColorF color;
public Cube(Point3F pos, Point3F scale, ColorF color)
{
this.pos = pos;
this.scale = scale;
this.color = color;
}
public void render()
{
glColor(this.color);
Point3F min = this.scale.mul(-1).add(this.pos);
Point3F max = this.scale.add(this.pos);
// Top
Point3F p1 = new Point3F(min.getX(), min.getY(), max.getZ());
Point3F p2 = new Point3F(max.getX(), min.getY(), max.getZ());
Point3F p3 = new Point3F(max.getX(), max.getY(), max.getZ());
Point3F p4 = new Point3F(min.getX(), max.getY(), max.getZ());
// Bottom
Point3F p5 = new Point3F(min.getX(), max.getY(), min.getZ());
Point3F p6 = new Point3F(max.getX(), max.getY(), min.getZ());
Point3F p7 = new Point3F(max.getX(), min.getY(), min.getZ());
Point3F p8 = new Point3F(min.getX(), min.getY(), min.getZ());
// Front
Point3F p9 = new Point3F(min.getX(), min.getY(), min.getZ());
Point3F p10 = new Point3F(max.getX(), min.getY(), min.getZ());
Point3F p11 = new Point3F(max.getX(), min.getY(), max.getZ());
Point3F p12 = new Point3F(min.getX(), min.getY(), max.getZ());
// Back
Point3F p13 = new Point3F(min.getX(), max.getY(), max.getZ());
Point3F p14 = new Point3F(max.getX(), max.getY(), max.getZ());
Point3F p15 = new Point3F(max.getX(), max.getY(), min.getZ());
Point3F p16 = new Point3F(min.getX(), max.getY(), min.getZ());
// Left
Point3F p17 = new Point3F(min.getX(), min.getY(), max.getZ());
Point3F p18 = new Point3F(min.getX(), max.getY(), max.getZ());
Point3F p19 = new Point3F(min.getX(), max.getY(), min.getZ());
Point3F p20 = new Point3F(min.getX(), min.getY(), min.getZ());
// Right
Point3F p21 = new Point3F(max.getX(), min.getY(), min.getZ());
Point3F p22 = new Point3F(max.getX(), max.getY(), min.getZ());
Point3F p23 = new Point3F(max.getX(), max.getY(), max.getZ());
Point3F p24 = new Point3F(max.getX(), min.getY(), max.getZ());
glBegin(GL_QUADS);
{
// Top
glVertex(p1);
glVertex(p2);
glVertex(p3);
glVertex(p4);
// Bottom