I trying to use CustomMaterial with surfaceShader, followed this article
but my model not appear after I try obtain customMaterial to modelComponent, I catch error. How to use surfaceShader on usdz model? Have a good day!
private func obtainUSDZModel() {
guard let doll = try? Entity.load(named: "Doll") else { return }
guard var modelComponent = doll.components[ModelComponent.self] as? ModelComponent else {
print("Error Model Component")
return
}
let surfaceShader = CustomMaterial.SurfaceShader(named: "rainbow", in: MetalLibLoader.library)
guard let customMaterials = try? modelComponent.materials.map({ material -> CustomMaterial in
let customMaterial = try CustomMaterial(from: material, surfaceShader: surfaceShader)
return customMaterial
}) else { return }
modelComponent.materials = customMaterials
doll.generateCollisionShapes(recursive: true)
doll.components[ModelComponent.self] = modelComponent
doll.scale = .init(repeating: 1.0)
anchorEntity.addChild(doll)
arView.scene.anchors.append(anchorEntity)
}
console output:
Error Model Component