RealityKit - Trasparenza Alpha del materiale
Aug 20 2020
È possibile avere la trasparenza alfa con le trame?
Ho un file png che contiene RGBA a 8 bit, ma per qualche motivo, le parti che dovrebbero essere trasparenti sono semplicemente nere.
Assegno il materiale in questo modo:
private func setupLightMeshes(_ scene: Entity) {
let lightEntity = scene.findEntity(named: "LightWindow_Plane")!
var lightMaterial = UnlitMaterial()
lightMaterial.baseColor = try! MaterialColorParameter.texture(
TextureResource.load(named: "light.png")) // this is 8bpc RGBA
var modelComponent = lightEntity.components[ModelComponent] as! ModelComponent
modelComponent = ModelComponent(mesh: modelComponent.mesh, materials: [lightMaterial])
lightEntity.components.set(modelComponent)
}
Risposte
1 AndyFedoroff Aug 24 2020 at 20:18
.tintColor
è un moltiplicatore per .baseColor
Se hai un .png
file con un alfa ( RGB
* A
) premoltiplicato . tutto ciò che devi fare è utilizzare in aggiunta una tintColor
proprietà di istanza con alfa uguale a 0.9999
.
material.tintColor = UIColor(white: 1.0, alpha: 0.9999)
Ecco come appare in un codice reale:
fileprivate func material() -> UnlitMaterial {
var material = UnlitMaterial()
material.baseColor = try! .texture(.load(named: "transparent.png"))
material.tintColor = UIColor(white: 1.0, alpha: 0.9999)
return material
}
override func viewDidLoad() {
super.viewDidLoad()
let sphere: MeshResource = .generateSphere(radius: 0.5)
let entity = ModelEntity(mesh: sphere,
materials: [material()])
let anchor = AnchorEntity()
anchor.orientation = simd_quatf(angle: .pi, axis: [0, 1, 0])
anchor.addChild(entity)
arView.scene.anchors.append(anchor)
}
PS
Per me, sembra un bug in RealityKit. Non so perché il metodo .load(named: "file.png")
non funzioni come previsto.