Error in latest book? (Chapter 2: Nodes) not same in xCode

Hi

I am just going through the swift 3 book which I bought a couple of days ago and one thing that is not the same in the book is on page 42.

In the book, clicking GeometryFighter.scnassets should bring up a panel showing Settings and iOS Image Settings but on my latest Xcode clicking the GeometryFighter.scnassets folder in Xcode does nothing, no updating of the screen and the last viewed file is still shown. I can click the images in Textures and see the interface update to show the image but I do not get the settings screen when clicking the scnassets folder.

Xcode Version 8.0 (8A218a)

I just come across another discrepancy between the book and what Xcode shows. Page 44 shows the storyboard view in the book as having a dimension of Any | Any but in my storyboard you donā€™t have that option?, just iPhone/iPad sized screens so page 44 and 45 have different values for the constraints when setting up the pins (if you are following the book).

Also, on page 46 it says add the background to the scnScene with scnScene.background.contents = ā€œGeometryFighter.scnassets/Textures/Background_Diffuse.pngā€

I did that and instead of a blue image I get a grey one?!? in both the simulator and on my iPhone. The image is blue so why does it render it in greyscale?

I thought this book had been updated for Swift 3 and Xcode 8?. Has Apple released a new version of Xcode since the book was updated?

Also, is this the right place to post these kind of editorial issues?

Cheers
Geoff

For anybody else with the same grey image problem, for some reason it was 144 dpi in the download, recreated the image at 72 dpi and it it now appears blue and works fine.

Thanks - I fiddled with this for a while and ending up ignoring it when I realised it was the same in the sample code. Good to know the reason.

Had the same problem, and while just an annoyance, I wanted my background to be blue like the book. I updated the image to 72 dpi, deleted the old file in my Xcode project then added my new 72 dpi file. I then immediately got a build failed with error: /usr/bin/codesign failed with exit code 1.

Any thoughts / help? Assuming that 1) i donā€™t know what iā€™m doing, and/or 2. i shouldnā€™t mess with individual elements in an scnassets folder/group?

I copied the original scnassets folder back into my project and all works again.

Thanks.

Update: (rubber duck ā€“ asked / answered myself) ā€“ writing this post gave me some new Google search ideas: the issue is, indeed, with changing files in scnassets folder. Solution is to clean the project in both the DerivedData folder (~/Library/Developer/Xcode/DerivedData) and running ā€˜xattr -rc .ā€™ from terminal in the current project dir to remove all extended attributes.

That worked to solve the problem.

Details thanks to:

Glad you got it sorted. I have had that error a few times too.

I use PhotoShop CS6 mostly but use Pixelmator when this happens.

How did you edit the Background_Diffuse.png imageā€¦Which program did you use? After I edit the image in photoshop I get the error /usr/bin/codesign failed with exit code 1.

Photoshop is what causes the problem for me, I think it adds extra info to the image file which xCode has a fit over. Try using another app or even SHIFT+CMD+4 to grab the screen area of your image (assuming it fits 100% on screen).

I discovered this as well. I tested importing a Maya 3D image. I rendered out a frame out .png, and it worked in SceneKit. When I tried to clean the old photoshop image using the Terminal, I have no success. Iā€™m probably doing something wrong, with terminal. I sent a bug report to Apple 2 weeks agoā€¦ I have not heard from Apple. Also, I found that if you import the images in to an .atlas folder. it seems to work in most sales. it will stop the error. but I canā€™t get the ā€œscene.background.contentā€ to pickup the file. the scene node does not like the atlas directory, but the compile error goes away.

I think the steps are:

To view extened attributes:

  1. Open Terminal
  2. Type xattr ā€œdrag drop file hereā€

To remove extended attributes just add the -c flag as in:

  1. Open Terminal
  2. Type xattr -c ā€œdrag drop file hereā€
1 Like

Thanks, that resolved the compile error, but it is still grayscale (@72 dpi). Iā€™m continue with the book, since I have a working blue background file. Apple will fix this. Iā€™ll re-test this later. I think Apple wants SceneKit and SpriteKit to require an .atlas folder or all images, moving forward, but they havenā€™t got it working properly yet.

I saw this too and figured out what is going on. Itā€™s not the image resolution that causes the greyscale image. Itā€™s because that texture is indexed RGB and does not contain an alpha channel. This texture worked fine in Xcode 7, so it must be a problem that was introduced with Xcode 8.

I fixed it by using GIMP to add an alpha channel to the image and also to change the image mode to RGB. You can do this in GIMP by right-clicking on the layer and selecting ā€œAdd Alpha Channelā€ and then selecting Image ā†’ Mode ā†’ RGB. Be sure to select the ā€œAlpha Channelā€ checkbox when saving the png.

I opened the png file with Affinity Photo, changed the color mode to 16 bit than back to 8 bit and saved the updated file. It still has no alpha channel. Did a project clean in Xcode and after a recompilation the emulator showed the background as intended in blue.

Thanks! You helped me a lot!

I find it interesting that the background diffuse file renders blue in Xcode after selecting it. Renders grey on the simulator and renders red on the my iPhone6, so weird!

Thanks Geoff did what you did recreated the image at 72dpi and now works fine, so many different comments on the forum not sure which to follow sometimes as a newbie but tried yourā€™s first.

Thanks.

Thanks. Does anybody know why the background needs to be 72 dpi to be displayed correctly? Is this documented in SceneKit anywhere?

I just opened the file in Paint and resaved it (e.g. File ā†’ Save As PNG)
Did the trick - presumably it messes with the DPI by default.

I fixed this by dragging the image to Assets.xcassets and replacing this line:
scnScene.background.contents = "GeometryFighter.scnassets/Textures/ Background_Diffuse.png"
with this: scnScene.background.contents = "Background_Diffuse"

Changing the image DPI to 72 in Preview : Tools : Adjust Sizeā€¦ worked for me.