Hi guys
How could I control the opacity of the ModelEntity or mesh in RealityKit?
Hi guys
How could I control the opacity of the ModelEntity or mesh in RealityKit?
Were you able to resolve your issue? I ran this code on a new RealityKit macOS project on macOS 12.0. The code should be similar on iOS, you should just need to change from NSColor to UIColor.
let entity = ModelEntity.init(mesh: MeshResource.generateBox(size: SIMD3<Float>(1.0, 1.0, 1.0)))
let anchor = AnchorEntity.init()
anchor.addChild(entity)
arView.scene.anchors.append(anchor)
var material = SimpleMaterial()
material.baseColor = MaterialColorParameter.color(
NSColor.init(displayP3Red: 1.0, green: 0.0, blue: 0.0, alpha: 0.5)
)
entity.model?.materials.append(material)
You can also take a look at our new PhysicallyBasedMaterial and CustomMaterial types in iOS 15 and macOS Monterey.
Not even an option to fade in a model at this time, another thing I'm hoping for soon. I'm sure it's being worked on… quite a standard feature in any scene graph.
@Gerry915 here is a package I made for fading entities in and out: https://github.com/Reality-Dev/RealityKit-Fade
Code Block swift var material = SimpleMaterial() material.baseColor = MaterialColorParameter.color( UIColor(red: 0.97, green: 0.75, blue: 0.09, alpha: 0.10) )
See my response below.
Were you able to resolve your issue? I ran this code on a new RealityKit macOS project on macOS 12.0. The code should be similar on iOS, you should just need to change from NSColor to UIColor.
let entity = ModelEntity.init(mesh: MeshResource.generateBox(size: SIMD3<Float>(1.0, 1.0, 1.0)))
let anchor = AnchorEntity.init()
anchor.addChild(entity)
arView.scene.anchors.append(anchor)
var material = SimpleMaterial()
material.baseColor = MaterialColorParameter.color(
NSColor.init(displayP3Red: 1.0, green: 0.0, blue: 0.0, alpha: 0.5)
)
entity.model?.materials.append(material)
You can also take a look at our new PhysicallyBasedMaterial and CustomMaterial types in iOS 15 and macOS Monterey.
It worked for me, thanks!