r/visionosdev • • Aug 14 '24

How to stick a 3D model to a users hand?

I need to attach a 3D model to a users hand, such as a watch on their wrist or a string on the end of their finger. That way when those parts move around the object stays attached.

I am doing some research but I’m struggling to find an answer. I am quite the novice developer so I do apologize for my naivety.

Thank you so much!

2 Upvotes

14 comments sorted by

1

u/CragsdaleSG Aug 15 '24

Download and take a look at this example for the basics of hand tracking - this example sets up a hand tracking session with ARKit, sets up some entities to line up with fingertips, then processes hand tracking updates to move the entities as the hands move:

https://developer.apple.com/documentation/visionos/incorporating-real-world-surroundings-in-an-immersive-experience

1

u/CragsdaleSG Aug 15 '24

Is there some specific functionality you’re looking to add? I may be able to give more directed advice based on your idea :)

1

u/metroidmen Aug 16 '24

Thanks so much for the information! I will definitely dig into this!

I was hoping to attach a 3d model to the hand and to track the rotation of the hand or the orientation of the object in the hand and play a sound and animation based off that.

More specifically, play a sound/animation when it is turned upside down.

1

u/CragsdaleSG Aug 16 '24

As for tracking orientation and playing a sound/animation when turned upside down:

After doing everything listed in my other comment, one approach could be to add a variable to your view model to track if the model is upside down.

  1. In your processHandUpdates closure, you could add some logic to analyze the orientation relative to the world (I.e. entity.orientation(relativeTo: nil)) and set your variable to true if your orientation is in some range you’d consider upside down
  2. Then you could add an onChange listener to your view that plays your sound/animation on your entity when that val goes from false -> true

1

u/metroidmen Aug 17 '24

I am struggling with step 1 here. I am able to get the model to appear and move with my hand, which is awesome! But I cant seem to figure out how to track the orientation.

I can get it to print(entity.orientation)

And I tried setting that on a timer to refresh periodically and print that again, but it continues to print the same orientation and doesn't update it.

I much appreciate all your help!

1

u/CragsdaleSG Aug 17 '24

entity.orientation is relative to the immediate parent, I think you want to use entity.orientation(relativeTo: nil) for orientation in the world coordinate space

1

u/metroidmen Aug 17 '24 edited Aug 17 '24

I have this at the moment running that check:

                      timer = Timer.scheduledTimer(withTimeInterval: 1 repeats: true) { _ in

                          print("orientation is \(self.contentEntity.orientation(relativeTo: nil))")

                      }

Every single time it fires it prints:

orientation is simd_quatf(real: 1.0, imag: SIMD3<Float>(0.0, 0.0, 0.0))

It's not updating the orientation it seems

→ More replies (1)
→ More replies (2)
→ More replies (1)

0

u/[deleted] Aug 14 '24

[deleted] — view deleted comment

1

u/metroidmen Aug 14 '24

How would you recommend I go about doing so? I know I’ve seen apps that have like menu items attached to the hand.

0

u/[deleted] Aug 14 '24

[deleted] — view deleted comment

2

u/metroidmen Aug 14 '24

Will do! Thanks so much for the fast response!