Skip to content

Commit a2b178a

Browse files
committed
Merge branch 'master' of github.com:OpenPerceptionX/OpenPerceptionX.github.io
2 parents 1c0c318 + a693d20 commit a2b178a

158 files changed

Lines changed: 2343 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎public/EgoHumanoid-V2/.nojekyll‎

Whitespace-only changes.

‎public/EgoHumanoid-V2/app.js‎

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
"use strict";
2+
3+
const tasks = {
4+
laptop: {
5+
name: "Laptop closing", score: "53.33", ego: true,
6+
},
7+
fridge: {
8+
name: "Refrigerator opening", score: "38.33", ego: true,
9+
},
10+
curtain: {
11+
name: "Curtain pulling", score: "53.33", ego: false,
12+
},
13+
drawer: {
14+
name: "Drawer closing", score: "61.67", ego: false,
15+
},
16+
};
17+
18+
const state = { demo: "laptop", ik: "laptop", view: "external" };
19+
const $ = (selector) => document.querySelector(selector);
20+
const $$ = (selector) => [...document.querySelectorAll(selector)];
21+
const announce = (message) => { $("#announcement").textContent = message; };
22+
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
23+
const heroVideos = $$("video[data-hero]");
24+
let previewsPaused = reducedMotion.matches || Boolean(navigator.connection?.saveData);
25+
26+
function nearViewport(video) {
27+
const rect = video.getBoundingClientRect();
28+
return rect.bottom > -240 && rect.top < innerHeight + 240;
29+
}
30+
31+
function loadVideo(video) {
32+
if (!video.getAttribute("src")) {
33+
video.src = video.dataset.src;
34+
video.preload = "metadata";
35+
video.load();
36+
}
37+
}
38+
39+
function clearFeedback(video) {
40+
const frame = video.closest(".video-frame");
41+
frame?.querySelector(".media-error")?.remove();
42+
frame?.querySelector(".media-status")?.remove();
43+
}
44+
45+
function setClip(video, id, label) {
46+
video.pause();
47+
clearFeedback(video);
48+
video.removeAttribute("src");
49+
video.poster = `assets/images/${id}.jpg`;
50+
video.dataset.src = `assets/videos/${id}.mp4`;
51+
video.setAttribute("aria-label", label);
52+
video.load();
53+
if (nearViewport(video)) loadVideo(video);
54+
}
55+
56+
function selectTab(group, task, focus = false) {
57+
state[group] = task;
58+
const tablist = $(`[data-tabs="${group}"]`);
59+
tablist.querySelectorAll("[role=tab]").forEach((tab) => {
60+
const selected = tab.dataset.task === task;
61+
tab.setAttribute("aria-selected", String(selected));
62+
tab.tabIndex = selected ? 0 : -1;
63+
if (selected && focus) tab.focus({ preventScroll: true });
64+
});
65+
$(`#${group}-panel`).setAttribute("aria-labelledby", `${group}-tab-${task}`);
66+
if (group === "ik") renderIK();
67+
announce(`${tasks[task].name} selected.`);
68+
}
69+
70+
function renderIK() {
71+
const foot = state.ik === "drawer";
72+
$("#ik-desc-a").textContent = foot ? "Leg IK; SONIC on remaining joints." : "Arm and waist IK; SONIC legs.";
73+
$("#ik-desc-b").textContent = foot ? "Leg IK + SONIC balance feedback." : "Endpoint IK + SONIC balance feedback.";
74+
$("#ik-desc-c").textContent = foot ? "IK controls the right leg; SONIC elsewhere." : "Arm IK; SONIC waist and legs.";
75+
["a", "b", "c"].forEach((variant) => setClip($(`#ik-video-${variant}`), `ik-${variant}-${state.ik}`, `Online IK variant ${variant.toUpperCase()}: ${tasks[state.ik].name}`));
76+
}
77+
78+
$$('[role="tablist"]').forEach((tablist) => {
79+
tablist.addEventListener("click", (event) => {
80+
const button = event.target.closest("[role=tab]");
81+
if (button) selectTab(tablist.dataset.tabs, button.dataset.task);
82+
});
83+
tablist.addEventListener("keydown", (event) => {
84+
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
85+
event.preventDefault();
86+
const buttons = [...tablist.querySelectorAll("[role=tab]")];
87+
let index = buttons.indexOf(document.activeElement);
88+
if (index < 0) return;
89+
if (event.key === "Home") index = 0;
90+
else if (event.key === "End") index = buttons.length - 1;
91+
else index = (index + (event.key === "ArrowRight" ? 1 : -1) + buttons.length) % buttons.length;
92+
selectTab(tablist.dataset.tabs, buttons[index].dataset.task, true);
93+
});
94+
});
95+
96+
function bindGroupPlayback(button, videos, playLabel, pauseLabel) {
97+
function updateLabel() {
98+
const playing = videos.some((video) => !video.paused && !video.ended);
99+
button.replaceChildren(Object.assign(document.createElement("span"), { textContent: playing ? "Ⅱ" : "▶" }), document.createTextNode(` ${playing ? pauseLabel : playLabel}`));
100+
button.firstElementChild.setAttribute("aria-hidden", "true");
101+
button.setAttribute("aria-pressed", String(playing));
102+
}
103+
videos.forEach((video) => ["play", "pause", "ended", "emptied"].forEach((event) => video.addEventListener(event, updateLabel)));
104+
button.addEventListener("click", async () => {
105+
if (videos.some((video) => !video.paused && !video.ended)) {
106+
videos.forEach((video) => video.pause());
107+
} else {
108+
heroVideos.forEach((video) => video.pause());
109+
const results = await Promise.allSettled(videos.map((video) => {
110+
loadVideo(video);
111+
if (video.ended) video.currentTime = 0;
112+
return video.play();
113+
}));
114+
if (results.some((result) => result.status === "rejected")) announce("One or more clips could not start. Use the video controls to retry.");
115+
}
116+
updateLabel();
117+
});
118+
}
119+
120+
bindGroupPlayback($("#play-ik"), ["a", "b", "c"].map((variant) => $(`#ik-video-${variant}`)), "Play all three", "Pause all three");
121+
122+
const videoLoader = new IntersectionObserver((entries) => {
123+
entries.forEach(({ target, isIntersecting }) => {
124+
if (isIntersecting) loadVideo(target);
125+
});
126+
}, { rootMargin: "200px 0px" });
127+
128+
$$('.video-frame video').forEach((video) => {
129+
videoLoader.observe(video);
130+
let waitingTimer;
131+
video.addEventListener("waiting", () => {
132+
clearTimeout(waitingTimer);
133+
waitingTimer = setTimeout(() => {
134+
const frame = video.closest(".video-frame");
135+
if (video.paused || video.error || frame.querySelector(".media-status")) return;
136+
const status = Object.assign(document.createElement("span"), { className: "media-status", textContent: "Loading video…" });
137+
status.setAttribute("role", "status");
138+
frame.append(status);
139+
}, 800);
140+
});
141+
["playing", "canplay", "emptied", "pause"].forEach((event) => video.addEventListener(event, () => {
142+
clearTimeout(waitingTimer);
143+
video.closest(".video-frame").querySelector(".media-status")?.remove();
144+
}));
145+
video.addEventListener("error", () => {
146+
if (!video.getAttribute("src") || !video.error || video.error.code === 1) return;
147+
clearFeedback(video);
148+
const error = Object.assign(document.createElement("div"), { className: "media-error" });
149+
const message = Object.assign(document.createElement("p"), { textContent: "This video could not load." });
150+
const retry = Object.assign(document.createElement("button"), { textContent: "Retry video", type: "button" });
151+
retry.addEventListener("click", () => { clearFeedback(video); video.load(); video.play().catch(() => {}); });
152+
const link = Object.assign(document.createElement("a"), { href: video.dataset.src, textContent: "Open MP4", target: "_blank", rel: "noopener" });
153+
error.append(message, retry, link);
154+
video.closest(".video-frame").append(error);
155+
});
156+
});
157+
158+
function updatePreviewButton() {
159+
const button = $("#preview-toggle");
160+
button.setAttribute("aria-pressed", String(previewsPaused));
161+
button.querySelector(".play-icon").textContent = previewsPaused ? "▶" : "Ⅱ";
162+
button.lastElementChild.textContent = previewsPaused ? "Play previews" : "Pause previews";
163+
}
164+
165+
function playPreview(video) {
166+
if (previewsPaused || document.hidden || !nearViewport(video)) return;
167+
loadVideo(video);
168+
video.play().catch(() => {
169+
previewsPaused = true;
170+
heroVideos.forEach((preview) => preview.pause());
171+
updatePreviewButton();
172+
});
173+
}
174+
175+
const previewObserver = new IntersectionObserver((entries) => {
176+
entries.forEach(({ target, isIntersecting }) => {
177+
if (isIntersecting) playPreview(target);
178+
else target.pause();
179+
});
180+
}, { threshold: .15 });
181+
heroVideos.forEach((video) => previewObserver.observe(video));
182+
updatePreviewButton();
183+
$("#preview-toggle").addEventListener("click", () => {
184+
previewsPaused = !previewsPaused;
185+
heroVideos.forEach((video) => previewsPaused ? video.pause() : playPreview(video));
186+
updatePreviewButton();
187+
});
188+
reducedMotion.addEventListener("change", (event) => {
189+
if (event.matches) {
190+
previewsPaused = true;
191+
heroVideos.forEach((video) => video.pause());
192+
updatePreviewButton();
193+
}
194+
});
195+
document.addEventListener("visibilitychange", () => {
196+
if (document.hidden) $$("video").forEach((video) => video.pause());
197+
else heroVideos.forEach(playPreview);
198+
});
199+
200+
const navToggle = $(".nav-toggle");
201+
function closeNavigation() {
202+
navToggle.setAttribute("aria-expanded", "false");
203+
$("#section-links").classList.remove("is-open");
204+
}
205+
navToggle.addEventListener("click", () => {
206+
const open = navToggle.getAttribute("aria-expanded") !== "true";
207+
navToggle.setAttribute("aria-expanded", String(open));
208+
$("#section-links").classList.toggle("is-open", open);
209+
});
210+
$(".section-nav").addEventListener("keydown", (event) => {
211+
if (event.key === "Escape") { closeNavigation(); navToggle.focus(); }
212+
});
213+
$$('.section-links a').forEach((link) => link.addEventListener("click", closeNavigation));
214+
document.addEventListener("click", (event) => {
215+
if (!event.target.closest(".section-nav")) closeNavigation();
216+
});
217+
window.matchMedia("(min-width: 75rem)").addEventListener("change", closeNavigation);
218+
219+
const sections = $$('main > section[id]');
220+
const sectionLinks = $$(".section-links a");
221+
let scrollUpdatePending = false;
222+
function updateScrollPosition() {
223+
const total = document.documentElement.scrollHeight - innerHeight;
224+
const progress = total > 0 ? Math.min(1, Math.max(0, scrollY / total)) : 0;
225+
$(".reading-progress").style.transform = `scaleX(${progress})`;
226+
$(".masthead").classList.toggle("is-scrolled", scrollY > 40);
227+
$(".section-nav").classList.toggle("on-hero", $("#introduction").getBoundingClientRect().bottom > innerHeight * .5);
228+
let current = sections[0].id;
229+
sections.forEach((section) => {
230+
if (section.getBoundingClientRect().top <= innerHeight * .33) current = section.id;
231+
});
232+
if (progress > .99) current = sections.at(-1).id;
233+
current = ({ results: "scaling", "online-ik": "scaling", "data-collection": "visual-alignment" })[current] || current;
234+
sectionLinks.forEach((link) => {
235+
if (link.hash === `#${current}`) link.setAttribute("aria-current", "location");
236+
else link.removeAttribute("aria-current");
237+
});
238+
scrollUpdatePending = false;
239+
}
240+
function scheduleScrollUpdate() {
241+
if (scrollUpdatePending) return;
242+
scrollUpdatePending = true;
243+
requestAnimationFrame(updateScrollPosition);
244+
}
245+
window.addEventListener("scroll", scheduleScrollUpdate, { passive: true });
246+
window.addEventListener("resize", scheduleScrollUpdate, { passive: true });
247+
$$('details').forEach((details) => details.addEventListener("toggle", scheduleScrollUpdate));
248+
updateScrollPosition();
249+
250+
// The source image stays directly accessible when JavaScript is unavailable.
251+
const figureDialog = $(".figure-dialog");
252+
let figureOpener = null;
253+
$$('[data-figure]').forEach((link) => {
254+
link.addEventListener("click", (event) => {
255+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
256+
event.preventDefault();
257+
figureOpener = link;
258+
const source = link.querySelector("img");
259+
$("#figure-dialog-image").src = link.href;
260+
$("#figure-fullsize").href = link.href;
261+
$("#figure-dialog-image").alt = source.alt;
262+
$("#figure-dialog-caption").textContent = link.closest("figure").querySelector("h3")?.textContent || "EgoHumanoid-V2 · Research figure";
263+
figureDialog.showModal();
264+
});
265+
});
266+
$("#close-figure").addEventListener("click", () => figureDialog.close());
267+
figureDialog.addEventListener("click", (event) => {
268+
if (event.target !== figureDialog) return;
269+
const rect = figureDialog.getBoundingClientRect();
270+
if (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom) figureDialog.close();
271+
});
272+
figureDialog.addEventListener("close", () => figureOpener?.focus({ preventScroll: true }));
273+
274+
// Keep a real frame visible until the first decoded video frame is ready.
275+
$$('video').forEach(video => {
276+
const thumb = video.parentElement.querySelector('.video-thumbnail');
277+
const pending = () => {
278+
if (thumb) thumb.src = video.poster;
279+
video.classList.add('poster-pending');
280+
video.parentElement.classList.remove('video-ready');
281+
};
282+
const ready = () => { if (video.readyState >= 2) {video.classList.remove('poster-pending');video.parentElement.classList.add('video-ready');} };
283+
['loadstart','emptied','error'].forEach(event => video.addEventListener(event,pending));
284+
['loadeddata','canplay','playing','seeked'].forEach(event => video.addEventListener(event,ready));
285+
new MutationObserver(pending).observe(video,{attributes:true,attributeFilter:['poster']});
286+
ready();
287+
});
53.6 MB
Binary file not shown.
Binary file not shown.
166 KB
Loading
400 KB
Loading

0 commit comments

Comments
 (0)