@@ -4,7 +4,7 @@ import { MergedProperties } from './properties/merged.js'
4
4
import { computedInheritableProperty } from './properties/index.js'
5
5
import { readReactive } from './utils.js'
6
6
7
- export type WithCameraDistance = { cameraDistance : number }
7
+ export type WithCameraDistance = { cameraDistance : number ; reversePainterSortStableCache ?: number }
8
8
9
9
export const cameraDistanceKey = Symbol ( 'camera-distance-key' )
10
10
export const orderInfoKey = Symbol ( 'order-info-key' )
@@ -16,11 +16,21 @@ export function reversePainterSortStable(a: RenderItem, b: RenderItem) {
16
16
if ( a . renderOrder !== b . renderOrder ) {
17
17
return a . renderOrder - b . renderOrder
18
18
}
19
- const aDistanceRef = ( a . object as any ) [ cameraDistanceKey ] as WithCameraDistance
20
- const bDistanceRef = ( b . object as any ) [ cameraDistanceKey ] as WithCameraDistance
19
+ let az = a . z
20
+ let bz = b . z
21
+ const aDistanceRef = ( a . object as any ) [ cameraDistanceKey ] as WithCameraDistance | undefined
22
+ const bDistanceRef = ( b . object as any ) [ cameraDistanceKey ] as WithCameraDistance | undefined
23
+ if ( aDistanceRef != null ) {
24
+ aDistanceRef . reversePainterSortStableCache ??= az
25
+ az = aDistanceRef . reversePainterSortStableCache
26
+ }
27
+ if ( bDistanceRef != null ) {
28
+ bDistanceRef . reversePainterSortStableCache ??= bz
29
+ bz = bDistanceRef . reversePainterSortStableCache
30
+ }
21
31
if ( aDistanceRef == null || bDistanceRef == null ) {
22
32
//default z comparison
23
- return a . z !== b . z ? b . z - a . z : a . id - b . id
33
+ return az !== bz ? bz - az : a . id - b . id
24
34
}
25
35
if ( aDistanceRef === bDistanceRef ) {
26
36
return compareOrderInfo ( ( a . object as any ) [ orderInfoKey ] . value , ( b . object as any ) [ orderInfoKey ] . value )
0 commit comments