I do not think you want to use GL_LINE_LOOP as it relies upon view.line_width= and view.line_stipple= which have defaults (likely 1 and solid respectively.) But the line width is scaled according to the user’s display scaling on the monitor that SketchUp is running on.
Basically, if the face has 4 vertices I would say use GL_QUADS and if more than GL_POLYGON. These are not affected by display scaled line widths.
You are. Either as Steve said you need to define a getExtents callback within your tool and inside this create a bounding box object that encompasses the @points.
So, somewhere in the tool wherever you determine the face, you get its vertices, their positions (@points) and create the tool’s bounding box immediately …
@bb = Geom::BoundingBox.new.add(@points)
… then your getExtents callback just returns that bounds whenever SketchUp’s graphics engine wants it.
def getExtents
@bb
end
Whenever your tool needs to expand the bounds, it need only add more points to @bb.
Another way is to simply have getExtents return its model’s bounds. Ie, a tool instance belongs to the toolstack collection for individual models. It is common to pass the active model instance reference into a tool’s constructor. …
model = Sketchup.active_model
model.select_tool(Vaibhav::NiftyTool.new(model))
In you tool …
def initialize(model)
@model = model
# ... other initialization ...
end
… and your tool’s getExtents callback …
def getExtents
@model.bounds
end
… okay?
Now the other basic thing is that in order for the SketchUp graphics engine to draw to the view, … for either a tool or an overlay, … the view must be invalidated with view.invalidate.
- Do not call
view.invalidate from within your tool’s (or overlay’s) draw callback.
It will crash SketchUp or lock it up within an endless loop.
Normally a tool will call view.invalidate at strategic places like after a certain mouse click on a desired object (a face in your case) and also likely in the activate, suspend, resume and deactivate callbacks.
NO … I third what the others have said. Global variables are a no-no. You would assign the face’s vertices positions to a @points instance variable, likely within your tool’s onLButtonUp callback.
There is no good reason for any of your code or data to exist or evaluate outside your top-level namespace module and each of your extensions should be in a submodule of your namespace module. The tool class would be wrapped inside your extension submodule.
Lastly, the indentation in your snippets is extreme. Ruby uses 2 space indents by convention.
It’s best to set your code editor to replace TABs with 2 spaces so that when pasted into the forum, we are not forced to scroll horizontally to read the snippets.