使用RealityKit,尝试将月球实体的材质更改为自定义 .jpg 并通过 hitTest 在屏幕上轻触来生成该对象。但是,在我轻触时没有任何显示,并且在调试中出现以下错误:[Collision] Bad paramater (SphereRadius), value = 0.000000, passed to shape creation.
import UIKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touchLocation = touches.first?.location(in: arView){
let hitTest = arView.hitTest(touchLocation)
if let hitResult = hitTest.first {
addObject(at: hitResult)
}
}
}
func addObject(at hitResult: CollisionCastHit) {
let moonAnchor = try! Galaxy.loadWorld()
let moon = moonAnchor.moon! as! ModelEntity
var material = SimpleMaterial()
material.baseColor = try! MaterialColorParameter.texture(TextureResource.load(named: "8k_moon.jpg"))
moon.model?.materials = [material]
moon.position = SIMD3(x: hitResult.position.x, y: hitResult.position.y, z: hitResult.position.z)
arView.scene.addAnchor(moonAnchor)
}
}