我需要用图像包裹3d对象(scene
)。像这样:
我正在使用以下代码:
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对象,但看不到它上面的图像。我在这里做错了什么?我们不能实用地编辑scene
的几何部分吗?
我可以将图像包裹在SCNBox
或arkit
中的任何其他预定义形状周围,但不能与外部3d
对象一起包裹
答案 0 :(得分:1)
以下代码有效:
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中创建了scene box