具有移动对象的场景工具箱视图

问题描述 投票:1回答:1

如何使用场景工具包视图和swift 4在Simple View Application中显示移动的3D对象。

例如,Windows中的bee.glb文件,我正在使用这四个文件:

  1. body.bmp
  2. body.jpg
  3. volkeswagon-vw-beetle.mtl
  4. volkeswagon-vw-beetle.obj

    import UIKit
    import SceneKit
    import ARKit
    
    class ViewController: UIViewController {
    
    @IBOutlet weak var sceneView: SCNView!
    
    override func viewDidLoad() {
    super.viewDidLoad()
    
    
    // 1: Load .obj file
    let scene = SCNScene(named: "volkeswagon-vw-beetle.obj")
    
    // 2: Add camera node
    let cameraNode = SCNNode()
    cameraNode.camera = SCNCamera()
    // 3: Place camera
    cameraNode.position = SCNVector3(x: 0, y: 10, z: 35)
    // 4: Set camera on scene
    scene!.rootNode.addChildNode(cameraNode)
    
    // 5: Adding light to scene
    let lightNode = SCNNode()
    lightNode.light = SCNLight()
    lightNode.light?.type = .omni
    lightNode.position = SCNVector3(x: 0, y: 10, z: 35)
    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)
    
    // Allow user to manipulate camera
    sceneView.allowsCameraControl = true
    
    // Show FPS logs and timming
     sceneView.showsStatistics = true
    
    // Set background color
    sceneView.backgroundColor = UIColor.white
    
    // Allow user translate image
    sceneView.cameraControlConfiguration.allowsTranslation = false
    
    // Set scene settings
    sceneView.scene = scene
    }
    
    }
    

输出为:

“ 3DVideo [6430:105708] [SceneKit]错误:OpenGL渲染器不支持基于物理的光照模型,改用Phong(3)2019-09-02 03:29:13.297536-0700 3DVideo [6430:105708] [SceneKit]错误:OpenGL渲染器不支持基于物理的光照模型,请改用Phong(2)2019-09-02 03:29:13.308381-0700 3DVideo [6430:105708] [SceneKit]错误:OpenGL渲染器不支持基于物理的照明模型,请改用Phong“”

swift scenekit .obj
1个回答
0
投票

我通过将文件扩展名从.obj更改为.dae来解决此问题,因为obj文件没有任何动画

© www.soinside.com 2019 - 2024. All rights reserved.