Luxe 87 Posted June 3, 2024 I discussed the EDU discord with @Smokeyjay, who helped me figure out how to paint entities and objects similar to runelite and I thought I should document it for any future googlers. The final result turned out like this and here is the code (with some code from my private hunting script). The code should be placed in the onPaint method if(this.getCurrentLeafName() != null && this.getCurrentLeafName().toLowerCase().contains("lizard")) { List<NPC> lizards = NPCs.all(x -> x.getName().equalsIgnoreCase(getSettings().huntingActivity.getPreyName())); for (NPC lizard : lizards) { if(lizard.isOnScreen()) { ViewportTools v = new ViewportTools(); Graphics2D g2D = (Graphics2D) graphics; if (lizard != null) { Model cloudModel = lizard.getModel(); cloudModel.drawWireFrame(graphics); graphics.drawString("Animation: " + lizard.getAnimation(), lizard.getX(), lizard.getY()); v.getModelArea(lizard); v.drawModel(g2D, lizard.getGridX(), lizard.getGridY(), lizard.getZ(), cloudModel); graphics.drawRect( (int) lizard.getBoundingBox().getX(), (int) lizard.getBoundingBox().getY(), (int) lizard.getBoundingBox().getHeight(), (int) lizard.getBoundingBox().getWidth() ); } } } } Note that drawing too many entities will slow the framerate significantly! Hope this helps someone else in the future! ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- On another note, does anyone know how to get a paint similar to this? Meteorite 1
morten1ela 32 Posted June 3, 2024 1 hour ago, Luxe said: On another note, does anyone know how to get a paint similar to this? You can use Model#getHullBounds @Override public void onPaint(Graphics2D graphics2D){ NPC banker = NPCs.closest(i -> i != null && i.getName().equals("Banker")); Shape shape = banker.getModel().getHullBounds(1.f); // Enable anti-aliasing for smoother lines graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Set the color to Cyan graphics2D.setColor(Color.CYAN); // Set the thickness of the boarder graphics2D.setStroke(new BasicStroke(2.f)); //Draw the shape graphics2D.draw(shape); } Luxe and NullVoid 2
Meteorite 77 Posted July 3, 2024 Would be very interesting to see something similar to RuneLite's ModelOutlineRenderer#drawOutline method that is used in some plugins like https://github.com/neilrush/Player-Outline Luxe 1
morten1ela 32 Posted July 4, 2024 21 hours ago, Meteorite said: Would be very interesting to see something similar to RuneLite's ModelOutlineRenderer#drawOutline method that is used in some plugins like https://github.com/neilrush/Player-Outline I've done this. It kills the FPS and wouldn't recommend it. Perhaps you could optimize it but I think it's pointless. It's a QOL feature that only players can enjoy, really. When it comes to debugging bots it serves next to no purpose. graphics2D.setColor(new Color(0, 0, 0, 125)); NPC guard = NPCs.closest("Guard"); if(guard != null && guard.getModel() != null){ java.awt.geom.Area modelArea = guard.getModel().calculateModelArea(); graphics2D.draw(modelArea); } Luxe and Meteorite 2
Meteorite 77 Posted July 4, 2024 1 hour ago, morten1ela said: I've done this. It kills the FPS and wouldn't recommend it. Perhaps you could optimize it but I think it's pointless. It's a QOL feature that only players can enjoy, really. When it comes to debugging bots it serves next to no purpose. graphics2D.setColor(new Color(0, 0, 0, 125)); NPC guard = NPCs.closest("Guard"); if(guard != null && guard.getModel() != null){ java.awt.geom.Area modelArea = guard.getModel().calculateModelArea(); graphics2D.draw(modelArea); } What's heavy about it, the model is complex and costly to paint or the calculateModelArea call? Can cache the calculateModelArea call and if it's too complex then could make it a little more simple?
morten1ela 32 Posted July 4, 2024 1 hour ago, Meteorite said: What's heavy about it, the model is complex and costly to paint or the calculateModelArea call? Can cache the calculateModelArea call and if it's too complex then could make it a little more simple? Just the model calculation, it seems. No area calculation or drawing: Just calculating: Calculating and drawing:
Pandemic 2846 Posted July 5, 2024 Improved Model#calculateModelArea/ViewportTools#getModelArea's performance in the latest client hotfix, the version should show 3.27.8.1 for those. For backward compatibility reasons I couldn't include an on canvas check, but that would save a lot of time also (making sure the NPC is on screen before getting the model area). Luxe, morten1ela and Meteorite 3
morten1ela 32 Posted July 5, 2024 Good enough, I guess... I guarantee there is a better method to do the feathering effect but this is all I'm willing to play around with for now. The model area calculation doesn't noticeably impact performance anymore, but my for loop absolutely does. if(Players.getLocal().getModel() != null){ java.awt.geom.Area modelArea = Players.getLocal().getModel().calculateModelArea(); // Glowing effect: for (int i = 1; i <= 3; i++) { BasicStroke stroke = new BasicStroke(i * 2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); // Create an expanded area for the glow effect java.awt.geom.Area expandedArea = new java.awt.geom.Area(stroke.createStrokedShape(modelArea)); expandedArea.subtract(modelArea); graphics2D.setColor(new Color(0, 0, 0, 75 - (i * 20))); // Decrease alpha for each layer graphics2D.fill(expandedArea); // Fill the glow area outside the outline } // Draw the main outline graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(new Color(0, 0, 0, 100)); graphics2D.draw(modelArea); } Luxe and Meteorite 2
Luxe 87 Author Posted July 7, 2024 On 7/5/2024 at 8:46 AM, morten1ela said: Good enough, I guess... I guarantee there is a better method to do the feathering effect but this is all I'm willing to play around with for now. The model area calculation doesn't noticeably impact performance anymore, but my for loop absolutely does. if(Players.getLocal().getModel() != null){ java.awt.geom.Area modelArea = Players.getLocal().getModel().calculateModelArea(); // Glowing effect: for (int i = 1; i <= 3; i++) { BasicStroke stroke = new BasicStroke(i * 2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); // Create an expanded area for the glow effect java.awt.geom.Area expandedArea = new java.awt.geom.Area(stroke.createStrokedShape(modelArea)); expandedArea.subtract(modelArea); graphics2D.setColor(new Color(0, 0, 0, 75 - (i * 20))); // Decrease alpha for each layer graphics2D.fill(expandedArea); // Fill the glow area outside the outline } // Draw the main outline graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(new Color(0, 0, 0, 100)); graphics2D.draw(modelArea); } Did you end up getting a benchmark for fps?
morten1ela 32 Posted July 7, 2024 11 hours ago, Luxe said: Did you end up getting a benchmark for fps? From <1 ms per frame to about 5-15 depending on how zoomed in on the character you are. That's with the for loop at 3 iterations. I tried caching the area and feathered thing but it only improved the fps while standing still. As soon as I start moving it'd stutter a bunch.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now