<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sergei Trushkin on Medium]]></title>
        <description><![CDATA[Stories by Sergei Trushkin on Medium]]></description>
        <link>https://medium.com/@drblax?source=rss-0f841946b850------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FKJAPsjePsaYy4kVER5WiQ.jpeg</url>
            <title>Stories by Sergei Trushkin on Medium</title>
            <link>https://medium.com/@drblax?source=rss-0f841946b850------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 15:31:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@drblax/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Gesture Recognition
BabylonJS + WebXR]]></title>
            <link>https://medium.com/@drblax/gesture-recognition-babylonjs-webxr-a5d286c62c8f?source=rss-0f841946b850------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5d286c62c8f</guid>
            <category><![CDATA[gesture-recognition]]></category>
            <category><![CDATA[webxr]]></category>
            <category><![CDATA[babylonjs]]></category>
            <dc:creator><![CDATA[Sergei Trushkin]]></dc:creator>
            <pubDate>Tue, 11 Mar 2025 15:15:39 GMT</pubDate>
            <atom:updated>2025-03-11T15:39:28.351Z</atom:updated>
            <content:encoded><![CDATA[<h4>Description of the experience in creating a package and auxiliary utilities for gesture recognition</h4><p>Using human hands as input devices makes VR applications more natural and intuitive. While controllers remain more precise tools, many scenarios allow for a comfortable user experience without them. This issue has become especially relevant with the emergence of standalone VR headsets that come without controllers.</p><p>Web applications running through WebXR in VR device browsers face additional limitations compared to native analogues. Limited device resources and the specifics of the browser environment create performance challenges. Under these conditions, it is critical to use a gesture recognition mechanism that is fast, lightweight, and consumes minimal computing resources — especially in low-end VR headsets.</p><h4>Objective</h4><p>To develop a service for browser-based applications using WebXR that enables hand gesture recognition with the following capabilities:</p><ul><li>Creation and customization of gestures and gesture combinations</li><li>Real-time recognition of gestures and combinations</li><li>Sufficient performance, even on low-power VR headsets</li></ul><h4>Approach Exploration</h4><p>At the start of the project, I researched existing methods and identified two main approaches:</p><ol><li><strong>Distance-based analysis</strong> — Measuring the distances between hand joints and comparing them to reference values.</li><li><strong>Neural networks</strong> — Using AI models that recognize gestures in a “magical” way.</li></ol><p>I couldn’t find any ready-made libraries that solved the problem efficiently. Both approaches required significant computational resources. While the distance-based method was more transparent and interpretable, it failed to account for hand orientation in 3D-space.</p><p>I chose the first approach but enhanced and refined it. As a result, the compressed package code was only <strong>~150 KB</strong>, including additional WebXR functions. Its relatively small size and low resource consumption make this method more suitable for WebXR than AI-based models.</p><h4>Key Requirements</h4><p>For the Utility:</p><ul><li>Must work directly in the browser of a VR headset.</li><li>Should recognize not only gesture shapes but also wrist angles.</li><li>Must allow configuring gesture combinations.</li><li>Should provide convenient testing and calibration tools.</li><li>Must support saving and loading data.</li></ul><p>For the Package:</p><ul><li>Should ensure easy integration with client-side code.</li><li>Must provide interfaces and types for all entities.</li><li>Should maintain sufficient performance.</li><li>Must recognize both individual gestures and gesture combinations.</li><li>Should allow managing gesture recognition by groups.</li><li>Must support gesture combinations with one or both hands.</li></ul><h4>Technologies</h4><p>The project is based on <a href="https://medium.com/u/efd98bd3d8f4">Babylon.js</a>, a powerful WebGL library with advanced WebXR support. It is stable, actively developed by a friendly community, and maintains good backward compatibility.</p><p>Technology Stack:</p><ul><li><strong>TypeScript</strong> — for type safety and scalability.</li><li><strong>RxJS</strong> — for reactive event handling and state management.</li><li><strong>Inversify</strong> — for dependency injection and modular architecture.</li></ul><p>Methodologies:</p><p><strong>SOLID</strong> principles — to ensure maintainability and extensibility.</p><p><strong>Object-Oriented Programming (OOP)</strong> — for structured, reusable code.</p><h4>Package Organization</h4><p><a href="https://medium.com/u/efd98bd3d8f4">Babylon.js</a> provides wrappers around WebXR entities, including <em>XRFeatures</em>. I followed this approach and extended it further:</p><ul><li>Created <strong>wrappers</strong> around BabylonJS.IWebXRFeature, adding additional functionality.</li><li>Developed a <strong>custom </strong><em>IXRFeatManager</em>, running alongside <em>BabylonJS.WebXRFeaturesManager</em>.</li><li>Integrated all additional functions into <em>IXRService</em>, a single entry point that utilizes <em>BabylonJS.WebXRExperienceHelper</em>.</li></ul><h3>Handshapes</h3><p>A <strong>handshape</strong> is a combination of joint positions in space, complemented by the <strong>wrist position and rotation angle</strong>. For example, if the thumb is extended to the side, the other fingers are curled into a fist, and the gesture is directed upward, it remains the same handshape regardless of its position in space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*5aEt3aJvZPRaXjGumcY5vw.png" /><figcaption>Simple handshape example</figcaption></figure><p>To <strong>speed up the search and analysis of handshapes</strong>, I decided <strong>not to use all joints</strong>, focusing only on those that are truly important. There are <strong>too many joints</strong>, and the number of possible combinations is even greater, making a full analysis excessively resource-intensive.</p><p>A simple example is the <strong>“thumbs-up” gesture</strong>. To recognize it correctly, <strong>only 6–7 parameters</strong> need to be checked, rather than analyzing all joint connections as mechanized methods do. Let’s compare:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*6wW4OCWml4YsvmBN00Jxug.png" /></figure><p>Considering <strong>both hands</strong>, we get <strong>552 connections</strong>.<br> If the application uses <strong>10 gestures</strong>, this would require <strong>5,520 checks</strong>.</p><p>With the <strong>proposed approach</strong>, we check:<br> <strong>7 parameters × 2 hands × 10 gestures = 140 checks</strong>.</p><p>Even if this calculation is not perfectly precise, the difference of <strong>more than 37 times</strong> highlights a <strong>significant optimization opportunity</strong>.</p><h4>Selection of Key Connections</h4><p>To reduce computational load, I identified the truly significant connections. I developed an interface for configuring and capturing hand shapes that is user-friendly for VR headset operation.</p><p>Using this interface, positions of joints can be recorded multiple times and averaged to form a reference template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yzNPIKlYunDgWScuI-svog.png" /><figcaption>UI of the capture utility</figcaption></figure><h4>Gesture Recognition Implementation</h4><p>The next step was to create a recognizer that compares the current hand configuration with the template. Initial tests showed that gestures were recognized, but they required excessive precision during demonstration, making the system cumbersome.</p><p>To address this issue, I:</p><ul><li>Introduced connection weights to control allowable deviations.</li><li>Added a <strong>softness</strong> parameter that globally expands the range of acceptable values.</li></ul><p>As a result, gestures recorded by one person started being correctly recognized by other users.</p><h4>Eliminating Random Deviations</h4><p>The next issue was the high variability of data caused by:</p><ul><li>Insufficient lighting</li><li>Finger overlap</li><li>Individual anatomical differences.</li></ul><p>To compensate for these factors:</p><ul><li>The gesture is captured multiple times, rather than just once</li><li>The user, while capturing the figure, can help the system refine the data by making small adjustments to the hand and finger positions during the capture process.</li></ul><p>Data processing methods used include:</p><ul><li>Removing outliers using the <a href="https://ru.wikipedia.org/wiki/%D0%A1%D1%80%D0%B5%D0%B4%D0%BD%D0%B5%D0%BA%D0%B2%D0%B0%D0%B4%D1%80%D0%B0%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%BE%D0%B5_%D0%BE%D1%82%D0%BA%D0%BB%D0%BE%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5">three-sigma rule</a></li><li>Averaging values to account for variations in hand anatomy (for instance, women and children tend to have more flexible joints).</li></ul><h4>Equipment Influence</h4><p>It turned out that different VR headsets record different distances between joints.<br>In Oculus Quest 2, Quest 3, and Quest Pro, the measurements matched.<br>However, in the Apple Vision Pro (AVP), the distances were different, and the templates captured on other devices did not work. It’s hard to say why this happened. Perhaps Apple decided that their users’ finger phalanges are longer. 😄</p><p>As a result, I implemented a mechanism for separate storage of parameters for different device families. However, since my access to AVP was limited, I didn’t develop this functionality further. The important thing is that gestures were reliably recognized even there.</p><h4>Wrists</h4><p>A few words about wrists.<br> Imagine two hand shapes with identical finger positioning but different wrist orientations. Visually, they are perceived as different, even though the joint structure is identical.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*17pycPlAytymOXI-2wgfqA.png" /><figcaption>Two different hand shapes with the same finger joint position</figcaption></figure><p>To account for this factor, I added the capture of two wrist angles:</p><ul><li>Vertical tilt of the hand.</li><li>Rotation around the imaginary axis of the radius.</li></ul><p>Checking these angles allows for determining the palm’s orientation in space relative to the imagined forearm, and correctly distinguishing gestures.</p><h4>Difficulties with Angle Capture</h4><p>Capturing angles is more challenging for the user than capturing the shape itself because:</p><ul><li>It’s necessary to isolate one angle first, then the second.</li><li>Sometimes, 2–3 re-captures are needed for the system to register the correct values.</li></ul><p>To simplify this process, I added the ability to re-capture angles separately from the shape. This improved the ease of setup and use of the utility.</p><h4>Next Step</h4><p>Once the shapes are captured and saved, we can move on to considering combinations of shapes.</p><h3>Combinations</h3><p>A combination is a sequence of shapes demonstrated in a specific order, tied to space.</p><h4>Optimization of Storage and Calculations</h4><p>Initially, I considered storing combinations as a full track (shape\position\time), but this approach turned out to be too resource-intensive. Additionally, the track needs to be fixed relative to something, which adds complexity without providing any real value.</p><p>After a series of experiments, I settled on dividing space into voxels (actually, these are uneven “boxes,” but it’s easier to explain this way). The key factor is the appearance of the expected shape in the correct voxel, which dramatically reduced the size of the combination description.</p><p>However, tying it to specific voxels wasn’t always convenient, so I added logical regions that group voxels together. This sped up calculations and simplified the code, as most combinations can be described this way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qdeoEkZWBqWboTDYs9YAvg.png" /><figcaption>UI of combinations constructor</figcaption></figure><p>Additionally, instead of voxel numbers, I use semantically meaningful labels (like ‘<strong>XL</strong>’, ‘<strong>ANY</strong>’ etc). This allows gestures to be constructed directly from the code or interface, though there is also the option to capture voxels in immersion mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OZ-lcQQCZ4K57gYQtEjXqg.jpeg" /><figcaption>Capturing voxels in immersive mode</figcaption></figure><p>Example of a combination description: The activation combination (right fist, facing outward, transitioning into an open palm raised in space):</p><pre>{<br>   &quot;name&quot;: &quot;activate&quot;,<br>   &quot;seq&quot;: [<br>      {<br>         &quot;templateName&quot;: &quot;fist-outside&quot;,<br>         &quot;r&quot;: {<br>            &quot;semantic&quot;: [<br>               { &quot;x&quot;: &quot;XR&quot;, &quot;y&quot;: &quot;YL1&quot;, &quot;z&quot;: &quot;ANY&quot; },<br>               { &quot;x&quot;: &quot;XR&quot;, &quot;y&quot;: &quot;YL2&quot;, &quot;z&quot;: &quot;ANY&quot; },<br>               { &quot;x&quot;: &quot;XR&quot;, &quot;y&quot;: &quot;YL3&quot;, &quot;z&quot;: &quot;ANY&quot; },<br>               { &quot;x&quot;: &quot;XR&quot;, &quot;y&quot;: &quot;YL4&quot;, &quot;z&quot;: &quot;ANY&quot; },<br>               { &quot;x&quot;: &quot;XR&quot;, &quot;y&quot;: &quot;YL5&quot;, &quot;z&quot;: &quot;ANY&quot; }<br>            ]<br>         }<br>      },<br>      {<br>         &quot;templateName&quot;: &quot;palm-out&quot;,<br>         &quot;r&quot;: {<br>            &quot;semantic&quot;: [<br>               { &quot;x&quot;: &quot;XR&quot;, &quot;y&quot;: &quot;YH3&quot;, &quot;z&quot;: &quot;ANY&quot; },<br>               { &quot;x&quot;: &quot;XR&quot;, &quot;y&quot;: &quot;YH2&quot;, &quot;z&quot;: &quot;ANY&quot; },<br>               { &quot;x&quot;: &quot;XR&quot;, &quot;y&quot;: &quot;YH1&quot;, &quot;z&quot;: &quot;ANY&quot; },<br>               { &quot;x&quot;: &quot;XR&quot;, &quot;y&quot;: &quot;YC&quot;, &quot;z&quot;: &quot;ANY&quot; }<br>            ]<br>         }<br>      }<br>   ]<br>}</pre><h4>Combination handling in code</h4><p>Simply defining a combination doesn’t solve all the problems — if different combinations contain the same gestures or require holding the last gesture (hold), their recognition may overlap. To prevent this, I created several combination processors that run in parallel. They:</p><ul><li>Separate the processing of different combinations.</li><li>Allow pausing and resuming specific combinations (for example, teleportation is disabled during elevator movement).</li><li>Generate events in an RxJS stream that can be subscribed to and filtered as needed.</li></ul><h4>Minimal code for working with combinations</h4><p>The entire algorithm can be summarized in 4 steps:</p><ol><li>Load gesture files and add them to the repository.</li><li>Load the combination file and add it to the repository.</li><li>Set up a stream handler for combinations.</li><li>Activate recognition for the required combination.</li></ol><pre>// Load all handshapes<br>const fistTemplate = await jLoader.load(&#39;/assets/gestures/figures/fist-outside.json&#39;);<br>this.handFeature.gesturesRepo.set(&#39;fist-outside&#39;, fistTemplate);<br><br>// Load the combination<br>const activateComb = await jLoader.load(&#39;/assets/gestures/combinations/activate.json&#39;);<br><br>// Create a repository and add a combination to it<br>const activateCombinationsRepo = new CombinationsRepo();<br>activateCombinationsRepo.set(&#39;activate&#39;, activateComb);<br><br>// Add to RepoMap<br>this.handFeature.combinationsReposMap.set(&#39;activate-deactivate&#39;, activateCombinationsRepo);<br><br>// Start listenin recognized combination<br>this._commandsSubscription = this.handFeature.combinations$<br>.pipe(<br>  /* is possible to add filtering */<br>)<br>.subscribe((comb)=&gt;{<br> /* DO SOME */<br>});<br><br>// Start recognition<br>this.handFeature.startRecognize(&#39;activate-deactivate&#39;);</pre><p>This makes the WebXR application with gesture support compact and flexible.</p><h4>Debugging and Practical Use</h4><p>In practice, there were some nuances:</p><ul><li>Some connections caused random errors, so I had to develop utilities for testing them.</li><li>Fine-tuning of hand shapes and wrist angles takes 30–60 minutes.</li></ul><p>Fortunately, shapes and combinations can be transferred between applications, saving time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2s0O_K27PTlr4jGU4wnPvw.jpeg" /><figcaption>UI of combination test reporting</figcaption></figure><h3>Conclusion</h3><p>The package @clickon/xr-extension supports the following features:</p><ul><li>Hand shape recognition</li><li>Gesture combinations recognition, combination management</li></ul><p>Additional features in the package:</p><ul><li>Hand animation recording</li><li>Hand animation playback</li><li>Space marking, including simulation of walls, stairs, slopes, and organization of possible user movements</li><li>Customizable teleportation (with gesture control)</li><li>Debugging console for output in VR</li><li>Integration with the @clickon/3d-gui-extension package for UI interaction through VUE3 entities in BabylonJS scenes</li><li>Auxiliary services</li></ul><h4>Future Plans</h4><p><strong>Performance<br></strong>Currently, the system does not affect FPS when processing 5–6 gestures, meaning the load on the CPU is minimal.</p><p>In the future, precise measurements will be made, and the possibility of moving the recognizer and combination processors to a WebWorker will be explored if necessary.</p><p><strong>Fake Elbows. <br></strong>Add calculations for elbow positions, in case they are needed by the user.</p><p><strong>Standard Gesture Set<br></strong>Implement swipe gestures, scrolls, rotations, and other control gestures.<br>A ready-to-use set of features for quickly building “sci-fi movie-like” interfaces 🚀</p><p><strong>Add Object Interaction: </strong>Grabbing, Throwing, Object connections, Climbing ladders, etc.</p><p>I hope my experience will be interesting and useful.<br>There are plans to expand the system in new directions — either suggested by users or dictated by further practice.<br>I am interested in the development of the project and the practical application of the approach, and I am <strong>open to ideas and discussions.</strong></p><p><a href="https://webxr.projects.clickon.pro/">Some demos and info’s</a><br><a href="https://youtube.com/playlist?list=PLlta-b8CW53-4mmBGVYV7lwftqy-FcYFN&amp;si=ADTyNviJ8SLHEYpM">Few demo videos</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5d286c62c8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>