#5905 Cleanup console warnings (#5908)

* Fix ToolBar WebkitAppRegion warning

* make intersectionPlane non-nullable, avoid trying to create it multiple times to get rid of warning

* remove derived scene from sceneEntities

* intersectionPlane is now always non-null, make it readonly too

* sceneInfra small cleanups

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* Clean up snapshots

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
This commit is contained in:
Andrew Varga
2025-03-21 01:55:20 +01:00
committed by GitHub
parent 054bb5b500
commit 9248b2e42d
4 changed files with 73 additions and 86 deletions

View File

@ -392,7 +392,8 @@ const ToolbarItemTooltip = memo(function ToolbarItemContents({
inert={false} inert={false}
wrapperStyle={ wrapperStyle={
isDesktop() isDesktop()
? ({ '-webkit-app-region': 'no-drag' } as React.CSSProperties) ? // Without this, the tooltip disappears before being able to click on anything in it
({ WebkitAppRegion: 'no-drag' } as React.CSSProperties)
: {} : {}
} }
hoverOnly hoverOnly

View File

@ -12,7 +12,6 @@ import {
PlaneGeometry, PlaneGeometry,
Points, Points,
Quaternion, Quaternion,
Scene,
Vector2, Vector2,
Vector3, Vector3,
Shape, Shape,
@ -189,19 +188,17 @@ type Vec3Array = [number, number, number]
// That mostly mean sketch elements. // That mostly mean sketch elements.
// Cameras, controls, raycasters, etc are handled by sceneInfra // Cameras, controls, raycasters, etc are handled by sceneInfra
export class SceneEntities { export class SceneEntities {
engineCommandManager: EngineCommandManager readonly engineCommandManager: EngineCommandManager
scene: Scene
activeSegments: { [key: string]: Group } = {} activeSegments: { [key: string]: Group } = {}
intersectionPlane: Mesh | null = null readonly intersectionPlane: Mesh
axisGroup: Group | null = null axisGroup: Group | null = null
draftPointGroups: Group[] = [] draftPointGroups: Group[] = []
currentSketchQuaternion: Quaternion | null = null currentSketchQuaternion: Quaternion | null = null
constructor(engineCommandManager: EngineCommandManager) { constructor(engineCommandManager: EngineCommandManager) {
this.engineCommandManager = engineCommandManager this.engineCommandManager = engineCommandManager
this.scene = sceneInfra?.scene this.intersectionPlane = SceneEntities.createIntersectionPlane()
sceneInfra?.camControls.subscribeToCamChange(this.onCamChange) sceneInfra.camControls.subscribeToCamChange(this.onCamChange)
window.addEventListener('resize', this.onWindowResize) window.addEventListener('resize', this.onWindowResize)
this.createIntersectionPlane()
} }
onWindowResize = () => { onWindowResize = () => {
@ -328,11 +325,7 @@ export class SceneEntities {
sceneInfra.overlayCallbacks(callbacks) sceneInfra.overlayCallbacks(callbacks)
} }
createIntersectionPlane() { private static createIntersectionPlane() {
if (sceneInfra.scene.getObjectByName(RAYCASTABLE_PLANE)) {
console.warn('createIntersectionPlane called when it already exists')
return
}
const hundredM = 100_0000 const hundredM = 100_0000
const planeGeometry = new PlaneGeometry(hundredM, hundredM) const planeGeometry = new PlaneGeometry(hundredM, hundredM)
const planeMaterial = new MeshBasicMaterial({ const planeMaterial = new MeshBasicMaterial({
@ -341,11 +334,12 @@ export class SceneEntities {
transparent: true, transparent: true,
opacity: 0.5, opacity: 0.5,
}) })
this.intersectionPlane = new Mesh(planeGeometry, planeMaterial) const intersectionPlane = new Mesh(planeGeometry, planeMaterial)
this.intersectionPlane.userData = { type: RAYCASTABLE_PLANE } intersectionPlane.userData = { type: RAYCASTABLE_PLANE }
this.intersectionPlane.name = RAYCASTABLE_PLANE intersectionPlane.name = RAYCASTABLE_PLANE
this.intersectionPlane.layers.set(INTERSECTION_PLANE_LAYER) intersectionPlane.layers.set(INTERSECTION_PLANE_LAYER)
this.scene.add(this.intersectionPlane) sceneInfra.scene.add(intersectionPlane)
return intersectionPlane
} }
createSketchAxis( createSketchAxis(
sketchPathToNode: PathToNode, sketchPathToNode: PathToNode,
@ -424,10 +418,10 @@ export class SceneEntities {
) )
this.axisGroup.setRotationFromQuaternion(quat) this.axisGroup.setRotationFromQuaternion(quat)
sketchPosition && this.axisGroup.position.set(...sketchPosition) sketchPosition && this.axisGroup.position.set(...sketchPosition)
this.scene.add(this.axisGroup) sceneInfra.scene.add(this.axisGroup)
} }
getDraftPoint() { getDraftPoint() {
return this.scene.getObjectByName(DRAFT_POINT) return sceneInfra.scene.getObjectByName(DRAFT_POINT)
} }
createDraftPoint({ createDraftPoint({
point, point,
@ -453,7 +447,7 @@ export class SceneEntities {
new Vector3(...zAxis) new Vector3(...zAxis)
) )
draftPointGroup.setRotationFromQuaternion(currentSketchQuaternion) draftPointGroup.setRotationFromQuaternion(currentSketchQuaternion)
this.scene.add(draftPointGroup) sceneInfra.scene.add(draftPointGroup)
const dummy = new Mesh() const dummy = new Mesh()
dummy.position.set(0, 0, 0) dummy.position.set(0, 0, 0)
const scale = sceneInfra.getClientSceneScaleFactor(dummy) const scale = sceneInfra.getClientSceneScaleFactor(dummy)
@ -505,8 +499,8 @@ export class SceneEntities {
) )
// Position the click raycast plane // Position the click raycast plane
this.intersectionPlane!.setRotationFromQuaternion(quaternion) this.intersectionPlane.setRotationFromQuaternion(quaternion)
this.intersectionPlane!.position.copy( this.intersectionPlane.position.copy(
new Vector3(...(sketchDetails?.origin || [0, 0, 0])) new Vector3(...(sketchDetails?.origin || [0, 0, 0]))
) )
sceneInfra.setCallbacks({ sceneInfra.setCallbacks({
@ -658,8 +652,6 @@ export class SceneEntities {
truncatedAst: Node<Program> truncatedAst: Node<Program>
variableDeclarationName: string variableDeclarationName: string
}> { }> {
this.createIntersectionPlane()
const prepared = this.prepareTruncatedAst(sketchNodePaths, maybeModdedAst) const prepared = this.prepareTruncatedAst(sketchNodePaths, maybeModdedAst)
if (err(prepared)) return Promise.reject(prepared) if (err(prepared)) return Promise.reject(prepared)
const { truncatedAst, variableDeclarationName } = prepared const { truncatedAst, variableDeclarationName } = prepared
@ -847,14 +839,11 @@ export class SceneEntities {
new Vector3(...forward) new Vector3(...forward)
) )
group.setRotationFromQuaternion(this.currentSketchQuaternion) group.setRotationFromQuaternion(this.currentSketchQuaternion)
this.intersectionPlane && this.intersectionPlane.setRotationFromQuaternion(
this.intersectionPlane.setRotationFromQuaternion( this.currentSketchQuaternion
this.currentSketchQuaternion )
) position && this.intersectionPlane.position.set(...position)
this.intersectionPlane && sceneInfra.scene.add(group)
position &&
this.intersectionPlane.position.set(...position)
this.scene.add(group)
sceneInfra.camControls.enableRotate = false sceneInfra.camControls.enableRotate = false
sceneInfra.overlayCallbacks(callbacks) sceneInfra.overlayCallbacks(callbacks)
@ -3059,18 +3048,18 @@ export class SceneEntities {
}) })
} }
removeSketchGrid() { removeSketchGrid() {
if (this.axisGroup) this.scene.remove(this.axisGroup) if (this.axisGroup) sceneInfra.scene.remove(this.axisGroup)
} }
tearDownSketch({ removeAxis = true }: { removeAxis?: boolean }) { tearDownSketch({ removeAxis = true }: { removeAxis?: boolean }) {
// Remove all draft groups // Remove all draft groups
this.draftPointGroups.forEach((draftPointGroup) => { this.draftPointGroups.forEach((draftPointGroup) => {
this.scene.remove(draftPointGroup) sceneInfra.scene.remove(draftPointGroup)
}) })
// Remove all sketch tools // Remove all sketch tools
if (this.axisGroup && removeAxis) this.scene.remove(this.axisGroup) if (this.axisGroup && removeAxis) sceneInfra.scene.remove(this.axisGroup)
const sketchSegments = this.scene.children.find( const sketchSegments = sceneInfra.scene.children.find(
({ userData }) => userData?.type === SKETCH_GROUP_SEGMENTS ({ userData }) => userData?.type === SKETCH_GROUP_SEGMENTS
) )
if (sketchSegments) { if (sketchSegments) {
@ -3082,7 +3071,7 @@ export class SceneEntities {
object.remove() object.remove()
} }
}) })
this.scene.remove(sketchSegments) sceneInfra.scene.remove(sketchSegments)
} }
sceneInfra.camControls.enableRotate = true sceneInfra.camControls.enableRotate = true
this.activeSegments = {} this.activeSegments = {}

View File

@ -110,18 +110,16 @@ interface OnMoveCallbackArgs {
type Voidish = void | Promise<void> type Voidish = void | Promise<void>
export class SceneInfra { export class SceneInfra {
static instance: SceneInfra static instance: SceneInfra
scene: Scene readonly scene: Scene
renderer: WebGLRenderer readonly renderer: WebGLRenderer
labelRenderer: CSS2DRenderer readonly labelRenderer: CSS2DRenderer
camControls: CameraControls readonly camControls: CameraControls
isPerspective = true private readonly fov = 45
fov = 45
fovBeforeAnimate = 45
isFovAnimationInProgress = false isFovAnimationInProgress = false
_baseUnit: BaseUnit = 'mm' _baseUnit: BaseUnit = 'mm'
_baseUnitMultiplier = 1 _baseUnitMultiplier = 1
_theme: Themes = Themes.System _theme: Themes = Themes.System
extraSegmentTexture: Texture readonly extraSegmentTexture: Texture
lastMouseState: MouseState = { type: 'idle' } lastMouseState: MouseState = { type: 'idle' }
onDragStartCallback: (arg: OnDragCallbackArgs) => Voidish = () => {} onDragStartCallback: (arg: OnDragCallbackArgs) => Voidish = () => {}
onDragEndCallback: (arg: OnDragCallbackArgs) => Voidish = () => {} onDragEndCallback: (arg: OnDragCallbackArgs) => Voidish = () => {}

View File

@ -870,14 +870,14 @@ export const modelingMachine = setup({
) )
// Position the click raycast plane // Position the click raycast plane
if (sceneEntitiesManager.intersectionPlane) {
sceneEntitiesManager.intersectionPlane.setRotationFromQuaternion( sceneEntitiesManager.intersectionPlane.setRotationFromQuaternion(
quaternion quaternion
) )
sceneEntitiesManager.intersectionPlane.position.copy( sceneEntitiesManager.intersectionPlane.position.copy(
new Vector3(...(sketchDetails?.origin || [0, 0, 0])) new Vector3(...(sketchDetails?.origin || [0, 0, 0]))
) )
}
sceneInfra.setCallbacks({ sceneInfra.setCallbacks({
onClick: (args) => { onClick: (args) => {
if (!args) return if (!args) return
@ -906,14 +906,14 @@ export const modelingMachine = setup({
) )
// Position the click raycast plane // Position the click raycast plane
if (sceneEntitiesManager.intersectionPlane) {
sceneEntitiesManager.intersectionPlane.setRotationFromQuaternion( sceneEntitiesManager.intersectionPlane.setRotationFromQuaternion(
quaternion quaternion
) )
sceneEntitiesManager.intersectionPlane.position.copy( sceneEntitiesManager.intersectionPlane.position.copy(
new Vector3(...(sketchDetails?.origin || [0, 0, 0])) new Vector3(...(sketchDetails?.origin || [0, 0, 0]))
) )
}
sceneInfra.setCallbacks({ sceneInfra.setCallbacks({
onClick: (args) => { onClick: (args) => {
if (!args) return if (!args) return
@ -939,14 +939,14 @@ export const modelingMachine = setup({
) )
// Position the click raycast plane // Position the click raycast plane
if (sceneEntitiesManager.intersectionPlane) {
sceneEntitiesManager.intersectionPlane.setRotationFromQuaternion( sceneEntitiesManager.intersectionPlane.setRotationFromQuaternion(
quaternion quaternion
) )
sceneEntitiesManager.intersectionPlane.position.copy( sceneEntitiesManager.intersectionPlane.position.copy(
new Vector3(...(sketchDetails?.origin || [0, 0, 0])) new Vector3(...(sketchDetails?.origin || [0, 0, 0]))
) )
}
sceneInfra.setCallbacks({ sceneInfra.setCallbacks({
onClick: (args) => { onClick: (args) => {
if (!args) return if (!args) return
@ -973,14 +973,14 @@ export const modelingMachine = setup({
) )
// Position the click raycast plane // Position the click raycast plane
if (sceneEntitiesManager.intersectionPlane) {
sceneEntitiesManager.intersectionPlane.setRotationFromQuaternion( sceneEntitiesManager.intersectionPlane.setRotationFromQuaternion(
quaternion quaternion
) )
sceneEntitiesManager.intersectionPlane.position.copy( sceneEntitiesManager.intersectionPlane.position.copy(
new Vector3(...(sketchDetails?.origin || [0, 0, 0])) new Vector3(...(sketchDetails?.origin || [0, 0, 0]))
) )
}
sceneInfra.setCallbacks({ sceneInfra.setCallbacks({
onClick: (args) => { onClick: (args) => {
if (!args) return if (!args) return
@ -1011,14 +1011,13 @@ export const modelingMachine = setup({
) )
// Position the click raycast plane // Position the click raycast plane
if (sceneEntitiesManager.intersectionPlane) {
sceneEntitiesManager.intersectionPlane.setRotationFromQuaternion( sceneEntitiesManager.intersectionPlane.setRotationFromQuaternion(
quaternion quaternion
) )
sceneEntitiesManager.intersectionPlane.position.copy( sceneEntitiesManager.intersectionPlane.position.copy(
new Vector3(...(sketchDetails?.origin || [0, 0, 0])) new Vector3(...(sketchDetails?.origin || [0, 0, 0]))
) )
}
const dummy = new Mesh() const dummy = new Mesh()
dummy.position.set(0, 0, 0) dummy.position.set(0, 0, 0)