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

Sketcher: Infinite axes #12319

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

Conversation

LemonBoy
Copy link
Contributor

@LemonBoy LemonBoy commented Feb 9, 2024

Resize the axes according to the viewport size so that they appear as infinite.

The implementation is trivial, let me know if I've overlooked something.

The previous auto-resizing behaviour is now gone for good, the machinery to compute the sketch BB is still there so re-adding this option is easily done if needed.

@github-actions github-actions bot added the Mod: Sketcher Related to the Sketcher Workbench label Feb 9, 2024
Copy link
Contributor

@PaddleStroke PaddleStroke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a preference to keep current behavior. No one asked for it and it would be a cluttering preference imo.

src/Mod/Sketcher/Gui/ViewProviderSketch.cpp Outdated Show resolved Hide resolved
src/Mod/Sketcher/Gui/ViewProviderSketch.cpp Outdated Show resolved Hide resolved
src/Mod/Sketcher/Gui/EditModeCoinManager.cpp Outdated Show resolved Hide resolved
@@ -3295,6 3295,27 @@ void ViewProviderSketch::camSensCB(void* data, SoSensor*)
vp->onCameraChanged(cam);
}

Base::Vector3d ViewProviderSketch::getCamCenterInSketchCoordinates(const Gui::View3DInventorViewer* viewer) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should not be required. You should be able to access the one that the grid is using : GridExtensionP::getCamCenterInSketchCoordinates()
If you can't access this function, then move it to somewhere that makes sense so that you can access it. But I think you should be able to with pImpl->getCamCenterInSketchCoordinates()
As a bonus you won't need viewer if you use this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I have just tried and you can't access it because pImpl is private. So you need to make a function in ViewProviderGridExtension to access it. Basically :

ViewProviderGridExtension:: getCamCenterInSketchCoordinates(){
 return pImpl->getCamCenterInSketchCoordinates();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or the function can be moved to ViewProviderGridExtension, I don't know if pImpl has access to ViewProviderGridExtension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't couple this with the ViewProviderGridExtension machinery as the latter, as the name implies, has to do with handling/drawing the grid.
The method name is also misleading as it's not really sketcher-specific.

Perhaps this function could be moved to a common module (where?) and be used by both the axis and the grid sizing mechanisms.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually ViewProviderSketch is a ViewProviderGridExtension (derives from it). So there no reason you wouldn't access its functions.
Yes the name is not strictly ideal as the gris has been separated from VPSketch. You can rename it something like : getCamCenterIn2DObjectCoordinates.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Well it is indeed harder than it seems.
Then I think the function should be in core in viewInventor

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah but wait I'm dumb, I wrote exactly what you need in my assembly PR :
View3DInventorViewer::getPointOnXYPlaneOfPlacement
https://github.com/FreeCAD/FreeCAD/pull/10764/files

And this assembly PR is planed to merge very soon (it was to merge yesterday but had a conflict). So if you wait a few days you can then make a new function :
getCamCenterOnXYPlaneOfPlacement() that pass the cam cetner to getPointOnXYPlaneOfPlacement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome news, I'll wait 'till the PR is merged then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LemonBoy 10764 merged yesterday. If you rebase you'll have access to this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up. I took the chance to address another problem that I've also seen when using the grid, for some "weird" camera orientations the axis length was too short because it didn't take into account the perspective.

The new method seems to work fine, I'm now worried about the computational cost as the camera sensor callback runs continuously.

Gui::View3DInventorViewer* viewer = view->getViewer();

// Add 50% to be sure the whole viewport is covered.
const float halfAxisLength = 1.5f * viewer->getMaxDimension() / 2.f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is imo needless computation. Be 50 or 75% it doesn't change anything. So :
const float halfAxisLength = viewer->getMaxDimension();

LemonBoy and others added 8 commits February 14, 2024 09:54
Resize the axes according to the viewport size so that they appear as
infinite.
When the sketch is rotated or shifted from the origin we need some
further adjustments.
Find the correct size by projecting the viewport onto the sketch plane.
@chennes chennes self-assigned this Feb 15, 2024
Attach the cameraSensor SoSensor to the actual camera node instead of
the whole scene, avoids lots of spurious updates when the camera is not
moving at all.
@LemonBoy
Copy link
Contributor Author

With the latest commit the redraw code is called less times and is actually correct even in presence of perspective distortion, see the image below to see how the grid boundaries stop before the viewport boundaries.

preview

There's still some room for optimization, the plan is to create a specialized SoSensor to detect the camera movement with thresholding and the likes (as it's already done by the GridExtension module) to be reused in the sketcher view for both the grid and the axes.

Abstracting the viewport projection to its own routine is also something I'd do as it may be useful for other features and to "fix" the computation of the grid size.

As usual, suggestions are welcome.

@maxwxyz
Copy link
Collaborator

maxwxyz commented Feb 16, 2024

Fixes #8675 as well? @FlachyJoe

@FlachyJoe
Copy link
Contributor

@maxwxyz Yes! 😃

@LemonBoy LemonBoy marked this pull request as draft February 16, 2024 10:00
@maxwxyz
Copy link
Collaborator

maxwxyz commented Feb 16, 2024

LemonBoy and others added 4 commits February 16, 2024 17:58
It turns out there was a missing piece, namely the final transform, to
make the viewport projection work.
Attach the sensor to the camera to reduce the amount of calls to the
camera update callback.

Handle the camera object destruction in the best possible way given the
few tools provided by Coin3D.
@LemonBoy
Copy link
Contributor Author

The latest changes fix the projection problems I've noticed and greatly reduces the axis recomputation.

The graphical results are good in orthographic mode, in perspective mode there are still some problems that also affect the grid, don't know if we can consider that as a blocker for merging.

The amount of times the sensor callback is invoked is much less than before.

Please give this a try and report back if you see any problem.

@maxwxyz maxwxyz linked an issue Feb 25, 2024 that may be closed by this pull request
2 tasks
@maxwxyz
Copy link
Collaborator

maxwxyz commented Apr 27, 2024

Any news on this, should this still be in draft or is this ready?

@maxwxyz
Copy link
Collaborator

maxwxyz commented May 15, 2024

@LemonBoy also a ping on this PR:
If you want this draft PR to be considered for a version 1.0 release, it should be marked ready for review by Monday, 2024-06-03 at the latest. (further details in the 1.0 feature freeze forum announcement).

@maxwxyz maxwxyz added this to the Post 1.0 milestone Jul 8, 2024
@BernhardSchiffner
Copy link

Please consider this as a real bug which should be solved before 1.0

The reasoning:
In sketcher you can't snap points of a curve (arc, line, ...) to be coincident with the axis, if the axis is not visible.

Think of making some sketch in full resolution and go on with adding something bigger outside by zooming out first.
No snap / automatic coincidence to axes is now possible and this way something very basic is missing.

Tested with self compiled FreaCad as of 2024-07-27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mod: Sketcher Related to the Sketcher Workbench
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Problem] Sketch axis size should follow zoom level
6 participants