Skip to content

URDF manipulator only works with full-page viewer #304

@jurmy24

Description

@jurmy24

If I want to drag a component of the URDF file right now it doesn't do joint highlighting right where the component appears to be visually if the viewer component is not covering the entire viewport. If I hover my mouse elsewhere on the page though I might get joint hovering, which suggests that the mouses x and y coordinates are improperly translated to the manipulator.

I believe the issue is in this code in URDFDragControls.js:

function updateMouse(e) {
    mouse.x = ((e.pageX - domElement.offsetLeft) / domElement.offsetWidth) * 2 - 1;
    mouse.y = -((e.pageY - domElement.offsetTop) / domElement.offsetHeight) * 2 + 1;
}        

e.pageX and e.pageY: These event properties give the mouse cursor's coordinates relative to the top-left corner of the entire HTML document. They account for page scrolling.

domElement.offsetLeft and domElement.offsetTop: These element properties give the distance from the element's outer border to the inner border of its offsetParent.

The offsetParent is not necessarily the main document body or the viewport. It could be any containing div or other element that establishes a positioning context.

The calculation subtracts offsetLeft (relative to offsetParent) from pageX (relative to the document). This subtraction only gives the correct mouse position relative to the domElement under very specific conditions:

  • The domElement's offsetParent must be the element (or another element positioned exactly at the document's top-left corner).
  • There must be no page scrolling involved (or the calculation needs further adjustments for scroll offsets, which this code lacks).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions