Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

ObjReader - load .obj files at runtime

Discussion in 'Assets and Asset Store' started by Eric5h5, May 7, 2013.

  1. appearition_unity

    appearition_unity

    Joined:
    Jun 1, 2015
    Posts:
    4
    Thanks for the help after changing to png in material and the texture file it works great.
     
  2. raj231

    raj231

    Joined:
    Nov 18, 2014
    Posts:
    46
    Is there anyway to validate the URL? Because i've backend webpage for anyuser can enter their 3D url in the field and it reflect into JSON then i'm loading the URL into app but if some peoples are wrongly giving some unwanted URL than model URL. So, is there a way to validate the URL while entering?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Possibly, but that's unrelated to ObjReader, so I'd suggest starting a separate topic about it.

    --Eric
     
  4. raj231

    raj231

    Joined:
    Nov 18, 2014
    Posts:
    46
    Does ObjReader allows cache? We've 5 buttons for load different models from server URL. If i click 1st button it loads the model and again click the 1st button then again it loading the model. So, is there a way to load the model from cache if it already loaded?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    ObjReader doesn't cache anything on its own, no.

    --Eric
     
  6. raj231

    raj231

    Joined:
    Nov 18, 2014
    Posts:
    46
    Oh. So, does user need to wait each time model loads? Does it makes sense?
     
    Last edited: Jun 22, 2015
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you want to program some kind of caching, that's up to you. It's not something that's in scope for ObjReader itself.

    --Eric
     
  8. CharlieBrown

    CharlieBrown

    Joined:
    May 11, 2015
    Posts:
    10
    Hi! I have bought this component, and it works really good. But I have a small problem . The component is loading the object as a mirror of what I have exported in the other program. I have analyzed the problem and it seems that my world base in the program where I export the model is different to unity( Z is -Y, Y is Z and X is X). THere is any way to change something in the component to have the same behavior? I would like to adapt it in Unity ( in the other software its nof possible). Thanks!

    Diego
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, generally there's a setting for stuff like that when exporting files. If you're sure there isn't, I'd recommend importing it into Blender (which is free), and then exporting from there, since Blender has the option of changing forward and up axes when exporting.

    --Eric
     
    CharlieBrown likes this.
  10. CharlieBrown

    CharlieBrown

    Joined:
    May 11, 2015
    Posts:
    10
    Not possible, I need to contact the other software developers to make available in their API or change the world base... Thanks anyway
     
  11. CharlieBrown

    CharlieBrown

    Joined:
    May 11, 2015
    Posts:
    10

    I have found this:

    private bool usesRightHanded = true;

    :D
     
  12. SuHwanK

    SuHwanK

    Joined:
    Dec 30, 2014
    Posts:
    43
    Hi Eric5h5 !
    I set Group my objects(4~5 obj models) and attached export.cs(Open Source of C#)
    so, Exported complete. but Import is not work.
    can u test my exported group model?
    i try test but i don't know reason.

    upload obj file, and mtl file.

    thank you.
     

    Attached Files:

    • T01.zip
      File size:
      797 KB
      Views:
      400
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Seems to work fine. What problem do you have?

    --Eric
     
  14. SuHwanK

    SuHwanK

    Joined:
    Dec 30, 2014
    Posts:
    43
    Hello Eric.
    I don't speak english very well.
    so i take two screenshot about my problem.

    first shot is load my model by default options set ObjReader.
    normal.png
    It's work find.

    but i have to not used "Combine Multiple Groups" option.

    I must control the child objects of load model by ObjReader.

    so second shot is unchecked that.
    NotCombineMultiGroup.png

    How can i fix it?
    Thank you.
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm still not seeing any problems like that, sorry. I always get 6 trees whether I use "Combine Multiple Groups" or not. Maybe you have some code that's removing duplicate objects, since there should be 6 "Object_1" objects, 6 "Object_2" objects, etc.

    --Eric
     
    SuHwanK likes this.
  16. SuHwanK

    SuHwanK

    Joined:
    Dec 30, 2014
    Posts:
    43
    If you try testing my model by 2 way(option check, uncheck), and then.. no see any problems.
    i guess too, removing objects in my code.
    thank you and so sorry.
    i must do find that, my self.
    have a nice day. Eric.
     
  17. Glynn-Taylor

    Glynn-Taylor

    Joined:
    May 14, 2013
    Posts:
    12
    Out of curiosity why is >65534 vertices in a single group not supported out of the box? I managed to modify ObjReader to do this but it was quite a pain as I mistakenly expected this to be already implemented in such a complete product.

    Now that that's sorted it works wonderfully, thanks.
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unity doesn't support more than 65K verts in a single mesh.

    --Eric
     
  19. Glynn-Taylor

    Glynn-Taylor

    Joined:
    May 14, 2013
    Posts:
    12
    You can autosplit it by iterating over the faces and keeping track of vertices used until the count reaches >65k, then instantiating the mesh up to that point and resetting the lists to continue with the iteration. I think this is also how the unity importer does it as the meshes generated are the same, but they might have a more performant/clever way of doing it.
     
  20. dlucredio

    dlucredio

    Joined:
    Aug 4, 2015
    Posts:
    1
    Hi Eric, congratulations on the plugin. It is really useful indeed. In fact, it is the only one that seems to work out of the box.

    However, I am using an architectural model exported from sketchup, and there seems to be a problem, and I guess I must be doing something wrong. When I import the .obj/mtl files via unity editor (dragging/dropping into unity editor), the model is loaded correctly. However, when I try to import the same files at runtime via your plugin, some faces appear inverted/transparent. I tried opening the original file and inverting the faces, but the problem remains. I am including two screenshots to show you the results. I am guessing it is some incompatibility with the scripts, and not a problem with the model, because I can import the same model into blender and it shows up OK. I also attached the console output, showing some warnings.

    importedViaUnity.png importedViaObjReader.png runtimeWarnings.png
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    ObjReader doesn't support n-gons, so those would have to be converted to quads or triangles.

    --Eric
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could probably add a plane underneath with a shadow texture, or something along those lines, but since this isn't really related to ObjReader, I'd recommend starting a separate topic about it if you need more help.

    --Eric
     
  23. S_P_S

    S_P_S

    Joined:
    Feb 25, 2015
    Posts:
    91
    A function for splitting large meshes would be really cool. The 64k verts limitation is a bit annoying.

    regards
     
  24. raj231

    raj231

    Joined:
    Nov 18, 2014
    Posts:
    46
    When we create the 3D model using Maya then the texture is not appearing. Please find the attached file for the model which developed by Maya software. But we've tried with model which created by 3DS Max then that worked but created with Maya the models are not working. Below is the code,

    //------------------------------------------
    IEnumerator Load ()
    {

    if (objData != null && objData.gameObjects != null)
    {
    for (var i = 0; i < objData.gameObjects.Length; i++)
    {
    Destroy (objData.gameObjects);
    }
    }

    objData = ObjReader.use.ConvertFileAsync (url, true, standardMaterial,transparentMaterial);

    while (!objData.isDone)
    {
    if(Input.GetKeyDown(KeyCode.Escape))
    {
    objData.Cancel();
    yield break;
    }

    Loading_Text.text = "Loading " + (objData.progress*100).ToString("f0") + "%";
    yield return null;
    }

    if (objData == null || objData.gameObjects == null)
    {
    yield return null;
    yield break;
    }

    FocusOnObjects();
    }




    public void FocusOnObjects ()
    {

    objData.gameObjects[0].transform.parent = Model_Parent;
    objData.gameObjects[0].transform.localPosition = Vector3.zero;
    objData.gameObjects[0].transform.localEulerAngles = Vector3.zero;
    objData.gameObjects[0].transform.localScale = new Vector3(60,60,60);

    GH.Parent_Model.transform.localEulerAngles = new Vector3(0,180,0);
    GH.Parent_Model.transform.localPosition = Default_Pos;

    GH.Model_3D = objData.gameObjects[0];
    string modelName=GH.Model_3D.name;

    string modelName1 = objData.gameObjects [0].name;
    model = GameObject.Find (modelName); // find the model reference

    model.name = GH.Model_3D.name;

    }
     

    Attached Files:

  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The MTL file doesn't specify any texture:

    Code (csharp):
    1. newmtl lambert3SG
    2. illum 4
    3. Kd 0.50 0.50 0.50
    4. Ka 0.00 0.00 0.00
    5. Tf 1.00 1.00 1.00
    6. Ni 1.00
    ObjReader has no way to know about textures if they aren't specified, so the only option is to correct the MTL file. (Please use code tags when posting code in the future.)

    --Eric
     
  26. Cagkan Toptas

    Cagkan Toptas

    Joined:
    Apr 10, 2015
    Posts:
    1
    Hi Eric, I am thinking to buy the component however I need to know which image formats for textures are supported in the library. Could you list them?
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    PNG and JPG, since that's what Unity supports.

    --Eric
     
  28. raj231

    raj231

    Joined:
    Nov 18, 2014
    Posts:
    46
    Why i'm getting like this below error,

    Error loading https://server.com//3D/Lounges/LoungeChair3/-s 0.333333 0.333333 _original.jpg: 404 Not Found
    UnityEngine.Debug:LogError(Object)
    <GetTexturesAsync>c__Iterator1:MoveNext()

    But i have this name in the .mtl file.
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If the error is 404, that means it doesn't exist at that location, simple as that. You'd have to fix the address.

    --Eric
     
  30. dmitriy99

    dmitriy99

    Joined:
    Jun 30, 2015
    Posts:
    3
    Hi , could you please help me. When i am loading an object with mtl file, it creates the object in unity but it uses only the color from mtl file, all the other parameters such as specular and shining are always the same and default when loaded. It is always Legacy/Diffuse shader . Or VErtexLit/Transparent if Tf property in the mtl is lower than 1. What i need is to be able to get the same material on the object when loaded as the material described by mtl file.There will be an application where the goal is that the 3d modeller guy could make a obj model and upload it to a server, then it could be loaded dynamically without Unity developer get involved. I am sure i am missing something as i am new to Unity. Can you please describe me a strategy for achieving this.I am using Unity 5.1. Thank you very much and sorry for my English.
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    ObjReader doesn't create any materials; it uses whatever material you pass in. In the MTL file, "ka" lines use the "_Emission" property in the shader, "kd" uses the "_Color" property, "ks" uses the "_SpecColor" property, and "ns" uses "_Shininess". So if the shader you're using lacks any of those properties, they won't be used.

    --Eric
     
  32. dmitriy99

    dmitriy99

    Joined:
    Jun 30, 2015
    Posts:
    3
    But how do i specify objReader should use one or another shader. I mean it just allways uses Legacy/Diffuse.
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You pass in a material when calling a ConvertFile function; see the docs.

    --Eric
     
  34. dmitriy99

    dmitriy99

    Joined:
    Jun 30, 2015
    Posts:
    3
    In that way the material is chosen before file is loaded. What i need is that the material will be set according to mtl file properties or it's name.I thought maybe there is such functionality that i am missing. However this could be more logic to implement separately. Anyway the tool is great and 100% worth it, thank you.
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, you pass in the material, and then the shader parameters are set when the file is loaded. Just make sure you use a material that has a shader with all of the properties I mentioned.

    --Eric
     
  36. S_P_S

    S_P_S

    Joined:
    Feb 25, 2015
    Posts:
    91
    If you import a .obj file that has several objects, all objects will be added to the hierarchy.

    But what if I want to add all objects to the hierarchy as child objects to a parent gameobject.
    What's the most efficient way to do this?

    regards
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use SetParent with the generated GameObjects.

    --Eric
     
  38. S_P_S

    S_P_S

    Joined:
    Feb 25, 2015
    Posts:
    91
    Thanks Eric,

    but where I get the gameObject reference of each generated GameObject from?

    I think the most effiecient way would be, to use SetParent as soon as the specific gameObject is generated in scene. But I can't find the line of code which says "gameObject generated".

    For sure I could loop through all importedObjects, after the whole import process is completed, and use SetParent for each Object until no importedObject is left.

    But this way is complete inefficient.

    best regards
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The ConvertFile functions return GameObject arrays. (Aside from ConvertFileAsync, which returns ObjData, which has a gameObjects property, which is a GameObject array.)

    --Eric
     
  40. RyanAchtenSoma

    RyanAchtenSoma

    Joined:
    Mar 21, 2015
    Posts:
    2
    Hi Eric

    Firstly thank you very much for producing this awesome asset, I have been using the ObjImporter script which works fine but is much too slow for my purposes.

    I have ObjReader working fine with the test objects you have provided as well as some other test objs (such as Blender’s Monkey model).
    However I seem to encounter issues when trying to import models created through photogrammetric processes (and therefore not optimised for Unity runtime).
    They have worked without problems using the previous ObjImporter parsing setup / Unity Editor Import and are each under the 65K vert limit, so I am hoping you might be able to shed light onto the cause of this issue?

    The error reports as “Incorrect number of points while trying to read vertices:
    v -0.479659 0.740015 -0.536782 0.749020 0.749020 0.749020”.


    Is there any preliminary optimisation setup required for ObjReader to parse objs properly?

    Many thanks in advance,
    Ryan
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vertices can only have xyz coordinates; I don't know what the additional 3 numbers are supposed to represent. The .obj specs don't allow for that. At most you can have xyzw, where the w would be used for things like curves (which wouldn't be imported by ObjReader anyway). I assume the other .obj importer was ignoring the extra numbers, however it does indicate an incorrect file so I'd be concerned about doing that.

    --Eric
     
  42. RyanAchtenSoma

    RyanAchtenSoma

    Joined:
    Mar 21, 2015
    Posts:
    2
    Thanks for your reply Eric,

    Ahh that’s very strange, but that was exactly the issue. The originals were compressed using MeshLab and must have exported with the strange vertices. Upon importing and exporting out of a different 3D package (C4D in my case) the import runs fine.

    Thank you so much!
    Ryan
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I wouldn't recommend that, since the .obj format has no animation.

    --Eric
     
  44. davegirdy1

    davegirdy1

    Joined:
    Jun 13, 2015
    Posts:
    6
    I got the Example2_WWW sample project working great with Web Player. I have Unity 5 so I tried using it with the WebGL output. I get an error when trying to import the http://www.starscenesoftware.com/objtest/Spot.obj sample. Could this be due to WebGL wanting "CORS" on the server? http://docs.unity3d.com/Manual/webgl-networking.html

    Thanks,
    Dave
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Works fine here (Unity 5.2.2 WebGL build).

    --Eric
     
  46. raj231

    raj231

    Joined:
    Nov 18, 2014
    Posts:
    46
    When ObjReader going to support cache stuff. As of now i've button to load the 3d model from server url. Here i user need to press each time and each time it's downloading from server. So, user getting frustrate and some times they're waiting until it loads everytime. It's not user friendly.
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's something you would implement yourself, since it's not related to ObjReader.

    --Eric
     
  48. raj231

    raj231

    Joined:
    Nov 18, 2014
    Posts:
    46
    I'm not sure why it's not relate to Obj Reader. For example, we have the obj file in www.testserver.com/test/chair.obj. In scene i've button called "Click". When click this button obj reader load the model from url but each time click, each time it download the model from URL and it taking time. Is there a method to implement like AssetBundle cache system
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Caching data isn't related to importing .obj files. If that's something you want, you'd need to implement it yourself, especially since that behavior isn't likely to be expected. e.g., if it's cached, then revisions wouldn't be re-downloaded, unless you take that into account, the details of which would vary depending on how exactly you want to handle it. It's far out of scope for what ObjReader is supposed to do. But you have the source code, so if you want to make customizations for your own specific usage, you're certainly welcome to do that.

    --Eric
     
  50. wita

    wita

    Joined:
    Jan 21, 2016
    Posts:
    1
    Hi Eric,
    first of all; great job with the asset and the afford at this thread. Coming from the Architecture field, unfortunally i am not that experienced with unity and especially with java (c++), but i am on it and came already far with my App-Project. Your asset helped me also a lot, but i need the last step to finish my project and i hope you can help me to solve the problem. It was mentioned in the thread before, but i still don´t get it and do struggle with this topic. So my question is: what should i do to add all the new generated/ imported meshes and objects directly as a child to an object in the hierarchy? Is it possible that the imported object moves directly to the "ObjectManager" as a child in the runtime, so i can put the ObjectManager to a parent Object in the editor? So i have to add SetParent into the Example2-WWW script or where to? I hope you, or maybe someone else, can help me with the definition, or at least point me in the right direction.