mpreble / UnityFBXImporter

150 stars 53 forks source link

JUNKS!!! #4

Closed Miloti closed 7 years ago

Miloti commented 7 years ago

FBXImporter?! A while loop that does nothing than freeze computer!!! I mean serious!! Go check this code before publishing

mpreble commented 7 years ago

Good point. I put this up 3 years ago when it was (mostly) working. Perhaps better to take it down now rather than keep parroting that it's out of date as I'm not seeing myself update it in the near future.

Miloti commented 7 years ago

I'm trying this for two days and I just cant make it work!

Get Outlook for Androidhttps://aka.ms/ghei36

On Wed, Nov 30, 2016 at 10:19 PM +0100, "Mathias Preble" notifications@github.com<mailto:notifications@github.com> wrote:

Good point. I put this up 3 years ago when it was (mostly) working. Perhaps better to take it down now rather than keep parroting that it's out of date as I'm not seeing myself update it in the near future.

- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mpreble/UnityFBXImporter/issues/4#issuecomment-263998428, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOf3L3-pdZTjO2SAuxHzyDU2mFj0_8xEks5rDegwgaJpZM4LAsDs.

dunachu commented 7 years ago

Hello,

Here is the package I used from this tool. I worked about it about 1 or 2 years ago. I've done some changes. I have transformed methods into Coroutines to import FBX. It avoids Unity to freeze. I had added a micro-implementation from Animations but if I remember I only implemented rotation animation. It worked in Unity 4.6. I don't know if it always work now.

I hope it can help you ;)

UnityFBXImporter.zip

Miloti commented 7 years ago

Hello,

Thanks for sending this, I tried again but in unity 5 it keeps freezing when I call like this StartCoroutine(ImportAllFBX());

Also tried in unity 4.7, in this version it does not freeze but the result is an empty GameObject with the name of the model.

Bests


From: dunachu notifications@github.com Sent: Thursday, December 1, 2016 10:12 AM To: mpreble/UnityFBXImporter Cc: Miloti; Author Subject: Re: [mpreble/UnityFBXImporter] JUNKS!!! (#4)

Hello,

Here is the package I used from this tool. I worked about it about 1 or 2 years ago. I've done some changes. I have transformed methods into Coroutines to import FBX. It avoids Unity to freeze. I had added a micro-implementation from Animations but if I remember I only implemented rotation animation. It worked in Unity 4.6. I don't know if it always work now.

I hope it can help you ;)

UnityFBXImporter.ziphttps://github.com/mpreble/UnityFBXImporter/files/624083/UnityFBXImporter.zip

- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mpreble/UnityFBXImporter/issues/4#issuecomment-264119940, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOf3LzAwC_5PbdqI0LHQi9awj14iaRKiks5rDo-MgaJpZM4LAsDs.

dunachu commented 7 years ago

Is your FBX in ASCII mode ? Is it triangulate ? Have you got an exception or some logs in the Console ?

Miloti commented 7 years ago

I converted a fbx file ASCII mode with Fbx Converter 2013.3 from Autodesk and tried to import it but again the same, it doesn't import!

if I save fbx to binary mode, the console shows this: ArgumentException: Arg_InsufficientSpace Parameter name: chars


From: dunachu notifications@github.com Sent: Thursday, December 1, 2016 11:37 AM To: mpreble/UnityFBXImporter Cc: Miloti; Author Subject: Re: [mpreble/UnityFBXImporter] JUNKS!!! (#4)

Is your FBX in ASCII mode ? Is it triangulate ? Have you got an exception or some logs in the Console ?

- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mpreble/UnityFBXImporter/issues/4#issuecomment-264137832, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOf3L8k93l7oTZUt5KnIuk4GDcjAMo-gks5rDqNQgaJpZM4LAsDs.

dunachu commented 7 years ago

The Fbx Converter from AutoDesk doesn't allow you to select the triangulate option for the export. Which software do you first use to export the FBX File ?

Miloti commented 7 years ago

hey, it works in unity 4.7 by changing the triangulate and file format to ASCII. Thanks :)

