Skip to content

Commit 8861b23

Browse files
author
mmiscool
committed
Fix hand drawn sketch functionality to work regardless of camera orientation.
1 parent bd96712 commit 8861b23

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/UI/sketcher/SketchMode3D.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,16 +1358,27 @@ export class SketchMode3D {
13581358
if (!c || !s || !e) return false;
13591359
if (Math.hypot(s.u - e.u, s.v - e.v) < 1e-6) return false;
13601360
const cId = this.#createPointAtUV(c.u, c.v, false);
1361-
// Swap start/end to match sketcher arc direction expectations.
1362-
const sId = this.#createPointAtUV(e.u, e.v, false);
1363-
const eId = this.#createPointAtUV(s.u, s.v, false);
1361+
const viewIsMirrored = this.#isViewingSketchFromBackSide();
1362+
const arcStart = viewIsMirrored ? e : s;
1363+
const arcEnd = viewIsMirrored ? s : e;
1364+
const sId = this.#createPointAtUV(arcStart.u, arcStart.v, false);
1365+
const eId = this.#createPointAtUV(arcEnd.u, arcEnd.v, false);
13641366
if (cId == null || sId == null || eId == null) return false;
13651367
this.#addGeometry("arc", [cId, sId, eId]);
13661368
return { type: "arc", pointIds: [cId, sId, eId], endpointIds: [sId, eId] };
13671369
}
13681370
return false;
13691371
}
13701372

1373+
#isViewingSketchFromBackSide() {
1374+
const cam = this.viewer?.camera;
1375+
const basis = this._lock?.basis;
1376+
if (!cam || !basis?.origin || !basis?.z) return false;
1377+
const viewOffset = cam.position.clone().sub(basis.origin);
1378+
if (viewOffset.lengthSq() < 1e-12) return false;
1379+
return viewOffset.dot(basis.z) > 0;
1380+
}
1381+
13711382
#createBezierFromStroke(points) {
13721383
if (!Array.isArray(points) || points.length < 2) return false;
13731384
const uvPts = [];

0 commit comments

Comments
 (0)