SCNCylinder 上的设置内容(图像)被反转(翻转)

Setting contents (images) on SCNCylinder is reversed (flipped)

我尝试使用以下代码在 SCNCylinder 对象上渲染图像:

    let coinGeometry = SCNCylinder(radius: 50, height: 55)
    coinNode = SCNNode(geometry: coinGeometry)
    coinNode.position = SCNVector3Make(0.0, 25.0, 25.0)
    coinScene.rootNode.addChildNode(coinNode)

   //Add image on cylinder shape
    let frontFacingImageMaterial = SCNMaterial()
    frontFacingImageMaterial.diffuse.contents = UIImage(named: "map")
    frontFacingImageMaterial.specular.contents = UIColor.blueColor()
    frontFacingImageMaterial.shininess = 5.0
    coinGeometry.firstMaterial = frontFacingImageMaterial

在圆柱体上,此图像显示为反转(翻转)。我该如何解决?

谢谢

来自How to flip UIImage horizontally?

UIImage* sourceImage = [UIImage imageNamed:@"whatever.png"];
UIImage* flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage 
                                        scale:sourceImage.scale
                           orientation:UIImageOrientationUpMirrored];

所以在 Swift 中,类似于:

if let originalImage = UIImage(named: "map") {
    let materialImage = UIImage(CGImage: originalImage.CGImage!, 
                                scale: originalImage.scale, 
                                orientation: .UpMirrored)
}

不要翻转原始图像数据,只需翻转它映射到几何体上的方式即可。将 frontFacingImageMaterial.diffuse.contentsTransform 设置为翻转 X 或 Y 的矩阵。