4

I have a collada file, it contains a cube, from this I export the data to a file (just raw bytes), and I import the bytes into iOS. All good, I examined the data and all looks the same for vertices on iOS and osx.

However when I examine the Collada file, the normals are very different from what SceneKit has

In SceneKit the normals are either 0, -1 or 1. In the Collada file I have -2.831...,-1.31..., etc.

Any insight appreciated,

Thanks

D

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Darren
  • 269
  • 3
  • 8
  • 1
    The normals in your file doesn't seem normalized (length of 1). Maybe your program doesn't care about that when exporting the geometry. – David Rönnqvist Jun 15 '13 at 15:08
  • Do you mean within Collada file the normals aren't (normalised), but within scene kit they have been? Does this matter? or is this normal? – Darren Jun 16 '13 at 05:38
  • -2.831 is bigger than -1 so it isn't normalized. In most cases you only care about the angle of the surface normal so the end result should matter visually. If this is the difference you are seeing in the data and what you see on screen is as expected then I would say that you have nothing to worry about. – David Rönnqvist Jun 16 '13 at 08:14
  • Can you post an actual x,y,z normal from Collada and its SceneKit counterpart? – Wil Shipley Jan 08 '14 at 13:11
  • Hi Wil, I actually worked out what my issue was (can't remember this precise issue was), but I ended up re-writing everything from scratch and understanding it a bit better, I can now export from blender, to SceneKit (using collada) and then write my byte format out to disk, process in iPhone. – Darren Jan 08 '14 at 16:10

1 Answers1

1

In Swift, the following code will load a collada .dae file into a scene:

let url = NSBundle.mainBundle().URLForResource("scene", withExtension: "dae")
var error: NSErrorPointer? = nil
let scene = SCNScene.sceneWithURL(url, options: nil, error: error!)

In Obj-C:

NSURL *url = [[NSBundle mainBundle] urlForResource:@"scene" withExtension:@"dae"];
NSError *error;
SCNScene *scene = [SCNScene sceneWithURL:url options:nil error:&error];

See http://adcdownload.apple.com//videos/wwdc_2012__sd/session_504__introducing_scene_kit.mov

(I figured out the conversion to Swift using XCode's dandy autocomplete.)

podperson
  • 2,284
  • 2
  • 24
  • 24
  • 2
    This doesn't load a DAE per se. In iOS SceneKit can only load DAE files that were added to the app's bundle resources in Xcode. When Xcode builds your app it converts the DAE into a compressed, device-optimized format. – rickster Jun 04 '14 at 01:37
  • It's quite possible that IF you import the file into your project it will be optimized, but since the API assumes URLs and not file paths, I believe it should work even if you're directly loading the relevant file from a server. – podperson Jun 04 '14 at 14:06
  • 1
    See [the docs](https://developer.apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SCNSceneSource_Class/index.html). Just Xcode-baked assets or NSKeyedArchiver-serialized SCN objects in iOS. Though I suppose you could use Xcode to bake a DAE and then put the resulting file on a server. – rickster Jun 04 '14 at 14:58