Skip to content

Commit 3297f23

Browse files
#7740 Extra segment UX improvements (#7786)
* convert extraSegment ui to dom from three.js, move it further from start point of a segment * hide extraSegmentGroup is segment is shorter than 130px in screen space pixels, otherwise UI would be too crammed * wip re-add mesh for drag interaction * fmt * match extraSegment color with line segment color, cleanups * dont show extrasegment if TangentialArc is length is below threshold * lint * circular deps, take1 * Update snapshots * circular deps, take 2 * fix test: extra segment point moved away so the drag is not creating a new line anymore * fix png url for playwright * Update snapshots * Update snapshots * make multi profile sketching test match main, this got broken on the PR because of EXTRA_SEGMENT_OFFSET_PX now being 20, but the original test seems very flakey anyway * Update snapshots --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 33e41fb commit 3297f23

File tree

13 files changed

+130
-85
lines changed

13 files changed

+130
-85
lines changed

e2e/playwright/sketch-tests.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,7 @@ sketch001 = startSketchOn(XZ)
812812
await editor.expectEditor.toContain(
813813
`sketch001 = startSketchOn(XZ)
814814
|> startProfile(at = [8.41, -9.97])
815-
|> line(end = [12.73, -0.09])
816-
|> line(end = [1.99, 2.06])
815+
|> line(end = [14.72, 1.97])
817816
|> tangentialArc(endAbsolute = [24.95, -5.38])
818817
|> close()
819818
|> revolve(axis = X)`,
@@ -2123,7 +2122,7 @@ profile003 = startProfile(sketch001, at = [206.63, -56.73])
21232122
await page.waitForTimeout(300)
21242123

21252124
// select end of profile again
2126-
await endLineStartTanArc()
2125+
await endArcStartLine()
21272126
await page.waitForTimeout(300)
21282127

21292128
// Define points for the three-point arc
90 Bytes
Loading
Lines changed: 4 additions & 0 deletions
Loading
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Loading

src/clientSideScene/sceneConstants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const PROFILE_START = 'profile-start'
4444
export const DRAFT_DASHED_LINE = 'draft-dashed-line'
4545

4646
// Measurements
47-
export const EXTRA_SEGMENT_OFFSET_PX = 8
47+
export const EXTRA_SEGMENT_OFFSET_PX = 20
4848
export const SEGMENT_WIDTH_PX = 1.6
4949
export const HIDE_SEGMENT_LENGTH = 75
5050
export const HIDE_HOVER_SEGMENT_LENGTH = 60
@@ -70,6 +70,10 @@ export const ARC_SEGMENT_TYPES = [
7070
ARC_SEGMENT,
7171
]
7272

73+
// Colors
74+
export const SEGMENT_YELLOW = 0xffff00
75+
export const SEGMENT_BLUE = 0x0000ff
76+
7377
// Helper functions
7478
export function getParentGroup(
7579
object: any,

src/clientSideScene/sceneEntities.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
OrthographicCamera,
1818
PerspectiveCamera,
1919
PlaneGeometry,
20-
Points,
2120
Shape,
2221
Vector2,
2322
Vector3,
@@ -67,6 +66,8 @@ import {
6766
THREE_POINT_ARC_HANDLE3,
6867
THREE_POINT_ARC_SEGMENT,
6968
getParentGroup,
69+
SEGMENT_BLUE,
70+
SEGMENT_YELLOW,
7071
} from '@src/clientSideScene/sceneConstants'
7172
import type {
7273
OnClickCallbackArgs,
@@ -158,6 +159,7 @@ import {
158159
updateRectangleSketch,
159160
} from '@src/lib/rectangleTool'
160161
import type RustContext from '@src/lib/rustContext'
162+
import { updateExtraSegments } from '@src/lib/selections'
161163
import type { Selections } from '@src/lib/selections'
162164
import { getEventForSegmentSelection } from '@src/lib/selections'
163165
import type { Themes } from '@src/lib/theme'
@@ -861,7 +863,6 @@ export class SceneEntities {
861863
pathToNode: segPathToNode,
862864
isDraftSegment,
863865
scale,
864-
texture: this.sceneInfra.extraSegmentTexture,
865866
theme: this.sceneInfra._theme,
866867
isSelected,
867868
sceneInfra: this.sceneInfra,
@@ -2540,14 +2541,14 @@ export class SceneEntities {
25402541

25412542
const pipeIndex = pathToNode[pathToNodeIndex + 1][0] as number
25422543
if (addingNewSegmentStatus === 'nothing') {
2543-
const prevSegment = sketch.paths[pipeIndex - 2]
2544+
const prevSegment = sketch.paths[pipeIndex - 2] // Is undefined when dragging the first segment
25442545
const mod = addNewSketchLn({
25452546
node: this.kclManager.ast,
25462547
variables: this.kclManager.variables,
25472548
input: {
25482549
type: 'straight-segment',
25492550
to: [intersectionPoint.twoD.x, intersectionPoint.twoD.y],
2550-
from: prevSegment.from,
2551+
from: prevSegment?.from || [0, 0],
25512552
},
25522553
// TODO assuming it's always a straight segments being added
25532554
// as this is easiest, and we'll need to add "tabbing" behavior
@@ -3346,16 +3347,10 @@ export class SceneEntities {
33463347
this.editorManager.setHighlightRange([
33473348
topLevelRange(node.start, node.end),
33483349
])
3349-
const yellow = 0xffff00
3350-
colorSegment(selected, yellow)
3351-
const extraSegmentGroup = parent.getObjectByName(EXTRA_SEGMENT_HANDLE)
3352-
if (extraSegmentGroup) {
3353-
extraSegmentGroup.traverse((child) => {
3354-
if (child instanceof Points || child instanceof Mesh) {
3355-
child.material.opacity = dragSelected ? 0 : 1
3356-
}
3357-
})
3358-
}
3350+
colorSegment(selected, SEGMENT_YELLOW)
3351+
const isSelected = parent?.userData?.isSelected
3352+
updateExtraSegments(parent, 'hoveringLine', true)
3353+
updateExtraSegments(parent, 'selected', isSelected)
33593354
const orthoFactor = orthoScale(this.sceneInfra.camControls.camera)
33603355

33613356
let input: SegmentInputs = {
@@ -3504,18 +3499,12 @@ export class SceneEntities {
35043499
colorSegment(
35053500
selected,
35063501
isSelected
3507-
? 0x0000ff
3502+
? SEGMENT_BLUE
35083503
: parent?.userData?.baseColor ||
35093504
getThemeColorForThreeJs(this.sceneInfra._theme)
35103505
)
3511-
const extraSegmentGroup = parent?.getObjectByName(EXTRA_SEGMENT_HANDLE)
3512-
if (extraSegmentGroup) {
3513-
extraSegmentGroup.traverse((child) => {
3514-
if (child instanceof Points || child instanceof Mesh) {
3515-
child.material.opacity = 0
3516-
}
3517-
})
3518-
}
3506+
updateExtraSegments(parent, 'hoveringLine', false)
3507+
updateExtraSegments(parent, 'selected', isSelected)
35193508
if ([X_AXIS, Y_AXIS].includes(selected?.userData?.type)) {
35203509
const obj = selected as Mesh
35213510
const mat = obj.material as MeshBasicMaterial
@@ -3812,7 +3801,7 @@ function sketchFromPathToNode({
38123801
return sg
38133802
}
38143803

3815-
function colorSegment(object: any, color: number) {
3804+
function colorSegment(object: Object3D, color: number) {
38163805
const segmentHead = getParentGroup(object, [ARROWHEAD, PROFILE_START])
38173806
if (segmentHead) {
38183807
segmentHead.traverse((child) => {

src/clientSideScene/sceneInfra.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type {
55
MeshBasicMaterial,
66
Object3D,
77
Object3DEventMap,
8-
Texture,
98
} from 'three'
109
import {
1110
AmbientLight,
@@ -16,7 +15,6 @@ import {
1615
OrthographicCamera,
1716
Raycaster,
1817
Scene,
19-
TextureLoader,
2018
Vector2,
2119
Vector3,
2220
WebGLRenderer,
@@ -105,7 +103,6 @@ export class SceneInfra {
105103
isFovAnimationInProgress = false
106104
_baseUnitMultiplier = 1
107105
_theme: Themes = Themes.System
108-
readonly extraSegmentTexture: Texture
109106
lastMouseState: MouseState = { type: 'idle' }
110107
onDragStartCallback: (arg: OnDragCallbackArgs) => Voidish = () => {}
111108
onDragEndCallback: (arg: OnDragCallbackArgs) => Voidish = () => {}
@@ -323,13 +320,6 @@ export class SceneInfra {
323320
const light = new AmbientLight(0x505050) // soft white light
324321
this.scene.add(light)
325322

326-
const textureLoader = new TextureLoader()
327-
this.extraSegmentTexture = textureLoader.load(
328-
'./clientSideSceneAssets/extra-segment-texture.png'
329-
)
330-
this.extraSegmentTexture.anisotropy =
331-
this.renderer?.capabilities?.getMaxAnisotropy?.()
332-
333323
SceneInfra.instance = this
334324
}
335325

0 commit comments

Comments
 (0)