Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

[FREE] Runtime OBJ Loader

Discussion in 'Assets and Asset Store' started by aaro4130, Nov 4, 2015.

  1. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,563
    Good stuff guys!
     
  2. aaro4130

    aaro4130

    Joined:
    Jul 15, 2010
    Posts:
    395
    Another update pushed, now supporting BumpScale , and also skipping over other texture args

    e.g.
    map_Kd -s 1 1 1 -o 0 0 0 -mm 0 1 chrome.mpc
    should no longer think "-s 1 1 1 -o 0 0 0 -mm 0 1 chrome.mpc" is the texture name
     
  3. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    140
    I've got a couple of questions:

    - The first post says that you have to add a specular shader to make it work. Can you use your own shaders for the imported objects too?
    - Is there already anything in place to import objects asynchrously (a coroutine or a thread)?

    - I know this says "2018.3.1 or higher" but has anyone tried running it with Unity 2017 yet (and succeeded?)?
    - Has anyone compared the speed of the new version to other importers yet?
     
  4. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,563
    Yes, you can change the shader in the code.

    Not sure.

    Should work fine in 2017, any version I suppose.

    Yes, it works great. Fast and light.
     
  5. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    140
    Nice, thanks.
    Does anyone know?
    I'm currently using a different asset (without any support for coroutines or threads) but I'm usually importing 20+ small .obj files, which often makes my game freeze for a split second.
    Unfortunately I can't download it through the asset store (it says that I have to upgrade) and the upload linked in post #93 is offline.
    May I ask what importers you've tested it against?
     
  6. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,563
    Most of the ones on the asset store. The author of this one is a friend of mine personally, so I know the code is well-structured (I'm using it in my own modifiable racing game) and quick (he's very keen on micro-optimizations). I load models with it over 50,000 tris in almost no time.
     
  7. Jake_Bellamy

    Jake_Bellamy

    Joined:
    Aug 21, 2018
    Posts:
    2
    Hey, just recently found this amazing asset (thanks for releasing it for free btw) and I'm having trouble loading an obj with its mtl file streaming from a server. Is there an example of this anywhere or can someone provide an example so I can see what I may be doing wrong? I can get it load and it Does put materials on it, it just doesn't color it correctly. As a test, I'm trying to load in a yellow Lamborghini but when it loads in its just black and grey. So..yeah, any help is greatly appreciated!

    Edit: So, with more fiddling I figured out it ended up being the mtl file associated with the obj I was testing with. This is all still fairly new to me and I was having issues with it reading transparent materials properly (by adjusting the mtl settings for the specific material it was supposed to be creating) and I ended up finding another option. Had to pay for it though, but, whatever works.
     
    Last edited: Mar 21, 2019
  8. FireGreeks

    FireGreeks

    Joined:
    Jan 14, 2017
    Posts:
    4
    Hello @aar4010
    I get an error while using your asset (I am surely missing something)...
    OBJLoader
    namespace couldn't be found... Am I missing a reference?

    Thank you in Advance

    Sincerely
     
  9. aaro4130

    aaro4130

    Joined:
    Jul 15, 2010
    Posts:
    395
    Are these errors happening in the sample scenes, or when trying from custom scripts?
     
  10. Sicerath

    Sicerath

    Joined:
    Feb 2, 2019
    Posts:
    5
    Would anyone be able to find some guidance as to how I can download the associated .mtl and .jpg files from a server? Aaro had mentioned passing in a stream for the MTL and overriding the texture loader, but to be honest I'm not sure how to go about accomplishing this. C# and Unity are pretty new to me, so I'm floundering a bit.

    I'm working on this project for my capstone class at University, so any help is greatly appreciated ASAP.
     
    Last edited: Mar 15, 2019
  11. aaro4130

    aaro4130

    Joined:
    Jul 15, 2010
    Posts:
    395
    I'm aware there's an error when building for IOS btw. When I get a decent amount of free time I'll deal with the asset upload process again and fix it. If you know code, you'll be able to fix it in the meantime.

    Sorry for the lack of responsiveness in private messages btw, working all the time D:
     
  12. Sicerath

    Sicerath

    Joined:
    Feb 2, 2019
    Posts:
    5
    No problem! I've got almost everything working at this point. My only issue is that calling OBJLoader.Load(objStream, mtlStream) completely freezes the app. Is there any way at all to get around this? I've tried using Ninja Multithread coroutines, but that won't work because there are some unity functions being called in there (so multithreading isn't an option). I timed it and the Load function freezes the app for about 5 seconds, which is a lot haha.

    Any tips @aaro4130?
     
    Last edited: Mar 27, 2019
  13. AnandSG

    AnandSG

    Joined:
    Oct 5, 2018
    Posts:
    8
    where i can find this loader ? is this work with UWP ? what is the limit for the size of the 3 d model file ( i want to load 200mb file)
     
  14. Xulain

    Xulain

    Joined:
    Oct 14, 2017
    Posts:
    20
    Exception: An error occured while loading DirectDraw Surface: Cannot load DDS due to an unsupported pixel format. Needs to be DXT1 or DXT5.

    the thing is these dds textures import into unity fine manually. So how do I make obj the importer ignore the textures?.


    Edit: NVM Unity can import obj files without this asset duh :) .
     
    Last edited: Mar 31, 2019
  15. prabhusam

    prabhusam

    Joined:
    Aug 3, 2017
    Posts:
    6
    I have loaded the 3D object via stream in .obj and .mtl formats successfully. I don’t know how to handle and apply the texture files. Kindly provide me with the possible solutions.

    Screen Shot 2019-04-05 at 5.02.05 PM.png
     
  16. Sicerath

    Sicerath

    Joined:
    Feb 2, 2019
    Posts:
    5
    You have to download the image files separately and then save them! That was my big mistake. I would look into using WebClient to download the images as I found it was a lot faster.
     
  17. Sicerath

    Sicerath

    Joined:
    Feb 2, 2019
    Posts:
    5
    Has anyone had any luck putting the OBJLoader.load() function into a background thread? It's freezing and even crashing my app at some points. Getting a bit frustrating.

    [Edit] It's looking like a really bad memory leak in ImageLoader... Memory usage spikes to almost 900mb within that class.
     
    Last edited: Apr 12, 2019
    smartinetz likes this.
  18. prabhusam

    prabhusam

    Joined:
    Aug 3, 2017
    Posts:
    6
    Hi Sicerath,
    Thank you for reply. Its really helpful to me.
     
  19. AnandSG

    AnandSG

    Joined:
    Oct 5, 2018
    Posts:
    8
    Do you found any solution? facing same problem here, its just stuck the scene for so long.
     
    smartinetz likes this.
  20. Prakash1206

    Prakash1206

    Joined:
    Jun 21, 2019
    Posts:
    2
    Issue with loading model on webgl
    if i run the code directly in unity, it works well - tried on unity 2017(old version of obj package) and unity 2019 (latest version of obj package)

    Code (CSharp):
    1. GameObject model = new OBJLoader.Load("I_Normal.obj");
    but if i build to webgl, build succeeds but model doesn't load on browser.
    on browser console i see message "FileNotFoundException" (for detailed log i have attached image)
    [tried with full file path with double back slash and single forward slash. nothing worked]

    what i noticed is that it always appends a forward slash to file path before loading model.
    in C# even if i specify full path as file:///D:/modelName.obj in browser console i see
    How to fix this?
    Thanks & Regards
     

    Attached Files:

  21. fxmdeveloper

    fxmdeveloper

    Joined:
    Aug 13, 2018
    Posts:
    1
    Hi, is this asset work for hololens? I cannot seem to get it working with Hololens. It does momentary stuck (if using big obj) but the model not loaded at all.

    This is the last debug I get before the object not loaded (I don't know if this is the right debug, I don't really know how to debug at hololens)

    Code (CSharp):
    1. Exception thrown at 0x77222DC2 in DTSA Template Hololens.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x0252F49C.
    2. Exception thrown at 0x77222DC2 in DTSA Template Hololens.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x0252F514.
    3. Exception thrown at 0x77222DC2 in DTSA Template Hololens.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x0252F5B4.
    4. Exception thrown at 0x77222DC2 in DTSA Template Hololens.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x0252F68C.
     
  22. mabakay

    mabakay

    Joined:
    Jun 10, 2016
    Posts:
    19
    Is there way to download this asset from external site that assetstore? Im using older version of Unity.
     
  23. smartinetz

    smartinetz

    Joined:
    Dec 8, 2017
    Posts:
    33
    Hi ..

    I am using your script and it works just fine in the editor. After I publish it to iOS however I get this error when I try to load my Model from Application.persistentDataPath. I use the same path to load images and my database, so I guess that's not the issue here. I am clueless right now.. any takers?

    I just call: loadedObject = new OBJLoader().Load(Configuration.Mypath + fileName);

    Why does this work in the editor but not on the device!??

    Code (CSharp):
    1. ArgumentNullException: Value cannot be null.
    2. Parameter name: shader
    3.   at UnityEngine.Material.CreateWithShader (UnityEngine.Material self, UnityEngine.Shader shader) [0x00000] in <00000000000000000000000000000000>:0
    4.   at UnityEngine.Material..ctor (UnityEngine.Shader shader) [0x00000] in <00000000000000000000000000000000>:0
    5.   at Dummiesman.OBJLoaderHelper.CreateNullMaterial () [0x00000] in <00000000000000000000000000000000>:0
    6.   at Dummiesman.OBJObjectBuilder.Build () [0x00000] in <00000000000000000000000000000000>:0
    7.   at Dummiesman.OBJLoader.Load (System.IO.Stream input) [0x00000] in <00000000000000000000000000000000>:0
    8.   at Dummiesman.OBJLoader.Load (System.String path, System.String mtlPath) [0x00000] in <00000000000000000000000000000000>:0
    9.   at Dummiesman.OBJLoader.Load (System.String path) [0x00000] in <00000000000000000000000000000000>:0
    10.   at ObjFromFile.OnGUI () [0x00000] in <00000000000000000000000000000000>:0
    11.  
     
  24. smartinetz

    smartinetz

    Joined:
    Dec 8, 2017
    Posts:
    33
    If anybody ever stumbles across this, I solved it by adding the Standard Specular Setup in
    Project Settings > Graphics > Always Included shaders

    Yes, I know, it says so in the included Readme ;) :p
     
  25. Midiphony

    Midiphony

    Joined:
    Jan 25, 2019
    Posts:
    3
    This asset was exactly what I needed ! The scripts are well documented so anyone should be able to use this importer within minutes (an hour max) :D

    However with the current version of Unity, it takes forever, while building to compile the Standard and Standard (Specular Setup) shaders. I am pretty sure the problem comes from Unity or my project settings (and not this asset!) and am currently seeking help :\
     
  26. JCUDOS

    JCUDOS

    Joined:
    Oct 11, 2018
    Posts:
    1
    Praise be aaro4130!
    I saw this feature in Besiege (which allows users to create skins themselves) before I started developing games and now I find out I don't even have to start from scratch to add it to my game, this is great...
    Praise be aaro4130!!!
     
  27. dandib

    dandib

    Joined:
    Jan 6, 2017
    Posts:
    2
    Hey @aaro4130 ,
    First of all great asset!

    I am loading multiple OBJs one after the other. they are loaded in the same position as they were when they were created in a different app. However, when loaded into Unity all gameobjects have the same position of 0,0,0.
    I've tried many things to try to get their actual position but I always receive 0,0,0.

    I really need to access their real positions, Is there a way to do this?

    Thanks! posProblem.png
     
  28. smartinetz

    smartinetz

    Joined:
    Dec 8, 2017
    Posts:
    33
    Hey... did any of you have success with async loading?
     
  29. TheDav1311

    TheDav1311

    Joined:
    Sep 30, 2019
    Posts:
    1
    I found a bug.
    If you load a obj-file which was created by Blender the mesh is all over the place.

    This should be a icosahedron. bug.png
     
  30. ianxyz100

    ianxyz100

    Joined:
    May 10, 2018
    Posts:
    3
    Hey, I have used this asset for desktop and it works great, but when I try to build for IOS, I get the errors:

    ImageLoader.cs error CS0117: 'TextureFormat' does not contain a definition for 'DXT1Crunched'
    ImageLoader.cs error CS0117: 'TextureFormat' does not contain a definition for 'DXT5Crunched'
    ImageLoader.cs error CS0117: 'TextureFormat' does not contain a definition for 'ETC2_RGBA8Crunched'

    Any help would be greatly appreciated :)
     
  31. prosoftvr

    prosoftvr

    Joined:
    Mar 23, 2017
    Posts:
    1
    Merhaba, Birden fazla obj dosyası nasıl eklenir?
     
  32. Elharter

    Elharter

    Joined:
    Sep 20, 2015
    Posts:
    42