以编程方式添加时出现条状材料

时间:2018-11-13 19:12:24

标签: swift textures arkit texture-mapping material-swift

我正在使用以.jpg为材料的3D模型。当我在Xcode中分配它时,一切正常: enter image description here

现在,当我以编程方式添加scene及其材料时,似乎会拉伸.jpg并将其弄乱。

代码:

override func viewDidLoad() {
    super.viewDidLoad()

    self.sceneView = ARSCNView(frame: self.view.frame)
    self.view.addSubview(self.sceneView)
    sceneView.delegate = self

    let scene = SCNScene()
    let baseScene = SCNScene(named: "art.scnassets/testing.scn")
    let baseNode = baseScene?.rootNode.childNode(withName: "base", recursively: true)
    baseNode?.position  = SCNVector3(0, 0, 0)

    let material = SCNMaterial()
    material.diffuse.contents = UIImage(named: "art.scnassets/texture.jpg")
    baseNode?.geometry?.materials = [material]

    scene.rootNode.addChildNode(baseNode!)

    sceneView.scene = scene
}

下面是它的样子:

enter image description here

0 个答案:

没有答案