ios - 如何在 ARkIt 2 中将图像包裹在 3d 对象上?

标签 ios iphone scenekit augmented-reality arkit

我需要用图像包装 3D 对象(场景)。像这样:

enter image description here

我正在使用以下代码:

let imageMaterial = SCNMaterial()
let image = UIImage(named: "temp_flow_image")
imageMaterial.diffuse.contents = image

let objectScene = SCNScene(named: "art.scnassets/frame.scn")
    let objectNode: SCNNode = objectScene!.rootNode.childNode(withName: "frame", recursively: true)! 
objectNode.geometry?.firstMaterial?.diffuse.contents = imageMaterial

objectNode.position = SCNVector3(0,0,-4)

let scene = SCNScene() // Main scene of the app
self.sceneView.scene = objectScene!

整个过程是这样的:

3d 对象加载为 SCNNode 并以编程方式将图像包裹在其周围。我可以看到 3D 对象,但看不到其上方的图像。我在这里做错了什么?我们不能实用地编辑场景的几何部分吗?

我可以将图像包裹在 SCNBoxarkit 中的任何其他预定义形状中,但不能使用外部 3d 对象

最佳答案

以下代码有效:

self.sceneView.scene.rootNode.enumerateChildNodes { (node, _) in
if(node.name == "box") {
   parentNode = node
   let geometry = parentNode.geometry
   geometry?.firstMaterial?.diffuse.contents = imageToDisplay
   parentNode.position = SCNVector3Make(0, 0, -2.9)
   let boxShape:SCNPhysicsShape = SCNPhysicsShape(geometry: geometry!, options: nil)
            parentNode.physicsBody = SCNPhysicsBody(type: .static, shape: boxShape)
            parentNode.physicsBody?.restitution = 1
        }
    }

 sceneView.scene.rootNode.addChildNode(parentNode)

我在 Xcode 中创建了场景框

关于ios - 如何在 ARkIt 2 中将图像包裹在 3d 对象上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53858423/

相关文章:

iphone - iPhone可以设置视频报警吗?

ios - SceneKit 相机仅在 x 轴上跟随对象? - swift

ios - SceneKit 子节点位置在父节点旋转期间未更改

iphone - 帧速率与 CADisplayLink 和 drawRect 妥协

ios - 如何在 iOS 上通过 UITextFields 进行枚举

ios - CLLocation 管理器使用默认位置而不更新实际位置

iphone - UIImageView 的图像的多重设置

ios - class is not-key value coding compliant error 但 Storyboard 中的一切都是正确的

iphone - 如何为 iPhone 构建不同高度图像的 3 列布局

ios - 使用 SCNRenderer 时未呈现 overlaySKScene