sketchucation logo sketchucation
    • Login
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Put forward drawings openGL

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 4 Posters 589 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      Anton_S
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • D Offline
        dacastror
        last edited by

        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)

        1 Reply Last reply Reply Quote 0
        • A Offline
          Anton_S
          last edited by

          Nothing's complicated:

          https://googledrive.com/host/0B3qg8f4WrNdHWktZLXN5T2d6Tms/highlight_picked_body.gif

          Place in Plugins folder

          Access: (Menu) Plugins → Highlight Tool

          However, I can't make it work while the other tool is active.

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            X-ray mode?

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              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..

              1 Reply Last reply Reply Quote 0
              • A Offline
                Anton_S
                last edited by

                @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?

                1 Reply Last reply Reply Quote 0
                • jolranJ Offline
                  jolran
                  last edited by

                  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..

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    dacastror
                    last edited by

                    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

                    1 Reply Last reply Reply Quote 0
                    • jolranJ Offline
                      jolran
                      last edited by

                      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.

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        dacastror
                        last edited by

                        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!

                        1 Reply Last reply Reply Quote 0
                        • jolranJ Offline
                          jolran
                          last edited by

                          It's working 😄

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            dacastror
                            last edited by

                            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

                            1 Reply Last reply Reply Quote 0
                            • 1 / 1
                            • First post
                              Last post
                            Buy SketchPlus
                            Buy SUbD
                            Buy WrapR
                            Buy eBook
                            Buy Modelur
                            Buy Vertex Tools
                            Buy SketchCuisine
                            Buy FormFonts

                            Advertisement