如何使用ARKit放置OBJ类型的3D模型? [英] How to place a 3D model of type OBJ with ARKit?
本文介绍了如何使用ARKit放置OBJ类型的3D模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用新的Apple ARKit放置3D模型时,我需要一些帮助.是否可以放置类型为OBJ
的对象?我正在尝试放置头骨的3D模型.
I need some help with placing a 3D model with the new apple ARKit. Is it possible to place an object of type OBJ
? I'm trying to place a 3d model of a skull.
//Load the OBJ file
let bundle = Bundle.main
guard let url = bundle.url(forResource: "Cranial", withExtension: "obj") else {
fatalError("Failed to find model file")
}
let asset = MDLAsset(url:url)
guard let object = asset.object(at: 0) as? MDLMesh else {
fatalError("Failed to get mesh from asset")
}
let scene = SCNScene()
let nodeCranial = SCNNode.init(mdlObject: object)
nodeCranial.simdPosition = float3(0, 0, 0.5)
sceneView.scene.rootNode.addChildNode(nodeCranial)
我不知道为什么镜头前什么也没有出现.如果我使用以下行而不是上面的nodeCranial,它将起作用:
I don't know why nothing shows up in front of the camera. It works if I use the following line instead of the nodeCranial from above:
let cubeNode = SCNNode(geometry: SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0))
为什么它也不能用于OBJ
文件?上面的代码在func viewDidLoad()
中.
Why doesn't it work for OBJ
file too? The code above is in the func viewDidLoad()
.
推荐答案
let tempScene = SCNScene(named: "art.scnassets/cat/cat.obj")!
modelNode = tempScene.rootNode
modelNode.simdPosition = float3(0, 0, 0.5)
sceneView.scene.rootNode.addChildNode(modelNode)
您可以以这种方式加载.obj,.scn或.dae文件.
you can load .obj, .scn or .dae files like this way.
这篇关于如何使用ARKit放置OBJ类型的3D模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文