| 337 | const Mouse = new MouseClass(); |
| 338 | |
| 339 | class AutoDriver { |
| 340 | mouse: MouseClass; |
| 341 | manager: WebGLManager; |
| 342 | enabled: boolean; |
| 343 | speed: number; |
| 344 | resumeDelay: number; |
| 345 | rampDurationMs: number; |
| 346 | active = false; |
| 347 | current = new THREE.Vector2(0, 0); |
| 348 | target = new THREE.Vector2(); |
| 349 | lastTime = performance.now(); |
| 350 | activationTime = 0; |
| 351 | margin = 0.2; |
| 352 | private _tmpDir = new THREE.Vector2(); |
| 353 | constructor( |
| 354 | mouse: MouseClass, |
| 355 | manager: WebGLManager, |
| 356 | opts: { |
| 357 | enabled: boolean; |
| 358 | speed: number; |
| 359 | resumeDelay: number; |
| 360 | rampDuration: number; |
| 361 | } |
| 362 | ) { |
| 363 | this.mouse = mouse; |
| 364 | this.manager = manager; |
| 365 | this.enabled = opts.enabled; |
| 366 | this.speed = opts.speed; |
| 367 | this.resumeDelay = opts.resumeDelay || 3000; |
| 368 | this.rampDurationMs = (opts.rampDuration || 0) * 1000; |
| 369 | this.pickNewTarget(); |
| 370 | } |
| 371 | pickNewTarget() { |
| 372 | const r = Math.random; |
| 373 | this.target.set( |
| 374 | (r() * 2 - 1) * (1 - this.margin), |
| 375 | (r() * 2 - 1) * (1 - this.margin) |
| 376 | ); |
| 377 | } |
| 378 | forceStop() { |
| 379 | this.active = false; |
| 380 | this.mouse.isAutoActive = false; |
| 381 | } |
| 382 | update() { |
| 383 | if (!this.enabled) return; |
| 384 | const now = performance.now(); |
| 385 | const idle = now - this.manager.lastUserInteraction; |
| 386 | if (idle < this.resumeDelay) { |
| 387 | if (this.active) this.forceStop(); |
| 388 | return; |
| 389 | } |
| 390 | if (this.mouse.isHoverInside) { |
| 391 | if (this.active) this.forceStop(); |
| 392 | return; |
| 393 | } |
| 394 | if (!this.active) { |
| 395 | this.active = true; |
| 396 | this.current.copy(this.mouse.coords); |
nothing calls this directly
no outgoing calls
no test coverage detected