However, it doesn't import the textures only the mesh, maybe I'm missing something?

In unity 5 it keeps freezing and I need to study your code deeper and hopefully I can find out why it keeps freezing when I call StartCoroutine(ImportAllFBX()); I need to make it work in unity 5 because I'm working in a Hololens project which only supports unity 5 pro!

I use Autodesk 3ds max for exporting to fbx.

apologize for the title of this message but I was experimenting with this stuff for a while and really couldn't fix that, but finally got something working!

Bests


From: dunachu notifications@github.com Sent: Thursday, December 1, 2016 12:50 PM To: mpreble/UnityFBXImporter Cc: Miloti; Author Subject: Re: [mpreble/UnityFBXImporter] JUNKS!!! (#4)

The Fbx Converter from AutoDesk doesn't allow you to select the triangulate option for the export. Which software do you first use to export the FBX File ?

- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mpreble/UnityFBXImporter/issues/4#issuecomment-264152620, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOf3L7N38v7Z8P6nU-0doVa-poDv5TEzks5rDrSYgaJpZM4LAsDs.

dunachu commented 7 years ago

If memory serves, you have to call the "TextureImporter" routine before importing the FBX for them to match, but I had a problem, the textures imported were X-mirrored. I didn't investigate about it.

Bests

Miloti commented 7 years ago

maybe I can import textures something like obj texture importer :

public static Material[] LoadMTLFile(string fn) { Material currentMaterial = null; List matlList = new List(); FileInfo mtlFileInfo = new FileInfo(fn); string baseFileName = Path.GetFileNameWithoutExtension(fn); string mtlFileDirectory = mtlFileInfo.Directory.FullName + Path.DirectorySeparatorChar; foreach (string ln in File.ReadAllLines(fn)) { string l = ln.Trim().Replace(" ", " "); string[] cmps = l.Split(' '); string data = l.Remove(0, l.IndexOf(' ') + 1);

        if (cmps[0] == "newmtl")
        {
            if (currentMaterial != null)
            {
                matlList.Add(currentMaterial);
            }
            currentMaterial = new Material(Shader.Find("Standard (Specular setup)"));
            currentMaterial.name = data;
        }
        else if (cmps[0] == "Kd")
        {
            currentMaterial.SetColor("_Color",ParseColorFromCMPS(cmps));
        }
        else if (cmps[0] == "map_Kd")
        {
            //TEXTURE
            string fpth = OBJGetFilePath(data, mtlFileDirectory,baseFileName);
            if (fpth != null)
                currentMaterial.SetTexture("_MainTex",TextureLoader.LoadTexture(fpth));
        }
        else if (cmps[0] == "map_Bump")
        {
            //TEXTURE
            string fpth = OBJGetFilePath(data, mtlFileDirectory,baseFileName);
            if (fpth != null)
            {
                currentMaterial.SetTexture("_BumpMap", TextureLoader.LoadTexture(fpth, true));
                currentMaterial.EnableKeyword("_NORMALMAP");
            }
        }
        else if (cmps[0] == "Ks")
        {
            currentMaterial.SetColor("_SpecColor", ParseColorFromCMPS(cmps));
        }
        else if (cmps[0] == "Ka")
        {
            currentMaterial.SetColor("_EmissionColor", ParseColorFromCMPS(cmps, 0.05f));
            currentMaterial.EnableKeyword("_EMISSION");
        }
        else if (cmps[0] == "d")
        {
            float visibility = float.Parse(cmps[1]);
            if (visibility < 1)
            {
                Color temp = currentMaterial.color;

                temp.a = visibility;
                currentMaterial.SetColor("_Color", temp);

                //TRANSPARENCY ENABLER
                currentMaterial.SetFloat("_Mode", 3);
                currentMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                currentMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                currentMaterial.SetInt("_ZWrite", 0);
                currentMaterial.DisableKeyword("_ALPHATEST_ON");
                currentMaterial.EnableKeyword("_ALPHABLEND_ON");
                currentMaterial.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                currentMaterial.renderQueue = 3000;
            }

        }
        else if (cmps[0] == "Ns")
        {
            float Ns = float.Parse(cmps[1]);
            Ns = (Ns / 1000);
            currentMaterial.SetFloat("_Glossiness", Ns);

        }
    }
    if(currentMaterial != null)
    {
        matlList.Add(currentMaterial);
    }
    return matlList.ToArray();
}

but still I don't get to the point to import the fbx textures to the imported fbx model


From: dunachu notifications@github.com Sent: Thursday, December 1, 2016 6:20 PM To: mpreble/UnityFBXImporter Cc: Miloti; Author Subject: Re: [mpreble/UnityFBXImporter] JUNKS!!! (#4)

If memory serves, you have to call the "TextureImporter" routine before importing the FBX for them to match, but I had a problem, the textures imported were X-mirrored. I didn't investigate about it.

- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mpreble/UnityFBXImporter/issues/4#issuecomment-264235447, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOf3L3_zDc1a6ozd1o4oQi4naG3WAwymks5rDwHYgaJpZM4LAsDs.

Miloti commented 7 years ago

I imported fbx model in autodesk and exported it back to ASCII and triangulate

then I tested but encountered these two errors

OverflowException: Value is too large System.Int32.Parse (System.String s) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Int32.cs:629) System.Convert.ToInt32 (System.String value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Convert.cs:1270) UnityFBXImporter.FBXImporter+c__Iterator3.MoveNext () (at Assets/UnityFBXImporter/FBXImporter.cs:545) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

ArgumentException: Arg_InsufficientSpace Parameter name: chars System.Text.UTF8Encoding.InternalGetChars (System.Byte bytes, Int32 byteCount, System.Char chars, Int32 charCount, System.UInt32& leftOverBits, System.UInt32& leftOverCount, System.Object provider, System.Text.DecoderFallbackBuffer& fallbackBuffer, System.Byte[]& bufferArg, Boolean flush) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Text/UTF8Encoding.cs:797) System.Text.UTF8Encoding.InternalGetChars (System.Byte[] bytes, Int32 byteIndex, Int32 byteCount, System.Char[] chars, Int32 charIndex, System.UInt32& leftOverBits, System.UInt32& leftOverCount, System.Object provider, System.Text.DecoderFallbackBuffer& fallbackBuffer, System.Byte[]& bufferArg, Boolean flush) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Text/UTF8Encoding.cs:744) System.Text.UTF8Encoding+UTF8Decoder.GetChars (System.Byte[] bytes, Int32 byteIndex, Int32 byteCount, System.Char[] chars, Int32 charIndex) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Text/UTF8Encoding.cs:1114) System.IO.StreamReader.ReadBuffer () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/StreamReader.cs:358) System.IO.StreamReader.Read (System.Char[] buffer, Int32 index, Int32 count) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/StreamReader.cs:415) System.IO.StreamReader.ReadToEnd () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/StreamReader.cs:519) UnityFBXImporter.FBXImporter+cIterator1.MoveNext () (at Assets/UnityFBXImporter/FBXImporter.cs:261) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) UnityFBXImporter.cIterator0:MoveNext() (at Assets/UnityFBXImporter/FBXImporter.cs:108) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) UnityFBXImporter.FBXImporter:OnGUI() (at Assets/UnityFBXImporter/FBXImporter.cs:83)

