我已经尝试使用texturetool
GUIPVRTexTool
生成每像素 4 位格式的 .pvrtc 纹理,通过 Swift 通过 SceneKit 加载SKTexture
,然后最终提供用作漫反射纹理,SCNSphere
如下代码
let diffuse_cloudTexture = SKTexture(imageNamed: "dc_4096.pvr")
let node = SCNNode()
node.geometry = SCNSphere(radius: 1)
node.geometry!.firstMaterial!.diffuse.contents = SKTexture(rect: CGRect(x: 0, y: 0, width: 4096, height: 2048), in: diffuse_cloudTexture)
node.geometry!.firstMaterial!.normal.contents = UIImage(named: "normal")
node.geometry!.firstMaterial!.isDoubleSided = false
node.geometry!.firstMaterial!.shininess = 10
node.geometry!.firstMaterial!.isLitPerPixel = true
scene.rootNode.addChildNode(node)
... <other unrelated code left out>
我
CGRect
在上面指定要指定里面的子纹理。我在要生成的源纹理中包含了 2 个纹理。上面是云纹理,下面是漫反射纹理。
因为texturetool
我使用了以下命令
texturetool -e PVRTC --channel-weighting-linear --bits-per-pixel-4 -o dc_4096.pvrtc -f PVR -p dc_4096_preview.png source_4096.png
因为PVRTexTool
我确实尝试了两种格式 => PVRTC 4bpp 和 PVRTCII 4bpp 都适用于 OpenGL 2.0。
一个显着的区别是该工具生成为 .pvr,但前者生成为 .pvrtc。因此,我在代码中使用相应的后缀,具体取决于用于生成此类纹理的工具。
不管我做什么,都是空洞透明的。球体没有纹理。从调试日志中,我通过
print(diffuse_cloudTexture.debugDescription)
print(diffuse_cloudTexture.textureRect())
print(diffuse_cloudTexture.size())
它显示
<SKTexture> 'dc_4096.pvr' (128 x 128)
(0.0, 0.0, 1.0, 1.0)
(128.0, 128.0)
top: 0.0, bottom: 0.0
为什么它只能识别 128x128 的大小。相反,我的尺寸为 4096x4096。
另外,如果使用以下代码
let diffuse_cloudTexture = SKTexture(imageNamed: "dc_4096.pvr")
let node = SCNNode()
node.geometry = SCNSphere(radius: 1)
node.geometry!.firstMaterial!.diffuse.contents = diffuse_cloudTexture
node.geometry!.firstMaterial!.normal.contents = UIImage(named: "normal")
它显示了如下奇怪的结果。
它应该是正常的地球纹理。
可能是什么问题?以及如何通过 SKTexture 使用 .pvrtc 纹理和 SceneKit?
编辑
(寻找解决方案仍在开发中)
- 首先感谢评论中看到的@KnightOfDragon。加载的奇怪纹理是默认的 X 图像,当它找不到要加载的纹理时。现在我明白了
SKTexture: Error loading image resource: "dc_4096.pvrtc"
。因此 128x128 分辨率的纹理应该是 X 默认图像。 - 这是正确的。似乎
SKTexture
不支持 .pvr 类型,因为@KnightOfDragon 在评论中指出了我。所以我只是尝试使用MTLTexture
viaMTKTextureLoader
并且现在能够将纹理渲染到球体上。我接下来面临的问题是如何以与SKTexture
via相同的方式抓取完整纹理的一部分SKTexture(rect: ...<rect to grab>, in: ...<SKTexture>...)
。我知道MTLTexture
支持 .pvr 的线索是查看它支持的像素格式列表。