SCNMaterial 中的图像纹理始终为灰色。如何上色?
Image texture in SCNMaterial is always grey. How to apply color?
我正在按照 Apple 文档中的示例编写图像识别应用程序:https://developer.apple.com/documentation/arkit/detecting_images_in_an_ar_experience
到目前为止一切正常,现在我想将透明平面覆盖图更改为图像。飞机的material我是这样设置的
let image = "overlay"
let material = SCNMaterial()
material.locksAmbientWithDiffuse = true;
material.isDoubleSided = false
material.diffuse.contents = image
material.ambient.contents = UIColor.white
let planeNode = SCNNode(geometry: plane)
planeNode.geometry?.materials = [material]
图片加载渲染完成,就是总是缺色。原图为红色,叠加层为b/w。
我已经尝试了许多不同的环境和漫反射设置但没有成功。我在这里错过了什么?
谢谢
在您的代码中,下一行是 String
类型,而不是 UIImage
类型:
let image: String = "overlay"
试试下面的代码:
let plane = SCNPlane(width: 10, height: 10)
let image = UIImage(named: "art.scnassets/texture")
// let image = UIColor.red
// let image = UIColor(hue: 0.25, saturation: 0.5, brightness: 0.75, alpha: 1)
let material = SCNMaterial()
material.locksAmbientWithDiffuse = true
material.isDoubleSided = false
material.diffuse.contents = image
material.ambient.contents = UIColor.white
let planeNode = SCNNode(geometry: plane)
planeNode.geometry?.materials = [material]
scene.rootNode.addChildNode(planeNode)
此外,将 diffuse
material 广告位的图像保存为 PNG
格式。
为了将来参考,以下是我发现的内容:
图片不得重名,即使保存在不同的组或文件夹中。我使用图像的名称作为加载叠加层的参考。当我更改名称并手动获取参考(通过 switch/case)时,一切正常。
我正在按照 Apple 文档中的示例编写图像识别应用程序:https://developer.apple.com/documentation/arkit/detecting_images_in_an_ar_experience
到目前为止一切正常,现在我想将透明平面覆盖图更改为图像。飞机的material我是这样设置的
let image = "overlay"
let material = SCNMaterial()
material.locksAmbientWithDiffuse = true;
material.isDoubleSided = false
material.diffuse.contents = image
material.ambient.contents = UIColor.white
let planeNode = SCNNode(geometry: plane)
planeNode.geometry?.materials = [material]
图片加载渲染完成,就是总是缺色。原图为红色,叠加层为b/w。 我已经尝试了许多不同的环境和漫反射设置但没有成功。我在这里错过了什么?
谢谢
在您的代码中,下一行是 String
类型,而不是 UIImage
类型:
let image: String = "overlay"
试试下面的代码:
let plane = SCNPlane(width: 10, height: 10)
let image = UIImage(named: "art.scnassets/texture")
// let image = UIColor.red
// let image = UIColor(hue: 0.25, saturation: 0.5, brightness: 0.75, alpha: 1)
let material = SCNMaterial()
material.locksAmbientWithDiffuse = true
material.isDoubleSided = false
material.diffuse.contents = image
material.ambient.contents = UIColor.white
let planeNode = SCNNode(geometry: plane)
planeNode.geometry?.materials = [material]
scene.rootNode.addChildNode(planeNode)
此外,将 diffuse
material 广告位的图像保存为 PNG
格式。
为了将来参考,以下是我发现的内容: 图片不得重名,即使保存在不同的组或文件夹中。我使用图像的名称作为加载叠加层的参考。当我更改名称并手动获取参考(通过 switch/case)时,一切正常。