Detect touches on different positions of a SCNNode in ARKit - ios

I have a 3D character in .dae format which i use in ARKit. I need to have different actions for touches at different positions of the character.eg: Menu options. I use scene kit and scnnode to create ar. I just started learning AR. Can someone please help me to get this done?

I fixed this by using hit test.I was having different meshes for different parts in my model. So simply calling node.name from hit test gets me which node was selected.
Thanks all.

Related

how to implement gear joint in sprite kit?

The gear joint in Box2d is great, but I don't know how to implement that in Sprite Kit. Is there any solutions to implement the gear joint in Sprite Kit?
Thanks.
Here are the available Sprite-Kit joints :https://developer.apple.com/reference/spritekit/skphysicsjoint
As far as I can understand, there does not appear to be a direct correlation to Box2D's gear joint, which seems to make one body rotate when another body is rotated.
In that case, you might want to investigate overriding the didSimulatePhysics or didFinishUpdate methods to manually set the rotation of one object based upon the rotation of another object:
https://developer.apple.com/reference/spritekit/skscene/1519965-didsimulatephysics
https://developer.apple.com/reference/spritekit/skscene/1520269-didfinishupdate
It might be as simple as:
wheel2.zRotation = wheel1.zRotation
but if the gears have different numbers of teeth (thus different ratios), you'll have to do some calculations.

How can I export a simple rigged model from Maya for use in Scenekit?

I am attempting to experiment with Apple’s Fox game SceneKit example (link below) by adding a model with a simple animation like the ‘panda.scn’ and ‘walk.scn’ assets.
I can create a static model with no joints or animation that works: e.g. In Maya (2017) I add a simple sphere, export selection to FBX_DAE (COLLADA) file, drag it into the project in XCode and convert it to a SCN file. I can then drag that model into the ‘level.scn’, position and scale it as I’d expect.
However as soon as I add any animation or joints to my model I lose the ability to position and scale the model in XCode.
In Maya I add two joints to my sphere select the sphere and joints and export as above. When I examine the model SCN in XCode (either in isolation or as a reference within another scene) I find that I cannot apply any translation or scaling. XCode lets me move the xyz locators in the GUI and update scale but the model does not change. I can see the mesh and joints in the outline view and I have tried moving the joints instead of the mesh, but they do nothing. I have even tried ignoring the GUI and positioning the model in code just as the panda character is set up, but applying positions or transforms to the node does nothing - it always appears at the origin and default scale.
Ignoring that for the moment, my understanding from looking at the ‘walk.scn’ file is that an animation is just an export of the joints with keyframes. I have tried to reproduce that by exporting only the joints to a separate DAE and importing it, then applying that in code as they do with the ‘walkAnimation’. This seems to do nothing as well.
I have experimented with various settings of the FBX_DAE export dialog including baking animations (By the way - what is the difference between baking an animation on export vs baking it in Maya before export? The former seems to do something and the other does nothing in my tests.)
I would dearly love a workflow for creating some simple character animations in Maya and getting them into SceneKit. Any help is greatly appreciated.
For reference:
Apple’s source: https://developer.apple.com/library/content/samplecode/Fox/Introduction/Intro.html
Maya scene for my trivial ball model with two joints:
http://pat.net/misc/ball1.mb
and the DAE output from Maya for that:
http://pat.net/misc/ball1.dae
UPDATE:
Mnuages's answer appears to be correct in that when I added a parent control over the geometry and joints SceneKit then allowed me to move them. But even after brushing up on my understanding of how these nodes and their transforms relate in Maya I do not feel that I have a real understanding of how SceneKit is interpreting them. (Would love to read some docs on that would illuminate this more if they exist).
UPDATE #2:
I was finally able to create an animation by doing the following: 1) Export either the full scene or just the joint with the animation being sure to select the "bake animation" option in the DAE export dialog or bake the entire animation using Key->Bake Animation. 2) It only works if I load the DAE file in scenekit instead of converting it to an SCN. Converting to SCN format seems to lose the animation.
what happens is that the node named joint1 is animated by the joint1-anim animation. So even if you move joint1 in the editor, what you see on screen is the result after the animation is evaluated.
If you create an intermediate node, say joint1-parent, and make joint1 as child node of joint1-parent, then you'll be able to translate and rotate joint1-parent freely and see the effects on joint1.
As for why moving pSphere does not change anything, it's the same idea. Just like the animation overrides the position, the skeleton will reposition the mesh.

Rotate 3D rigged human model around pelvis root node while keeping feet planted

I am currently using iOS's Scenekit along with an imported collada file from Cheetah 3D.
I have a simple rigged body with the root attached to the pelvis. All the children nodes are attached to the pelvis (spine, legs).
The problem occurs when I try to rotate the pelvis say 45 degrees. The entire model rotates 45 degrees and the feet then wind up above the floor. How can I keep the feet planted on the floor. Do I need to make the change in the Cheetah 3D or make the change in objective-c adjusting SCNNode properties manually?
Appreciate your help in advance.
If the pelvis is the root of the node hierarchy, rotating it rotates everything—that's how hierarchical modeling is supposed to work. Sounds like what you want is for other parts of your skeleton to move relative to the pelvis—so look for its child nodes and rotate those.
You can do this in code, but working with whatever tool you used to create the skeleton or with Xcode's SceneKit editor might help you get a visual feel for what your code needs to do.

Hit-testing a UIGestureRecogniser in 3d space

I'm reasonably new to iOS's SceneKit and have come across a dilemma with regards to user-interaction in a 3d scene:
I have a set of SCNNode cubes in an SCNView, and would like to be able to pin-point where a user touches the mesh of a given cube, as a 3d coordinate (so as to later manipulate the scene according to touch vectors). At present, I've been using a UIGestureRecognizer in order to achieve basic hit-testing, but this seems to be limited to returning 2d-points.
This isn't a problem when wanting to hit-test a whole node itself, as this can be achieved via a UIGestureRecognizer's hittest method in the SCNView. However, does anybody have any suggestions as to how to precisely locate where a touch landed on a node, in terms of coordinates (i.e. SCNVector3)?
Thanks!
You are on the right track with calling hitTest:options: on the SCNView. As you have probably seen it results in an array of SCNHitTestResults.
The hit test result can tell you many things about the hit, one of them being what node was hit. What you are looking for is either the localCoordinates or the worldCoordinates.
The local coordinate is relative to the node that was hit. Since you are asking "how to precisely locate where a touch landed on a node" this is probably the one you are looking for.
The world coordinate is relative to the root node.

SpriteKit Racing top down Game

I want to write a simple top down racing game for iOS. I want to use Sprite Kit instead Cocos2D , I'm new to game development and I have a question:
How can I create the race tracks? What I think is: One single big background image for each track and a car that moves over it and remains inside the track by interaction with a path. The path is inserted by a coordinate system in the level code and represents the "borders" of the road.
Is this a good way to start a top down racing game? Or are there better ways? How can I "draw" the path over my background image?
You can use "Tiled Map Editor" http://www.mapeditor.org/ to create your maps. I'm thinking you'll only need a few unique tiles, one for straight track, one for grass, one for curved track, maybe some trees, etc.
As for the path, you can try to use an polygonal edge physics body? And then move the car to where the user touches on the screen. if the user tries to move the car outside, the car will bump against the physics body of the edge.

Resources