SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
39 stars 10 forks source link

View drawing: Add new capabilities to the SketchUp Ruby API to allow improved performance when drawing to a View (Tool#draw and Overlay#draw) #883

Open mccs001 opened 1 year ago

mccs001 commented 1 year ago

These are feature requests (originally raised in the SketchUp MeetUp meeting on 8th March 2023: ThomThom asked me to raise them here)

The requests are to allow SketchUp Extensions to be able to draw large amounts of mainly-fixed geometry (in model coordinates, anyway) in a way that runs performantly (without introducing lag to the UI when orbiting/panning/zooming) and looks nice.

These can be achieved with some manual calls to C++ OpenGL functions (while in Tool#draw call - probably also with Overlay#draw but not tested yet) but it would be much better for them to be available with officially-documented SketchUp API functions that will continue to work with the new Graphics pipelines being introduced.

Please add the following capabilities:

  1. Allow an extension to store fixed geometry that doesn't change (in model coordinates) between draw calls and render it quickly without needing to make the same individual View#draw calls each time.
  1. Allow an extension to selectively enable something similar to OpenGL polygon offsetting
  1. Consider making it possible for C/C++ code to call an officially-supported draw function with plain C++ data types (eg arrays of doubles for points) - when called inside Tool#draw

Hope that all makes sense. I'll be happy to give more details if that would help and take part in any discussions around implementation ideas.

Fredosixx commented 1 year ago

Personally, I never found no major performance issues with view.draw methods.

FredoCorner Preview mode

For 3D drawing, storing the instructions (independent from the view camera) and calling the view.draw methods is good enough.

For 2D drawing (dependent on view camera), I only recompute the instructions when there is an observer event onViewChanged.

What would however be nice to have, is a method to draw any type of polygons. Currently, GL_POLYGON only works for convex polygons, not concave ones.

DanRathbun commented 1 year ago
  • For example, there could be an officially-supported C-style function exported by the SketchUp.exe process (similar to other SketchUp C API functions) that accepts the same arguments as View#draw but in a native format (I don't think it would make sense to make it a Ruby function unless it's easy and safe for the caller to pass through some kind of object in the native representation)

We have talked about this in the past for the Live C API. A year and 9 months ago ... this request was opened:

Issue 853 : Implement SUViewDraw

thomthom commented 1 year ago

What would however be nice to have, is a method to draw any type of polygons. Currently, GL_POLYGON only works for convex polygons, not concave ones.

You can use Geom.tesselate to deal with convext and complex (with holes) polygons: https://ruby.sketchup.com/Geom.html#tesselate-class_method