Browse Source

Stencil build up of navmesh

hull4
MagicBot 1 year ago
parent
commit
e473aa5f08
  1. 29
      src/engine/objects/Building.java

29
src/engine/objects/Building.java

@ -25,6 +25,7 @@ import engine.job.JobScheduler;
import engine.jobs.DoorCloseJob; import engine.jobs.DoorCloseJob;
import engine.jobs.SiegeSpireWithdrawlJob; import engine.jobs.SiegeSpireWithdrawlJob;
import engine.math.Bounds; import engine.math.Bounds;
import engine.math.Vector2f;
import engine.math.Vector3f; import engine.math.Vector3f;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.net.ByteBufferWriter; import engine.net.ByteBufferWriter;
@ -34,8 +35,8 @@ import engine.net.client.msg.UpdateObjectMsg;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.awt.*;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Path2D;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -1536,13 +1537,27 @@ public class Building extends AbstractWorldObject {
} }
public void updateNavMesh() { public void updateNavMesh() {
Polygon area = new Polygon();
for(Colliders collider : this.getBounds().colliders){ // Build up navmesh by stencil of the
area.addPoint((int) collider.startX, (int) collider.startY); // prop's convex hull
area.addPoint((int) collider.endX, (int) collider.endY);
ArrayList<ArrayList<Vector2f>> convexHullList;
convexHullList = BuildingManager._hull_data.get(this.meshUUID);
for (ArrayList<Vector2f> meshEntry : convexHullList) {
Path2D.Float stencil = new Path2D.Float();
for (Vector2f vertex : meshEntry)
stencil.moveTo(vertex.x, vertex.y);
// enclose polygon
stencil.moveTo(meshEntry.get(0).x, meshEntry.get(0).y);
Area stencilArea = new Area(stencil);
this.parentZone.navMesh.subtract(stencilArea);
} }
Area blocked = new Area(area);
this.parentZone.navMesh.subtract(blocked);
//add in all the regions to the navMesh //add in all the regions to the navMesh
for (Regions region : this.getBounds().getRegions()) for (Regions region : this.getBounds().getRegions())

Loading…
Cancel
Save