gpt4 book ai didi

swift - 具有移动对象的场景套件 View

转载 作者:行者123 更新时间:2023-11-28 07:22:02 24 4
gpt4 key购买 nike

如何使用 Swift 4 的场景套件 View 在我的简单 View 应用程序中显示移动的 3D 对象。

例如windows中的bee.glb文件,我使用的是这四个文件:

  1. 正文.bmp
  2. 正文.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] Error: Physically based lighting model is not supported by the OpenGL renderer, using Phong instead (3) 2019-09-02 03:29:13.297536-0700 3DVideo[6430:105708] [SceneKit] Error: Physically based lighting model is not supported by the OpenGL renderer, using Phong instead (2) 2019-09-02 03:29:13.308381-0700 3DVideo[6430:105708] [SceneKit] Error: Physically based lighting model is not supported by the OpenGL renderer, using Phong instead"

最佳答案

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

关于swift - 具有移动对象的场景套件 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57755758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com