@rig-c/review 0.21.0 → 0.22.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 +4 -0
- package/docs/PANELS.md +1 -1
- package/package.json +1 -1
- package/src/animation-ops.ts +406 -52
- package/web/animation-inspection.ts +1031 -35
- package/web/compare-picked-tools.ts +435 -154
- package/web/compare.css +25 -24
- package/web/main.ts +9 -0
- package/web/styles.css +28 -17
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
checkAnimationEditGate,
|
|
17
17
|
classifyAnimationTracks,
|
|
18
18
|
cleanMotionNumber,
|
|
19
|
+
findBoneConstraint,
|
|
19
20
|
MAX_ANIMATION_OPS,
|
|
20
21
|
overlayDraftOnInspection,
|
|
21
22
|
seedCubicCurve,
|
|
@@ -32,7 +33,7 @@ import {animationPreviewAdjust} from './preview.ts';
|
|
|
32
33
|
const NS='http://www.w3.org/2000/svg';
|
|
33
34
|
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;};
|
|
34
35
|
const numeric=(value:number)=>Object.is(value,-0)?'-0':String(value);
|
|
35
|
-
const button=(label:string,click:()=>void)=>{const b=document.createElement('button');b.type='button';b.textContent=label;b.onclick=click;return b;};
|
|
36
|
+
const button=(label:string,click:(e?:MouseEvent)=>void)=>{const b=document.createElement('button');b.type='button';b.textContent=label;b.onclick=click;return b;};
|
|
36
37
|
|
|
37
38
|
/** Clean human-readable seconds without Float32 noise (e.g. 1.6 instead of 1.600000023841858). */
|
|
38
39
|
export function formatSeconds(value:number):string {
|
|
@@ -67,7 +68,7 @@ export interface AnimationPanelOptions {
|
|
|
67
68
|
apply?:(ops:readonly AnimationSourceOp[])=>Promise<unknown>;
|
|
68
69
|
reset?:()=>Promise<void>;
|
|
69
70
|
pause?:()=>void;
|
|
70
|
-
readOnlyReason?:string|null;
|
|
71
|
+
readOnlyReason?:string|null|(()=>string|null);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
export interface SelectedAnimationKey {
|
|
@@ -77,6 +78,23 @@ export interface SelectedAnimationKey {
|
|
|
77
78
|
pointer:string;
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
export interface AnimationSideState {
|
|
82
|
+
document?:unknown;
|
|
83
|
+
animation?:string;
|
|
84
|
+
baseInspection?:AnimationInspection|null;
|
|
85
|
+
source:AnimationSourceView|null;
|
|
86
|
+
sourceLoaded:boolean;
|
|
87
|
+
sourceFallbackReason:string|null;
|
|
88
|
+
builder:AnimationOpBuilder|null;
|
|
89
|
+
appliedOps:AnimationSourceOp[];
|
|
90
|
+
selectedKey:SelectedAnimationKey|null;
|
|
91
|
+
selectedKeys:SelectedAnimationKey[];
|
|
92
|
+
editorStatus:{text:string;error:boolean};
|
|
93
|
+
poseMode:'rotate'|'translate';
|
|
94
|
+
poseModeLockedByUser:boolean;
|
|
95
|
+
zoom:number;
|
|
96
|
+
}
|
|
97
|
+
|
|
80
98
|
/** All picking reads the last drawn primitives, including their resolved clip; never a setup bounding box. */
|
|
81
99
|
export function pickedSlot(frame:PosedFrame,x:number,y:number):string|null {
|
|
82
100
|
const inside=(p:readonly number[])=>{let hit=false;for(let i=0,j=p.length-2;i<p.length;j=i,i+=2){const ax=p[i]!,ay=p[i+1]!,bx=p[j]!,by=p[j+1]!;if((ay>y)!==(by>y)&&x<(bx-ax)*(y-ay)/(by-ay)+ax)hit=!hit;}return hit;};
|
|
@@ -101,11 +119,14 @@ export class AnimationInspectionPanel {
|
|
|
101
119
|
private channel=0;
|
|
102
120
|
private view='timeline';
|
|
103
121
|
private zoom=1;
|
|
122
|
+
private poseMode:'rotate'|'translate'='rotate';
|
|
123
|
+
private poseModeLockedByUser=false;
|
|
104
124
|
private unavailableChannel='';
|
|
105
125
|
private selection:InspectionSelection;
|
|
106
126
|
private panes=new Map<string,HTMLElement>();
|
|
107
127
|
private views:HTMLButtonElement[]=[];
|
|
108
128
|
private zoomButtons:HTMLButtonElement[]=[];
|
|
129
|
+
private poseModeButtons:HTMLButtonElement[]=[];
|
|
109
130
|
private playhead:SVGElement|null=null;
|
|
110
131
|
private cursor:SVGElement|null=null;
|
|
111
132
|
private plot:((t:number,v:number)=>{x:number;y:number})|null=null;
|
|
@@ -127,7 +148,7 @@ export class AnimationInspectionPanel {
|
|
|
127
148
|
private applyNote:HTMLElement;
|
|
128
149
|
private editorStatus:HTMLElement;
|
|
129
150
|
private picks:HTMLElement;
|
|
130
|
-
private bones=new Map<string,{x:number;y:number}>();
|
|
151
|
+
private bones=new Map<string,{x:number;y:number;a:number;b:number;c:number;d:number;hasMatrix:boolean}>();
|
|
131
152
|
private frame:PosedFrame|null=null;
|
|
132
153
|
private down:{x:number;y:number}|null=null;
|
|
133
154
|
private space=false;
|
|
@@ -135,16 +156,25 @@ export class AnimationInspectionPanel {
|
|
|
135
156
|
private boneButtons=new Map<string,HTMLButtonElement>();
|
|
136
157
|
private bonePoints=false;
|
|
137
158
|
|
|
138
|
-
// Keyed animation editing state (Slice 3 / Slice 3b / Slice 4a)
|
|
159
|
+
// Keyed animation editing state (Slice 3 / Slice 3b / Slice 4a / Slice 4b / Slice 4c)
|
|
139
160
|
private source:AnimationSourceView|null=null;
|
|
140
161
|
private sourceLoaded=false;
|
|
141
162
|
private sourceFallbackReason:string|null=null;
|
|
142
163
|
private builder:AnimationOpBuilder|null=null;
|
|
143
164
|
private appliedOps:AnimationSourceOp[]=[];
|
|
165
|
+
private cachedDraftText:string|null=null;
|
|
166
|
+
private cachedDraftDoc:unknown=undefined;
|
|
167
|
+
private cachedTracksKey='';
|
|
168
|
+
private cachedTracks:TrackClassification[]=[];
|
|
169
|
+
private cachedGateKey='';
|
|
170
|
+
private cachedGate:AnimationEditGate|null=null;
|
|
144
171
|
private selectedKey:SelectedAnimationKey|null=null;
|
|
172
|
+
private selectedKeys:SelectedAnimationKey[]=[];
|
|
145
173
|
private lastNonEmptyAnimation='';
|
|
174
|
+
private forceNextModelReload=false;
|
|
146
175
|
private isBusy=false;
|
|
147
176
|
private suppressNextKeyClick=false;
|
|
177
|
+
private suppressNextBoneClick=false;
|
|
148
178
|
private lastDockClientHeight=0;
|
|
149
179
|
private lastLanesHeight=186;
|
|
150
180
|
private draggingKey:{
|
|
@@ -153,6 +183,8 @@ export class AnimationInspectionPanel {
|
|
|
153
183
|
keyIndex:number;
|
|
154
184
|
startX:number;
|
|
155
185
|
moved:boolean;
|
|
186
|
+
wasAlreadyInMulti:boolean;
|
|
187
|
+
undoGroupId:number;
|
|
156
188
|
laneEl:HTMLElement;
|
|
157
189
|
markEl:HTMLButtonElement;
|
|
158
190
|
end:number;
|
|
@@ -163,11 +195,23 @@ export class AnimationInspectionPanel {
|
|
|
163
195
|
segmentIndex:number;
|
|
164
196
|
handleIndex:1|2;
|
|
165
197
|
channel:number;
|
|
198
|
+
undoGroupId:number;
|
|
166
199
|
low:number;
|
|
167
200
|
high:number;
|
|
168
201
|
span:number;
|
|
169
202
|
end:number;
|
|
170
203
|
}|null=null;
|
|
204
|
+
private draggingStageBone:{
|
|
205
|
+
pointerId:number;
|
|
206
|
+
boneName:string;
|
|
207
|
+
mode:'rotate'|'translate';
|
|
208
|
+
startX:number;
|
|
209
|
+
startY:number;
|
|
210
|
+
moved:boolean;
|
|
211
|
+
undoGroupId:number;
|
|
212
|
+
originWorld:{x:number;y:number};
|
|
213
|
+
parentWorld:{x:number;y:number;a:number;b:number;c:number;d:number};
|
|
214
|
+
}|null=null;
|
|
171
215
|
|
|
172
216
|
constructor(private options:AnimationPanelOptions){
|
|
173
217
|
const {host,stage}=options;
|
|
@@ -176,6 +220,7 @@ export class AnimationInspectionPanel {
|
|
|
176
220
|
<h3 class="animation-dock-title">Animation timeline & inspection</h3>
|
|
177
221
|
<div class="animation-view-buttons" aria-label="Animation inspection views"></div>
|
|
178
222
|
<div class="animation-zoom-buttons" role="group" aria-label="Timeline horizontal zoom"></div>
|
|
223
|
+
<div class="animation-pose-buttons" role="group" aria-label="Stage bone pose mode"></div>
|
|
179
224
|
<div class="animation-editor-bar" data-animation-editor-bar>
|
|
180
225
|
<div class="animation-editor-actions">
|
|
181
226
|
<span class="animation-preview-badge" data-animation-preview-badge hidden>preview — Apply decides</span>
|
|
@@ -252,6 +297,20 @@ export class AnimationInspectionPanel {
|
|
|
252
297
|
this.zoomButtons.push(zb);
|
|
253
298
|
}
|
|
254
299
|
}
|
|
300
|
+
const poseHost=host.querySelector('.animation-pose-buttons');
|
|
301
|
+
if(poseHost){
|
|
302
|
+
for(const [mode,label,tip] of [
|
|
303
|
+
['rotate','Rotate','Drag bone handles on stage to rotate (hold Alt during drag to translate)'],
|
|
304
|
+
['translate','Move','Drag bone handles on stage to translate (hold Alt during drag to rotate)'],
|
|
305
|
+
] as const){
|
|
306
|
+
const pb=button(label,()=>this.setStagePoseMode(mode,true));
|
|
307
|
+
pb.dataset.stagePoseMode=mode;
|
|
308
|
+
pb.setAttribute('aria-pressed',String(mode===this.poseMode));
|
|
309
|
+
pb.title=tip;
|
|
310
|
+
poseHost.append(pb);
|
|
311
|
+
this.poseModeButtons.push(pb);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
255
314
|
this.selection=new InspectionSelection(value=>{options.select(value);this.renderSelection();});
|
|
256
315
|
host.querySelector<HTMLButtonElement>('[data-curve-seek]')!.onclick=()=>{const value=host.querySelector<HTMLInputElement>('[data-curve-time]')!.value.trim();options.seek(value?Number(value):NaN);};
|
|
257
316
|
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);};
|
|
@@ -259,7 +318,9 @@ export class AnimationInspectionPanel {
|
|
|
259
318
|
this.curveSegment=Math.max(0,Number(this.segmentSelect.value)||0);
|
|
260
319
|
const cls=this.resolveTrackClassification(this.track);
|
|
261
320
|
if(this.gateInfo().editable&&cls?.editable&&this.track){
|
|
262
|
-
|
|
321
|
+
const sel={animation:this.animation,trackIndex:cls.trackIndex,keyIndex:this.curveSegment,pointer:this.track.pointer};
|
|
322
|
+
this.selectedKey=sel;
|
|
323
|
+
this.selectedKeys=[sel];
|
|
263
324
|
this.syncTimelineKeysInPlace();
|
|
264
325
|
this.syncKeyInspectorInPlace();
|
|
265
326
|
}
|
|
@@ -272,7 +333,24 @@ export class AnimationInspectionPanel {
|
|
|
272
333
|
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;
|
|
273
334
|
const rect=stage.getBoundingClientRect(),p0=options.project(0,0),px=options.project(1,0),py=options.project(0,1),x=(e.clientX-rect.left-p0.x)/(px.x-p0.x),y=(e.clientY-rect.top-p0.y)/(py.y-p0.y),slot=pickedSlot(this.frame,x,y);if(slot)this.select({kind:'slot',name:slot});
|
|
274
335
|
};
|
|
275
|
-
const key=(e:KeyboardEvent)=>{
|
|
336
|
+
const key=(e:KeyboardEvent)=>{
|
|
337
|
+
if(e.code==='Space')this.space=e.type==='keydown';
|
|
338
|
+
if(e.type==='keydown'&&(e.key==='Delete'||e.key==='Backspace')&&!this.isBusy){
|
|
339
|
+
const active=document.activeElement as Element|null;
|
|
340
|
+
const inField=active&&typeof active.closest==='function'&&active.closest('input,textarea,select');
|
|
341
|
+
const inHost=active&&typeof this.options.host.contains==='function'&&this.options.host.contains(active);
|
|
342
|
+
if(!inField&&inHost){
|
|
343
|
+
if(this.selectedKeys.length>1){
|
|
344
|
+
e.preventDefault();
|
|
345
|
+
this.deleteSelection();
|
|
346
|
+
}else if(this.selectedKey&&this.selectedKey.animation===this.animation){
|
|
347
|
+
e.preventDefault();
|
|
348
|
+
this.deleteKey(this.selectedKey.trackIndex,this.selectedKey.keyIndex);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
const blur=()=>{this.space=false;this.down=null;};
|
|
276
354
|
stage.addEventListener('pointerdown',down);stage.addEventListener('pointerup',up);window.addEventListener('keydown',key);window.addEventListener('keyup',key);window.addEventListener('blur',blur);
|
|
277
355
|
this.disposers.push(()=>{stage.removeEventListener('pointerdown',down);stage.removeEventListener('pointerup',up);window.removeEventListener('keydown',key);window.removeEventListener('keyup',key);window.removeEventListener('blur',blur);});
|
|
278
356
|
|
|
@@ -289,6 +367,122 @@ export class AnimationInspectionPanel {
|
|
|
289
367
|
this.renderEditorBar();
|
|
290
368
|
}
|
|
291
369
|
|
|
370
|
+
stagePoseMode():'rotate'|'translate'{
|
|
371
|
+
return this.poseMode;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
setStagePoseMode(mode:'rotate'|'translate',lockedByUser=true){
|
|
375
|
+
if(mode!=='rotate'&&mode!=='translate')return;
|
|
376
|
+
this.poseMode=mode;
|
|
377
|
+
if(lockedByUser)this.poseModeLockedByUser=true;
|
|
378
|
+
for(const pb of this.poseModeButtons){
|
|
379
|
+
pb.setAttribute('aria-pressed',String(pb.dataset.stagePoseMode===this.poseMode));
|
|
380
|
+
}
|
|
381
|
+
this.redraw();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
private isBoneEditableInMode(boneName:string,mode:'rotate'|'translate'=this.poseMode):boolean{
|
|
385
|
+
if(!this.gateInfo().editable)return false;
|
|
386
|
+
const props=mode==='rotate'?['rotate']:['translate','translatex','translatey'];
|
|
387
|
+
return this.tracksInfo().some(
|
|
388
|
+
c=>c.targetKind==='bone'&&c.target===boneName&&c.editable&&props.includes(c.property),
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
private firstEditableTrackIndexForBone(boneName:string,mode:'rotate'|'translate'=this.poseMode):number{
|
|
393
|
+
const props=mode==='rotate'?['rotate']:['translate','translatex','translatey'];
|
|
394
|
+
const hit=this.tracksInfo().find(
|
|
395
|
+
c=>c.targetKind==='bone'&&c.target===boneName&&c.editable&&props.includes(c.property),
|
|
396
|
+
);
|
|
397
|
+
return hit?hit.trackIndex:Number.MAX_SAFE_INTEGER;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
private overlappingBonesFor(boneName:string,maxScreenDistPx:number):string[]{
|
|
401
|
+
const origin=this.bones.get(boneName);
|
|
402
|
+
if(!origin)return [boneName];
|
|
403
|
+
const originScreen=this.options.project(origin.x,origin.y);
|
|
404
|
+
const btn=this.boneButtons.get(boneName);
|
|
405
|
+
const hasRealDomLayout=(btn?.getBoundingClientRect?.().width??0)>0;
|
|
406
|
+
const out:string[]=[];
|
|
407
|
+
for(const [name,p] of this.bones){
|
|
408
|
+
const worldDist=Math.hypot(p.x-origin.x,p.y-origin.y);
|
|
409
|
+
if(worldDist<=1e-3){
|
|
410
|
+
out.push(name);
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if(hasRealDomLayout&&maxScreenDistPx>0){
|
|
414
|
+
const sc=this.options.project(p.x,p.y);
|
|
415
|
+
if(Math.hypot(sc.x-originScreen.x,sc.y-originScreen.y)<=maxScreenDistPx){
|
|
416
|
+
out.push(name);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return out.length>0?out:[boneName];
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private sortOverlappingBones(candidates:readonly string[],mode:'rotate'|'translate'=this.poseMode):string[]{
|
|
424
|
+
const otherMode:'rotate'|'translate'=mode==='rotate'?'translate':'rotate';
|
|
425
|
+
const boneOrder=new Map((this.inspection?.bones??[]).map((b,i)=>[b.name,i]));
|
|
426
|
+
return [...candidates].sort((a,b)=>{
|
|
427
|
+
const aEdit=this.isBoneEditableInMode(a,mode);
|
|
428
|
+
const bEdit=this.isBoneEditableInMode(b,mode);
|
|
429
|
+
if(aEdit!==bEdit)return aEdit?-1:1;
|
|
430
|
+
if(aEdit&&bEdit){
|
|
431
|
+
const ta=this.firstEditableTrackIndexForBone(a,mode);
|
|
432
|
+
const tb=this.firstEditableTrackIndexForBone(b,mode);
|
|
433
|
+
if(ta!==tb)return ta-tb;
|
|
434
|
+
}
|
|
435
|
+
const aOther=this.isBoneEditableInMode(a,otherMode);
|
|
436
|
+
const bOther=this.isBoneEditableInMode(b,otherMode);
|
|
437
|
+
if(aOther!==bOther)return aOther?-1:1;
|
|
438
|
+
return (boneOrder.get(a)??0)-(boneOrder.get(b)??0);
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
private resolveBoneForStageDrag(boneName:string,mode:'rotate'|'translate'=this.poseMode):string{
|
|
443
|
+
const selected=this.selection.value();
|
|
444
|
+
const exactGroup=this.overlappingBonesFor(boneName,2);
|
|
445
|
+
const editableExact=this.sortOverlappingBones(
|
|
446
|
+
exactGroup.filter(n=>this.isBoneEditableInMode(n,mode)),
|
|
447
|
+
mode,
|
|
448
|
+
);
|
|
449
|
+
if(editableExact.length>0){
|
|
450
|
+
if(selected?.kind==='bone'&&editableExact.includes(selected.name)){
|
|
451
|
+
return selected.name;
|
|
452
|
+
}
|
|
453
|
+
return editableExact[0]!;
|
|
454
|
+
}
|
|
455
|
+
const hitboxGroup=this.overlappingBonesFor(boneName,12);
|
|
456
|
+
const editableNearby=this.sortOverlappingBones(
|
|
457
|
+
hitboxGroup.filter(n=>this.isBoneEditableInMode(n,mode)),
|
|
458
|
+
mode,
|
|
459
|
+
);
|
|
460
|
+
if(editableNearby.length>0){
|
|
461
|
+
if(selected?.kind==='bone'&&editableNearby.includes(selected.name)){
|
|
462
|
+
return selected.name;
|
|
463
|
+
}
|
|
464
|
+
return editableNearby[0]!;
|
|
465
|
+
}
|
|
466
|
+
return boneName;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
private resolveBoneForStageClick(boneName:string):string{
|
|
470
|
+
const group=this.overlappingBonesFor(boneName,2);
|
|
471
|
+
const candidates=group.length>1?group:this.overlappingBonesFor(boneName,10);
|
|
472
|
+
if(candidates.length<=1)return boneName;
|
|
473
|
+
const ordered=this.sortOverlappingBones(candidates,this.poseMode);
|
|
474
|
+
const selected=this.selection.value();
|
|
475
|
+
const curIdx=selected?.kind==='bone'?ordered.indexOf(selected.name):-1;
|
|
476
|
+
if(curIdx<0)return ordered[0]!;
|
|
477
|
+
return ordered[(curIdx+1)%ordered.length]!;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
private autoSyncPoseModeFromProperty(property:string|undefined){
|
|
481
|
+
if(this.poseModeLockedByUser||!property)return;
|
|
482
|
+
if(property==='rotate')this.setStagePoseMode('rotate',false);
|
|
483
|
+
else if(property==='translate'||property==='translatex'||property==='translatey')this.setStagePoseMode('translate',false);
|
|
484
|
+
}
|
|
485
|
+
|
|
292
486
|
zoomLevel():number{
|
|
293
487
|
return this.zoom;
|
|
294
488
|
}
|
|
@@ -333,12 +527,74 @@ export class AnimationInspectionPanel {
|
|
|
333
527
|
this.builder=null;
|
|
334
528
|
this.appliedOps=[];
|
|
335
529
|
this.selectedKey=null;
|
|
530
|
+
this.selectedKeys=[];
|
|
336
531
|
this.syncEffectiveInspection(false);
|
|
337
532
|
this.renderGateBanner();
|
|
338
533
|
this.renderEditorBar();
|
|
339
534
|
this.renderSelection();
|
|
340
535
|
}
|
|
341
536
|
|
|
537
|
+
exportSideState():AnimationSideState{
|
|
538
|
+
return {
|
|
539
|
+
document:this.document,
|
|
540
|
+
animation:this.animation,
|
|
541
|
+
baseInspection:this.baseInspection,
|
|
542
|
+
source:this.source,
|
|
543
|
+
sourceLoaded:this.sourceLoaded,
|
|
544
|
+
sourceFallbackReason:this.sourceFallbackReason,
|
|
545
|
+
builder:this.builder,
|
|
546
|
+
appliedOps:this.appliedOps.map(o=>structuredClone(o)),
|
|
547
|
+
selectedKey:this.selectedKey?{...this.selectedKey}:null,
|
|
548
|
+
selectedKeys:this.selectedKeys.map(k=>({...k})),
|
|
549
|
+
editorStatus:{
|
|
550
|
+
text:this.editorStatus.textContent??'',
|
|
551
|
+
error:this.editorStatus.classList.contains('error'),
|
|
552
|
+
},
|
|
553
|
+
poseMode:this.poseMode,
|
|
554
|
+
poseModeLockedByUser:this.poseModeLockedByUser,
|
|
555
|
+
zoom:this.zoom,
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
importSideState(state:AnimationSideState|null){
|
|
560
|
+
this.draggingKey=null;
|
|
561
|
+
this.draggingCurveHandle=null;
|
|
562
|
+
this.draggingStageBone=null;
|
|
563
|
+
this.forceNextModelReload=true;
|
|
564
|
+
if(!state){
|
|
565
|
+
this.document=null;
|
|
566
|
+
this.baseInspection=null;
|
|
567
|
+
this.inspection=null;
|
|
568
|
+
this.source=null;
|
|
569
|
+
this.sourceLoaded=false;
|
|
570
|
+
this.sourceFallbackReason=null;
|
|
571
|
+
this.builder=null;
|
|
572
|
+
this.appliedOps=[];
|
|
573
|
+
this.selectedKey=null;
|
|
574
|
+
this.selectedKeys=[];
|
|
575
|
+
this.setEditorStatus('',false);
|
|
576
|
+
}else{
|
|
577
|
+
this.document=state.document??null;
|
|
578
|
+
if(state.animation!==undefined)this.animation=state.animation;
|
|
579
|
+
this.baseInspection=state.baseInspection??null;
|
|
580
|
+
this.inspection=this.baseInspection;
|
|
581
|
+
this.source=state.source;
|
|
582
|
+
this.sourceLoaded=state.sourceLoaded;
|
|
583
|
+
this.sourceFallbackReason=state.sourceFallbackReason;
|
|
584
|
+
this.builder=state.builder;
|
|
585
|
+
this.appliedOps=state.appliedOps.map(o=>structuredClone(o));
|
|
586
|
+
this.selectedKey=state.selectedKey?{...state.selectedKey}:null;
|
|
587
|
+
this.selectedKeys=state.selectedKeys.map(k=>({...k}));
|
|
588
|
+
this.setEditorStatus(state.editorStatus.text,state.editorStatus.error);
|
|
589
|
+
this.setStagePoseMode(state.poseMode,state.poseModeLockedByUser);
|
|
590
|
+
this.setZoom(state.zoom);
|
|
591
|
+
}
|
|
592
|
+
this.syncEffectiveInspection(true);
|
|
593
|
+
this.renderGateBanner();
|
|
594
|
+
this.renderEditorBar();
|
|
595
|
+
this.renderSelection();
|
|
596
|
+
}
|
|
597
|
+
|
|
342
598
|
loadSource(source:AnimationSourceView|null,fallbackReason:string|null=null){
|
|
343
599
|
this.sourceLoaded=true;
|
|
344
600
|
this.source=source;
|
|
@@ -355,6 +611,7 @@ export class AnimationInspectionPanel {
|
|
|
355
611
|
this.builder=null;
|
|
356
612
|
this.appliedOps=[];
|
|
357
613
|
this.selectedKey=null;
|
|
614
|
+
this.selectedKeys=[];
|
|
358
615
|
}
|
|
359
616
|
this.syncEffectiveInspection(false);
|
|
360
617
|
this.renderGateBanner();
|
|
@@ -363,9 +620,11 @@ export class AnimationInspectionPanel {
|
|
|
363
620
|
}
|
|
364
621
|
|
|
365
622
|
model(doc:unknown,animation:string){
|
|
366
|
-
if(this.document===doc&&this.animation===animation)return;
|
|
623
|
+
if(!this.forceNextModelReload&&this.document===doc&&this.animation===animation)return;
|
|
624
|
+
this.forceNextModelReload=false;
|
|
367
625
|
if(animation&&this.lastNonEmptyAnimation&&this.lastNonEmptyAnimation!==animation){
|
|
368
626
|
this.selectedKey=null;
|
|
627
|
+
this.selectedKeys=[];
|
|
369
628
|
this.setEditorStatus('',false);
|
|
370
629
|
}
|
|
371
630
|
if(animation)this.lastNonEmptyAnimation=animation;
|
|
@@ -400,7 +659,11 @@ export class AnimationInspectionPanel {
|
|
|
400
659
|
|
|
401
660
|
private draftDocument():unknown{
|
|
402
661
|
if(!this.builder)return undefined;
|
|
403
|
-
|
|
662
|
+
const text=this.builder.text;
|
|
663
|
+
if(text===this.cachedDraftText)return this.cachedDraftDoc;
|
|
664
|
+
this.cachedDraftText=text;
|
|
665
|
+
try{this.cachedDraftDoc=JSON.parse(text);}catch{this.cachedDraftDoc=undefined;}
|
|
666
|
+
return this.cachedDraftDoc;
|
|
404
667
|
}
|
|
405
668
|
|
|
406
669
|
gateInfo():AnimationEditGate{
|
|
@@ -410,12 +673,13 @@ export class AnimationInspectionPanel {
|
|
|
410
673
|
if(this.animation==='idle'){
|
|
411
674
|
return checkAnimationEditGate('idle',this.source?.path??null);
|
|
412
675
|
}
|
|
413
|
-
|
|
676
|
+
const ro=typeof this.options.readOnlyReason==='function'?this.options.readOnlyReason():this.options.readOnlyReason;
|
|
677
|
+
if(ro||!this.options.apply||!this.options.preview){
|
|
414
678
|
return {
|
|
415
679
|
editable:false,
|
|
416
680
|
code:'ANIMATION_COMPARE_READ_ONLY',
|
|
417
681
|
reason:
|
|
418
|
-
|
|
682
|
+
ro??
|
|
419
683
|
'keyed animation editing is read-only in comparison sessions until per-side animation rebuild is wired.',
|
|
420
684
|
note:null,
|
|
421
685
|
};
|
|
@@ -433,13 +697,22 @@ export class AnimationInspectionPanel {
|
|
|
433
697
|
const clean=r.replace(/^ANIMATION_SOURCE_MISSING:\s*/,'');
|
|
434
698
|
return {editable:false,code:'ANIMATION_SOURCE_MISSING',reason:clean,note:null};
|
|
435
699
|
}
|
|
436
|
-
|
|
700
|
+
const gateKey=`${this.animation}\0${this.source.path??''}\0${this.builder?.text??''}`;
|
|
701
|
+
if(gateKey===this.cachedGateKey&&this.cachedGate)return this.cachedGate;
|
|
702
|
+
const gate=checkAnimationEditGate(this.animation,this.source.path,this.draftDocument());
|
|
703
|
+
this.cachedGateKey=gateKey;
|
|
704
|
+
this.cachedGate=gate;
|
|
705
|
+
return gate;
|
|
437
706
|
}
|
|
438
707
|
|
|
439
708
|
tracksInfo():TrackClassification[]{
|
|
440
709
|
const doc=this.draftDocument();
|
|
441
710
|
if(!doc||!this.animation)return [];
|
|
442
|
-
|
|
711
|
+
const key=`${this.animation}\0${this.builder?.text??''}`;
|
|
712
|
+
if(key===this.cachedTracksKey)return this.cachedTracks;
|
|
713
|
+
this.cachedTracksKey=key;
|
|
714
|
+
this.cachedTracks=classifyAnimationTracks(doc,this.animation);
|
|
715
|
+
return this.cachedTracks;
|
|
443
716
|
}
|
|
444
717
|
|
|
445
718
|
hasUnappliedPreview():boolean{
|
|
@@ -728,7 +1001,10 @@ export class AnimationInspectionPanel {
|
|
|
728
1001
|
const insertedIdx=rawKeys.findIndex(k=>k.t===cleanMotionNumber(time));
|
|
729
1002
|
if(insertedIdx>=0){
|
|
730
1003
|
const inspTrack=this.inspection?.tracks.find(t=>t.kind==='bone'&&t.target===cls.target&&t.name===cls.property);
|
|
731
|
-
|
|
1004
|
+
const sel={animation:this.animation,trackIndex,keyIndex:insertedIdx,pointer:inspTrack?.pointer??''};
|
|
1005
|
+
this.selectedKey=sel;
|
|
1006
|
+
this.selectedKeys=[sel];
|
|
1007
|
+
this.autoSyncPoseModeFromProperty(cls.property);
|
|
732
1008
|
this.syncTimelineKeysInPlace();
|
|
733
1009
|
this.syncKeyInspectorInPlace();
|
|
734
1010
|
}
|
|
@@ -743,8 +1019,10 @@ export class AnimationInspectionPanel {
|
|
|
743
1019
|
if(this.selectedKey&&this.selectedKey.trackIndex===trackIndex){
|
|
744
1020
|
if(rawKeys.length===0){
|
|
745
1021
|
this.selectedKey=null;
|
|
1022
|
+
this.selectedKeys=[];
|
|
746
1023
|
}else{
|
|
747
1024
|
this.selectedKey={...this.selectedKey,keyIndex:Math.min(keyIndex,rawKeys.length-1)};
|
|
1025
|
+
this.selectedKeys=[this.selectedKey];
|
|
748
1026
|
}
|
|
749
1027
|
this.syncTimelineKeysInPlace();
|
|
750
1028
|
this.syncKeyInspectorInPlace();
|
|
@@ -753,6 +1031,48 @@ export class AnimationInspectionPanel {
|
|
|
753
1031
|
return res;
|
|
754
1032
|
}
|
|
755
1033
|
|
|
1034
|
+
deleteSelection(
|
|
1035
|
+
selections?:ReadonlyArray<{track:number;key:number}>,
|
|
1036
|
+
):{ok:true;ops:readonly AnimationSourceOp[]}|{ok:false;error:string}{
|
|
1037
|
+
const gate=this.gateInfo();
|
|
1038
|
+
if(!gate.editable){
|
|
1039
|
+
const err=`${gate.code}: ${gate.reason??'animation is read-only'}`;
|
|
1040
|
+
this.setEditorStatus(err,true);
|
|
1041
|
+
return {ok:false,error:err};
|
|
1042
|
+
}
|
|
1043
|
+
if(!this.builder||!this.source?.available){
|
|
1044
|
+
const err='ANIMATION_SOURCE_MISSING: animation source is not loaded';
|
|
1045
|
+
this.setEditorStatus(err,true);
|
|
1046
|
+
return {ok:false,error:err};
|
|
1047
|
+
}
|
|
1048
|
+
const targets=
|
|
1049
|
+
selections??
|
|
1050
|
+
this.selectedKeys
|
|
1051
|
+
.filter(s=>s.animation===this.animation)
|
|
1052
|
+
.map(s=>({track:s.trackIndex,key:s.keyIndex}));
|
|
1053
|
+
if(targets.length===0){
|
|
1054
|
+
const err='ANIMATION_KEY_OUT_OF_RANGE: no keys selected to delete';
|
|
1055
|
+
this.setEditorStatus(err,true);
|
|
1056
|
+
return {ok:false,error:err};
|
|
1057
|
+
}
|
|
1058
|
+
try{
|
|
1059
|
+
this.options.pause?.();
|
|
1060
|
+
this.builder.deleteSelection(this.animation,targets);
|
|
1061
|
+
this.selectedKey=null;
|
|
1062
|
+
this.selectedKeys=[];
|
|
1063
|
+
this.syncEffectiveInspection(true);
|
|
1064
|
+
this.renderEditorBar();
|
|
1065
|
+
this.renderTimeline();
|
|
1066
|
+
this.renderChannels();
|
|
1067
|
+
this.setEditorStatus(`Deleted ${targets.length} selected key(s) (${this.builder.ops.length} pending op(s)).`,false);
|
|
1068
|
+
return {ok:true,ops:this.builder.ops};
|
|
1069
|
+
}catch(e){
|
|
1070
|
+
const msg=e instanceof Error?e.message:String(e);
|
|
1071
|
+
this.setEditorStatus(msg,true);
|
|
1072
|
+
return {ok:false,error:msg};
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
|
|
756
1076
|
moveSelection(
|
|
757
1077
|
selections:ReadonlyArray<{track:number;key:number}>,
|
|
758
1078
|
deltaTime:number,
|
|
@@ -816,6 +1136,7 @@ export class AnimationInspectionPanel {
|
|
|
816
1136
|
this.builder=new AnimationOpBuilder(this.source.text,(this.source.easings??undefined) as Readonly<Record<string,EasingTuple>>|undefined);
|
|
817
1137
|
}
|
|
818
1138
|
this.selectedKey=null;
|
|
1139
|
+
this.selectedKeys=[];
|
|
819
1140
|
this.syncEffectiveInspection(true);
|
|
820
1141
|
this.renderEditorBar();
|
|
821
1142
|
this.renderTimeline();
|
|
@@ -823,6 +1144,112 @@ export class AnimationInspectionPanel {
|
|
|
823
1144
|
this.setEditorStatus('Reset: no pending animation ops.',false);
|
|
824
1145
|
}
|
|
825
1146
|
|
|
1147
|
+
isKeySelected(trackIndex:number,keyIndex:number):boolean{
|
|
1148
|
+
if(this.selectedKeys.some(s=>s.animation===this.animation&&s.trackIndex===trackIndex&&s.keyIndex===keyIndex)){
|
|
1149
|
+
return true;
|
|
1150
|
+
}
|
|
1151
|
+
return (
|
|
1152
|
+
this.selectedKey!==null&&
|
|
1153
|
+
this.selectedKey.animation===this.animation&&
|
|
1154
|
+
this.selectedKey.trackIndex===trackIndex&&
|
|
1155
|
+
this.selectedKey.keyIndex===keyIndex
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
selectedKeysInfo():SelectedAnimationKey[]{
|
|
1160
|
+
const list=this.selectedKeys.filter(s=>s.animation===this.animation);
|
|
1161
|
+
if(list.length>0)return [...list];
|
|
1162
|
+
if(this.selectedKey&&this.selectedKey.animation===this.animation)return [this.selectedKey];
|
|
1163
|
+
return [];
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
toggleKeySelection(trackIndex:number,keyIndex:number,pointerHint?:string):boolean{
|
|
1167
|
+
const gate=this.gateInfo();
|
|
1168
|
+
if(!gate.editable){
|
|
1169
|
+
this.setEditorStatus(`${gate.code}: ${gate.reason}`,true);
|
|
1170
|
+
return false;
|
|
1171
|
+
}
|
|
1172
|
+
const clss=this.tracksInfo();
|
|
1173
|
+
const cls=clss[trackIndex];
|
|
1174
|
+
if(!cls){
|
|
1175
|
+
this.setEditorStatus(`ANIMATION_TRACK_OUT_OF_RANGE: track ${trackIndex}`,true);
|
|
1176
|
+
return false;
|
|
1177
|
+
}
|
|
1178
|
+
if(!cls.editable){
|
|
1179
|
+
this.setEditorStatus(`ANIMATION_TRACK_READ_ONLY: ${cls.reason}`,true);
|
|
1180
|
+
return false;
|
|
1181
|
+
}
|
|
1182
|
+
const rawKeys=this.readDraftTrackKeys(trackIndex);
|
|
1183
|
+
const k=rawKeys[keyIndex];
|
|
1184
|
+
if(!k){
|
|
1185
|
+
this.setEditorStatus(`ANIMATION_KEY_OUT_OF_RANGE: key ${keyIndex} on track ${trackIndex}`,true);
|
|
1186
|
+
return false;
|
|
1187
|
+
}
|
|
1188
|
+
const inspTrack=this.inspection?.tracks.find(t=>t.kind==='bone'&&t.target===cls.target&&t.name===cls.property)??null;
|
|
1189
|
+
const pointer=pointerHint??inspTrack?.pointer??'';
|
|
1190
|
+
const current=this.selectedKeysInfo();
|
|
1191
|
+
const existingIdx=current.findIndex(s=>s.trackIndex===trackIndex&&s.keyIndex===keyIndex);
|
|
1192
|
+
if(existingIdx>=0){
|
|
1193
|
+
current.splice(existingIdx,1);
|
|
1194
|
+
this.selectedKeys=current;
|
|
1195
|
+
this.selectedKey=current.at(-1)??null;
|
|
1196
|
+
}else{
|
|
1197
|
+
const entry:SelectedAnimationKey={animation:this.animation,trackIndex,keyIndex,pointer};
|
|
1198
|
+
current.push(entry);
|
|
1199
|
+
this.selectedKeys=current;
|
|
1200
|
+
this.selectedKey=entry;
|
|
1201
|
+
this.autoSyncPoseModeFromProperty(cls.property);
|
|
1202
|
+
}
|
|
1203
|
+
this.syncTimelineKeysInPlace();
|
|
1204
|
+
this.syncKeyInspectorInPlace();
|
|
1205
|
+
this.setEditorStatus(`Selected ${this.selectedKeys.length} key(s) across ${new Set(this.selectedKeys.map(s=>s.trackIndex)).size} track(s).`,false);
|
|
1206
|
+
return true;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
selectKeys(selections:ReadonlyArray<{track:number;key:number}>):boolean{
|
|
1210
|
+
const gate=this.gateInfo();
|
|
1211
|
+
if(!gate.editable){
|
|
1212
|
+
this.setEditorStatus(`${gate.code}: ${gate.reason}`,true);
|
|
1213
|
+
return false;
|
|
1214
|
+
}
|
|
1215
|
+
const clss=this.tracksInfo();
|
|
1216
|
+
const next:SelectedAnimationKey[]=[];
|
|
1217
|
+
const seen=new Set<string>();
|
|
1218
|
+
const skippedReadonly=new Set<string>();
|
|
1219
|
+
for(const sel of selections){
|
|
1220
|
+
const cls=clss[sel.track];
|
|
1221
|
+
if(!cls)continue;
|
|
1222
|
+
if(!cls.editable){
|
|
1223
|
+
skippedReadonly.add(`${cls.target}.${cls.property}`);
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
const rawKeys=this.readDraftTrackKeys(sel.track);
|
|
1227
|
+
if(!rawKeys[sel.key])continue;
|
|
1228
|
+
const id=`${sel.track}:${sel.key}`;
|
|
1229
|
+
if(seen.has(id))continue;
|
|
1230
|
+
seen.add(id);
|
|
1231
|
+
const inspTrack=this.inspection?.tracks.find(t=>t.kind==='bone'&&t.target===cls.target&&t.name===cls.property)??null;
|
|
1232
|
+
next.push({animation:this.animation,trackIndex:sel.track,keyIndex:sel.key,pointer:inspTrack?.pointer??''});
|
|
1233
|
+
}
|
|
1234
|
+
this.selectedKeys=next;
|
|
1235
|
+
this.selectedKey=next.at(-1)??null;
|
|
1236
|
+
if(this.selectedKey){
|
|
1237
|
+
const lastCls=clss[this.selectedKey.trackIndex];
|
|
1238
|
+
this.autoSyncPoseModeFromProperty(lastCls?.property);
|
|
1239
|
+
}
|
|
1240
|
+
this.syncTimelineKeysInPlace();
|
|
1241
|
+
this.syncKeyInspectorInPlace();
|
|
1242
|
+
if(skippedReadonly.size>0){
|
|
1243
|
+
this.setEditorStatus(
|
|
1244
|
+
`Selected ${next.length} editable key(s); skipped read-only track(s): ${[...skippedReadonly].join(', ')} (ANIMATION_TRACK_READ_ONLY).`,
|
|
1245
|
+
false,
|
|
1246
|
+
);
|
|
1247
|
+
}else{
|
|
1248
|
+
this.setEditorStatus(`Selected ${next.length} key(s) across ${new Set(next.map(s=>s.trackIndex)).size} track(s).`,false);
|
|
1249
|
+
}
|
|
1250
|
+
return next.length>0;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
826
1253
|
selectKey(trackIndex:number,keyIndex:number):boolean{
|
|
827
1254
|
const gate=this.gateInfo();
|
|
828
1255
|
if(!gate.editable){
|
|
@@ -845,8 +1272,15 @@ export class AnimationInspectionPanel {
|
|
|
845
1272
|
this.setEditorStatus(`ANIMATION_KEY_OUT_OF_RANGE: key ${keyIndex} on track ${trackIndex}`,true);
|
|
846
1273
|
return false;
|
|
847
1274
|
}
|
|
1275
|
+
const curTarget=this.selection.value();
|
|
1276
|
+
if(curTarget&&(curTarget.kind!==cls.targetKind||curTarget.name!==cls.target)){
|
|
1277
|
+
this.selection.select(null);
|
|
1278
|
+
}
|
|
848
1279
|
const inspTrack=this.inspection?.tracks.find(t=>t.kind==='bone'&&t.target===cls.target&&t.name===cls.property)??null;
|
|
849
|
-
|
|
1280
|
+
const sel={animation:this.animation,trackIndex,keyIndex,pointer:inspTrack?.pointer??''};
|
|
1281
|
+
this.selectedKey=sel;
|
|
1282
|
+
this.selectedKeys=[sel];
|
|
1283
|
+
this.autoSyncPoseModeFromProperty(cls.property);
|
|
850
1284
|
if(inspTrack){
|
|
851
1285
|
this.track=inspTrack;
|
|
852
1286
|
this.channel=0;
|
|
@@ -1012,6 +1446,7 @@ export class AnimationInspectionPanel {
|
|
|
1012
1446
|
if(!box)return;
|
|
1013
1447
|
const gate=this.gateInfo();
|
|
1014
1448
|
const info=this.selectedKeyInfo();
|
|
1449
|
+
const multi=this.selectedKeysInfo();
|
|
1015
1450
|
|
|
1016
1451
|
const trackSel=box.querySelector<HTMLSelectElement>('[data-insert-track]');
|
|
1017
1452
|
if(trackSel&&info){
|
|
@@ -1059,6 +1494,7 @@ export class AnimationInspectionPanel {
|
|
|
1059
1494
|
if(delBtn){
|
|
1060
1495
|
delBtn.hidden=hideInputs;
|
|
1061
1496
|
delBtn.disabled=true;
|
|
1497
|
+
delBtn.textContent='Delete key';
|
|
1062
1498
|
delBtn.onclick=null;
|
|
1063
1499
|
}
|
|
1064
1500
|
if(emptyHint){
|
|
@@ -1073,8 +1509,14 @@ export class AnimationInspectionPanel {
|
|
|
1073
1509
|
|
|
1074
1510
|
if(title){
|
|
1075
1511
|
title.hidden=false;
|
|
1076
|
-
|
|
1077
|
-
|
|
1512
|
+
if(multi.length>1){
|
|
1513
|
+
const trackCount=new Set(multi.map(s=>s.trackIndex)).size;
|
|
1514
|
+
title.textContent=`${multi.length} keys selected (${trackCount} track${trackCount===1?'':'s'})`;
|
|
1515
|
+
title.title=`${multi.length} keys selected (${trackCount} track(s)) · anchor ${info.bone} · ${info.property} #${info.keyIndex}`;
|
|
1516
|
+
}else{
|
|
1517
|
+
title.textContent=`${info.bone} · ${info.property} · key #${info.keyIndex} (track #${info.trackIndex})`;
|
|
1518
|
+
title.title=title.textContent;
|
|
1519
|
+
}
|
|
1078
1520
|
}
|
|
1079
1521
|
if(timeInput){
|
|
1080
1522
|
if(timeInput.parentElement)timeInput.parentElement.hidden=false;
|
|
@@ -1082,11 +1524,16 @@ export class AnimationInspectionPanel {
|
|
|
1082
1524
|
if(document.activeElement!==timeInput)timeInput.value=String(cleanMotionNumber(info.time));
|
|
1083
1525
|
timeInput.onchange=()=>{
|
|
1084
1526
|
const nextT=Number(timeInput.value);
|
|
1085
|
-
|
|
1527
|
+
if(multi.length>1){
|
|
1528
|
+
const delta=cleanMotionNumber(nextT-info.time);
|
|
1529
|
+
this.moveSelection(multi.map(s=>({track:s.trackIndex,key:s.keyIndex})),delta);
|
|
1530
|
+
}else{
|
|
1531
|
+
this.setKeyTime(info.trackIndex,info.keyIndex,nextT);
|
|
1532
|
+
}
|
|
1086
1533
|
};
|
|
1087
1534
|
}
|
|
1088
1535
|
if(channelsHost){
|
|
1089
|
-
channelsHost.hidden=
|
|
1536
|
+
channelsHost.hidden=multi.length>1;
|
|
1090
1537
|
const existing=channelsHost.querySelectorAll<HTMLInputElement>('[data-key-channel]');
|
|
1091
1538
|
const sameShape=
|
|
1092
1539
|
existing.length===info.channels.length&&
|
|
@@ -1128,8 +1575,13 @@ export class AnimationInspectionPanel {
|
|
|
1128
1575
|
if(delBtn){
|
|
1129
1576
|
delBtn.hidden=false;
|
|
1130
1577
|
delBtn.disabled=this.isBusy;
|
|
1578
|
+
delBtn.textContent=multi.length>1?`Delete ${multi.length} keys`:'Delete key';
|
|
1131
1579
|
delBtn.onclick=()=>{
|
|
1132
|
-
|
|
1580
|
+
if(multi.length>1){
|
|
1581
|
+
this.deleteSelection();
|
|
1582
|
+
}else{
|
|
1583
|
+
this.deleteKey(info.trackIndex,info.keyIndex);
|
|
1584
|
+
}
|
|
1133
1585
|
};
|
|
1134
1586
|
}
|
|
1135
1587
|
if(emptyHint){
|
|
@@ -1176,7 +1628,7 @@ export class AnimationInspectionPanel {
|
|
|
1176
1628
|
const kIdx=Number(mark.dataset.keyIndex);
|
|
1177
1629
|
const srcTrack=mark.dataset.sourceTrack!==undefined?Number(mark.dataset.sourceTrack):undefined;
|
|
1178
1630
|
const isEditable=mark.dataset.editable==='true';
|
|
1179
|
-
const isSelected=isEditable&&srcTrack!==undefined&&this.
|
|
1631
|
+
const isSelected=isEditable&&srcTrack!==undefined&&this.isKeySelected(srcTrack,kIdx);
|
|
1180
1632
|
mark.classList.toggle('selected',isSelected);
|
|
1181
1633
|
mark.setAttribute('aria-pressed',String(isSelected));
|
|
1182
1634
|
if(track&&track.keys[kIdx]){
|
|
@@ -1217,6 +1669,7 @@ export class AnimationInspectionPanel {
|
|
|
1217
1669
|
list.className='animation-lanes';
|
|
1218
1670
|
list.dataset.animationLanes='';
|
|
1219
1671
|
pane.append(list);
|
|
1672
|
+
this.bindLaneBoxSelection(list);
|
|
1220
1673
|
|
|
1221
1674
|
// Sticky top time ruler with ticks and scrub support
|
|
1222
1675
|
const ruler=document.createElement('div');
|
|
@@ -1279,7 +1732,7 @@ export class AnimationInspectionPanel {
|
|
|
1279
1732
|
|
|
1280
1733
|
const label=button(`${track.target} · ${track.name}`,()=>{
|
|
1281
1734
|
const liveTrack=this.inspection?.tracks.find(t=>t.pointer===trackPointer)??track;
|
|
1282
|
-
this.track=liveTrack;this.channel=0;this.renderChannels();this.show('curve');
|
|
1735
|
+
this.track=liveTrack;this.channel=0;this.autoSyncPoseModeFromProperty(track.name);this.renderChannels();this.show('curve');
|
|
1283
1736
|
});
|
|
1284
1737
|
label.className='animation-lane-label';
|
|
1285
1738
|
label.title=`${track.target} · ${track.name}`;
|
|
@@ -1314,8 +1767,8 @@ export class AnimationInspectionPanel {
|
|
|
1314
1767
|
|
|
1315
1768
|
track.keys.forEach((key,index)=>{
|
|
1316
1769
|
const cleanT=formatSeconds(key.time);
|
|
1317
|
-
const mark=button('◆',
|
|
1318
|
-
if(this.suppressNextKeyClick){
|
|
1770
|
+
const mark=button('◆',e=>{
|
|
1771
|
+
if(this.suppressNextKeyClick||(isEditable&&cls&&(e?.detail??0)>0)){
|
|
1319
1772
|
this.suppressNextKeyClick=false;
|
|
1320
1773
|
return;
|
|
1321
1774
|
}
|
|
@@ -1324,9 +1777,16 @@ export class AnimationInspectionPanel {
|
|
|
1324
1777
|
const liveKey=liveTrack.keys[liveIdx]??key;
|
|
1325
1778
|
this.track=liveTrack;this.channel=0;this.renderChannels();
|
|
1326
1779
|
if(isEditable&&cls){
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1780
|
+
if(e?.shiftKey){
|
|
1781
|
+
this.toggleKeySelection(cls.trackIndex,liveIdx,trackPointer);
|
|
1782
|
+
}else{
|
|
1783
|
+
const sel={animation:this.animation,trackIndex:cls.trackIndex,keyIndex:liveIdx,pointer:trackPointer};
|
|
1784
|
+
this.selectedKey=sel;
|
|
1785
|
+
this.selectedKeys=[sel];
|
|
1786
|
+
this.autoSyncPoseModeFromProperty(cls.property);
|
|
1787
|
+
this.syncTimelineKeysInPlace();
|
|
1788
|
+
this.syncKeyInspectorInPlace();
|
|
1789
|
+
}
|
|
1330
1790
|
}else{
|
|
1331
1791
|
this.setEditorStatus(readonlyReason,true);
|
|
1332
1792
|
}
|
|
@@ -1335,7 +1795,7 @@ export class AnimationInspectionPanel {
|
|
|
1335
1795
|
}
|
|
1336
1796
|
});
|
|
1337
1797
|
mark.className='animation-key';
|
|
1338
|
-
const isSelected=isEditable&&cls!==undefined&&this.
|
|
1798
|
+
const isSelected=isEditable&&cls!==undefined&&this.isKeySelected(cls.trackIndex,index);
|
|
1339
1799
|
if(isSelected)mark.classList.add('selected');
|
|
1340
1800
|
mark.setAttribute('aria-pressed',String(isSelected));
|
|
1341
1801
|
Object.assign(mark.dataset,{
|
|
@@ -1432,6 +1892,155 @@ export class AnimationInspectionPanel {
|
|
|
1432
1892
|
if(prevScrollLeft>0)list.scrollLeft=prevScrollLeft;
|
|
1433
1893
|
}
|
|
1434
1894
|
|
|
1895
|
+
/**
|
|
1896
|
+
* Box-drag selection (>= 3 px) across `.animation-lanes` / `.animation-key-lane`,
|
|
1897
|
+
* while a plain click (< 3 px) on an empty editable `.animation-key-lane` seeks the playhead.
|
|
1898
|
+
* Playhead scrub remains on `.animation-ruler-track`.
|
|
1899
|
+
*/
|
|
1900
|
+
private bindLaneBoxSelection(list:HTMLElement){
|
|
1901
|
+
let activeBox:{
|
|
1902
|
+
pointerId:number;
|
|
1903
|
+
startX:number;
|
|
1904
|
+
startY:number;
|
|
1905
|
+
shiftKey:boolean;
|
|
1906
|
+
baseSelection:SelectedAnimationKey[];
|
|
1907
|
+
clickedLane:HTMLElement|null;
|
|
1908
|
+
clickedRow:HTMLElement|null;
|
|
1909
|
+
moved:boolean;
|
|
1910
|
+
boxEl:HTMLElement|null;
|
|
1911
|
+
}|null=null;
|
|
1912
|
+
|
|
1913
|
+
list.addEventListener('pointerdown',e=>{
|
|
1914
|
+
if(!e.isPrimary||e.button!==0||this.isBusy)return;
|
|
1915
|
+
const rawTarget=e.target as (Element&{dataset?:DOMStringMap;className?:string})|null;
|
|
1916
|
+
const hitInteractive=rawTarget?.closest?.('button,input,select,textarea,[data-animation-ruler],[data-lane-head]');
|
|
1917
|
+
if(hitInteractive)return;
|
|
1918
|
+
const clickedLane=rawTarget?.closest?.<HTMLElement>('.animation-key-lane')??(rawTarget?.className?.includes('animation-key-lane')?rawTarget as unknown as HTMLElement:null);
|
|
1919
|
+
const clickedRow=rawTarget?.closest?.<HTMLElement>('.animation-lane,.animation-readonly-lane')??(clickedLane?.parentElement as HTMLElement|null)??null;
|
|
1920
|
+
e.preventDefault();
|
|
1921
|
+
if(typeof window!=='undefined'&&typeof window.getSelection==='function'){
|
|
1922
|
+
window.getSelection()?.removeAllRanges?.();
|
|
1923
|
+
}
|
|
1924
|
+
activeBox={
|
|
1925
|
+
pointerId:e.pointerId,
|
|
1926
|
+
startX:e.clientX,
|
|
1927
|
+
startY:e.clientY,
|
|
1928
|
+
shiftKey:e.shiftKey,
|
|
1929
|
+
baseSelection:e.shiftKey?this.selectedKeysInfo():[],
|
|
1930
|
+
clickedLane,
|
|
1931
|
+
clickedRow,
|
|
1932
|
+
moved:false,
|
|
1933
|
+
boxEl:null,
|
|
1934
|
+
};
|
|
1935
|
+
list.setPointerCapture?.(e.pointerId);
|
|
1936
|
+
});
|
|
1937
|
+
|
|
1938
|
+
list.addEventListener('pointermove',e=>{
|
|
1939
|
+
if(!activeBox||activeBox.pointerId!==e.pointerId)return;
|
|
1940
|
+
const dist=Math.hypot(e.clientX-activeBox.startX,e.clientY-activeBox.startY);
|
|
1941
|
+
if(!activeBox.moved&&dist<3)return;
|
|
1942
|
+
activeBox.moved=true;
|
|
1943
|
+
e.preventDefault();
|
|
1944
|
+
if(typeof window!=='undefined'&&typeof window.getSelection==='function'){
|
|
1945
|
+
window.getSelection()?.removeAllRanges?.();
|
|
1946
|
+
}
|
|
1947
|
+
const listRect=list.getBoundingClientRect();
|
|
1948
|
+
const minX=Math.min(activeBox.startX,e.clientX);
|
|
1949
|
+
const maxX=Math.max(activeBox.startX,e.clientX);
|
|
1950
|
+
const minY=Math.min(activeBox.startY,e.clientY);
|
|
1951
|
+
const maxY=Math.max(activeBox.startY,e.clientY);
|
|
1952
|
+
|
|
1953
|
+
if(!activeBox.boxEl){
|
|
1954
|
+
const boxEl=document.createElement('div');
|
|
1955
|
+
boxEl.className='animation-selection-box';
|
|
1956
|
+
boxEl.dataset.selectionBox='';
|
|
1957
|
+
list.append(boxEl);
|
|
1958
|
+
activeBox.boxEl=boxEl;
|
|
1959
|
+
}
|
|
1960
|
+
activeBox.boxEl.style.left=`${minX-listRect.left+(list.scrollLeft||0)}px`;
|
|
1961
|
+
activeBox.boxEl.style.top=`${minY-listRect.top+(list.scrollTop||0)}px`;
|
|
1962
|
+
activeBox.boxEl.style.width=`${maxX-minX}px`;
|
|
1963
|
+
activeBox.boxEl.style.height=`${maxY-minY}px`;
|
|
1964
|
+
|
|
1965
|
+
const merged=new Map<string,SelectedAnimationKey>();
|
|
1966
|
+
for(const s of activeBox.baseSelection){
|
|
1967
|
+
merged.set(`${s.trackIndex}:${s.keyIndex}`,s);
|
|
1968
|
+
}
|
|
1969
|
+
const skippedReadonly=new Set<string>();
|
|
1970
|
+
const allMarks=list.querySelectorAll<HTMLButtonElement>('.animation-key');
|
|
1971
|
+
for(const mark of allMarks){
|
|
1972
|
+
const r=mark.getBoundingClientRect();
|
|
1973
|
+
const cx=(r.left+r.right)/2;
|
|
1974
|
+
const cy=(r.top+r.bottom)/2;
|
|
1975
|
+
const intersects=r.right>=minX&&r.left<=maxX&&r.bottom>=minY&&r.top<=maxY&&(cx>=minX-4&&cx<=maxX+4&&cy>=minY-4&&cy<=maxY+4);
|
|
1976
|
+
if(!intersects)continue;
|
|
1977
|
+
if(mark.dataset.editable==='true'&&mark.dataset.sourceTrack!==undefined){
|
|
1978
|
+
const tr=Number(mark.dataset.sourceTrack);
|
|
1979
|
+
const kIdx=Number(mark.dataset.keyIndex);
|
|
1980
|
+
merged.set(`${tr}:${kIdx}`,{
|
|
1981
|
+
animation:this.animation,
|
|
1982
|
+
trackIndex:tr,
|
|
1983
|
+
keyIndex:kIdx,
|
|
1984
|
+
pointer:mark.dataset.track??'',
|
|
1985
|
+
});
|
|
1986
|
+
}else{
|
|
1987
|
+
skippedReadonly.add(`${mark.dataset.target??''}.${mark.dataset.timeline??''}`);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
this.selectedKeys=[...merged.values()];
|
|
1991
|
+
this.selectedKey=this.selectedKeys.at(-1)??null;
|
|
1992
|
+
this.syncTimelineKeysInPlace();
|
|
1993
|
+
this.syncKeyInspectorInPlace();
|
|
1994
|
+
if(skippedReadonly.size>0){
|
|
1995
|
+
this.setEditorStatus(
|
|
1996
|
+
`Selected ${this.selectedKeys.length} editable key(s); skipped read-only track(s): ${[...skippedReadonly].join(', ')} (ANIMATION_TRACK_READ_ONLY).`,
|
|
1997
|
+
false,
|
|
1998
|
+
);
|
|
1999
|
+
}else{
|
|
2000
|
+
this.setEditorStatus(
|
|
2001
|
+
`Selected ${this.selectedKeys.length} key(s) across ${new Set(this.selectedKeys.map(s=>s.trackIndex)).size} track(s).`,
|
|
2002
|
+
false,
|
|
2003
|
+
);
|
|
2004
|
+
}
|
|
2005
|
+
});
|
|
2006
|
+
|
|
2007
|
+
const endBox=(e:PointerEvent)=>{
|
|
2008
|
+
if(!activeBox||activeBox.pointerId!==e.pointerId)return;
|
|
2009
|
+
const box=activeBox;
|
|
2010
|
+
activeBox=null;
|
|
2011
|
+
if(list.hasPointerCapture?.(e.pointerId))list.releasePointerCapture(e.pointerId);
|
|
2012
|
+
if(box.boxEl)box.boxEl.remove();
|
|
2013
|
+
if(!box.moved&&box.clickedLane){
|
|
2014
|
+
const rowEditable=box.clickedRow?.dataset.editable==='true';
|
|
2015
|
+
const roReason=box.clickedRow?.dataset.readonlyReason;
|
|
2016
|
+
if(!rowEditable&&roReason){
|
|
2017
|
+
this.setEditorStatus(roReason,true);
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
2020
|
+
if(rowEditable){
|
|
2021
|
+
if(!box.shiftKey){
|
|
2022
|
+
this.selectedKey=null;
|
|
2023
|
+
this.selectedKeys=[];
|
|
2024
|
+
this.syncTimelineKeysInPlace();
|
|
2025
|
+
this.syncKeyInspectorInPlace();
|
|
2026
|
+
}
|
|
2027
|
+
const rect=box.clickedLane.getBoundingClientRect();
|
|
2028
|
+
if(rect.width>0){
|
|
2029
|
+
const end=this.effectiveEnd();
|
|
2030
|
+
const ratio=Math.max(0,Math.min(1,(e.clientX-rect.left)/rect.width));
|
|
2031
|
+
const rawTime=cleanMotionNumber(ratio*end);
|
|
2032
|
+
this.at=rawTime;
|
|
2033
|
+
this.placePlayheads();
|
|
2034
|
+
const maxSeek=this.runtimeDuration>0?Math.min(end,this.runtimeDuration):end;
|
|
2035
|
+
this.options.seek(cleanMotionNumber(Math.min(maxSeek,rawTime)));
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
};
|
|
2040
|
+
list.addEventListener('pointerup',endBox);
|
|
2041
|
+
list.addEventListener('pointercancel',endBox);
|
|
2042
|
+
}
|
|
2043
|
+
|
|
1435
2044
|
private bindRulerScrub(rulerTrack:HTMLElement){
|
|
1436
2045
|
let scrubbingId:number|null=null;
|
|
1437
2046
|
const scrubAt=(clientX:number)=>{
|
|
@@ -1485,7 +2094,18 @@ export class AnimationInspectionPanel {
|
|
|
1485
2094
|
const liveIdx=Number(mark.dataset.keyIndex??keyIndex);
|
|
1486
2095
|
if(liveTrack)this.track=liveTrack;
|
|
1487
2096
|
this.channel=0;
|
|
1488
|
-
|
|
2097
|
+
if(e.shiftKey){
|
|
2098
|
+
this.toggleKeySelection(trackIndex,liveIdx,trackPointer);
|
|
2099
|
+
this.renderChannels();
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
2102
|
+
const alreadyInMulti=this.selectedKeys.length>1&&this.isKeySelected(trackIndex,liveIdx);
|
|
2103
|
+
const sel={animation:this.animation,trackIndex,keyIndex:liveIdx,pointer:trackPointer};
|
|
2104
|
+
this.selectedKey=sel;
|
|
2105
|
+
if(!alreadyInMulti){
|
|
2106
|
+
this.selectedKeys=[sel];
|
|
2107
|
+
}
|
|
2108
|
+
this.autoSyncPoseModeFromProperty(liveTrack?.name);
|
|
1489
2109
|
this.syncTimelineKeysInPlace();
|
|
1490
2110
|
this.syncKeyInspectorInPlace();
|
|
1491
2111
|
this.renderChannels();
|
|
@@ -1499,6 +2119,8 @@ export class AnimationInspectionPanel {
|
|
|
1499
2119
|
keyIndex:liveIdx,
|
|
1500
2120
|
startX:e.clientX,
|
|
1501
2121
|
moved:false,
|
|
2122
|
+
wasAlreadyInMulti:alreadyInMulti,
|
|
2123
|
+
undoGroupId:this.builder?this.builder.beginUndoGroup():1,
|
|
1502
2124
|
laneEl,
|
|
1503
2125
|
markEl:mark,
|
|
1504
2126
|
end:this.effectiveEnd(),
|
|
@@ -1516,6 +2138,22 @@ export class AnimationInspectionPanel {
|
|
|
1516
2138
|
if(rect.width<=0)return;
|
|
1517
2139
|
const ratio=Math.max(0,(e.clientX-rect.left)/rect.width);
|
|
1518
2140
|
const rawTime=Math.round(ratio*drag.end*10000)/10000;
|
|
2141
|
+
if(this.selectedKeys.length>1&&this.isKeySelected(drag.trackIndex,drag.keyIndex)){
|
|
2142
|
+
const anchorKey=this.readDraftTrackKeys(drag.trackIndex)[drag.keyIndex];
|
|
2143
|
+
if(!anchorKey)return;
|
|
2144
|
+
const delta=cleanMotionNumber(rawTime-anchorKey.t);
|
|
2145
|
+
if(Math.abs(delta)<1e-6)return;
|
|
2146
|
+
const runMove=()=>
|
|
2147
|
+
this.moveSelection(
|
|
2148
|
+
this.selectedKeys.map(s=>({track:s.trackIndex,key:s.keyIndex})),
|
|
2149
|
+
delta,
|
|
2150
|
+
);
|
|
2151
|
+
const res=this.builder?this.builder.withUndoGroup(drag.undoGroupId,runMove):runMove();
|
|
2152
|
+
if(res.ok&&rawTime>=0&&rawTime<=this.runtimeDuration){
|
|
2153
|
+
this.options.seek(rawTime);
|
|
2154
|
+
}
|
|
2155
|
+
return;
|
|
2156
|
+
}
|
|
1519
2157
|
const res=this.applyOp(
|
|
1520
2158
|
{op:'set_key_time',animation:this.animation,track:drag.trackIndex,key:drag.keyIndex,time:rawTime},
|
|
1521
2159
|
{skipTimelineDomRebuild:true},
|
|
@@ -1527,11 +2165,20 @@ export class AnimationInspectionPanel {
|
|
|
1527
2165
|
|
|
1528
2166
|
const finishDrag=(e:PointerEvent)=>{
|
|
1529
2167
|
const drag=this.draggingKey;
|
|
1530
|
-
if(!drag||drag.pointerId!==e.pointerId)
|
|
2168
|
+
if(!drag||drag.pointerId!==e.pointerId){
|
|
2169
|
+
if(mark.hasPointerCapture?.(e.pointerId))mark.releasePointerCapture(e.pointerId);
|
|
2170
|
+
if(e.type==="pointercancel")this.suppressNextKeyClick=false;
|
|
2171
|
+
return;
|
|
2172
|
+
}
|
|
1531
2173
|
this.draggingKey=null;
|
|
1532
2174
|
if(mark.hasPointerCapture?.(e.pointerId))mark.releasePointerCapture(e.pointerId);
|
|
2175
|
+
if(!drag.moved&&drag.wasAlreadyInMulti&&this.selectedKey){
|
|
2176
|
+
this.selectedKeys=[this.selectedKey];
|
|
2177
|
+
this.syncTimelineKeysInPlace();
|
|
2178
|
+
this.syncKeyInspectorInPlace();
|
|
2179
|
+
}
|
|
1533
2180
|
e.preventDefault();
|
|
1534
|
-
|
|
2181
|
+
if(e.type==="pointercancel")this.suppressNextKeyClick=false;
|
|
1535
2182
|
};
|
|
1536
2183
|
mark.addEventListener('pointerup',finishDrag);
|
|
1537
2184
|
mark.addEventListener('pointercancel',finishDrag);
|
|
@@ -1743,7 +2390,9 @@ export class AnimationInspectionPanel {
|
|
|
1743
2390
|
const segIdx=Number(target.dataset.segment??0);
|
|
1744
2391
|
const handleIdx=Number(target.dataset.curveHandle)===2?2:1;
|
|
1745
2392
|
this.curveSegment=segIdx;
|
|
1746
|
-
|
|
2393
|
+
const sel={animation:this.animation,trackIndex:cls.trackIndex,keyIndex:segIdx,pointer:this.track.pointer};
|
|
2394
|
+
this.selectedKey=sel;
|
|
2395
|
+
this.selectedKeys=[sel];
|
|
1747
2396
|
this.syncTimelineKeysInPlace();
|
|
1748
2397
|
this.syncKeyInspectorInPlace();
|
|
1749
2398
|
const field=CHANNELS[this.track.name]?.[this.channel]?.field;
|
|
@@ -1759,6 +2408,7 @@ export class AnimationInspectionPanel {
|
|
|
1759
2408
|
segmentIndex:segIdx,
|
|
1760
2409
|
handleIndex:handleIdx,
|
|
1761
2410
|
channel:this.channel,
|
|
2411
|
+
undoGroupId:this.builder?this.builder.beginUndoGroup():1,
|
|
1762
2412
|
low,
|
|
1763
2413
|
high,
|
|
1764
2414
|
span,
|
|
@@ -1866,16 +2516,362 @@ export class AnimationInspectionPanel {
|
|
|
1866
2516
|
|
|
1867
2517
|
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
2518
|
|
|
2519
|
+
boneWorldMatrix(boneName:string):{x:number;y:number;a:number;b:number;c:number;d:number}{
|
|
2520
|
+
const captured=this.bones.get(boneName);
|
|
2521
|
+
if(captured&&captured.hasMatrix){
|
|
2522
|
+
return {x:captured.x,y:captured.y,a:captured.a,b:captured.b,c:captured.c,d:captured.d};
|
|
2523
|
+
}
|
|
2524
|
+
if(!this.inspection)return {x:captured?.x??0,y:captured?.y??0,a:1,b:0,c:0,d:1};
|
|
2525
|
+
const chain:string[]=[];
|
|
2526
|
+
let curr:string|undefined=boneName;
|
|
2527
|
+
const visited=new Set<string>();
|
|
2528
|
+
while(curr&&!visited.has(curr)){
|
|
2529
|
+
visited.add(curr);
|
|
2530
|
+
chain.unshift(curr);
|
|
2531
|
+
const b=this.inspection.bones.find(x=>x.name===curr);
|
|
2532
|
+
curr=b?.parent;
|
|
2533
|
+
}
|
|
2534
|
+
let wa=1,wb=0,wc=0,wd=1,wx=0,wy=0;
|
|
2535
|
+
for(const name of chain){
|
|
2536
|
+
const locals=evaluateBoneLocals(this.inspection,name,this.at);
|
|
2537
|
+
const rx=(locals.rotation+locals.shearX)*(Math.PI/180);
|
|
2538
|
+
const ry=(locals.rotation+90+locals.shearY)*(Math.PI/180);
|
|
2539
|
+
const la=Math.cos(rx)*locals.scaleX;
|
|
2540
|
+
const lb=Math.cos(ry)*locals.scaleY;
|
|
2541
|
+
const lc=Math.sin(rx)*locals.scaleX;
|
|
2542
|
+
const ld=Math.sin(ry)*locals.scaleY;
|
|
2543
|
+
const nx=wa*locals.x+wb*locals.y+wx;
|
|
2544
|
+
const ny=wc*locals.x+wd*locals.y+wy;
|
|
2545
|
+
const na=wa*la+wb*lc;
|
|
2546
|
+
const nb=wa*lb+wb*ld;
|
|
2547
|
+
const nc=wc*la+wd*lc;
|
|
2548
|
+
const nd=wc*lb+wd*ld;
|
|
2549
|
+
wx=nx;wy=ny;wa=na;wb=nb;wc=nc;wd=nd;
|
|
2550
|
+
}
|
|
2551
|
+
return {x:wx,y:wy,a:wa,b:wb,c:wc,d:wd};
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
private clientToWorld(clientX:number,clientY:number):{x:number;y:number}{
|
|
2555
|
+
const pickRect=this.picks.getBoundingClientRect();
|
|
2556
|
+
const rect=pickRect.width>0?pickRect:this.options.stage.getBoundingClientRect();
|
|
2557
|
+
const p0=this.options.project(0,0);
|
|
2558
|
+
const px=this.options.project(1,0);
|
|
2559
|
+
const py=this.options.project(0,1);
|
|
2560
|
+
const sx=px.x-p0.x||1;
|
|
2561
|
+
const sy=py.y-p0.y||1;
|
|
2562
|
+
return {
|
|
2563
|
+
x:(clientX-rect.left-p0.x)/sx,
|
|
2564
|
+
y:(clientY-rect.top-p0.y)/sy,
|
|
2565
|
+
};
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
/**
|
|
2569
|
+
* Pose `boneName` on stage in `mode` ('rotate' or 'translate') at viewport client coordinates
|
|
2570
|
+
* `(clientX, clientY)`. When the playhead sits on an existing key (within 5e-4 s), sets that key's
|
|
2571
|
+
* value; otherwise inserts a key at the playhead (`this.at`) and sets it as one undo group.
|
|
2572
|
+
*/
|
|
2573
|
+
poseBoneOnStage(
|
|
2574
|
+
boneName:string,
|
|
2575
|
+
mode:'rotate'|'translate',
|
|
2576
|
+
clientX:number,
|
|
2577
|
+
clientY:number,
|
|
2578
|
+
gesture?:{
|
|
2579
|
+
undoGroupId:number;
|
|
2580
|
+
originWorld:{x:number;y:number};
|
|
2581
|
+
parentWorld:{x:number;y:number;a:number;b:number;c:number;d:number};
|
|
2582
|
+
},
|
|
2583
|
+
):{ok:true;ops:readonly AnimationSourceOp[]}|{ok:false;error:string}{
|
|
2584
|
+
const gate=this.gateInfo();
|
|
2585
|
+
if(!gate.editable){
|
|
2586
|
+
const err=`${gate.code}: ${gate.reason??'animation is read-only'}`;
|
|
2587
|
+
this.setEditorStatus(err,true);
|
|
2588
|
+
return {ok:false,error:err};
|
|
2589
|
+
}
|
|
2590
|
+
if(!this.builder||!this.source?.available||!this.inspection){
|
|
2591
|
+
const err='ANIMATION_SOURCE_MISSING: animation source is not loaded';
|
|
2592
|
+
this.setEditorStatus(err,true);
|
|
2593
|
+
return {ok:false,error:err};
|
|
2594
|
+
}
|
|
2595
|
+
const setup=this.inspection.bones.find(b=>b.name===boneName);
|
|
2596
|
+
if(!setup){
|
|
2597
|
+
const err=`ANIMATION_BONE_NO_TRACK: unknown bone "${boneName}"`;
|
|
2598
|
+
this.setEditorStatus(err,true);
|
|
2599
|
+
return {ok:false,error:err};
|
|
2600
|
+
}
|
|
2601
|
+
const clss=this.tracksInfo();
|
|
2602
|
+
const boneTracks=clss.filter(c=>c.targetKind==='bone'&&c.target===boneName);
|
|
2603
|
+
const matchingProps=mode==='rotate'?['rotate']:['translate','translatex','translatey'];
|
|
2604
|
+
const matchingTracks=boneTracks.filter(c=>matchingProps.includes(c.property));
|
|
2605
|
+
const readonlyMatch=matchingTracks.find(c=>!c.editable);
|
|
2606
|
+
if(readonlyMatch){
|
|
2607
|
+
const err=`ANIMATION_TRACK_READ_ONLY: ${readonlyMatch.reason}`;
|
|
2608
|
+
this.setEditorStatus(err,true);
|
|
2609
|
+
return {ok:false,error:err};
|
|
2610
|
+
}
|
|
2611
|
+
// Also check if compiled inspection has a bone track for this property that is missing from source
|
|
2612
|
+
const editableMatches=matchingTracks.filter(c=>c.editable);
|
|
2613
|
+
if(editableMatches.length===0){
|
|
2614
|
+
const constraint=findBoneConstraint(this.document,boneName);
|
|
2615
|
+
if(constraint){
|
|
2616
|
+
const err=`ANIMATION_BONE_CONSTRAINED: bone "${boneName}" is driven by ${constraint.kind} constraint "${constraint.name}" and cannot be posed directly on stage`;
|
|
2617
|
+
this.setEditorStatus(err,true);
|
|
2618
|
+
return {ok:false,error:err};
|
|
2619
|
+
}
|
|
2620
|
+
const compiledOnly=this.inspection.tracks.find(
|
|
2621
|
+
t=>t.kind==='bone'&&t.target===boneName&&matchingProps.includes(t.name),
|
|
2622
|
+
);
|
|
2623
|
+
if(compiledOnly){
|
|
2624
|
+
const err=`ANIMATION_TRACK_READ_ONLY: bone track "${boneName}.${compiledOnly.name}" is not an editable source track in ${this.source.path??'animations_from'}`;
|
|
2625
|
+
this.setEditorStatus(err,true);
|
|
2626
|
+
return {ok:false,error:err};
|
|
2627
|
+
}
|
|
2628
|
+
const err=`ANIMATION_BONE_NO_TRACK: bone "${boneName}" has no editable "${mode}" track in animation "${this.animation}" (${this.source.path??'animations_from'})`;
|
|
2629
|
+
this.setEditorStatus(err,true);
|
|
2630
|
+
return {ok:false,error:err};
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
const worldPt=this.clientToWorld(clientX,clientY);
|
|
2634
|
+
const parentWorld=
|
|
2635
|
+
gesture?.parentWorld??
|
|
2636
|
+
(setup.parent?this.boneWorldMatrix(setup.parent):{x:0,y:0,a:1,b:0,c:0,d:1});
|
|
2637
|
+
const originWorld=gesture?.originWorld??this.boneWorldMatrix(boneName);
|
|
2638
|
+
const det=parentWorld.a*parentWorld.d-parentWorld.b*parentWorld.c;
|
|
2639
|
+
|
|
2640
|
+
let targetOps:Array<{trackIndex:number;property:string;channel?:number;value:number|readonly number[]}>=[];
|
|
2641
|
+
|
|
2642
|
+
if(mode==='rotate'){
|
|
2643
|
+
const rotTrack=editableMatches.find(c=>c.property==='rotate')!;
|
|
2644
|
+
const vx=worldPt.x-originWorld.x;
|
|
2645
|
+
const vy=worldPt.y-originWorld.y;
|
|
2646
|
+
if(Math.hypot(vx,vy)<1e-6){
|
|
2647
|
+
return {ok:true,ops:this.builder.ops};
|
|
2648
|
+
}
|
|
2649
|
+
const lvx=Math.abs(det)>1e-8?(parentWorld.d*vx-parentWorld.b*vy)/det:vx;
|
|
2650
|
+
const lvy=Math.abs(det)>1e-8?(-parentWorld.c*vx+parentWorld.a*vy)/det:vy;
|
|
2651
|
+
const angleDeg=Math.atan2(lvy,lvx)*(180/Math.PI);
|
|
2652
|
+
const rawDelta=angleDeg-(setup.rotation??0);
|
|
2653
|
+
const wrapped=((((rawDelta+180)%360)+360)%360)-180;
|
|
2654
|
+
const rotVal=cleanMotionNumber(wrapped);
|
|
2655
|
+
targetOps=[{trackIndex:rotTrack.trackIndex,property:'rotate',value:[rotVal]}];
|
|
2656
|
+
}else{
|
|
2657
|
+
const dx=worldPt.x-parentWorld.x;
|
|
2658
|
+
const dy=worldPt.y-parentWorld.y;
|
|
2659
|
+
const localX=Math.abs(det)>1e-8?(parentWorld.d*dx-parentWorld.b*dy)/det:dx;
|
|
2660
|
+
const localY=Math.abs(det)>1e-8?(-parentWorld.c*dx+parentWorld.a*dy)/det:dy;
|
|
2661
|
+
const trackValX=cleanMotionNumber(localX-(setup.x??0));
|
|
2662
|
+
const trackValY=cleanMotionNumber(localY-(setup.y??0));
|
|
2663
|
+
const tr2d=editableMatches.find(c=>c.property==='translate');
|
|
2664
|
+
if(tr2d){
|
|
2665
|
+
targetOps=[{trackIndex:tr2d.trackIndex,property:'translate',value:[trackValX,trackValY]}];
|
|
2666
|
+
}else{
|
|
2667
|
+
const trx=editableMatches.find(c=>c.property==='translatex');
|
|
2668
|
+
const tryTrack=editableMatches.find(c=>c.property==='translatey');
|
|
2669
|
+
if(trx)targetOps.push({trackIndex:trx.trackIndex,property:'translatex',value:[trackValX]});
|
|
2670
|
+
if(tryTrack)targetOps.push({trackIndex:tryTrack.trackIndex,property:'translatey',value:[trackValY]});
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
|
|
2674
|
+
const groupId=gesture?.undoGroupId??this.builder.beginUndoGroup();
|
|
2675
|
+
const savedText=this.builder.text;
|
|
2676
|
+
try{
|
|
2677
|
+
this.options.pause?.();
|
|
2678
|
+
if(gesture){
|
|
2679
|
+
this.builder.unwindUndoGroup(groupId);
|
|
2680
|
+
}
|
|
2681
|
+
let keyCountChanged=false;
|
|
2682
|
+
const playheadTime=cleanMotionNumber(this.at);
|
|
2683
|
+
this.builder.withUndoGroup(groupId,()=>{
|
|
2684
|
+
for(const item of targetOps){
|
|
2685
|
+
const beforeKeys=this.readDraftTrackKeys(item.trackIndex);
|
|
2686
|
+
const existingIdx=beforeKeys.findIndex(k=>Math.abs(k.t-playheadTime)<=5e-4);
|
|
2687
|
+
const arrVal=Array.isArray(item.value)?item.value:[item.value as number];
|
|
2688
|
+
if(existingIdx>=0){
|
|
2689
|
+
this.builder!.apply({
|
|
2690
|
+
op:'set_key_value',
|
|
2691
|
+
animation:this.animation,
|
|
2692
|
+
track:item.trackIndex,
|
|
2693
|
+
key:existingIdx,
|
|
2694
|
+
value:arrVal,
|
|
2695
|
+
});
|
|
2696
|
+
const inspTrack=this.inspection?.tracks.find(t=>t.kind==='bone'&&t.target===boneName&&t.name===item.property);
|
|
2697
|
+
const sel={animation:this.animation,trackIndex:item.trackIndex,keyIndex:existingIdx,pointer:inspTrack?.pointer??''};
|
|
2698
|
+
this.selectedKey=sel;
|
|
2699
|
+
this.selectedKeys=[sel];
|
|
2700
|
+
}else{
|
|
2701
|
+
this.builder!.apply({
|
|
2702
|
+
op:'insert_key',
|
|
2703
|
+
animation:this.animation,
|
|
2704
|
+
track:item.trackIndex,
|
|
2705
|
+
time:playheadTime,
|
|
2706
|
+
value:arrVal,
|
|
2707
|
+
});
|
|
2708
|
+
const afterKeys=this.readDraftTrackKeys(item.trackIndex);
|
|
2709
|
+
const newIdx=afterKeys.findIndex(k=>Math.abs(k.t-playheadTime)<=5e-4);
|
|
2710
|
+
const inspTrack=this.inspection?.tracks.find(t=>t.kind==='bone'&&t.target===boneName&&t.name===item.property);
|
|
2711
|
+
if(newIdx>=0){
|
|
2712
|
+
const sel={animation:this.animation,trackIndex:item.trackIndex,keyIndex:newIdx,pointer:inspTrack?.pointer??''};
|
|
2713
|
+
this.selectedKey=sel;
|
|
2714
|
+
this.selectedKeys=[sel];
|
|
2715
|
+
}
|
|
2716
|
+
const domLaneKeys=this.options.host.querySelectorAll(`.animation-key[data-source-track="${item.trackIndex}"]`).length;
|
|
2717
|
+
if(domLaneKeys!==afterKeys.length)keyCountChanged=true;
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
});
|
|
2721
|
+
this.syncEffectiveInspection(true);
|
|
2722
|
+
this.renderEditorBar();
|
|
2723
|
+
if(keyCountChanged){
|
|
2724
|
+
this.renderTimeline();
|
|
2725
|
+
}else{
|
|
2726
|
+
this.syncTimelineKeysInPlace();
|
|
2727
|
+
this.syncKeyInspectorInPlace();
|
|
2728
|
+
}
|
|
2729
|
+
this.renderChannels();
|
|
2730
|
+
this.setEditorStatus(
|
|
2731
|
+
`Posed bone "${boneName}" (${mode}) at ${formatSeconds(playheadTime)} s (${this.builder.ops.length} pending op(s), preview active).`,
|
|
2732
|
+
false,
|
|
2733
|
+
);
|
|
2734
|
+
return {ok:true,ops:this.builder.ops};
|
|
2735
|
+
}catch(e){
|
|
2736
|
+
if(this.builder.text!==savedText&&gesture){
|
|
2737
|
+
this.builder.unwindUndoGroup(groupId);
|
|
2738
|
+
}
|
|
2739
|
+
const msg=e instanceof Error?e.message:String(e);
|
|
2740
|
+
this.setEditorStatus(msg,true);
|
|
2741
|
+
return {ok:false,error:msg};
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
private bindStageBoneDrag(btn:HTMLButtonElement,boneName:string){
|
|
2746
|
+
btn.addEventListener('pointerdown',e=>{
|
|
2747
|
+
if(!e.isPrimary||e.button!==0||this.isBusy||this.space)return;
|
|
2748
|
+
e.stopPropagation();
|
|
2749
|
+
const mode:'rotate'|'translate'=e.altKey?(this.poseMode==='rotate'?'translate':'rotate'):this.poseMode;
|
|
2750
|
+
const targetBone=this.resolveBoneForStageDrag(boneName,mode);
|
|
2751
|
+
const setup=this.inspection?.bones.find(b=>b.name===targetBone);
|
|
2752
|
+
const originWorld=this.boneWorldMatrix(targetBone);
|
|
2753
|
+
const parentWorld=setup?.parent?this.boneWorldMatrix(setup.parent):{x:0,y:0,a:1,b:0,c:0,d:1};
|
|
2754
|
+
const undoGroupId=this.builder?this.builder.beginUndoGroup():1;
|
|
2755
|
+
this.draggingStageBone={
|
|
2756
|
+
pointerId:e.pointerId,
|
|
2757
|
+
boneName:targetBone,
|
|
2758
|
+
mode,
|
|
2759
|
+
startX:e.clientX,
|
|
2760
|
+
startY:e.clientY,
|
|
2761
|
+
moved:false,
|
|
2762
|
+
undoGroupId,
|
|
2763
|
+
originWorld:{x:originWorld.x,y:originWorld.y},
|
|
2764
|
+
parentWorld,
|
|
2765
|
+
};
|
|
2766
|
+
btn.setPointerCapture?.(e.pointerId);
|
|
2767
|
+
});
|
|
2768
|
+
|
|
2769
|
+
btn.addEventListener('pointermove',e=>{
|
|
2770
|
+
const drag=this.draggingStageBone;
|
|
2771
|
+
if(!drag||drag.pointerId!==e.pointerId)return;
|
|
2772
|
+
if(!drag.moved&&Math.hypot(e.clientX-drag.startX,e.clientY-drag.startY)<2)return;
|
|
2773
|
+
if(!drag.moved){
|
|
2774
|
+
drag.moved=true;
|
|
2775
|
+
this.suppressNextBoneClick=true;
|
|
2776
|
+
this.select({kind:'bone',name:drag.boneName});
|
|
2777
|
+
}
|
|
2778
|
+
const activeMode:'rotate'|'translate'=e.altKey?(this.poseMode==='rotate'?'translate':'rotate'):drag.mode;
|
|
2779
|
+
this.poseBoneOnStage(drag.boneName,activeMode,e.clientX,e.clientY,{
|
|
2780
|
+
undoGroupId:drag.undoGroupId,
|
|
2781
|
+
originWorld:drag.originWorld,
|
|
2782
|
+
parentWorld:drag.parentWorld,
|
|
2783
|
+
});
|
|
2784
|
+
});
|
|
2785
|
+
|
|
2786
|
+
const endBoneDrag=(e:PointerEvent)=>{
|
|
2787
|
+
const drag=this.draggingStageBone;
|
|
2788
|
+
if(!drag||drag.pointerId!==e.pointerId)return;
|
|
2789
|
+
this.draggingStageBone=null;
|
|
2790
|
+
if(btn.hasPointerCapture?.(e.pointerId))btn.releasePointerCapture(e.pointerId);
|
|
2791
|
+
if(drag.moved){
|
|
2792
|
+
e.preventDefault();
|
|
2793
|
+
setTimeout(()=>{this.suppressNextBoneClick=false;},0);
|
|
2794
|
+
}
|
|
2795
|
+
};
|
|
2796
|
+
btn.addEventListener('pointerup',endBoneDrag);
|
|
2797
|
+
btn.addEventListener('pointercancel',endBoneDrag);
|
|
2798
|
+
}
|
|
2799
|
+
|
|
1869
2800
|
capture(player:Pick<RigPlayer,'bone'>|null,frame:PosedFrame|undefined){
|
|
1870
|
-
this.frame=frame??null;this.bones.clear();
|
|
2801
|
+
this.frame=frame??null;this.bones.clear();
|
|
2802
|
+
for(const b of player&&frame?this.inspection?.bones??[]:[]){
|
|
2803
|
+
try{
|
|
2804
|
+
const p=player!.bone(b.name) as {x:number;y:number;active:boolean;a?:number;b?:number;c?:number;d?:number};
|
|
2805
|
+
if(p.active){
|
|
2806
|
+
const hasMatrix=typeof p.a==='number'&&typeof p.b==='number'&&typeof p.c==='number'&&typeof p.d==='number';
|
|
2807
|
+
this.bones.set(b.name,{
|
|
2808
|
+
x:p.x,
|
|
2809
|
+
y:p.y,
|
|
2810
|
+
a:hasMatrix?p.a!:1,
|
|
2811
|
+
b:hasMatrix?p.b!:0,
|
|
2812
|
+
c:hasMatrix?p.c!:0,
|
|
2813
|
+
d:hasMatrix?p.d!:1,
|
|
2814
|
+
hasMatrix,
|
|
2815
|
+
});
|
|
2816
|
+
}
|
|
2817
|
+
}catch{/* unavailable bones have no stage handle */}
|
|
2818
|
+
}
|
|
2819
|
+
this.redraw();
|
|
1871
2820
|
}
|
|
1872
2821
|
|
|
1873
2822
|
redraw(bonePoints=this.bonePoints){
|
|
1874
2823
|
this.bonePoints=bonePoints;
|
|
1875
2824
|
for(const [name,node]of this.boneButtons)if(!this.bones.has(name)){node.remove();this.boneButtons.delete(name);}
|
|
1876
|
-
const {stage}=this.options,selected=this.selection.value();
|
|
1877
|
-
|
|
1878
|
-
|
|
2825
|
+
const {stage}=this.options,selected=this.selection.value();
|
|
2826
|
+
stage.dataset.heldFrame=this.frame?'available':'unavailable';
|
|
2827
|
+
stage.dataset.selectedKind=selected?.kind??'';
|
|
2828
|
+
stage.dataset.selectedName=selected?.name??'';
|
|
2829
|
+
const enabled=this.options.enabled();
|
|
2830
|
+
this.picks.hidden=!enabled;
|
|
2831
|
+
const otherMode:'rotate'|'translate'=this.poseMode==='rotate'?'translate':'rotate';
|
|
2832
|
+
let order=0;
|
|
2833
|
+
for(const [name,p]of this.bones){
|
|
2834
|
+
let b=this.boneButtons.get(name);
|
|
2835
|
+
if(!b){
|
|
2836
|
+
b=button('',()=>{
|
|
2837
|
+
if(this.suppressNextBoneClick){
|
|
2838
|
+
this.suppressNextBoneClick=false;
|
|
2839
|
+
return;
|
|
2840
|
+
}
|
|
2841
|
+
const targetName=this.resolveBoneForStageClick(name);
|
|
2842
|
+
this.select({kind:'bone',name:targetName});
|
|
2843
|
+
});
|
|
2844
|
+
b.className='animation-bone-pick';
|
|
2845
|
+
b.title=`Select or drag bone ${name}`;
|
|
2846
|
+
b.setAttribute('aria-label',`Select bone ${name}`);
|
|
2847
|
+
b.dataset.bone=name;
|
|
2848
|
+
this.bindStageBoneDrag(b,name);
|
|
2849
|
+
this.boneButtons.set(name,b);
|
|
2850
|
+
this.picks.append(b);
|
|
2851
|
+
}
|
|
2852
|
+
const isSelected=selected?.kind==='bone'&&selected.name===name;
|
|
2853
|
+
const visible=enabled&&(bonePoints||isSelected);
|
|
2854
|
+
b.hidden=!bonePoints&&!isSelected;
|
|
2855
|
+
b.setAttribute('aria-pressed',String(isSelected));
|
|
2856
|
+
if(!visible){
|
|
2857
|
+
order++;
|
|
2858
|
+
continue;
|
|
2859
|
+
}
|
|
2860
|
+
const editableNow=this.isBoneEditableInMode(name,this.poseMode);
|
|
2861
|
+
const editableOther=this.isBoneEditableInMode(name,otherMode);
|
|
2862
|
+
b.dataset.poseEditable=editableNow?'true':editableOther?'other':'false';
|
|
2863
|
+
const zRank=isSelected&&editableNow
|
|
2864
|
+
?500
|
|
2865
|
+
:editableNow
|
|
2866
|
+
?400-Math.min(90,this.firstEditableTrackIndexForBone(name,this.poseMode))
|
|
2867
|
+
:isSelected||editableOther
|
|
2868
|
+
?200+order
|
|
2869
|
+
:100+order;
|
|
2870
|
+
order++;
|
|
2871
|
+
b.style.zIndex=String(zRank);
|
|
2872
|
+
const at=this.options.project(p.x,p.y);
|
|
2873
|
+
b.style.left=`${at.x}px`;
|
|
2874
|
+
b.style.top=`${at.y}px`;
|
|
1879
2875
|
}
|
|
1880
2876
|
}
|
|
1881
2877
|
|