shift + f to fit workspace contents immediate

This commit is contained in:
Stewart Allen 2025-12-14 20:52:06 -05:00
commit c61fadd68b
2 changed files with 12 additions and 19 deletions

View file

@ -227,10 +227,10 @@ class Orbit extends EventDispatcher {
this.setPosition = function(set) { this.setPosition = function(set) {
thetaSet = firstValue([set.left, set.theta, thetaSet]); thetaSet = firstValue([set.left, set.theta, thetaSet]);
phiSet = firstValue([set.up, set.phi, phiSet]); phiSet = firstValue([set.up, set.phi, phiSet]);
if (set.panX) this.target.x = set.panX; if (set.panX !== undefined) this.target.x = set.panX;
if (set.panY) this.target.y = set.panY; if (set.panY !== undefined) this.target.y = set.panY;
if (set.panZ) this.target.z = set.panZ; if (set.panZ !== undefined) this.target.z = set.panZ;
if (set.scale) scale = set.scale; if (set.scale !== undefined) scale = set.scale;
}; };
this.getPosition = function(scaled) { this.getPosition = function(scaled) {

View file

@ -1306,27 +1306,20 @@ let Space = {
const newPanZ = center.z; const newPanZ = center.z;
// First, tween to center the view on the object // First, tween to center the view on the object
tweenCam({ viewControl.setPosition({
left, left,
up: upAngle, up: upAngle,
panX: newPanX, panX: newPanX,
panY: newPanY, panY: newPanY,
panZ: newPanZ, panZ: newPanZ,
then: () => {
// After centering, adjust zoom to fit
// Calculate the actual current distance after recentering
const currentDist = camera.position.distanceTo(viewControl.getTarget());
const scale = desiredDistance / currentDist;
// Apply the zoom adjustment
viewControl.setPosition({ scale });
viewControl.update();
requestRefresh();
// Call user's callback if provided
if (then) then();
}
}); });
const currentDist = camera.position.distanceTo(viewControl.getTarget());
const scale = desiredDistance / currentDist;
viewControl.setPosition({ scale });
viewControl.update();
if (then) then();
}, },
setCtrl: (name) => { setCtrl: (name) => {
if (name === 'onshape') { if (name === 'onshape') {