Reputation: 35
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
Upvotes: 2
Views: 612
Reputation: 126167
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.
Upvotes: 1
Reputation: 7665
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)
}
Upvotes: 3