Browse Source

load mesh data and structure meshes

server-collision
FatBoy-DOTC 12 months ago
parent
commit
68920f150d
  1. 16
      src/engine/CollisionEngine/CollisionManager.java
  2. 16
      src/engine/CollisionEngine/Mesh.java
  3. 3
      src/engine/db/handlers/dbBuildingHandler.java
  4. 2
      src/engine/devcmd/cmds/InfoCmd.java
  5. 7
      src/engine/devcmd/cmds/RegionCmd.java
  6. 78
      src/engine/gameManager/BuildingManager.java
  7. 2
      src/engine/objects/Building.java

16
src/engine/CollisionEngine/CollisionManager.java

@ -8,20 +8,10 @@ import java.awt.geom.Line2D;
public class CollisionManager { public class CollisionManager {
public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight, float charY){ public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight, float charY){
Rectangle.Float boundsRect = new Rectangle.Float(); for (Mesh mesh : building.buildingMeshes)
Vector3f topLeft = new Vector3f(building.loc.x - building.getBounds().getHalfExtents().x,building.loc.y,building.loc.z - building.getBounds().getHalfExtents().y); if(mesh.MeshCollides(travelLine,charHeight,charY))
boundsRect.setRect(topLeft.x, topLeft.z, building.getBounds().getHalfExtents().x * 2,building.getBounds().getHalfExtents().y * 2);
if(travelLine.intersects(boundsRect)){
//collided with building
for(Triangle tri : building.buildingTriangles) {
if (tri.collides(travelLine)) {
//ChatManager.chatSystemInfo(pc, "Collision Detected");
//MovementManager.movement(msg, pc);
return true; return true;
}
}
}
return false; return false;
} }
} }

16
src/engine/CollisionEngine/Mesh.java

