18.4 C
Wednesday, May 15, 2024

ios – SK3DNode exhibits SCNScene darker than in SCNView

Earlier than I’m going mad I might prefer to ask right here concerning the following situation.
I wrote an iOS take a look at app in SwiftUI that exhibits a SpriteView and a SceneView. The SpriteView exhibits (amongst different issues) two SK3DNode nodes that show one and the identical SCNScene from completely different digicam positions. The SceneView renders the exact same SCNScene.

The issue is that the rendered scene in each SK3DNode’s are proven darker than in SceneView.

The scenes in SpriteKit are unusable as a result of they’re too darkish.

This can be a screenshot from the iPad simulator:

Screenshot in simulator

I anticipated each SK3DNode‘s (on the prime half) to render the scene on the similar brightness because the SceneView (backside half).

If I merely enhance the ambient gentle, objects are proven means too vivid.
I believed the issue is the feel or the fabric, however the issue additionally happens with colors. Therefore the pink/inexperienced/blue shapes.
I’ve disabled SK3DNode‘s built-in lighting by setting autoenablesDefaultLighting to false. By some means SceneView (or its inside SCNView) should add its personal lighting however I can not determine how. The scene’s rootNode solely exhibits my nodes from the .scn file.

I’ve disabled the surroundings within the scene file so there isn’t any sky dice. There may be one ambient gentle supply, one spot gentle, and one omni gentle. Regardless of which lights I’m utilizing, each SK3DNode‘s nonetheless current the scene a lot darker than the SceneView.

Right here is the perform that creates the 2 SK3DNodes:

func make3DNode(camPos: SCNVector3) -> SK3DNode {
    // Add SceneKit scene in 3D node
    let node3d = SK3DNode(viewportSize: CGSize(width: 300, peak: 200))
    node3d.scnScene = scnScene
    node3d.autoenablesDefaultLighting = false
    let digicam = SCNCamera()
    let cameraNode = SCNNode()
    cameraNode.digicam = digicam
    if let lookAtTarget = scnScene.rootNode.childNode(withName: "red_texture", recursively: false) {
        let constraint = SCNLookAtConstraint(goal: lookAtTarget)
        // why does this not work?
        cameraNode.constraints = [constraint]
    cameraNode.place = camPos
    node3d.pointOfView = cameraNode

    return node3d

On a aspect notice: the digicam lookAt constraint doesn’t appear to work both.

Code so as to add the nodes to the scene:

    // Add SceneKit nodes
    let node3d_1 = make3DNode(camPos: SCNVector3(x: -5, y: -2, z: 14))
    node3d_1.title = "3d_1"
    node3d_1.place = CGPoint(x: 150, y: 110)

    let node3d_2 = make3DNode(camPos: SCNVector3(x: 5, y: 2, z: 14))
    node3d_2.title = "3d_2"
    node3d_2.place = CGPoint(x: 150, y: -110)

Full venture supply: https://github.com/biochill/test-spritekit

It contains each the SpriteKit scene file and the SceneKit file. The SK3DNodes are added programmatically. I can not paste code for the scenes as a result of I’ve created scene information each for SpriteKit and SceneKit. Greatest when you obtain the GitHub venture and hit Cmd+R in Xcode for some iPad simulator.

Thanks for any assist upfront.

Latest news
Related news


Please enter your comment!
Please enter your name here