Scenekit - Why Scnlight Created Automatically in Scnscene

SceneKit – Why SCNLight created automatically in SCNScene?

Eventually, the problem was in ar configuration

ARKit automatically adds light probes when environment texturing is enabled. You can disable this behavior by setting the environmentTexturing property's value in your configuration to .none.

autoenablesDefaultLighting is too bright in iOS 12 and SCNView.pointOfView is not effective

You can try enabling HDR. It should result in a balanced exposure

scnView?.pointOfView?.camera?.wantsHDR = true

With HDR enabled, you can even control exposure compensation with

scnView?.pointOfView?.camera?.exposureOffset

SceneKit: adding directional light to camera node has no effect

Create a SCNNode with for example the name cameraNode.
Create a SCNCamera and assign it to the camera property of cameraNode.
Add the cameraNode to the scene (as a child of the rootNode).

After that you can add the light node as a child node of cameraNode or, given it’s the only camera, as a child of the pointOfView node (which now represents the cameraNode you created and added to the scene). The default camera and its pointOfView node are not part of the scene’s object hierarchy.

How to disable Camera Framing that enframes all the content in the scene?

What I was need to do is to save pointOfView.worldTransform before substitute the scene and after that return it back.

...
let trans: SCNMatrix4 = pointOfView.worldTransform
scnView.pointOfView!.setWorldTransform(trans)
...

SceneKit avoid lighting on specific node

SCNLight has a categoryBitMask property. This lets you choose which nodes are affected by the light (Although this is ignored for ambient lights). You could have 2 light source categories, one for your main scene, and another that only affects your lines.

Here is a simple example with 2 nodes, each lit with a different colour light:

struct LightType {
static let light1:Int = 0x1 << 1
static let light2:Int = 0x1 << 2
}

class GameViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

let scene = SCNScene(named: "art.scnassets/scene.scn")!

let lightNode1 = SCNNode()
lightNode1.light = SCNLight()
lightNode1.light!.type = .omni
lightNode1.light!.color = UIColor.yellow
lightNode1.position = SCNVector3(x: 0, y: 10, z: 10)
lightNode1.light!.categoryBitMask = LightType.light1
scene.rootNode.addChildNode(lightNode1)

let lightNode2 = SCNNode()
lightNode2.light = SCNLight()
lightNode2.light!.type = .omni
lightNode2.light!.color = UIColor.red
lightNode2.position = SCNVector3(x: 0, y: 10, z: 10)
lightNode2.light!.categoryBitMask = LightType.light2
scene.rootNode.addChildNode(lightNode2)

let sphere1 = scene.rootNode.childNode(withName: "sphere1", recursively: true)!
sphere1.categoryBitMask = LightType.light1
let sphere2 = scene.rootNode.childNode(withName: "sphere2", recursively: true)!
sphere2.categoryBitMask = LightType.light2

let scnView = self.view as! SCNView
scnView.scene = scene
}
}

Sample Image



Related Topics



Leave a reply



Submit