ARKit How can I know root node is initialized - arkit

above x, y, z is root node.
I want to know when root node is shown
how to show/hide root node on screen.
Thank you

You can't ever 'show the node', but you can attach objects to the node and visualise those, as you have done (with the lines).
If you want to see the actual point that the node is at, you can attach a SCNSphere (or any geometry).
let sphere = SCNSphere(radius: CGFloat(0.02))
sphere.firstMaterial?.diffuse.contents = UIColor.magenta
var node = SCNNode(geometry: sphere)
As an aside, you can make the node visible / invisible using node.isHidden = true etc. This will hide the node, any attached geometry, and all of its children nodes.

Related

Need to SCNNode within restricted area

I have created a SCNNode object on a SCNPlane object. Both objects are added to the scene view root node, like below:
scView.scene.rootNode.addChildNode(ballNode)
scView.scene.rootNode.addChildNode(planeNode)
Now, my issue is that the ball node is moving out of the plane node boundary.
When I tried to add ballNode as planeNode's child then, the ball node is not getting added to a plane as expected. It behaves very strangely.
Basically, I need to restrict the movement of ballNode within planeNode area. How can I do it?
Great question!
When adding a child node to another node, there are no constraints being implicitly applied to the child, aside from existing within the infinite coordinate space of the parent node.
While changing the transform (eg position) of the parent node will directly apply to all child nodes, each child node can still freely transform within the parent nodes local coordinate space.
It'd be a good idea to read the SCNNode docs if you haven't already, as it covers the foundational aspects.
To do what you want, when moving the ball in your gameloop, you will need to manually check whether or not that ball is outside the boundary you are trying to enforce, and change its position accordingly.
Depending on your desired outcome, you may want to also check out SCNPhysicsBody as a way to construct your scene with implied physical boundaries.

Swift SceneKit issue with node position on preview

I'm trying to add nodes to my scene view, but all of the nodes have a zero position, but different placements.
Each node has a position (0,0,0) but, on the scene view, this node has a different placement. Also, I can`t find the distance between nodes because each node has a position (0, 0, 0). Please explain to me what is wrong with my nodes.
If you want to fetch the real position of a node try this:
node.presentation.worldPosition
This should always return you the effective position of the node as seen on screen.
The problem was in 3d object, the original position of the 3d was not centered. I upload each 3c object to Blender and change original position to (0,0,0)

Can you mask an SKSpriteNode with another SKSpriteNode

Just ask the title asks, I am wondering if this is at all possible. Most examples of the SKCropNode use a texture or a shape. What I want to accomplish is a mask of a custom shape. Let me know if there's a way!
You could mask a node by giving it a child node where the child node's zPosition is greater than the parent's. And then, of course, you'd have to position the child node correctly on top of the parent node -but this should be easy as the child node's position is located relative to the parent node (i.e. if parent has position (25, 30) in the scene, and you set child.position = CGPoint(x:5, y:0), the child's position in the scene would be (30, 30)). Also, if the parent node moves, the child node moves with it.

Changing parent node in SpriteKit

I'm new to SpriteKit. When I drag and drop "Color Sprite" from object library to make a new node. It gives the correct size (as you can see in the image below). Here the parent is the main scene not the blue one.
But when I change the parent node from the main scene to any other node (like blue one in my case) the new node gets larger however it's width and height remain same (shown below).
EDIT:
I'm running Xcode 7 beta 3.
I prefer you to do everything programmatically in sprite kit. I didn't understand what is going on there actually but if you want to make a shape like this, you should use SKShapeNode. SKSpriteNode is generally for making a node with a texture and animating that stuff etc...
//for example
let node = SKShapeNode(rectOfSize:CGSize(width:100,height:100))
node.position = CGPoint(x:500,y:350)
node.fillColor = UIColor.redColor()
self.addChild(node)
if you still have problems with the size, you can play with;
// for example;
node.xScale = 469
node.yScale = 300

SpriteKit SKNode visual position in parent(s) after parent(s) are rotated?

I have following hierarchy:
Scene -> Root node -> NodeA -> NodeB (anchor node that's rotated) -> NodeC
how can I figure out visual position of NodeC in Root node coordinate space?
I've tried several variants with convertPoint:toNode: and convertPoint:fromNode: but numbers i'm getting don't match.
I've also looked at Get visible location of SpriteKit node after parent rotation, which seems to be close to my issue, but no luck there either.
Found what I was missing - convertToPoint needs to be called from the node in which final CGPoint value will be represented in. So, this works:
// point is CGPointZero because it is center of NodeC
let point = rootNode.convertPoint(CGPointZero, fromNode: NodeC) as CGPoint!