2015-11-10 31 views
2

我已經嘗試使用以下代碼來呈現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 

在汽缸,正在顯示當前圖像作爲反轉(翻轉)。我該如何解決它?

感謝

回答

1

不翻轉的原始圖像數據,只需扳動它被映射到的方式幾何。將frontFacingImageMaterial.diffuse.contentsTransform設置爲翻轉X或Y的矩陣。

3

How to flip UIImage horizontally?

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

所以在斯威夫特,是這樣的:

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