对象在场景中,当我按下按钮实时更改它的纹理时我想要。可能吗? 我已经尝试过,但它不起作用。
VirtualObjectsManager.shared.getVirtualObjectSelected()?.geometry?.materials.first?.diffuse.contents = UIColor.red
答案 0 :(得分:1)
假设这是你的对象:
let obj = SCNNode()
obj.name = "obj1" // set a name, so you can access your object node later
首先,为对象的材质设置名称:
let material = SCNMaterial()
material.name = "BackgroundImage" // set a name for the material
material.diffuse.contents = UIImage(named: "texture1.jpg")
obj.geometry?.materials = [material]
然后,在按下按钮的方法中,您需要一个对象的实例:
let node = sceneView.scene.rootNode.childNode(withName: "obj1", recursively: true)
然后你可以改变它的纹理:
let material = node.geometry?.material(named: "BackgroundImage")
material.diffuse.contents = UIImage(named: "texture2.jpg")