activate grid button and widget size
This commit is contained in:
@@ -545,12 +545,37 @@ void vtkHandlerWidget::UpdateGizmoPosition() {
|
||||
if (!this->Prop3D)
|
||||
return;
|
||||
|
||||
// Calculate scaling factor: min(object_bbox, 1/5 of viewport)
|
||||
double bboxSize = 1.0;
|
||||
double bounds[6];
|
||||
this->Prop3D->GetBounds(bounds);
|
||||
if (vtkMath::AreBoundsInitialized(bounds)) {
|
||||
bboxSize = std::max({bounds[1] - bounds[0], bounds[3] - bounds[2], bounds[5] - bounds[4]});
|
||||
}
|
||||
if (bboxSize < 1e-6) bboxSize = 1.0;
|
||||
|
||||
double screenLimit = bboxSize * 2.0; // Default if no renderer
|
||||
if (this->CurrentRenderer) {
|
||||
int *sz = this->CurrentRenderer->GetSize();
|
||||
if (sz[1] > 0) {
|
||||
double pixelSize = std::min(sz[0], sz[1]) / 5.0;
|
||||
vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
|
||||
if (cam->GetParallelProjection()) {
|
||||
screenLimit = (pixelSize / (double)sz[1]) * 2.0 * cam->GetParallelScale();
|
||||
} else {
|
||||
double dist = cam->GetDistance();
|
||||
double angleRad = vtkMath::Pi() * cam->GetViewAngle() / 180.0;
|
||||
double viewHeightAtDist = 2.0 * dist * tan(angleRad / 2.0);
|
||||
screenLimit = (pixelSize / (double)sz[1]) * viewHeightAtDist;
|
||||
}
|
||||
}
|
||||
}
|
||||
double scaleFactor = std::min(bboxSize, screenLimit);
|
||||
|
||||
vtkNew<vtkMatrix4x4> mat_gizmo;
|
||||
mat_gizmo->Identity();
|
||||
|
||||
double center[3];
|
||||
double bounds[6];
|
||||
this->Prop3D->GetBounds(bounds);
|
||||
center[0] = (bounds[0] + bounds[1]) / 2.0;
|
||||
center[1] = (bounds[2] + bounds[3]) / 2.0;
|
||||
center[2] = (bounds[4] + bounds[5]) / 2.0;
|
||||
@@ -602,6 +627,13 @@ void vtkHandlerWidget::UpdateGizmoPosition() {
|
||||
mat_gizmo->SetElement(2, 3, center[2]);
|
||||
}
|
||||
|
||||
// Apply scaleFactor to the gizmo matrix (only top-left 3x3)
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
mat_gizmo->SetElement(i, j, mat_gizmo->GetElement(i, j) * scaleFactor);
|
||||
}
|
||||
}
|
||||
|
||||
m_AxesX->SetUserMatrix(mat_gizmo);
|
||||
m_AxesY->SetUserMatrix(mat_gizmo);
|
||||
m_AxesZ->SetUserMatrix(mat_gizmo);
|
||||
@@ -635,6 +667,7 @@ void vtkHandlerWidget::UpdateGizmoPosition() {
|
||||
// Orient RotCam actor to face 'dir'
|
||||
vtkNew<vtkTransform> tcam;
|
||||
tcam->PostMultiply();
|
||||
tcam->Scale(scaleFactor, scaleFactor, scaleFactor);
|
||||
// Default circle is in XY plane (Normal Z: 0,0,1)
|
||||
double z[3] = {0, 0, 1};
|
||||
double cross[3];
|
||||
|
||||
Reference in New Issue
Block a user