From 59ec52eccad489fa49caee99669c82b646898c0a Mon Sep 17 00:00:00 2001 From: hnmr293 Date: Mon, 6 Mar 2023 23:20:47 +0900 Subject: [PATCH] fix #12 --- index.html | 2 ++ javascript/lazyload/posex-webui.js | 7 +++++++ js/app.js | 1 + js/posex.js | 16 ++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/index.html b/index.html index 49aa62f..0d87505 100644 --- a/index.html +++ b/index.html @@ -54,6 +54,8 @@ +
- Others
+
diff --git a/javascript/lazyload/posex-webui.js b/javascript/lazyload/posex-webui.js index 17a9b58..6b26c86 100644 --- a/javascript/lazyload/posex-webui.js +++ b/javascript/lazyload/posex-webui.js @@ -142,6 +142,10 @@ const { init, init_3d } = await _import(); const elliptic_limbs_label = $('label'); const elliptic_limbs = $('input'); elliptic_limbs.type = 'checkbox'; elliptic_limbs.classList.add('posex_joints', 'posex_elliptic_limbs'); elliptic_limbs.checked = true; elliptic_limbs_label.append(elliptic_limbs, document.createTextNode('Elliptic Limbs')); + const other_marker = $('div'); other_marker.textContent = '- Others'; + const low_fps_label = $('label'); + const low_fps = $('input'); low_fps.type = 'checkbox'; low_fps.classList.add('posex_low_fps', 'posex_others'); low_fps.checked = false; + low_fps_label.append(low_fps, document.createTextNode('Low fps')); const setting_cont = $('div'); setting_cont.classList.add('posex_setting_cont'); @@ -159,6 +163,8 @@ const { init, init_3d } = await _import(); joint_marker, limb_width_label, elliptic_limbs_label, + other_marker, + low_fps_label, ); const canvas_cont = $('div'); @@ -247,6 +253,7 @@ const { init, init_3d } = await _import(); reset_bg, limb_width, elliptic_limbs, + low_fps, save, copy, save_pose, diff --git a/js/app.js b/js/app.js index 825a5c1..20a0dd0 100644 --- a/js/app.js +++ b/js/app.js @@ -94,6 +94,7 @@ document.addEventListener('DOMContentLoaded', async () => { elliptic_limbs: document.querySelector('#elliptic_limbs'), //joint_radius: document.querySelector('#joint_radius'), limb_width: document.querySelector('#limb_width'), + low_fps: document.querySelector('#low_fps'), save: document.querySelector('#save_button'), copy: document.querySelector('#copy_button'), save_pose: document.querySelector('#save_pose'), diff --git a/js/posex.js b/js/posex.js index 5e8fc22..391933f 100644 --- a/js/posex.js +++ b/js/posex.js @@ -607,9 +607,22 @@ function init_3d(ui) { mesh.geometry.setPoints(limb_vecs, elliptic_limbs ? elliptic_limb_width : stick_limb_width); } + let low_fps = ui.low_fps ? !!ui.low_fps.checked : false; + if (ui.low_fps) + ui.low_fps.addEventListener('change', () => { + low_fps = !!ui.low_fps.checked; + }, false); + let last_zoom = camera.zoom; let running = true; + //const frames = [0,0,0,0,0,0,0,0,0,0], frame_index = 0; + let last_tick = globalThis.performance.now(); const animate = () => { + const t0 = globalThis.performance.now(); + //frames[(frame_index++)%frames.length] = t0 - last_tick; + //last_tick = t0; + //console.log(frames.reduce((acc, cur) => acc + cur) / frames.length); + requestAnimationFrame(animate); if (!running) return; @@ -620,6 +633,9 @@ function init_3d(ui) { } controls.update(); + if (low_fps && t0 - last_tick < 30) return; // nearly 30fps + last_tick = t0; + for (let [name, body] of bodies) { const { joints, limbs, group } = body;