Loading collada file from webserver in scenekit - ios

I am working with SceneKit and Collada file. Now, I am able to load the collada file inside art.scnassets folder as well as in my project root directory. I am getting an error when i am trying to load the file from a local webserver. Any reason why I cannot do this?
let url = NSURL(string: "http://localhost:8888/new.dae")
let scn = try! SCNScene(URL: url!, options: nil)
2016-07-31 17:41:29.537 biOS[3863:254446] SceneKit IO: error, COLLADA files are not supported on this platform.
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=259 "The document "new.dae" could not be opened." UserInfo={NSURL=http://localhost:8888/new.dae, NSLocalizedDescription=The document "new.dae" could not be opened., NSLocalizedRecoverySuggestion=Collada is not supported by this version of SceneKit}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-703.0.18.8/src/swift/stdlib/public/core/ErrorType.swift, line 54
My goal is to read the collada file from a websever and then offer the user to download the file onto the device. I do not know why I am getting the error. By the way, I did a document preview to render the file, and it was successfully about to render document in xml. So, it is not a case of access to the file. Please help!

Any reason why I cannot do this?
Yes unfortunately.
During the build process XCode compiles your collada to .scn files. This is a scenekit specific binary file format, doing this reduces the size of the asset files (collada files are XML based) improving the load performance. SceneKit running on an iOS device does not load collada files, only .scn files.
You could look at using ModelIO to load resources that aren't part of your application, but I note collada isn't one of the supported formats.

You can also convert your dae files just like Xcode does using terminal.
Build a project with Xcode that has a dae and check the commands executed by Xcode (search for scntool)
Related: COLLADA transformations in SceneKit

I have found the AssetImportKit framework to solve this problem. The framework allows you to import Assimp supported file formats directly in SceneKit at runtime (macOS & iOS). The library supports:
Geometry Materials (with color, embedded textures and external textures)
Cameras and Skeletal animations
Serialization to .scn format

Related

How to export and share a .gltf file as .usdz file in iOS through code? [duplicate]

I am creating an app where users can scan objects in 3D, I have a scene which I can easily save in documents directory and share it in .scn format, but I want to share this .scn file as .usdz file via UIActivityController.
Basically I am using this library https://github.com/StandardCyborg/StandardCyborgCocoa
In this library, a scene file is saved as .gltf format, but I want to share this .gltf file which is not supported on iOS devices. Apple only support .usdz file format. So, I want to convert this .gltf file into .usdz file before sharing.
I have been searching different solutions over internet for a week, but nothing is working till now.
Can anyone help me to resolve this issue?
Any help is greatly appreciated.
It's not documented, but SCNScene's write method works with a .usdz URL, at least since iOS 14.7. This is what I'm using in my app.

How to export mp3 file with AVAssetWriter

I'm trying to export my asset as an .mp3 file using AVAssetWriter.
Here's how I create an instance of it:
writer = try! AVAssetWriter(url: outputURL,
fileType: AVFileType.mp3)
Unfortunately, it throws the error:
[AVAssetWriter initWithURL:fileType:error:] Invalid file type UTI.
Available file types are: com.scenarist.closed-caption, org.w3.webvtt,
public.aiff-audio, com.apple.m4v-video,
org.3gpp.adaptive-multi-rate-audio, com.apple.m4a-audio,
com.microsoft.waveform-audio, com.apple.coreaudio-format,
public.mpeg-4, com.apple.itunes-timed-text, com.apple.quicktime-movie,
public.aifc-audio
I'm running this code on macOS 10.15.
I find it hard to believe that there's no support for exporting an mp3 file. Can anyone guide me on how to make it work?
I find it hard to believe that there's no support for exporting an mp3 file
Overcome your difficulty and believe it. Due to a complex of copyright issues, Apple has no license to provide any native capacity to create MP3 files. You might find some third party library that can do it, but you won't do it with AVAssetWriter.

How do I specify a file type for importing .obj files?

I'm trying to get my app to recognize .obj files for importing.
I've tried to follow the instructions in this WWDC video.
I've tried specifying as both an Imported UTI, and an Exported UTI. Neither causes the file to be openable in UIDocumentBrowserViewController (the document icon is grayed). I don't understand how my native document format is openable in the browser either. I've tried deleting and reinstalling the app from the device.
What am I missing? Why isn't this simple?
Here's what I've got:
It turns out iOS already knows about .obj files. On macOS, I ran the following:
mdls myfile.obj
Which among other things shows:
kMDItemContentType = "public.geometry-definition-format"
kMDItemContentTypeTree = (
"public.content",
"public.geometry-definition-format",
"public.text",
"public.data",
"public.item",
"public.3d-content"
)
So the UTI is public.geometry-definition-format. I don't know if that already specifies the extension or is a more generic type.
The following worked to make the files openable in UIDocumentBrowserViewController:
The UTI isn't declared in the documentation (what a surprise!), so I'd recommend using mdls to look up UTIs.

Convert ( .obj / .fbx ) to .dae runtime which must support iOS SceneKit

I am facing trouble to find a way to convert .obj / .fbx to .dae (iOS scenefit Supported) automatically in background.
In python, it may be available to convert the file from .obj / .fbx to .dae file format. This process should run in background, immediately run after we will get .obj / .fbx file on server.
Here is the sample file, which we are trying to convert.
https://s3.ap-south-1.amazonaws.com/p9-platform/DAE/barware_s11624.obj
Please help me, if you have any suggestion.
Scenekit on IOS doesn’t support dae unless it was included in the app. So because of the “iOS Scenekit Supported” requirement there is no right answer, sort of. Although there are third party libraries (like https://github.com/dmsurti/AssimpKit ) to read and convert many 3d model formats, it won’t change the fact dae isn’t properly supported on IOS Scenekit .
That said, it is possible to convert OBJ to DAE in SceneKit using the following steps (in IOS 11.2 and later)
Load the obj file into a SCNScene.
Write the scene to a file with .dae extension using SCNScene’s writeToURL method.
That will create a .dae file SceneKit can support (but not directly, i.e. would need to be included in xcode or converted first) that starts with the following:
<?xml version="1.0" encoding="UTF-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
<asset>
<contributor>
<authoring_tool>SceneKit Collada Exporter v1.0</authoring_tool>
</contributor>
I would second the recommendation for using Assimp or AssimpKit (I’ve only used the former but the latter might be an easier starting point).
I believe the DAEs on iOS aren’t DAEs at all, they just left the suffix the same and the actual files are SceneKit archives. I’m not sure if the API to write them is exposed yet, but I think it might be now since Xcode is now willing to load DAEs and write out SceneKit archives (but it adds the “.scn” suffix, not “.dae”).
It’s possible that iOS SceneKit can just load “.scn” files — it won’t load true DAEs because the DEA-reading/writing framework was licensed from Sony and is HUGE and the iOS team just doesn’t want that giant ugly framework on its system.
Another option would be to just link the iOS app against Assimp — it can load a ton of formats natively so you could skip all the intermediate stuff. It’s not NEARLY as huge as Sony’s DAE library so it might be acceptable to ship it with your app.

Load uncompressed collada file using iOS Scene Kit

I need to load a collada file I downloaded on iOS, I intend to use Scene Kit to do it. But reading the documentation I found out that XCode compresses the collada files on compilation time, and Scene Kit can only load the compressed files.
After some research I ran into this article where the author was able to find the scripts XCode uses and compress the files using them. The problem is that I'm not being able to run them on my server.
So my question is: Is there any other way to load collada files using scene kit? Or is there somewhere where I can find an algorithm to do the compression myself?
if you can't upload compressed files on your server and cannot convert them on the fly on the server, I'm afraid that you will have to manually parse the Collada files and instantiate all the SceneKit objects yourself.

Resources