@ -23,15 +23,13 @@ public class Mesh {
public boolean MeshCollides(Line2D line, float charHeight, float charY){ public boolean MeshCollides(Line2D line, float charHeight, float charY){
//check if movement path intersects this mesh //check if movement path intersects this mesh
//if(!this.BoundsCollides(line)) if(!this.BoundsCollides(line))
// return false; return false;
//boolean feetcollides = (charY + charHeight) < this.minY;
//boolean headcollides = charY > this.maxY; //check to see if character is under or over the mesh
//check to see if the mesh collides between the characters feet and head locations if((charY + charHeight) < this.minY || charY > this.maxY)
//if(feetcollides && headcollides){ return false;
// return false;
//}
//check if any triangles intersect the movement path //check if any triangles intersect the movement path
for(Triangle tri : triangles) for(Triangle tri : triangles)

3
src/engine/db/handlers/dbBuildingHandler.java

@ -928,7 +928,6 @@ public class dbBuildingHandler extends dbHandlerBase {
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public void LOAD_MESH_BOUNDING_BOXES() { public void LOAD_MESH_BOUNDING_BOXES() {
@ -948,7 +947,7 @@ public class dbBuildingHandler extends dbHandlerBase {
float refZ = Float.parseFloat(rs.getString("ref").split(";")[1]); float refZ = Float.parseFloat(rs.getString("ref").split(";")[1]);
Vector2f topLeft = new Vector2f(centerX - refX,centerZ + refZ); Vector2f topLeft = new Vector2f(refX,refZ);
float width = Math.abs(endX-refX); float width = Math.abs(endX-refX);
float height = Math.abs(endZ-refZ); float height = Math.abs(endZ-refZ);
Rectangle2D boundRect = new Rectangle2D.Float(); Rectangle2D boundRect = new Rectangle2D.Float();

2
src/engine/devcmd/cmds/InfoCmd.java

@ -244,7 +244,7 @@ public class InfoCmd extends AbstractDevCmd {
for (Regions regions : targetBuilding.getBounds().getRegions()) { for (Regions regions : targetBuilding.getBounds().getRegions()) {
//TODO ADD REGION INFO //TODO ADD REGION INFO
} }
output += "Triangle Count: " + targetBuilding.buildingTriangles.size(); output += "Mesh Count: " + targetBuilding.buildingMeshes.size();
break; break;
case PlayerCharacter: case PlayerCharacter:
output += newline; output += newline;

7
src/engine/devcmd/cmds/RegionCmd.java

@ -47,6 +47,13 @@ public class RegionCmd extends AbstractDevCmd {
output += "is Outside: " + region.isOutside(); output += "is Outside: " + region.isOutside();
this.throwbackInfo(pc, output); this.throwbackInfo(pc, output);
} }
if(building != null){
for (Mesh mesh : building.buildingMeshes){
if(mesh.boundsRect.contains(pc.loc.x,pc.loc.z))
this.throwbackInfo(pc, "Inside A Mesh's Bounds");
}
}
} }
@Override @Override

78
src/engine/gameManager/BuildingManager.java

@ -982,47 +982,51 @@ public enum BuildingManager {
if (building == null) if (building == null)
return; return;
building.buildingTriangles = new ArrayList<>(); building.buildingMeshes = new ArrayList<>();
float rotation = building.getRot().getRotation(); float rotation = building.getRot().getRotation();
Vector3f buildingLoc = new Vector3f(building.loc.x, building.loc.y, building.loc.z); Vector3f buildingLoc = new Vector3f(building.loc.x, building.loc.y, building.loc.z);
if (!mesh_triangle_points.containsKey(building.meshUUID)) if (!mesh_triangle_points.containsKey(building.meshUUID))
return; //no data for this prop ID return; //no data for this prop ID
//ArrayList<Integer> meshes = prop_meshes.get(building.meshUUID); ArrayList<Integer> meshes = prop_meshes.get(building.meshUUID);
//for (int mesh : meshes) { for (int mesh : meshes) {
//if (!mesh_heights.containsKey(mesh) || !mesh_triangle_points.containsKey(mesh)) if (!mesh_heights.containsKey(mesh) || !mesh_triangle_points.containsKey(mesh))
//return; //no data for this mesh return; //no data for this mesh
//Mesh generatedMesh = new Mesh(); Mesh generatedMesh = new Mesh();
//generatedMesh.maxY = building.loc.y + mesh_heights.get(mesh).x; generatedMesh.maxY = building.loc.y + mesh_heights.get(mesh).x;
//generatedMesh.minY = building.loc.y + mesh_heights.get(mesh).y; generatedMesh.minY = building.loc.y + mesh_heights.get(mesh).y;
ArrayList<ArrayList<Vector3f>> triPoints = mesh_triangle_points.get(building.meshUUID); ArrayList<ArrayList<Vector3f>> triPoints = mesh_triangle_points.get(building.meshUUID);
//if (mesh_bounding_boxes.containsKey(mesh)) { if (mesh_bounding_boxes.containsKey(mesh)) {
//Rectangle2D boundingBox = mesh_bounding_boxes.get(mesh); Rectangle2D boundingBox = mesh_bounding_boxes.get(mesh);
//Bounds buildingBounds = building.getBounds(); float halfX = (float) boundingBox.getWidth() * 0.5f;
//float halfX = (float) boundingBox.getWidth() * 0.5f; float halfZ = (float) boundingBox.getHeight() * 0.5f;
//float halfZ = (float)boundingBox.getHeight() * 0.5f; Vector3f bottomRight = new Vector3f(building.loc.x + halfX, building.loc.y, building.loc.z + halfZ);
//Vector3f bottomRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z + halfZ); Vector3f topLeft = new Vector3f(building.loc.x - halfX, building.loc.y, building.loc.z - halfZ);
//Vector3f topLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z - halfZ); Vector3f topRight = new Vector3f(building.loc.x + halfX, building.loc.y, building.loc.z - halfZ);
//Vector3f topRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z - halfZ); Vector3f bottomLeft = new Vector3f(building.loc.x - halfX, building.loc.y, building.loc.z + halfZ);
//Vector3f bottomLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z + halfZ);
topLeft.x *= -1;
//generatedMesh.BoundingLines = new ArrayList<>(); bottomLeft.x *= -1;
//Point2D.Float p1 = new Point2D.Float(topLeft.x, topLeft.z); topRight.x *= -1;
//Point2D.Float p2 = new Point2D.Float(topRight.x, topRight.z); bottomRight.x *= -1;
//Point2D.Float p3 = new Point2D.Float(bottomRight.x, bottomRight.z);
//Point2D.Float p4 = new Point2D.Float(bottomLeft.x, bottomLeft.z); generatedMesh.BoundingLines = new ArrayList<>();
//float rectWidth = topLeft.distance(topRight); Point2D.Float p1 = new Point2D.Float(topLeft.x, topLeft.z);
//float rectHeight = topLeft.distance(bottomLeft); Point2D.Float p2 = new Point2D.Float(topRight.x, topRight.z);
//boundingBox.setRect(p1.x,p1.y,rectWidth, rectHeight); Point2D.Float p3 = new Point2D.Float(bottomRight.x, bottomRight.z);
//generatedMesh.BoundingLines.add(new Line2D.Float(p1, p2)); Point2D.Float p4 = new Point2D.Float(bottomLeft.x, bottomLeft.z);
//generatedMesh.BoundingLines.add(new Line2D.Float(p2, p3)); float rectWidth = topLeft.distance(topRight);
//generatedMesh.BoundingLines.add(new Line2D.Float(p3, p4)); float rectHeight = topLeft.distance(bottomLeft);
//generatedMesh.BoundingLines.add(new Line2D.Float(p4, p1)); boundingBox.setRect(p1.x, p1.y, rectWidth, rectHeight);
//generatedMesh.boundsRect = boundingBox; generatedMesh.BoundingLines.add(new Line2D.Float(p1, p2));
//} generatedMesh.BoundingLines.add(new Line2D.Float(p2, p3));
//generatedMesh.triangles = new ArrayList<>(); generatedMesh.BoundingLines.add(new Line2D.Float(p3, p4));
generatedMesh.BoundingLines.add(new Line2D.Float(p4, p1));
generatedMesh.boundsRect = boundingBox;
}
generatedMesh.triangles = new ArrayList<>();
for (ArrayList<Vector3f> pointList : triPoints) { for (ArrayList<Vector3f> pointList : triPoints) {
ArrayList<Vector3f> rotatedPoints = new ArrayList<>(); ArrayList<Vector3f> rotatedPoints = new ArrayList<>();
@ -1040,11 +1044,11 @@ public enum BuildingManager {
tri.sides.add(new Line2D.Float(p1, p2)); tri.sides.add(new Line2D.Float(p1, p2));
tri.sides.add(new Line2D.Float(p2, p3)); tri.sides.add(new Line2D.Float(p2, p3));
tri.sides.add(new Line2D.Float(p3, p1)); tri.sides.add(new Line2D.Float(p3, p1));
//generatedMesh.triangles.add(tri); generatedMesh.triangles.add(tri);
building.buildingTriangles.add(tri);
}
building.buildingMeshes.add(generatedMesh);
} }
//building.buildingMeshes.add(generatedMesh);
//}
} }
catch(Exception e){ catch(Exception e){
Logger.info("Failed To Bake Building Mesh Data For Structure: " + building.meshUUID); Logger.info("Failed To Bake Building Mesh Data For Structure: " + building.meshUUID);

2
src/engine/objects/Building.java

@ -101,7 +101,7 @@ public class Building extends AbstractWorldObject {
private ConcurrentHashMap<Integer, Condemned> condemned; private ConcurrentHashMap<Integer, Condemned> condemned;
private ArrayList<Building> children = null; private ArrayList<Building> children = null;
public ArrayList<Triangle> buildingTriangles; public ArrayList<Mesh> buildingMeshes;
/** /**
* ResultSet Constructor * ResultSet Constructor

Loading…
Cancel
Save