distark-render 1.2.5 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/characterSchema.d.ts +128 -0
- package/dist/modules/characterSchema.d.ts.map +1 -0
- package/dist/modules/characterSchema.js +347 -0
- package/dist/modules/characterSchema.js.map +1 -0
- package/dist/modules/characterValidator.d.ts +4 -18
- package/dist/modules/characterValidator.d.ts.map +1 -1
- package/dist/modules/characterValidator.js +9 -67
- package/dist/modules/characterValidator.js.map +1 -1
- package/dist/modules/eyeSystem.js +5 -5
- package/dist/modules/filmsetToWorld.d.ts +54 -0
- package/dist/modules/filmsetToWorld.d.ts.map +1 -0
- package/dist/modules/filmsetToWorld.js +110 -0
- package/dist/modules/filmsetToWorld.js.map +1 -0
- package/dist/modules/imageLoad.d.ts.map +1 -1
- package/dist/modules/imageLoad.js +2 -21
- package/dist/modules/imageLoad.js.map +1 -1
- package/dist/modules/perspectiveDepth.d.ts +52 -0
- package/dist/modules/perspectiveDepth.d.ts.map +1 -0
- package/dist/modules/perspectiveDepth.js +69 -0
- package/dist/modules/perspectiveDepth.js.map +1 -0
- package/dist/modules/sceneRenderer.d.ts +3 -1
- package/dist/modules/sceneRenderer.d.ts.map +1 -1
- package/dist/modules/sceneRenderer.js +9 -5
- package/dist/modules/sceneRenderer.js.map +1 -1
- package/dist/modules/svgAssetFix.d.ts.map +1 -1
- package/dist/modules/svgAssetFix.js +2 -17
- package/dist/modules/svgAssetFix.js.map +1 -1
- package/dist/modules/svgUnits.d.ts +17 -0
- package/dist/modules/svgUnits.d.ts.map +1 -0
- package/dist/modules/svgUnits.js +37 -0
- package/dist/modules/svgUnits.js.map +1 -0
- package/dist/modules/worldBuilder.d.ts +73 -0
- package/dist/modules/worldBuilder.d.ts.map +1 -0
- package/dist/modules/worldBuilder.js +176 -0
- package/dist/modules/worldBuilder.js.map +1 -0
- package/dist/modules/worldPlacement.d.ts +130 -0
- package/dist/modules/worldPlacement.d.ts.map +1 -0
- package/dist/modules/worldPlacement.js +262 -0
- package/dist/modules/worldPlacement.js.map +1 -0
- package/dist/tests/test-character-schema.d.ts +8 -0
- package/dist/tests/test-character-schema.d.ts.map +1 -0
- package/dist/tests/test-character-schema.js +118 -0
- package/dist/tests/test-character-schema.js.map +1 -0
- package/dist/tests/test-character-validator.js +8 -3
- package/dist/tests/test-character-validator.js.map +1 -1
- package/dist/tests/test-rig-standardization.js +18 -18
- package/dist/tests/test-svg-asset-fix.js +20 -20
- package/dist/tests/test-world-builder.d.ts +5 -0
- package/dist/tests/test-world-builder.d.ts.map +1 -0
- package/dist/tests/test-world-builder.js +103 -0
- package/dist/tests/test-world-builder.js.map +1 -0
- package/dist/tests/test-world-z-order.d.ts +5 -0
- package/dist/tests/test-world-z-order.d.ts.map +1 -0
- package/dist/tests/test-world-z-order.js +45 -0
- package/dist/tests/test-world-z-order.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +150 -126
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svgUnits.js","sourceRoot":"","sources":["../../modules/svgUnits.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAqC;IAC7D,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE,GAAG,IAAI;IACb,EAAE,EAAE,EAAE,GAAG,IAAI;IACb,EAAE,EAAE,EAAE,GAAG,EAAE;IACX,EAAE,EAAE,EAAE;CACT,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAgC;IAC/D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACxE,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/C,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9C,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IAC9B,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* worldBuilder.ts — Build WorldJSON scenes (aligned with make_episodes submit / arcPlanToWorld).
|
|
3
|
+
*
|
|
4
|
+
* Pure assembly: placements + background URL → WorldJSON with camera + character tracks.
|
|
5
|
+
*/
|
|
6
|
+
import { type NormalizedFootprint } from './worldPlacement.js';
|
|
7
|
+
import type { WorldJSON } from './sceneRenderer.js';
|
|
8
|
+
export interface CameraViewport {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SceneSize {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
}
|
|
18
|
+
export interface CharacterPlacementInput {
|
|
19
|
+
name: string;
|
|
20
|
+
orcKey: string;
|
|
21
|
+
/** Rig root anchor Y (WorldJSON yCoor). */
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
/** Foot / ground contact Y for z-order (defaults to y when omitted). */
|
|
25
|
+
footY?: number;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
z?: number;
|
|
29
|
+
renderScale?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface ForegroundObjectInput {
|
|
32
|
+
id: string;
|
|
33
|
+
frontImage: string;
|
|
34
|
+
xCoor: number;
|
|
35
|
+
yCoor: number;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
/** Normalised 0–1 ground footprint for obstacle z-order. */
|
|
39
|
+
groundFootprint?: NormalizedFootprint;
|
|
40
|
+
/** Raw SVG markup (CAM svgSource). */
|
|
41
|
+
svgSource?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface WorldDialogInput {
|
|
44
|
+
id: string;
|
|
45
|
+
title: string;
|
|
46
|
+
duration: number;
|
|
47
|
+
agent_name: string;
|
|
48
|
+
text: string;
|
|
49
|
+
}
|
|
50
|
+
export interface BuildShotWorldInput {
|
|
51
|
+
shotId: string;
|
|
52
|
+
background: string | null;
|
|
53
|
+
characters: CharacterPlacementInput[];
|
|
54
|
+
foregroundObjects?: ForegroundObjectInput[];
|
|
55
|
+
duration?: number;
|
|
56
|
+
viewport?: CameraViewport;
|
|
57
|
+
/** End camera viewport at `duration` (e.g. camera movement). Defaults to `viewport`. */
|
|
58
|
+
cameraEndViewport?: CameraViewport;
|
|
59
|
+
sceneSize?: SceneSize;
|
|
60
|
+
orcBaseUrl?: string;
|
|
61
|
+
dialogs?: WorldDialogInput[];
|
|
62
|
+
characterDefaults?: {
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build a single-shot WorldJSON — same structure as arcPlanToWorld in make_episodes submit pipeline.
|
|
69
|
+
*/
|
|
70
|
+
export declare function buildShotWorld(input: BuildShotWorldInput): WorldJSON;
|
|
71
|
+
/** CAM expects size + variation lanes and renderScale on characters. */
|
|
72
|
+
export declare function ensureCamTimelineLanes(world: WorldJSON): void;
|
|
73
|
+
//# sourceMappingURL=worldBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worldBuilder.d.ts","sourceRoot":"","sources":["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d;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,uBAAuB,EAAE,CAAC;IACtC,iBAAiB,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,wFAAwF;IACxF,iBAAiB,CAAC,EAAE,cAAc,CAAC;IACnC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC7B,iBAAiB,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACvD;AAkBD;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,SAAS,CA6HpE;AAED,wEAAwE;AACxE,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAmC7D"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* worldBuilder.ts — Build WorldJSON scenes (aligned with make_episodes submit / arcPlanToWorld).
|
|
3
|
+
*
|
|
4
|
+
* Pure assembly: placements + background URL → WorldJSON with camera + character tracks.
|
|
5
|
+
*/
|
|
6
|
+
import { assignZIndices, DEFAULT_WORLD_SIZE, footprintToPixels, } from './worldPlacement.js';
|
|
7
|
+
const DEFAULT_ORC = 'https://orchestrator.distark.com';
|
|
8
|
+
const DEFAULT_CHAR_SIZE = { width: 200, height: 400 };
|
|
9
|
+
function orcArtifactSource(orcBaseUrl, orcKey) {
|
|
10
|
+
return `${orcBaseUrl}/api/v1/artifacts/artkey_${encodeURIComponent(orcKey)}`;
|
|
11
|
+
}
|
|
12
|
+
function fullSceneViewport(scene) {
|
|
13
|
+
return {
|
|
14
|
+
x: scene.width / 2,
|
|
15
|
+
y: scene.height / 2,
|
|
16
|
+
width: scene.width,
|
|
17
|
+
height: scene.height,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build a single-shot WorldJSON — same structure as arcPlanToWorld in make_episodes submit pipeline.
|
|
22
|
+
*/
|
|
23
|
+
export function buildShotWorld(input) {
|
|
24
|
+
const scene = input.sceneSize ?? DEFAULT_WORLD_SIZE;
|
|
25
|
+
const duration = input.duration ?? 3;
|
|
26
|
+
const orcBase = input.orcBaseUrl ?? DEFAULT_ORC;
|
|
27
|
+
const charDefaults = input.characterDefaults ?? DEFAULT_CHAR_SIZE;
|
|
28
|
+
const viewport = input.viewport ?? fullSceneViewport(scene);
|
|
29
|
+
const endViewport = input.cameraEndViewport ?? viewport;
|
|
30
|
+
const characters = [];
|
|
31
|
+
const charNames = new Set();
|
|
32
|
+
for (const c of input.characters) {
|
|
33
|
+
charNames.add(c.name);
|
|
34
|
+
const char = {
|
|
35
|
+
id: c.name,
|
|
36
|
+
name: c.name,
|
|
37
|
+
source: orcArtifactSource(orcBase, c.orcKey),
|
|
38
|
+
xCoor: c.x,
|
|
39
|
+
yCoor: c.y,
|
|
40
|
+
footY: c.footY ?? c.y,
|
|
41
|
+
width: c.width || charDefaults.width,
|
|
42
|
+
height: c.height || charDefaults.height,
|
|
43
|
+
};
|
|
44
|
+
if (c.renderScale != null)
|
|
45
|
+
char.renderScale = c.renderScale;
|
|
46
|
+
characters.push(char);
|
|
47
|
+
}
|
|
48
|
+
const fgObjects = input.foregroundObjects ?? [];
|
|
49
|
+
const zSortItems = [
|
|
50
|
+
...input.characters.map(c => ({
|
|
51
|
+
id: c.name,
|
|
52
|
+
yCoor: c.footY ?? c.y,
|
|
53
|
+
xCoor: c.x,
|
|
54
|
+
kind: 'character',
|
|
55
|
+
})),
|
|
56
|
+
...fgObjects.map(o => ({
|
|
57
|
+
id: o.id,
|
|
58
|
+
yCoor: o.yCoor,
|
|
59
|
+
xCoor: o.xCoor,
|
|
60
|
+
kind: 'object',
|
|
61
|
+
groundFootprint: o.groundFootprint
|
|
62
|
+
? footprintToPixels(o.groundFootprint, scene.width, scene.height)
|
|
63
|
+
: undefined,
|
|
64
|
+
})),
|
|
65
|
+
];
|
|
66
|
+
const zIndexMap = assignZIndices(zSortItems);
|
|
67
|
+
for (const char of characters) {
|
|
68
|
+
char.zIndex = zIndexMap.get(char.id) ?? 0;
|
|
69
|
+
}
|
|
70
|
+
const timeline = [];
|
|
71
|
+
const camStart = {
|
|
72
|
+
x: viewport.x,
|
|
73
|
+
y: viewport.y,
|
|
74
|
+
width: viewport.width,
|
|
75
|
+
height: viewport.height,
|
|
76
|
+
};
|
|
77
|
+
const camEnd = {
|
|
78
|
+
x: endViewport.x,
|
|
79
|
+
y: endViewport.y,
|
|
80
|
+
width: endViewport.width,
|
|
81
|
+
height: endViewport.height,
|
|
82
|
+
};
|
|
83
|
+
const cameraKeyframes = [
|
|
84
|
+
{ time: 0, value: camStart, easing: 'easeInOut' },
|
|
85
|
+
];
|
|
86
|
+
if (duration > 0) {
|
|
87
|
+
cameraKeyframes.push({ time: duration, value: camEnd, easing: 'easeInOut' });
|
|
88
|
+
}
|
|
89
|
+
timeline.push({
|
|
90
|
+
characterId: '__camera__',
|
|
91
|
+
lanes: [{ property: 'camera', keyframes: cameraKeyframes }],
|
|
92
|
+
actions: [],
|
|
93
|
+
});
|
|
94
|
+
for (const c of input.characters) {
|
|
95
|
+
const w = c.width || charDefaults.width;
|
|
96
|
+
const h = c.height || charDefaults.height;
|
|
97
|
+
timeline.push({
|
|
98
|
+
characterId: c.name,
|
|
99
|
+
lanes: [
|
|
100
|
+
{
|
|
101
|
+
property: 'size',
|
|
102
|
+
keyframes: [{ time: 0, value: { width: w, height: h }, easing: 'linear' }],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
property: 'variation',
|
|
106
|
+
keyframes: [{ time: 0, value: 'default', easing: 'instant' }],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
property: 'position',
|
|
110
|
+
keyframes: [{ time: 0, value: { x: c.x, y: c.y }, easing: 'linear' }],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
property: 'zIndex',
|
|
114
|
+
keyframes: [{ time: 0, value: zIndexMap.get(c.name), easing: 'instant' }],
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
actions: [],
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
const worldObjects = fgObjects.map(o => ({
|
|
121
|
+
id: o.id,
|
|
122
|
+
frontImage: o.frontImage,
|
|
123
|
+
xCoor: o.xCoor,
|
|
124
|
+
yCoor: o.yCoor,
|
|
125
|
+
width: o.width,
|
|
126
|
+
height: o.height,
|
|
127
|
+
zIndex: zIndexMap.get(o.id) ?? 0,
|
|
128
|
+
...(o.svgSource ? { svgSource: o.svgSource } : {}),
|
|
129
|
+
}));
|
|
130
|
+
return {
|
|
131
|
+
scene: { background: input.background },
|
|
132
|
+
filename: input.shotId,
|
|
133
|
+
characters,
|
|
134
|
+
objects: worldObjects,
|
|
135
|
+
dialogs: input.dialogs ?? [],
|
|
136
|
+
timeline,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** CAM expects size + variation lanes and renderScale on characters. */
|
|
140
|
+
export function ensureCamTimelineLanes(world) {
|
|
141
|
+
for (const char of world.characters ?? []) {
|
|
142
|
+
const track = world.timeline?.find(t => t.characterId === char.id);
|
|
143
|
+
if (!track)
|
|
144
|
+
continue;
|
|
145
|
+
track.lanes = track.lanes ?? [];
|
|
146
|
+
const height = char.height ?? 400;
|
|
147
|
+
const width = char.width ?? 200;
|
|
148
|
+
if (char.renderScale == null && height > 0) {
|
|
149
|
+
char.renderScale = height / 943;
|
|
150
|
+
}
|
|
151
|
+
if (!track.lanes.some(l => l.property === 'variation')) {
|
|
152
|
+
track.lanes.unshift({
|
|
153
|
+
property: 'variation',
|
|
154
|
+
keyframes: [{ time: 0, value: 'default', easing: 'instant' }],
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const sizeLane = track.lanes.find(l => l.property === 'size');
|
|
158
|
+
const sizeAtZero = { width, height };
|
|
159
|
+
if (!sizeLane) {
|
|
160
|
+
track.lanes.unshift({
|
|
161
|
+
property: 'size',
|
|
162
|
+
keyframes: [{ time: 0, value: sizeAtZero, easing: 'linear' }],
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
for (const kf of sizeLane.keyframes) {
|
|
167
|
+
if (kf.time === 0)
|
|
168
|
+
kf.value = sizeAtZero;
|
|
169
|
+
}
|
|
170
|
+
if (!sizeLane.keyframes.some(kf => kf.time === 0)) {
|
|
171
|
+
sizeLane.keyframes.unshift({ time: 0, value: sizeAtZero, easing: 'linear' });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=worldBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worldBuilder.js","sourceRoot":"","sources":["../../modules/worldBuilder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,iBAAiB,GAGlB,MAAM,qBAAqB,CAAC;AAsE7B,MAAM,WAAW,GAAG,kCAAkC,CAAC;AACvD,MAAM,iBAAiB,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAEtD,SAAS,iBAAiB,CAAC,UAAkB,EAAE,MAAc;IAC3D,OAAO,GAAG,UAAU,4BAA4B,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAgB;IACzC,OAAO;QACL,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC;QAClB,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC;QACnB,KAAK,EAAE,KAAK,CAAC,KAAK;Q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C,QAAQ,EAAE,CAAC;YACd,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;gBAClB,QAAQ,EAAE,MAAM;gBAChB,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;aAC9D,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,KAAK,MAAM,EAAE,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACpC,IAAI,EAAE,CAAC,IAAI,KAAK,CAAC;oBAAE,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC;YAC3C,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC;gBAClD,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC/E,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* worldPlacement.ts — Perspective depth → pixel foot position + character size.
|
|
3
|
+
*/
|
|
4
|
+
import type { RigData } from '../types.js';
|
|
5
|
+
import { type PerspectiveDepthInput } from './perspectiveDepth.js';
|
|
6
|
+
export { DEFAULT_DEPTH_MAX, DEFAULT_DEPTH_MIN, DEFAULT_NATURAL_HEIGHT, DEFAULT_REFERENCE_FRACTION, DEFAULT_WORLD_SIZE, characterSizeAtDepth, clampDepth, depthBackY, depthFromY, depthMax, depthMin, depthScaleFactor, rigAspectRatio, rigNaturalHeight, renderScaleForHeight, yFromDepth, } from './perspectiveDepth.js';
|
|
7
|
+
export interface LayoutPerspective extends PerspectiveDepthInput {
|
|
8
|
+
cameraAngle?: number;
|
|
9
|
+
steepness?: number;
|
|
10
|
+
standingZoneTopY?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface LayoutRegion {
|
|
13
|
+
type: string;
|
|
14
|
+
bbox: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
w: number;
|
|
18
|
+
h: number;
|
|
19
|
+
};
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface LayoutData {
|
|
23
|
+
imagePath?: string;
|
|
24
|
+
width?: number;
|
|
25
|
+
height?: number;
|
|
26
|
+
perspective?: LayoutPerspective;
|
|
27
|
+
regions?: LayoutRegion[];
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
export interface StandingPoint {
|
|
31
|
+
id: string;
|
|
32
|
+
label: string;
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
z: number;
|
|
36
|
+
kind?: string;
|
|
37
|
+
meta?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
export interface FootPlacement {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
z: number;
|
|
45
|
+
}
|
|
46
|
+
export interface ResolvedPlacement {
|
|
47
|
+
x: number;
|
|
48
|
+
/** Rig root anchor Y for WorldJSON (feet at footY when full rig correction applied). */
|
|
49
|
+
y: number;
|
|
50
|
+
/** Scene-point foot / ground contact Y (canonical for z-order and overlays). */
|
|
51
|
+
footY: number;
|
|
52
|
+
z: number;
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
renderScale: number;
|
|
56
|
+
}
|
|
57
|
+
export type RigDimensionsInput = {
|
|
58
|
+
width?: number;
|
|
59
|
+
height?: number;
|
|
60
|
+
};
|
|
61
|
+
export type RigInput = RigData | RigDimensionsInput;
|
|
62
|
+
export declare function isFullRigData(rig: RigInput | null | undefined): rig is RigData;
|
|
63
|
+
/**
|
|
64
|
+
* Pixel foot Y from normalized ingest person detection (bottom of bbox).
|
|
65
|
+
*/
|
|
66
|
+
export declare function footYFromIngestDetection(centerYNorm: number, sizeNorm: number, worldH?: number): number;
|
|
67
|
+
export interface CharacterPositionLike {
|
|
68
|
+
x: number;
|
|
69
|
+
y: number;
|
|
70
|
+
width?: number;
|
|
71
|
+
height?: number;
|
|
72
|
+
z?: number;
|
|
73
|
+
key?: string;
|
|
74
|
+
renderScale?: number;
|
|
75
|
+
}
|
|
76
|
+
export interface NormalizedFootprint {
|
|
77
|
+
x: number;
|
|
78
|
+
y: number;
|
|
79
|
+
w: number;
|
|
80
|
+
h: number;
|
|
81
|
+
}
|
|
82
|
+
/** Pixel-space ground footprint (unstandable zone). */
|
|
83
|
+
export interface PixelFootprint {
|
|
84
|
+
left: number;
|
|
85
|
+
right: number;
|
|
86
|
+
top: number;
|
|
87
|
+
bottom: number;
|
|
88
|
+
}
|
|
89
|
+
export type ObstacleRelation = 'in_front' | 'behind';
|
|
90
|
+
export interface ZSortable {
|
|
91
|
+
id: string;
|
|
92
|
+
yCoor: number;
|
|
93
|
+
xCoor?: number;
|
|
94
|
+
kind?: 'character' | 'object';
|
|
95
|
+
/** Object ground footprint in pixels (for obstacle z-order rules). */
|
|
96
|
+
groundFootprint?: PixelFootprint;
|
|
97
|
+
/** @deprecated No longer used for z-order; kept for callers that still pass scene depth. */
|
|
98
|
+
z?: number;
|
|
99
|
+
}
|
|
100
|
+
export declare function footprintToPixels(fp: NormalizedFootprint, worldW: number, worldH: number): PixelFootprint;
|
|
101
|
+
/**
|
|
102
|
+
* Character vs obstacle unstandable footprint:
|
|
103
|
+
* - foot above footprint (y < top) → behind
|
|
104
|
+
* - foot below footprint (y > bottom) → in front
|
|
105
|
+
* - foot beside footprint (no x overlap) → behind
|
|
106
|
+
*/
|
|
107
|
+
export declare function characterObstacleRelation(charX: number, charY: number, footprint: PixelFootprint): ObstacleRelation;
|
|
108
|
+
export declare function defaultLayoutData(): LayoutData;
|
|
109
|
+
export declare function placementFromPoint(point: StandingPoint, layout: LayoutData | null, rig?: RigInput | null): FootPlacement;
|
|
110
|
+
/**
|
|
111
|
+
* Convert foot placement → rig root anchor Y using measured rig bounds.
|
|
112
|
+
* WorldJSON yCoor uses root Y; renderer places root at yCoor so feet land at footY.
|
|
113
|
+
*/
|
|
114
|
+
export declare function rootAnchorFromFootPlacement(foot: FootPlacement, rigData: RigData): Promise<ResolvedPlacement>;
|
|
115
|
+
export declare function placementFromCharacterPosition(pos: CharacterPositionLike, layout: LayoutData | null, rig?: RigInput | null): FootPlacement;
|
|
116
|
+
export interface ResolvePlacementOptions {
|
|
117
|
+
rigDataMap?: Record<string, RigInput>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Place characters at scene-aware standing points (round-robin over points).
|
|
121
|
+
* When full rig JSON is available, y is adjusted to rig root anchor (feet at footY).
|
|
122
|
+
*/
|
|
123
|
+
export declare function resolveCharacterPlacements(layout: LayoutData, characterNames: string[], _charKeys: Record<string, string>, points: StandingPoint[], opts?: ResolvePlacementOptions): Promise<Record<string, ResolvedPlacement>>;
|
|
124
|
+
export declare function characterRenderOrder(pos: CharacterPositionLike, perspective?: LayoutPerspective, worldH?: number): number;
|
|
125
|
+
export declare function compareCharactersByDepth(a: string, b: string, positions: Record<string, CharacterPositionLike>, perspective?: LayoutPerspective, worldH?: number): number;
|
|
126
|
+
/**
|
|
127
|
+
* Assign world zIndex (1 = furthest back) using foot Y and obstacle footprint rules.
|
|
128
|
+
*/
|
|
129
|
+
export declare function assignZIndices(items: ZSortable[]): Map<string, number>;
|
|
130
|
+
//# sourceMappingURL=worldPlacement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worldPlacement.d.ts","sourceRoot":"","sources":["../../modules/worldPlacement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAUL,KAAK,qBAAqB,EAC3B,MAAM,uBAAuB,CAAC;AA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C,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CACvC;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,UAAU,EAClB,cAAc,EAAE,MAAM,EAAE,EACxB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,MAAM,EAAE,aAAa,EAAE,EACvB,IAAI,GAAE,uBAA4B,GACjC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAkD5C;AAED,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,qBAAqB,EAC1B,WAAW,GAAE,iBAAoD,EACjE,MAAM,SAA4B,GACjC,MAAM,CAGR;AAED,wBAAgB,wBAAwB,CACtC,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,EAChD,WAAW,GAAE,iBAAoD,EACjE,MAAM,SAA4B,GACjC,MAAM,CAOR;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBtE"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* worldPlacement.ts — Perspective depth → pixel foot position + character size.
|
|
3
|
+
*/
|
|
4
|
+
import { DEFAULT_DEPTH_MAX, DEFAULT_DEPTH_MIN, DEFAULT_REFERENCE_FRACTION, DEFAULT_WORLD_SIZE, characterSizeAtDepth, clampDepth, depthFromY, rigNaturalHeight, yFromDepth, } from './perspectiveDepth.js';
|
|
5
|
+
import { computeRigBounds } from './sceneRenderer.js';
|
|
6
|
+
export { DEFAULT_DEPTH_MAX, DEFAULT_DEPTH_MIN, DEFAULT_NATURAL_HEIGHT, DEFAULT_REFERENCE_FRACTION, DEFAULT_WORLD_SIZE, characterSizeAtDepth, clampDepth, depthBackY, depthFromY, depthMax, depthMin, depthScaleFactor, rigAspectRatio, rigNaturalHeight, renderScaleForHeight, yFromDepth, } from './perspectiveDepth.js';
|
|
7
|
+
export function isFullRigData(rig) {
|
|
8
|
+
if (!rig || typeof rig !== 'object')
|
|
9
|
+
return false;
|
|
10
|
+
return 'imagePaths' in rig || 'pivotPoints' in rig;
|
|
11
|
+
}
|
|
12
|
+
function rigForSizing(rig) {
|
|
13
|
+
if (!rig)
|
|
14
|
+
return null;
|
|
15
|
+
return rig;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Pixel foot Y from normalized ingest person detection (bottom of bbox).
|
|
19
|
+
*/
|
|
20
|
+
export function footYFromIngestDetection(centerYNorm, sizeNorm, worldH = DEFAULT_WORLD_SIZE.height) {
|
|
21
|
+
const heightPx = Math.max(80, Math.round(sizeNorm * worldH));
|
|
22
|
+
return Math.round(centerYNorm * worldH + heightPx / 2);
|
|
23
|
+
}
|
|
24
|
+
export function footprintToPixels(fp, worldW, worldH) {
|
|
25
|
+
return {
|
|
26
|
+
left: Math.round(fp.x * worldW),
|
|
27
|
+
right: Math.round((fp.x + fp.w) * worldW),
|
|
28
|
+
top: Math.round(fp.y * worldH),
|
|
29
|
+
bottom: Math.round((fp.y + fp.h) * worldH),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Character vs obstacle unstandable footprint:
|
|
34
|
+
* - foot above footprint (y < top) → behind
|
|
35
|
+
* - foot below footprint (y > bottom) → in front
|
|
36
|
+
* - foot beside footprint (no x overlap) → behind
|
|
37
|
+
*/
|
|
38
|
+
export function characterObstacleRelation(charX, charY, footprint) {
|
|
39
|
+
const xOverlaps = charX >= footprint.left && charX <= footprint.right;
|
|
40
|
+
if (!xOverlaps) {
|
|
41
|
+
return 'behind';
|
|
42
|
+
}
|
|
43
|
+
if (charY > footprint.bottom) {
|
|
44
|
+
return 'in_front';
|
|
45
|
+
}
|
|
46
|
+
return 'behind';
|
|
47
|
+
}
|
|
48
|
+
function sortFootY(item) {
|
|
49
|
+
if (item.groundFootprint)
|
|
50
|
+
return item.groundFootprint.bottom;
|
|
51
|
+
return item.yCoor;
|
|
52
|
+
}
|
|
53
|
+
function compareFootY(a, b) {
|
|
54
|
+
const dy = sortFootY(a) - sortFootY(b);
|
|
55
|
+
if (dy !== 0)
|
|
56
|
+
return dy;
|
|
57
|
+
return (a.xCoor ?? 0) - (b.xCoor ?? 0);
|
|
58
|
+
}
|
|
59
|
+
function moveIdAfter(order, id, afterId) {
|
|
60
|
+
const ci = order.indexOf(id);
|
|
61
|
+
const oi = order.indexOf(afterId);
|
|
62
|
+
if (ci < 0 || oi < 0 || ci > oi)
|
|
63
|
+
return;
|
|
64
|
+
order.splice(ci, 1);
|
|
65
|
+
const newOi = order.indexOf(afterId);
|
|
66
|
+
order.splice(newOi + 1, 0, id);
|
|
67
|
+
}
|
|
68
|
+
function inFrontConstraintsHold(order, charId, char, obstacles) {
|
|
69
|
+
for (const o of obstacles) {
|
|
70
|
+
if (!o.groundFootprint)
|
|
71
|
+
continue;
|
|
72
|
+
if (characterObstacleRelation(char.x, char.y, o.groundFootprint) === 'in_front') {
|
|
73
|
+
if (order.indexOf(charId) <= order.indexOf(o.id))
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
function applyObstacleOrderAdjustments(items) {
|
|
80
|
+
const order = [...items].sort(compareFootY).map(i => i.id);
|
|
81
|
+
const chars = items.filter(i => i.kind === 'character');
|
|
82
|
+
const obstacles = items.filter(i => i.groundFootprint);
|
|
83
|
+
for (const c of chars) {
|
|
84
|
+
const pos = { x: c.xCoor ?? 0, y: c.yCoor };
|
|
85
|
+
for (const o of obstacles) {
|
|
86
|
+
if (characterObstacleRelation(pos.x, pos.y, o.groundFootprint) === 'in_front') {
|
|
87
|
+
moveIdAfter(order, c.id, o.id);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const c of chars) {
|
|
92
|
+
const pos = { x: c.xCoor ?? 0, y: c.yCoor };
|
|
93
|
+
for (const o of obstacles) {
|
|
94
|
+
if (characterObstacleRelation(pos.x, pos.y, o.groundFootprint) !== 'behind')
|
|
95
|
+
continue;
|
|
96
|
+
const ci = order.indexOf(c.id);
|
|
97
|
+
const oi = order.indexOf(o.id);
|
|
98
|
+
if (ci < 0 || oi < 0 || ci < oi)
|
|
99
|
+
continue;
|
|
100
|
+
order.splice(ci, 1);
|
|
101
|
+
const newOi = order.indexOf(o.id);
|
|
102
|
+
order.splice(newOi, 0, c.id);
|
|
103
|
+
if (!inFrontConstraintsHold(order, c.id, pos, obstacles)) {
|
|
104
|
+
order.splice(order.indexOf(c.id), 1);
|
|
105
|
+
order.splice(ci, 0, c.id);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return order;
|
|
110
|
+
}
|
|
111
|
+
export function defaultLayoutData() {
|
|
112
|
+
return {
|
|
113
|
+
imagePath: '',
|
|
114
|
+
width: DEFAULT_WORLD_SIZE.width,
|
|
115
|
+
height: DEFAULT_WORLD_SIZE.height,
|
|
116
|
+
perspective: {
|
|
117
|
+
horizonY: 0.55,
|
|
118
|
+
vanishingPoint: { x: 0.5, y: 0.45 },
|
|
119
|
+
scaleRatio: 2.2,
|
|
120
|
+
cameraAngle: 25,
|
|
121
|
+
steepness: 0.28,
|
|
122
|
+
standingZoneTopY: 0.55,
|
|
123
|
+
standingZoneBottomY: 1.0,
|
|
124
|
+
depthMin: DEFAULT_DEPTH_MIN,
|
|
125
|
+
depthMax: DEFAULT_DEPTH_MAX,
|
|
126
|
+
},
|
|
127
|
+
regions: [],
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export function placementFromPoint(point, layout, rig) {
|
|
131
|
+
const perspective = layout?.perspective ?? defaultLayoutData().perspective;
|
|
132
|
+
const worldH = layout?.height ?? DEFAULT_WORLD_SIZE.height;
|
|
133
|
+
const sized = characterSizeAtDepth(point.z, perspective, DEFAULT_REFERENCE_FRACTION, worldH, rigForSizing(rig));
|
|
134
|
+
const footY = typeof point.y === 'number' ? point.y : yFromDepth(point.z, perspective, worldH);
|
|
135
|
+
return {
|
|
136
|
+
x: point.x,
|
|
137
|
+
y: footY,
|
|
138
|
+
width: sized.width,
|
|
139
|
+
height: sized.height,
|
|
140
|
+
z: point.z,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Convert foot placement → rig root anchor Y using measured rig bounds.
|
|
145
|
+
* WorldJSON yCoor uses root Y; renderer places root at yCoor so feet land at footY.
|
|
146
|
+
*/
|
|
147
|
+
export async function rootAnchorFromFootPlacement(foot, rigData) {
|
|
148
|
+
const bounds = await computeRigBounds(rigData);
|
|
149
|
+
const naturalH = rigNaturalHeight(rigForSizing(rigData));
|
|
150
|
+
const renderScale = bounds && bounds.height > 0
|
|
151
|
+
? foot.height / bounds.height
|
|
152
|
+
: foot.height / naturalH;
|
|
153
|
+
const rootY = bounds
|
|
154
|
+
? Math.round(foot.y - bounds.belowRoot * renderScale)
|
|
155
|
+
: foot.y;
|
|
156
|
+
return {
|
|
157
|
+
x: foot.x,
|
|
158
|
+
y: rootY,
|
|
159
|
+
footY: foot.y,
|
|
160
|
+
z: foot.z,
|
|
161
|
+
width: foot.width,
|
|
162
|
+
height: foot.height,
|
|
163
|
+
renderScale,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export function placementFromCharacterPosition(pos, layout, rig) {
|
|
167
|
+
const perspective = layout?.perspective ?? defaultLayoutData().perspective;
|
|
168
|
+
const worldH = layout?.height ?? DEFAULT_WORLD_SIZE.height;
|
|
169
|
+
const z = pos.z ?? depthFromY(pos.y, perspective, worldH);
|
|
170
|
+
const sized = characterSizeAtDepth(z, perspective, DEFAULT_REFERENCE_FRACTION, worldH, rigForSizing(rig));
|
|
171
|
+
return {
|
|
172
|
+
x: pos.x,
|
|
173
|
+
y: pos.y,
|
|
174
|
+
width: pos.width ?? sized.width,
|
|
175
|
+
height: pos.height ?? sized.height,
|
|
176
|
+
z,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Place characters at scene-aware standing points (round-robin over points).
|
|
181
|
+
* When full rig JSON is available, y is adjusted to rig root anchor (feet at footY).
|
|
182
|
+
*/
|
|
183
|
+
export async function resolveCharacterPlacements(layout, characterNames, _charKeys, points, opts = {}) {
|
|
184
|
+
if (!layout?.perspective) {
|
|
185
|
+
throw new Error('Layout metadata with perspective data is required for character placement');
|
|
186
|
+
}
|
|
187
|
+
if (!points || points.length === 0) {
|
|
188
|
+
throw new Error('Standing points from layout metadata are required for character placement.');
|
|
189
|
+
}
|
|
190
|
+
const { rigDataMap } = opts;
|
|
191
|
+
const H = layout.height || DEFAULT_WORLD_SIZE.height;
|
|
192
|
+
const p = layout.perspective;
|
|
193
|
+
const n = characterNames.length;
|
|
194
|
+
if (n === 0)
|
|
195
|
+
return {};
|
|
196
|
+
const result = {};
|
|
197
|
+
for (let i = 0; i < n; i++) {
|
|
198
|
+
const name = characterNames[i];
|
|
199
|
+
const rig = rigDataMap?.[name];
|
|
200
|
+
const pt = points[i % points.length];
|
|
201
|
+
const depth = clampDepth(pt.z, p);
|
|
202
|
+
const footY = typeof pt.y === 'number' ? pt.y : yFromDepth(depth, p, H);
|
|
203
|
+
const sized = characterSizeAtDepth(depth, p, DEFAULT_REFERENCE_FRACTION, H, rigForSizing(rig));
|
|
204
|
+
const naturalH = rigNaturalHeight(rigForSizing(rig));
|
|
205
|
+
const foot = {
|
|
206
|
+
x: Math.round(pt.x),
|
|
207
|
+
y: footY,
|
|
208
|
+
width: sized.width,
|
|
209
|
+
height: sized.height,
|
|
210
|
+
z: Math.round(depth * 1000) / 1000,
|
|
211
|
+
};
|
|
212
|
+
if (isFullRigData(rig)) {
|
|
213
|
+
result[name] = await rootAnchorFromFootPlacement(foot, rig);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
result[name] = {
|
|
217
|
+
x: foot.x,
|
|
218
|
+
y: foot.y,
|
|
219
|
+
footY: foot.y,
|
|
220
|
+
z: foot.z,
|
|
221
|
+
width: foot.width,
|
|
222
|
+
height: foot.height,
|
|
223
|
+
renderScale: foot.height / naturalH,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
export function characterRenderOrder(pos, perspective = defaultLayoutData().perspective, worldH = DEFAULT_WORLD_SIZE.height) {
|
|
230
|
+
if (pos.z != null)
|
|
231
|
+
return pos.z;
|
|
232
|
+
return depthFromY(pos.y, perspective, worldH);
|
|
233
|
+
}
|
|
234
|
+
export function compareCharactersByDepth(a, b, positions, perspective = defaultLayoutData().perspective, worldH = DEFAULT_WORLD_SIZE.height) {
|
|
235
|
+
const pa = positions[a];
|
|
236
|
+
const pb = positions[b];
|
|
237
|
+
const za = pa ? characterRenderOrder(pa, perspective, worldH) : 0;
|
|
238
|
+
const zb = pb ? characterRenderOrder(pb, perspective, worldH) : 0;
|
|
239
|
+
if (za !== zb)
|
|
240
|
+
return za - zb;
|
|
241
|
+
return (pa?.x ?? 0) - (pb?.x ?? 0);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Assign world zIndex (1 = furthest back) using foot Y and obstacle footprint rules.
|
|
245
|
+
*/
|
|
246
|
+
export function assignZIndices(items) {
|
|
247
|
+
if (items.length === 0)
|
|
248
|
+
return new Map();
|
|
249
|
+
const hasObstacleRules = items.some(i => i.kind === 'character')
|
|
250
|
+
&& items.some(i => i.groundFootprint);
|
|
251
|
+
let order;
|
|
252
|
+
if (hasObstacleRules) {
|
|
253
|
+
order = applyObstacleOrderAdjustments(items);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
order = [...items].sort(compareFootY).map(i => i.id);
|
|
257
|
+
}
|
|
258
|
+
const result = new Map();
|
|
259
|
+
order.forEach((id, i) => result.set(id, i + 1));
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=worldPlacement.js.map
|