1
\$\begingroup\$

I want to import .obj file from a server on run time in unity3D, read lot of questions/answers but not able to find a suitable solution. Using WWW in unity I am able to get .png file and store it in local repository but this thing not works for .obj file. Following is the code I used to get image from server

public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
    IEnumerator Start() {
        WWW www = new WWW(url);

        while (!www.isDone)
            yield return www;

        if (www.isDone)
            Debug.LogError ("Done");

        File.WriteAllBytes("C:\\Users\\Admin\\Downloads\\conan\\test1.jpg", www.bytes);
    }

ans similarly I tried to get .obj file but it not works test .obj file created but without any data

public string url = "https://drive.google.com/open?id=0B5_UUyYa_2XdZUpuNlE4Z3pqWUk";
    IEnumerator Start() {
        WWW www = new WWW(url);

        while (!www.isDone)
            yield return www;

        if (www.isDone)
            Debug.LogError ("Done");

        File.WriteAllBytes("C:\\Users\\Admin\\Downloads\\conan\\test.obj", www.bytes);
    }

Kindly give me help in this regard.

\$\endgroup\$
  • 1
    \$\begingroup\$ You're trying to access a drive.google.com link, which doesn't include the file itself but a page that gets loaded and a download button that probably works with javascript to never let you actually see the direct access link of the file. Try accessing the file from an address that actually includes the file. (www.example.com/objfilethatyouhosted.obj or C:\objfile.obj) \$\endgroup\$ – John Hamilton Mar 17 '17 at 9:21
  • 1
    \$\begingroup\$ If you don't have access to a hosted server, you can test it on your own machine by setting up a local server. You can use tools like WampServer. \$\endgroup\$ – Vaillancourt Mar 20 '17 at 18:01
1
\$\begingroup\$

I agree with the drive link comment. Google Drive does not allow for direct file access. Maybe try uploading your obj file to a server and then d9wnload it using www in unity. Should work.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.