Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing AsImpL with 3D models #3

Open
gpvigano opened this issue Oct 4, 2017 · 12 comments
Open

Testing AsImpL with 3D models #3

gpvigano opened this issue Oct 4, 2017 · 12 comments

Comments

@gpvigano
Copy link
Owner

gpvigano commented Oct 4, 2017

I opened this issue to help the users who found any problem loading models with AsImpL (like @trevortknguyen in issue #2, or @Alacrious who contacted me via e-mail).

You can write a comment to this issue to share details about the problems you found (errors, performances issues, ...), in this way who has the same problems can read questions and answers.
If you need to send information or 3D models for testing and you can't or don't want to share them here, you can contact me at [email protected]

If you want to suggest new features, you find bugs or whatever else, please open a new issue or make a pull request.

@anonymouswaterbear
Copy link

Hey gpvigano,
I seem to be having some issues using your library for importing models during runtime.
Take for instance this model by Don Carson: https://poly.google.com/view/2cX88a40PMz

When I use the AsImpL library to import the model I get a bit of a weird result:
screen shot 2018-03-13 at 11 46 22

First off, the orientation is wrong (which might be a wrong import setting by me). Only a very small amount of child objects have materials and some of them don't even have renderers.

I only get one error and one warning when processing this file:
Material: default not found. UnityEngine.Debug:LogError(Object) AsImpL.ObjectBuilder:ImportSubObject(GameObject, ObjectData, Dictionary2) (at Assets/Scripts/AsImpL/Scripts/Dataset/ObjectBuilder.cs:568)
AsImpL.ObjectBuilder:BuildNextObject(GameObject, Dictionary`2) (at Assets/Scripts/AsImpL/Scripts/Dataset/ObjectBuilder.cs:336)
AsImpL.ObjectBuilder:BuildObjectAsync(ProgressInfo&) (at Assets/Scripts/AsImpL/Scripts/Dataset/ObjectBuilder.cs:129)
AsImpL.c__Iterator1:MoveNext() (at Assets/Scripts/AsImpL/Scripts/Loaders/Loader.cs:402)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Unable to compute tangent space vectors - texture coordinates not defined.
UnityEngine.Debug:LogWarning(Object)
AsImpL.ObjectBuilder:Solve(Mesh) (at Assets/Scripts/AsImpL/Scripts/Dataset/ObjectBuilder.cs:146)
AsImpL.ObjectBuilder:ImportSubObject(GameObject, ObjectData, Dictionary2) (at Assets/Scripts/AsImpL/Scripts/Dataset/ObjectBuilder.cs:597) AsImpL.ObjectBuilder:BuildNextObject(GameObject, Dictionary2) (at Assets/Scripts/AsImpL/Scripts/Dataset/ObjectBuilder.cs:336)
AsImpL.ObjectBuilder:BuildObjectAsync(ProgressInfo&) (at Assets/Scripts/AsImpL/Scripts/Dataset/ObjectBuilder.cs:129)
AsImpL.c__Iterator1:MoveNext() (at Assets/Scripts/AsImpL/Scripts/Loaders/Loader.cs:402)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)`

I also tested this model (exact same data/file) with another library and ended up with this:
screen shot 2018-03-13 at 11 45 01
This is the OBJImport library that I believe you also use for this library. Downside of it is that it isn't async which is very annoying for large models.

A part from that I also tried some other models like this guitar by David Edwards: https://poly.google.com/view/bf6_h_1wp2D.
This results in no guitar being visible and being spammed with:
face vertex count :5 larger than 4
Ranging from 5-14. Is this just a feature not implemented yet or am I doing something wrong?

Thanks in advance for the help.

@gpvigano
Copy link
Owner Author

You found some bugs, thanks for your feedback, anyway, did you use the latest version? I got a different result (I unchecked the Z Up toggle):
asimpl-2018-03-16_13-16-13
The error about the material is a collateral effect of a bug, you can find a fix with my last commit (15f7cef).
The last warnings you mentioned happened because of a known limitation: the support for faces with more than 4 vertices is still missing, I created a new issue, see issue #19.

@gpvigano
Copy link
Owner Author

I made a simple triangulation that works for simple convex polygons, it is not optimized to maximize triangle areas, but for now it is better than seeing holes in the surfaces. See issue #19 (and b388f43).
asimpl-2018-03-30_15-51-03.

@gpvigano
Copy link
Owner Author

gpvigano commented Apr 3, 2018

@LucasWalters In my commit c401204 there is a fix for a serious bug when using Unity 2017.3 or above (see issue #22).

@anonymouswaterbear
Copy link

That triangulation algorithm works really well even if it doesn't support concave polygons. Thanks for the fix.

Another issue that I forgot to mention before is that I'm using an online storage platform that uses a "&files=model.obj" suffix on the link in order to point to the file that is accessed. Problem is that the LoaderObj class uses this to try and find the MTL file:

mtlPath = absolutePath.Remove(absolutePath.LastIndexOf('/') + 1) + mtlLib;

This is why in my earlier post the high tea model didn't have any materials.
Maybe a better solution is to grab the link and replace the OBJ file name with the MTL file name?

@gpvigano
Copy link
Owner Author

gpvigano commented Apr 24, 2018

@LucasWalters

I think = could be a valid part of a file name, thus I would try something else.
Try to replace in LoaderObj class

               mtlPath = absolutePath.Remove(absolutePath.LastIndexOf('/') + 1) + mtlLib;

with

                int pos;
                // handle the case of an URL containing ".php?file=model.obj"
                if (absolutePath.Contains(".php?")
                    && absolutePath.EndsWith(".obj", true, CultureInfo.InvariantCulture))
                {
                    // in this case try to get the library path reading until last "=".
                    pos = absolutePath.LastIndexOf('=');
                }
                else
                {
                    pos = absolutePath.LastIndexOf('/');
                }
                mtlPath = absolutePath.Remove(pos + 1) + mtlLib;

and tell me if it works for you. If so I will commit this change.

@gpvigano
Copy link
Owner Author

gpvigano commented May 8, 2018

@LucasWalters can you test if the above changes work for you or at least give me an URL for testing? Thanks.

@anonymouswaterbear
Copy link

My apologies for the late response @gpvigano,
Unfortunately this solution is also not completely fool proof.
The storage service I use doesn't have ".php?" in the links, it does however contain just ".php" so that could work I guess.

I made a test folder with a few models from Poly Google so you can test it if you want to:
https://surfdrive.surf.nl/files/index.php/s/2cwYXhpXo4dFwnd
You can also edit and add files if you want to.

To download only the model I would use the link like so:
https://surfdrive.surf.nl/files/index.php/s/2cwYXhpXo4dFwnd/download?path=%2F&files=turtle.obj

Thanks for the work you're putting into this!

@gpvigano
Copy link
Owner Author

@LucasWalters You're welcome. I made some changes to enable downloading from PHP-based: if the URL contains a "?" and ends with ".obj" the LoaderObj class starts from last "=" to extract
the file name (and the material library path) instead of "/". See my commit e0e5b3d.
This is your turtle model loaded with example 003_Import_URL_Test (maybe you must move the camera and/or change the model scale to view it):

asimpl-2018-05-16_13-36-16

@harry881218
Copy link

Hi gpvigano,

For some reasons, I'm having issues loading the obj I want successfully. I've tried the examples you provided with your example scripts (AsImpLSample.cs) and it works wonderfully, but when I tried to load the obj I want to load, it failed. This is the result I got (sometimes it takes more than 30 seconds to load partially, sometimes about 14):
image

image

And here's what I got by importing it manually with the material applied:
image

Here's the file I'm using with .obj and .mtl in zip.
mesh_test.zip
Its texture map can be downloaded here (can't be uploaded due to its size).

As you can see in the image above, I didn't get any error message as it says the obj is loaded successfully, so I don't know what further information I can provide. Could you look into it and see if there's anything wrong or it's just me not knowing how to use the loader? Thanks in advance.

@NoTuxNoBux
Copy link
Contributor

NoTuxNoBux commented Apr 26, 2021

I'm having an issue where the imported models are much darker than they should be. I've verified this by comparing them with the same model as DAE imported by Unity, as well as with Blender opening the same OBJ or the DAE:

Example

The left version is the version as is imported in Unity by AsImpL. The right one is the way it should be. (Notice both the darkened colors as well as the metallic reflection.)

When comparing the shaders, it appears that AsImpL leaves the value of Smoothness at 0.5, which is perhaps the Unity default (?). Lowering this value explicitly to 0 seems to fix the issue. I can do this programatically by changing the following in ObjectBuilder.cs:

else
{
    newMaterial.SetFloat("_Metallic", metallic);
    //m.SetFloat( "_Glossiness", md.shininess );
}

To:

else
{
    newMaterial.SetFloat("_Metallic", metallic);
    newMaterial.SetFloat("_Smoothness", 0);
    //m.SetFloat( "_Glossiness", md.shininess );
}

But I'm not familiar enough with OBJ and shaders to know if this is the "correct" solution. I've tested three models, and all of them expose the same issue and seem to be fixed by adding this line.

EDIT: This is in Unity 2019.4.18f1.

@gpvigano
Copy link
Owner Author

gpvigano commented Sep 1, 2021

@harry881218
The name of the texture in the mtl file has underscores instead of hyphens, thus the file is not found.
The model seems to be fully loaded, but with a different transformation. Disabling Z up option and setting a rotation of 180 degrees around vertical axis (Local Euler Angles|Y) matches the transformation of the model loaded with Unity. If you open this model with other viewers you'll see that it is Unity Editor that does not load the OBJ correctly. Anyway you can change loading options as above to match your requirements.

@NoTuxNoBux Does something like m.SetFloat( "_Smoothness", md.shininess / 1000.0f) work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants