Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 454
Harshil.Chokshi Avatar asked Mar 17 '16 16:03

Harshil.Chokshi


2 Answers

Move "silver-background" to Assets.xcassets.

like image 62
beyowulf Avatar answered Oct 26 '22 20:10

beyowulf


// use this line instead of your current one and be sure that your image path is correct.. it works for me
// silverMaterial.diffuse.contents = [UIImage imageNamed:@"silver-background"];   
silverMaterial.diffuse.contents = [UIImage imageNamed:@"art.scnassets/silver-background.png"];
like image 34
morex87 Avatar answered Oct 26 '22 21:10

morex87