.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)
}
}