From 83606046badb09685e59dbc98710b356cb2a32d7 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 17 Jan 2024 20:55:04 -0600 Subject: [PATCH] load mesh data and structure meshes --- src/engine/CollisionEngine/Mesh.java | 18 ++++++++++-------- src/engine/devcmd/cmds/ColliderCmd.java | 5 +++-- src/engine/gameManager/BuildingManager.java | 5 ++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/engine/CollisionEngine/Mesh.java b/src/engine/CollisionEngine/Mesh.java index 94f2f762..b482c143 100644 --- a/src/engine/CollisionEngine/Mesh.java +++ b/src/engine/CollisionEngine/Mesh.java @@ -32,13 +32,13 @@ public class Mesh { } this.triangles = new ArrayList<>(); - double radian = (double)rotation; + int degrees = (int)Math.toDegrees(rotation); for(Triangle tri : CollisionManager.mesh_triangles.get(this.mesh_id)){ Triangle newTri = new Triangle(); - Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(new Vector3f(tri.point1.x,mesh_location.y,tri.point1.y),mesh_location,radian); - Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(new Vector3f(tri.point2.x,mesh_location.y,tri.point2.y),mesh_location,radian); - Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(new Vector3f(tri.point3.x,mesh_location.y,tri.point3.y),mesh_location,radian); + Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(new Vector3f(tri.point1.x,mesh_location.y,tri.point1.y),mesh_location,degrees); + Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(new Vector3f(tri.point2.x,mesh_location.y,tri.point2.y),mesh_location,degrees); + Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(new Vector3f(tri.point3.x,mesh_location.y,tri.point3.y),mesh_location,degrees); newTri.point1 = new Point2D.Float(rotatedPoint1.x,rotatedPoint1.z); newTri.point2 = new Point2D.Float(rotatedPoint2.x,rotatedPoint2.z); @@ -48,15 +48,17 @@ public class Mesh { newTri.sides.add(new Line2D.Float(newTri.point1,newTri.point2)); newTri.sides.add(new Line2D.Float(newTri.point2,newTri.point3)); newTri.sides.add(new Line2D.Float(newTri.point3,newTri.point1)); + + this.triangles.add(newTri); } } public void MakeBounds(float rotation){ - double radian = (double)rotation; - Vector3f rotatedEnd = Vector3f.rotateAroundPoint(new Vector3f(this.mesh_end_point.x,mesh_location.y,this.mesh_end_point.z),mesh_location,radian); - Vector3f rotatedRef = Vector3f.rotateAroundPoint(new Vector3f(this.mesh_ref_point.x,mesh_location.y,this.mesh_ref_point.z),mesh_location,radian); + int degrees = (int)Math.toDegrees(rotation); + Vector3f rotatedEnd = Vector3f.rotateAroundPoint(new Vector3f(this.mesh_end_point.x,mesh_location.y,this.mesh_end_point.z),mesh_location,degrees); + Vector3f rotatedRef = Vector3f.rotateAroundPoint(new Vector3f(this.mesh_ref_point.x,mesh_location.y,this.mesh_ref_point.z),mesh_location,degrees); this.mesh_bounds = new Rectangle2D.Float(); - this.mesh_bounds.setRect(rotatedEnd.x,rotatedEnd.z,Math.abs(rotatedEnd.x) - Math.abs(rotatedRef.x),Math.abs(rotatedEnd.z) - Math.abs(rotatedRef.z)); + this.mesh_bounds.setRect(rotatedEnd.x,rotatedEnd.z,Math.abs(Math.abs(rotatedRef.x) - rotatedEnd.x),Math.abs(rotatedEnd.z) - Math.abs(rotatedRef.z)); } } diff --git a/src/engine/devcmd/cmds/ColliderCmd.java b/src/engine/devcmd/cmds/ColliderCmd.java index 654d99f5..af9e49db 100644 --- a/src/engine/devcmd/cmds/ColliderCmd.java +++ b/src/engine/devcmd/cmds/ColliderCmd.java @@ -33,13 +33,14 @@ public class ColliderCmd extends AbstractDevCmd { output = "Collision Info:" + newline; output += "Total Meshes: " + building.buildingMeshes.size() + newline; for(Mesh mesh : building.buildingMeshes){ - output += "-----------------------------"; + output += "-----------------------------" + newline; output += "Mesh ID: " + mesh.mesh_id + newline; output += "Mesh Location: " + mesh.mesh_location + newline; + output += "Mesh Scale: " + mesh.mesh_scale + newline; output += "Mesh Min/Max: " + mesh.mesh_min_y + "/" + mesh.mesh_max_y + newline; output += "Mesh Triangle Count: " + mesh.triangles.size() + newline; output += "Mesh Rect: " + mesh.mesh_bounds + newline; - output += "-----------------------------"; + output += "-----------------------------" + newline; } throwbackInfo(pc,output); diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 30e68f73..fb9d2ae7 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -981,7 +981,7 @@ public enum BuildingManager { public static void BakeBuildingColliders(Building building){ if(CollisionManager.structure_meshes.containsKey(building.meshUUID) == false) { - Logger.error("No Meshes Found Fro Structure: " + building.meshUUID); + Logger.error("No Meshes Found For Structure: " + building.meshUUID); return; } @@ -990,6 +990,9 @@ public enum BuildingManager { //create the actual meshes from the stored mesh data for(MeshData meshData : CollisionManager.structure_meshes.get(building.meshUUID)){ + if(meshData.meshID == 0) + continue; + Mesh generatedMesh = new Mesh(); generatedMesh.mesh_end_point = new Vector3f(building.loc.x,building.loc.y,building.loc.z).add(meshData.loc).add(meshData.endPoint); generatedMesh.mesh_ref_point = new Vector3f(building.loc.x,building.loc.y,building.loc.z).add(meshData.loc).add(meshData.refPoint);