InputPoint and snapping
-
I've been toying with the idea of mimicing AutoCAD by using PickHelper (instead of InputPoint.)
There are times when you really want to control the Osnap point, in the old way.
-
Yea, you have to make you own Inputpoint to control what you snap to. For BezierSurface I'm doing that so I can snap to the Bezier control point. The Bezier control points gets priority first, then if none are picked it uses an InputPoint.
-
@thomthom said:
Yea, you have to make you own Inputpoint to control what you snap to. For BezierSurface I'm doing that so I can snap to the Bezier control point. The Bezier control points gets priority first, then if none are picked it uses an InputPoint.
Is there any chance that we can share it with us? I'm trying to do it but it's quite a bitch. Namely translate the mouse 2d coordinate (x,y) into 3d coordinate.
-
@jorat1346 said:
I'm trying to do it but it's quite a bitch. Namely translate the mouse 2d coordinate (x,y) into 3d coordinate.
I just use the PickHelper class to get the various entities under the mouse. http://code.google.com/apis/sketchup/docs/ourdoc/pickhelper.html
-
@jorat1346 said:
@thomthom said:
Yea, you have to make you own Inputpoint to control what you snap to. For BezierSurface I'm doing that so I can snap to the Bezier control point. The Bezier control points gets priority first, then if none are picked it uses an InputPoint.
Is there any chance that we can share it with us? I'm trying to do it but it's quite a bitch. Namely translate the mouse 2d coordinate (x,y) into 3d coordinate.
The whole inputpoint and pickhelper things etc are designed to help you to do this BUT you must do it with a 'Tool' that you define as a new class with the required appropriate 'special' def methods like initialize(). activate(), onMouseMove(), draw() etc etc... See the linetool.rb et al example that comes with SUp... You then activate the tool from a menu item [or toolbar or whatever] and it does your bidding...
-
@thomthom said:
@jorat1346 said:
I'm trying to do it but it's quite a bitch. Namely translate the mouse 2d coordinate (x,y) into 3d coordinate.
I just use the PickHelper class to get the various entities under the mouse. http://code.google.com/apis/sketchup/docs/ourdoc/pickhelper.html
That doesn't work well enough for me. :S
@tig said:
The whole inputpoint and pickhelper things etc are designed to help you to do this BUT you must do it with a 'Tool' that you define as a new class with the required appropriate 'special' def methods like initialize(). activate(), onMouseMove(), draw() etc etc... See the linetool.rb et al example that comes with SUp... You then activate the tool from a menu item [or toolbar or whatever] and it does your bidding...
Humm yeah, it's already what I'm doing.
You see, what I'm really trying to do is to make a tool similar to the rotation tool (protractor). The problem is that when I move the mouse around to pick an angle, it keep on snapping on about anything principally because of the "From Point" snapping. So to disable that, it seen for now that I have to make my own version of InputPoint so I can adjust the behavior to what I want.
Right now, I'm at trying to get the transformation matrix of the view which doesn't seem to be easy to get. So I have two choices here: either I try to remake all the math behind or try to find that matrix using a series of coordinate obtained with view.screen_coords. This matrix will allowed me to project a 2d mouse coordinate on a 3d plane which will be perfect to find an angle.
-
PickHelper does not use snapping. InputPoint does.
-
@dan rathbun said:
PickHelper does not use snapping. InputPoint does.
Yes, but if you want to make your own custom InputPoint class that let you snap to what you want you'll need PickHelper to get the entities under the cursor.
-
@dan rathbun said:
PickHelper does not use snapping. InputPoint does.
I totally understand that, but PickHelper doesn't have the .position function that InputPoint have and that I desperately need.
-
@jorat1346 said:
I totally understand that, but PickHelper doesn't have the .position function that InputPoint have and that I desperately need.
ray = view.pickray result = model.raytest( ray )
http://code.google.com/apis/sketchup/docs/ourdoc/view.html#pickray
http://code.google.com/apis/sketchup/docs/ourdoc/model.html#raytest -
If you are trying to get a picked_point onto a 'plane' you use
point.project_to_plane
.
If you are mimicking the 'Rotate Tool' then before you get to that step you will pick a center_point [which is by definition on that plane].
You will next set the axis/normal for the rotation [which is a vector needed to define the plane]...
You define a plane asplane=[center_point, normal_vector]
...
So now you have everything you need to project the next picked_point onto that plane...When you take a mouse_click event the returned view inputpoint can be used to return a Point3d [ip.position] AND with a view pick_helper an entity type [or even types using several pick_helpers] - e.g. an edge or a face.
If your code somehow destroys the inputpoint [?] then clone it with a 'copy' before hand and use the copy in your second bit of code...
So you can click and return a point in the model and object(s) at that point.
A bit of simple math will transform that point onto a predetermined 'plane' as explained above...
Advertisement