Harshil.Chokshi Harshil.Chokshi - 9 months ago 55
iOS Question

Want to add Image as texture in scenekit ios

I have created an object and now I am trying to add an image as a texture to the object. But for some reason the texture doesnt show up and the object appears white. I downloaded a png file and added it to Xcode and created a SCNMaterial object that uses the image.

SCNMaterial *silverMaterial = [SCNMaterial material];
silverMaterial.diffuse.contents = [UIImage imageNamed:@"silver-background"];

SCNBox *horizontalBarOne = [SCNBox boxWithWidth:11 height:0.5 length:0.5 chamferRadius:0];
SCNNode *horizontalBarOneNode = [SCNNode nodeWithGeometry:horizontalBarOne];
horizontalBarOneNode.position = SCNVector3Make(0, 2.0, 0.5);
horizontalBarOne.materials = @[silverMaterial];
[scene.rootNode addChildNode:horizontalBarOneNode];

What am I doing wrong?

Answer Source

Move "silver-background" to Assets.xcassets.