我使用了这个Medium 故事中的代码,但我没有使用 RealityComposer。我在锚点上添加了一个简单的球体和平面。但是结果很奇怪,球体投射了三盏灯,但飞机只有聚光灯。另一个问题是我看不到任何阴影出现。
任何人都可以帮忙吗?非常感谢!
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
for anchor in anchors {
let sphere = MeshResource.generateSphere(radius: 0.2)
let simplemodel = ModelEntity(mesh: sphere,
materials: [SimpleMaterial(color: .white,
isMetallic: false)])
usdzEntity = simplemodel
usdzEntity.generateCollisionShapes(recursive: true)
// Plane primitive
let plane: MeshResource = .generatePlane(width: 1.0,
depth: 1.0)
let material = SimpleMaterial(color: .white,
isMetallic: false)
let entity = ModelEntity(mesh: plane,
materials: [material])
usdzEntity.addChild(entity)
usdzAnchorEntity = AnchorEntity(anchor: anchor)
usdzAnchorEntity.addChild(usdzEntity)
scene.addAnchor(usdzAnchorEntity)
let lightAnchor = AnchorEntity(world: [0,0,-3])
lightAnchor.addChild(directLight)
lightAnchor.addChild(spotLight)
lightAnchor.addChild(pointLight)
scene.addAnchor(lightAnchor)
}
}