cancel
Showing results for 
Search instead for 
Did you mean: 

ONSPPropagationGeometry loading from file is broken on Quest.

DarkTable
Level 5

In the file ONSPPropagationGeometry the ReadFile method tries to read directly from Stream Assets, but on Android this has to be done using a UnityWebRequest. The code below is a workaround that reads the file out of streaming assets and saves it to persistent data. I just tried this on Quest and it seems to work.

 

Just need to replace these two methods:

void CreatePropagationGeometry()
{
// Create Geometry
if (ONSPPropagation.Interface.CreateAudioGeometry(out geometryHandle) != OSPSuccess)
{
throw new Exception("Unable to create geometry handle");
}

// Upload Mesh
if (!string.IsNullOrEmpty(filePath) && fileEnabled && Application.isPlaying)
{
ReadFile(success => {
if (!success)
{
Debug.LogError("Failed to read file, attempting to regenerate audio geometry");

// We should not try to upload data dynamically if data already exists
UploadGeometry();
}
});
}
else
{
UploadGeometry();
}
}

public void ReadFile(Action<bool> callback) {
string geoFilePath = filePath;

if (string.IsNullOrEmpty(geoFilePath))
{
Debug.LogError("Invalid mesh file path");
callback?.Invoke(false);
}

#if UNITY_ANDROID
if (geoFilePath.StartsWith("jar:")) {
// strip the apk prefix off the file uri.
var splithPath = geoFilePath.Split('!');
var dataPath = Path.Combine(Application.persistentDataPath, splithPath[1].Substring(1));

if (File.Exists(dataPath)) {
geoFilePath = dataPath;
}
else {
// read the file out of the apk and save it to persistent data.
var request = UnityWebRequest.Get(filePath).SendWebRequest();

request.completed += delegate(AsyncOperation operation) {
var asyncWebOp = operation as UnityWebRequestAsyncOperation;

if (asyncWebOp.webRequest.result == UnityWebRequest.Result.Success) {
var directory = Path.GetDirectoryName(dataPath);

Directory.CreateDirectory(directory);

File.WriteAllBytes(dataPath, asyncWebOp.webRequest.downloadHandler.data);

// now that the file's in place, try again.
ReadFile(callback);
}
else {
Debug.LogError($"couldn't retrieve geo file: \"{filePath}\"");
callback?.Invoke(false);
}
};

return;
}
}
#endif

if (ONSPPropagation.Interface.AudioGeometryReadMeshFile(geometryHandle, geoFilePath) != OSPSuccess)
{
Debug.LogError("Error reading mesh file " + geoFilePath);
callback?.Invoke(false);
}

callback?.Invoke(true);
}

 

1 REPLY 1

DarkTable
Level 5

Whoops, missed a "!" in above code.