Add remote USDZ file to local RealityKit .rcproject file and display in QLPreviewController - augmented-reality

I'm using AR Quick Look. I have a Reality Composer scene (.rcproject) in my project. I'd like to add a variety of entities to the .rcproject, define triggers and actions AND add a USDZ file from a file at run time.
I can load a remote USDZ file into a QLPreviewController and display it fine as the single QLPreviewItem. I have the URL, covert it to a local file then open it as a preview item.
There are lots of examples of adding entities to an ARView.
But I do not see how I can have a scene defined in Xcode (.rcproject), that I edited with Reality Composer, add a entity (e.g. USDZ file) at run time and display the revised reality file using QLPreviewController and QLPreviewItem.
I can Entity.load(contentsOf: url) to load the .rcproject scene, get the anchor and add a child, which is the USDZ file I got from a remote URL and converted to a local file, but then how do I save that back (the updated anchor or ???) to a .reality file and pass the temporary local file URL as a QLPreviewItem?
Or is there a way to add an entity (USDZ file) to a running QLPreviewController view at run time?
I'm trying to stay with QLPreviewController because I need users to be able to share this AR Quick Look view with other iPhone users so they can open the view in Safari on the iPhone without needing my app.

Related

Download .rcproject from remote and place it in AR view?

So, I'm following the documentation and created a composition with Reality Composer. There is a step in the docs called Add the Composition to Your App, what I would like is to add the Composition to my app dynamically. Upload the file to a server and download it from a URL.
In the tutorial, it says that when importing the .rcproject it generates a code
Xcode automatically generates code that you use to manipulate the stored objects. For example, Xcode generates a class for the scene based on the scene’s name (MyGreatScene) inside an enumeration based on the name of the project file (MyProject.rcproject). As a convenience, it also provides a loadMyGreatScene() method
Is there a way for me to generate this code downloading it from my url? Should I upload another file to be able to download it?

Web view UWP not loading files in the machine

can I open a html file on the C drive or on any location using the web view in UWP?
I am using the following code but it is not working:
Uri targeturi = new Uri("C:/Users/user/Pictures/Files/Forms/dac36cac-5d83-4fae-bf4f-112361b719ea/index.html");
browser.Navigate(targeturi);
In uwp files have limited access permission. By the default the app can only access the application install directory and data locations. Additional locations require special capabilities. More details about file access permission please reference this document.
You can gain access to files and folders on a removable device by calling the file picker (using FileOpenPicker and FolderPicker) and letting the user pick files and folders for your app to access. Learn how to use the file picker in Open files and folders with a picker.
According to your code snippet, you want to access the HTML file inside the picture folder. For accessing file in picture folder please reference Files and folders in the Music, Pictures, and Videos libraries. Pay attention on the Capabilities page, select the libraries that your app manages. So the correct way to open the file and show it in the WebView may as follows:
StorageFolder storageFolder = await KnownFolders.GetFolderForUserAsync(null /* current user */, KnownFolderId.PicturesLibrary);
StorageFile indexFile = await storageFolder.GetFileAsync("index.html");/*Change to your file path inside the picture folder*/
browser.NavigateToString(await FileIO.ReadTextAsync(indexFile));
You may find I used the NavigateToString method. The Navigate(Uri) method can not navigate to a file by path directly. To load uncompressed and unencrypted content from your app’s LocalFolder or TemporaryFolder data stores, use the Navigate method with a Uri that uses the `ms-appdata scheme, to HTML content in the app package using the ms-appx-web scheme. For example:
webView1.Navigate("ms-appx-web:///help/about.html");
More details please reference "Navigating to content" of WebView. And the scenario 5 of the official sample provide samples about navigating to file you can reference.

UIDocument + NSFileWrapper + iCloud = Strange Behaviour

I’m trying to write a fairly simple UIDocument based app and I want the data for each document to be a parent directory containing some image files.
To get started I chose to use Apple’s ShapeEdit sample as that seems to handle lots of the complexity of having files in iCloud. It does only use a single plist file for it’s document data though.
As a first step I got the ShapeEdit app up and running on my iPad and everything works as expected. I have the app and iCloud Drive app running in split view on my iPad so I can see the files ShapeEdit is creating. As expected each time I add a new document a new file appears in iCloud Drive.
To migrate the ShapeEdit app to use more files I moved over to using NSFileWrapper. When ShapeEdit creates a new document it copies a template file. I changed this to just create a new folder using
try fileManager.createDirectoryAtURL(writeIntent.URL, withIntermediateDirectories: false, attributes: nil)
I then modified the UIDocument code to have it read from a NSFileWrapper like this
override func loadFromContents(contents: AnyObject, ofType typeName: String?) throws {
guard let data = contents as? NSFileWrapper else {
fatalError("Cannot handle contents of type \(contents.dynamicType).")
}
fileWrapper = data
I also hobbled some of the other functions in the document to return a simple image for thumbnails, just to get it running and set LSTypeIsPackage to true. Finally I left the shape selection UI there to trigger a document update with
updateChangeCount(.Done)
Again this all works fine. Creating a new document creates a new Directory named Untitled.shapeFile and it shows up in iCloud. Now for odd thing number one. If I open that document and tap on the shape selection UI to trigger a change and wait a few seconds another Untitled.shapeFile directory shows in iCloud. In fact every time I do this I get another one. These seem to only be local to the iPad though as iCloud on my mac only has one copy. Deleting any of these directories within the iCloud Drive app causes all of them to be deleted.
For the next step I added little bit of code to the UIDocument loadFromContents() function
fileWrapper?.addRegularFileWithContents(UIImagePNGRepresentation(image!)!, preferredFilename: "MYImage.png")
so every time the document is loaded it adds another image file to the parent directory.
To begin with this does exactly as I hoped. Open the doc, tap the shape select UI see the MyImage.png file turn up in iCloud Drive inside Untitled.shapeFile. Keep closing and opening and I get more MyImage.png files with some junk on the front which, I assume, is iCloud’s way of preventing files with the same name so all is well there. Except for strange thing number two. Shortly after the MYImage.png file shows in iCloud Drive another one pops up called MyImage 2.png. If I keep closing and opening all the versions of MyImage also get a copy with a 2. My edited version of ShapeEdit never adds any image files with this name format. These extra images do show up on the mac as well so they aren't the same strange phantom copies as the main document directory.
So two things
1) Why do I get multiple copies of the Untitled.shapeFile doc which seem to actually be the same thing?
2) Why do I get extra copies of my image file with a 2 added that my app never had anything to do with?
Any suggestions welcome before this drives me crackers.

iOS - Download files to application folder

I do have a UIWebview inside one of my UIViewControllers. The destination URL to be displayed within the WebView is a page on my server (therefore I have access to make changes on it).
That page basically has a list of PDFs to be downloaded (imagine an un-ordered list of hyperlinks each pointing to a PDF file).
I need a way to tell my App that whenever a file is downloaded from that WebView by clicking on one of the links, I need it to be saved inside my application folder instead of the iPhone/iPad memory.
Is there any way I can achieve that? Are there alternatives?
You can allow UIWebView to call your Objective-C delegate function. This link provides an overview of how to do it: http://dblog.com.au/iphone-development/iphone-sdk-tip-firing-custom-events-when-a-link-is-clicked-in-a-uiwebview/ Basically, the delegate function will be called on all requests from the UIWebView. You can examine if they are for links to a pdf files, and if so, write your own objective-c code to download the file and store it in your Application directory. You'll probably want to add some UI to let the user know what is happening. Otherwise you let the request go on as normal and it will be displayed in the web browser.

SWF file extraction

If I have a link to a SWF file - for example here http://redletterdaysb2b.co.uk/swf/our-video.swf
how can I extract it for use on another website?
I have downloaded the swf, but just get an error#2044 when I try and play it. does it need to go in some sort of wrapper?
thanks guys
You're trying to load a swf that in turn loads and displays a .flv using the FLVPlayback component. I'm guessing our-video.swf loads fine, but it probably keeps a relative reference to the .flv.
I can think of two ways to handle this:
Simple add a new FLVPlayback (or any other video player) on the other site but tell it to load the .flv file from the original site.
Try to copy the .flv file in the same folder as the new .swf on the new site.
With the FLVPlayback component there's another part that could cause the error: the skin which on the original site is here.
The #2024 IOError should also include an URL.
This is your best hint to how the our-video.swf is trying to load the .swf file (using a relative(./swf/redletterdays.swf) or an absolute(/swf/redletterdays.swf) path).
Based on this, if you decide to load the player from the original site (not just the .flv file), you can work out where to place the skin (i.e. in the in a folder named swf on the root of the new site)

Resources