load mesh data and structure meshes
This commit is contained in:
@@ -29,24 +29,41 @@ public class Mesh {
|
|||||||
public Rectangle2D.Float mesh_bounds;
|
public Rectangle2D.Float mesh_bounds;
|
||||||
public MeshData meshData;
|
public MeshData meshData;
|
||||||
|
|
||||||
public void AdoptTriangles(float rotation){
|
public void update(){
|
||||||
if(CollisionManager.mesh_triangles.containsKey(this.mesh_id) == false){
|
this.BakeTriangles();
|
||||||
Logger.error("Failed To Bake Triangles For Mesh: " + this.mesh_id);
|
this.BakeBoundsRect();
|
||||||
|
}
|
||||||
|
public Vector3f getLocation(){
|
||||||
|
Building parentBuilding = BuildingManager.getBuilding(this.parentUUID);
|
||||||
|
int degrees = (int)Math.toDegrees(parentBuilding.getBounds().getQuaternion().angleY);
|
||||||
|
Vector3f parentLoc = new Vector3f(parentBuilding.loc.x,parentBuilding.loc.y,parentBuilding.loc.z);
|
||||||
|
Vector3f offsetLoc = parentLoc.add(this.meshData.loc);
|
||||||
|
Vector3f rotatedPoint = Vector3f.rotateAroundPoint(offsetLoc,parentLoc,degrees);
|
||||||
|
return rotatedPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BakeTriangles(){
|
||||||
|
|
||||||
|
if(CollisionManager.mesh_triangles.containsKey(this.meshData.meshID) == false){
|
||||||
|
Logger.error("Failed To Bake Triangles For Mesh: " + this.meshData.meshID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Building parentBuilding = BuildingManager.getBuilding(this.parentUUID);
|
||||||
|
int degrees = (int)Math.toDegrees(parentBuilding.getBounds().getQuaternion().angleY);
|
||||||
|
Vector3f parentLoc = new Vector3f(parentBuilding.loc.x,parentBuilding.loc.y,parentBuilding.loc.z);
|
||||||
|
Vector3f offsetLoc = parentLoc.add(this.meshData.loc);
|
||||||
|
|
||||||
Vector3fImmutable parentLoc = BuildingManager.getBuilding(this.parentUUID).loc;
|
for(Triangle tri : CollisionManager.mesh_triangles.get(this.meshData.meshID)) {
|
||||||
Vector3f offsetLoc = new Vector3f(parentLoc.x,parentLoc.y,parentLoc.z).add(this.meshData.loc);
|
|
||||||
|
|
||||||
this.triangles = new ArrayList<>();
|
|
||||||
int degrees = (int)Math.toDegrees(rotation);
|
|
||||||
for(Triangle tri : CollisionManager.mesh_triangles.get(this.mesh_id)){
|
|
||||||
|
|
||||||
Triangle newTri = new Triangle();
|
Triangle newTri = new Triangle();
|
||||||
|
|
||||||
Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(offsetLoc.add(new Vector3f(tri.point1.x,mesh_location.y,tri.point1.y)),offsetLoc,degrees);
|
Vector3f Point1 = offsetLoc.add(new Vector3f(tri.point1.x,offsetLoc.y,tri.point1.y));
|
||||||
Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(offsetLoc.add(new Vector3f(tri.point2.x,mesh_location.y,tri.point2.y)),offsetLoc,degrees);
|
Vector3f Point2 = offsetLoc.add(new Vector3f(tri.point2.x,offsetLoc.y,tri.point2.y));
|
||||||
Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(offsetLoc.add(new Vector3f(tri.point3.x,mesh_location.y,tri.point3.y)),offsetLoc,degrees);
|
Vector3f Point3 = offsetLoc.add(new Vector3f(tri.point3.x,offsetLoc.y,tri.point3.y));
|
||||||
|
|
||||||
|
Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(Point1,offsetLoc,degrees);
|
||||||
|
Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(Point2,offsetLoc,degrees);
|
||||||
|
Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(Point3,offsetLoc,degrees);
|
||||||
|
|
||||||
newTri.point1 = new Point2D.Float(rotatedPoint1.x,rotatedPoint1.z);
|
newTri.point1 = new Point2D.Float(rotatedPoint1.x,rotatedPoint1.z);
|
||||||
newTri.point2 = new Point2D.Float(rotatedPoint2.x,rotatedPoint2.z);
|
newTri.point2 = new Point2D.Float(rotatedPoint2.x,rotatedPoint2.z);
|
||||||
@@ -61,8 +78,7 @@ public class Mesh {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MakeBounds(){
|
public void BakeBoundsRect(){
|
||||||
|
|
||||||
ArrayList<Rectangle2D> rects = new ArrayList<>();
|
ArrayList<Rectangle2D> rects = new ArrayList<>();
|
||||||
for(Triangle tri : this.triangles){
|
for(Triangle tri : this.triangles){
|
||||||
Path2D.Float path = new Path2D.Float();
|
Path2D.Float path = new Path2D.Float();
|
||||||
@@ -77,10 +93,6 @@ public class Mesh {
|
|||||||
for(Rectangle2D rectangle : rects){
|
for(Rectangle2D rectangle : rects){
|
||||||
boundsRect.add(rectangle);
|
boundsRect.add(rectangle);
|
||||||
}
|
}
|
||||||
|
this.mesh_bounds = (Rectangle2D.Float)boundsRect.clone();
|
||||||
this.mesh_bounds = new Rectangle2D.Float();
|
|
||||||
float width = (float)boundsRect.getWidth();
|
|
||||||
float height = (float)boundsRect.getHeight();
|
|
||||||
this.mesh_bounds.setRect(boundsRect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1016,8 +1016,7 @@ public enum BuildingManager {
|
|||||||
generatedMesh.parent_prop_id = meshData.propID;
|
generatedMesh.parent_prop_id = meshData.propID;
|
||||||
generatedMesh.parent_structure_id = building.meshUUID;
|
generatedMesh.parent_structure_id = building.meshUUID;
|
||||||
generatedMesh.parentUUID = building.getObjectUUID();
|
generatedMesh.parentUUID = building.getObjectUUID();
|
||||||
generatedMesh.AdoptTriangles(building.getBounds().getQuaternion().angleY);
|
generatedMesh.update();
|
||||||
//generatedMesh.MakeBounds();
|
|
||||||
building.buildingMeshes.add(generatedMesh);
|
building.buildingMeshes.add(generatedMesh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user