KittyCAD / modeling-app

The KittyCAD modeling app.
https://kittycad.io/modeling-app/download
MIT License
422 stars 35 forks source link

sketch mode camera out of sync with Jordan's code #3307

Closed Irev-Dev closed 2 months ago

Irev-Dev commented 3 months ago

If you go into sketch mode with Jordan's cod below (besides the fact that it doesn't draw some of the arcs properly). Camera pans stop staying in sync with the engine camera.

const gearRadius = 1
const nTeeth = 20

const toothSketch = startSketchOn('XY')
  |> startProfileAt([0, gearRadius], %)
  |> arc({
       angleStart: 90,
       angleEnd: 90 + 180 / pi() * asin(0.7376425 / gearRadius),
       radius: gearRadius
     }, %, $arc1)
  |> angledLine({
       angle: 180 / pi() * asin(0.7376425 / gearRadius),
       length: 0.0001
     }, %)
  |> tangentialArc({
       offset: 70 - (180 / pi() * asin(0.7376425 / gearRadius)),
       radius: 0.389854023
     }, %, $arc2)
  |> xLineTo(-0.04, %)
const arc1_end_x = segEndX(arc1)
const arc1_end_y = segEndY(arc1)
const arc2_end_x = segEndX(arc2)
const arc2_end_y = segEndY(arc2)
const arc1_end_angle = segAng(arc1)
const arc2_end_angle = segAng(arc2)

const debugSketch = startSketchOn("XY")
  |> startProfileAt([arc2_end_x, arc2_end_y], %)
  |> angledLine({ angle: arc2_end_angle, length: 1 }, %)

// const debugSketch2 = startSketchOn("XY")
//   |> startProfileAt([arc1_end_x, arc1_end_y], %)
//   |> angledLine({ angle: arc2_end_angle, length: 1 }, %)

const debugSketch3 = startSketchOn("XY")
  |> startProfileAt([arc1_end_x, arc1_end_y + gearRadius], %)
  |> arc({
       angleStart: 90,
       angleEnd: 90 + 180 / pi() * asin(0.7376425 / gearRadius),
       radius: gearRadius
     }, %)
  |> angledLine({
       angle: 65+180 / pi() * asin(0.7376425 / gearRadius),
       length: 0.0001
     }, %)
  |> tangentialArc({
       offset: -1*(70 - (180 / pi() * asin(0.7376425 / gearRadius))),
       radius: 0.389854023
     }, %)
Irev-Dev commented 3 months ago

Not sure where this one might lead, we may or may not need to pair, we can talk about it tomorrow @nadr0

Irev-Dev commented 2 months ago

I have a feeling this is related to the XY plane, i.e. might not be reproducible if the plane is changed to XZ etc.

nadr0 commented 2 months ago

I have a feeling this is related to the XY plane, i.e. might not be reproducible if the plane is changed to XZ etc.

I believe you are correct. I was able to recreate this with my own KCL code. I do not think it is specific to Jordan's code. It is something specific with XY planes.

The engine command flow looks like

enable_sketch_mode
default_camera_get_settings
default_camera_set_orthographic
default_camera_look_at <-- throws massive errors for XY planes. 

My sample KCL code

// Swap 'XY' for the different permutations
const sketch001 = startSketchOn('XY')
  |> startProfileAt([0.12, 0.03], %)
  |> line([-0.03, 1.02], %)
  |> line([1.06, 0.03], %)
planes engine + edit sketch synced
-XY :x:
XY :x:
-XZ :heavy_check_mark:
XZ :heavy_check_mark:
-YZ :heavy_check_mark:
YZ :heavy_check_mark: