runelite-api: move getConvexHull to Model
This commit is contained in:
@@ -56,8 +56,6 @@ public interface TileObject
|
|||||||
|
|
||||||
Point getMinimapLocation();
|
Point getMinimapLocation();
|
||||||
|
|
||||||
Polygon getConvexHull(Model model, int orientation);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the on-screen clickable area of {@code object}
|
* Get the on-screen clickable area of {@code object}
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,12 +35,12 @@ import net.runelite.api.Point;
|
|||||||
import net.runelite.api.SpritePixels;
|
import net.runelite.api.SpritePixels;
|
||||||
import net.runelite.api.coords.LocalPoint;
|
import net.runelite.api.coords.LocalPoint;
|
||||||
import net.runelite.api.coords.WorldPoint;
|
import net.runelite.api.coords.WorldPoint;
|
||||||
|
import net.runelite.api.events.AnimationChanged;
|
||||||
import net.runelite.api.events.GraphicChanged;
|
import net.runelite.api.events.GraphicChanged;
|
||||||
import net.runelite.api.mixins.FieldHook;
|
import net.runelite.api.mixins.FieldHook;
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
import net.runelite.api.mixins.Shadow;
|
import net.runelite.api.mixins.Shadow;
|
||||||
import net.runelite.api.events.AnimationChanged;
|
|
||||||
import static net.runelite.client.callback.Hooks.eventBus;
|
import static net.runelite.client.callback.Hooks.eventBus;
|
||||||
import net.runelite.rs.api.RSActor;
|
import net.runelite.rs.api.RSActor;
|
||||||
import net.runelite.rs.api.RSClient;
|
import net.runelite.rs.api.RSClient;
|
||||||
|
|||||||
@@ -28,12 +28,13 @@ import java.awt.Polygon;
|
|||||||
import java.awt.geom.Area;
|
import java.awt.geom.Area;
|
||||||
import net.runelite.api.Model;
|
import net.runelite.api.Model;
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.Renderable;
|
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
import net.runelite.api.mixins.Shadow;
|
import net.runelite.api.mixins.Shadow;
|
||||||
import net.runelite.rs.api.RSClient;
|
import net.runelite.rs.api.RSClient;
|
||||||
import net.runelite.rs.api.RSDecorativeObject;
|
import net.runelite.rs.api.RSDecorativeObject;
|
||||||
|
import net.runelite.rs.api.RSModel;
|
||||||
|
import net.runelite.rs.api.RSRenderable;
|
||||||
|
|
||||||
@Mixin(RSDecorativeObject.class)
|
@Mixin(RSDecorativeObject.class)
|
||||||
public abstract class RSDecorativeObjectMixin implements RSDecorativeObject
|
public abstract class RSDecorativeObjectMixin implements RSDecorativeObject
|
||||||
@@ -59,19 +60,19 @@ public abstract class RSDecorativeObjectMixin implements RSDecorativeObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Model getModel()
|
private RSModel getModel()
|
||||||
{
|
{
|
||||||
Renderable renderable = getRenderable();
|
RSRenderable renderable = getRenderable();
|
||||||
if (renderable == null)
|
if (renderable == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Model model;
|
RSModel model;
|
||||||
|
|
||||||
if (renderable instanceof Model)
|
if (renderable instanceof Model)
|
||||||
{
|
{
|
||||||
model = (Model) renderable;
|
model = (RSModel) renderable;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -92,13 +93,13 @@ public abstract class RSDecorativeObjectMixin implements RSDecorativeObject
|
|||||||
@Override
|
@Override
|
||||||
public Polygon getConvexHull()
|
public Polygon getConvexHull()
|
||||||
{
|
{
|
||||||
Model model = getModel();
|
RSModel model = getModel();
|
||||||
|
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getConvexHull(model, getOrientation());
|
return model.getConvexHull(getX(), getY(), getOrientation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ package net.runelite.mixins;
|
|||||||
|
|
||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
import java.awt.geom.Area;
|
import java.awt.geom.Area;
|
||||||
import net.runelite.api.Model;
|
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.Point;
|
import net.runelite.api.Point;
|
||||||
import net.runelite.api.Renderable;
|
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
import net.runelite.api.mixins.Shadow;
|
import net.runelite.api.mixins.Shadow;
|
||||||
import net.runelite.rs.api.RSClient;
|
import net.runelite.rs.api.RSClient;
|
||||||
import net.runelite.rs.api.RSGameObject;
|
import net.runelite.rs.api.RSGameObject;
|
||||||
|
import net.runelite.rs.api.RSModel;
|
||||||
|
import net.runelite.rs.api.RSRenderable;
|
||||||
|
|
||||||
@Mixin(RSGameObject.class)
|
@Mixin(RSGameObject.class)
|
||||||
public abstract class RSGameObjectMixin implements RSGameObject
|
public abstract class RSGameObjectMixin implements RSGameObject
|
||||||
@@ -57,17 +57,17 @@ public abstract class RSGameObjectMixin implements RSGameObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Model getModel()
|
private RSModel getModel()
|
||||||
{
|
{
|
||||||
Renderable renderable = getRenderable();
|
RSRenderable renderable = getRenderable();
|
||||||
if (renderable == null)
|
if (renderable == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderable instanceof Model)
|
if (renderable instanceof RSModel)
|
||||||
{
|
{
|
||||||
return (Model) renderable;
|
return (RSModel) renderable;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -86,13 +86,13 @@ public abstract class RSGameObjectMixin implements RSGameObject
|
|||||||
@Override
|
@Override
|
||||||
public Polygon getConvexHull()
|
public Polygon getConvexHull()
|
||||||
{
|
{
|
||||||
Model model = getModel();
|
RSModel model = getModel();
|
||||||
|
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getConvexHull(model, getOrientation());
|
return model.getConvexHull(getX(), getY(), getOrientation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,17 +24,26 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.mixins;
|
package net.runelite.mixins;
|
||||||
|
|
||||||
|
import java.awt.Polygon;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.runelite.api.model.Triangle;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.model.Vertex;
|
import net.runelite.api.Point;
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
|
import net.runelite.api.mixins.Shadow;
|
||||||
|
import net.runelite.api.model.Jarvis;
|
||||||
|
import net.runelite.api.model.Triangle;
|
||||||
|
import net.runelite.api.model.Vertex;
|
||||||
|
import net.runelite.rs.api.RSClient;
|
||||||
import net.runelite.rs.api.RSModel;
|
import net.runelite.rs.api.RSModel;
|
||||||
|
|
||||||
@Mixin(RSModel.class)
|
@Mixin(RSModel.class)
|
||||||
public abstract class RSModelMixin implements RSModel
|
public abstract class RSModelMixin implements RSModel
|
||||||
{
|
{
|
||||||
|
@Shadow("clientInstance")
|
||||||
|
private static RSClient client;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Inject
|
@Inject
|
||||||
public List<Vertex> getVertices()
|
public List<Vertex> getVertices()
|
||||||
@@ -85,4 +94,49 @@ public abstract class RSModelMixin implements RSModel
|
|||||||
|
|
||||||
return triangles;
|
return triangles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Inject
|
||||||
|
public Polygon getConvexHull(int localX, int localY, int orientation)
|
||||||
|
{
|
||||||
|
List<Vertex> vertices = getVertices();
|
||||||
|
|
||||||
|
// rotate vertices
|
||||||
|
for (int i = 0; i < vertices.size(); ++i)
|
||||||
|
{
|
||||||
|
Vertex v = vertices.get(i);
|
||||||
|
vertices.set(i, v.rotate(orientation));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Point> points = new ArrayList<Point>();
|
||||||
|
|
||||||
|
for (Vertex v : vertices)
|
||||||
|
{
|
||||||
|
// 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,9 +26,6 @@ package net.runelite.mixins;
|
|||||||
|
|
||||||
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;
|
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.Point;
|
import net.runelite.api.Point;
|
||||||
import net.runelite.api.TileObject;
|
import net.runelite.api.TileObject;
|
||||||
@@ -38,8 +35,6 @@ import net.runelite.api.mixins.Inject;
|
|||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
import net.runelite.api.mixins.Mixins;
|
import net.runelite.api.mixins.Mixins;
|
||||||
import net.runelite.api.mixins.Shadow;
|
import net.runelite.api.mixins.Shadow;
|
||||||
import net.runelite.api.model.Jarvis;
|
|
||||||
import net.runelite.api.model.Vertex;
|
|
||||||
import net.runelite.rs.api.RSClient;
|
import net.runelite.rs.api.RSClient;
|
||||||
import net.runelite.rs.api.RSDecorativeObject;
|
import net.runelite.rs.api.RSDecorativeObject;
|
||||||
import net.runelite.rs.api.RSGameObject;
|
import net.runelite.rs.api.RSGameObject;
|
||||||
@@ -115,52 +110,4 @@ public abstract class TileObjectMixin implements TileObject
|
|||||||
{
|
{
|
||||||
return Perspective.worldToMiniMap(client, getX(), getY());
|
return Perspective.worldToMiniMap(client, getX(), getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Inject
|
|
||||||
public Polygon getConvexHull(Model model, int orientation)
|
|
||||||
{
|
|
||||||
int localX = getX();
|
|
||||||
int localY = getY();
|
|
||||||
|
|
||||||
List<Vertex> vertices = model.getVertices();
|
|
||||||
|
|
||||||
// rotate vertices
|
|
||||||
for (int i = 0; i < vertices.size(); ++i)
|
|
||||||
{
|
|
||||||
Vertex v = vertices.get(i);
|
|
||||||
vertices.set(i, v.rotate(orientation));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Point> points = new ArrayList<Point>();
|
|
||||||
|
|
||||||
for (Vertex v : vertices)
|
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
import net.runelite.api.DecorativeObject;
|
import net.runelite.api.DecorativeObject;
|
||||||
import net.runelite.api.Renderable;
|
|
||||||
import net.runelite.mapping.Import;
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
public interface RSDecorativeObject extends DecorativeObject
|
public interface RSDecorativeObject extends DecorativeObject
|
||||||
@@ -44,7 +43,7 @@ public interface RSDecorativeObject extends DecorativeObject
|
|||||||
int getOrientation();
|
int getOrientation();
|
||||||
|
|
||||||
@Import("renderable1")
|
@Import("renderable1")
|
||||||
Renderable getRenderable();
|
RSRenderable getRenderable();
|
||||||
|
|
||||||
void setPlane(int plane);
|
void setPlane(int plane);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,13 +25,12 @@
|
|||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
import net.runelite.api.GameObject;
|
import net.runelite.api.GameObject;
|
||||||
import net.runelite.api.Renderable;
|
|
||||||
import net.runelite.mapping.Import;
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
public interface RSGameObject extends GameObject
|
public interface RSGameObject extends GameObject
|
||||||
{
|
{
|
||||||
@Import("renderable")
|
@Import("renderable")
|
||||||
Renderable getRenderable();
|
RSRenderable getRenderable();
|
||||||
|
|
||||||
@Import("plane")
|
@Import("plane")
|
||||||
int getPlane();
|
int getPlane();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
|
import java.awt.Polygon;
|
||||||
import net.runelite.api.Model;
|
import net.runelite.api.Model;
|
||||||
import net.runelite.mapping.Import;
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
@@ -52,4 +53,13 @@ public interface RSModel extends RSRenderable, Model
|
|||||||
|
|
||||||
@Import("indices3")
|
@Import("indices3")
|
||||||
int[] getTrianglesZ();
|
int[] getTrianglesZ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the convex hull of this model
|
||||||
|
* @param localX
|
||||||
|
* @param localY
|
||||||
|
* @param orientation
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Polygon getConvexHull(int localX, int localY, int orientation);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
import net.runelite.api.Model;
|
|
||||||
import net.runelite.api.Renderable;
|
import net.runelite.api.Renderable;
|
||||||
import net.runelite.mapping.Import;
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
@@ -35,5 +34,5 @@ public interface RSRenderable extends RSNode, Renderable
|
|||||||
|
|
||||||
@Import("getModel")
|
@Import("getModel")
|
||||||
@Override
|
@Override
|
||||||
Model getModel();
|
RSModel getModel();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user