4

I am setting my 3d model’s cull mode and double sided properties directly in my usdz file in my Scene graph. However, once it renders live real time, these properties are automatically reset to default. Is there a way I can access these properties programmatically through BodyEntity to ensure they're set when I render the character?

Settings

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Mochi
  • 1,059
  • 11
  • 26

2 Answers2

2

There is a new enum in RealityKit 2.0 for iOS 15 called FaceCulling:

enum MaterialParameterTypes.FaceCulling

with front, back and none cases. You can use it in PhysicallyBasedMaterial or in SimpleMaterial.

There's still no doubleSided property in RealityKit, like the popular property in SceneKit.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 1
    How would I access this from BodyEntity or ModelEntity in RealityKit? – Mochi Jul 01 '21 at 12:20
  • 1
    Using ModelComponent — https://stackoverflow.com/questions/67408552/change-a-colour-of-an-object/67419742#67419742 – Andy Jazz Jul 01 '21 at 13:06
  • 1
    @Mochi, also read this story, and leave your comment if you wish — https://medium.com/geekculture/the-top-9-most-in-demand-features-for-realitykit-3-0-c1a50f08909d – Andy Jazz Jul 02 '21 at 10:03
  • I have changed the culling to none and the back of the model is still not rendered correctly. – Darkwonder Sep 27 '22 at 06:39
1

The working solution for Xcode 13.4.1., Swift 5.6.1.

if var material = particleME.model?.materials.first as? PhysicallyBasedMaterial {
    material.faceCulling = .none
    // Set transparency (if needed):
    // material.blending = .transparent(opacity: .init(floatLiteral:0.5))
    particleME.model?.materials = [material]
}
  • Changing any property on the struct only changes the value since it's copied (by value). That's why I have to reassign it.
  • Setting the faceCulling via the Scene Graph Editor via Settings -> Visibility -> "Cull _" is not possible because there is no "none" option.
  • Your .usdz will most likely be a Entity (and not ModelEntity). Don't type cast it inside an if because it will most of the time fail.

NOTE: I have set the transparency via the Scene Graph Editor and using the above code reset it to 1.0. If you have edited your .usdz via the SGE it might be possible that modifying the materials array (like I did) will reset your previous settings. I had to set the blending to transparent to get my transparency back.

My suggestion is that when working with RealityKit, offload as many .usdz or 3D file changes to the 3D content creator because the API leaves a lot to be desired besides the stuff that does not work.

OTHER HELPFUL LINKS:

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Darkwonder
  • 1,149
  • 1
  • 13
  • 26