View.draw GL_POINTS with color and size, is it even possible from Ruby API?

Hi there community,

So I’m somewhat new to SU Ruby scripting and new to this forum. I’m writing a plugin that draws points using view.draw with GL_POINTS using Ruby API. I’m in SU 2023 and I’m trying to accomplish this by drawing using an Overlay class I wrote. I picked view.draw instead of view.draw_points because in my local testing I saw a severe framerate drop when using draw_points (from >60 to 20), not to mention draw_points does not seem to take occlusions into consideration.I have something between 20K and 100K points I want to render.

Looking at the documentation for view.draw and noting there was no option to pass colors or sizes, in a desperate attempt, I supplied a texture map and uv coords. Documentation does not clarify if this is only for GL_QUADS or triangles. I was able to render the color of the texture map to display when using GL_QUADS, but not when using GL_POINTS.

Questions are:

  • Is it possible to do view.draw while supplying different colors for my points?
  • Is it possible to set the size the whole pointset (line_width does not work) when using view.draw?
  • What is the most performant way to get 20K sized pointclouds with colors and size drawn in an overlay?

Constraint: I can’t use an existing extension.

Thank you all!

Use Sketchup::View#drawing_color= (I think default color is black.)

Sketchup::View#line_width= applies to lines drawn.

What I think coders do is draw little shapes around the location of a point, or use #draw_points which allows size and shape arguments.

I don’t know as I do not think Overlays were meant for point clouds.
Ie, users cannot interact with the virtual geometry drawn to an overlay.

SketchUp can handle true point clouds, but they are not exposed to the API.
We must use Trimble Scan Essentials which is included with a Studio subscription.

Thanks for noting that view.draw_points can handle color and size. The the issue for my plugin is that it can’t handle occlusions, or at least I dont know how to do it. That is, points will be visible even I draw a wall between them. But, using view.draw I can see occlusion is properly handled. But line_width prop does not seem to work for view.draw.

Also, for my plugin, not being able to snap is actually positive.

Trimble Scan Essentials, let me research on this side.

Thank you!

Incorrect. The following example shows that view.line_width does work for view.draw

class ExampleOverlay < Sketchup::Overlay

  def initialize
    super('example_inc.my_overlay', 'Example Overlay')
    @points = [
      [100, 100, 0], [300, 100, 0], [300, 200, 0], [100, 200, 0]
    ]
    @bounds = Sketchup.active_model.bounds
    @bounds.add(@points)
  end

  def draw(view)
    view.drawing_color = 'purple'
    view.line_width = 10
    view.draw(GL_LINE_LOOP, @points)
  end

  def getExtents
    return @bounds
  end

end

# Using an observer to create a new overlay per model.
class ExampleAppObserver < Sketchup::AppObserver

  def expectsStartupModelNotifications
    true
  end

  def register_overlay(model)
    overlay = ExampleOverlay.new
    model.overlays.add(overlay)
    overlay.enabled= true
  end
  alias_method :onNewModel, :register_overlay
  alias_method :onOpenModel, :register_overlay

end

observer = ExampleAppObserver.new
Sketchup.add_observer(observer)

# The following line is needed if you copy+paste in the Ruby Console or
# at the moment the extension is installed:
observer.register_overlay(Sketchup.active_model)

(…scroll to see all code …)

Again, as I said above (quoting with emphasis) …

Note that you must have the overlay switched ON to see the lines drawn.

I have reproduced this. I think it should be filed as a bug report in the official API tracker.
The Sketchup::View#draw_points method should work like the other draw methods in my opinion.

@tt_su

Thank you Dan, I’ll look into creating an issue for draw_points.

As for the line_width, sorry for not clarifying, I meant that line_width does not apply/work with GL_POINTS which does make sense for sure, but there is no similar setting that applies to GL_POINTS.