【发布时间】:2020-09-20 04:53:32
【问题描述】:
使用 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)
}
}
【问题讨论】:
-
你能提供更多你的代码吗?根据错误,我认为问题出在模型而不是纹理上。
-
@iicaptain 嘿,感谢您的回复。刚刚更新了代码,其中包含 ViewController 中的所有内容。没有触及任何其他 Realitykit 文件。我尝试加载的月球实体来自 Reality Composer 的 RCProject 文件。
-
我遇到了完全相同的问题。它似乎与模型无关,因为我尝试了一些来自不同来源的不同模型。
标签: arkit swift5 realitykit