I want adding grounding shadow on my Entity
in RealityView
on visionPro. However it seems that the shadow can only appear on another Entity
. So I using plane detection in ARKit and add a transparent plane on it to render shadow.
let planeEntity = ModelEntity(mesh: .generatePlane(width: anchor.geometry.extent.width, height: anchor.geometry.extent.height), materials: [material])
planeEntity.components.set(OpacityComponent(opacity: 0.0))
But sometimes there will be a border around my Entity
on the plane.
I do not know why it will happen, and I want remove the border.
Thank you for the reply @YaShiho , I'm very happy to help you with your problem.
I can confirm that extra geometry is not necessary to render shadows on real geometry, however the effect is different on real geometry vs virtual geometry. Additionally, I believe the size of your objects is making it more difficult to see this effect on real world objects. To test this, try running this code in a brand new project inside the simulator (I've positioned the spheres above the table in the living room inside the simulator):
struct ImmersiveView: View {
var body: some View {
RealityView { content in
let mat = SimpleMaterial(color: .yellow, isMetallic: false)
@MainActor
func createSphere(radius: Float, position: SIMD3<Float>) -> Entity {
let sphere = Entity(components: [
ModelComponent(mesh: .generateSphere(radius: radius), materials: [mat]),
GroundingShadowComponent(castsShadow: true)
])
sphere.setPosition(position, relativeTo: nil)
return sphere
}
let sphereA = createSphere(radius: 0.1, position: [-0.2, 0.8, -1.7])
let sphereB = createSphere(radius: 0.05, position: [-0, 0.75, -1.7])
let sphereC = createSphere(radius: 0.01, position: [0.2, 0.71, -1.7])
content.add(sphereA)
content.add(sphereB)
content.add(sphereC)
}
}
}
You will notice shadows beneath the first two spheres, but not the third, because it is very small. I think this may be related to what you are seeing, because the models in your screenshot are also very small.
If increasing the size of your objects is not viable, this certainly seems like unexpected behavior so please file a bug report via Feedback Assistant and include as much detail about your use case as possible. If you do submit a report, please share your report number here. Thank you!