Do you have any idea why these errors appear?

Thanks


From: dunachu notifications@github.com Sent: Thursday, December 1, 2016 6:20 PM To: mpreble/UnityFBXImporter Cc: Miloti; Author Subject: Re: [mpreble/UnityFBXImporter] JUNKS!!! (#4)

If memory serves, you have to call the "TextureImporter" routine before importing the FBX for them to match, but I had a problem, the textures imported were X-mirrored. I didn't investigate about it.

- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mpreble/UnityFBXImporter/issues/4#issuecomment-264235447, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOf3L3_zDc1a6ozd1o4oQi4naG3WAwymks5rDwHYgaJpZM4LAsDs.

dunachu commented 7 years ago

Hello,

I supposed you know what is a OverflowException and ArgumentException.

The OverflowException is thrown when it try to parse a int below the minimal value or above the maximal value.

The ArgumentException seems to be thrown because the buffer size is less than it could be. That is weird that it throws this exception because ReadToEnd method from StreamReader not throwing this exception... I don't know why this exception is thrown. For this, I can't help you anymore...

For the rest, as I said before, it was a long time I didn't work on it. At first sight, the texture import could work like this. But, why don't you call the TextureImporter method before calling the FBXImporter's one like this in another coroutine ? It records some informations in others utility class.

[RequireComponent(typeof(TextureImporter),typeof(FBXImporter))]
public class TestFBXImporter : MonoBehaviour{
IEnumerator Start(){
TextureImporter textureImporter = GetComponent<TextureImporter>();
FBXImporter fbxImporter = GetComponent<FBXImporter>();
yield return StartCoroutine(textureImporter.ImportAllJPG());
yield return StartCoroutine(fbxImporter.ImportAllFBX());
Debug.Log("It's done ;-)");
}
}

PS : I wrote the script directly here, I didn't test it in Unity. (it could be syntax errors ;) )

Hope it helps, Bests,

Miloti commented 7 years ago

Hi,

I'm new to unity so maybe the exception is thrown because of the int type. I tried to change all the types in FBXImporter to long data type but the Meshfilter.mesh.triangles is a type int and locked class so wont allow unity to change it so I switched the types back to int.

the text Debug.Log("It's done ;-)"); never prints after IEnumerator Start() is called or some button click because an error shows up in TextureImporter script :

NullReferenceException: Object reference not set to an instance of an object UnityFBXImporter.TextureImporter+c__Iterator9.MoveNext () (at Assets/UnityFBXImporter/TextureImporter.cs:34) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

TextureImporter line 34 : BuildDefinitions.textures.Add(text.texture);

the textures path is ok, this is strange idk why!

thanks


From: dunachu notifications@github.com Sent: Friday, December 2, 2016 9:58 AM To: mpreble/UnityFBXImporter Cc: Miloti; Author Subject: Re: [mpreble/UnityFBXImporter] JUNKS!!! (#4)

Hello,

I supposed you know what is a OverflowException and ArgumentException.

The OverflowException is thrown when it try to parse a int below the minimal value or above the maximal value.

The ArgumentException seems to be thrown because the buffer size is less than it could be. That is weird that it throws this exception because ReadToEnd method from StreamReader not throwing this exception... I don't know why this exception is thrown. For this, I can't help you anymore...

For the rest, as I said before, it was a long time I didn't work on it. At first sight, the texture import could work like this. But, why don't you call the TextureImporter method before calling the FBXImporter's one like this in another coroutine ? It records some informations in others utility class.

[RequireComponent(typeof(TextureImporter),typeof(FBXImporter))] public class TestFBXImporter : MonoBehaviour{ IEnumerator Start(){ TextureImporter textureImporter = GetComponent(); FBXImporter fbxImporter = GetComponent(); yield return StartCoroutine(textureImporter.ImportAllJPG()); yield return StartCoroutine(fbxImporter.ImportAllFBX()); Debug.Log("It's done ;-)"); } }

PS : I wrote the script directly here, I didn't test it in Unity. (it could be syntax errors ;) )

Hope it helps, Bests,

- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mpreble/UnityFBXImporter/issues/4#issuecomment-264405358, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOf3L8mP41Buq1cm8l8vOv5Ln1rf28caks5rD93PgaJpZM4LAsDs.