SceneKit – material's colorBufferWriteMask - ios

I'm working with SceneKit (swift) and found colorBufferWriteMask parameter that working with SCNMaterial. But it's still working with iOS11+.
So, have anyone know a parameter like colorBufferWriteMask that working with iOS9+?
Thanks.

After research about scenekit, i found a solution. The first, i create a SCNNode (A) that is setting with opacity = 0.000001 and renderingOrder = -1. The second, i create other SCNNode (B) that setting with renderingOrder = 100 and add A.
So, right now, Part of B will be hidden, and this is okie like colorBufferWriteMask.
Thanks.

Related

Different results when using isNode(_:insideFrustumOf:) vs nodesInsideFrustum(of:)

Have a quick question to see if I'm using isNode(_:insideFrustumOf:) correctly.
I'm putting an node (SCNNode) into an ARSCNView with standard configuration. The geometry in the node is off-centered so I used the node's pivot property to adjust its center point.
let c = object.boundingSphere.center
object.pivot = SCNMatrix4MakeTranslation(c.x, c.y, c.z)
object.position = c
My issue arises after I update the object's scale or rotation using a pinch gesture. After this happens, I get different results from isNode(_:insideFrustumOf:) and from nodesInsideFrustum(of:).
The node I'm testing is clearly visible in the screen, but isNode(_:insideFrustumOf:) fails to see it. However, the node is in the [SCNNode] results from nodesInsideFrustum(of:).
My question is whether this is a bug, or is there some other proper way of centering geometry to a node that may fix this issue. For now, I'm going to use the nodesInsideFrustum(of:) function and test if the object is in the array.
Thanks!
The trick is making sure you are using the ”presentation” node for any moving objects, even the pointOfView if it’s moving.
This is a working snippet from my app inside the renderer: (updateAtTime)
if renderer.isNode(stationaryObjectNode, insideFrustrumOf: renderer.pointOfView!.presentation) == true {
//do stuff if seen
}
If your object is not stationary, use movingObject.presentation instead of stationaryObjectNode

Does shadow for directional light even work in SceneKit?

I can only get shadows to work for spotlight, but not for directional light.
Has anyone out there ever gotten it to work? (Using Swift, if that should matter.)
You need to set the scale property of the light e.g.
lightNode.light?.orthographicScale = 50
Try this:
lightNode.light?.automaticallyAdjustsShadowProjection = true

How to change center of gravity in sprite kit game?

I have been trying to find, but did not succeed. Is there a way to change physicsworld gravity property in such way, that objects would not be attracted towards the bottom of the screen, but to the centre of it instead?
Use an SKFieldNode for that. Just place it at the center of your map and disable gravity by putting code in that sets the gravity to zero (CGVector(0,0))
I would give you code, but I don't use Objective C, so I don't know the exact syntax for it. I can give it a shot though... [physicsBody setGravity: CGVector(0,0)]; PLEASE NOTE I HAVE NO IDEA IF THAT IS CORRECT SYNTAX
EDIT:
The asker requested an example of SKFieldNode in Swift, so here it goes.
For the question asked, what you would do is create a Radial Gravity Field node at the center. This code goes in GameScene.swift (or .m if you're using Objective C, and make sure you change the syntax to Obj-C).
let gravField = SKFieldNode.radialGravityField(); // Create grav field
gravField.position.x = size.width/2; // Center on X axis
gravField.position.y = size.height/2; // Center on Y axis (Now at center of screen)
addChild(gravField); // Add to world
You are probably looking for a SKFieldNode. There are a couple of different types so you will have to read the docs. The one you are probably looking for is called radialGravityField.

Moving a node in SceneKit

I have a SCNNode and I want it to be in a specific position by default. I tried to set the position from .dae file, but it's not saving. Can some give me a hint how can I do that?
You set the position like that:
yourNode.position = SCNVector3Make(yourXValue, yourYValue, yourZValue)
Call that method when you first start your app.

Physic Spring Joint Worked Unexpectedly

I'm quite new to Sprite Builder. I'm trying Clone Angry Birds with SpriteBuilder > Add Physics using Chipmunk, Part 1. Now I encountered a weird problem.
According to the code, the restLength of spring that joins catapult arm and the square shouldn't be able to be stretched. The square is a invisible CCNode.
_mouseJoint = [CCPhysicsJoint connectedSpringJointWithBodyA:_mouseJointNode.physicsBody bodyB:_catapultArm.physicsBody anchorA:ccp(0, 0) anchorB:ccp(14, 150) restLength:0.f stiffness:3000.f damping:150.f];
Here's my spring(Sorry I don't know how to make a screenshot while dragging the mouse):
And here's what it should look like:
It seems the spring in the tutorial can't be stretched, and I didn't see this invisible CCNode in the expected result.
Is this because of the value of anchorB? Actually I don't think so.
All the suggestions will be appreciated. =)
Alright, I got why. I should set the invisible CCNode to Circle and its corner to 0. Also, I should set it to "static"

Resources