gpt4 book ai didi

scenekit - SwiftUI-如何添加Scenekit场景

转载 作者:行者123 更新时间:2023-12-03 17:41:09 24 4
gpt4 key购买 nike

如何将Scenekit场景添加到SwiftUI View ?

我使用标准的“船舶场景”示例尝试了以下“Hello World” ...

import SwiftUI
import SceneKit


struct SwiftUIView : View {
var body: some View {

ship()

Text("hello World")


}


但这没有用:
enter image description here

最佳答案

您不再需要使用UIViewRepresentable。这是SwiftUI的更新代码

import SwiftUI
import SceneKit

struct ContentView: View {
var scene: SCNScene? {
SCNScene(named: "Models.scnassets/Avatar.scn")
}

var cameraNode: SCNNode? {
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 2)
return cameraNode
}

var body: some View {
SceneView(
scene: scene,
pointOfView: cameraNode,
options: [
.allowsCameraControl,
.autoenablesDefaultLighting,
.temporalAntialiasingEnabled
]
)
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

关于scenekit - SwiftUI-如何添加Scenekit场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56743724/

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