Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior of inference locking with two inputpoints #1011

Open
Eneroth3 opened this issue Nov 14, 2024 · 1 comment
Open

Unexpected behavior of inference locking with two inputpoints #1011

Eneroth3 opened this issue Nov 14, 2024 · 1 comment

Comments

@Eneroth3
Copy link

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
@Eneroth3
Copy link
Author

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

@Eneroth3 Eneroth3 changed the title Unexpected behavior f inference locking with two inputpoints Unexpected behavior of inference locking with two inputpoints Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant