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

Improve CAD viewer camera #3236

Open
je-cook opened this issue Apr 30, 2024 · 0 comments
Open

Improve CAD viewer camera #3236

je-cook opened this issue Apr 30, 2024 · 0 comments
Labels
cad Tasks relating to the cad module display enhancement New feature or request

Comments

@je-cook
Copy link
Contributor

je-cook commented Apr 30, 2024

Description of issue / requirement to address

Our freecad cad viewer has a slight hack in it that rotates the CAD instead of the camera of the viewer

Proposed solution

The camera can be accessed here:

viewer.setSceneGraph(root)

with some of the below dump of exploratory code being useful, its half translated from c++ ie the pointers dont work:

    camera = viewer.getSoEventManager().getCamera()
    cam_pos = camera.position.getValue().getValue()

    direction = (0, 0, -1)
    orient = s
    direction *= orient

    focal_point = cam_pos + camera.focalDistance.getValue() * direction

    # rotation_dist = camera.focalDistance.getValue() * coin.SbVec3f(0, 0, 1)
    # new_rot_cen = orient * = rotation_dist
    front_orient = np.sqrt(2) / 2

    orientation = (front_orient, 0, 0, front_orient)
    # // Distance from rotation center to camera position in camera coordinate system
    rotationCenterDistanceCam: SbVec3f = camera.focalDistance.getValue() * SbVec3f(
        0, 0, 1
    )

    # // Set to the given orientation
    camera.orientation = orientation

    # // Distance from rotation center to new camera position in global coordinate system
    newRotationCenterDistance: SbVec3f = camera.orientation.getValue().multVec(
        rotationCenterDistanceCam, newRotationCenterDistance
    )
    # // Reposition camera so the rotation center stays in the same place
    # // Optionally add translation to move to center

    camera.position = focal_point + newRotationCenterDistance

    # vprt = coin.SbViewportRegion()
    # action = coin.SoGetBoundingBoxAction(vprt)
    # root.getBoundingBox(action)
    # action.getBoundingBox().getSize().getValue()

With the above you need to remvoe the rotate=True from the viewer and the rotate argument completely as mentioned in #3235

Alternative solutions

leave as is, it does work.

Additional context

This may lead to us being able to specify the viewing angle say for an autogenerated image in future.

@je-cook je-cook added enhancement New feature or request cad Tasks relating to the cad module display labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cad Tasks relating to the cad module display enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant