• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Camera Rays wanted

Scheduled Pinned Locked Moved Plugins
35 Posts 4 Posters 4.6k 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.
  • T Offline
    TIG Moderator
    last edited by 9 May 2010, 10:00

    Without seeing all of the code... you need to set @ip=nil before it's set by the picking - then you should not get the error messages.
    I can see nothing wrong with the way you are setting the vector.
    Try adding some extra code to entities.add_cpoint(camera.eye) and entities.add_cpoint(@ip.position) so you can check these are getting taken properly.
    Are you setting the 'camera' and then moving the view point to pick @ip ? You need to get the camera immediately after you click on @ip, otherwise you'll get an old camera.eye being used ??

    TIG

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 9 May 2010, 10:32

      Add a little validation of the vector to ensure it's not of zero length.

      
        def onLButtonUp(flags, x, y, view);
          vector = view.camera.eye.vector_to(@ip.position)
          Sketchup.active_model.active_entities.add_cline(view.camera.eye, vector) if vector.valid?
        end
      
      

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • C Offline
        Chris Fullmer
        last edited by 9 May 2010, 17:11

        I was getting that same error August. And I am not sure why, hopefully one of their suggestions will fix it. I have little to no experience with conctruction geometry (apart from construction points I guess).

        Chris

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • A Offline
          August
          last edited by 10 May 2010, 18:37

          @tig said:

          ... you need to set @ip=nil before it's set by the picking ... You need to get the camera immediately after you click on @ip, otherwise you'll get an old camera.eye being used ??

          Ah Ha! That explains why sometimes I seem to only get one line. It must be using the old @ip and therefor I'm getting the same line constructed with each click, no matter where it is. In this scenario, I seem to get one line with each re-invocation of the tool.

          Separately, but similarly, the visible line that does not go through the current camera eye, must be using the older camera eye.

          Definitely some issues to explore.

          All my links to Ruby reference sources are stuck on my dead computer and I had not begun to use them enough to have them in my head. Can someone point me to where @ip is well described?

          Thanks,
          August

          β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
          [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 10 May 2010, 18:38

            The 'line tool' example rb script is perhaps as good as any to start with - you should have that already...

            TIG

            1 Reply Last reply Reply Quote 0
            • A Offline
              August
              last edited by 10 May 2010, 18:42

              @chris fullmer said:

              ... I have little to no experience with conctruction geometry ...

              😲 Pick my jaw off the floor! Given how much of your code, Chris, I use in contructing my own geometry, to use a totally geeky metaphor πŸ€“ , that strikes me like Yoda saying he's not very good with a light saber. Sorry.

              β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
              [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

              1 Reply Last reply Reply Quote 0
              • A Offline
                August
                last edited by 10 May 2010, 18:46

                @tig said:

                The 'line tool' example rb script is perhaps as good as any to start with - you should have that already...

                Thanks. Your suggestion about validating the vector should be useful too. I'll have it kick off a msgbox.

                Forgive me if my attention to this is sporadic. I do appreciate all the help.

                August

                β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
                [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

                1 Reply Last reply Reply Quote 0
                • A Offline
                  August
                  last edited by 10 May 2010, 18:48

                  As an aside, it occured to me that this thread is an example of the meaning of my signature quote from Dickens. Thanks again to everyone. I'm very encouraged that this will come together quickly from here.

                  β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
                  [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    August
                    last edited by 12 May 2010, 07:15

                    @august said:

                    ...All my links to Ruby reference sources are stuck on my dead computer and I had not begun to use them enough to have them in my head. Can someone point me to where @ip is well described?

                    Thanks TIG,

                    There are definitely more examples of @ip and @xxxx in the Google-supplied examples. But they didn't help. Your previous suggestion about setting @ip=nil has not helped (so far), at least with the things that I've been wrestling with, and I think I may have a clue why.

                    Major Ruby Thinking Glitch

                    I think I've found a major conceptual glitch in my understanding SketchUp Ruby "under the hood" -- and maybe this will help others, at least newbies, too. The following outlines my Ruby learning process to get there. Later I'll try to post full examples for testing to demonstrate what I think is really going on and why the results have seemed to make no sense and the suggested fixes have not worked.

                    I finally figured out that I was asking the wrong question. I don't need to understand " @ip" as much as I first need to understand " @".

                    After some hours of digging (both of my Ruby books are missing somewhere in "the disaster that once was my home office" but I finally found a good online reference) , I have learned that @ip is an instance variable.

                    I had originally been trying to follow Chris' usage:

                    @ip = view.inputpoint(x,y);

                    That line is used in the working snippet that Chris posted earlier in this thread that defines the " clf_auguat_lines" class.

                    I've been assuming that @ip would hold an inputpoint.

                    The SketchUp Ruby API doc says that view.inputpoint(x,y) returns nil, but clearly nil is not assigned to the @ip variable or the script would not do anything.

                    The other OO languages I'm most familiar with, FrameMaker FrameScript and Acrobat JavaScript, allow a method to return an instance of a class and that can be assigned to a variable. Their doc would have said "Returns point object" instead of "Returns nil".

                    Also, somewhere along the way I got the mistaken idea that Ruby had typeless variables. I guess I assumed that because you don't declare variables. But Ruby has implicit declarations based on the first letter of the variable name and value assigments happen very differently depending on the type of variable being assigned.

                    I have been assuming that @ip is an inputpoint object created by:

                    @ip = view.inputpoint(x,y);

                    From that assumption, I've been further assuming that @ip.position would return a Point3D object.

                    But it appears that it doesn't, at least not exactly. I had been reading the code as if it would create the Point3D object as soon as @ip.position was executed, but instead it appears to hold off evaluating it until the last possible moment. It appears to not create a Point3D at all "if it doesn't have to".

                    The code:

                    eye = view.camera.eye;
                    Sketchup.active_model.active_entities.add_line(eye,@ip.position);
                    

                    will, embedded in Chris' snippet, draws a line wherever you click. But the code:

                    eye = view.camera.eye;
                    vector = eye.vector_to(@ip.position);
                    Sketchup.active_model.active_entities.add_cline(eye,vector);
                    

                    will only draw a cline if you click on a place that is a valid reference for a cline. Anywhere else, you get an error about a zero-length vector.

                    That has been totally confusing me until the idea of postponed evaluation occurred to me.

                    What it says to me is that SketcnUp Ruby is not creating a vector object by using " eye" as one Point3D and @ip.position as a second Point3D. It does not create the second Point3D right away (I'm guessing).

                    Instead, the vector is not actually evaluated until the add_cline is being executed, and because it's add_cline and not add_line, if the @ip.position is not valid for a cline, you get an error about an invalid vector.

                    I'm stretching here, so I'm hoping someone who knows this much better than I do can follow my logic and tell me if I'm on track or missing the point.

                    Am I making sense? Is there a better way to make sense out of this?

                    Thanks,
                    August

                    β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
                    [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      August
                      last edited by 13 May 2010, 03:50

                      This is driving me crazy and now I've spent nearly another full day on it. Arrgh!

                      I can draw Camera Ray lines just fine. But not clines unless there is an object to reference.

                      I can get one, single unreferenced cline. Once a cline fails to get an input point because of a lack of a reference object, I cannot get another valid @ip for a line, only for clines that have reference objects. Doesn't matter if I reload the file, I have to restart SU to clear this state.

                      I thought I could draw the line first, and then use its endpoints to create the vector (that works) and the cline (that doesn't work).

                      To demonstrate, I have two files. The only difference between them is that in the first one, some code is commented out: the single line of code that creates a cline from a point and a vector and some following messages to report on it.

                      Both versions create a vector from the original line and that appears to work fine.

                      Here's the version that creates plain old ordinary edge lines. I call it rayL.txt:

                      
                      class Clf_august_lines;
                      
                        def onMouseMove(flags, x, y, view);
                          @ip = view.inputpoint(x,y);
                          view.invalidate;
                        end;
                      
                        def onLButtonUp(flags, x, y, view);
                      
                      line1 = Sketchup.active_model.active_entities\
                      .add_line(view.camera.eye, @ip.position);
                       if (line1)
                         UI.messagebox "line1 SUCCESS\n
                      view.camera.eye = " + view.camera.eye.to_s + "\n
                      @ip.position = " + @ip.position.to_s else
                       else
                         UI.messagebox "line1 Failure\n
                      view.camera.eye = " + view.camera.eye.to_s + "\n
                      @ip.position = " + @ip.position.to_s
                       end
                      
                      vector1 = line1.start.position\
                      .vector_to(line1.end.position);
                       if (vector1)
                         UI.messagebox "vector 1 = " + vector1.to_s
                       else
                         UI.messagebox "vector1 Failure"
                       end
                      
                      #cline1 = Sketchup.active_model.active_entities\
                      #.add_cline(line1.start.position, vector1);
                      # if (cline1)
                      #   UI.messagebox "cline1 = " + cline1.to_s
                      #   line1.erase!
                      # else
                      #   UI.messagebox "cline1 Failure"
                      # end
                      
                        end;
                      
                        def draw(view);
                          @ip.draw view;
                        end;
                      
                      end;
                      
                      Sketchup.active_model.select_tool\
                      (Clf_august_lines.new)
                      
                      

                      And here's the version that creates a line, then uses that line's endpoints to create a vector, which works in both versions, and then creates a cline from one endpoint of the line and the vector. It is this cline which initiates the problem.

                      I call this one rayLC.txt because it attempts to create a line and then a cline:

                      
                      class Clf_august_lines;
                      
                        def onMouseMove(flags, x, y, view);
                          @ip = view.inputpoint(x,y);
                          view.invalidate;
                        end;
                      
                        def onLButtonUp(flags, x, y, view);
                      
                      line1 = Sketchup.active_model.active_entities\
                      .add_line(view.camera.eye, @ip.position);
                       if (line1)
                         UI.messagebox "line1 SUCCESS\n
                      view.camera.eye = " + view.camera.eye.to_s + "\n
                      @ip.position = " + @ip.position.to_s
                       else
                         UI.messagebox "line1 Failure!\n
                      view.camera.eye = " + view.camera.eye.to_s + "\n
                      @ip.position = " + @ip.position.to_s
                       end
                      
                      vector1 = line1.start.position\
                      .vector_to(line1.end.position);
                       if (vector1)
                         UI.messagebox "vector 1 = " + vector1.to_s
                       else
                         UI.messagebox "vector1 Failure"
                       end
                      
                      cline1 = Sketchup.active_model.active_entities\
                      .add_cline(line1.start.position, vector1);
                       if (cline1)
                         UI.messagebox "cline1 = " + cline1.to_s
                      #   line1.erase!
                       else
                         UI.messagebox "cline1 Failure"
                       end
                      
                        end;
                      
                        def draw(view);
                          @ip.draw view;
                        end;
                      
                      end;
                      
                      Sketchup.active_model.select_tool\
                      (Clf_august_lines.new)
                      
                      

                      If I open a new SU drawing and load 'rayL.txt', it will draw lines whereever I click. But unless there is an object for them to reference, they stop at the bounding planes of the near quadrant.

                      If I then either load 'rayLC.txt' or open a new SU file and load it, I can draw clines that reference existing objects, e.g., Sang, and there is no problem.

                      But when I attempt to draw a cline that does not reference an existing object, I can create just that one, single cline and then all subsequent attmpts to create clines will fail because @ip.position is stuck at the camera.eye position or line1.start.position.

                      Even if I load rayL.txt again to create just lines, they fail, referencing Sang, the origin, or whatever. After one cline, @ip.position is stuck on camera.eye.

                      I have tried TIG's suggestion of inserting @ip = nil but everywhere I have tried it produces error messages.

                      This doesn't seem like it should be this hard.

                      I have been poring over the SketchUp Ruby doc about view and inputpoint etc. and unfortunatley it all seems written for those who already get it. It also says things like the inputpoint should "normally" be obtained using [ruby:11qtfq9b]pick[/ruby:11qtfq9b], but I've followed those examples and not even gotten a working start. At least this one based on Chris Fullmer's version works sometimes.

                      It appears to be one of three things:

                      • It really is this hard.
                      • I'm overlooking something very basic.
                      • There is a bug in creating clines from a point and a vector.

                      Can someone help me figure out which it is, and/or possibly suggest a workaround?

                      Thanks,
                      August

                      β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
                      [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

                      1 Reply Last reply Reply Quote 0
                      • C Offline
                        Chris Fullmer
                        last edited by 13 May 2010, 04:57

                        There is something wrong going on here and I'm not sure if its something in the script or an SU bug. But after the cline is created, focus is not given back to the mouse correctly. You will notice that it is no longer drawing the inference dots after the first line is drawn correctly. That shows me that somehow the on_Mouse_move is not being called after the mouse button is clicked. But once you orbit, then it all gets reset.

                        I'm looking it over right now, but so far I am not seeing any obvious error.

                        Chris

                        PS somehow I never got intot he habit of using contrsution geometry. I always just use regular lines to act as guides πŸ˜„

                        Lately you've been tan, suspicious for the winter.
                        All my Plugins I've written

                        1 Reply Last reply Reply Quote 0
                        • C Offline
                          Chris Fullmer
                          last edited by 13 May 2010, 05:14

                          Well, I don't know why that is broken and I got tired of looking at it so I took a new approach. I just used the pickray method to make the point and vector. It is much simpler and seems to be working great. So try this little code.

                          class Clf_august_lines
                          
                          	def onMouseMove(flags, x, y, view)
                          		@ip = view.inputpoint(x,y)
                          		view.invalidate
                          	end
                          
                          	def onLButtonUp(flags, x, y, view)
                          		Sketchup.active_model.active_entities.add_cpoint(view.camera.eye)
                          		ray = Sketchup.active_model.active_view.pickray(x,y)
                          		Sketchup.active_model.active_entities.add_cline(ray.to_a[0], ray.to_a[1])
                          	end
                          
                          	def draw(view)
                          		@ip.draw view
                          	end
                          
                          end
                          
                          Sketchup.active_model.select_tool(Clf_august_lines.new)
                          
                          

                          Oh and I erased out all the semi-colons. They look messy to me. I only put them in the original code so I could condense it all to one line to run from the console. But since you are not doing it that way, I didn't feel there was a need to keep them around. Feel free to put them back if you miss them though πŸ˜„

                          Chris

                          Lately you've been tan, suspicious for the winter.
                          All my Plugins I've written

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            August
                            last edited by 13 May 2010, 23:08

                            @chris fullmer said:

                            There is something wrong going on here and I'm not sure if its something in the script or an SU bug. ...

                            Thanks for that confirmation.

                            It's worse than you had so-far discovered.

                            After the tool fails, if you activate the Select tool, it will not select. If you activate the Line tool, it will not draw. After a bunch of tool changes and attempts, I got function back, I presume because one tool or another did a better job of resetting things.

                            It's a bug.

                            I will try your new approach.

                            I had tried my own "new approach" by taking linetool.rb and hacking out the two-point construction to get just one point. I also didn't try calculating a vector, I just drew the cline between view.camera.eye and @ip1 and gave it a name, newRay, then set newRay.end = nil.

                            But the core construction method of my new version is still the same and it has the same problem as the old version. I'm convinced it's a bug.

                            Thanks again,
                            August

                            β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
                            [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

                            1 Reply Last reply Reply Quote 0
                            • A Offline
                              August
                              last edited by 13 May 2010, 23:34

                              @chris fullmer said:

                              ... I got tired of looking at it so I took a new approach. ...

                              Thanks. I tried it; it works great. No bugs.

                              However, like the earlier versions, it creates an infinite cline in both directions, not a true ray that starts at a point and goes infinitely in one direction. That's not a problem, just a curiosity. (If it's not "supposed" to be that way, it may be related to the bug -- just guessing.)

                              Do you know why the cpoint at view.camera.eye is necessary? You don't appear to use the point. Is it a requirement for pickray to work? (Maybe the omission of a cpoint there is the source of the bug? More guessing.)

                              Thanks again.

                              β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
                              [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

                              1 Reply Last reply Reply Quote 0
                              • C Offline
                                Chris Fullmer
                                last edited by 13 May 2010, 23:56

                                The cpoint is not needed for the code. I just like to put it there so I can see exactly where the camera was.

                                As for the bug, I know that 7.1 added some sort of infinite line viewing bug. I thought it had been fixed, but maybe not? Or maybe we've uncovered another iteration of their bug. I noticed that clines are not clipping like they should. They do not appear to clip at the near clipping plane. i'm not sure if it has always worked that way. I really hate construction geometry, so I haven't used it enough to know how it used to behave compared to how it currently behaves.

                                But the part where you said that it still produces an infinite line instead of a ray, I think that is a known bug. I'll see if I can track down the info on that bug if you'd like.

                                Chris

                                Lately you've been tan, suspicious for the winter.
                                All my Plugins I've written

                                1 Reply Last reply Reply Quote 0
                                • A Offline
                                  August
                                  last edited by 14 May 2010, 01:03

                                  @chris fullmer said:

                                  ... But the part where you said that it still produces an infinite line instead of a ray, I think that is a known bug. I'll see if I can track down the info on that bug if you'd like.

                                  Thanks, but no need. It doesn't interfere with anything that I'm trying to do. I'm just curious.

                                  You have already been most helpful, and you've helped me get my feet wet in SketchUp Ruby again (after they'd dried out for nearly a year).

                                  And now that I've started wrestling with this, I've begun to appreciate your dislike/aversion for construction geometry. Modifying something that already exists is clearly much easier.

                                  Thanks again,
                                  August

                                  β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
                                  [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

                                  1 Reply Last reply Reply Quote 0
                                  • A Offline
                                    August
                                    last edited by 14 May 2010, 04:00

                                    @august said:

                                    [... if you activate the Select tool, it will not select. If you activate the Line tool, it will not draw. ...

                                    This bug is still there. Just to make it stranger, it seems to go away if you orbit, but if you return to the exact viewpoint, using either Previous View or a Scene, it appears to be stuck again.

                                    For example, with the Rectangle Tool active, the first InputPoint appears to be stuck at the Camera Eye. The second InputPoint will not go just anywhere, it appears to have to inference an object, just like when drawing a CLine. If you orbit away with Rectangle active, you can see that the first point is already set. If you press Escape, you can draw a normal rectangle, but if you return to the exact Eye view, that point is pre-picked again.

                                    Similarly for the Line tool. The first point is already picked and the only allowable lines are the ones that terminate on a pre-existing point.

                                    Clearly a bug.


                                    CLine InputPoint Bug.PNG

                                    β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
                                    [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

                                    1 Reply Last reply Reply Quote 0
                                    • C Offline
                                      Chris Fullmer
                                      last edited by 14 May 2010, 19:10

                                      August, are you saying the that the bug is still present in the most recent snippet I posted?

                                      Chris

                                      Lately you've been tan, suspicious for the winter.
                                      All my Plugins I've written

                                      1 Reply Last reply Reply Quote 0
                                      • A Offline
                                        August
                                        last edited by 14 May 2010, 20:59

                                        @chris fullmer said:

                                        August, are you saying the that the bug is still present in the most recent snippet I posted?

                                        Yes, the above image was generated using your newest snippet, unchanged.

                                        I load your snippet, saved as a separate .txt file, make a few clicks that generate the desired clines, and then when I select the rectangle tool, as described above, the first rectangle inputpoint seems locked to camera.eye and the second point will, in this drawing, only reference one of Sang's points.

                                        I can orbit, draw a normal rectangle, and when I return to the original view, using Previous View or my Scene, the first inputpoint is locked at camera.eye again and the second inputpoint will not reference anything except Sang.

                                        I am getting the lines I want, and I can work around that input point locking, but I do think this is a bug in SketchUp, probably in .add_cline, maybe in view.

                                        β€œAn idea, like a ghost, must be spoken to a little before it will explain itself.”
                                        [floatr:v1mcbde2]-- Charles Dickens[/floatr:v1mcbde2]

                                        1 Reply Last reply Reply Quote 0
                                        • C Offline
                                          Chris Fullmer
                                          last edited by 14 May 2010, 21:31

                                          I am starting to think it has to do with the way I am making an inputpoint with view.inputpoint(x,y ). I think I might need to look that over a little closer. I think I am messing something up with the IP associated to that view. I don't really undestand how IP points work behind the scenes, but I have a feeling the way I am calling it is messing things up. Might be a bug, or could just be un-intended usage of an input point. This is something I would like to understand better, so I'll try to figure it out this weekend (I have been excited about a few ruby projects lately, so I am spending some time on ruby again, it is fun!)

                                          Chris

                                          Lately you've been tan, suspicious for the winter.
                                          All my Plugins I've written

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

                                          Advertisement