Commit 371448e6 authored by Human Gamer's avatar Human Gamer

Automatically Scales imported OBJ files to be 100 times smaller

parent 2beb98b4
Pipeline #1861105 skipped
......@@ -1039,6 +1039,11 @@ public class Interior
this.surfaces[i].setTexGenIndex(this.texGenEQs.indexOf(texGen));
}
Point3F min = new Point3F((float)1e10, (float)1e10, (float)1e10);
Point3F max = new Point3F((float)-1e10, (float)-1e10, (float)-1e10);
this.boundingBox = new Box3F(min, max);
if (this.convexHulls == null)
this.convexHulls = new ConvexHull[0];
for (int i = 0; i < this.convexHulls.length; i++)
......@@ -1061,12 +1066,66 @@ public class Interior
PlaneF plane = this.planes[planeIndex];
if (i == 272)
/*if (i == 272)
{
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();
for (int k = windingStart; k < windingStart + windingCount; k++)
{
Point3F point = this.points[this.windings[k]].getPoint();
minHull.setMin(point);
maxHull.setMax(point);
}
/*if (plane.getX() > 0)
{
maxHull.setMaxX(plane.getD());
} else if (plane.getX() < 0)
{
minHull.setMinX(plane.getD());
}
if (plane.getX() > 0 && plane.getD() * -1 > hull.getMaxX())
if (plane.getY() > 0)
{
maxHull.setMaxY(plane.getD());
} else if (plane.getY() < 0)
{
minHull.setMinY(plane.getD());
}
if (plane.getZ() > 0)
{
maxHull.setMaxZ(plane.getD());
} else if (plane.getZ() < 0)
{
minHull.setMinZ(plane.getD());
}*/
//minHull = minHull.sub(4);
//maxHull = maxHull.add(4);
//minHull = new Point3F(-1000, -1000, -1000);
//maxHull = new Point3F(1000, 1000, 1000);
//minHull = new Point3F(0, 0, 0);
//maxHull = new Point3F(0, 0, 0);
hull.setMinX(minHull.getX());
hull.setMinY(minHull.getY());
hull.setMinZ(minHull.getZ());
hull.setMaxX(maxHull.getX());
hull.setMaxY(maxHull.getY());
hull.setMaxZ(maxHull.getZ());
/*if (plane.getX() > 0 && plane.getD() * -1 > hull.getMaxX())
{
hull.setMaxX(plane.getD() * -1);
} else if (plane.getX() < 0 && plane.getD() < hull.getMinX())
......@@ -1088,10 +1147,10 @@ public class Interior
} else if (plane.getZ() < 0 && plane.getD() < hull.getMinZ())
{
hull.setMinZ(plane.getD());
}
}*/
}
if (hull.getMaxX() > this.boundingBox.getMax().getX())
/*if (hull.getMaxX() > this.boundingBox.getMax().getX())
{
this.boundingBox.getMax().setX(hull.getMaxX());
} else if (hull.getMinX() < this.boundingBox.getMin().getX())
......@@ -1113,19 +1172,25 @@ public class Interior
} else if (hull.getMinZ() < this.boundingBox.getMin().getZ())
{
this.boundingBox.getMin().setZ(hull.getMinZ());
}
}*/
this.boundingBox.getMin().setMin(new Point3F(hull.getMinX(), hull.getMinY(), hull.getMinZ()));
this.boundingBox.getMax().setMax(new Point3F(hull.getMaxX(), hull.getMaxY(), hull.getMaxZ()));
if (this.boundingSphere == null)
this.boundingSphere = new SphereF(new Point3F(), 0);
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 max1 = this.boundingBox.getMax().absMax();
float min1 = this.boundingBox.getMin().absMax();
float diamater = Math.max(max, min);
float diamater = Math.max(max1, min1);
this.boundingSphere.setRadius(diamater);
}
//this.boundingBox = new Box3F(new Point3F(-200.00002f, -152.00002f, -33.00009f), new Point3F(232.0f, 168.0f, 14.0f));
//this.boundingSphere.setCenter(new Point3F(15.999992f, 7.9999924f, -9.500046f));
//this.boundingSphere.setRadius(269.83005f);
}
public void readPlaneVector(ReverseDataInputStream dis) throws IOException
......
......@@ -94,6 +94,17 @@ public class OBJModel
}
this.indices = newIndices;
for (int i = 0; i < this.positions.size(); i++)
{
Point3F pos = this.positions.get(i);
pos = pos.mul(0.01f);
//pos = pos.rotate(0, 1, 0, 90);
//pos = pos.rotate(0, 0, 1, 180);
this.positions.set(i, pos);
}
}
private OBJIndex parseOBJIndex(String token, String texture)
......
......@@ -150,6 +150,89 @@ public class Point3F
return new Point3F(this.x / r, this.y / r, this.z / r);
}
public void setMinX(float r)
{
this.x = (r < this.x) ? r : this.x;
}
public void setMinY(float r)
{
this.y = (r < this.y) ? r : this.y;
}
public void setMinZ(float r)
{
this.z = (r < this.z) ? r : this.z;
}
public void setMin(Point3F r)
{
this.x = (r.x < this.x) ? r.x : this.x;
this.y = (r.y < this.y) ? r.y : this.y;
this.z = (r.z < this.z) ? r.z : this.z;
}
public void setMaxX(float r)
{
this.x = (r > this.x) ? r : this.x;
}
public void setMaxY(float r)
{
this.y = (r > this.y) ? r : this.y;
}
public void setMaxZ(float r)
{
this.z = (r > this.z) ? r : this.z;
}
public void setMax(Point3F r)
{
this.x = (r.x > this.x) ? r.x : this.x;
this.y = (r.y > this.y) ? r.y : this.y;
this.z = (r.z > this.z) ? r.z : this.z;
}
/*public Point3F rotate(float cx, float cy, float cz, float angle)
{
float sin = (float) Math.sin(angle);
float cos = (float) Math.cos(angle);
float tan = (float) Math.tan(angle);
*/
/*float x = this.x - cx;
float y = this.y - cy;
float z = this.z - cz;
x = this.x * cos - this.y * sin;
y = this.x * sin + this.y * cos;
z = this.z; // TODO: Z ROT*/
/*
if (cx != 0)
{
float x = this.x;
float y = this.y * cos - this.z * sin;
float z = this.y * sin + this.z * cos;
return new Point3F(x, y, z);
} else if (cy != 0)
{
float x = this.x * cos + this.z * sin;
float y = this.y;
float z = this.x * -sin + this.z * cos;
return new Point3F(x, y, z);
} else if (cz != 0)
{
float x = this.x * cos - this.y * sin;
float y = this.x * sin + this.y * cos;
float z = this.z;
return new Point3F(x, y, z);
}
return null;
}*/
public String getPointString()
{
return this.x + " " + this.y + " " + this.z;
......
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