dhomes dhomes - 1 year ago 308
iOS Question

SceneKit, flip direction of SCNMaterial

extremely new to SceneKit, so just looking for help here:

I have an SCNSphere with a camera at the center of it

I create an SCNMaterial, doubleSided, and assign it to the sphere

Since the camera is at the center, the image looks flipped vertically, which when having text inside totally messes things up.

So how can i flip the material, or the image (although later it will be frames from a video), any other suggestion is welcome.

This solution, btw, is failing on me, normalImage is applied as a material (but the image is flipped when looking from inside the sphere), but assigning flippedImage results in no material whatsoever (white screen)

let normalImage = UIImage(named: "text2.png")
let ciimage = CIImage(CGImage: normalImage!.CGImage!)
let flippeCIImage = ciimage.imageByApplyingTransform(CGAffineTransformMakeScale(-1, 1))
let flippedImage = UIImage(CIImage: flippeCIImage, scale: 1.0, orientation: .Left)

sceneMaterial.diffuse.contents = flippedImage
sceneMaterial.specular.contents = UIColor.whiteColor()
sceneMaterial.doubleSided = true
sceneMaterial.shininess = 0.5

Answer Source

Instead of scaling the node (which may break your lighting) you can flip the mapping using SCNMaterialProperty's contentsTransform property.

material.diffuse.contentsTransform = SCNMatrix4MakeScale(1,-1,1);
material.diffuse.wrapT = SCNWrapModeRepeat; //or translate contentsTransform by (0,1,0);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download