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

Fix: Limit scale on widget on printing #623

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions src/app/models/ModelGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,18 @@ class ModelGroup extends EventEmitter {
};
}

shouldApplyScaleToObjects(scaleX, scaleY, scaleZ) {
return this.selectedGroup.children.every((meshObject) => {
if (scaleX * this.selectedGroup.scale.x * meshObject.scale.x < 0.01
|| scaleY * this.selectedGroup.scale.y * meshObject.scale.y < 0.01
|| scaleZ * this.selectedGroup.scale.z * meshObject.scale.z < 0.01
) {
return false; // should disable
}
return true;
});
}

updateSelectedGroupTransformation(transformation) {
const { positionX, positionY, rotationX, rotationY, rotationZ, scaleX, scaleY, scaleZ, width, height, uniformScalingState } = transformation;

Expand All @@ -928,24 +940,51 @@ class ModelGroup extends EventEmitter {
this.selectedGroup.position.setY(positionY);
}
if (this.selectedGroup.uniformScalingState === true) {
if (scaleX !== undefined) {
if (scaleX !== undefined && this.shouldApplyScaleToObjects(scaleX, scaleX, scaleX)) {
this.selectedGroup.scale.set(scaleX, scaleX, scaleX);
}
if (scaleY !== undefined) {
if (scaleY !== undefined && this.shouldApplyScaleToObjects(scaleY, scaleY, scaleY)) {
this.selectedGroup.scale.set(scaleY, scaleY, scaleY);
}
if (scaleZ !== undefined) {
if (scaleZ !== undefined && this.shouldApplyScaleToObjects(scaleZ, scaleZ, scaleZ)) {
this.selectedGroup.scale.set(scaleZ, scaleZ, scaleZ);
}
} else {
if (scaleX !== undefined) {
this.selectedGroup.scale.setX(scaleX);
const shouldApplyScaleToObjects = this.selectedGroup.children.every((meshObject) => {
if (scaleX * this.selectedGroup.scale.x * meshObject.scale.x < 0.01
) {
return false; // should disable
}
return true;
});
if (shouldApplyScaleToObjects) {
this.selectedGroup.scale.setX(scaleX);
}
}
if (scaleY !== undefined) {
this.selectedGroup.scale.setY(scaleY);
const shouldApplyScaleToObjects = this.selectedGroup.children.every((meshObject) => {
if (scaleY * this.selectedGroup.scale.y * meshObject.scale.y < 0.01
) {
return false; // should disable
}
return true;
});
if (shouldApplyScaleToObjects) {
this.selectedGroup.scale.setY(scaleY);
}
}
if (scaleZ !== undefined) {
this.selectedGroup.scale.setZ(scaleZ);
const shouldApplyScaleToObjects = this.selectedGroup.children.every((meshObject) => {
if (scaleZ * this.selectedGroup.scale.z * meshObject.scale.z < 0.01
) {
return false; // should disable
}
return true;
});
if (shouldApplyScaleToObjects) {
this.selectedGroup.scale.setZ(scaleZ);
}
}
}
if (uniformScalingState !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,12 @@ class VisualizerModelTransformation extends PureComponent {
transformation.positionY = value;
break;
case 'scaleX':
value = value < 0.01 ? 0.01 : value;
transformation.scaleX = value;
break;
case 'scaleY':
value = value < 0.01 ? 0.01 : value;
transformation.scaleY = value;
break;
case 'scaleZ':
value = value < 0.01 ? 0.01 : value;
transformation.scaleZ = value;
break;
case 'rotateX':
Expand Down