In my recent discoveries of the SU Ruby, I’ve been literally “faced” with the following inconsistency, what I would like to understand. I’ll give a possible solution too, but still, I want to understand what’s going on…
I can’t tell it is a bug or not, but confused me lot and takes 3 days to identify.
My question can be also shortened like this:
Why do I get Sketchup::InputPoint #face object, if the input point is getting its position NOT from a face? The cursor is above the face, but for sure, the input point is not getting its position from that face!
I’ll try to explain.
Background:
“The face method retrieves the face if the input point is getting its position from a face.”
"If you are using the edge, face or vertex method on the InputPoint though, you will probably need to use the transformation method to transform the data that you get back from the selected entity."
Phenomenon:
So if your cursor above the face you will get a Sketchup::InputPoint#face and Sketchup::InputPoint#transformation. The transformation should be related to face since the input point is getting its position from a face. Right?
In most cases, yes. But… It seam to be the InputPoint is still getting the #face object even getting its position NOT from a face but edge or vertex of the face. (or other Inference !) Then the #transformation will be different than the transformation of the face. The inconsistency is here. The InputPoint transformation showing his real transformation (out of the face, but above in screen 2D) but to confuse, still giving you #face object too. You have to think, okay, "I have an @ip.face then the transformation will match to tat face… And if so, why not? "
Reproduce:
Let’s create a face and put it into a group. To show my “problem” it should not be parallel to “main” planes. (test_face.skp attached.)
test_face (1).skp (16.8 KB)
Copy-paste my dirty code to console, position your mouse… and you can see the questionable face id’s and transformations on your screen top left corner.
In this picture it is clear, that the input point getting its position from a point “far away” from the face, but you still get the face object. The ip.transformation is IDENTITY, but the face transformation should be the transformation what you get by pick helper method.
class Tool_test_ipface
###dirty!!###
def initialize
@ip = Sketchup::InputPoint.new
end
def onMouseMove(flags, x, y, view)
@ip.pick(view, x, y)
# get the face and transformation by ip
@ip_face = @ip.face
@tr_ip_face = @ip.transformation
# get the face and transformation by pick_helper
# this is a possible method to get the right transformation for the face under cursor
ph = view.pick_helper
ph.do_pick(x, y, 0)
@ph_face = ph.picked_face
if( @ph_face )
ph.count.times{|i|
if ph.leaf_at(i) == @ph_face
@tr_ph_face = ph.transformation_at(i)
end
}
end
view.invalidate
end
def draw(view)
@ip.draw(view)
view.line_width = 3
view.tooltip = @ip.tooltip
#just to see where are we...
view.draw_points( @ip.position, 15, 1, "peru" ) if @ip
# display the face_id:
view.draw_text((view.corner 0), " ip Face: " + @ip_face.to_s ) if @ip_face
view.draw_text((view.corner 0), "\n ph Face: " + @ph_face.to_s ) if @ph_face
# display the transformation matrix:
view.draw_text((view.corner 0), "\n\n iF tr: " + @tr_ip_face.to_a.to_s ) if @ip_face
view.draw_text((view.corner 0), "\n\n\n pF tr: " + @tr_ph_face.to_a.to_s ) if @ph_face
end
end
Sketchup.active_model.select_tool(Tool_test_ipface.new)
This behavior can be mentioned in the documentation and/or reported as a bug? Don’t you think? Or can it be explained on other way?
(At least it might be useful for others…)