无法在 Hololens 中读取文件 [英] Unable to read file in Hololens

查看:61
本文介绍了无法在 Hololens 中读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要在运行时读取 hololens 中的 .obj 格式文件的应用.

I am working on an app which needs to read .obj format files in the hololens at runtime.

确切地说,我想要做的是将 .obj 文件保存在 hololens 中,当应用程序运行时,它应该通过 hololens 文件系统访问该文件.将文件放入资产文件夹并通过 Unity 编辑器加载不是我想要的.

Precisely, What I want to do is to save the .obj file in the hololens, when the app runs, it should access the file through the hololens file system. Putting the file in asset folder and loading by Unity editor is not what I want.

我搜索了几个论坛和主题线程,很多都给出了非常相似的解决方案.我遵循一些示例代码并编写自己的代码来读取 hololens 中的文件.但是,它不起作用.

I have searched several forums and topic threads, many give quite similar solutions. I follow some sample codes and write my own codes to read files in hololens. However, it doesn't work.

我的程序相关部分如下:

The relevant parts of my program are as follows:

在脚本文件的头部,导入命名空间

At the head of script file, import namespace

    #if WINDOWS_UWP
    using Windows.Storage;
    using Windows.Storage.Pickers;
    using System.Threading.Tasks;
    #endif

加载 obj 文件的脚本接收 Stream 类型参数.所以我实现了这个函数OpenFileForRead",它接收一个文件夹路径和一个文件名作为参数,返回文件流.

The script which load obj file receives Stream type parameter. So I implement this function "OpenFileForRead", which receives a folder path and a file name as parameter, returns file stream.

    private static Stream OpenFileForRead(string folderName, string fileName)
    {
        Stream stream = null;
#if WINDOWS_UWP
        Task task = new Task(
        async () => {
            StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(folderName);
            StorageFile file = await folder.GetFileAsync(fileName);
            stream = await file.OpenStreamForReadAsync();
        });
        task.Start();
        task.Wait();
#endif
        return stream;
    }

我这样调用这个函数:

#if WINDOWS_UWP
        string objname = "Model.obj";
        Stream stream = OpenFileForRead(ApplicationData.Current.RoamingFolder.Path, objname);
        loadedObj = new OBJLoader().Load(stream);
#endif

ApplicationData.Current.RoamingFolder.Path"映射到全息镜头中的LocalAppData\SOMEAPP\RoamingState".

"ApplicationData.Current.RoamingFolder.Path" is mapped to "LocalAppData\SOMEAPP\RoamingState" in the hololens.

因此,当我在 hololens 中部署此应用程序时,我会将设备门户中的Model.obj"文件上传到此应用程序的 RoamingState 文件夹.然后我运行这个应用程序,在理想情况下,它应该可以工作,不幸的是它没有.

So when I deployed this app in hololens, I will upload the "Model.obj" file in device portal, to this app's RoamingState folder. Then I run this app, under ideal circumstance, it should work, unfortunately it doesn't.

目前的情况是,app可以成功部署到hololens上运行.其他游戏对象在 hololens 中可以正常运行,但无法将 .obj 文件加载到场景中.

The current situation is, the app can be successfully deployed to hololens and run. Other Gameobjects can function normally in hololens, though it fails to load the .obj file into scene.

顺便说一下,new OBJLoader().Load(stream);"已经在Unity Editor中测试过,可以成功读取和加载我电脑本地文件夹中的.obj文件.因此,问题很可能在于我在 hololens 中读取文件的方式.但我肯定会遵循其他类似主题给出的解决方案.我很困惑,不知道到底出了什么问题?

By the way, " new OBJLoader().Load(stream); " has been tested in Unity Editor, which can successfully read and load .obj file in local folder on my PC. So it is most likely that the problem lies in the way I read files in hololens. But I surely follows the solutions given by other similar topics. I am confused and have no idea what exactly is going wrong?

以下是我参考的一些网站并从中复制了一些代码:

Here are some websites I have referenced and copied some codes from:

https://longqian.me/2017/02/08/hololens-文件传输/

https:///forums.hololens.com/discussion/1862/how-to-deploy-and-read-data-file-with-app

https://github.com/Maximilian-Winter/ObjHololensViewer

https://github.com/jmher019/Hololens-OBJRenderer

几乎所有上述代码都使用类似的代码来读取 hololens 中的文件,虽然我无法在我的设备上读取它,但它非常令人沮丧!

Nearly all above use similar codes to read files in hololens, though I can't get it through on my device, it is so frustrating!

Untiy 编辑器:2018.4.0f1

Untiy Editor: 2018.4.0f1

Hololens:第一代

Hololens: 1st gen

推荐答案

我之前在 Hololens (v1) 和 Unity 读取数据时遇到了很多问题.我花了很长时间才找出原因...尤其是当我发现这是 Unity 中的一个错误时.我查看了我以前的论坛帖子,您的 Unity 版本仍然存在此问题.

I have had quite some issues before with the Hololens (v1) and Unity, reading data. It took me ages to figure out the cause... especially when I discovered that it was a bug in Unity. I checked my old forum posts, and you have a Unity version that still suffers from this.

参见:https://forum.unity.com/threads/how-to-access-files-folders-on-hololens-with-il2cpp.543022/

请注意来自 Unity 的人(几乎是最后一个帖子)说:

Please note that the person from Unity (almost last post) says:

是的,我愿意.修复已发布到 2019.1.8f12018.4.3f1.它尚未 > 登陆到 2019.2 或 2019.3.

Yeah, I do. The fix landed to 2019.1.8f1 and 2018.4.3f1. It hasn't > landed to 2019.2 or 2019.3 yet.

只是有点落后.我会正确备份您的项目,然后尝试安装新的 Unity.我记得在升级使所有 Visual Studio 工具再次正常工作后我也遇到了问题(与 Win10 SDK 版本有关?).

You are just a little bit behind that. I would backup your project properly, and try installing a new Unity. I remember I also suffered from issues after upgrading getting all the Visual Studio tools properly working again (something related to Win10 SDK versions?).

最后,我不得不更改 XML 清单文件中的权限,因为 Unity 没有添加正确的权限,即使在应用设置中更改它也是如此.不幸的是,我不记得具体是什么,由于在家工作,现在无法完成这个项目.

Finally, I had to change the permissions in a XML manifest file as Unity did not add the proper permissions, even when changing it in the app settings. Unfortunately I cannot remember what exactly, and cannot reach this project right now due to working from home.

我在 2019.1 发行说明中找到了对修复的引用.我在 2018.x one 中找不到它:

I have found the reference to the fix in the 2019.1 release notes. I could not find it in the 2018.x one:

https://unity3d.com/unity/whats-new/2019.1.8:

通用 Windows 平台:修复了 System.IO API 无法处理 IL2CPP 脚本后端上的应用程序和 AppData 目录之外的文件的问题.(1063768, 1156200)

Universal Windows Platform: Fixed System.IO APIs not working on files outside of application and AppData directories on IL2CPP scripting backend. (1063768, 1156200)

以及实际的 issuetracker 问题:

And the actual issuetracker issue:

https://issuetracker.unity3d.com/issues/uwp-il2cpp-file-dot-exists-method-returns-false

我认为这也可能是您的问题.

I think this is likely your issue too.

这篇关于无法在 Hololens 中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