Make fence drawing continue between segments
This commit is contained in:
@@ -427,6 +427,12 @@ export const FenceTool: React.FC = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let previousFenceEnd: FencePlanPoint | null = null
|
let previousFenceEnd: FencePlanPoint | null = null
|
||||||
|
|
||||||
|
const stopDrafting = () => {
|
||||||
|
buildingState.current = 0
|
||||||
|
previewRef.current.visible = false
|
||||||
|
setDraftMeasurement(null)
|
||||||
|
}
|
||||||
|
|
||||||
const onGridMove = (event: GridEvent) => {
|
const onGridMove = (event: GridEvent) => {
|
||||||
if (!(cursorRef.current && previewRef.current)) return
|
if (!(cursorRef.current && previewRef.current)) return
|
||||||
const { walls, fences } = getCurrentLevelElements()
|
const { walls, fences } = getCurrentLevelElements()
|
||||||
@@ -468,6 +474,11 @@ export const FenceTool: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onGridClick = (event: GridEvent) => {
|
const onGridClick = (event: GridEvent) => {
|
||||||
|
if (buildingState.current === 1 && event.nativeEvent.detail >= 2) {
|
||||||
|
stopDrafting()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const { walls, fences } = getCurrentLevelElements()
|
const { walls, fences } = getCurrentLevelElements()
|
||||||
const localClick: FencePlanPoint = [event.localPosition[0], event.localPosition[2]]
|
const localClick: FencePlanPoint = [event.localPosition[0], event.localPosition[2]]
|
||||||
|
|
||||||
@@ -489,9 +500,18 @@ export const FenceTool: React.FC = () => {
|
|||||||
const dx = snappedEnd[0] - startingPoint.current.x
|
const dx = snappedEnd[0] - startingPoint.current.x
|
||||||
const dz = snappedEnd[1] - startingPoint.current.z
|
const dz = snappedEnd[1] - startingPoint.current.z
|
||||||
if (dx * dx + dz * dz < 0.01 * 0.01) return
|
if (dx * dx + dz * dz < 0.01 * 0.01) return
|
||||||
createFenceOnCurrentLevel([startingPoint.current.x, startingPoint.current.z], snappedEnd)
|
const createdFence = createFenceOnCurrentLevel(
|
||||||
|
[startingPoint.current.x, startingPoint.current.z],
|
||||||
|
snappedEnd,
|
||||||
|
)
|
||||||
|
if (!createdFence) return
|
||||||
|
|
||||||
|
const nextStart = createdFence.end
|
||||||
|
startingPoint.current.set(nextStart[0], event.localPosition[1], nextStart[1])
|
||||||
|
endingPoint.current.copy(startingPoint.current)
|
||||||
|
cursorRef.current.position.copy(startingPoint.current)
|
||||||
previewRef.current.visible = false
|
previewRef.current.visible = false
|
||||||
buildingState.current = 0
|
buildingState.current = 1
|
||||||
setDraftMeasurement(null)
|
setDraftMeasurement(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -507,9 +527,7 @@ export const FenceTool: React.FC = () => {
|
|||||||
const onCancel = () => {
|
const onCancel = () => {
|
||||||
if (buildingState.current === 1) {
|
if (buildingState.current === 1) {
|
||||||
markToolCancelConsumed()
|
markToolCancelConsumed()
|
||||||
buildingState.current = 0
|
stopDrafting()
|
||||||
if (previewRef.current) previewRef.current.visible = false
|
|
||||||
setDraftMeasurement(null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user