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

추신

저에게는 RealityKit의 버그처럼 보입니다. 방법 .load(named: "file.png")이 예상대로 작동하지 않는 이유를 모르겠습니다 .