Commit ea8cd675 authored by Anthony Kleine's avatar Anthony Kleine

I used a triangular prism to confirm that the way I'm doing polyListStrings is...

I used a triangular prism to confirm that the way I'm doing polyListStrings is 100% correct. Added convexHullEmitStrings, I think these are being done right but I don't know. Determined the purpose of fanMask.
parent 6fcb39e1
Pipeline #1905107 skipped
......@@ -177,7 +177,9 @@ public class InteriorBuilder
int texGenIndex = texGenEQs.indexOfIndex(face.getTexGen());
short lightCount = 0;
byte surfaceFlags = 16;
int fanMask = 15;
//int fanMask = 15;
// ideally, the number 255 would handle all cases, but that would write as -1 in Java. Can't have it.
int fanMask = 127;
int lightStateInfoStart = 0;
int mapOffsetX = 0;
int mapOffsetY = 0;
......@@ -307,38 +309,83 @@ public class InteriorBuilder
// 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++) {
// the number of POINTS in this triangle minus one
convexHullByteStrings.add((byte)2);
// the point indices
// Torque does the work of adding the hullStart for us. We should be able to just do 0,1
convexHullByteStrings.add((byte)0);
convexHullByteStrings.add((byte)1);
// regardless of whether our DIF supports edges, we need to output numEdges here. Thankfully this is always the same in a triangle.
convexHullByteStrings.add((byte)3);
// I don't know what to do here, other than I know they come in groups of two
convexHullByteStrings.add((byte)0);
convexHullByteStrings.add((byte)1);
convexHullByteStrings.add((byte)0);
convexHullByteStrings.add((byte)2);
convexHullByteStrings.add((byte)0);
convexHullByteStrings.add((byte)3);
// Now we need to write out the number of polys which is 1, but I question whether this is good enough or not
convexHullByteStrings.add((byte)1);
// now we need vertex count, again questioning the legitimacy though
convexHullByteStrings.add((byte)3);
// now we need the planeIndex, which is by far the most straightforward thing here
convexHullByteStrings.add((byte)convexHulls[i].getPlaneStart());
// now we emit the vertices one after the other?
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);
/*
These are the Convex Hull Emit Strings for a Triangular Prism.
convexHullEmitStrings = byte[252]{
6,, 2, 3, 0, 1, 4, 5,,, 8,, 0, 1, 2, 0, 2, 3, 3, 1, 2, 4, 0, 5, 4, 5, 3, 4,,, 3,, 4!, 0, 1, 0, 2, 3,,, 4!, 3, 5, 4, 2, 0,,, 3!, 1, 4, 3, 2,
6,, 2, 3, 0, 1, 4, 5,,, 8,, 0, 1, 2, 0, 2, 3, 3, 1, 3, 4, 2, 4, 1, 5, 4, 5,,, 3,, 4!, 0, 1, 0, 2, 3,,, 3!, 1, 4, 3, 2 ,,, 4!, 4, 5, 1, 3, 4,
6,, 2, 3, 0, 1, 5, 4,,, 8,, 0, 1, 2, 0, 2, 3, 3, 1, 0, 4, 1, 4, 2, 5, 5, 4,,, 3,, 4!, 0, 1, 0, 2, 3,,, 3!, 2, 4, 0, 1 ,,, 4!, 3, 4, 5, 2, 0,
6,, 2, 3, 0, 1, 5, 4,,, 8,, 0, 1, 2, 0, 2, 3, 3, 1, 0, 4, 1, 4, 3, 5, 5, 4,,, 3,, 4!, 0, 1, 0, 2, 3,,, 3!, 2, 4, 0, 1 ,,, 4!, 4, 4, 1, 3, 5,
6,, 0, 1, 4, 3, 5, 2,,, 8,, 0, 1, 1, 2, 0, 2, 1, 3, 3, 4, 2, 4, 0, 5, 5, 4,,, 3,, 3!, 1, 2, 1, 0,,, 4!, 4, 4, 3, 1, 2,,, 4!, 3, 4, 2, 0, 5,
6,, 2, 3, 5, 0, 4, 1,,, 8,, 0, 1, 0, 2, 1, 2, 3, 0, 3, 4, 4, 2, 5, 1, 5, 4,,, 3,, 3!, 2, 2, 0, 1,,, 4!, 3, 2, 4, 3, 0,,, 4!, 4, 2, 1, 5, 4
}
*/
// Convex Hull Emit Strings require we have a 3D shape of some kind, but our triangles are flat.
// This just makes an infinitely flat triangular prism where the rectangles in it are infinitely small, and the same vertices make up the top and bottom of the prism.
// This is taken from the example above, which was for a triangular prism, except with all the planeIndexes replaced with 0, and with the 3rd vertex replaced with 0, the 4th with 1, and the fifth with 2.
// Torque does the work of getting the current Convex Hull and adding HullStart to them, so the vertices need to be referenced from 0 for every Convex Hull.
byte[] convexHullEmitStrings = new byte[]{
// Points
6,
2, 0, 0, 1, 1, 2,
// Edges
8,
0, 1, 2, 0, 2, 0, 0, 1, 2, 1, 0, 2, 1, 2, 0, 1,
// Polygons
3,
// First Vertex/planeIndex/Vertices
4, 0, 1, 0, 2, 0,
// Second Vertex/planeIndex/Vertices
4, 0, 2, 1, 2, 0,
// Third Vertex/planeIndex/Vertices
3, 0, 1, 0, 2,
6,
2, 0, 0, 1, 1, 2,
8,
0, 1, 2, 0, 2, 0, 0, 1, 0, 1, 2, 1, 1, 2, 1, 2,
3,
4, 0, 1, 0, 2, 0,
3, 0, 1, 0, 2,
4, 0, 2, 1, 0, 1,
6,
2, 0, 0, 1, 2, 1,
8,
0, 1, 2, 0, 2, 0, 0, 1, 0, 1, 1, 1, 2, 2, 2, 1,
3,
4, 0, 1, 0, 2, 0,
3, 0, 1, 0, 1,
4, 0, 1, 2, 2, 0,
6,
2, 0, 0, 1, 2, 1,
8,
0, 1, 2, 0, 2, 0, 0, 1, 0, 1, 1, 1, 0, 2, 2, 1,
3,
4, 0, 1, 0, 2, 0,
3, 0, 1, 0, 1,
4, 0, 1, 1, 0, 2,
6,
0, 1, 1, 0, 2, 2,
8,
0, 1, 1, 2, 0, 2, 1, 0, 0, 1, 2, 1, 0, 2, 2, 1,
3,
3, 0, 2, 1, 0,
4, 0, 1, 0, 1, 2,
4, 0, 1, 2, 0, 2,
6,
2, 0, 2, 0, 1, 1,
8,
0, 1, 0, 2, 1, 2, 0, 0, 0, 1, 1, 2, 2, 1, 2, 1,
3,
3, 0, 2, 0, 1,
4, 0, 2, 1, 0, 0,
4, 0, 2, 1, 2, 1
};
result.setConvexHullEmitStrings(convexHullEmitStrings);
// TODO: Hull Indices
System.out.println("Adding Hull Indices");
......@@ -352,17 +399,22 @@ public class InteriorBuilder
// TODO: Hull Plane Indices
System.out.println("Adding Hull Plane Indices");
// just the planeIndexes in some order
// it's worth noting that sometimes this is -32768 in DIF files. Hopefully we can ignore this fact.
short[] hullPlaneIndices = new short[planes.sizeIndices()];
for (short i = 0; i < planes.sizeIndices(); i++)
hullPlaneIndices[i] = i;
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.
// Each surface uses 42 numbers in the convexHullEmitStrings.
System.out.println("Adding Hull Emit String Indices");
int[] hullEmitStringIndices = new int[convexHulls.length];
for (int i = 0; i < convexHulls.length; i++)
{
hullEmitStringIndices[i] = i*15;
int[] hullEmitStringIndices = new int[convexHulls.length*6];
for (int i = 0; i < convexHulls.length; i++) {
for (int j = 0; j < 6; j++)
{
hullEmitStringIndices[i*6+j] = j*42;
// I'm doing this in the hopes that it's possible to just repeat the same Convex Hull Emit Strings over and over
System.out.println("hullEmitStringIndices: " + hullEmitStringIndices[j]);
}
}
result.setHullEmitStringIndices(hullEmitStringIndices);
......@@ -388,6 +440,7 @@ public class InteriorBuilder
System.out.println("Adding Poly List Strings");
List<Byte> polyByteStrings = new ArrayList<Byte>();
for (int i = 0; i < convexHulls.length; i++) {
// 1, 1, 0, 3, 1, 1, 1, 1, 3, 1, 0, 0, 0, 0, 1, 0, 2
// 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)
......@@ -422,7 +475,7 @@ public class InteriorBuilder
polyByteStrings.add((byte)mesh.getIndices()[1+(i*3)]);
polyByteStrings.add((byte)0);
polyByteStrings.add((byte)mesh.getIndices()[2+(i*3)]);
convexHulls[i].setPolyListStringStart(i*19);
convexHulls[i].setPolyListStringStart(i*17);
}
byte[] polyListStrings = new byte[polyByteStrings.size()];
for (int i = 0; i < polyByteStrings.size(); i++) {
......@@ -479,7 +532,7 @@ public class InteriorBuilder
short oppositeIndex = (short)(surfaces.sizeIndices() - i);
int backIndex = i + 1;
if (backIndex == surfaces.sizeIndices())
backIndex = -16384;
backIndex = -16384 + i;
bspNodes[i] = new BSPNode(oppositeIndex, -32768, backIndex);
}
result.setBspNodes(bspNodes);
......
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