RealityKit –材质的Alpha透明度

问题描述

是否可以使纹理具有alpha透明度?

我有一个包含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)
}

解决方法

.tintColor.baseColor的乘数

如果您有一个带有预乘alpha(.png * RGB的{​​{1}}文件。您所需要做的就是另外使用一个A实例属性,其alpha值等于tintColor

0.9999


这是真实代码中的样子:

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

PS

对我来说,这似乎是RealityKit中的错误。我不知道为什么方法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) } 不能按预期工作。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...