2

I have trying to render an image on SCNCylinder object using following code:

    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

On cylinder, this image is being shown as reversed (flipped). How can I fix it?

Thanks

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
A.Bajwa
  • 35
  • 3

2 Answers2

3

From How to flip UIImage horizontally?:

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

So in Swift, something like:

if let originalImage = UIImage(named: "map") {
    let materialImage = UIImage(CGImage: originalImage.CGImage!, 
                                scale: originalImage.scale, 
                                orientation: .UpMirrored)
}
Community
  • 1
  • 1
Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
1

Don't flip the original image data, just flip the way it gets mapped onto the geometry. Set frontFacingImageMaterial.diffuse.contentsTransform to a matrix that flips either X or Y.

rickster
  • 124,678
  • 26
  • 272
  • 326