Search code examples
iosswiftscene

I have added a Human 3d Model in Scene Kit , its background is black how to make it as white as front view?


I have added a Human 3d Model in Scene Kit. Its background is black how to make it as white as front view? I have used this in swift app, used scene kit and human 3d model, Please check image I have attached..

Back View

3d Model Settings

enter image description here

Code :-

 //MARK: - Scene Related Methods
func loadScene() {
    self.removeExistingNodes()
    loadSceneLayer(fileName: "FinalBaseMesh.obj")
    sceneView.allowsCameraControl = true
    sceneView.autoenablesDefaultLighting = false
    
    load3DScene()
    
    //layerSelectionIndex = 0
    sceneView.scene = scene
}

func load3DScene() {
    sceneView.scene = scene
    // Allow user to manipulate camera
    sceneView.allowsCameraControl = true
    
    sceneView.backgroundColor = UIColor.white
    
    sceneView.cameraControlConfiguration.allowsTranslation = true
    sceneView.cameraControlConfiguration.panSensitivity = 0.9
    
    sceneView.delegate = self as SCNSceneRendererDelegate
    //            sceneView.isPlaying = true
    for reco in sceneView.gestureRecognizers! {
        if let panReco = reco as? UIPanGestureRecognizer {
            panReco.maximumNumberOfTouches = 1
        }
    }
    
    //         add a tap gesture recognizer
    let tapGesture = UITapGestureRecognizer(target: self, action:#selector(handleTap(_:)))
    sceneView.addGestureRecognizer(tapGesture)
    
    self.addSavedNode()
    
}



func loadSceneLayer(fileName: String) {
    
    
    scene = SCNScene(named: fileName) ?? SCNScene()
    let cameraNode = SCNNode()
    cameraNode.camera = SCNCamera()
    
    
    cameraNode.position = SCNVector3(x: 0, y: 6.5, z: 20)
    scene.rootNode.addChildNode(cameraNode)
    
    let lightNode = SCNNode()
    lightNode.light = SCNLight()
    lightNode.light?.type = .omni
    
    lightNode.position = SCNVector3(x: 0, y: 6.5, z: 20)
    scene.rootNode.addChildNode(lightNode)
    
    // 6: Creating and adding ambien light to scene
    let ambientLightNode = SCNNode()
    ambientLightNode.light = SCNLight()
    ambientLightNode.light?.type = .ambient
    ambientLightNode.light?.color = UIColor.darkGray
    scene.rootNode.addChildNode(ambientLightNode)
    
}

I forgot to add last method please check loadstonelayer method


Solution

    1. Remove all the camera control code
    2. See How to rotate object in a scene with pan gesture - SceneKit for rotating an object
    3. Put in a light node at a negative z facing the object