rig-review 0.20.0 → 0.21.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/README.md +2 -2
- package/docs/ANIMATION_INSPECTION.md +1 -1
- package/docs/DESIGN.md +1 -1
- package/docs/PANELS.md +2 -2
- package/package.json +1 -1
- package/src/animation-ops.ts +147 -17
- package/src/applied-context.ts +6 -2
- package/src/compare-html.ts +5 -5
- package/src/rebuild.ts +110 -11
- package/web/animation-inspection.ts +1783 -36
- package/web/compare-picked-tools.ts +11 -2
- package/web/compare.css +83 -13
- package/web/compare.html +1 -1
- package/web/index.html +1 -1
- package/web/inspector-blocks.ts +22 -16
- package/web/main.ts +108 -9
- package/web/preview.ts +31 -0
- package/web/rebuild-client.ts +14 -6
- package/web/requirements-panel.ts +1 -1
- package/web/styles.css +82 -14
- package/web/workspace-preferences.ts +3 -2
- package/web/workspace-ui.ts +10 -9
|
@@ -1,11 +1,81 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type {BoneAdjust,PosedFrame,RigPlayer} from '@rig-c/play';
|
|
2
|
+
import {
|
|
3
|
+
boneHierarchy,
|
|
4
|
+
CHANNELS,
|
|
5
|
+
channelSegments,
|
|
6
|
+
evaluateBoneLocals,
|
|
7
|
+
evaluateStoredChannel,
|
|
8
|
+
filterTracks,
|
|
9
|
+
readAnimationInspection,
|
|
10
|
+
type AnimationInspection,
|
|
11
|
+
type InspectionTarget,
|
|
12
|
+
type InspectionTrack,
|
|
13
|
+
} from '../src/animation-inspection.ts';
|
|
14
|
+
import {
|
|
15
|
+
AnimationOpBuilder,
|
|
16
|
+
checkAnimationEditGate,
|
|
17
|
+
classifyAnimationTracks,
|
|
18
|
+
cleanMotionNumber,
|
|
19
|
+
MAX_ANIMATION_OPS,
|
|
20
|
+
overlayDraftOnInspection,
|
|
21
|
+
seedCubicCurve,
|
|
22
|
+
type AnimationEditGate,
|
|
23
|
+
type AnimationSourceOp,
|
|
24
|
+
type EasingTuple,
|
|
25
|
+
type TrackClassification,
|
|
26
|
+
} from '../src/animation-ops.ts';
|
|
27
|
+
import type {AppliedAnimation} from '../src/applied-context.ts';
|
|
28
|
+
import type {AnimationSourceView} from './rebuild-client.ts';
|
|
3
29
|
import {InspectionSelection} from './inspection-selection.ts';
|
|
30
|
+
import {animationPreviewAdjust} from './preview.ts';
|
|
31
|
+
|
|
4
32
|
const NS='http://www.w3.org/2000/svg';
|
|
5
33
|
const svg=(tag:string,attrs:Record<string,string|number>)=>{const n=document.createElementNS(NS,tag);for(const [k,v]of Object.entries(attrs))n.setAttribute(k,String(v));return n;};
|
|
6
34
|
const numeric=(value:number)=>Object.is(value,-0)?'-0':String(value);
|
|
7
35
|
const button=(label:string,click:()=>void)=>{const b=document.createElement('button');b.type='button';b.textContent=label;b.onclick=click;return b;};
|
|
8
|
-
|
|
36
|
+
|
|
37
|
+
/** Clean human-readable seconds without Float32 noise (e.g. 1.6 instead of 1.600000023841858). */
|
|
38
|
+
export function formatSeconds(value:number):string {
|
|
39
|
+
if(!Number.isFinite(value))return '0';
|
|
40
|
+
const cleaned=Number(value.toFixed(4));
|
|
41
|
+
return Object.is(cleaned,-0)?'0':String(cleaned);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Clean ruler tick positions from 0 to end for the given horizontal zoom factor. */
|
|
45
|
+
export function buildRulerTicks(end:number,zoom=1):number[] {
|
|
46
|
+
if(!(end>0)||!Number.isFinite(end))return [0];
|
|
47
|
+
const cleanEnd=Number(end.toFixed(4));
|
|
48
|
+
const niceSteps=[0.02,0.05,0.1,0.2,0.25,0.5,1,2,5,10];
|
|
49
|
+
const targetCount=Math.max(6,Math.min(32,Math.round(8*Math.max(1,zoom))));
|
|
50
|
+
const step=niceSteps.find(s=>cleanEnd/s<=targetCount)??niceSteps.at(-1)!;
|
|
51
|
+
const ticks:number[]=[0];
|
|
52
|
+
for(let i=1;i*step<cleanEnd-step*0.35;i++){
|
|
53
|
+
ticks.push(Number((i*step).toFixed(4)));
|
|
54
|
+
}
|
|
55
|
+
if(ticks.at(-1)!==cleanEnd)ticks.push(cleanEnd);
|
|
56
|
+
return ticks;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface AnimationPanelOptions {
|
|
60
|
+
host:HTMLElement;
|
|
61
|
+
stage:HTMLElement;
|
|
62
|
+
select:(value:InspectionTarget)=>void;
|
|
63
|
+
seek:(time:number)=>void;
|
|
64
|
+
project:(x:number,y:number)=>{x:number;y:number};
|
|
65
|
+
enabled:()=>boolean;
|
|
66
|
+
preview?:(adjust:BoneAdjust|null,active:boolean)=>void;
|
|
67
|
+
apply?:(ops:readonly AnimationSourceOp[])=>Promise<unknown>;
|
|
68
|
+
reset?:()=>Promise<void>;
|
|
69
|
+
pause?:()=>void;
|
|
70
|
+
readOnlyReason?:string|null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface SelectedAnimationKey {
|
|
74
|
+
animation:string;
|
|
75
|
+
trackIndex:number;
|
|
76
|
+
keyIndex:number;
|
|
77
|
+
pointer:string;
|
|
78
|
+
}
|
|
9
79
|
|
|
10
80
|
/** All picking reads the last drawn primitives, including their resolved clip; never a setup bounding box. */
|
|
11
81
|
export function pickedSlot(frame:PosedFrame,x:number,y:number):string|null {
|
|
@@ -17,19 +87,186 @@ export function pickedSlot(frame:PosedFrame,x:number,y:number):string|null {
|
|
|
17
87
|
}return null;
|
|
18
88
|
}
|
|
19
89
|
|
|
90
|
+
export const ANIMATION_APPLY_ISOLATION_NOTE =
|
|
91
|
+
'An animation Apply builds from the handoff config.json and animations_from file into scratch (rig-parts rig → rigc build → rig-parts check), so it does not carry another kind\'s Apply on the stage.';
|
|
92
|
+
|
|
20
93
|
export class AnimationInspectionPanel {
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
private
|
|
94
|
+
private baseInspection:AnimationInspection|null=null;
|
|
95
|
+
private inspection:AnimationInspection|null=null;
|
|
96
|
+
private document:unknown=null;
|
|
97
|
+
private animation='';
|
|
98
|
+
private at=0;
|
|
99
|
+
private runtimeDuration=0;
|
|
100
|
+
private track:InspectionTrack|null=null;
|
|
101
|
+
private channel=0;
|
|
102
|
+
private view='timeline';
|
|
103
|
+
private zoom=1;
|
|
104
|
+
private unavailableChannel='';
|
|
105
|
+
private selection:InspectionSelection;
|
|
106
|
+
private panes=new Map<string,HTMLElement>();
|
|
107
|
+
private views:HTMLButtonElement[]=[];
|
|
108
|
+
private zoomButtons:HTMLButtonElement[]=[];
|
|
109
|
+
private playhead:SVGElement|null=null;
|
|
110
|
+
private cursor:SVGElement|null=null;
|
|
111
|
+
private plot:((t:number,v:number)=>{x:number;y:number})|null=null;
|
|
112
|
+
private channelSelect:HTMLSelectElement;
|
|
113
|
+
private segmentSelect:HTMLSelectElement;
|
|
114
|
+
private easeSelect:HTMLSelectElement;
|
|
115
|
+
private curveReadonly:HTMLElement;
|
|
116
|
+
private curvePlot:SVGSVGElement;
|
|
117
|
+
private curveSegment=0;
|
|
118
|
+
private readout:HTMLOutputElement;
|
|
119
|
+
private status:HTMLElement;
|
|
120
|
+
private gateBanner:HTMLElement;
|
|
121
|
+
private previewBadge:HTMLElement;
|
|
122
|
+
private opsSummary:HTMLElement;
|
|
123
|
+
private undoOpBtn:HTMLButtonElement;
|
|
124
|
+
private clearOpsBtn:HTMLButtonElement;
|
|
125
|
+
private applyBtn:HTMLButtonElement;
|
|
126
|
+
private resetBtn:HTMLButtonElement;
|
|
127
|
+
private applyNote:HTMLElement;
|
|
128
|
+
private editorStatus:HTMLElement;
|
|
129
|
+
private picks:HTMLElement;
|
|
130
|
+
private bones=new Map<string,{x:number;y:number}>();
|
|
131
|
+
private frame:PosedFrame|null=null;
|
|
132
|
+
private down:{x:number;y:number}|null=null;
|
|
133
|
+
private space=false;
|
|
134
|
+
private disposers:(()=>void)[]=[];
|
|
135
|
+
private boneButtons=new Map<string,HTMLButtonElement>();
|
|
136
|
+
private bonePoints=false;
|
|
137
|
+
|
|
138
|
+
// Keyed animation editing state (Slice 3 / Slice 3b / Slice 4a)
|
|
139
|
+
private source:AnimationSourceView|null=null;
|
|
140
|
+
private sourceLoaded=false;
|
|
141
|
+
private sourceFallbackReason:string|null=null;
|
|
142
|
+
private builder:AnimationOpBuilder|null=null;
|
|
143
|
+
private appliedOps:AnimationSourceOp[]=[];
|
|
144
|
+
private selectedKey:SelectedAnimationKey|null=null;
|
|
145
|
+
private lastNonEmptyAnimation='';
|
|
146
|
+
private isBusy=false;
|
|
147
|
+
private suppressNextKeyClick=false;
|
|
148
|
+
private lastDockClientHeight=0;
|
|
149
|
+
private lastLanesHeight=186;
|
|
150
|
+
private draggingKey:{
|
|
151
|
+
pointerId:number;
|
|
152
|
+
trackIndex:number;
|
|
153
|
+
keyIndex:number;
|
|
154
|
+
startX:number;
|
|
155
|
+
moved:boolean;
|
|
156
|
+
laneEl:HTMLElement;
|
|
157
|
+
markEl:HTMLButtonElement;
|
|
158
|
+
end:number;
|
|
159
|
+
}|null=null;
|
|
160
|
+
private draggingCurveHandle:{
|
|
161
|
+
pointerId:number;
|
|
162
|
+
trackIndex:number;
|
|
163
|
+
segmentIndex:number;
|
|
164
|
+
handleIndex:1|2;
|
|
165
|
+
channel:number;
|
|
166
|
+
low:number;
|
|
167
|
+
high:number;
|
|
168
|
+
span:number;
|
|
169
|
+
end:number;
|
|
170
|
+
}|null=null;
|
|
171
|
+
|
|
25
172
|
constructor(private options:AnimationPanelOptions){
|
|
26
|
-
const {host,stage}=options;
|
|
27
|
-
|
|
173
|
+
const {host,stage}=options;
|
|
174
|
+
host.classList.add('animation-inspection');
|
|
175
|
+
host.innerHTML=`<div class="animation-dock-bar">
|
|
176
|
+
<h3 class="animation-dock-title">Animation timeline & inspection</h3>
|
|
177
|
+
<div class="animation-view-buttons" aria-label="Animation inspection views"></div>
|
|
178
|
+
<div class="animation-zoom-buttons" role="group" aria-label="Timeline horizontal zoom"></div>
|
|
179
|
+
<div class="animation-editor-bar" data-animation-editor-bar>
|
|
180
|
+
<div class="animation-editor-actions">
|
|
181
|
+
<span class="animation-preview-badge" data-animation-preview-badge hidden>preview — Apply decides</span>
|
|
182
|
+
<span class="animation-ops-summary" data-animation-ops-summary>0 pending ops</span>
|
|
183
|
+
<button type="button" data-animation-undo-op disabled>Undo op</button>
|
|
184
|
+
<button type="button" data-animation-clear-ops disabled>Discard pending</button>
|
|
185
|
+
<button type="button" data-animation-apply disabled>Apply · Rebuild</button>
|
|
186
|
+
<button type="button" data-animation-reset disabled>Reset</button>
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
<div class="animation-dock-status">
|
|
191
|
+
<div class="animation-gate-banner hint" data-animation-gate></div>
|
|
192
|
+
<p class="hint" data-animation-editor-status role="status"></p>
|
|
193
|
+
<p class="hint" data-animation-apply-note></p>
|
|
194
|
+
<p data-inspection-status class="hint"></p>
|
|
195
|
+
</div>
|
|
196
|
+
<section data-animation-pane="timeline" aria-label="Timeline"></section>
|
|
197
|
+
<section data-animation-pane="curve" aria-label="Stored curves" hidden>
|
|
198
|
+
<div class="animation-curve-toolbar">
|
|
199
|
+
<label>Channel <select data-curve-channel aria-label="Stored animation channel"></select></label>
|
|
200
|
+
<label>Segment <select data-curve-segment aria-label="Curve segment"></select></label>
|
|
201
|
+
<label>Curve <select data-curve-ease aria-label="Segment curve or easing"></select></label>
|
|
202
|
+
<label>Time (s) <input data-curve-time type="number" min="0" step="any" aria-label="Exact inspection seconds"></label>
|
|
203
|
+
<button data-curve-seek type="button">Inspect time</button>
|
|
204
|
+
<span class="animation-curve-readonly hint" data-curve-readonly hidden></span>
|
|
205
|
+
<output data-curve-readout aria-live="off"></output>
|
|
206
|
+
</div>
|
|
207
|
+
<svg data-curve-plot role="img" aria-label="Exact stored curve and control points" viewBox="0 0 800 230"></svg>
|
|
208
|
+
<p class="hint">Stored curve and handles are exact. Runtime evaluation uses Play’s ten-piece Float32 interpolation; the cursor may sit off the cubic. Values are authored locals before constraints and previews.</p>
|
|
209
|
+
</section>
|
|
210
|
+
<section data-animation-pane="tree" aria-label="Bone tree" hidden></section>`;
|
|
211
|
+
|
|
212
|
+
this.status=host.querySelector('[data-inspection-status]')!;
|
|
213
|
+
this.gateBanner=host.querySelector('[data-animation-gate]')!;
|
|
214
|
+
this.previewBadge=host.querySelector('[data-animation-preview-badge]')!;
|
|
215
|
+
this.opsSummary=host.querySelector('[data-animation-ops-summary]')!;
|
|
216
|
+
this.undoOpBtn=host.querySelector('[data-animation-undo-op]')!;
|
|
217
|
+
this.clearOpsBtn=host.querySelector('[data-animation-clear-ops]')!;
|
|
218
|
+
this.applyBtn=host.querySelector('[data-animation-apply]')!;
|
|
219
|
+
this.resetBtn=host.querySelector('[data-animation-reset]')!;
|
|
220
|
+
this.applyNote=host.querySelector('[data-animation-apply-note]')!;
|
|
221
|
+
this.editorStatus=host.querySelector('[data-animation-editor-status]')!;
|
|
222
|
+
this.applyNote.textContent=ANIMATION_APPLY_ISOLATION_NOTE;
|
|
223
|
+
this.applyNote.title=ANIMATION_APPLY_ISOLATION_NOTE;
|
|
224
|
+
this.channelSelect=host.querySelector('[data-curve-channel]')!;
|
|
225
|
+
this.segmentSelect=host.querySelector('[data-curve-segment]')!;
|
|
226
|
+
this.easeSelect=host.querySelector('[data-curve-ease]')!;
|
|
227
|
+
this.curveReadonly=host.querySelector('[data-curve-readonly]')!;
|
|
228
|
+
this.curvePlot=host.querySelector('[data-curve-plot]')!;
|
|
229
|
+
this.readout=host.querySelector('[data-curve-readout]')!;
|
|
230
|
+
|
|
231
|
+
this.undoOpBtn.onclick=()=>{this.undoOp();};
|
|
232
|
+
this.clearOpsBtn.onclick=()=>{this.clearPending();};
|
|
233
|
+
this.applyBtn.onclick=()=>{if(this.options.apply)void this.options.apply(this.ops());};
|
|
234
|
+
this.resetBtn.onclick=()=>{this.resetEdits();if(this.options.reset)void this.options.reset();};
|
|
235
|
+
|
|
28
236
|
for(const pane of host.querySelectorAll<HTMLElement>('[data-animation-pane]'))this.panes.set(pane.dataset.animationPane!,pane);
|
|
29
|
-
|
|
237
|
+
const viewButtonsHost=host.querySelector('.animation-view-buttons')!;
|
|
238
|
+
for(const [id,label]of [['timeline','Timeline'],['curve','Curves'],['tree','Bone tree']]){
|
|
239
|
+
const b=button(label!,()=>this.show(id!));
|
|
240
|
+
b.dataset.animationView=id;
|
|
241
|
+
viewButtonsHost.append(b);
|
|
242
|
+
this.views.push(b);
|
|
243
|
+
}
|
|
244
|
+
const zoomHost=host.querySelector('.animation-zoom-buttons');
|
|
245
|
+
if(zoomHost){
|
|
246
|
+
for(const z of [1,2,4,8]){
|
|
247
|
+
const zb=button(`${z}×`,()=>this.setZoom(z));
|
|
248
|
+
zb.dataset.animationZoom=String(z);
|
|
249
|
+
zb.setAttribute('aria-pressed',String(z===this.zoom));
|
|
250
|
+
zb.title=`Timeline horizontal zoom ${z}×`;
|
|
251
|
+
zoomHost.append(zb);
|
|
252
|
+
this.zoomButtons.push(zb);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
30
255
|
this.selection=new InspectionSelection(value=>{options.select(value);this.renderSelection();});
|
|
31
256
|
host.querySelector<HTMLButtonElement>('[data-curve-seek]')!.onclick=()=>{const value=host.querySelector<HTMLInputElement>('[data-curve-time]')!.value.trim();options.seek(value?Number(value):NaN);};
|
|
32
257
|
this.channelSelect.onchange=()=>{this.unavailableChannel='';const [pointer,c]=JSON.parse(this.channelSelect.value) as [string,number];this.track=this.inspection?.tracks.find(t=>t.pointer===pointer)??null;this.channel=c;this.renderCurve();this.update(this.at,this.runtimeDuration);};
|
|
258
|
+
this.segmentSelect.onchange=()=>{
|
|
259
|
+
this.curveSegment=Math.max(0,Number(this.segmentSelect.value)||0);
|
|
260
|
+
const cls=this.resolveTrackClassification(this.track);
|
|
261
|
+
if(this.gateInfo().editable&&cls?.editable&&this.track){
|
|
262
|
+
this.selectedKey={animation:this.animation,trackIndex:cls.trackIndex,keyIndex:this.curveSegment,pointer:this.track.pointer};
|
|
263
|
+
this.syncTimelineKeysInPlace();
|
|
264
|
+
this.syncKeyInspectorInPlace();
|
|
265
|
+
}
|
|
266
|
+
this.renderCurve();
|
|
267
|
+
};
|
|
268
|
+
this.easeSelect.onchange=()=>{this.applyCurveModeChange(this.easeSelect.value);};
|
|
269
|
+
this.bindCurveHandleDrag();
|
|
33
270
|
this.picks=document.createElement('div');this.picks.className='animation-stage-picks';stage.append(this.picks);
|
|
34
271
|
const down=(e:PointerEvent)=>{this.down=e.isPrimary&&e.button===0?{x:e.clientX,y:e.clientY}:null;};
|
|
35
272
|
const up=(e:PointerEvent)=>{const start=this.down;this.down=null;if(!start||Math.hypot(e.clientX-start.x,e.clientY-start.y)>3||this.space||!options.enabled()||e.target instanceof Element&&e.target.closest('button,input,select,textarea')||!this.frame)return;
|
|
@@ -37,26 +274,632 @@ export class AnimationInspectionPanel {
|
|
|
37
274
|
};
|
|
38
275
|
const key=(e:KeyboardEvent)=>{if(e.code==='Space')this.space=e.type==='keydown';};const blur=()=>{this.space=false;this.down=null;};
|
|
39
276
|
stage.addEventListener('pointerdown',down);stage.addEventListener('pointerup',up);window.addEventListener('keydown',key);window.addEventListener('keyup',key);window.addEventListener('blur',blur);
|
|
40
|
-
this.disposers.push(()=>{stage.removeEventListener('pointerdown',down);stage.removeEventListener('pointerup',up);window.removeEventListener('keydown',key);window.removeEventListener('keyup',key);window.removeEventListener('blur',blur);});
|
|
277
|
+
this.disposers.push(()=>{stage.removeEventListener('pointerdown',down);stage.removeEventListener('pointerup',up);window.removeEventListener('keydown',key);window.removeEventListener('keyup',key);window.removeEventListener('blur',blur);});
|
|
278
|
+
|
|
279
|
+
if(typeof ResizeObserver!=='undefined'&&typeof host.closest==='function'){
|
|
280
|
+
const playbackPanel=host.closest<HTMLElement>('[data-inspector-panel]');
|
|
281
|
+
const dockPanel=host.closest<HTMLElement>('.inspector');
|
|
282
|
+
const ro=new ResizeObserver(()=>{this.syncDockHeight(true);});
|
|
283
|
+
if(playbackPanel)ro.observe(playbackPanel);
|
|
284
|
+
if(dockPanel&&dockPanel!==playbackPanel)ro.observe(dockPanel);
|
|
285
|
+
ro.observe(host);
|
|
286
|
+
this.disposers.push(()=>ro.disconnect());
|
|
287
|
+
}
|
|
288
|
+
this.show('timeline');
|
|
289
|
+
this.renderEditorBar();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
zoomLevel():number{
|
|
293
|
+
return this.zoom;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
setZoom(nextZoom:number){
|
|
297
|
+
const clamped=[1,2,4,8].includes(nextZoom)?nextZoom:1;
|
|
298
|
+
if(this.zoom===clamped)return;
|
|
299
|
+
this.zoom=clamped;
|
|
300
|
+
for(const zb of this.zoomButtons){
|
|
301
|
+
zb.setAttribute('aria-pressed',String(Number(zb.dataset.animationZoom)===this.zoom));
|
|
302
|
+
}
|
|
303
|
+
this.renderTimeline();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private syncDockHeight(fromResize=false){
|
|
307
|
+
const lanes=this.options.host.querySelector<HTMLElement>('.animation-lanes');
|
|
308
|
+
if(!lanes)return;
|
|
309
|
+
if(typeof this.options.host.closest!=='function'){
|
|
310
|
+
lanes.style.height=`${this.lastLanesHeight}px`;
|
|
311
|
+
lanes.style.maxHeight=`${this.lastLanesHeight}px`;
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const panel=this.options.host.closest<HTMLElement>('[data-inspector-panel]')??this.options.host.closest<HTMLElement>('.inspector');
|
|
315
|
+
if(!panel||panel.clientHeight<=0){
|
|
316
|
+
lanes.style.height=`${this.lastLanesHeight}px`;
|
|
317
|
+
lanes.style.maxHeight=`${this.lastLanesHeight}px`;
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if(fromResize||panel.clientHeight!==this.lastDockClientHeight){
|
|
321
|
+
this.lastDockClientHeight=panel.clientHeight;
|
|
322
|
+
const overhead=panel.hasAttribute('data-inspector-panel')?129:159;
|
|
323
|
+
this.lastLanesHeight=Math.max(104,Math.floor(panel.clientHeight-overhead));
|
|
324
|
+
}
|
|
325
|
+
lanes.style.height=`${this.lastLanesHeight}px`;
|
|
326
|
+
lanes.style.maxHeight=`${this.lastLanesHeight}px`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
setSourceLoading(){
|
|
330
|
+
this.sourceLoaded=false;
|
|
331
|
+
this.source=null;
|
|
332
|
+
this.sourceFallbackReason=null;
|
|
333
|
+
this.builder=null;
|
|
334
|
+
this.appliedOps=[];
|
|
335
|
+
this.selectedKey=null;
|
|
336
|
+
this.syncEffectiveInspection(false);
|
|
337
|
+
this.renderGateBanner();
|
|
338
|
+
this.renderEditorBar();
|
|
339
|
+
this.renderSelection();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
loadSource(source:AnimationSourceView|null,fallbackReason:string|null=null){
|
|
343
|
+
this.sourceLoaded=true;
|
|
344
|
+
this.source=source;
|
|
345
|
+
this.sourceFallbackReason=fallbackReason;
|
|
346
|
+
if(source?.available&&source.text){
|
|
347
|
+
if(!this.builder||this.builder.baseText!==source.text){
|
|
348
|
+
const prevOps=this.builder?[...this.builder.ops]:[...this.appliedOps];
|
|
349
|
+
this.builder=new AnimationOpBuilder(source.text,(source.easings??undefined) as Readonly<Record<string,EasingTuple>>|undefined);
|
|
350
|
+
for(const op of prevOps){
|
|
351
|
+
try{this.builder.apply(op);}catch{break;}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}else{
|
|
355
|
+
this.builder=null;
|
|
356
|
+
this.appliedOps=[];
|
|
357
|
+
this.selectedKey=null;
|
|
358
|
+
}
|
|
359
|
+
this.syncEffectiveInspection(false);
|
|
360
|
+
this.renderGateBanner();
|
|
361
|
+
this.renderEditorBar();
|
|
362
|
+
this.renderSelection();
|
|
41
363
|
}
|
|
364
|
+
|
|
42
365
|
model(doc:unknown,animation:string){
|
|
43
|
-
if(this.document===doc&&this.animation===animation)return;
|
|
44
|
-
|
|
45
|
-
|
|
366
|
+
if(this.document===doc&&this.animation===animation)return;
|
|
367
|
+
if(animation&&this.lastNonEmptyAnimation&&this.lastNonEmptyAnimation!==animation){
|
|
368
|
+
this.selectedKey=null;
|
|
369
|
+
this.setEditorStatus('',false);
|
|
370
|
+
}
|
|
371
|
+
if(animation)this.lastNonEmptyAnimation=animation;
|
|
372
|
+
this.document=doc;
|
|
373
|
+
this.animation=animation;
|
|
374
|
+
this.baseInspection=null;
|
|
375
|
+
this.inspection=null;
|
|
376
|
+
this.track=null;
|
|
377
|
+
this.unavailableChannel='';
|
|
378
|
+
this.frame=null;
|
|
379
|
+
this.bones.clear();
|
|
380
|
+
this.boneButtons.clear();
|
|
381
|
+
this.picks.replaceChildren();
|
|
382
|
+
this.channelSelect.replaceChildren();
|
|
383
|
+
this.playhead=null;
|
|
384
|
+
try{
|
|
385
|
+
this.baseInspection=readAnimationInspection(doc,animation);
|
|
386
|
+
boneHierarchy(this.baseInspection);
|
|
387
|
+
this.syncEffectiveInspection(true);
|
|
388
|
+
this.status.textContent=`${animation||'Setup'} · ${this.inspection!.tracks.length} stored tracks · key times in seconds; frames require a declared clock.`;
|
|
389
|
+
this.status.title=this.status.textContent;
|
|
390
|
+
}catch(e){
|
|
391
|
+
this.status.textContent=e instanceof Error?e.message:String(e);
|
|
392
|
+
this.status.title=this.status.textContent;
|
|
393
|
+
}
|
|
46
394
|
if(this.selection.value()&&!this.has(this.selection.value()))this.selection.select(null);
|
|
47
|
-
this.
|
|
395
|
+
this.renderGateBanner();
|
|
396
|
+
this.renderEditorBar();
|
|
397
|
+
this.renderTree();
|
|
398
|
+
this.renderSelection();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
private draftDocument():unknown{
|
|
402
|
+
if(!this.builder)return undefined;
|
|
403
|
+
try{return JSON.parse(this.builder.text);}catch{return undefined;}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
gateInfo():AnimationEditGate{
|
|
407
|
+
if(!this.animation){
|
|
408
|
+
return {editable:false,code:'ANIMATION_NOT_IN_SOURCE',reason:'No animation selected.',note:null};
|
|
409
|
+
}
|
|
410
|
+
if(this.animation==='idle'){
|
|
411
|
+
return checkAnimationEditGate('idle',this.source?.path??null);
|
|
412
|
+
}
|
|
413
|
+
if(this.options.readOnlyReason||!this.options.apply||!this.options.preview){
|
|
414
|
+
return {
|
|
415
|
+
editable:false,
|
|
416
|
+
code:'ANIMATION_COMPARE_READ_ONLY',
|
|
417
|
+
reason:
|
|
418
|
+
this.options.readOnlyReason??
|
|
419
|
+
'keyed animation editing is read-only in comparison sessions until per-side animation rebuild is wired.',
|
|
420
|
+
note:null,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
if(!this.sourceLoaded){
|
|
424
|
+
return {
|
|
425
|
+
editable:false,
|
|
426
|
+
code:'ANIMATION_SOURCE_LOADING',
|
|
427
|
+
reason:'Reading the producer handoff…',
|
|
428
|
+
note:null,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
if(!this.source||!this.source.available||!this.source.text){
|
|
432
|
+
const r=this.source?.reason??this.sourceFallbackReason??'config.json does not declare an "animations_from" motion spec file.';
|
|
433
|
+
const clean=r.replace(/^ANIMATION_SOURCE_MISSING:\s*/,'');
|
|
434
|
+
return {editable:false,code:'ANIMATION_SOURCE_MISSING',reason:clean,note:null};
|
|
435
|
+
}
|
|
436
|
+
return checkAnimationEditGate(this.animation,this.source.path,this.draftDocument());
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
tracksInfo():TrackClassification[]{
|
|
440
|
+
const doc=this.draftDocument();
|
|
441
|
+
if(!doc||!this.animation)return [];
|
|
442
|
+
return classifyAnimationTracks(doc,this.animation);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
hasUnappliedPreview():boolean{
|
|
446
|
+
if(!this.builder)return false;
|
|
447
|
+
return JSON.stringify(this.builder.ops)!==JSON.stringify(this.appliedOps);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
ops():readonly AnimationSourceOp[]{
|
|
451
|
+
return this.builder?this.builder.ops:[];
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
unappliedOps():readonly AnimationSourceOp[]{
|
|
455
|
+
const all=this.ops();
|
|
456
|
+
if(!this.hasUnappliedPreview())return [];
|
|
457
|
+
return all;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
overlaidInspection():AnimationInspection|null{
|
|
461
|
+
return this.inspection;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
sourceInfo(){
|
|
465
|
+
return this.source?{
|
|
466
|
+
available:this.source.available,
|
|
467
|
+
reason:this.source.reason,
|
|
468
|
+
path:this.source.path,
|
|
469
|
+
sha256:this.source.sha256,
|
|
470
|
+
}:null;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
private syncEffectiveInspection(notifyPreview=true){
|
|
474
|
+
if(!this.baseInspection){
|
|
475
|
+
this.inspection=null;
|
|
476
|
+
if(notifyPreview)this.options.preview?.(null,false);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
const hasPreview=this.hasUnappliedPreview();
|
|
480
|
+
if(hasPreview&&this.builder){
|
|
481
|
+
try{
|
|
482
|
+
this.inspection=overlayDraftOnInspection(
|
|
483
|
+
this.baseInspection,
|
|
484
|
+
this.builder.text,
|
|
485
|
+
(this.source?.easings??undefined) as Readonly<Record<string,EasingTuple>>|undefined,
|
|
486
|
+
);
|
|
487
|
+
}catch{
|
|
488
|
+
this.inspection=this.baseInspection;
|
|
489
|
+
}
|
|
490
|
+
}else{
|
|
491
|
+
this.inspection=this.baseInspection;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if(this.track&&this.inspection){
|
|
495
|
+
this.track=this.inspection.tracks.find(t=>t.pointer===this.track!.pointer)??this.track;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if(notifyPreview){
|
|
499
|
+
if(hasPreview&&this.inspection&&this.builder){
|
|
500
|
+
const clss=this.tracksInfo();
|
|
501
|
+
const editedBones=new Set<string>();
|
|
502
|
+
for(const op of [...this.builder.ops,...this.appliedOps]){
|
|
503
|
+
if(op.animation===this.animation){
|
|
504
|
+
const c=clss[op.track];
|
|
505
|
+
if(c&&c.targetKind==='bone'&&c.target)editedBones.add(c.target);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
const adjust=animationPreviewAdjust(this.inspection,editedBones,false);
|
|
509
|
+
this.options.preview?.(adjust,editedBones.size>0);
|
|
510
|
+
}else{
|
|
511
|
+
this.options.preview?.(null,false);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
private renderGateBanner(){
|
|
517
|
+
const gate=this.gateInfo();
|
|
518
|
+
if(!this.animation){
|
|
519
|
+
this.gateBanner.textContent='Select an animation clip to inspect or edit keys.';
|
|
520
|
+
this.gateBanner.title=this.gateBanner.textContent;
|
|
521
|
+
this.gateBanner.dataset.gateCode='NONE';
|
|
522
|
+
this.gateBanner.dataset.editable='false';
|
|
523
|
+
delete this.gateBanner.dataset.loading;
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
if(gate.code==='ANIMATION_SOURCE_LOADING'){
|
|
527
|
+
this.gateBanner.textContent=gate.reason??'Reading the producer handoff…';
|
|
528
|
+
this.gateBanner.title=this.gateBanner.textContent;
|
|
529
|
+
this.gateBanner.dataset.gateCode='LOADING';
|
|
530
|
+
this.gateBanner.dataset.editable='false';
|
|
531
|
+
this.gateBanner.dataset.loading='true';
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
delete this.gateBanner.dataset.loading;
|
|
535
|
+
this.gateBanner.dataset.gateCode=gate.code;
|
|
536
|
+
this.gateBanner.dataset.editable=String(gate.editable);
|
|
537
|
+
if(!gate.editable){
|
|
538
|
+
this.gateBanner.textContent=`Read-only clip · ${gate.code}: ${gate.reason}`;
|
|
539
|
+
}else{
|
|
540
|
+
const srcPath=this.source?.path??'animations_from';
|
|
541
|
+
const hashShort=this.source?.sha256?` (sha256 ${this.source.sha256.slice(0,12)}…)`:'';
|
|
542
|
+
const notePart=gate.note?` · Note: ${gate.note}`:'';
|
|
543
|
+
this.gateBanner.textContent=`Editable clip "${this.animation}" from ${srcPath}${hashShort}${notePart}`;
|
|
544
|
+
}
|
|
545
|
+
this.gateBanner.title=this.gateBanner.textContent;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
private renderEditorBar(){
|
|
549
|
+
const allOps=this.ops();
|
|
550
|
+
const hasPreview=this.hasUnappliedPreview();
|
|
551
|
+
const appliedCount=this.appliedOps.length;
|
|
552
|
+
this.previewBadge.hidden=!hasPreview;
|
|
553
|
+
if(hasPreview){
|
|
554
|
+
const clips=[...new Set([...allOps,...this.appliedOps].map(o=>o.animation))];
|
|
555
|
+
this.previewBadge.textContent=`preview — Apply decides (${allOps.length} op(s)${clips.length?` on ${clips.join(', ')}`:''})`;
|
|
556
|
+
}
|
|
557
|
+
if(allOps.length===0&&appliedCount===0){
|
|
558
|
+
this.opsSummary.textContent=`0 pending ops (cap ${MAX_ANIMATION_OPS})`;
|
|
559
|
+
}else if(hasPreview){
|
|
560
|
+
this.opsSummary.textContent=`${allOps.length} cumulative op(s) pending${appliedCount?` (${appliedCount} applied on stage)`:''} · cap ${MAX_ANIMATION_OPS}`;
|
|
561
|
+
}else{
|
|
562
|
+
this.opsSummary.textContent=`${appliedCount} op(s) applied on stage · 0 unapplied`;
|
|
563
|
+
}
|
|
564
|
+
const gate=this.gateInfo();
|
|
565
|
+
this.undoOpBtn.disabled=this.isBusy||!gate.editable||allOps.length===0;
|
|
566
|
+
this.clearOpsBtn.disabled=this.isBusy||!gate.editable||!hasPreview;
|
|
567
|
+
this.applyBtn.disabled=this.isBusy||!gate.editable||!hasPreview||allOps.length===0||!this.source?.available;
|
|
568
|
+
this.resetBtn.disabled=this.isBusy||!gate.editable||(allOps.length===0&&appliedCount===0);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
setEditorStatus(text:string,error=false){
|
|
572
|
+
this.editorStatus.textContent=text;
|
|
573
|
+
this.editorStatus.title=text;
|
|
574
|
+
this.editorStatus.classList.toggle('error',error);
|
|
575
|
+
this.editorStatus.setAttribute('role',error?'alert':'status');
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
busy(isBusy:boolean){
|
|
579
|
+
this.isBusy=isBusy;
|
|
580
|
+
this.options.host.setAttribute('aria-busy',String(isBusy));
|
|
581
|
+
this.renderEditorBar();
|
|
582
|
+
this.syncKeyInspectorInPlace();
|
|
583
|
+
this.renderCurve();
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
markApplied(ops:readonly AnimationSourceOp[],statusText:string,isError=false){
|
|
587
|
+
this.appliedOps=ops.map(o=>structuredClone(o));
|
|
588
|
+
this.syncEffectiveInspection(true);
|
|
589
|
+
this.renderEditorBar();
|
|
590
|
+
this.renderTimeline();
|
|
591
|
+
this.renderChannels();
|
|
592
|
+
this.setEditorStatus(statusText,isError);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Reconcile the stage's currently active animation record without wiping pending edits in `this.builder`.
|
|
597
|
+
* When another kind of Apply (Bones, Mesh, Idle, Retarget, Chest, etc.) replaces the stage build, `applied` is `null`
|
|
598
|
+
* and `this.appliedOps` clears to `[]` while `this.builder.ops` stays intact as pending unapplied edits.
|
|
599
|
+
*/
|
|
600
|
+
reconcileStageApplied(applied:AppliedAnimation|null){
|
|
601
|
+
const nextApplied=applied?applied.ops.map(o=>structuredClone(o)):[];
|
|
602
|
+
if(JSON.stringify(this.appliedOps)===JSON.stringify(nextApplied))return;
|
|
603
|
+
this.appliedOps=nextApplied;
|
|
604
|
+
this.syncEffectiveInspection(true);
|
|
605
|
+
this.renderEditorBar();
|
|
606
|
+
this.renderTimeline();
|
|
607
|
+
this.renderChannels();
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
syncApplied(applied:AppliedAnimation|null){
|
|
611
|
+
this.appliedOps=applied?applied.ops.map(o=>structuredClone(o)):[];
|
|
612
|
+
if(this.source?.available&&this.source.text){
|
|
613
|
+
this.builder=new AnimationOpBuilder(this.source.text,(this.source.easings??undefined) as Readonly<Record<string,EasingTuple>>|undefined);
|
|
614
|
+
for(const op of this.appliedOps){
|
|
615
|
+
try{this.builder.apply(op);}catch{break;}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
this.syncEffectiveInspection(true);
|
|
619
|
+
this.renderEditorBar();
|
|
620
|
+
this.renderSelection();
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
applyOp(
|
|
624
|
+
op:AnimationSourceOp,
|
|
625
|
+
opts:{skipTimelineDomRebuild?:boolean}={},
|
|
626
|
+
):{ok:true;ops:readonly AnimationSourceOp[]}|{ok:false;error:string}{
|
|
627
|
+
const gate=this.gateInfo();
|
|
628
|
+
if(!gate.editable){
|
|
629
|
+
const err=`${gate.code}: ${gate.reason??'animation is read-only'}`;
|
|
630
|
+
this.setEditorStatus(err,true);
|
|
631
|
+
return {ok:false,error:err};
|
|
632
|
+
}
|
|
633
|
+
if(!this.builder||!this.source?.available){
|
|
634
|
+
const err='ANIMATION_SOURCE_MISSING: animation source is not loaded';
|
|
635
|
+
this.setEditorStatus(err,true);
|
|
636
|
+
return {ok:false,error:err};
|
|
637
|
+
}
|
|
638
|
+
try{
|
|
639
|
+
this.options.pause?.();
|
|
640
|
+
this.builder.apply(op);
|
|
641
|
+
this.syncEffectiveInspection(true);
|
|
642
|
+
this.renderEditorBar();
|
|
643
|
+
if(opts.skipTimelineDomRebuild){
|
|
644
|
+
this.syncTimelineKeysInPlace();
|
|
645
|
+
this.syncKeyInspectorInPlace();
|
|
646
|
+
}else{
|
|
647
|
+
this.renderTimeline();
|
|
648
|
+
}
|
|
649
|
+
this.renderChannels();
|
|
650
|
+
this.setEditorStatus(`Applied ${op.op} on ${op.animation} track ${op.track} (${this.builder.ops.length} pending op(s), preview active).`,false);
|
|
651
|
+
return {ok:true,ops:this.builder.ops};
|
|
652
|
+
}catch(e){
|
|
653
|
+
const msg=e instanceof Error?e.message:String(e);
|
|
654
|
+
this.setEditorStatus(msg,true);
|
|
655
|
+
return {ok:false,error:msg};
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
setKeyTime(trackIndex:number,keyIndex:number,time:number){
|
|
660
|
+
return this.applyOp(
|
|
661
|
+
{op:'set_key_time',animation:this.animation,track:trackIndex,key:keyIndex,time},
|
|
662
|
+
{skipTimelineDomRebuild:true},
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
setKeyValue(trackIndex:number,keyIndex:number,channel:number|undefined,value:number|readonly number[]){
|
|
667
|
+
return this.applyOp(
|
|
668
|
+
channel!==undefined
|
|
669
|
+
?{op:'set_key_value',animation:this.animation,track:trackIndex,key:keyIndex,channel,value:value as number}
|
|
670
|
+
:{op:'set_key_value',animation:this.animation,track:trackIndex,key:keyIndex,value:value as readonly number[]},
|
|
671
|
+
{skipTimelineDomRebuild:true},
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
setKeyCurve(trackIndex:number,keyIndex:number,curve:readonly number[]|'stepped'|null){
|
|
676
|
+
return this.applyOp(
|
|
677
|
+
{op:'set_key_curve',animation:this.animation,track:trackIndex,key:keyIndex,curve},
|
|
678
|
+
{skipTimelineDomRebuild:true},
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
setKeyEase(trackIndex:number,keyIndex:number,ease:string|null){
|
|
683
|
+
return this.applyOp(
|
|
684
|
+
{op:'set_key_ease',animation:this.animation,track:trackIndex,key:keyIndex,ease},
|
|
685
|
+
{skipTimelineDomRebuild:true},
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
insertKey(trackIndex:number,time:number,value?:readonly number[]){
|
|
690
|
+
const gate=this.gateInfo();
|
|
691
|
+
if(!gate.editable){
|
|
692
|
+
const err=`${gate.code}: ${gate.reason??'animation is read-only'}`;
|
|
693
|
+
this.setEditorStatus(err,true);
|
|
694
|
+
return {ok:false as const,error:err};
|
|
695
|
+
}
|
|
696
|
+
const clss=this.tracksInfo();
|
|
697
|
+
const cls=clss[trackIndex];
|
|
698
|
+
if(!cls||!cls.editable){
|
|
699
|
+
const err=cls?`ANIMATION_TRACK_READ_ONLY: ${cls.reason}`:`ANIMATION_TRACK_OUT_OF_RANGE: track ${trackIndex}`;
|
|
700
|
+
this.setEditorStatus(err,true);
|
|
701
|
+
return {ok:false as const,error:err};
|
|
702
|
+
}
|
|
703
|
+
let resolvedValue=value;
|
|
704
|
+
if(!resolvedValue){
|
|
705
|
+
const inspTrack=this.inspection?.tracks.find(t=>t.kind==='bone'&&t.target===cls.target&&t.name===cls.property);
|
|
706
|
+
const vals:number[]=[];
|
|
707
|
+
for(let c=0;c<cls.channels;c++){
|
|
708
|
+
const sampled=inspTrack?evaluateStoredChannel(inspTrack,c,time):null;
|
|
709
|
+
if(sampled!==null&&Number.isFinite(sampled)){
|
|
710
|
+
vals.push(cleanMotionNumber(sampled));
|
|
711
|
+
}else{
|
|
712
|
+
const doc=this.draftDocument() as {animations?:Record<string,{tracks?:Array<{keys?:Array<{v?:number[]}>}>}>}|undefined;
|
|
713
|
+
const fallback=doc?.animations?.[this.animation]?.tracks?.[trackIndex]?.keys?.[0]?.v?.[c]??0;
|
|
714
|
+
vals.push(cleanMotionNumber(fallback));
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
resolvedValue=vals;
|
|
718
|
+
}
|
|
719
|
+
const res=this.applyOp({
|
|
720
|
+
op:'insert_key',
|
|
721
|
+
animation:this.animation,
|
|
722
|
+
track:trackIndex,
|
|
723
|
+
time,
|
|
724
|
+
value:resolvedValue,
|
|
725
|
+
});
|
|
726
|
+
if(res.ok){
|
|
727
|
+
const rawKeys=this.readDraftTrackKeys(trackIndex);
|
|
728
|
+
const insertedIdx=rawKeys.findIndex(k=>k.t===cleanMotionNumber(time));
|
|
729
|
+
if(insertedIdx>=0){
|
|
730
|
+
const inspTrack=this.inspection?.tracks.find(t=>t.kind==='bone'&&t.target===cls.target&&t.name===cls.property);
|
|
731
|
+
this.selectedKey={animation:this.animation,trackIndex,keyIndex:insertedIdx,pointer:inspTrack?.pointer??''};
|
|
732
|
+
this.syncTimelineKeysInPlace();
|
|
733
|
+
this.syncKeyInspectorInPlace();
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return res;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
deleteKey(trackIndex:number,keyIndex:number){
|
|
740
|
+
const res=this.applyOp({op:'delete_key',animation:this.animation,track:trackIndex,key:keyIndex});
|
|
741
|
+
if(res.ok){
|
|
742
|
+
const rawKeys=this.readDraftTrackKeys(trackIndex);
|
|
743
|
+
if(this.selectedKey&&this.selectedKey.trackIndex===trackIndex){
|
|
744
|
+
if(rawKeys.length===0){
|
|
745
|
+
this.selectedKey=null;
|
|
746
|
+
}else{
|
|
747
|
+
this.selectedKey={...this.selectedKey,keyIndex:Math.min(keyIndex,rawKeys.length-1)};
|
|
748
|
+
}
|
|
749
|
+
this.syncTimelineKeysInPlace();
|
|
750
|
+
this.syncKeyInspectorInPlace();
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return res;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
moveSelection(
|
|
757
|
+
selections:ReadonlyArray<{track:number;key:number}>,
|
|
758
|
+
deltaTime:number,
|
|
759
|
+
):{ok:true;ops:readonly AnimationSourceOp[]}|{ok:false;error:string}{
|
|
760
|
+
const gate=this.gateInfo();
|
|
761
|
+
if(!gate.editable){
|
|
762
|
+
const err=`${gate.code}: ${gate.reason??'animation is read-only'}`;
|
|
763
|
+
this.setEditorStatus(err,true);
|
|
764
|
+
return {ok:false,error:err};
|
|
765
|
+
}
|
|
766
|
+
if(!this.builder||!this.source?.available){
|
|
767
|
+
const err='ANIMATION_SOURCE_MISSING: animation source is not loaded';
|
|
768
|
+
this.setEditorStatus(err,true);
|
|
769
|
+
return {ok:false,error:err};
|
|
770
|
+
}
|
|
771
|
+
try{
|
|
772
|
+
this.options.pause?.();
|
|
773
|
+
this.builder.moveSelection(this.animation,selections,deltaTime);
|
|
774
|
+
this.syncEffectiveInspection(true);
|
|
775
|
+
this.renderEditorBar();
|
|
776
|
+
this.syncTimelineKeysInPlace();
|
|
777
|
+
this.syncKeyInspectorInPlace();
|
|
778
|
+
this.renderChannels();
|
|
779
|
+
this.setEditorStatus(`Moved ${selections.length} selected key(s) by ${deltaTime} s (${this.builder.ops.length} pending op(s)).`,false);
|
|
780
|
+
return {ok:true,ops:this.builder.ops};
|
|
781
|
+
}catch(e){
|
|
782
|
+
const msg=e instanceof Error?e.message:String(e);
|
|
783
|
+
this.setEditorStatus(msg,true);
|
|
784
|
+
return {ok:false,error:msg};
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
undoOp():boolean{
|
|
789
|
+
if(!this.builder)return false;
|
|
790
|
+
const undone=this.builder.undo();
|
|
791
|
+
if(!undone)return false;
|
|
792
|
+
this.syncEffectiveInspection(true);
|
|
793
|
+
this.renderEditorBar();
|
|
794
|
+
this.renderTimeline();
|
|
795
|
+
this.renderChannels();
|
|
796
|
+
this.setEditorStatus(`Undid last pending op (${this.builder.ops.length} pending op(s) remaining).`,false);
|
|
797
|
+
return true;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
clearPending():void{
|
|
801
|
+
if(!this.builder||!this.source?.text)return;
|
|
802
|
+
this.builder=new AnimationOpBuilder(this.source.text,(this.source.easings??undefined) as Readonly<Record<string,EasingTuple>>|undefined);
|
|
803
|
+
for(const op of this.appliedOps){
|
|
804
|
+
try{this.builder.apply(op);}catch{break;}
|
|
805
|
+
}
|
|
806
|
+
this.syncEffectiveInspection(true);
|
|
807
|
+
this.renderEditorBar();
|
|
808
|
+
this.renderTimeline();
|
|
809
|
+
this.renderChannels();
|
|
810
|
+
this.setEditorStatus('Discarded unapplied animation edits.',false);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
resetEdits():void{
|
|
814
|
+
this.appliedOps=[];
|
|
815
|
+
if(this.source?.available&&this.source.text){
|
|
816
|
+
this.builder=new AnimationOpBuilder(this.source.text,(this.source.easings??undefined) as Readonly<Record<string,EasingTuple>>|undefined);
|
|
817
|
+
}
|
|
818
|
+
this.selectedKey=null;
|
|
819
|
+
this.syncEffectiveInspection(true);
|
|
820
|
+
this.renderEditorBar();
|
|
821
|
+
this.renderTimeline();
|
|
822
|
+
this.renderChannels();
|
|
823
|
+
this.setEditorStatus('Reset: no pending animation ops.',false);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
selectKey(trackIndex:number,keyIndex:number):boolean{
|
|
827
|
+
const gate=this.gateInfo();
|
|
828
|
+
if(!gate.editable){
|
|
829
|
+
this.setEditorStatus(`${gate.code}: ${gate.reason}`,true);
|
|
830
|
+
return false;
|
|
831
|
+
}
|
|
832
|
+
const clss=this.tracksInfo();
|
|
833
|
+
const cls=clss[trackIndex];
|
|
834
|
+
if(!cls){
|
|
835
|
+
this.setEditorStatus(`ANIMATION_TRACK_OUT_OF_RANGE: track ${trackIndex}`,true);
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
if(!cls.editable){
|
|
839
|
+
this.setEditorStatus(`ANIMATION_TRACK_READ_ONLY: ${cls.reason}`,true);
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
const rawKeys=this.readDraftTrackKeys(trackIndex);
|
|
843
|
+
const k=rawKeys[keyIndex];
|
|
844
|
+
if(!k){
|
|
845
|
+
this.setEditorStatus(`ANIMATION_KEY_OUT_OF_RANGE: key ${keyIndex} on track ${trackIndex}`,true);
|
|
846
|
+
return false;
|
|
847
|
+
}
|
|
848
|
+
const inspTrack=this.inspection?.tracks.find(t=>t.kind==='bone'&&t.target===cls.target&&t.name===cls.property)??null;
|
|
849
|
+
this.selectedKey={animation:this.animation,trackIndex,keyIndex,pointer:inspTrack?.pointer??''};
|
|
850
|
+
if(inspTrack){
|
|
851
|
+
this.track=inspTrack;
|
|
852
|
+
this.channel=0;
|
|
853
|
+
this.renderChannels();
|
|
854
|
+
}
|
|
855
|
+
if(k.t>=0&&k.t<=this.runtimeDuration){
|
|
856
|
+
this.options.seek(k.t);
|
|
857
|
+
}
|
|
858
|
+
this.syncTimelineKeysInPlace();
|
|
859
|
+
this.syncKeyInspectorInPlace();
|
|
860
|
+
return true;
|
|
48
861
|
}
|
|
862
|
+
|
|
863
|
+
selectedKeyInfo(){
|
|
864
|
+
if(!this.selectedKey||this.selectedKey.animation!==this.animation)return null;
|
|
865
|
+
const clss=this.tracksInfo();
|
|
866
|
+
const cls=clss[this.selectedKey.trackIndex];
|
|
867
|
+
if(!cls||!cls.editable)return null;
|
|
868
|
+
const rawKeys=this.readDraftTrackKeys(this.selectedKey.trackIndex);
|
|
869
|
+
const k=rawKeys[this.selectedKey.keyIndex];
|
|
870
|
+
if(!k)return null;
|
|
871
|
+
const spec=CHANNELS[cls.property]??[];
|
|
872
|
+
return {
|
|
873
|
+
animation:this.animation,
|
|
874
|
+
trackIndex:this.selectedKey.trackIndex,
|
|
875
|
+
keyIndex:this.selectedKey.keyIndex,
|
|
876
|
+
bone:cls.target,
|
|
877
|
+
property:cls.property,
|
|
878
|
+
time:k.t,
|
|
879
|
+
values:[...k.v],
|
|
880
|
+
channels:spec.map((ch,idx)=>({index:idx,field:ch.field,local:ch.local,value:k.v[idx]!})),
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
private readDraftTrackKeys(trackIndex:number):Array<{t:number;v:number[];ease?:string;curve?:number[]|'stepped'}>{
|
|
885
|
+
const doc=this.draftDocument() as {animations?:Record<string,{tracks?:Array<{keys?:Array<{t:number;v:number[];ease?:string;curve?:number[]|'stepped'}>}>}>}|undefined;
|
|
886
|
+
const keys=doc?.animations?.[this.animation]?.tracks?.[trackIndex]?.keys;
|
|
887
|
+
return Array.isArray(keys)?keys:[];
|
|
888
|
+
}
|
|
889
|
+
|
|
49
890
|
private has(value:InspectionTarget){return !value||!!this.inspection&&(value.kind==='bone'?this.inspection.bones:this.inspection.slots).some(x=>x.name===value.name);}
|
|
50
891
|
unavailable(reason:string){this.model(null,'');this.capture(null,undefined);this.status.textContent=reason;}
|
|
51
892
|
select(value:InspectionTarget){if(this.has(value))this.selection.select(value);}
|
|
52
893
|
fromParts(slot:string|null){this.selection.select(slot?{kind:'slot',name:slot}:null);}
|
|
53
894
|
value(){return this.selection.value();}
|
|
54
895
|
show(view:string){this.view=view;for(const [id,pane]of this.panes)pane.hidden=id!==view;for(const b of this.views)b.setAttribute('aria-pressed',String(b.dataset.animationView===view));}
|
|
896
|
+
|
|
55
897
|
private renderSelection(){
|
|
56
898
|
const selected=this.selection.value();this.options.host.dataset.selectedKind=selected?.kind??'';this.options.host.dataset.selectedName=selected?.name??'';
|
|
57
899
|
for(const b of this.options.host.querySelectorAll<HTMLButtonElement>('[data-tree-kind]'))b.setAttribute('aria-pressed',String(b.dataset.treeKind===selected?.kind&&b.dataset.treeName===selected?.name));
|
|
58
900
|
this.renderTimeline();this.renderChannels();this.redraw();
|
|
59
901
|
}
|
|
902
|
+
|
|
60
903
|
private renderTree(){
|
|
61
904
|
const pane=this.panes.get('tree')!;pane.replaceChildren();if(!this.inspection)return;
|
|
62
905
|
pane.append(button('Whole rig',()=>this.select(null)));const root=document.createElement('ul');root.className='animation-tree';pane.append(root);const parents=new Map<string,HTMLElement>();
|
|
@@ -67,23 +910,633 @@ export class AnimationInspectionPanel {
|
|
|
67
910
|
}
|
|
68
911
|
const note=document.createElement('p');note.className='hint';note.textContent='Enable Bone points to pick bones on stage. Overlapping points pick the last active bone in source order; use the tree for an exact target. Attached Parts rows highlight together.';pane.prepend(note);
|
|
69
912
|
}
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Fixed-height single-row Key Bar. Both the insert controls and the selected-key fields
|
|
916
|
+
* always occupy the same 26px bar so selecting or editing a key produces zero layout shift.
|
|
917
|
+
*/
|
|
918
|
+
private renderKeyInspector(host:HTMLElement){
|
|
919
|
+
const box=document.createElement('div');
|
|
920
|
+
box.className='animation-key-inspector';
|
|
921
|
+
box.dataset.keyInspector='';
|
|
922
|
+
const gate=this.gateInfo();
|
|
923
|
+
const clss=this.tracksInfo();
|
|
924
|
+
const editableTracks=clss.filter(c=>c.editable);
|
|
925
|
+
|
|
926
|
+
const addBar=document.createElement('div');
|
|
927
|
+
addBar.className='animation-insert-bar';
|
|
928
|
+
const trackLabel=document.createElement('label');
|
|
929
|
+
trackLabel.className='animation-bar-field';
|
|
930
|
+
trackLabel.textContent='Track ';
|
|
931
|
+
const trackSel=document.createElement('select');
|
|
932
|
+
trackSel.dataset.insertTrack='';
|
|
933
|
+
trackSel.disabled=!gate.editable||editableTracks.length===0;
|
|
934
|
+
if(editableTracks.length===0){
|
|
935
|
+
const opt=document.createElement('option');
|
|
936
|
+
opt.value='';
|
|
937
|
+
opt.textContent='No editable tracks';
|
|
938
|
+
trackSel.append(opt);
|
|
939
|
+
}else{
|
|
940
|
+
for(const c of editableTracks){
|
|
941
|
+
const opt=document.createElement('option');
|
|
942
|
+
opt.value=String(c.trackIndex);
|
|
943
|
+
opt.textContent=`#${c.trackIndex} ${c.target} · ${c.property}`;
|
|
944
|
+
if(this.selectedKey?.trackIndex===c.trackIndex)opt.selected=true;
|
|
945
|
+
trackSel.append(opt);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
trackLabel.append(trackSel);
|
|
949
|
+
|
|
950
|
+
const timeLabel=document.createElement('label');
|
|
951
|
+
timeLabel.className='animation-bar-field';
|
|
952
|
+
timeLabel.textContent='t ';
|
|
953
|
+
const timeIn=document.createElement('input');
|
|
954
|
+
timeIn.type='number';
|
|
955
|
+
timeIn.step='any';
|
|
956
|
+
timeIn.min='0';
|
|
957
|
+
timeIn.dataset.insertTime='';
|
|
958
|
+
timeIn.disabled=!gate.editable||editableTracks.length===0;
|
|
959
|
+
timeIn.value=String(cleanMotionNumber(this.at));
|
|
960
|
+
timeLabel.append(timeIn);
|
|
961
|
+
|
|
962
|
+
const addBtn=button('+ Add key',()=>{
|
|
963
|
+
const tIdx=Number(trackSel.value);
|
|
964
|
+
const tVal=Number(timeIn.value);
|
|
965
|
+
this.insertKey(tIdx,tVal);
|
|
966
|
+
});
|
|
967
|
+
addBtn.dataset.insertKey='';
|
|
968
|
+
addBtn.disabled=!gate.editable||editableTracks.length===0;
|
|
969
|
+
addBar.append(trackLabel,timeLabel,addBtn);
|
|
970
|
+
box.append(addBar);
|
|
971
|
+
|
|
972
|
+
const detail=document.createElement('div');
|
|
973
|
+
detail.className='animation-key-detail';
|
|
974
|
+
detail.dataset.keyDetail='';
|
|
975
|
+
const title=document.createElement('strong');
|
|
976
|
+
title.className='animation-key-title';
|
|
977
|
+
title.dataset.keyInspectorTitle='';
|
|
978
|
+
detail.append(title);
|
|
979
|
+
|
|
980
|
+
const timeWrap=document.createElement('label');
|
|
981
|
+
timeWrap.className='animation-bar-field';
|
|
982
|
+
timeWrap.textContent='Key t (s) ';
|
|
983
|
+
const timeInput=document.createElement('input');
|
|
984
|
+
timeInput.type='number';
|
|
985
|
+
timeInput.step='any';
|
|
986
|
+
timeInput.min='0';
|
|
987
|
+
timeInput.dataset.keyTimeInput='';
|
|
988
|
+
timeWrap.append(timeInput);
|
|
989
|
+
detail.append(timeWrap);
|
|
990
|
+
|
|
991
|
+
const channelsHost=document.createElement('span');
|
|
992
|
+
channelsHost.className='animation-key-channels';
|
|
993
|
+
channelsHost.dataset.keyChannelsHost='';
|
|
994
|
+
detail.append(channelsHost);
|
|
995
|
+
|
|
996
|
+
const delBtn=button('Delete key',()=>{});
|
|
997
|
+
delBtn.dataset.deleteKey='';
|
|
998
|
+
detail.append(delBtn);
|
|
999
|
+
|
|
1000
|
+
const hint=document.createElement('span');
|
|
1001
|
+
hint.className='hint animation-key-empty';
|
|
1002
|
+
hint.dataset.keyInspectorEmpty='';
|
|
1003
|
+
detail.append(hint);
|
|
1004
|
+
|
|
1005
|
+
box.append(detail);
|
|
1006
|
+
host.append(box);
|
|
1007
|
+
this.syncKeyInspectorInPlace();
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
private syncKeyInspectorInPlace(){
|
|
1011
|
+
const box=this.options.host.querySelector<HTMLElement>('[data-key-inspector]');
|
|
1012
|
+
if(!box)return;
|
|
1013
|
+
const gate=this.gateInfo();
|
|
1014
|
+
const info=this.selectedKeyInfo();
|
|
1015
|
+
|
|
1016
|
+
const trackSel=box.querySelector<HTMLSelectElement>('[data-insert-track]');
|
|
1017
|
+
if(trackSel&&info){
|
|
1018
|
+
for(const opt of trackSel.options){
|
|
1019
|
+
opt.selected=opt.value===String(info.trackIndex);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
const title=box.querySelector<HTMLElement>('[data-key-inspector-title]');
|
|
1024
|
+
const timeInput=box.querySelector<HTMLInputElement>('[data-key-time-input]');
|
|
1025
|
+
const channelsHost=box.querySelector<HTMLElement>('[data-key-channels-host]');
|
|
1026
|
+
const delBtn=box.querySelector<HTMLButtonElement>('[data-delete-key]');
|
|
1027
|
+
const emptyHint=box.querySelector<HTMLElement>('[data-key-inspector-empty]');
|
|
1028
|
+
|
|
1029
|
+
if(!info){
|
|
1030
|
+
const hideInputs=!gate.editable;
|
|
1031
|
+
if(title){
|
|
1032
|
+
title.hidden=hideInputs;
|
|
1033
|
+
title.textContent='No key selected';
|
|
1034
|
+
title.title='';
|
|
1035
|
+
}
|
|
1036
|
+
if(timeInput){
|
|
1037
|
+
timeInput.disabled=true;
|
|
1038
|
+
if(timeInput.parentElement)timeInput.parentElement.hidden=hideInputs;
|
|
1039
|
+
if(document.activeElement!==timeInput)timeInput.value='';
|
|
1040
|
+
timeInput.onchange=null;
|
|
1041
|
+
}
|
|
1042
|
+
if(channelsHost){
|
|
1043
|
+
channelsHost.hidden=hideInputs;
|
|
1044
|
+
const existing=channelsHost.querySelectorAll<HTMLInputElement>('[data-key-channel]');
|
|
1045
|
+
if(existing.length!==1||!existing[0]!.disabled){
|
|
1046
|
+
const chWrap=document.createElement('label');
|
|
1047
|
+
chWrap.className='animation-bar-field';
|
|
1048
|
+
chWrap.textContent='val ';
|
|
1049
|
+
const chInput=document.createElement('input');
|
|
1050
|
+
chInput.type='number';
|
|
1051
|
+
chInput.step='any';
|
|
1052
|
+
chInput.dataset.keyChannel='0';
|
|
1053
|
+
chInput.disabled=true;
|
|
1054
|
+
chInput.value='';
|
|
1055
|
+
chWrap.append(chInput);
|
|
1056
|
+
channelsHost.replaceChildren(chWrap);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
if(delBtn){
|
|
1060
|
+
delBtn.hidden=hideInputs;
|
|
1061
|
+
delBtn.disabled=true;
|
|
1062
|
+
delBtn.onclick=null;
|
|
1063
|
+
}
|
|
1064
|
+
if(emptyHint){
|
|
1065
|
+
emptyHint.hidden=gate.editable;
|
|
1066
|
+
emptyHint.textContent=gate.editable
|
|
1067
|
+
?''
|
|
1068
|
+
:`Key editing disabled (${gate.code})`;
|
|
1069
|
+
emptyHint.title=gate.editable?'':`${gate.code}: ${gate.reason}`;
|
|
1070
|
+
}
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
if(title){
|
|
1075
|
+
title.hidden=false;
|
|
1076
|
+
title.textContent=`${info.bone} · ${info.property} · key #${info.keyIndex} (track #${info.trackIndex})`;
|
|
1077
|
+
title.title=title.textContent;
|
|
1078
|
+
}
|
|
1079
|
+
if(timeInput){
|
|
1080
|
+
if(timeInput.parentElement)timeInput.parentElement.hidden=false;
|
|
1081
|
+
timeInput.disabled=this.isBusy;
|
|
1082
|
+
if(document.activeElement!==timeInput)timeInput.value=String(cleanMotionNumber(info.time));
|
|
1083
|
+
timeInput.onchange=()=>{
|
|
1084
|
+
const nextT=Number(timeInput.value);
|
|
1085
|
+
this.setKeyTime(info.trackIndex,info.keyIndex,nextT);
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
if(channelsHost){
|
|
1089
|
+
channelsHost.hidden=false;
|
|
1090
|
+
const existing=channelsHost.querySelectorAll<HTMLInputElement>('[data-key-channel]');
|
|
1091
|
+
const sameShape=
|
|
1092
|
+
existing.length===info.channels.length&&
|
|
1093
|
+
info.channels.every((ch,idx)=>existing[idx]?.dataset.channelLocal===ch.local&&existing[idx]?.dataset.channelField===ch.field);
|
|
1094
|
+
if(sameShape){
|
|
1095
|
+
info.channels.forEach((ch,idx)=>{
|
|
1096
|
+
const chIn=existing[idx]!;
|
|
1097
|
+
chIn.disabled=this.isBusy;
|
|
1098
|
+
if(document.activeElement!==chIn)chIn.value=String(ch.value);
|
|
1099
|
+
chIn.onchange=()=>{
|
|
1100
|
+
const nextV=Number(chIn.value);
|
|
1101
|
+
this.setKeyValue(info.trackIndex,info.keyIndex,ch.index,nextV);
|
|
1102
|
+
};
|
|
1103
|
+
});
|
|
1104
|
+
}else{
|
|
1105
|
+
const nodes:HTMLElement[]=[];
|
|
1106
|
+
for(const ch of info.channels){
|
|
1107
|
+
const chWrap=document.createElement('label');
|
|
1108
|
+
chWrap.className='animation-bar-field';
|
|
1109
|
+
chWrap.textContent=`${ch.local} (${ch.field}) `;
|
|
1110
|
+
const chInput=document.createElement('input');
|
|
1111
|
+
chInput.type='number';
|
|
1112
|
+
chInput.step='any';
|
|
1113
|
+
chInput.disabled=this.isBusy;
|
|
1114
|
+
chInput.dataset.keyChannel=String(ch.index);
|
|
1115
|
+
chInput.dataset.channelLocal=ch.local;
|
|
1116
|
+
chInput.dataset.channelField=ch.field;
|
|
1117
|
+
chInput.value=String(ch.value);
|
|
1118
|
+
chInput.onchange=()=>{
|
|
1119
|
+
const nextV=Number(chInput.value);
|
|
1120
|
+
this.setKeyValue(info.trackIndex,info.keyIndex,ch.index,nextV);
|
|
1121
|
+
};
|
|
1122
|
+
chWrap.append(chInput);
|
|
1123
|
+
nodes.push(chWrap);
|
|
1124
|
+
}
|
|
1125
|
+
channelsHost.replaceChildren(...nodes);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
if(delBtn){
|
|
1129
|
+
delBtn.hidden=false;
|
|
1130
|
+
delBtn.disabled=this.isBusy;
|
|
1131
|
+
delBtn.onclick=()=>{
|
|
1132
|
+
this.deleteKey(info.trackIndex,info.keyIndex);
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
if(emptyHint){
|
|
1136
|
+
emptyHint.hidden=true;
|
|
1137
|
+
emptyHint.textContent='';
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
private effectiveEnd():number{
|
|
1142
|
+
return Math.max(
|
|
1143
|
+
this.runtimeDuration,
|
|
1144
|
+
...(this.inspection?.tracks??[]).map(t=>t.keys.at(-1)?.time??0),
|
|
1145
|
+
Number.MIN_VALUE,
|
|
1146
|
+
);
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
private syncRulerInPlace(end:number){
|
|
1150
|
+
const cleanEnd=formatSeconds(end);
|
|
1151
|
+
const axis=this.options.host.querySelector<HTMLElement>('.animation-axis');
|
|
1152
|
+
if(axis)axis.textContent=`0 s → ${cleanEnd} s`;
|
|
1153
|
+
const rulerTrack=this.options.host.querySelector<HTMLElement>('[data-animation-ruler-track]');
|
|
1154
|
+
if(!rulerTrack)return;
|
|
1155
|
+
for(const oldTick of [...rulerTrack.querySelectorAll('.animation-ruler-tick')])oldTick.remove();
|
|
1156
|
+
const playhead=rulerTrack.querySelector('[data-playhead]');
|
|
1157
|
+
for(const tickTime of buildRulerTicks(end,this.zoom)){
|
|
1158
|
+
const tick=document.createElement('span');
|
|
1159
|
+
tick.className='animation-ruler-tick';
|
|
1160
|
+
tick.dataset.rulerTick=formatSeconds(tickTime);
|
|
1161
|
+
tick.style.left=`${Math.max(0,Math.min(100,tickTime/end*100))}%`;
|
|
1162
|
+
tick.textContent=`${formatSeconds(tickTime)} s`;
|
|
1163
|
+
rulerTrack.append(tick);
|
|
1164
|
+
}
|
|
1165
|
+
if(playhead)rulerTrack.append(playhead);
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
private syncTimelineKeysInPlace(){
|
|
1169
|
+
if(!this.inspection)return;
|
|
1170
|
+
const end=this.effectiveEnd();
|
|
1171
|
+
this.syncRulerInPlace(end);
|
|
1172
|
+
const marks=this.options.host.querySelectorAll<HTMLButtonElement>('.animation-key');
|
|
1173
|
+
for(const mark of marks){
|
|
1174
|
+
const ptr=mark.dataset.track;
|
|
1175
|
+
const track=ptr?this.inspection.tracks.find(t=>t.pointer===ptr):undefined;
|
|
1176
|
+
const kIdx=Number(mark.dataset.keyIndex);
|
|
1177
|
+
const srcTrack=mark.dataset.sourceTrack!==undefined?Number(mark.dataset.sourceTrack):undefined;
|
|
1178
|
+
const isEditable=mark.dataset.editable==='true';
|
|
1179
|
+
const isSelected=isEditable&&srcTrack!==undefined&&this.selectedKey?.animation===this.animation&&this.selectedKey.trackIndex===srcTrack&&this.selectedKey.keyIndex===kIdx;
|
|
1180
|
+
mark.classList.toggle('selected',isSelected);
|
|
1181
|
+
mark.setAttribute('aria-pressed',String(isSelected));
|
|
1182
|
+
if(track&&track.keys[kIdx]){
|
|
1183
|
+
const key=track.keys[kIdx]!;
|
|
1184
|
+
const cleanT=formatSeconds(key.time);
|
|
1185
|
+
mark.dataset.keyTime=cleanT;
|
|
1186
|
+
mark.style.left=`${Math.max(0,Math.min(100,key.time/end*100))}%`;
|
|
1187
|
+
mark.title=`${track.target} · ${track.name} · key ${kIdx} · ${cleanT} s${isEditable?' (drag to retime)':' (read-only)'}`;
|
|
1188
|
+
mark.setAttribute('aria-label',mark.title);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
this.placePlayheads();
|
|
1192
|
+
}
|
|
1193
|
+
|
|
70
1194
|
private renderTimeline(){
|
|
71
|
-
const pane=this.panes.get('timeline')!;
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
1195
|
+
const pane=this.panes.get('timeline')!;
|
|
1196
|
+
const prevLanes=pane.querySelector<HTMLElement>('.animation-lanes');
|
|
1197
|
+
const prevScrollTop=prevLanes?.scrollTop??0;
|
|
1198
|
+
const prevScrollLeft=prevLanes?.scrollLeft??0;
|
|
1199
|
+
pane.replaceChildren();
|
|
1200
|
+
this.playhead=null;
|
|
1201
|
+
if(!this.inspection)return;
|
|
1202
|
+
this.renderKeyInspector(pane);
|
|
1203
|
+
|
|
1204
|
+
const gate=this.gateInfo();
|
|
1205
|
+
const clss=this.tracksInfo();
|
|
1206
|
+
const clsByBoneProp=new Map<string,TrackClassification>();
|
|
1207
|
+
for(const c of clss){
|
|
1208
|
+
if(c.targetKind==='bone')clsByBoneProp.set(`${c.target}\0${c.property}`,c);
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
const tracks=filterTracks(this.inspection,this.selection.value());
|
|
1212
|
+
const end=this.effectiveEnd();
|
|
1213
|
+
const cleanEnd=formatSeconds(end);
|
|
1214
|
+
const rowWidth=this.zoom>1?`calc(190px + (100% - 190px) * ${this.zoom})`:'100%';
|
|
1215
|
+
|
|
1216
|
+
const list=document.createElement('div');
|
|
1217
|
+
list.className='animation-lanes';
|
|
1218
|
+
list.dataset.animationLanes='';
|
|
1219
|
+
pane.append(list);
|
|
1220
|
+
|
|
1221
|
+
// Sticky top time ruler with ticks and scrub support
|
|
1222
|
+
const ruler=document.createElement('div');
|
|
1223
|
+
ruler.className='animation-ruler';
|
|
1224
|
+
ruler.dataset.animationRuler='';
|
|
1225
|
+
ruler.style.width=rowWidth;
|
|
1226
|
+
const rulerCorner=document.createElement('div');
|
|
1227
|
+
rulerCorner.className='animation-ruler-corner';
|
|
1228
|
+
const axis=document.createElement('div');
|
|
1229
|
+
axis.className='animation-axis';
|
|
1230
|
+
axis.textContent=`0 s → ${cleanEnd} s`;
|
|
1231
|
+
rulerCorner.append(axis);
|
|
1232
|
+
|
|
1233
|
+
const rulerTrack=document.createElement('div');
|
|
1234
|
+
rulerTrack.className='animation-ruler-track';
|
|
1235
|
+
rulerTrack.dataset.animationRulerTrack='';
|
|
1236
|
+
for(const tickTime of buildRulerTicks(end,this.zoom)){
|
|
1237
|
+
const tick=document.createElement('span');
|
|
1238
|
+
tick.className='animation-ruler-tick';
|
|
1239
|
+
tick.dataset.rulerTick=formatSeconds(tickTime);
|
|
1240
|
+
tick.style.left=`${Math.max(0,Math.min(100,tickTime/end*100))}%`;
|
|
1241
|
+
tick.textContent=`${formatSeconds(tickTime)} s`;
|
|
1242
|
+
rulerTrack.append(tick);
|
|
1243
|
+
}
|
|
1244
|
+
const rulerPlayhead=document.createElement('span');
|
|
1245
|
+
rulerPlayhead.className='animation-playhead';
|
|
1246
|
+
rulerPlayhead.dataset.playhead='';
|
|
1247
|
+
rulerTrack.append(rulerPlayhead);
|
|
1248
|
+
this.bindRulerScrub(rulerTrack);
|
|
1249
|
+
ruler.append(rulerCorner,rulerTrack);
|
|
1250
|
+
list.append(ruler);
|
|
1251
|
+
|
|
1252
|
+
const matchedSourceIndices=new Set<number>();
|
|
1253
|
+
|
|
1254
|
+
for(const kind of ['bone','slot'] as const){
|
|
77
1255
|
for(const track of tracks.filter(t=>t.kind===kind)){
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
1256
|
+
const trackPointer=track.pointer;
|
|
1257
|
+
const cls=kind==='bone'?clsByBoneProp.get(`${track.target}\0${track.name}`):clss.find(c=>c.targetKind==='slot'&&c.target===track.target&&c.property===track.name);
|
|
1258
|
+
if(cls)matchedSourceIndices.add(cls.trackIndex);
|
|
1259
|
+
const isEditable=gate.editable&&!!cls?.editable;
|
|
1260
|
+
const readonlyReason=!gate.editable
|
|
1261
|
+
?`${gate.code}: ${gate.reason}`
|
|
1262
|
+
:cls&&!cls.editable
|
|
1263
|
+
?`ANIMATION_TRACK_READ_ONLY: ${cls.reason}`
|
|
1264
|
+
:kind==='slot'
|
|
1265
|
+
?`ANIMATION_TRACK_READ_ONLY: slot track "${track.target}.${track.name}" is read-only in v1`
|
|
1266
|
+
:`ANIMATION_TRACK_READ_ONLY: bone track "${track.target}.${track.name}" is not an editable source track in ${this.source?.path??'animations_from'}`;
|
|
1267
|
+
|
|
1268
|
+
const row=document.createElement('div');
|
|
1269
|
+
row.className='animation-lane';
|
|
1270
|
+
row.style.width=rowWidth;
|
|
1271
|
+
row.dataset.track=trackPointer;
|
|
1272
|
+
row.dataset.editable=String(isEditable);
|
|
1273
|
+
if(cls!==undefined)row.dataset.sourceTrack=String(cls.trackIndex);
|
|
1274
|
+
if(!isEditable)row.dataset.readonlyReason=readonlyReason;
|
|
1275
|
+
|
|
1276
|
+
const head=document.createElement('div');
|
|
1277
|
+
head.className='animation-lane-head';
|
|
1278
|
+
head.dataset.laneHead='';
|
|
1279
|
+
|
|
1280
|
+
const label=button(`${track.target} · ${track.name}`,()=>{
|
|
1281
|
+
const liveTrack=this.inspection?.tracks.find(t=>t.pointer===trackPointer)??track;
|
|
1282
|
+
this.track=liveTrack;this.channel=0;this.renderChannels();this.show('curve');
|
|
1283
|
+
});
|
|
1284
|
+
label.className='animation-lane-label';
|
|
1285
|
+
label.title=`${track.target} · ${track.name}`;
|
|
1286
|
+
head.append(label);
|
|
1287
|
+
|
|
1288
|
+
if(isEditable&&cls){
|
|
1289
|
+
const addKeyBtn=button('+ Key',()=>{
|
|
1290
|
+
this.insertKey(cls.trackIndex,this.at);
|
|
1291
|
+
});
|
|
1292
|
+
addKeyBtn.className='animation-lane-add';
|
|
1293
|
+
addKeyBtn.dataset.addKeyTrack=String(cls.trackIndex);
|
|
1294
|
+
addKeyBtn.title=`Insert key on ${track.target} · ${track.name} at playhead (${formatSeconds(this.at)} s)`;
|
|
1295
|
+
head.append(addKeyBtn);
|
|
1296
|
+
}
|
|
1297
|
+
row.append(head);
|
|
1298
|
+
|
|
1299
|
+
const marks=document.createElement('div');
|
|
1300
|
+
marks.className='animation-key-lane';
|
|
1301
|
+
marks.dataset.track=trackPointer;
|
|
1302
|
+
if(!isEditable){
|
|
1303
|
+
marks.onclick=e=>{if(e.target===marks)this.setEditorStatus(readonlyReason,true);};
|
|
1304
|
+
}
|
|
1305
|
+
if(!isEditable&&track.keys.length===0){
|
|
1306
|
+
const badge=document.createElement('span');
|
|
1307
|
+
badge.className='animation-readonly-badge';
|
|
1308
|
+
badge.dataset.readonlyBadge='';
|
|
1309
|
+
badge.textContent=readonlyReason;
|
|
1310
|
+
badge.title=readonlyReason;
|
|
1311
|
+
marks.append(badge);
|
|
1312
|
+
}
|
|
1313
|
+
row.append(marks);
|
|
1314
|
+
|
|
1315
|
+
track.keys.forEach((key,index)=>{
|
|
1316
|
+
const cleanT=formatSeconds(key.time);
|
|
1317
|
+
const mark=button('◆',()=>{
|
|
1318
|
+
if(this.suppressNextKeyClick){
|
|
1319
|
+
this.suppressNextKeyClick=false;
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
const liveTrack=this.inspection?.tracks.find(t=>t.pointer===trackPointer)??track;
|
|
1323
|
+
const liveIdx=Number(mark.dataset.keyIndex??index);
|
|
1324
|
+
const liveKey=liveTrack.keys[liveIdx]??key;
|
|
1325
|
+
this.track=liveTrack;this.channel=0;this.renderChannels();
|
|
1326
|
+
if(isEditable&&cls){
|
|
1327
|
+
this.selectedKey={animation:this.animation,trackIndex:cls.trackIndex,keyIndex:liveIdx,pointer:trackPointer};
|
|
1328
|
+
this.syncTimelineKeysInPlace();
|
|
1329
|
+
this.syncKeyInspectorInPlace();
|
|
1330
|
+
}else{
|
|
1331
|
+
this.setEditorStatus(readonlyReason,true);
|
|
1332
|
+
}
|
|
1333
|
+
if(liveKey.time>=0&&liveKey.time<=this.runtimeDuration){
|
|
1334
|
+
this.options.seek(liveKey.time);
|
|
1335
|
+
}
|
|
1336
|
+
});
|
|
1337
|
+
mark.className='animation-key';
|
|
1338
|
+
const isSelected=isEditable&&cls!==undefined&&this.selectedKey?.animation===this.animation&&this.selectedKey.trackIndex===cls.trackIndex&&this.selectedKey.keyIndex===index;
|
|
1339
|
+
if(isSelected)mark.classList.add('selected');
|
|
1340
|
+
mark.setAttribute('aria-pressed',String(isSelected));
|
|
1341
|
+
Object.assign(mark.dataset,{
|
|
1342
|
+
track:trackPointer,
|
|
1343
|
+
targetKind:kind,
|
|
1344
|
+
target:track.target,
|
|
1345
|
+
timeline:track.name,
|
|
1346
|
+
keyIndex:String(index),
|
|
1347
|
+
keyTime:cleanT,
|
|
1348
|
+
editable:String(isEditable),
|
|
1349
|
+
...(cls!==undefined?{sourceTrack:String(cls.trackIndex)}:{}),
|
|
1350
|
+
});
|
|
1351
|
+
mark.style.left=`${Math.max(0,Math.min(100,key.time/end*100))}%`;
|
|
1352
|
+
mark.title=`${track.target} · ${track.name} · key ${index} · ${cleanT} s${isEditable?' (drag to retime)':' (read-only)'}`;
|
|
1353
|
+
mark.setAttribute('aria-label',mark.title);
|
|
1354
|
+
|
|
1355
|
+
if(isEditable&&cls){
|
|
1356
|
+
this.bindKeyDrag(mark,marks,cls.trackIndex,index,trackPointer);
|
|
1357
|
+
}
|
|
1358
|
+
marks.append(mark);
|
|
1359
|
+
});
|
|
1360
|
+
|
|
1361
|
+
const line=document.createElement('span');
|
|
1362
|
+
line.className='animation-playhead';
|
|
1363
|
+
line.dataset.playhead='';
|
|
1364
|
+
marks.append(line);
|
|
1365
|
+
if(gate.editable&&!isEditable&&track.keys.length>0){
|
|
1366
|
+
row.classList.add('has-readonly-note');
|
|
1367
|
+
const badge=document.createElement('div');
|
|
1368
|
+
badge.className='animation-readonly-badge animation-readonly-subrow';
|
|
1369
|
+
badge.dataset.readonlyBadge='';
|
|
1370
|
+
badge.textContent=readonlyReason;
|
|
1371
|
+
badge.title=readonlyReason;
|
|
1372
|
+
row.append(badge);
|
|
1373
|
+
}
|
|
1374
|
+
list.append(row);
|
|
83
1375
|
}
|
|
84
1376
|
}
|
|
85
|
-
|
|
1377
|
+
|
|
1378
|
+
// Render any additional read-only source tracks from animations_from (e.g. physics, group, path, slider, bone.inherit)
|
|
1379
|
+
const selectedTarget=this.selection.value();
|
|
1380
|
+
const extraReadonly=clss.filter(c=>{
|
|
1381
|
+
if(matchedSourceIndices.has(c.trackIndex))return false;
|
|
1382
|
+
if(!selectedTarget)return true;
|
|
1383
|
+
if(selectedTarget.kind==='bone'&&c.targetKind==='bone'&&c.target===selectedTarget.name)return true;
|
|
1384
|
+
if(selectedTarget.kind==='slot'&&c.targetKind==='slot'&&c.target===selectedTarget.name)return true;
|
|
1385
|
+
return false;
|
|
1386
|
+
});
|
|
1387
|
+
for(const c of extraReadonly){
|
|
1388
|
+
const reason=gate.editable?`ANIMATION_TRACK_READ_ONLY: ${c.reason}`:`${gate.code}: ${gate.reason}`;
|
|
1389
|
+
const row=document.createElement('div');
|
|
1390
|
+
row.className='animation-readonly-lane';
|
|
1391
|
+
row.style.width=rowWidth;
|
|
1392
|
+
row.dataset.sourceTrack=String(c.trackIndex);
|
|
1393
|
+
row.dataset.targetKind=c.targetKind;
|
|
1394
|
+
row.dataset.target=c.target;
|
|
1395
|
+
row.dataset.property=c.property;
|
|
1396
|
+
row.dataset.editable='false';
|
|
1397
|
+
row.dataset.readonlyReason=reason;
|
|
1398
|
+
|
|
1399
|
+
const head=document.createElement('div');
|
|
1400
|
+
head.className='animation-lane-head';
|
|
1401
|
+
head.dataset.laneHead='';
|
|
1402
|
+
const lbl=document.createElement('span');
|
|
1403
|
+
lbl.className='animation-lane-label';
|
|
1404
|
+
lbl.textContent=`${c.targetKind}:${c.target} · ${c.property}`;
|
|
1405
|
+
lbl.title=lbl.textContent;
|
|
1406
|
+
head.append(lbl);
|
|
1407
|
+
|
|
1408
|
+
const trackArea=document.createElement('div');
|
|
1409
|
+
trackArea.className='animation-key-lane readonly-lane-track';
|
|
1410
|
+
const badge=document.createElement('span');
|
|
1411
|
+
badge.className='animation-readonly-badge';
|
|
1412
|
+
badge.dataset.readonlyBadge='';
|
|
1413
|
+
badge.textContent=reason;
|
|
1414
|
+
badge.title=reason;
|
|
1415
|
+
const line=document.createElement('span');
|
|
1416
|
+
line.className='animation-playhead';
|
|
1417
|
+
line.dataset.playhead='';
|
|
1418
|
+
trackArea.append(badge,line);
|
|
1419
|
+
|
|
1420
|
+
row.append(head,trackArea);
|
|
1421
|
+
list.append(row);
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
if(!tracks.length&&!extraReadonly.length){
|
|
1425
|
+
const empty=document.createElement('p');
|
|
1426
|
+
empty.textContent='No stored tracks for this selection.';
|
|
1427
|
+
list.append(empty);
|
|
1428
|
+
}
|
|
1429
|
+
this.syncDockHeight(false);
|
|
1430
|
+
this.placePlayheads();
|
|
1431
|
+
if(prevScrollTop>0)list.scrollTop=prevScrollTop;
|
|
1432
|
+
if(prevScrollLeft>0)list.scrollLeft=prevScrollLeft;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
private bindRulerScrub(rulerTrack:HTMLElement){
|
|
1436
|
+
let scrubbingId:number|null=null;
|
|
1437
|
+
const scrubAt=(clientX:number)=>{
|
|
1438
|
+
const rect=rulerTrack.getBoundingClientRect();
|
|
1439
|
+
if(rect.width<=0)return;
|
|
1440
|
+
const end=this.effectiveEnd();
|
|
1441
|
+
const ratio=Math.max(0,Math.min(1,(clientX-rect.left)/rect.width));
|
|
1442
|
+
const rawTime=cleanMotionNumber(ratio*end);
|
|
1443
|
+
this.at=rawTime;
|
|
1444
|
+
this.placePlayheads();
|
|
1445
|
+
const maxSeek=this.runtimeDuration>0?Math.min(end,this.runtimeDuration):end;
|
|
1446
|
+
const target=cleanMotionNumber(Math.min(maxSeek,rawTime));
|
|
1447
|
+
this.options.seek(target);
|
|
1448
|
+
};
|
|
1449
|
+
rulerTrack.addEventListener('pointerdown',e=>{
|
|
1450
|
+
if(!e.isPrimary||e.button!==0)return;
|
|
1451
|
+
e.preventDefault();
|
|
1452
|
+
e.stopPropagation();
|
|
1453
|
+
scrubbingId=e.pointerId;
|
|
1454
|
+
rulerTrack.setPointerCapture?.(e.pointerId);
|
|
1455
|
+
scrubAt(e.clientX);
|
|
1456
|
+
});
|
|
1457
|
+
rulerTrack.addEventListener('pointermove',e=>{
|
|
1458
|
+
if(scrubbingId!==e.pointerId)return;
|
|
1459
|
+
scrubAt(e.clientX);
|
|
1460
|
+
});
|
|
1461
|
+
const endScrub=(e:PointerEvent)=>{
|
|
1462
|
+
if(scrubbingId!==e.pointerId)return;
|
|
1463
|
+
scrubbingId=null;
|
|
1464
|
+
if(rulerTrack.hasPointerCapture?.(e.pointerId))rulerTrack.releasePointerCapture(e.pointerId);
|
|
1465
|
+
};
|
|
1466
|
+
rulerTrack.addEventListener('pointerup',endScrub);
|
|
1467
|
+
rulerTrack.addEventListener('pointercancel',endScrub);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
private bindKeyDrag(
|
|
1471
|
+
mark:HTMLButtonElement,
|
|
1472
|
+
laneEl:HTMLElement,
|
|
1473
|
+
trackIndex:number,
|
|
1474
|
+
keyIndex:number,
|
|
1475
|
+
trackPointer:string,
|
|
1476
|
+
){
|
|
1477
|
+
mark.addEventListener('pointerdown',e=>{
|
|
1478
|
+
if(!e.isPrimary||e.button!==0||this.isBusy)return;
|
|
1479
|
+
e.preventDefault();
|
|
1480
|
+
e.stopPropagation();
|
|
1481
|
+
this.suppressNextKeyClick=true;
|
|
1482
|
+
// Immediately select the key in place on pointerdown without rebuilding the DOM,
|
|
1483
|
+
// so pressing and dragging an unselected key works in a single gesture with zero layout shift.
|
|
1484
|
+
const liveTrack=this.inspection?.tracks.find(t=>t.pointer===trackPointer)??null;
|
|
1485
|
+
const liveIdx=Number(mark.dataset.keyIndex??keyIndex);
|
|
1486
|
+
if(liveTrack)this.track=liveTrack;
|
|
1487
|
+
this.channel=0;
|
|
1488
|
+
this.selectedKey={animation:this.animation,trackIndex,keyIndex:liveIdx,pointer:trackPointer};
|
|
1489
|
+
this.syncTimelineKeysInPlace();
|
|
1490
|
+
this.syncKeyInspectorInPlace();
|
|
1491
|
+
this.renderChannels();
|
|
1492
|
+
const k=liveTrack?.keys[liveIdx];
|
|
1493
|
+
if(k&&k.time>=0&&k.time<=this.runtimeDuration){
|
|
1494
|
+
this.options.seek(k.time);
|
|
1495
|
+
}
|
|
1496
|
+
this.draggingKey={
|
|
1497
|
+
pointerId:e.pointerId,
|
|
1498
|
+
trackIndex,
|
|
1499
|
+
keyIndex:liveIdx,
|
|
1500
|
+
startX:e.clientX,
|
|
1501
|
+
moved:false,
|
|
1502
|
+
laneEl,
|
|
1503
|
+
markEl:mark,
|
|
1504
|
+
end:this.effectiveEnd(),
|
|
1505
|
+
};
|
|
1506
|
+
mark.setPointerCapture?.(e.pointerId);
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
mark.addEventListener('pointermove',e=>{
|
|
1510
|
+
const drag=this.draggingKey;
|
|
1511
|
+
if(!drag||drag.pointerId!==e.pointerId)return;
|
|
1512
|
+
if(!drag.moved&&Math.abs(e.clientX-drag.startX)<1)return;
|
|
1513
|
+
drag.moved=true;
|
|
1514
|
+
this.selectedKey={animation:this.animation,trackIndex:drag.trackIndex,keyIndex:drag.keyIndex,pointer:trackPointer};
|
|
1515
|
+
const rect=drag.laneEl.getBoundingClientRect();
|
|
1516
|
+
if(rect.width<=0)return;
|
|
1517
|
+
const ratio=Math.max(0,(e.clientX-rect.left)/rect.width);
|
|
1518
|
+
const rawTime=Math.round(ratio*drag.end*10000)/10000;
|
|
1519
|
+
const res=this.applyOp(
|
|
1520
|
+
{op:'set_key_time',animation:this.animation,track:drag.trackIndex,key:drag.keyIndex,time:rawTime},
|
|
1521
|
+
{skipTimelineDomRebuild:true},
|
|
1522
|
+
);
|
|
1523
|
+
if(res.ok&&rawTime>=0&&rawTime<=this.runtimeDuration){
|
|
1524
|
+
this.options.seek(rawTime);
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
|
|
1528
|
+
const finishDrag=(e:PointerEvent)=>{
|
|
1529
|
+
const drag=this.draggingKey;
|
|
1530
|
+
if(!drag||drag.pointerId!==e.pointerId)return;
|
|
1531
|
+
this.draggingKey=null;
|
|
1532
|
+
if(mark.hasPointerCapture?.(e.pointerId))mark.releasePointerCapture(e.pointerId);
|
|
1533
|
+
e.preventDefault();
|
|
1534
|
+
setTimeout(()=>{this.suppressNextKeyClick=false;},0);
|
|
1535
|
+
};
|
|
1536
|
+
mark.addEventListener('pointerup',finishDrag);
|
|
1537
|
+
mark.addEventListener('pointercancel',finishDrag);
|
|
86
1538
|
}
|
|
1539
|
+
|
|
87
1540
|
private renderChannels(){
|
|
88
1541
|
const unsupported=this.track&&(this.track.kind!=='bone'||!CHANNELS[this.track.name])?`${this.track.target} · ${this.track.name} has no numeric curve evaluator`:'';this.unavailableChannel=unsupported;
|
|
89
1542
|
this.channelSelect.replaceChildren();const tracks=this.inspection?filterTracks(this.inspection,this.selection.value()):[];
|
|
@@ -94,36 +1547,329 @@ export class AnimationInspectionPanel {
|
|
|
94
1547
|
else{const first=this.channelSelect.options[0];if(first){const [pointer,c]=JSON.parse(first.value);this.track=tracks.find(t=>t.pointer===pointer)??null;this.channel=c;}else this.track=null;}
|
|
95
1548
|
this.channelSelect.disabled=this.channelSelect.options.length===0;this.renderCurve();this.update(this.at,this.runtimeDuration);
|
|
96
1549
|
}
|
|
1550
|
+
|
|
1551
|
+
private resolveTrackClassification(track:InspectionTrack|null):TrackClassification|undefined{
|
|
1552
|
+
if(!track||track.kind!=='bone')return undefined;
|
|
1553
|
+
return this.tracksInfo().find(c=>c.targetKind==='bone'&&c.target===track.target&&c.property===track.name);
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
private availableEasings():Record<string,EasingTuple>{
|
|
1557
|
+
const out:Record<string,EasingTuple>={...(this.source?.easings??{})};
|
|
1558
|
+
const doc=this.draftDocument() as {easings?:Record<string,unknown>}|undefined;
|
|
1559
|
+
if(doc?.easings&&typeof doc.easings==='object'&&!Array.isArray(doc.easings)){
|
|
1560
|
+
for(const [k,v] of Object.entries(doc.easings)){
|
|
1561
|
+
if(Array.isArray(v)&&v.length===4&&v.every(n=>typeof n==='number'&&Number.isFinite(n))){
|
|
1562
|
+
out[k]=[v[0] as number,v[1] as number,v[2] as number,v[3] as number];
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
return out;
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
private fullSegmentCubic(trackIndex:number,segmentIndex:number):number[]|null{
|
|
1570
|
+
const rawKeys=this.readDraftTrackKeys(trackIndex);
|
|
1571
|
+
const k0=rawKeys[segmentIndex],k1=rawKeys[segmentIndex+1];
|
|
1572
|
+
if(!k0||!k1)return null;
|
|
1573
|
+
const numChannels=k0.v.length;
|
|
1574
|
+
if(Array.isArray(k0.curve)&&k0.curve.length===numChannels*4){
|
|
1575
|
+
return k0.curve.map(n=>cleanMotionNumber(n));
|
|
1576
|
+
}
|
|
1577
|
+
if(typeof k0.ease==='string'&&k0.ease!=='stepped'){
|
|
1578
|
+
const handles=this.availableEasings()[k0.ease];
|
|
1579
|
+
if(handles&&handles.length===4){
|
|
1580
|
+
const [hx1,hy1,hx2,hy2]=handles;
|
|
1581
|
+
const dt=k1.t-k0.t;
|
|
1582
|
+
const out:number[]=[];
|
|
1583
|
+
for(let c=0;c<numChannels;c++){
|
|
1584
|
+
const v1=k0.v[c]!,dv=k1.v[c]!-v1;
|
|
1585
|
+
out.push(
|
|
1586
|
+
cleanMotionNumber(k0.t+dt*hx1),
|
|
1587
|
+
cleanMotionNumber(v1+dv*hy1),
|
|
1588
|
+
cleanMotionNumber(k0.t+dt*hx2),
|
|
1589
|
+
cleanMotionNumber(v1+dv*hy2),
|
|
1590
|
+
);
|
|
1591
|
+
}
|
|
1592
|
+
return out;
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
return seedCubicCurve(k0.t,k0.v,k1.t,k1.v);
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
private applyCurveModeChange(mode:string){
|
|
1599
|
+
const gate=this.gateInfo();
|
|
1600
|
+
const cls=this.resolveTrackClassification(this.track);
|
|
1601
|
+
if(!gate.editable||!cls?.editable){
|
|
1602
|
+
const reason=!gate.editable?`${gate.code}: ${gate.reason}`:cls?`ANIMATION_TRACK_READ_ONLY: ${cls.reason}`:'ANIMATION_TRACK_READ_ONLY: track is read-only';
|
|
1603
|
+
this.setEditorStatus(reason,true);
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
const segIdx=this.curveSegment;
|
|
1607
|
+
if(mode==='linear'){
|
|
1608
|
+
this.setKeyCurve(cls.trackIndex,segIdx,null);
|
|
1609
|
+
}else if(mode==='stepped'){
|
|
1610
|
+
this.setKeyCurve(cls.trackIndex,segIdx,'stepped');
|
|
1611
|
+
}else if(mode==='cubic'){
|
|
1612
|
+
const seeded=this.fullSegmentCubic(cls.trackIndex,segIdx);
|
|
1613
|
+
if(seeded)this.setKeyCurve(cls.trackIndex,segIdx,seeded);
|
|
1614
|
+
}else if(mode.startsWith('ease:')){
|
|
1615
|
+
this.setKeyEase(cls.trackIndex,segIdx,mode.slice(5));
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
private renderCurveControls(
|
|
1620
|
+
t:InspectionTrack|null,
|
|
1621
|
+
segments:ReturnType<typeof channelSegments>,
|
|
1622
|
+
cls:TrackClassification|undefined,
|
|
1623
|
+
trackEditable:boolean,
|
|
1624
|
+
){
|
|
1625
|
+
const gate=this.gateInfo();
|
|
1626
|
+
this.segmentSelect.replaceChildren();
|
|
1627
|
+
this.easeSelect.replaceChildren();
|
|
1628
|
+
if(!t||segments.length===0){
|
|
1629
|
+
const opt=document.createElement('option');
|
|
1630
|
+
opt.value='0';
|
|
1631
|
+
opt.textContent='No segments';
|
|
1632
|
+
this.segmentSelect.append(opt);
|
|
1633
|
+
this.segmentSelect.disabled=true;
|
|
1634
|
+
const eOpt=document.createElement('option');
|
|
1635
|
+
eOpt.value='linear';
|
|
1636
|
+
eOpt.textContent='Linear';
|
|
1637
|
+
this.easeSelect.append(eOpt);
|
|
1638
|
+
this.easeSelect.disabled=true;
|
|
1639
|
+
const reason=!gate.editable
|
|
1640
|
+
?`${gate.code}: ${gate.reason}`
|
|
1641
|
+
:cls&&!cls.editable
|
|
1642
|
+
?`ANIMATION_TRACK_READ_ONLY: ${cls.reason}`
|
|
1643
|
+
:t
|
|
1644
|
+
?'Track has fewer than 2 keys (no curve segments).'
|
|
1645
|
+
:'Select a bone channel.';
|
|
1646
|
+
this.curveReadonly.hidden=false;
|
|
1647
|
+
this.curveReadonly.textContent=reason;
|
|
1648
|
+
this.curveReadonly.title=reason;
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
if(
|
|
1653
|
+
cls&&
|
|
1654
|
+
this.selectedKey?.animation===this.animation&&
|
|
1655
|
+
this.selectedKey.trackIndex===cls.trackIndex&&
|
|
1656
|
+
this.selectedKey.keyIndex>=0&&
|
|
1657
|
+
this.selectedKey.keyIndex<segments.length
|
|
1658
|
+
){
|
|
1659
|
+
this.curveSegment=this.selectedKey.keyIndex;
|
|
1660
|
+
}
|
|
1661
|
+
this.curveSegment=Math.max(0,Math.min(this.curveSegment,segments.length-1));
|
|
1662
|
+
|
|
1663
|
+
segments.forEach((s,idx)=>{
|
|
1664
|
+
const opt=document.createElement('option');
|
|
1665
|
+
opt.value=String(idx);
|
|
1666
|
+
opt.textContent=`#${idx} · ${formatSeconds(s.from[0])}s → ${formatSeconds(s.to[0])}s`;
|
|
1667
|
+
if(idx===this.curveSegment)opt.selected=true;
|
|
1668
|
+
this.segmentSelect.append(opt);
|
|
1669
|
+
});
|
|
1670
|
+
this.segmentSelect.disabled=segments.length<=1;
|
|
1671
|
+
|
|
1672
|
+
const easings=this.availableEasings();
|
|
1673
|
+
const modeOptions:Array<[string,string]>=[
|
|
1674
|
+
['linear','Linear'],
|
|
1675
|
+
['cubic','Cubic Bézier (handles)'],
|
|
1676
|
+
['stepped','Stepped (hold)'],
|
|
1677
|
+
...Object.keys(easings).map((name):[string,string]=>[`ease:${name}`,`Ease: ${name}`]),
|
|
1678
|
+
];
|
|
1679
|
+
for(const [val,label] of modeOptions){
|
|
1680
|
+
const opt=document.createElement('option');
|
|
1681
|
+
opt.value=val;
|
|
1682
|
+
opt.textContent=label;
|
|
1683
|
+
this.easeSelect.append(opt);
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
let currentMode='linear';
|
|
1687
|
+
if(cls){
|
|
1688
|
+
const rawKey=this.readDraftTrackKeys(cls.trackIndex)[this.curveSegment];
|
|
1689
|
+
if(rawKey){
|
|
1690
|
+
if(rawKey.curve==='stepped'||rawKey.ease==='stepped')currentMode='stepped';
|
|
1691
|
+
else if(Array.isArray(rawKey.curve))currentMode='cubic';
|
|
1692
|
+
else if(typeof rawKey.ease==='string'&&rawKey.ease){
|
|
1693
|
+
const eVal=`ease:${rawKey.ease}`;
|
|
1694
|
+
if(![...this.easeSelect.options].some(o=>o.value===eVal)){
|
|
1695
|
+
const extra=document.createElement('option');
|
|
1696
|
+
extra.value=eVal;
|
|
1697
|
+
extra.textContent=`Ease: ${rawKey.ease}`;
|
|
1698
|
+
this.easeSelect.append(extra);
|
|
1699
|
+
}
|
|
1700
|
+
currentMode=eVal;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
}else{
|
|
1704
|
+
const seg=segments[this.curveSegment];
|
|
1705
|
+
if(seg?.curve==='stepped')currentMode='stepped';
|
|
1706
|
+
else if(Array.isArray(seg?.curve))currentMode='cubic';
|
|
1707
|
+
}
|
|
1708
|
+
this.easeSelect.value=currentMode;
|
|
1709
|
+
this.easeSelect.disabled=this.isBusy||!trackEditable;
|
|
1710
|
+
|
|
1711
|
+
if(!trackEditable){
|
|
1712
|
+
const readonlyReason=!gate.editable
|
|
1713
|
+
?`${gate.code}: ${gate.reason}`
|
|
1714
|
+
:cls&&!cls.editable
|
|
1715
|
+
?`ANIMATION_TRACK_READ_ONLY: ${cls.reason}`
|
|
1716
|
+
:`ANIMATION_TRACK_READ_ONLY: bone track "${t.target}.${t.name}" is not an editable source track in ${this.source?.path??'animations_from'}`;
|
|
1717
|
+
this.curveReadonly.hidden=false;
|
|
1718
|
+
this.curveReadonly.textContent=readonlyReason;
|
|
1719
|
+
this.curveReadonly.title=readonlyReason;
|
|
1720
|
+
}else{
|
|
1721
|
+
this.curveReadonly.hidden=true;
|
|
1722
|
+
this.curveReadonly.textContent='';
|
|
1723
|
+
this.curveReadonly.title='';
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
private onCurveHandlePointerDown(e:PointerEvent,target:SVGElement){
|
|
1728
|
+
if(!e.isPrimary||e.button!==0||this.isBusy||this.draggingCurveHandle)return;
|
|
1729
|
+
e.preventDefault();
|
|
1730
|
+
e.stopPropagation();
|
|
1731
|
+
const gate=this.gateInfo();
|
|
1732
|
+
const cls=this.resolveTrackClassification(this.track);
|
|
1733
|
+
const trackEditable=gate.editable&&!!cls?.editable;
|
|
1734
|
+
if(!trackEditable||!cls||!this.track){
|
|
1735
|
+
const reason=!gate.editable
|
|
1736
|
+
?`${gate.code}: ${gate.reason}`
|
|
1737
|
+
:cls&&!cls.editable
|
|
1738
|
+
?`ANIMATION_TRACK_READ_ONLY: ${cls.reason}`
|
|
1739
|
+
:'ANIMATION_TRACK_READ_ONLY: curve handles are read-only on this track';
|
|
1740
|
+
this.setEditorStatus(reason,true);
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
const segIdx=Number(target.dataset.segment??0);
|
|
1744
|
+
const handleIdx=Number(target.dataset.curveHandle)===2?2:1;
|
|
1745
|
+
this.curveSegment=segIdx;
|
|
1746
|
+
this.selectedKey={animation:this.animation,trackIndex:cls.trackIndex,keyIndex:segIdx,pointer:this.track.pointer};
|
|
1747
|
+
this.syncTimelineKeysInPlace();
|
|
1748
|
+
this.syncKeyInspectorInPlace();
|
|
1749
|
+
const field=CHANNELS[this.track.name]?.[this.channel]?.field;
|
|
1750
|
+
if(!field||!this.track.keys.length)return;
|
|
1751
|
+
const segments=channelSegments(this.track,this.channel);
|
|
1752
|
+
const values=this.track.keys.map(k=>k[field] as number);
|
|
1753
|
+
for(const s of segments)if(Array.isArray(s.curve))values.push(s.curve[1]!,s.curve[3]!);
|
|
1754
|
+
const low=Math.min(...values),high=Math.max(...values),span=high-low||1;
|
|
1755
|
+
const end=Math.max(this.runtimeDuration,this.track.keys.at(-1)!.time,Number.MIN_VALUE);
|
|
1756
|
+
this.draggingCurveHandle={
|
|
1757
|
+
pointerId:e.pointerId,
|
|
1758
|
+
trackIndex:cls.trackIndex,
|
|
1759
|
+
segmentIndex:segIdx,
|
|
1760
|
+
handleIndex:handleIdx,
|
|
1761
|
+
channel:this.channel,
|
|
1762
|
+
low,
|
|
1763
|
+
high,
|
|
1764
|
+
span,
|
|
1765
|
+
end,
|
|
1766
|
+
};
|
|
1767
|
+
this.curvePlot.setPointerCapture?.(e.pointerId);
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
private bindCurveHandleDrag(){
|
|
1771
|
+
const svgHost=this.curvePlot;
|
|
1772
|
+
svgHost.addEventListener('pointerdown',e=>{
|
|
1773
|
+
const rawTarget=e.target as (Element&{dataset?:DOMStringMap})|null;
|
|
1774
|
+
const target=rawTarget?.closest?.<SVGElement>('[data-curve-handle]')??(rawTarget?.dataset?.curveHandle?rawTarget as unknown as SVGElement:null);
|
|
1775
|
+
if(target)this.onCurveHandlePointerDown(e,target);
|
|
1776
|
+
});
|
|
1777
|
+
|
|
1778
|
+
svgHost.addEventListener('pointermove',e=>{
|
|
1779
|
+
const drag=this.draggingCurveHandle;
|
|
1780
|
+
if(!drag||drag.pointerId!==e.pointerId)return;
|
|
1781
|
+
const rect=svgHost.getBoundingClientRect();
|
|
1782
|
+
if(rect.width<=0||rect.height<=0)return;
|
|
1783
|
+
const toPlot=svgHost.getScreenCTM()?.inverse();
|
|
1784
|
+
if(!toPlot)return;
|
|
1785
|
+
const svgX=toPlot.a*e.clientX+toPlot.c*e.clientY+toPlot.e;
|
|
1786
|
+
const svgY=toPlot.b*e.clientX+toPlot.d*e.clientY+toPlot.f;
|
|
1787
|
+
const rawT=((svgX-48)/728)*drag.end;
|
|
1788
|
+
const rawV=drag.low+((195-svgY)/160)*drag.span;
|
|
1789
|
+
const rawKeys=this.readDraftTrackKeys(drag.trackIndex);
|
|
1790
|
+
const k0=rawKeys[drag.segmentIndex],k1=rawKeys[drag.segmentIndex+1];
|
|
1791
|
+
if(!k0||!k1)return;
|
|
1792
|
+
const cx=cleanMotionNumber(Math.max(k0.t,Math.min(k1.t,rawT)));
|
|
1793
|
+
const cy=cleanMotionNumber(rawV);
|
|
1794
|
+
const baseCurve=this.fullSegmentCubic(drag.trackIndex,drag.segmentIndex);
|
|
1795
|
+
if(!baseCurve)return;
|
|
1796
|
+
const nextCurve=[...baseCurve];
|
|
1797
|
+
const offset=drag.channel*4+(drag.handleIndex===2?2:0);
|
|
1798
|
+
nextCurve[offset]=cx;
|
|
1799
|
+
nextCurve[offset+1]=cy;
|
|
1800
|
+
this.setKeyCurve(drag.trackIndex,drag.segmentIndex,nextCurve);
|
|
1801
|
+
});
|
|
1802
|
+
|
|
1803
|
+
const endDrag=(e:PointerEvent)=>{
|
|
1804
|
+
const drag=this.draggingCurveHandle;
|
|
1805
|
+
if(!drag||drag.pointerId!==e.pointerId)return;
|
|
1806
|
+
this.draggingCurveHandle=null;
|
|
1807
|
+
if(svgHost.hasPointerCapture?.(e.pointerId))svgHost.releasePointerCapture(e.pointerId);
|
|
1808
|
+
this.renderCurve();
|
|
1809
|
+
};
|
|
1810
|
+
svgHost.addEventListener('pointerup',endDrag);
|
|
1811
|
+
svgHost.addEventListener('pointercancel',endDrag);
|
|
1812
|
+
}
|
|
1813
|
+
|
|
97
1814
|
private renderCurve(){
|
|
98
|
-
const host=this.
|
|
99
|
-
const t=this.track,field=t&&CHANNELS[t.name]?.[this.channel]?.field;
|
|
100
|
-
const
|
|
101
|
-
const
|
|
1815
|
+
const host=this.curvePlot;host.replaceChildren();this.cursor=null;this.plot=null;
|
|
1816
|
+
const t=this.track,field=t&&CHANNELS[t.name]?.[this.channel]?.field;
|
|
1817
|
+
const cls=this.resolveTrackClassification(t);
|
|
1818
|
+
const trackEditable=this.gateInfo().editable&&!!cls?.editable;
|
|
1819
|
+
if(!t||!field||!t.keys.length){
|
|
1820
|
+
this.renderCurveControls(null,[],cls,false);
|
|
1821
|
+
return;
|
|
1822
|
+
}
|
|
1823
|
+
const segments=channelSegments(t,this.channel);
|
|
1824
|
+
this.renderCurveControls(t,segments,cls,trackEditable);
|
|
1825
|
+
const values=t.keys.map(k=>k[field] as number);for(const s of segments)if(Array.isArray(s.curve))values.push(s.curve[1]!,s.curve[3]!);
|
|
1826
|
+
const activeDrag=this.draggingCurveHandle&&cls&&this.draggingCurveHandle.trackIndex===cls.trackIndex&&this.draggingCurveHandle.channel===this.channel?this.draggingCurveHandle:null;
|
|
1827
|
+
const low=activeDrag?activeDrag.low:Math.min(...values);
|
|
1828
|
+
const high=activeDrag?activeDrag.high:Math.max(...values);
|
|
1829
|
+
const span=activeDrag?activeDrag.span:(high-low||1);
|
|
1830
|
+
const end=activeDrag?activeDrag.end:Math.max(this.runtimeDuration,t.keys.at(-1)!.time,Number.MIN_VALUE);
|
|
102
1831
|
const plot=this.plot=(time:number,value:number)=>({x:48+time/end*728,y:195-(value-low)/span*160});
|
|
103
1832
|
host.append(svg('path',{d:'M48 20 V195 H776',class:'animation-axes'}));
|
|
104
|
-
for(const [time,value]of [[0,low],[end,high]]){const n=svg('text',{x:time===0?48:650,y:time===0?220:15});n.textContent=`${time} s · ${value}`;host.append(n);}
|
|
1833
|
+
for(const [time,value]of [[0,low],[end,high]]){const n=svg('text',{x:time===0?48:650,y:time===0?220:15});n.textContent=`${formatSeconds(time)} s · ${formatSeconds(value)}`;host.append(n);}
|
|
105
1834
|
for(const [index,s]of segments.entries()){
|
|
106
1835
|
const a=plot(...s.from),b=plot(...s.to);let d=`M${a.x} ${a.y}`;
|
|
107
1836
|
if(Array.isArray(s.curve)){const c=plot(s.curve[0]!,s.curve[1]!),e=plot(s.curve[2]!,s.curve[3]!);d+=` C${c.x} ${c.y} ${e.x} ${e.y} ${b.x} ${b.y}`;
|
|
108
|
-
|
|
1837
|
+
const hLine=svg('path',{d:`M${a.x} ${a.y} L${c.x} ${c.y} M${b.x} ${b.y} L${e.x} ${e.y}`,class:'animation-handles'});
|
|
1838
|
+
hLine.dataset.handleLines=String(index);
|
|
1839
|
+
host.append(hLine);
|
|
1840
|
+
for(const [hIdx,p] of [[1,c],[2,e]] as const){
|
|
1841
|
+
const hCircle=svg('circle',{cx:p.x,cy:p.y,r:trackEditable?5:3,class:`animation-handle${index===this.curveSegment?' active':''}`});
|
|
1842
|
+
hCircle.dataset.curveHandle=String(hIdx);
|
|
1843
|
+
hCircle.dataset.segment=String(index);
|
|
1844
|
+
hCircle.dataset.editable=String(trackEditable);
|
|
1845
|
+
hCircle.addEventListener('pointerdown',e=>this.onCurveHandlePointerDown(e as PointerEvent,hCircle));
|
|
1846
|
+
host.append(hCircle);
|
|
1847
|
+
}
|
|
109
1848
|
}else d+=s.curve==='stepped'?` H${b.x} V${b.y}`:` L${b.x} ${b.y}`;
|
|
110
1849
|
const path=svg('path',{d,class:'animation-curve'});path.dataset.segment=String(index);path.dataset.stored=JSON.stringify(s);host.append(path);
|
|
111
1850
|
}
|
|
112
1851
|
for(const k of t.keys){const p=plot(k.time,k[field] as number);host.append(svg('circle',{cx:p.x,cy:p.y,r:3,class:'animation-curve-key'}));}
|
|
113
1852
|
this.cursor=svg('circle',{r:5,class:'animation-runtime-cursor'});host.append(this.cursor);
|
|
114
1853
|
}
|
|
1854
|
+
|
|
115
1855
|
update(time:number,duration:number){
|
|
116
|
-
this.at=time;this.runtimeDuration=duration;const timeInput=this.options.host.querySelector<HTMLInputElement>('[data-curve-time]')!;timeInput.max=String(duration);if(document.activeElement!==timeInput)timeInput.value=String(time)
|
|
1856
|
+
this.at=time;this.runtimeDuration=duration;const timeInput=this.options.host.querySelector<HTMLInputElement>('[data-curve-time]')!;timeInput.max=String(formatSeconds(duration));if(document.activeElement!==timeInput)timeInput.value=String(formatSeconds(time));
|
|
1857
|
+
const insertTimeInput=this.options.host.querySelector<HTMLInputElement>('[data-insert-time]');
|
|
1858
|
+
if(insertTimeInput&&document.activeElement!==insertTimeInput)insertTimeInput.value=String(cleanMotionNumber(time));
|
|
1859
|
+
this.placePlayheads();const t=this.track,c=t&&CHANNELS[t.name]?.[this.channel];this.readout.textContent=`Runtime evaluation unavailable: ${this.unavailableChannel||'select a numeric stored channel'}.`;for(const key of ['time','channelValue','localValue','bone','property'])delete this.readout.dataset[key];
|
|
117
1860
|
if(!t||!c||!this.inspection)return;
|
|
118
1861
|
const value=evaluateStoredChannel(t,this.channel,time),local=evaluateBoneLocals(this.inspection,t.target,time)[c.local];
|
|
119
1862
|
Object.assign(this.readout.dataset,{time:String(time),channelValue:value===null?'setup':numeric(value),localValue:numeric(local),bone:t.target,property:c.local});
|
|
120
|
-
this.readout.textContent=`Runtime evaluation · ${time} s · ${c.local} track: ${value===null?'before first key (setup)':numeric(value)} · authored local: ${numeric(local)}`;
|
|
1863
|
+
this.readout.textContent=`Runtime evaluation · ${formatSeconds(time)} s · ${c.local} track: ${value===null?'before first key (setup)':numeric(value)} · authored local: ${numeric(local)}`;
|
|
121
1864
|
if(this.cursor&&this.plot){this.cursor.setAttribute('visibility',value===null?'hidden':'visible');if(value!==null){const p=this.plot(time,value);this.cursor.setAttribute('cx',String(p.x));this.cursor.setAttribute('cy',String(p.y));}}
|
|
122
1865
|
}
|
|
123
|
-
|
|
1866
|
+
|
|
1867
|
+
private placePlayheads(){const end=this.effectiveEnd();for(const n of this.options.host.querySelectorAll<HTMLElement>('[data-playhead]'))n.style.left=`${Math.max(0,Math.min(100,this.at/end*100))}%`;}
|
|
1868
|
+
|
|
124
1869
|
capture(player:Pick<RigPlayer,'bone'>|null,frame:PosedFrame|undefined){
|
|
125
1870
|
this.frame=frame??null;this.bones.clear();for(const b of player&&frame?this.inspection?.bones??[]:[]){try{const p=player!.bone(b.name);if(p.active)this.bones.set(b.name,{x:p.x,y:p.y});}catch{/* unavailable bones have no stage handle */}}this.redraw();
|
|
126
1871
|
}
|
|
1872
|
+
|
|
127
1873
|
redraw(bonePoints=this.bonePoints){
|
|
128
1874
|
this.bonePoints=bonePoints;
|
|
129
1875
|
for(const [name,node]of this.boneButtons)if(!this.bones.has(name)){node.remove();this.boneButtons.delete(name);}
|
|
@@ -132,5 +1878,6 @@ export class AnimationInspectionPanel {
|
|
|
132
1878
|
b.style.zIndex=String(order++);const at=this.options.project(p.x,p.y);b.style.left=`${at.x}px`;b.style.top=`${at.y}px`;b.hidden=!bonePoints&&!(selected?.kind==='bone'&&selected.name===name);b.setAttribute('aria-pressed',String(selected?.kind==='bone'&&selected.name===name));
|
|
133
1879
|
}
|
|
134
1880
|
}
|
|
1881
|
+
|
|
135
1882
|
dispose(){for(const dispose of this.disposers)dispose();this.picks.remove();}
|
|
136
1883
|
}
|