Draw hull on decorative objects too
This commit is contained in:
@@ -24,6 +24,8 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.api;
|
package net.runelite.api;
|
||||||
|
|
||||||
|
import java.awt.Polygon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorative object, such as objects on walls
|
* Decorative object, such as objects on walls
|
||||||
*
|
*
|
||||||
@@ -56,4 +58,36 @@ public class DecorativeObject extends TileObject
|
|||||||
{
|
{
|
||||||
return decorativeObject.getY();
|
return decorativeObject.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Renderable getRenderable()
|
||||||
|
{
|
||||||
|
return Renderable.of(decorativeObject.getRenderable());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Polygon getConvexHull()
|
||||||
|
{
|
||||||
|
Renderable renderable = getRenderable();
|
||||||
|
if (renderable == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Model model;
|
||||||
|
|
||||||
|
if (renderable instanceof Model)
|
||||||
|
{
|
||||||
|
model = (Model) renderable;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
model = renderable.getModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getConvexHull(model, decorativeObject.getOrientation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,6 @@
|
|||||||
package net.runelite.api;
|
package net.runelite.api;
|
||||||
|
|
||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import net.runelite.api.model.Jarvis;
|
|
||||||
import net.runelite.api.model.Vertex;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -91,52 +87,6 @@ public class GameObject extends TileObject
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int localX = gameObject.getX();
|
return getConvexHull(model, gameObject.getOrientation());
|
||||||
int localY = gameObject.getY();
|
|
||||||
|
|
||||||
// models are orientated north (1024) and there are 2048 angles total
|
|
||||||
int orientation = (gameObject.getOrientation() + 1024) % 2048;
|
|
||||||
|
|
||||||
List<Vertex> verticies = model.getVertices();
|
|
||||||
|
|
||||||
if (orientation != 0)
|
|
||||||
{
|
|
||||||
// rotate verticies
|
|
||||||
for (int i = 0; i < verticies.size(); ++i)
|
|
||||||
{
|
|
||||||
Vertex v = verticies.get(i);
|
|
||||||
verticies.set(i, v.rotate(orientation));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Point> points = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Vertex v : verticies)
|
|
||||||
{
|
|
||||||
// Compute canvas location of vertex
|
|
||||||
Point p = Perspective.worldToCanvas(client,
|
|
||||||
localX - v.getX(),
|
|
||||||
localY - v.getZ(),
|
|
||||||
-v.getY());
|
|
||||||
if (p != null)
|
|
||||||
{
|
|
||||||
points.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run Jarvis march algorithm
|
|
||||||
points = Jarvis.convexHull(points);
|
|
||||||
if (points == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert to a polygon
|
|
||||||
Polygon p = new Polygon();
|
|
||||||
for (Point point : points)
|
|
||||||
{
|
|
||||||
p.addPoint(point.getX(), point.getY());
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ package net.runelite.api;
|
|||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import net.runelite.api.model.Jarvis;
|
||||||
|
import net.runelite.api.model.Vertex;
|
||||||
|
|
||||||
public abstract class TileObject
|
public abstract class TileObject
|
||||||
{
|
{
|
||||||
@@ -79,4 +83,56 @@ public abstract class TileObject
|
|||||||
{
|
{
|
||||||
return Perspective.worldToMiniMap(client, getLocalX(), getLocalY());
|
return Perspective.worldToMiniMap(client, getLocalX(), getLocalY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Polygon getConvexHull(Model model, int orientation)
|
||||||
|
{
|
||||||
|
int localX = getLocalX();
|
||||||
|
int localY = getLocalY();
|
||||||
|
|
||||||
|
// models are orientated north (1024) and there are 2048 angles total
|
||||||
|
orientation = (orientation + 1024) % 2048;
|
||||||
|
|
||||||
|
List<Vertex> verticies = model.getVertices();
|
||||||
|
|
||||||
|
if (orientation != 0)
|
||||||
|
{
|
||||||
|
// rotate verticies
|
||||||
|
for (int i = 0; i < verticies.size(); ++i)
|
||||||
|
{
|
||||||
|
Vertex v = verticies.get(i);
|
||||||
|
verticies.set(i, v.rotate(orientation));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Point> points = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Vertex v : verticies)
|
||||||
|
{
|
||||||
|
// Compute canvas location of vertex
|
||||||
|
Point p = Perspective.worldToCanvas(client,
|
||||||
|
localX - v.getX(),
|
||||||
|
localY - v.getZ(),
|
||||||
|
-v.getY());
|
||||||
|
if (p != null)
|
||||||
|
{
|
||||||
|
points.add(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run Jarvis march algorithm
|
||||||
|
points = Jarvis.convexHull(points);
|
||||||
|
if (points == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to a polygon
|
||||||
|
Polygon p = new Polygon();
|
||||||
|
for (Point point : points)
|
||||||
|
{
|
||||||
|
p.addPoint(point.getX(), point.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -298,6 +298,12 @@ public class DevToolsOverlay extends Overlay
|
|||||||
{
|
{
|
||||||
OverlayUtil.renderTileOverlay(graphics, decorObject, "ID: " + decorObject.getId(), DEEP_PURPLE);
|
OverlayUtil.renderTileOverlay(graphics, decorObject, "ID: " + decorObject.getId(), DEEP_PURPLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Polygon p = decorObject.getConvexHull();
|
||||||
|
if (p != null)
|
||||||
|
{
|
||||||
|
graphics.drawPolygon(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,4 +36,10 @@ public interface DecorativeObject
|
|||||||
|
|
||||||
@Import("y")
|
@Import("y")
|
||||||
int getY();
|
int getY();
|
||||||
|
|
||||||
|
@Import("rotation")
|
||||||
|
int getOrientation();
|
||||||
|
|
||||||
|
@Import("renderable1")
|
||||||
|
Renderable getRenderable();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user