Sketcher: Sketch autoscale (#21084)
* Working scale prototype * Call viewAll to fit geometries in the viewport post-scaling * Exclude angle dimensions * Scale the viewport rather than calling viewAll * Scale dimension annotation along geometries * Early return when counting more than one dimensional constraint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Disable sketch autoscale if there are external geometries in the sketch * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add a setting to disable the feature _ and eventually parametrize * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Check for objects in the viewport in the sketch's ancestry to decide wheter or not to autoscale * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More consistent camera scaling * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Check for visual indicator in the whole document * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Find visible items in nested assemblies * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Check visual elements in assemblies nested in assemblies * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Set the dimension even if the scaling fails * Allow constraints that interact with the origin axis/root * Remove unused variable * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Misc fixes from review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -606,16 +606,30 @@ void NavigationStyle::boxZoom(const SbBox2s& box)
|
||||
// Set height or height angle of the camera
|
||||
float scaleX = (float)sizeX/(float)size[0];
|
||||
float scaleY = (float)sizeY/(float)size[1];
|
||||
float scale = std::max<float>(scaleX, scaleY);
|
||||
if (cam->getTypeId() == SoOrthographicCamera::getClassTypeId()) {
|
||||
float height = static_cast<SoOrthographicCamera*>(cam)->height.getValue() * scale;
|
||||
static_cast<SoOrthographicCamera*>(cam)->height = height;
|
||||
}
|
||||
else if (cam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) {
|
||||
float height = static_cast<SoPerspectiveCamera*>(cam)->heightAngle.getValue() / 2.0f;
|
||||
height = 2.0f * atan(tan(height) * scale);
|
||||
static_cast<SoPerspectiveCamera*>(cam)->heightAngle = height;
|
||||
float scaleFactor = std::max<float>(scaleX, scaleY);
|
||||
|
||||
doScale(cam, scaleFactor);
|
||||
}
|
||||
void NavigationStyle::scale(float factor)
|
||||
{
|
||||
SoCamera* cam = viewer->getSoRenderManager()->getCamera();
|
||||
if (!cam) { // no camera
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the current center of the screen
|
||||
SbVec3f direction;
|
||||
cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
|
||||
SbVec3f initCenter = cam->position.getValue() + cam->focalDistance.getValue() * direction;
|
||||
|
||||
// Move the camera to the origin for scaling
|
||||
cam->position = cam->position.getValue() - initCenter;
|
||||
|
||||
// Scale the view
|
||||
doScale(cam, factor);
|
||||
|
||||
// Move the camera back to it's initial position scaled
|
||||
cam->position = cam->position.getValue() + initCenter * factor;
|
||||
}
|
||||
|
||||
void NavigationStyle::viewAll()
|
||||
@@ -954,7 +968,18 @@ void NavigationStyle::doZoom(SoCamera* camera, float logfactor, const SbVec2f& p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationStyle::doScale(SoCamera * cam, float factor)
|
||||
{
|
||||
if (cam->getTypeId() == SoOrthographicCamera::getClassTypeId()) {
|
||||
float height = static_cast<SoOrthographicCamera*>(cam)->height.getValue() * factor;
|
||||
static_cast<SoOrthographicCamera*>(cam)->height = height;
|
||||
}
|
||||
else if (cam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) {
|
||||
float height = static_cast<SoPerspectiveCamera*>(cam)->heightAngle.getValue() / 2.0f;
|
||||
height = 2.0f * atan(tan(height) * factor);
|
||||
static_cast<SoPerspectiveCamera*>(cam)->heightAngle = height;
|
||||
}
|
||||
}
|
||||
void NavigationStyle::doRotate(SoCamera * camera, float angle, const SbVec2f& pos)
|
||||
{
|
||||
SbBool zoomAtCur = this->zoomAtCursor;
|
||||
|
||||
Reference in New Issue
Block a user