Improving ground shadows for objects in RealityKit?

I am currently working with RealityKit to load a USDZ model from my application's bundle. My model is being added like so;

Code Block
var modelLoading: Cancellable?
modelLoading = Entity.loadAsync(named: name)
.receive(on: RunLoop.main)
.sink(receiveCompletion: { (completion) in
modelLoading?.cancel()
}, receiveValue: { (model) in
model.setScale(SIMD3(repeating: 5.0), relativeTo: nil)
let parentEntity = ModelEntity()
parentEntity.addChild(model)
let entityBounds = model.visualBounds(relativeTo: parentEntity)
parentEntity.collision = CollisionComponent(shapes: [ShapeResource.generateBox(size: entityBounds.extents).offsetBy(translation: entityBounds.center)])
self.arView.installGestures(for: parentEntity)
let anchor = AnchorEntity(plane: .horizontal)
anchor.addChild(aparentEntity)
arView.scene.addAnchor(anchor)
})

When my model is added to the scene, which works as expected, I notice that the model has no "ground shadows." This varies in comparison to viewing this model via AR Quick Look, as well as when loading a Reality Composer project (.rcproject), which seems to automatically add grounding shadows.

While I have done some research into PointLight, DirectionalLight, and SpotLight entities, I am quite a novice at 3D modeling, and just only seek to add a shadow just below the object, to give it a more realistic appearance on tables.

Is there a methodology for achieving this?

Replies

Hey Brandon,

As long as you haven't specified disableGroundingShadows in your render options, then the expected behavior is that any model would have a grounding shadow when added to an anchor with horizontal plane anchoring by default, no additional light entities needed.

Another possibility is that your model was authored with its origin at the top of the model, instead of the bottom, which would mean it might actually be under the plane and would not cast a shadow on the plane.

If neither of those cases apply, then please file a technical support incident and we will take a look at the model.

Thanks!
Hi @gchiste,

Thank you for your reply! I am not specifying disableGroundingShadows in my render options, though your comment pointed me in a few directions that is uncovering the root of my issue. I ended up downloading a sample .usdz from Apple's Quick Look gallery page, adding that to my app, and found that that model, too, had no shadows. As I looked through my code, I found that I was complicating how I was creating my AnchorEntity, and simplified to be an anchor with horizontal plane anchoring, which brought in shadows for the downloaded model.

Moreover, I can now see that my desired .usdz model does, in fact, have ground shadows. Albeit, they are lighter than I would have expected, and am analyzing the file in a 3D modeling program to better understand what may have been the root cause of the issue. As such, I will follow-up with a technical support incident if the issue persists, but I believe your clue regarding the model's anchor and the way I was creating the original AnchorEntity was causing the anomaly. Thank you!