Monday, May 20, 2024
HomeiOS Developmentios - SK3DNode exhibits SCNScene darker than in SCNView

ios – SK3DNode exhibits SCNScene darker than in SCNView


Earlier than I’m going mad I would wish to ask right here in regards to the following subject.
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 high half) to render the scene on the identical brightness because the SceneView (backside half).

If I merely improve the ambient gentle, objects are proven approach too vibrant.
I assumed 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. One way or the other SceneView (or its inner 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 setting within the scene file so there isn’t a 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, top: 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 word: 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.identify = "3d_1"
    node3d_1.place = CGPoint(x: 150, y: 110)
    spriteScene.addChild(node3d_1)

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

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

It consists of 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 recordsdata each for SpriteKit and SceneKit. Greatest when you obtain the GitHub undertaking and hit Cmd+R in Xcode for some iPad simulator.

Thanks for any assist upfront.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments