RealityKit –マテリアルのアルファ透明度

Aug 20 2020

テクスチャでアルファ透明度を設定することは可能ですか?

8ビットRGBAを含むpngファイルがありますが、何らかの理由で、透明になるはずの部分が単純に黒くなっています。

私は次のように資料を割り当てます:

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)
}

回答

1 AndyFedoroff Aug 24 2020 at 20:18

.tintColor の乗数です .baseColor

.pngアルファ(RGB* A)が事前に乗算されたファイルがある場合。あなたがする必要があるのはtintColor、アルファがに等しいインスタンスプロパティを追加で使用すること0.9999です。

material.tintColor = UIColor(white: 1.0, alpha: 0.9999)


実際のコードでは次のようになります。

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

私にとっては、RealityKitのバグのようです。メソッド.load(named: "file.png")が期待どおりに機能しない理由がわかりません。