Repository navigation
Expand file tree
/
Copy pathIndex.js
More file actions
649 lines (541 loc) · 30.7 KB
/
Copy pathIndex.js
File metadata and controls
649 lines (541 loc) · 30.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
import { Animics } from './src/Animics.js'
import { UTILS } from './src/Utils.js'
import { LX } from 'lexgui';
// Wait until the session is loaded
UTILS.makeLoading("Loading application, please wait");
let limit = 10, offset = 0;
const animics = new Animics();
const connected = await animics.loadSession();
const mobile = navigator && /Android|iPhone/i.test(navigator.userAgent);
LX.setThemeColor( 'blue' );
const mainArea = await LX.init( { rootClass: "" } );
const [warningArea, area] = mainArea.split( { sizes: ["2.5rem", null], type: "vertical", minimizable: false, resize: false});
const dropOver = LX.makeContainer(["100%", "100%"], "border-dashed overlay-top bg-neutral-800 z-100 data-[disabled=true]:opacity-50 content-center text-center text-4xl text-muted-foreground hidden","Drop files here", LX.mainArea.root );
dropOver.setAttribute("data-disabled", true);
// Menubar
let menubar = null;
let buttonsContainer = null;
const sidebar = createSideBar( area );
menubar = createMenuBar( area );
const content = LX.makeContainer( ["100%", "100%"], "relative flex flex-col px-1", "", area );
const home = createHome( content );
const about = createAbout( content );
createFooter();
bindEvents( area );
// try to load system warnings (file). If non existant, just continue as if nothing happened.
// It makes it easy to display warnings without having to rebuild animics
fetch("systemWarnings/warnings.json")
.then((Response)=>{ return Response.json() })
.then( json => {
if ( Array.isArray( json ) && json.length ) {
if( json[0].type == 0 ) {
const warning = json[0];
const container = LX.makeContainer( ["auto", "100%"], "flex flex-row gap-2 ml-auto bg-primary items-center justify-center italic", `<p>${warning.message}</p>`, warningArea);
if( warning.button || json.length > 1 ) {
const button = new LX.Button("more-info", warning.button || "More info", () => { showSystemWarnings( json, 1 ); }, {hideName: true, width: "100px", buttonClass: "warning"});
container.appendChild(button.root);
}
}
}
else {
mainArea._moveSplit(100);
}
} )
.catch( (e)=>{
mainArea._moveSplit(100);
console.warn(e)
}
);
UTILS.hideLoading();
const body = area.root;
body.classList.remove("hidden");
// displays system warnings as modals, one at a time.
function showSystemWarnings( systemWarningsArray, index ){
const warning = systemWarningsArray[index];
let titleIcon = "";
if ( warning.titleIcon ){
titleIcon = LX.makeIcon(warning.titleIcon, { svgClass: warning.svgClass }).innerHTML + " ";
}
if ( warning.titleSvg ){
const iconName = `_system_warning_${index}_`;
LX.registerIcon( iconName, warning.titleSvg );
titleIcon = LX.makeIcon(iconName, { svgClass: warning.svgClass }).innerHTML + " ";
}
const container = document.createElement("div")
LX.makeContainer(["auto", "auto"], "flex flex-row justify-start items-center", titleIcon + warning.title, container);
const dialog = new LX.Dialog( container.innerHTML, p => {
p.root.classList.remove("overflow-y-scroll");
p.root.classList.add("overflow-hidden");
const textarea = p.addTextArea(null, warning.message , null, {disabled: true, fitHeight: true }).root.querySelector("textarea");
textarea.className = LX.mergeClass( textarea.className, "bg-none text-primary");
p.sameLine(1, 'justify-end')
p.addButton( null, warning.txtButton || "Continue", ()=>{
dialog.destroy();
// display next queued warning
index++;
if ( systemWarningsArray.length > index ){
// timeout so user notices a change of warning
setTimeout( ()=>{
showSystemWarnings(systemWarningsArray, index);
}, 200 );
}
}, { buttonClass: 'primary', width: "100px" });
}, {modal: true, closable: true, size: ["40%", "fit-content"], icon: "Trash", className: "overflow-none"});
dialog.root.style.border = "1px solid var(--foreground)";
dialog.root.style.maxHeight = "80%";
}
if( !connected ) {
showSystemWarnings( [{title: "Database Connection Error!", titleIcon: "TriangleAlert@solid", svgClass: "text-orange-500", txt: "Unable to connect to the database. Login and saving animations are currently unavailable. Please export and download your animations before closing to avoid losing your work." }], 0)
}
function createMenuBar( area ) {
buttonsContainer = LX.makeContainer( ["auto", "auto"], "flex flex-row gap-2 ml-auto", "", menubar.root);
const signupButton = LX.makeContainer( ["100px", "auto"], "text-md font-medium rounded-lg p-2 ml-auto text-primary border hover:bg-accent self-center content-center text-center cursor-pointer select-none", "Sign Up", buttonsContainer );
signupButton.tabIndex = "1";
signupButton.role = "button";
LX.listen( signupButton, "click", () => {
animics.showCreateAccountDialog( { user: "", password: "" }, _checkSession );
} );
signupButton.id = "signup-button";
const loginButton = LX.makeContainer( ["100px", "auto"], "text-md font-medium rounded-lg p-2 ml-auto bg-primary text-white hover:bg-mix self-center content-center text-center cursor-pointer select-none", "Login", buttonsContainer );
loginButton.tabIndex = "1";
loginButton.role = "button";
LX.listen( loginButton, "click", () => {
animics.showLoginModal( _checkSession );
} );
loginButton.id = "login-button";
loginButton.style.minWidth = "100px";
const userButton = LX.makeContainer( ["auto", "auto"], "max-w-3xl text-md font-medium rounded-lg p-2 ml-auto bg-primary text-white hover:bg-mix self-center content-center text-center cursor-pointer select-none", animics.fileSystem.session ? animics.fileSystem.session.user.username : "", buttonsContainer );
userButton.tabIndex = "1";
userButton.role = "button";
userButton.style.minWidth = "100px";
LX.listen( userButton, "click", () => {
new LX.DropdownMenu( userButton, [
{ name: "Go to Database", icon: "Server", callback: () => { window.open("https://animics-lfs.gti.upf.edu/src/", "_blank")} },
{ name: "Refresh", icon: "RotateCcw", callback: () => {
offset = 0;
appendAnimationFiles( true );
} },
null,
{ name: "Logout", icon: "LogOut", callback: () => { animics._logout( _checkSession ); } },
], { side: "bottom", align: "end" });
} );
userButton.id = "user-button";
_checkSession();
area = menubar.siblingArea;
area.root.style.placeContent = "center";
return menubar;
}
function createSideBar( area ) {
const starterTheme = LX.getMode();
// so any theme trigger (browser, SO, anything) will update the image, not only the switch button
LX.addSignal( "@on_new_color_scheme", ( el, value ) => {
const img = document.getElementById("animics-img");
const swapValue = value == "light";
if( img ) {
img.src = "data/imgs/logos/animics_" + (swapValue ? "black" : "white") + ".png";
}
} );
const sidebarCallback = m => {
m.add( "Home", { icon: "House", callback: () => {
about.classList.add("hidden");
home.classList.remove("hidden");
} } );
m.add( "Documentation", { icon: "BookOpen" });
m.add( "Documentation/Keyframe Animation", { xicon: "", callback: () => { window.open( "docs/keyframe" , "_blank" ) } } );
m.add( "Documentation/Script Animation", { xicon: "", callback: () => { window.open( "docs/script" , "_blank" ) } } );
m.add( "About", { icon: "Info", callback: () => {
home.classList.add("hidden");
about.classList.remove("hidden");
} });
m.separator();
m.add( "Switch Theme", {
icon: starterTheme == "dark" ? "Sun" : "Moon",
swap: starterTheme == "dark" ? "Moon" : "Sun",
skipSelection: true, // Alex: This is new too. Useful to avoid non-selectable entries to be selected / deselect others
callback: (v) => {
const swapValue = LX.getMode() == "dark";
LX.switchMode();
// LX.setMode( swapValue ? "light" : "dark" );
}
});
// m.add( "TÀNDEM", { callback: () => {} } );
};
const sidebarOptions = {
filter: false,
headerTitle: `ANIMICS`,
headerSubtitle: `v${ Animics.version }`,
headerImage: "./data/imgs/animics_monster.png",
footerTitle: "TÀNDEM",
footerImage: "./data/imgs/tandem_monster.png",
onHeaderPressed: (e) => { console.log( "onHeaderPressed" ) },
onFooterPressed: (e, element) => {
new LX.DropdownMenu( element, [
"Pages",
{ name: "Main", callback: () => { window.open("https://animics.gti.upf.edu/") } },
{ name: "Animics", callback: () => { window.open("https://animics.gti.upf.edu/") } },
{ name: "Performs", callback: () => { window.open("https://performs.gti.upf.edu/") } },
null,
{
name: "Social Media", submenu: [
{ name: "Github", icon: "Github@solid", callback: () => { window.open("https://github.com/upf-gti/") } },
{ name: "Twitter", icon: "X-Twitter", callback: () => { window.open("https://x.com/gti_upf/") } },
{ name: "Discord", icon: "Discord", callback: () => { window.open("https://discord.gg/9YGrGjnycj") } }
]
}
], { side: "right", align: "end" });
},
collapsed: false,
collapsable: false,
displaySelected: true
};
let sidebar2 = null;
if( mobile )
{
menubar = area.addMenubar();
const sheetArea = new LX.Area({ skipAppend: true });
sheetArea.addSidebar( sidebarCallback, sidebarOptions );
menubar.addButtons([
{
title: "Menu",
icon: "PanelLeft",
callback: (value, event) => {
window.__currentSheet = new LX.Sheet("256px", [ sheetArea ] );
}
}], { float: "left" })
}
else
{
const sidebar1 = area.addSidebar( sidebarCallback, sidebarOptions );
menubar = sidebar1.siblingArea.addMenubar();
}
return sidebar2;
}
function createHome( content ) {
const mainContent = LX.makeContainer( ["100%", "calc(100% - 38px)"], "main-content bg-secondary flex flex-col items-center py-6 rounded-lg overflow-y-auto", "", content );
mainContent.id = "home-container";
const padContainer = LX.makeContainer( ["100%", "auto"], "px-6", "", mainContent );
const headerContent = LX.makeContainer( ["100%", "auto"], "flex flex-row gap-10 p-4 my-6 overflow-scroll", "", padContainer );
headerContent.style.minHeight = "256px";
const _makeProjectOptionItem = ( icon, innerText, outerText, id, parent ) => {
const item = LX.makeContainer( ["auto", "auto"], "flex flex-col gap-3 p-3 text-md rounded-lg hover:bg-accent cursor-pointer", ``, parent );
LX.makeContainer( ["200px", "auto"], "flex flex-col py-6 justify-center items-center content-center rounded-lg gap-3 card-button", `
${LX.makeIcon(icon, {svgClass:"xxxl text-secondary-foreground"}).innerHTML}
<p class="text-sm text-center px-4 text-tertiary ">${ innerText }</p>
`, item );
LX.makeContainer( ["auto", "auto"], "", `<p>${ outerText }</p>`, item );
item.id = id;
};
const keyframeContent = LX.makeContainer( ["auto", "auto"], "flex flex-col", "", headerContent );
LX.makeContainer( ["auto", "auto"], "p-2 font-bold", "Keyframe Animation", keyframeContent );
const keyframeItems = LX.makeContainer( ["auto", "auto"], "flex flex-row p-2", "", keyframeContent );
_makeProjectOptionItem( "PlusCircle@solid", "Create from scratch", "Empty project", "keyframe-project", keyframeItems );
_makeProjectOptionItem( "ClapperboardClosed@solid", "Upload video/s", "From video/s", "video-project", keyframeItems );
_makeProjectOptionItem( "Camera@solid", "Record yourself", "Real-time capture", "webcam-project", keyframeItems );
LX.makeContainer(["2px", "auto"], "flex", '<span style="width: 2px;background-color: var(--color-info);filter: blur(1px);margin: 100px 0px;"></span>', headerContent);
const scriptContent = LX.makeContainer( ["auto", "auto"], "flex flex-col", "", headerContent );
LX.makeContainer( ["auto", "auto"], "p-2 font-bold", "Script Animation", scriptContent );
const scriptItems = LX.makeContainer( ["auto", "auto"], "flex flex-row p-2", "", scriptContent );
_makeProjectOptionItem( "PlusCircle@solid", "Create from scratch", "Empty project", "script-project", scriptItems );
LX.makeContainer(["2px", "auto"], "flex", '<span style="width: 2px;background-color: var(--color-info);filter: blur(1px);margin: 100px 0px;"></span>', headerContent);
const fileContent = LX.makeContainer( ["auto", "auto"], "flex flex-col", "", headerContent );
LX.makeContainer( ["auto", "auto"], "p-2 font-bold", "Edit Animation", fileContent );
const fileItems = LX.makeContainer( ["auto", "auto"], "flex flex-row p-2", "", fileContent );
_makeProjectOptionItem( "FolderOpen@solid", "Upload .bvh, .bvhe, .bml, .sigml or .json file/s", "Drop file/s", "import", fileItems );
const projectsContent = LX.makeContainer( ["100%", "auto"], "flex flex-col gap-4 my-6 p-4", "", padContainer );
LX.makeContainer( ["auto", "auto"], "font-bold", "Animations", projectsContent );
const projectItems = LX.makeContainer( ["100%", "auto"], "grid gap-4 p-4 overflow-y-auto overflow-x-hidden ", "", projectsContent );
projectItems.style.gridTemplateColumns = "repeat(auto-fill, minmax(280px, 1fr))";
projectItems.id = "project-items-container";
const projectText = LX.makeContainer( ["auto", "auto"],"text-md text-secondary-foreground", "<p> Login to see your last animations. </p>", projectsContent);
projectText.id = "project-text";
return mainContent;
}
function createAbout( content ) {
const mainContent = LX.makeContainer( ["100%", "calc(100% - 38px)"], "main-content bg-secondary flex flex-col items-center py-6 rounded-lg hidden", "", content );
mainContent.id = "about-container";
const swapValue = LX.getMode() == "dark";
const headerContent = LX.makeContainer( ["auto", "25%"], "flex flex-row gap-4 my-6 p-8 overflow-scroll items-end justify-center",`<img id="animics-img" class="${mobile? "w-screen" : "h-full"}" src="data/imgs/logos/animics_${(swapValue ? "white" : "black")}.png">` , mainContent );
const container = LX.makeContainer( ["100%", "calc(100% - 25%)"], "flex flex-col overflow-scroll items-center",'' , mainContent );
const infoContainer = LX.makeContainer( ["100%", "auto"], "flex flex-col items-center py-8",'' , container );
infoContainer.style.background = "linear-gradient(0deg, var(--background), transparent)";
const textContent = LX.makeContainer( [`${mobile? "auto" : "30%"}`, "auto"], ` pb-4 flex justify-center ${mobile? "w-screen" : ""}`,`<p class="text-xl font-light text-center p-5" >Animics is an online application to create and
edit animations for 3D humanoid characters,
focused in Sign Language synthesis.</p>` , infoContainer );
const techContent = LX.makeContainer(["auto", "auto"], "flex flex-col items-center gap-4 my-6 py-6 text-secondary-foreground text-lg font-bold", "" , infoContainer);
const techText = LX.makeContainer(["auto","auto"], "py-6", `<p>Developed using</p>`, techContent);
const techLinksContent = LX.makeContainer(["auto", "auto"], `flex ${mobile? "flex-col" : "flex-row"} justify-center items-center gap-12 pb-4`, `
<a class="h-full" href="https://chuoling.github.io/mediapipe/"><img class="hover:scale" style="height:60px; filter:grayscale(1) invert(0.5) brightness(1);" src="https://images.viblo.asia/d70d57f3-6756-47cd-a942-249cc1a7da82.png" alt="Mediapipe"></a>
<a class="h-full" href="https://threejs.org/"><img class="hover:scale" style="height:60px;filter:invert(0.5);" src="https://needle.tools/assets/logo-three.CiaNm32y.png" alt="Threejs"></a>
<a class="h-full" href="https://github.com/jxarco/lexgui.js"><img class="hover:scale" style="height:60px; filter:grayscale(1) invert(0.5) brightness(1);" src="data/imgs/logos/lexgui.png" alt="Lexgui"></a>`, techContent)
const fundingContent = LX.makeContainer(["auto", "auto"], "flex flex-col items-center gap-4 my-6 py-6 text-secondary-foreground text-lg font-bold", "" , infoContainer);
const fundingText = LX.makeContainer(["auto","auto"], "py-6", `<p>Funded by</p>`, fundingContent);
const linksContent = LX.makeContainer(["auto", "auto"], "flex flex-row justify-center gap-12 pb-4", `
<a class="h-full" href="https://signon-project.eu/"><img class="hover:scale" style="height:70px; filter:grayscale(1) invert(1) brightness(0.8);" src="./data/imgs/logos/marco_SignON.png" alt="SignON"></a>
<a class="h-full" href="https://www.upf.edu/web/emerald"><img class="hover:scale" style="height:70px; filter:grayscale(1) invert(1) brightness(0.8);" src="./data/imgs/logos/marco_EMERALD.png" alt="EMERALD"></a>
<a class="h-full" href="https://www.upf.edu/web/gti" style="align-content:center"><img class="py-5 hover:scale" style="height:50px; filter:grayscale(1) invert(1) brightness(0.8);" src="./data/imgs/logos/GTIlogo.png" alt="UPF-GTI"></a>`, fundingContent);
const devContent = LX.makeContainer(["100%", "auto"], "flex flex-col items-center py-8 bg-background text-secondary-foreground text-lg font-bold", "<h3>Implemented by</h3>" , container);
const peopleItems = LX.makeContainer( ["100%", "auto"], "flex flex-row gap-4 my-6 p-8 overflow-scroll items-end justify-center",'' , devContent );
_makePersonItem({name: "Víctor Ubieto Nogales", img: "https://www.upf.edu/documents/115100603/264407312/Victor_cropped.jpg/dd5ee7db-580d-c51c-b499-bbbacbbfbb9e?t=1679569197124", avatar:"./docs/imgs/RPM_Victor.png", email: "victoremilio.ubieto@upf.edu", url:"https://www.upf.edu/web/gti/people/-/asset_publisher/PrrUzDqdWrKt/content/victor-ubieto-nogales/maximized"}, peopleItems);
_makePersonItem({name: "Eva Valls Garolera", img: "https://www.upf.edu/documents/115100603/264407312/unnamed.png/9e17f242-5800-b95d-af77-dd03dbc91b7d?t=1679568161101", avatar:"./docs/imgs/RPM_Eva.png", email: "eva.valls@upf.edu", url: "https://www.upf.edu/web/gti/people/-/asset_publisher/PrrUzDqdWrKt/content/eva-valls-garolera/maximized"}, peopleItems);
_makePersonItem({name: "Jaume Pozo Prades", img: "https://www.upf.edu/image/user_portrait?img_id=183376073&img_id_token=CykVYRbgc1iuesVtnp88oTFB8UA%3D&t=1745944004158", avatar:"./docs/imgs/RPM_Jaume.png", email: "jaume.pozo@upf.edu", url: "https://www.upf.edu/web/gti/people/-/asset_publisher/PrrUzDqdWrKt/content/jaume-pozo-prades/maximized"}, peopleItems);
_makePersonItem({name: "Carol Del Corral Farrarós", img: "https://www.upf.edu/documents/115100603/264407312/DSCN1914-2.jpg/8d97985d-5e38-0a41-e730-aa2444146fed?t=1679568714469", avatar:"./docs/imgs/RPM_Carol.png", email: "carolina.delcorral@upf.edu", url: "https://www.upf.edu/web/gti/people/-/asset_publisher/PrrUzDqdWrKt/content/carolina-del-corral/maximized"}, peopleItems);
_makePersonItem({name: "Alex Rodríguez Corrales", img: "https://www.upf.edu/documents/115100603/0/foto_orla.png/dff9a88c-b762-1f33-466c-c2c1fdd5f07e?t=1680027958307", avatar:"./docs/imgs/RPM_Alex.png", email: "alejandro.rodriguez@upf.edu", url: "https://www.upf.edu/web/gti/people/-/asset_publisher/PrrUzDqdWrKt/content/rodriguez-corrales-alejandro/maximized"}, peopleItems);
return mainContent;
}
function _makeProjectItem( item ) {
const projectText = document.getElementById("project-text");
const projectItems = document.getElementById("project-items-container");
projectText.classList.add("hidden");
let extension = item.filename.split('.');
extension = extension[extension.length - 1];
let color = "--color-info";
switch(extension) {
case "bml": case "sigml":
color = "--color-success";
break;
case "glb":
color = "--color-accent";
break;
}
let div = `<div class="rounded-xl w-full flex justify-center items-center overflow-hidden justify-center hover:scale" style="min-height: 130px;background: var(--background-blur);">
<p class="text-2xl font-extrabold text-secondary-foreground" style="text-shadow: 1px 1px 0px var(${color});">.${extension.toUpperCase()}</p>
</div>`
if( item.img ) {
div = `<img class="w-full hover:scale" style="object-fit:cover" src="${ item.img || "./docs/imgs/editStation.png"} ">`
}
const itemContainer = LX.makeContainer( ["auto", "auto"], "flex flex-col gap-4 p-4 text-md rounded-xl hover:bg-accent hover:scale cursor-pointer", `
<div class="rounded-xl w-full overflow-hidden justify-center" style="height:130px;">
${div}
</div>
<div class="flex flex-row justify-between px-1">
<div class="flex flex-col gap-0.5">
<p>${ item.filename }</p>
<p class="text-sm text-tertiary">Last modified ${ item.timestamp }</p>
</div>
<a class="px-2 py-1 rounded-lg lexicon fa-solid fa-ellipsis-vertical"></a>
</div>
`, projectItems );
itemContainer.addEventListener( "click", () => {
onLoadFiles([{name: item.filename, fullpath: item.fullpath, type: "application/json"}]);
})
const optionsIcon = itemContainer.querySelector( ".lexicon" );
LX.listen( optionsIcon, "click", () => {
new LX.DropdownMenu( optionsIcon, [
{ name: "Duplicate", icon: "Copy", callback: () => {} },
null,
{ name: "Delete", icon: "Trash2" }
], { side: "bottom", align: "start" });
} );
}
function _makePersonItem( item, container ) {
const itemContainer = LX.makeContainer( ["auto", "auto"], "flex flex-col gap-4 p-4 text-md rounded-xl hover:bg-accent cursor-pointer", `
<div class="rounded-xl w-full overflow-hidden card">
<div class="card-inner">
<div class="card-front">
<img class="w-full hover:scale" style="object-fit:cover" src="${ item.avatar || "./docs/imgs/editStation.png"} ">
</div>
<div class="card-back">
<img class="w-full img-top" style="object-fit:cover" src="${ item.img || "./docs/imgs/editStation.png"} ">
</div>
</div>
</div>
<div class="flex flex-row justify-center px-1">
<div class="flex flex-col items-center gap-0.5 text-sm">
<p>${ item.name }</p>
<p class="text-xs text-muted-foreground"> ${ item.email }</p>
</div>
</div>
`, container );
LX.listen( itemContainer, "click", () => {
window.open(item.url, "_blank");
})
}
function createFooter() {
const footer = new LX.Footer( {
className: "left-0 bottom-0 absolute",
parent: content,
credits: `2021-${ new Date().getUTCFullYear() } GTI - UPF | Developed within <a href="https://signon-project.eu/" target="_blank">SignON</a> and <a href="https://www.upf.edu/web/emerald" target="_blank">EMERALD EU H2020</a> projects. Released under the Apache 2.0 License.`,
socials: [
{ title: "Github", link: "https://github.com/upf-gti/", icon: `Github@solid` },
{ title: "X/Twitter", link: "https://x.com/gti_upf/", icon: `X-Twitter` },
{ title: "Discord", link: "https://discord.gg/9YGrGjnycj", icon: `Discord` }
]
} );
const footerCreditsSocials = footer.root.querySelector( ".credits-and-socials" );
footerCreditsSocials.innerHTML = `<img src="data/imgs/logos/GTIlogo.png" width="150px" style="filter:invert(0.5)" draggable="false">` + footerCreditsSocials.innerHTML;
return footer;
}
function bindEvents( area ) {
const keyframeBtn = document.getElementById("keyframe-project");
const videoBtn = document.getElementById("video-project");
const webcamBtn = document.getElementById("webcam-project");
const scriptBtn = document.getElementById("script-project");
const importBtn = document.getElementById("import");
// Keyframe mode
keyframeBtn.addEventListener("click", () => {
startAnimics({mode: "keyframe"});
});
videoBtn.addEventListener("click", () => {
const input = document.createElement('input');
input.type = 'file';
input.multiple = true;
input.click();
input.onchange = (event) => {
onLoadFiles( event.currentTarget.files);
// startAnimics({pendingResources: event.currentTarget.files})
};
});
webcamBtn.addEventListener("click", () => {
startAnimics({mode: "keyframe", capture: true});
});
// Script mode
scriptBtn.addEventListener("click", () => {
startAnimics({mode: "script"});
});
// Import resurces
importBtn.addEventListener("click", () => {
const input = document.createElement('input');
input.type = 'file';
input.multiple = true;
input.click();
input.onchange = (event) => {
onLoadFiles( event.currentTarget.files);
// startAnimics({pendingResources: event.currentTarget.files})
};
});
// Drag and Drop
const body = area.root;
window.ondragenter = ( event ) => {
event.preventDefault();
event.stopImmediatePropagation();
dropOver.classList.remove("hidden");
return false
};
window.ondragleave = ( event ) => {
event.preventDefault();
event.stopImmediatePropagation();
if (event.clientX === 0 && event.clientY === 0) {
dropOver.classList.add("hidden");
}
return false
};
window.ondrop = (event) => {
dropOver.classList.add("hidden");
event.preventDefault();
event.stopPropagation();
if ( onLoadFiles( event.dataTransfer.files ) ){
window.ondrop = null;
}
};
}
function unbindEvents() {
window.ondragenter = null;
window.ondragleave = null;
window.ondrop = null;
}
function startAnimics(settings) {
unbindEvents();
const loadingAnim = UTILS.makeLoading("Starting Animics");
loadingAnim.onfinish = () => {
// Manually resetting lexgui
LX.root.innerHTML = "";
LX.mainArea = new LX.Area( { id: 'mainarea' } );
LX.doAsync( () => animics.init(settings), 150 );
};
window.global = {app: animics};
}
function onLoadFiles( files ) {
if(!files || !files.length) {
return null;
}
let mode = null;
let resultFiles = [];
const animExtensions = ['bvh','bvhe', 'glb', 'json', 'mov'];
const scriptExtensions = ['bml', 'sigml'];
// First valid file will determine the mode. Following files must be of the same format
for( let i = 0; i < files.length; ++i ) {
// MIME type is video
if( files[i].type.startsWith("video/") ) {
if ( !mode ) {
mode = "keyframe";
}
if ( mode == "keyframe" ) {
resultFiles.push( files[i] );
}
continue;
}
// other valid file formats
const extension = UTILS.getExtension(files[i].name.replace(".gz","")).toLowerCase();
if( animExtensions.includes(extension) ) {
if ( !mode ) {
mode = "keyframe";
}
if ( mode == "keyframe") {
resultFiles.push( files[i] );
}
}
if( scriptExtensions.includes(extension) ) {
if ( !mode ) {
mode = "script";
}
if ( mode == "script") {
resultFiles.push( files[i] );
}
}
}
if ( resultFiles.length ) {
return startAnimics({ mode, pendingResources: resultFiles});
}
alert("Format not supported.\n\nFormats accepted:\n\tVideo: 'webm','mp4','ogv','avi', 'mov'\n\tScript animation: 'bml', 'sigml'\n\tKeyframe animation: 'bvh', 'bvhe', 'json'");
return null;
}
function _checkSession() {
const signupButton = document.getElementById("signup-button");
const loginButton = document.getElementById("login-button");
const userButton = document.getElementById("user-button");
if(!animics.fileSystem.session || !animics.fileSystem.session.user || animics.fileSystem.session.user.username == "guest") {
signupButton.classList.remove("hidden");
loginButton.classList.remove("hidden");
userButton.classList.add("hidden");
const projectsContent = document.getElementById("project-items-container");
if(projectsContent) {
projectsContent.innerHTML = "";
const projectText = document.getElementById("project-text");
projectText.classList.remove("hidden");
}
offset=0;
limit = 10;
}
else {
signupButton.classList.add("hidden");
loginButton.classList.add("hidden");
userButton.classList.remove("hidden");
userButton.innerHTML = animics.fileSystem.session.user.username;
appendAnimationFiles();
}
}
function appendAnimationFiles( refresh = false) {
animics.fileSystem.session.getLastFiles(limit, offset, (files) => {
const projectItems = document.getElementById("project-items-container");
if(projectItems && projectItems.lastChild) {
projectItems.lastChild.remove();
if(refresh) {
projectItems.innerHTML = "";
}
}
const projectText = document.getElementById("project-text");
projectText.classList.add("hidden");
files = files ?? [];
for(const data of files) {
_makeProjectItem( data );
}
if(files.length >= limit) {
const itemContainer = LX.makeContainer( ["auto", "162px"], "flex flex-col gap-4 p-4 text-md rounded-xl justify-center items-center", ``, projectItems);
const loadMoreButton = LX.makeContainer( ["60%", "80px"], "text-md font-medium rounded-lg p-2 bg-primary text-white hover:scale self-center content-center text-center cursor-pointer select-none flex flex-col items-center justify-center", `${LX.makeIcon("MoreHorizontal", {svgClass:"xxl text-white"}).innerHTML} <p class="text-lg">LOAD MORE</p>`, itemContainer );
loadMoreButton.tabIndex = "1";
loadMoreButton.role = "button";
LX.listen( loadMoreButton, "click", () => { offset+=10;_checkSession()} );
loadMoreButton.id = "loadmore-button";
}
})
}