-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(viewer): per-level base elevation parameter #312
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
Aymericr
merged 8 commits into
pascalorg:main
from
mvanhorn:feat/209-level-floor-height-parameter
Aug 4, 2026
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
92a550e
feat(viewer): per-level base elevation parameter
mvanhorn 1b5db7c
Merge remote-tracking branch 'upstream/main' into feat/209-level-floo…
mvanhorn ac82cf8
fix: thread baseElevation through slab clamps, elevator stacking and …
mvanhorn bb72693
Merge remote-tracking branch 'origin/main' into HEAD
Aymericr 97c10ca
viewer: stop the level-system test mocking core, and fix the type gate
Aymericr 61cfb47
Merge remote-tracking branch 'origin/main' into HEAD
Aymericr 0f47923
test(core): build a fresh nodes record when re-asserting the lowered …
Aymericr b96c3b9
fix(core): take the highest ceiling in the stack as the elevator shaf…
Aymericr 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
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,165 @@ | ||
| // @ts-expect-error — bun:test is provided by the Bun runtime; viewer does not | ||
| // include Bun ambient types in its production declaration build. | ||
| import { afterEach, describe, expect, mock, test } from 'bun:test' | ||
|
|
||
| type FakeLevelObject = { | ||
| position: { y: number } | ||
| visible: boolean | ||
| } | ||
|
|
||
| type FakeLevelNode = { | ||
| id: string | ||
| type: 'level' | ||
| parentId: string | ||
| level: number | ||
| baseElevation: number | ||
| children: [] | ||
| } | ||
|
|
||
| type FakeBuildingNode = { | ||
| id: string | ||
| type: 'building' | ||
| children: string[] | ||
| } | ||
|
|
||
| const levelIds = new Set<string>() | ||
| const registryNodes = new Map<string, FakeLevelObject>() | ||
| const sceneRegistry = { | ||
| byType: { level: levelIds }, | ||
| nodes: registryNodes, | ||
| } | ||
| let nodes: Record<string, FakeLevelNode | FakeBuildingNode> = {} | ||
| let viewerState = { | ||
| levelMode: 'stacked' as 'stacked' | 'exploded' | 'solo', | ||
| selection: { levelId: null as string | null }, | ||
| } | ||
| let frameCallback: ((state: unknown, delta: number) => void) | null = null | ||
|
|
||
| mock.module('@pascal-app/core', () => ({ | ||
| getLevelHeight: (levelId: string) => (nodes[levelId]?.type === 'level' ? 2.5 : 0), | ||
| sceneRegistry, | ||
| useScene: { | ||
| getState: () => ({ nodes }), | ||
| }, | ||
| })) | ||
|
|
||
| mock.module('@react-three/fiber', () => ({ | ||
| useFrame: (callback: (state: unknown, delta: number) => void) => { | ||
| frameCallback = callback | ||
| }, | ||
| })) | ||
|
|
||
| mock.module('three/src/math/MathUtils.js', () => ({ | ||
| lerp: (start: number, end: number, alpha: number) => start + (end - start) * alpha, | ||
| })) | ||
|
|
||
| mock.module('../../store/use-viewer', () => ({ | ||
| default: { | ||
| getState: () => viewerState, | ||
| }, | ||
| })) | ||
|
|
||
| const [{ LevelSystem }, { snapLevelsToTruePositions }] = await Promise.all([ | ||
| import('./level-system'), | ||
| import('./level-utils'), | ||
| ]) | ||
|
|
||
| function setupLevels(baseElevations: number[]) { | ||
| const buildingId = 'building_base-elevation-system-test' | ||
| const levels: FakeLevelNode[] = baseElevations.map((baseElevation, level) => ({ | ||
| id: `level_base-elevation-system-${level}`, | ||
| type: 'level', | ||
| parentId: buildingId, | ||
| level, | ||
| baseElevation, | ||
| children: [], | ||
| })) | ||
| const building: FakeBuildingNode = { | ||
| id: buildingId, | ||
| type: 'building', | ||
| children: levels.map((level) => level.id), | ||
| } | ||
| nodes = Object.fromEntries([building, ...levels].map((node) => [node.id, node])) | ||
|
|
||
| const objects = levels.map((level) => { | ||
| const object: FakeLevelObject = { | ||
| position: { y: -100 }, | ||
| visible: true, | ||
| } | ||
| sceneRegistry.nodes.set(level.id, object) | ||
| sceneRegistry.byType.level.add(level.id) | ||
| return object | ||
| }) | ||
|
|
||
| return { building, levels, objects } | ||
| } | ||
|
|
||
| function setLevelMode( | ||
| mode: 'stacked' | 'exploded' | 'solo', | ||
| selectedLevelId: string | null = null, | ||
| ) { | ||
| viewerState = { | ||
| levelMode: mode, | ||
| selection: { levelId: selectedLevelId }, | ||
| } | ||
| } | ||
|
|
||
| function updateLevelPresentation(delta: number) { | ||
| frameCallback = null | ||
| LevelSystem() | ||
| expect(frameCallback).not.toBeNull() | ||
| frameCallback?.({}, delta) | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| sceneRegistry.nodes.clear() | ||
| sceneRegistry.byType.level.clear() | ||
| nodes = {} | ||
| }) | ||
|
|
||
| describe('updateLevelPresentation', () => { | ||
| test('writes offset positions to the registry transform used by floorplan and selection', () => { | ||
| const { objects } = setupLevels([0, 1.25, 0]) | ||
| setLevelMode('stacked') | ||
|
|
||
| updateLevelPresentation(1 / 12) | ||
|
|
||
| expect(objects.map((object) => object.position.y)).toEqual([0, 3.75, 6.25]) | ||
| }) | ||
|
|
||
| test('keeps offset-aware positions in exploded and solo modes', () => { | ||
| const { levels, objects } = setupLevels([1, 0.5]) | ||
|
|
||
| setLevelMode('exploded') | ||
| updateLevelPresentation(1 / 12) | ||
| expect(objects.map((object) => object.position.y)).toEqual([1, 9]) | ||
|
|
||
| objects.forEach((object) => { | ||
| object.position.y = -100 | ||
| }) | ||
| setLevelMode('solo', levels[1]!.id) | ||
| updateLevelPresentation(1 / 12) | ||
| expect(objects.map((object) => object.position.y)).toEqual([1, 4]) | ||
| expect(objects[0]!.visible).toBe(false) | ||
| expect(objects[1]!.visible).toBe(true) | ||
| }) | ||
| }) | ||
|
|
||
| describe('snapLevelsToTruePositions', () => { | ||
| test('bakes offset-aware stacked positions and restores the prior presentation', () => { | ||
| const { objects } = setupLevels([0.5, 1.25]) | ||
| objects[0]!.position.y = 10 | ||
| objects[0]!.visible = false | ||
| objects[1]!.position.y = 20 | ||
|
|
||
| const restore = snapLevelsToTruePositions() | ||
|
|
||
| expect(objects.map((object) => object.position.y)).toEqual([0.5, 4.25]) | ||
| expect(objects.map((object) => object.visible)).toEqual([true, true]) | ||
|
|
||
| restore() | ||
|
|
||
| expect(objects.map((object) => object.position.y)).toEqual([10, 20]) | ||
| expect(objects.map((object) => object.visible)).toEqual([false, true]) | ||
| }) | ||
| }) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.