Added basic grid snapping.

This commit is contained in:
Michael Mainguy 2023-07-27 21:34:33 -05:00
parent ecf28deffc
commit fc588c5dbe

View File

@ -71,13 +71,24 @@ export class Base {
if (config.rotateSnap == 0) { if (config.rotateSnap == 0) {
return rotation; return rotation;
} }
rotation.x = this.calcDegreesToSnap(rotation.x, config.rotateSnap); rotation.x = this.CalcToSnap(rotation.x, config.rotateSnap);
rotation.y = this.calcDegreesToSnap(rotation.y, config.rotateSnap); rotation.y = this.CalcToSnap(rotation.y, config.rotateSnap);
rotation.z = this.calcDegreesToSnap(rotation.z, config.rotateSnap); rotation.z = this.CalcToSnap(rotation.z, config.rotateSnap);
return rotation; return rotation;
} }
static calcDegreesToSnap(val, snap) { static snapPosition(position): Vector3 {
const config = AppConfig.config;
if (config.gridSnap == 0) {
return position;
}
position.x = round(position.x, config.gridSnap);
position.y = round(position.y, config.gridSnap);
position.z = round(position.z, config.gridSnap);
return position;
}
static CalcToSnap(val, snap) {
const deg = Angle.FromRadians(val).degrees(); const deg = Angle.FromRadians(val).degrees();
const snappedDegrees = round(deg, snap); const snappedDegrees = round(deg, snap);
log.getLogger('Base').debug("deg", val, deg, snappedDegrees, snap); log.getLogger('Base').debug("deg", val, deg, snappedDegrees, snap);
@ -145,7 +156,8 @@ export class Base {
return; return;
} }
} }
const snapped = Base.snapRotation(mesh.absoluteRotationQuaternion.toEulerAngles().clone()); const snappedRotation = Base.snapRotation(mesh.absoluteRotationQuaternion.toEulerAngles().clone());
const snappedPosition = Base.snapPosition(mesh.absolutePosition.clone());
if (this.previousParent) { if (this.previousParent) {
const p = this.scene.getMeshById(this.previousParent); const p = this.scene.getMeshById(this.previousParent);
if (p) { if (p) {
@ -156,7 +168,8 @@ export class Base {
} }
} else { } else {
mesh && mesh.setParent(null); mesh && mesh.setParent(null);
mesh.rotation = snapped; mesh.rotation = snappedRotation;
mesh.position = snappedPosition;
} }
const entity = MeshConverter.toDiagramEntity(mesh); const entity = MeshConverter.toDiagramEntity(mesh);
const event: DiagramEvent = { const event: DiagramEvent = {