mixins: add method for grabbing game object polys.
This commit is contained in:
@@ -24,8 +24,8 @@
|
||||
*/
|
||||
package net.runelite.api;
|
||||
|
||||
import net.runelite.api.coords.Angle;
|
||||
import java.awt.Polygon;
|
||||
import net.runelite.api.coords.Angle;
|
||||
|
||||
/**
|
||||
* Represents a game object.
|
||||
@@ -61,6 +61,13 @@ public interface GameObject extends TileObject
|
||||
*/
|
||||
Polygon getConvexHull();
|
||||
|
||||
/**
|
||||
* Gets the polygons that make up the game object model.
|
||||
*
|
||||
* @return the model polygons
|
||||
*/
|
||||
Polygon[] getPolygons();
|
||||
|
||||
/**
|
||||
* Gets the orientation of the object.
|
||||
*
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
package net.runelite.client.plugins.devtools;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
@@ -46,9 +46,7 @@ import net.runelite.api.DynamicObject;
|
||||
import net.runelite.api.Entity;
|
||||
import net.runelite.api.GameObject;
|
||||
import net.runelite.api.GraphicsObject;
|
||||
import net.runelite.api.TileItem;
|
||||
import net.runelite.api.GroundObject;
|
||||
import net.runelite.api.TileItemPile;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.NPCDefinition;
|
||||
import net.runelite.api.Node;
|
||||
@@ -58,6 +56,8 @@ import net.runelite.api.Point;
|
||||
import net.runelite.api.Projectile;
|
||||
import net.runelite.api.Scene;
|
||||
import net.runelite.api.Tile;
|
||||
import net.runelite.api.TileItem;
|
||||
import net.runelite.api.TileItemPile;
|
||||
import net.runelite.api.WallObject;
|
||||
import net.runelite.api.coords.LocalPoint;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
@@ -243,6 +243,7 @@ class DevToolsOverlay extends Overlay
|
||||
if (plugin.getGameObjects().isActive())
|
||||
{
|
||||
renderGameObjects(graphics, tile, player);
|
||||
|
||||
}
|
||||
|
||||
if (plugin.getWalls().isActive())
|
||||
@@ -328,6 +329,8 @@ class DevToolsOverlay extends Overlay
|
||||
{
|
||||
graphics.drawPolygon(p);
|
||||
}
|
||||
// This is incredibly taxing to run, only uncomment if you know what you're doing.
|
||||
/*renderGameObjectWireframe(graphics, gameObject, Color.CYAN);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,6 +551,23 @@ class DevToolsOverlay extends Overlay
|
||||
graphics.drawString(text, textX, textY);
|
||||
}
|
||||
|
||||
private void renderGameObjectWireframe(Graphics2D graphics, GameObject gameObject, Color color)
|
||||
{
|
||||
Polygon[] polys = gameObject.getPolygons();
|
||||
|
||||
if (polys == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
graphics.setColor(color);
|
||||
|
||||
for (Polygon p : polys)
|
||||
{
|
||||
graphics.drawPolygon(p);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderPlayerWireframe(Graphics2D graphics, Player player, Color color)
|
||||
{
|
||||
Polygon[] polys = player.getPolygons();
|
||||
|
||||
@@ -24,15 +24,20 @@
|
||||
*/
|
||||
package net.runelite.mixins;
|
||||
|
||||
import java.awt.Polygon;
|
||||
import java.awt.geom.Area;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.runelite.api.Model;
|
||||
import net.runelite.api.Perspective;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.coords.Angle;
|
||||
import net.runelite.api.coords.LocalPoint;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.geom.Area;
|
||||
import net.runelite.api.mixins.Inject;
|
||||
import net.runelite.api.mixins.Mixin;
|
||||
import net.runelite.api.mixins.Shadow;
|
||||
import net.runelite.api.model.Triangle;
|
||||
import net.runelite.api.model.Vertex;
|
||||
import net.runelite.rs.api.RSClient;
|
||||
import net.runelite.rs.api.RSEntity;
|
||||
import net.runelite.rs.api.RSGameObject;
|
||||
@@ -85,6 +90,89 @@ public abstract class RSGameObjectMixin implements RSGameObject
|
||||
return Perspective.getClickbox(client, getModel(), getRsOrientation(), getLocalLocation());
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public Polygon[] getPolygons()
|
||||
{
|
||||
Model model = getModel();
|
||||
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int localX = getX();
|
||||
int localY = getY();
|
||||
|
||||
int orientation = getRsOrientation();
|
||||
|
||||
final int tileHeight = Perspective.getTileHeight(client, new LocalPoint(localX, localY), client.getPlane());
|
||||
|
||||
List<Triangle> triangles = model.getTriangles();
|
||||
|
||||
triangles = rotate(triangles, orientation);
|
||||
|
||||
List<Polygon> polys = new ArrayList<Polygon>();
|
||||
for (Triangle triangle : triangles)
|
||||
{
|
||||
Vertex vx = triangle.getA();
|
||||
Vertex vy = triangle.getB();
|
||||
Vertex vz = triangle.getC();
|
||||
|
||||
Point x = Perspective.localToCanvas(client,
|
||||
localX - vx.getX(),
|
||||
localY - vx.getZ(),
|
||||
tileHeight + vx.getY());
|
||||
|
||||
Point y = Perspective.localToCanvas(client,
|
||||
localX - vy.getX(),
|
||||
localY - vy.getZ(),
|
||||
tileHeight + vy.getY());
|
||||
|
||||
Point z = Perspective.localToCanvas(client,
|
||||
localX - vz.getX(),
|
||||
localY - vz.getZ(),
|
||||
tileHeight + vz.getY());
|
||||
|
||||
if (x == null || y == null || z == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int[] xx =
|
||||
{
|
||||
x.getX(), y.getX(), z.getX()
|
||||
};
|
||||
int[] yy =
|
||||
{
|
||||
x.getY(), y.getY(), z.getY()
|
||||
};
|
||||
polys.add(new Polygon(xx, yy, 3));
|
||||
}
|
||||
|
||||
return polys.toArray(new Polygon[0]);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private List<Triangle> rotate(List<Triangle> triangles, int orientation)
|
||||
{
|
||||
List<Triangle> rotatedTriangles = new ArrayList<Triangle>();
|
||||
for (Triangle triangle : triangles)
|
||||
{
|
||||
Vertex a = triangle.getA();
|
||||
Vertex b = triangle.getB();
|
||||
Vertex c = triangle.getC();
|
||||
|
||||
Triangle rotatedTriangle = new Triangle(
|
||||
a.rotate(orientation),
|
||||
b.rotate(orientation),
|
||||
c.rotate(orientation)
|
||||
);
|
||||
rotatedTriangles.add(rotatedTriangle);
|
||||
}
|
||||
return rotatedTriangles;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public Polygon getConvexHull()
|
||||
|
||||
Reference in New Issue
Block a user