Put forward drawings openGL
-
Hi all, I want to ask how can I bring to the front drawing openGL?,
something like this:I do not know how to do this, in advance I appreciate your help
(google translator) -
use view 2d methods and transform to screen cordinates to with view.screen_coords ?
-
I think he means how to draw while the other tool is active?
As described in the picture above, the scale tool is active, meantime the circle is drawn.Yet, I don't think its not possible to draw via Sketchup API while the other tool is active.
-
thanks for replying, I mean that the OpenGL geometry not hide because of the entities in the model,
use 2d drawings is an option but it seems a bit complicated for something with back and front part, in my case the object has shape of a cube
(sorry for any errors in translation) -
Nothing's complicated:
Access: (Menu) Plugins → Highlight Tool
However, I can't make it work while the other tool is active.
-
X-ray mode?
-
Nice Anton_S! Useful code.
@unknownuser said:
However, I can't make it work while the other tool is active.
Can't one just delegate to the other class/tool ?
Or are you talking about some other issue..Initializing an instance of the other toolclass in current tool and delegate the useful methods ?
Or is that bad practice or do there exist a better way ?
I'm interested in doing this properly.. -
@jolran said:
Can't one just delegate to the other class/tool ?
If your thinking of including this in your tool, then yes, this is absolutely possible. I was making an argument about having this tool active while the other tools are active too. I'm thinking dacastror wants this to be active while the other tool is active, but I'm not sure yet. I mean the select tool, push pull tool, scale tool, rotate tool - How to incorporate this tool into them or how to keep this tool active while the other tools are active too?
-
Ahh, ok. Now I see what you meant. Good point.
I don't think one can have costume tools active alongside Sketchup native tools(They are not written in Ruby?)
I havent seen that anyway. Would save a lot of effort if possible.. -
thanks for answering, I do not mean to have two tools running simultaneously, what I want to do is create a clone of the scale tool to add additional features, I do not understand is how to draw a cube in front of sketchup instances, or draw a cube in 2d consistent with the perspective
-
We use the draw2d methods because they DO draw in front of Sketchup Geometry.
(I'm sure someone is going to pitch in and tidy this info
)
The view.screen_coords method converts 3d(x,y,z) positions to screen X and Y positions, (valid as 2nd argument in the draw2d methods).
For an easy example. to convert a boundingbox cornerpoints to view screen points (untested!):
# Somewhere in your class... bb = @group.bounds # could be any element responding to Bounds. @corners_to_screen_position = (0..7).collect{|i| view.screen_coords( bb.corner(i) ) } # in your toolclass draw-method view.draw2d( GL_POINTS, @corners_to_screen_position )
You could use any GL constant for drawing other types of geometry, but this should give you the idea.
-
thank you very much Jolran,
view.screen_coords
is very useful,
Initially I did this:class DibujaCubo3d def activate @size = 60 @tr = Geom;;Transformation.new([20,10,30]) end def transformar(pts,axis_num) pts = pts.map{|p| [p.z,p.x,p.y]} if axis_num == 0 pts = pts.map{|p| [p.y,p.z,p.x]} if axis_num == 1 pts = pts.map{|p| p.transform! @tr} end def draw_square(view, axis_num, size, alto) pts = [[0,0,alto],[size,0,alto],[size,size,alto],[0,size,alto]] pts = transformar(pts,axis_num) view.drawing_color = [0,0,0] view.draw GL_LINES, pts view.drawing_color = [0,255,0] view.draw GL_QUADS, pts end def draw(view) 3.times{|i| draw_square(view, i, @size, 0)} 3.times{|i| draw_square(view, i, @size, @size)} end end Sketchup.active_model.select_tool DibujaCubo3d.new
and this is the best that I can get for now
class DibujaCubo def activate @size = 60 @tr = Geom;;Transformation.new([20,10,30]) end def transformar(view,pts,axis_num) pts = pts.map{|p| [p.z,p.x,p.y]} if axis_num == 0 pts = pts.map{|p| [p.y,p.z,p.x]} if axis_num == 1 pts = pts.map{|p| view.screen_coords(p.transform!(@tr))} end def points_square(view, axis_num, size, alto) pts = [[0,0,alto],[size,0,alto],[size,size,alto],[0,size,alto]] pts = transformar(view,pts,axis_num) end def draw_shapes(view, tipe, size, color) view.drawing_color = color 3.times{|i| view.draw2d tipe, points_square(view, i, size, 0)} 3.times{|i| view.draw2d tipe, points_square(view, i, size, @size)} end def draw(view) draw_shapes(view, GL_QUADS, @size, [0,255,0]) draw_shapes(view, GL_LINES, @size, [0,0,0]) end end Sketchup.active_model.select_tool DibujaCubo.new
always shown ahead of all geometry!
-
It's working
-
Anton_S your code is very interesting (highlight_picked_body.rb), I have never used Start and stop operation inside a custom tool, I like the result, I am studying this code
Advertisement