Applying Decal Textures to Material of a MeshResource

Is there a technique to apply a png with an alpha channel, so that the opaque parts of the image are "stamped" onto the entity's surface like a decal?

The code shown applies an image to all 6 sides of a box. It works, but the box geometry itself becomes transparent wherever the texture is transparent. I would like the box to remain opaque with the base color showing through.

let block = MeshResource.generateBox(width: 0.1, height: 0.1, depth: 0.1, cornerRadius: 0.01, splitFaces: false)

var material = PhysicallyBasedMaterial()
material.blending = .transparent(opacity: 1.0)

do {

  let texture = try TextureResource.load(named: "texture_9")
  material.baseColor = .init(tint: .white, texture: .init(texture))
  let entity = ModelEntity(mesh: block, materials: [material])

} catch {
  print("TextureResource.load(...) failed")
}

Hello,

I would like the box to remain opaque with the base color showing through.

This can be achieved with a CustomMaterial. I recommend that you take a look at Modifying RealityKit Rendering Using Custom Materials to get started with CustomMaterial.

Then, if you have further questions specific to your implementation, I recommend that you Request Technical Support.

Applying Decal Textures to Material of a MeshResource
 
 
Q