3

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

以编程方式将材质添加到 ModelEntity

但是不接近白色的图像会显示得很暗,接近黑色。我也试过了UnlitMaterial。它确实创造了更好的结果,但图像仍然很暗。此问题在 JPEG 和 PNG 文件上仍然存在。

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

sceneView.automaticallyUpdatesLighting = true
sceneView.autoenablesDefaultLighting = true

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

如何解决 RealityKit 中的问题?

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

4

2 回答 2

1

.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)
    }
}
于 2019-10-15T09:31:28.593 回答
1
 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)
于 2020-10-30T13:02:45.277 回答