RealityKit仅显示深色图像

时间:2019-07-11 09:50:26

标签: ios swift augmented-reality arkit realitykit

我正在使用ARKit 3和RealityKit开发iOS应用。我想在包含图像的房间内创建虚拟2​​d平面。因此,我使用了

Adding a material to a ModelEntity programmatically

但不是几乎是白色的图像将显示为非常暗,接近黑色。我还尝试了UnlitMaterial。它确实创造了更好的结果,但是图像仍然很暗。对于JPEG和PNG文件,此问题仍然存在。

在使用SceneKit的早期版本中,我通过以下方式解决了类似的问题

sceneView.automaticallyUpdatesLighting = true
sceneView.autoenablesDefaultLighting = true

我想图像确实通过这段代码使自己亮了。

如何解决RealityKit中的问题?

可能与之相关:https://forums.developer.apple.com/thread/119265

2 个答案:

答案 0 :(得分:0)

您可以使用每个.rcproject包含在Reality Composer中的ARView自动照明功能。尝试以下简单的iOS代码以了解其工作原理:

import ARKit
import RealityKit

class GameViewController: UIViewController {

    @IBOutlet var arView: ARView!

    override func viewDidLoad() {
        super.viewDidLoad()

        arView.cameraMode = ARView.CameraMode.ar

        arView.renderOptions = [.disableMotionBlur,
                                .disableDepthOfField]

        arView.automaticallyConfigureSession = true

        var material = SimpleMaterial()
        material.tintColor = UIColor.yellow
        material.baseColor = try! MaterialColorParameter.texture(
                                          TextureResource.load(named: "yourImg.jpg"))
        material.roughness = MaterialScalarParameter(floatLiteral: 0.1)
        material.metallic = MaterialScalarParameter(floatLiteral: 1.0)

        let sceneElement = try! Experience.loadBox()
        sceneElement.scale = SIMD3<Float>(x: 0.5, y: 0.5, z: 0.5)
        sceneElement.position = SIMD3<Float>(x: 1, y: 0.5, z: 0)

        let mesh: MeshResource = .generateSphere(radius: 1.0)
        let component = ModelComponent(mesh: mesh,
                                 materials: [material])

        sceneElement.components.set(component)
        arView.scene.anchors.append(sceneElement)
    }
}

或尝试类似的macOS代码:

import AppKit
import RealityKit

class GameViewController: NSViewController {

    @IBOutlet var arView: ARView!

    override func awakeFromNib() {

        arView.debugOptions = [.showStatistics,
                               .showPhysics]

        arView.environment.background = .color(ARView.Environment.Color.black)

        var material = SimpleMaterial()    
        material.tintColor = NSColor.yellow
        material.baseColor = try! MaterialColorParameter.texture(
                                          TextureResource.load(named: "yourImg.jpg"))
        material.roughness = MaterialScalarParameter(floatLiteral: 0.1)
        material.metallic = MaterialScalarParameter(floatLiteral: 1.0)           

        let sceneElement = try! TwoScenes.loadSecondScene()
        sceneElement.scale = SIMD3<Float>(x: 0.5, y: 0.5, z: 0.5)
        sceneElement.position = SIMD3<Float>(x: 1, y: 0.5, z: 0)

        let mesh: MeshResource = .generateSphere(radius: 1.0)
        let component = ModelComponent(mesh: mesh,
                                  materials: [material])

        sceneElement.components.set(component)
        arView.scene.anchors.append(sceneElement)
    }
}

答案 1 :(得分:0)

 let img = UIImage(named: ouputSrc, in: Bundle(path: resourcePath), compatibleWith: nil)
                
  var myMaterial = UnlitMaterial()
  myMaterial.baseColor = try! .texture(.load(named: ouputSrc, in: Bundle(path: resourcePath)))
  myMaterial.tintColor = UIColor.white.withAlphaComponent(1)