<?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 Siddharth on Medium]]></title>
        <description><![CDATA[Stories by Siddharth on Medium]]></description>
        <link>https://medium.com/@siddharth_70859?source=rss-2f19c5707cab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*l3n1X3GSJpml8f8N</url>
            <title>Stories by Siddharth on Medium</title>
            <link>https://medium.com/@siddharth_70859?source=rss-2f19c5707cab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:04:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@siddharth_70859/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[Creating a Hand Menu in Vision Pro with SwiftUI and RealityKit]]></title>
            <link>https://medium.com/@siddharth_70859/creating-a-hand-menu-in-vision-pro-with-swiftui-and-realitykit-d49f25428384?source=rss-2f19c5707cab------2</link>
            <guid isPermaLink="false">https://medium.com/p/d49f25428384</guid>
            <category><![CDATA[swi̇ft]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[realitykit]]></category>
            <category><![CDATA[arkit]]></category>
            <category><![CDATA[vision-pro-development]]></category>
            <dc:creator><![CDATA[Siddharth]]></dc:creator>
            <pubDate>Wed, 19 Feb 2025 07:25:20 GMT</pubDate>
            <atom:updated>2025-07-11T09:50:03.135Z</atom:updated>
            <content:encoded><![CDATA[<p>Vision Pro introduces a new way to interact with digital elements using hand tracking. In this blog, we will build a <strong>Hand Menu UI</strong> that appears when the user raises their hand and allows interaction through a slider and button. We’ll use <strong>SwiftUI, RealityKit, and ARKit</strong> to implement this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xoqK43McjxcgO4v2IemzQA.png" /></figure><h3>Step 1: Create a New Xcode Project</h3><p>Create a new <strong>VisionOS</strong> project in Xcode. Ensure the project type is set to <strong>VisionOS App</strong>. Below is a reference screenshots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*isZqwjN_R5dAO1OqPV0Z5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BIz6-wdszHpsxYRYuC8E6w.png" /></figure><h3>Step 2: Configure Info.plist for Hand Tracking</h3><p>To enable hand tracking, add the following key in <strong>Info.plist</strong>:</p><ul><li><strong>Key</strong>: NSHandsTrackingUsageDescription</li><li><strong>Value</strong>: Track your hands to detect your palm gesture for hand menu.</li></ul><p>This is required to request permission from the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D5dujiXl8ZvN6CLEt6QHiQ.png" /></figure><h3>Step 3: Implement Hand Tracking with HandTrackingModel</h3><p>We need to track the user’s hands and determine when to display the menu. The HandTrackingModel class manages this process.</p><h3>HandTrackingModel.swift</h3><pre>import Foundation<br>import SwiftUI<br>import ARKit<br>import RealityKit</pre><pre>@MainActor<br>@Observable<br>final class HandTrackingModel {<br>    struct HandsUpdates {<br>        var left: HandAnchor?<br>        var right: HandAnchor?<br>    }<br>    <br>    var handTracking = HandTrackingProvider()<br>    var latestHandTracking: HandsUpdates = .init(left: nil, right: nil)<br>    var myHandAnchor = ModelEntity()<br>    var lerpFactor: CGFloat = 1.0<br>    var isHandTracked: Bool = false<br>    var attachmentEntity: ViewAttachmentEntity?<br>    var attachmentParent = Entity()<br>    let session = ARKitSession()<br>    <br>    func start() async {<br>        do {<br>            if HandTrackingProvider.isSupported {<br>                print(&quot;ARKitSession starting.&quot;)<br>                try await session.run([handTracking])<br>            }<br>        } catch {<br>            print(&quot;ARKitSession error:&quot;, error)<br>        }<br>    }<br>    <br>    func publishHandTrackingUpdates() async {<br>        for await update in handTracking.anchorUpdates {<br>            switch update.event {<br>            case .updated:<br>                let anchor = update.anchor<br>                guard anchor.isTracked else { continue }<br>                if anchor.chirality == .left {<br>                    latestHandTracking.left = anchor<br>                    updateHandMenuVisibility(for: latestHandTracking.left)<br>                }<br>            default:<br>                break<br>            }<br>        }<br>    }<br>    <br>    func updateHandMenuVisibility(for handAnchor: HandAnchor?) {<br>        guard let handAnchor = handAnchor,<br>              let handLocation = getLeftHandPointPosition(handAnchor: handAnchor) else { return }<br>        <br>        myHandAnchor.setTransformMatrix(handLocation, relativeTo: nil)<br>        updateEntityPositionUsingLerp(entityAttachment: attachmentParent, target: myHandAnchor)<br>        isHandTracked = checkHandRotation(myHandAnchor.transform.rotation.axis)<br>        attachmentEntity?.isEnabled = isHandTracked<br>    }<br>    <br>    private func checkHandRotation(_ axis: SIMD3&lt;Float&gt;) -&gt; Bool {<br>        let front = axis.x.isBetween(-0.2, 0.8) &amp;&amp; axis.y.isBetween(-0.4, 0.9) &amp;&amp; axis.z.isBetween(-0.2, 1)<br>        return front<br>    }<br>    <br>    func getLeftHandPointPosition(handAnchor: HandAnchor?) -&gt; simd_float4x4? {<br>        guard let handAnchor = handAnchor else { return nil }<br>        let pos = handAnchor.handSkeleton?.joint(.wrist)<br>        return handAnchor.originFromAnchorTransform * pos!.anchorFromJointTransform<br>    }<br>}</pre><pre>private extension Float {<br>    func isBetween(_ min: Float, _ max: Float) -&gt; Bool {<br>        return self &gt;= min &amp;&amp; self &lt;= max<br>    }<br>}</pre><h3>Explanation</h3><ul><li><strong>HandTrackingProvider</strong> listens for hand updates.</li><li>The <strong>updateHandMenuVisibility</strong> function determines when to show the hand menu.</li><li>The <strong>checkHandRotation</strong> function ensures the menu appears only when the palm faces the user.</li></ul><h3>Step 4: Create an Immersive View</h3><p>The <strong>ImmersiveView</strong> adds our hand menu as an attachment when hand tracking is detected.</p><h3>ImmersiveView.swift</h3><pre>import SwiftUI<br>import RealityKit</pre><pre>struct ImmersiveView: View {<br>    @State var handTrackingModel: HandTrackingModel<br>    <br>    var body: some View {<br>        RealityView { content, attachments in<br>            content.add(handTrackingModel.myHandAnchor)<br>            content.add(handTrackingModel.attachmentParent)<br>            <br>            if let attachment_hand_Menu = attachments.entity(for: &quot;hand_menu&quot;) {<br>                content.add(attachment_hand_Menu)<br>                attachment_hand_Menu.scale = [0.6, 0.6, 0.6]<br>                attachment_hand_Menu.position = handTrackingModel.attachmentParent.position<br>                handTrackingModel.attachmentEntity = attachment_hand_Menu<br>                handTrackingModel.attachmentParent.addChild(handTrackingModel.attachmentEntity!)<br>            }<br>        }<br>        attachments: {<br>            Attachment(id: &quot;hand_menu&quot;) {<br>                HandMenuView()<br>                    .frame(width: 400, height: 600)<br>                    .glassBackgroundEffect()<br>            }<br>        }.onAppear() {<br>            Task {<br>                await handTrackingModel.start()<br>                await handTrackingModel.publishHandTrackingUpdates()<br>            }<br>        }<br>    }<br>}</pre><h3>Explanation</h3><ul><li>Adds the <strong>hand menu</strong> as an attachment.</li><li>Sets the <strong>scale, position, and rotation</strong> of the menu.</li><li>Uses <strong>RealityKit</strong> to place the UI in the AR scene.</li></ul><h3>Step 5: Build the Hand Menu UI</h3><p>The <strong>HandMenuView</strong> contains a slider and a button to reset its value.</p><h3>HandMenuView.swift</h3><pre>import SwiftUI</pre><pre>struct HandMenuView: View {<br>    @State private var sliderValue: Double = 0<br>    <br>    var body: some View {<br>        VStack(alignment: .center, spacing: 20) {<br>            Text(&quot;Hand Menu UI&quot;)<br>                .font(.title)<br>                .bold()<br>            <br>            Slider(value: $sliderValue, in: 0...100, step: 1)<br>                .padding()<br>            <br>            Text(&quot;Value: \(Int(sliderValue))&quot;)<br>                .font(.headline)<br>            <br>            Button(&quot;Reset&quot;) {<br>                sliderValue = 0<br>            }<br>        }<br>        .padding()<br>    }<br>}</pre><h3>Explanation</h3><ul><li>A <strong>slider</strong> to change values dynamically.</li><li>A <strong>reset button</strong> to reset the slider.</li></ul><h3>Conclusion</h3><p>We successfully built a <strong>hand menu UI</strong> in Vision Pro that appears when the user raises their left hand. This menu allows interaction using a slider and a button.</p><p>This project demonstrates how <strong>hand tracking and UI integration</strong> can enhance immersive experiences in <strong>VisionOS</strong>.</p><p>Sorry i am forgive to add this helper function . here is that fucntion</p><p>func updateEntityPositionUsingLerp(entityAttachment:Entity, target:Entity) {</p><p>withAnimation(.smooth) {</p><p>print(“updateEntityPositionUsingLerp”)</p><p>entityAttachment.position = lerp(start: entityAttachment.position, end: target.position, factor: self.lerpFactor)</p><p>entityAttachment.orientation = slerp(start: entityAttachment.orientation, end: target.orientation, t: Float(self.lerpFactor))</p><p>}</p><p>}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d49f25428384" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>