Add a radius length indicator to the circle sketch tool (#4304)
* Add a radius length indicator to the circle sketch tool
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)
* Revert "A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)"
This reverts commit 15b078f641
.
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: 49fl <ircsurfer33@gmail.com>
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 46 KiB |
Binary file not shown.
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 44 KiB |
@ -517,6 +517,12 @@ class CircleSegment implements SegmentUtils {
|
|||||||
const meshType = isDraftSegment ? CIRCLE_SEGMENT_DASH : CIRCLE_SEGMENT_BODY
|
const meshType = isDraftSegment ? CIRCLE_SEGMENT_DASH : CIRCLE_SEGMENT_BODY
|
||||||
const arrowGroup = createArrowhead(scale, theme, color)
|
const arrowGroup = createArrowhead(scale, theme, color)
|
||||||
const circleCenterGroup = createCircleCenterHandle(scale, theme, color)
|
const circleCenterGroup = createCircleCenterHandle(scale, theme, color)
|
||||||
|
// A radius indicator that appears from the center to the perimeter
|
||||||
|
const radiusIndicatorGroup = createLengthIndicator({
|
||||||
|
from: center,
|
||||||
|
to: [center[0] + radius, center[1]],
|
||||||
|
scale,
|
||||||
|
})
|
||||||
|
|
||||||
arcMesh.userData.type = meshType
|
arcMesh.userData.type = meshType
|
||||||
arcMesh.name = meshType
|
arcMesh.name = meshType
|
||||||
@ -535,7 +541,7 @@ class CircleSegment implements SegmentUtils {
|
|||||||
}
|
}
|
||||||
group.name = CIRCLE_SEGMENT
|
group.name = CIRCLE_SEGMENT
|
||||||
|
|
||||||
group.add(arcMesh, arrowGroup, circleCenterGroup)
|
group.add(arcMesh, arrowGroup, circleCenterGroup, radiusIndicatorGroup)
|
||||||
const updateOverlaysCallback = this.update({
|
const updateOverlaysCallback = this.update({
|
||||||
prevSegment,
|
prevSegment,
|
||||||
input,
|
input,
|
||||||
@ -567,6 +573,9 @@ class CircleSegment implements SegmentUtils {
|
|||||||
group.userData.radius = radius
|
group.userData.radius = radius
|
||||||
group.userData.prevSegment = prevSegment
|
group.userData.prevSegment = prevSegment
|
||||||
const arrowGroup = group.getObjectByName(ARROWHEAD) as Group
|
const arrowGroup = group.getObjectByName(ARROWHEAD) as Group
|
||||||
|
const radiusLengthIndicator = group.getObjectByName(
|
||||||
|
SEGMENT_LENGTH_LABEL
|
||||||
|
) as Group
|
||||||
const circleCenterHandle = group.getObjectByName(
|
const circleCenterHandle = group.getObjectByName(
|
||||||
CIRCLE_CENTER_HANDLE
|
CIRCLE_CENTER_HANDLE
|
||||||
) as Group
|
) as Group
|
||||||
@ -584,11 +593,14 @@ class CircleSegment implements SegmentUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (arrowGroup) {
|
if (arrowGroup) {
|
||||||
arrowGroup.position.set(
|
// The arrowhead is placed at the perimeter of the circle,
|
||||||
center[0] + Math.cos(Math.PI / 4) * radius,
|
// pointing up and to the right
|
||||||
center[1] + Math.sin(Math.PI / 4) * radius,
|
const arrowPoint = {
|
||||||
0
|
x: center[0] + Math.cos(Math.PI / 4) * radius,
|
||||||
)
|
y: center[1] + Math.sin(Math.PI / 4) * radius,
|
||||||
|
}
|
||||||
|
|
||||||
|
arrowGroup.position.set(arrowPoint.x, arrowPoint.y, 0)
|
||||||
|
|
||||||
const arrowheadAngle = Math.PI / 4
|
const arrowheadAngle = Math.PI / 4
|
||||||
arrowGroup.quaternion.setFromUnitVectors(
|
arrowGroup.quaternion.setFromUnitVectors(
|
||||||
@ -599,6 +611,31 @@ class CircleSegment implements SegmentUtils {
|
|||||||
arrowGroup.visible = isHandlesVisible
|
arrowGroup.visible = isHandlesVisible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (radiusLengthIndicator) {
|
||||||
|
// The radius indicator is placed at the midpoint of the radius,
|
||||||
|
// at a 45 degree CCW angle from the positive X-axis
|
||||||
|
const indicatorPoint = {
|
||||||
|
x: center[0] + (Math.cos(Math.PI / 4) * radius) / 2,
|
||||||
|
y: center[1] + (Math.sin(Math.PI / 4) * radius) / 2,
|
||||||
|
}
|
||||||
|
const labelWrapper = radiusLengthIndicator.getObjectByName(
|
||||||
|
SEGMENT_LENGTH_LABEL_TEXT
|
||||||
|
) as CSS2DObject
|
||||||
|
const labelWrapperElem = labelWrapper.element as HTMLDivElement
|
||||||
|
const label = labelWrapperElem.children[0] as HTMLParagraphElement
|
||||||
|
label.innerText = `${roundOff(radius)}`
|
||||||
|
label.classList.add(SEGMENT_LENGTH_LABEL_TEXT)
|
||||||
|
const isPlaneBackFace = center[0] > indicatorPoint.x
|
||||||
|
label.style.setProperty(
|
||||||
|
'--degree',
|
||||||
|
`${isPlaneBackFace ? '45' : '-45'}deg`
|
||||||
|
)
|
||||||
|
label.style.setProperty('--x', `0px`)
|
||||||
|
label.style.setProperty('--y', `0px`)
|
||||||
|
labelWrapper.position.set(indicatorPoint.x, indicatorPoint.y, 0)
|
||||||
|
radiusLengthIndicator.visible = isHandlesVisible
|
||||||
|
}
|
||||||
|
|
||||||
if (circleCenterHandle) {
|
if (circleCenterHandle) {
|
||||||
circleCenterHandle.position.set(center[0], center[1], 0)
|
circleCenterHandle.position.set(center[0], center[1], 0)
|
||||||
circleCenterHandle.scale.set(scale, scale, scale)
|
circleCenterHandle.scale.set(scale, scale, scale)
|
||||||
|
Reference in New Issue
Block a user