api-issue-tracker
api-issue-tracker copied to clipboard
Unexpected behavior of inference locking with two inputpoints
The Ruby API docs state the following.
# Lock inference to X axis. # The points can be anywhere; only the vector between them affects # the result. view.lock_inference( Sketchup::InputPoint.new(ORIGIN), Sketchup::InputPoint.new(Geom::Point3d.new(1, 0, 0)) )
This is untrue. The points define a line in space that inference is locked to. Not just a vector.
This tool can only lock inference onto the model coordinate axes, not parallel to the axes as the comment suggests.
class TestTool
def initialize
@ip = Sketchup::InputPoint.new
end
def draw(view)
@ip.draw(view)
end
def onKeyDown(key, _repeat, _flags, _view)
case key
when VK_RIGHT
lock_axis(0)
when VK_LEFT
lock_axis(1)
when VK_UP
lock_axis(2)
end
end
def onKeyUp(key, _repeat, _flags, _view); end
def onLButtonDown(flags, x, y, view); end
def onMouseMove(flags, x, y, view)
@x = x
@y = y
do_pick(view)
end
private
# Extracting the picking from mouse move allows the input point to be updated
# immediately once the inference lock is released.
def do_pick(view)
# May get called as tool is activated, before the first mouse event
return unless @x
return unless @y
@ip.pick(view, @x, @y)
view.tooltip = @ip.tooltip
view.invalidate
end
# Lock the tool inference to a drawing axis.
#
# @param axis_i [0, 1, 2] 0 = red, 1 = green, 2 = blue
def lock_axis(axis_i)
model = Sketchup.active_model
direction = model.axes.axes[axis_i]
model.active_view.lock_inference(
Sketchup::InputPoint.new(ORIGIN),
Sketchup::InputPoint.new(ORIGIN.offset(direction))
)
end
# Lock the tool inference to what is currently hovered.
def lock_hovered
Sketchup.active_model.active_view.lock_inference(@ip)
end
# Unlock any tool inference
def unlock
view = Sketchup.active_model.active_view
view.lock_inference
do_pick(view)
end
end
Sketchup.active_model.select_tool(TestTool.new)
If you change the inference lock to use the input point from the mouse cursor, you can lock along the line the inputpoint is on, as you would expand from a SketchUp tool.
class TestTool
def lock_axis(axis_i)
model = Sketchup.active_model
direction = model.axes.axes[axis_i]
### model.active_view.lock_inference(
### Sketchup::InputPoint.new(ORIGIN),
### Sketchup::InputPoint.new(ORIGIN.offset(direction))
### )
model.active_view.lock_inference(
@ip,
Sketchup::InputPoint.new(@ip.position.offset(direction))
)
end
end
Observed behavior goes back to SketchUp 6, suggesting this is a documentation issue and not a regression.
(For SketchUp prior to 2017, replace model.axes.axes with [X_AXIS, Y_AXIS, Z_AXIS].)