Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify two-sided material for RealityKit / ARView?

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?

like image 302
smithco Avatar asked Oct 17 '19 22:10

smithco


People also ask

What can I do with 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.

How do I use arview in Android?

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.

How do I implement custom rendering effects in realitykit?

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.

What can you do with the ARKit framework?

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.


Video Answer


2 Answers

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
like image 116
Mark D Avatar answered Oct 05 '22 03:10

Mark D


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.

enter image description here

like image 28
Nativ Avatar answered Oct 05 '22 01:10

Nativ