dynamic cursor depending on mouse scene state (#1995)

* dynamic cursor depending on mouse scene state

* hover stuff

* bump min length

* clean up

* sketch on face failing randomly

* more time out for extrude snapshots

* Update src/clientSideScene/sceneEntities.ts

Co-authored-by: Frank Noirot <frank@zoo.dev>

* move for profileStart handle, and select when no tool equiped

---------

Co-authored-by: Frank Noirot <frank@zoo.dev>
This commit is contained in:
Kurt Hutten
2024-04-04 11:07:51 +11:00
committed by GitHub
parent 108bb4ee90
commit f03f34d8be
8 changed files with 237 additions and 93 deletions

View File

@ -30,6 +30,7 @@ import { type BaseUnit } from 'lib/settings/settingsTypes'
import { CameraControls } from './CameraControls'
import { EngineCommandManager } from 'lang/std/engineConnection'
import { settings } from 'lib/settings/initialSettings'
import { MouseState } from 'machines/modelingMachine'
type SendType = ReturnType<typeof useModelingContext>['send']
@ -102,6 +103,7 @@ export class SceneInfra {
_baseUnit: BaseUnit = 'mm'
_baseUnitMultiplier = 1
extraSegmentTexture: Texture
lastMouseState: MouseState = { type: 'idle' }
onDragStartCallback: (arg: OnDragCallbackArgs) => void = () => {}
onDragEndCallback: (arg: OnDragCallbackArgs) => void = () => {}
onDragCallback: (arg: OnDragCallbackArgs) => void = () => {}
@ -338,8 +340,6 @@ export class SceneInfra {
planeIntersectPoint.twoD &&
planeIntersectPoint.threeD
) {
// // console.log('onDrag', this.selected)
this.onDragCallback({
mouseEvent,
intersectionPoint: {
@ -349,6 +349,10 @@ export class SceneInfra {
intersects,
selected: this.selected.object,
})
this.updateMouseState({
type: 'isDragging',
on: this.selected.object,
})
}
} else if (
planeIntersectPoint &&
@ -368,27 +372,34 @@ export class SceneInfra {
if (intersects[0]) {
const firstIntersectObject = intersects[0].object
if (this.hoveredObject !== firstIntersectObject) {
if (this.hoveredObject) {
this.onMouseLeave({
selected: this.hoveredObject,
mouseEvent: mouseEvent,
})
}
const hoveredObj = this.hoveredObject
this.hoveredObject = null
this.onMouseLeave({
selected: hoveredObj,
mouseEvent: mouseEvent,
})
this.hoveredObject = firstIntersectObject
this.onMouseEnter({
selected: this.hoveredObject,
dragSelected: this.selected?.object,
mouseEvent: mouseEvent,
})
if (!this.selected)
this.updateMouseState({
type: 'isHovering',
on: this.hoveredObject,
})
}
} else {
if (this.hoveredObject) {
const hoveredObj = this.hoveredObject
this.hoveredObject = null
this.onMouseLeave({
selected: this.hoveredObject,
selected: hoveredObj,
dragSelected: this.selected?.object,
mouseEvent: mouseEvent,
})
this.hoveredObject = null
if (!this.selected) this.updateMouseState({ type: 'idle' })
}
}
}
@ -445,6 +456,11 @@ export class SceneInfra {
(a, b) => a.distance - b.distance
)
}
updateMouseState(mouseState: MouseState) {
if (this.lastMouseState.type === mouseState.type) return
this.lastMouseState = mouseState
this.modelingSend({ type: 'Set mouse state', data: mouseState })
}
onMouseDown = (event: MouseEvent) => {
this.currentMouseVector.x = (event.clientX / window.innerWidth) * 2 - 1
@ -484,6 +500,16 @@ export class SceneInfra {
mouseEvent,
selected: this.selected as any,
})
if (intersects.length) {
this.updateMouseState({
type: 'isHovering',
on: intersects[0].object,
})
} else {
this.updateMouseState({
type: 'idle',
})
}
} else if (planeIntersectPoint?.twoD && planeIntersectPoint?.threeD) {
// fire onClick event as there was no drags
this.onClickCallback({