无法将纹理图像添加到ARKit中的多维数据集 [英] Not able to add texture image to a cube in ARKit

查看:111
本文介绍了无法将纹理图像添加到ARKit中的多维数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用材料"对象将图像添加到ARKit中的多维数据集.

I am not able to add an image to the cube in ARKit using the "Material" object.

这是代码:

import UIKit
import SceneKit
import ARKit

class SimpleBoxViewController: UIViewController, ARSCNViewDelegate {

var sceneView: ARSCNView!

override func viewDidLoad() {
    super.viewDidLoad()

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

    sceneView.delegate = self
    sceneView.showsStatistics = true

    let scene = SCNScene()

    let box = SCNBox(width: 0.2, height: 0.2, length: 0.2, chamferRadius: 0)

    let material = SCNMaterial() 

    //This is not working
    material.diffuse.contents = UIImage(named: "<someImage>.png")

    let node = SCNNode() 
    node.geometry = box
    node.geometry?.materials = [material]
    node.position = SCNVector3(0, -0.1, -0.5)
    scene.rootNode.addChildNode(node)

    sceneView.scene = scene


}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    let configuration = ARWorldTrackingConfiguration()
    sceneView.session.run(configuration)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    // Pause the view's session
    sceneView.session.pause()
}

我尝试添加各种不同的图像,但是没有任何效果.唯一有效的图像是名为"textures.png"的图像,该图像已预加载到ARKit项目中.

I tried to add various different images but nothing works. The only image that works is the image named "textures.png" which is preloaded into an ARKit project.

要加载图像是否有特定要求?

Is there a specific requirement for an image to be to loaded?

推荐答案

我不确定对此有100%的把握,但是问题可能在于在imageName中包含.png,因为此图像应该在您的素材资源中文件夹.

I'm not 100% sure on this one, but the issue might be with including the .png with the imageName, since this image should be in your Assets folder.

无论如何,这段代码对我有用,并且在创建带有图像的多维数据集方面尝试做同样的事情.

Anyway, this code is working for me and tries do to the same thing with regards to creating the cube with an image.

var box = SCNBox(width: pd.width, height: pd.height, length: 0.01,
chamferRadius: 0.0)
var imageMaterial = SCNMaterial()
var image = UIImage(named: "image")
imageMaterial.diffuse.contents = image
box.materials = [imageMaterial, imageMaterial, imageMaterial, imageMaterial, imageMaterial, imageMaterial]
var cube = SCNNode(geometry: box)

这篇关于无法将纹理图像添加到ARKit中的多维数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