-
Notifications
You must be signed in to change notification settings - Fork 62
Scene System Testing [AARD-1938]
#1217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
806a1f3
Camera Controls Unit Test
AlexD717 7ee94de
Unnecessary Tests Removed
AlexD717 c793680
Drag Mode Tests
AlexD717 95f7582
Gizmo Scene Object Tests
AlexD717 fdc712c
Joystick Unit Tests
AlexD717 409389d
Initial Scene Renderer Unit Tests
AlexD717 bd7c660
Scene Rendered Tests Cleanup
AlexD717 4090d35
Scene Interaction Unit Tests
AlexD717 470d5f6
General Test Cleanup
AlexD717 91a16b1
Mock WebGLRenderer
AlexD717 1176ac7
Camera Controls Test Rewrite
AlexD717 f39d8f7
Drag Mode System Test Improvements
AlexD717 8be5267
Gizmo Scene Object Test Improvement
AlexD717 afcc980
Joystick Tests Improved
AlexD717 de691c8
Scene Renderer Tests Optimized
AlexD717 0b4f703
Update SceneInteractionHandler.test.ts
AlexD717 be1bb6d
Test Split Up
AlexD717 bfae1b5
Merge branch 'dev' into alexey/1938/scene-system-testing
rutmanz 13c1d6e
More Test Fixes
AlexD717 7d442a4
Merge branch 'dev' into alexey/1938/scene-system-testing
PepperLola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| import { expect, test, beforeEach, describe } from "vitest" | ||
| import { CustomOrbitControls } from "@/systems/scene/CameraControls" | ||
| import * as THREE from "three" | ||
| import ScreenInteractionHandler, { InteractionType } from "@/systems/scene/ScreenInteractionHandler" | ||
|
|
||
| describe("CustomOrbitControls", () => { | ||
| let camera: THREE.PerspectiveCamera | ||
| let interactionHandler: ScreenInteractionHandler | ||
| let controls: CustomOrbitControls | ||
|
|
||
| beforeEach(() => { | ||
| camera = new THREE.PerspectiveCamera(75, 1, 0.1, 1000) | ||
| camera.position.set(0, 0, 5) | ||
|
|
||
| const mockElement = document.createElement("div") | ||
| interactionHandler = new ScreenInteractionHandler(mockElement) | ||
|
|
||
| controls = new CustomOrbitControls(camera, interactionHandler) | ||
| }) | ||
|
|
||
| describe("Camera Position and Update", () => { | ||
| test("sets simple coordinates correctly", () => { | ||
| controls.setImmediateCoordinates({ theta: Math.PI / 2, phi: 0, r: 2.0 }) | ||
| controls.update(1 / 60) | ||
|
|
||
| expect(camera.position.x).toBeCloseTo(2) | ||
| expect(camera.position.y).toBeCloseTo(0) | ||
| expect(camera.position.z).toBeCloseTo(0) | ||
| }) | ||
|
|
||
| test("sets complex coordinates correctly", () => { | ||
| controls.setImmediateCoordinates({ theta: Math.PI / 3, phi: Math.PI / 6, r: 4.0 }) | ||
| controls.update(1 / 60) | ||
|
|
||
| expect(camera.position.distanceTo(new THREE.Vector3(0, 0, 0))).toBeCloseTo(4) | ||
|
|
||
| expect(camera.position.x).toBeCloseTo(3) | ||
| expect(camera.position.y).toBeCloseTo(-2) | ||
| expect(camera.position.z).toBeCloseTo(1.732) | ||
| }) | ||
|
|
||
| test("clamps extreme values", () => { | ||
| // Test r (zoom) bounds - values should be clamped | ||
| controls.setImmediateCoordinates({ r: 1000 }) | ||
| controls.update(1 / 60) | ||
| const maxR = controls.getCurrentCoordinates().r | ||
|
|
||
| controls.setImmediateCoordinates({ r: 0.001 }) | ||
| controls.update(1 / 60) | ||
| const minR = controls.getCurrentCoordinates().r | ||
|
|
||
| expect(maxR).toBeLessThan(1000) | ||
| expect(minR).toBeGreaterThan(0.001) | ||
| expect(minR).toBeLessThan(maxR) | ||
|
|
||
| // Test phi (vertical) bounds | ||
| controls.setImmediateCoordinates({ phi: Math.PI }) | ||
| controls.update(1 / 60) | ||
| const maxPhi = controls.getCurrentCoordinates().phi | ||
|
|
||
| controls.setImmediateCoordinates({ phi: -Math.PI }) | ||
| controls.update(1 / 60) | ||
| const minPhi = controls.getCurrentCoordinates().phi | ||
|
|
||
| expect(maxPhi).toBeLessThan(Math.PI) | ||
| expect(minPhi).toBeGreaterThan(-Math.PI) | ||
| expect(minPhi).toBeLessThan(maxPhi) | ||
| }) | ||
| }) | ||
|
|
||
| describe("Mouse Interaction", () => { | ||
| const simulateMouseInteraction = (options: { | ||
| startPosition: [number, number] | ||
| movement?: [number, number] | ||
| scale?: number | ||
| updateFrames: number | ||
| endPosition: [number, number] | ||
| interactionType?: InteractionType | ||
| }) => { | ||
| const { startPosition, movement, scale, updateFrames, endPosition, interactionType = 0 } = options | ||
|
|
||
| controls.interactionStart({ | ||
| interactionType, | ||
| position: startPosition, | ||
| }) | ||
|
|
||
| if (movement || scale !== undefined) { | ||
| controls.interactionMove({ | ||
| interactionType, | ||
| movement, | ||
| scale, | ||
| }) | ||
| } | ||
|
|
||
| for (let i = 0; i < updateFrames; i++) { | ||
| controls.update(1 / 60) | ||
| } | ||
|
|
||
| controls.interactionEnd({ | ||
| interactionType, | ||
| position: endPosition, | ||
| }) | ||
|
|
||
| for (let i = 0; i < 10; i++) { | ||
| controls.update(1 / 60) | ||
| } | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| controls.setImmediateCoordinates({ theta: 0, phi: 0, r: 5 }) | ||
| controls.update(1 / 60) | ||
| }) | ||
|
|
||
| test("simulate mouse drag", () => { | ||
| const initialCoords = controls.getCurrentCoordinates() | ||
|
|
||
| simulateMouseInteraction({ | ||
| startPosition: [100, 100], | ||
| movement: [0.28, -0.105], | ||
| updateFrames: 60, | ||
| endPosition: [180, 70], | ||
| }) | ||
|
|
||
| expect(controls.getCurrentCoordinates()).not.toEqual(initialCoords) | ||
|
|
||
| expect(camera.position.distanceTo(new THREE.Vector3(0, 0, 0))).toBeCloseTo(5) | ||
| }) | ||
|
|
||
| test("should zoom in and out correctly", () => { | ||
| const initialDistance = camera.position.distanceTo(new THREE.Vector3(0, 0, 0)) | ||
| expect(initialDistance).toBeCloseTo(5, 0) | ||
|
|
||
| simulateMouseInteraction({ | ||
| scale: -1.0, | ||
| updateFrames: 1, | ||
| startPosition: [100, 100], | ||
| endPosition: [100, 100], | ||
| }) | ||
|
|
||
| const zoomedInDistance = camera.position.distanceTo(new THREE.Vector3(0, 0, 0)) | ||
|
|
||
| simulateMouseInteraction({ | ||
| scale: 2.0, | ||
| updateFrames: 1, | ||
| startPosition: [100, 100], | ||
| endPosition: [100, 100], | ||
| }) | ||
|
|
||
| const finalDistance = camera.position.distanceTo(new THREE.Vector3(0, 0, 0)) | ||
|
|
||
| expect(zoomedInDistance).toBeCloseTo(4, 0) | ||
| expect(finalDistance).toBeCloseTo(5.4, 0) | ||
| }) | ||
|
|
||
| test("should not update when disabled", () => { | ||
| const initialPosition = camera.position.clone() | ||
|
|
||
| controls.enabled = false | ||
|
|
||
| simulateMouseInteraction({ | ||
| startPosition: [100, 100], | ||
| movement: [0.175, 0.35], | ||
| updateFrames: 30, | ||
| endPosition: [150, 200], | ||
| }) | ||
|
|
||
| expect(camera.position.distanceTo(initialPosition)).toBeCloseTo(0) | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function was added in the view cube pr, but it isn't actually used anywhere in the code. It also only moves the camera towards the target coordinates for only one frame and then stops.