hl2ss icon indicating copy to clipboard operation
hl2ss copied to clipboard

How load obj file during running Unity App

Open vincenzocivale opened this issue 2 years ago • 3 comments

Hi, I'm trying to load a obj file, saved in a server, while the app unity is running on the hololens. I've created a new command to send the url of the file and download it with the same method of OBJLoader project. But It seems to not work. Someone has an idea?

My code:

public uint MSG_LoadOBJFile(byte[] data) { //string url = Encoding.UTF8.GetString(data); // Create a UnityWebRequest to download the OBJ file UnityWebRequest request = UnityWebRequest.Get(url);

    // Send the request and wait for it to complete
    request.SendWebRequest();
    while (!request.isDone)
    {
        System.Threading.Thread.Sleep(1);
    }

    // Check for errors during the download
    if (request.result != UnityWebRequest.Result.Success)
    {
        Debug.LogError("Failed to download OBJ file. Error: " + request.error);

    }

    // Get the downloaded data as bytes
    byte[] downloadedData = request.downloadHandler.data;

    // Create a stream and load the OBJ file
    var textStream = new MemoryStream(downloadedData);
    var loadedObj = new OBJLoader().Load(textStream);

    // Add the loaded object to your game
    uint id = AddGameObject(loadedObj);
    return id;
} 

vincenzocivale avatar Sep 12 '23 10:09 vincenzocivale

Hello, Does the python code receive the id of the object (from ipc_umq.pull)?

jdibenes avatar Sep 13 '23 23:09 jdibenes

Yes, this Is the idea.

vincenzocivale avatar Sep 14 '23 06:09 vincenzocivale

Hello,Does the current code work? I also want to know how to load obj file, can you share your experience?

bxcharlie avatar Oct 31 '23 03:10 bxcharlie