I'm trying to load a model and texture in RealityKit (set up in an ARView instance), but I can't seem to figure out how to specify the material should be two-sided.
I have the model loaded up as a ModelEntity
, the texture loaded up as a TextureResource
. The model and texture are loading up, but are rending one-sided. Since the model is open (i.e., back faces are visible), there are gaps on how it is rendered.
So far, I have,
let entity: ModelEntity = try .loadModel(named: "model.obj")
var material = SimpleMaterial()
material.baseColor = try .texture(.load(named: "texture.png"))
entity.model?.materials = [material]
I was hoping to find a property such as
material.twoSided = true
but so far, I have not found the equivalent thing in RealityKit.
Anyone know how to set two-sided materials in RealityKit?
Use RealityKit’s rich functionality to create compelling augmented reality (AR) experiences. Import fully formed assets, including sophisticated compositions that you make with the Reality Composer app, or build them from meshes, materials, and textures.
Use an ARView instance to display rendered 3D graphics to the user. You typically add a single view to your app’s storyboard, and then provide an outlet for that view in your code. Alternatively, you can create and add a view to your view hierarchy programmatically at runtime, as you would any other view.
Write Metal shader functions to implement custom rendering effects. A bitmask used to define the collision group to which an entity belongs. A set of masks that determine whether entities can collide during simulations. Create collision filters to control which objects collide. Configure your RealityKit scenes to avoid performance bottlenecks.
Simulate and render 3D content for use in your augmented reality apps. Use the RealityKit framework to implement high-performance 3D simulation and rendering. RealityKit leverages information provided by the ARKit framework to seamlessly integrate virtual objects into the real world.
There doesn't seem to be any way to do this programmatically at the moment via the RealityKit APIs.
Can you change your model definition so it doesn't do back face culling? For example in a USDZ file I am importing it defines one part of the mesh as:
def Mesh "Plane_1"
{
uniform bool doubleSided = 1
You might be able to convert your obj file to a used file using usdzconvert first (https://developer.apple.com/download/more/?=USDPython) then edit the file manually, then import that in to your scene.
It might also be depending on how the model is setup that you can pass in more than one material to the materials array that are applied to different parts of the model, you can see how many materials the model expects:
entity.model?.mesh.expectedMaterialCount
As others already answered you can't do it programmatically. You can however do it manually for each model via the inspection panel. See the image below. Near the bottom, you have "Double Sided" checkbox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With