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

时间:2015-11-10 20:02:35

标签: ios swift scenekit

我尝试使用以下代码在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

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

由于

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

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