Browse Source

load mesh data and structure meshes

server-collision
FatBoy-DOTC 10 months ago
parent
commit
d6ad0ecbd3
  1. 50
      src/engine/CollisionEngine/Mesh.java
  2. 3
      src/engine/gameManager/BuildingManager.java

50
src/engine/CollisionEngine/Mesh.java

@ -29,24 +29,41 @@ public class Mesh { @@ -29,24 +29,41 @@ public class Mesh {
public Rectangle2D.Float mesh_bounds;
public MeshData meshData;
public void AdoptTriangles(float rotation){
if(CollisionManager.mesh_triangles.containsKey(this.mesh_id) == false){
Logger.error("Failed To Bake Triangles For Mesh: " + this.mesh_id);
public void update(){
this.BakeTriangles();
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;
}
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;
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)){
for(Triangle tri : CollisionManager.mesh_triangles.get(this.meshData.meshID)) {
Triangle newTri = new Triangle();
Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(offsetLoc.add(new Vector3f(tri.point1.x,mesh_location.y,tri.point1.y)),offsetLoc,degrees);
Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(offsetLoc.add(new Vector3f(tri.point2.x,mesh_location.y,tri.point2.y)),offsetLoc,degrees);
Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(offsetLoc.add(new Vector3f(tri.point3.x,mesh_location.y,tri.point3.y)),offsetLoc,degrees);
Vector3f Point1 = offsetLoc.add(new Vector3f(tri.point1.x,offsetLoc.y,tri.point1.y));
Vector3f Point2 = offsetLoc.add(new Vector3f(tri.point2.x,offsetLoc.y,tri.point2.y));
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.point2 = new Point2D.Float(rotatedPoint2.x,rotatedPoint2.z);
@ -61,8 +78,7 @@ public class Mesh { @@ -61,8 +78,7 @@ public class Mesh {
}
}
public void MakeBounds(){
public void BakeBoundsRect(){
ArrayList<Rectangle2D> rects = new ArrayList<>();
for(Triangle tri : this.triangles){
Path2D.Float path = new Path2D.Float();
@ -77,10 +93,6 @@ public class Mesh { @@ -77,10 +93,6 @@ public class Mesh {
for(Rectangle2D rectangle : rects){
boundsRect.add(rectangle);
}
this.mesh_bounds = new Rectangle2D.Float();
float width = (float)boundsRect.getWidth();
float height = (float)boundsRect.getHeight();
this.mesh_bounds.setRect(boundsRect);
this.mesh_bounds = (Rectangle2D.Float)boundsRect.clone();
}
}

3
src/engine/gameManager/BuildingManager.java

@ -1016,8 +1016,7 @@ public enum BuildingManager { @@ -1016,8 +1016,7 @@ public enum BuildingManager {
generatedMesh.parent_prop_id = meshData.propID;
generatedMesh.parent_structure_id = building.meshUUID;
generatedMesh.parentUUID = building.getObjectUUID();
generatedMesh.AdoptTriangles(building.getBounds().getQuaternion().angleY);
//generatedMesh.MakeBounds();
generatedMesh.update();
building.buildingMeshes.add(generatedMesh);
}
}

Loading…
Cancel
Save