public void Load( )
    {
        if (this._isDone == false)
        {
            return;
        }
        this._isDone          = false;
        this.counter          = 0;
        this.porcentage       = 0.0f;
        this.CONNECTION_COUNT = 0;
        UniFBXStads.Init();
        UniFBXStads.TimerStart();

        if (this.setting.paths.urlModels.Contains("http"))
        {
            StartCoroutine(this.ILoadWWW());
        }
#if !UNITY_WEBPLAYER || !UNITY_WEBGL
        else
        {
            this.setting.paths.urlModels = this.setting.paths.urlModels.Replace("file:///", "");
            StartCoroutine(this.ILoad());
        }
#endif
    }
    public bool SetModels(int i)
    {
        string rootID = "RootNode";

        if (this.fbxsdk == FBX.SDK2010)
        {
            rootID = " \"Model::Scene\"";
        }

        int n = foo + i;

        if (n >= (list.Count - 1) || list[n].Contains(";Takes section"))
        {
            return(false);
        }

        if (list[n].Contains(";Model::") && list[n].Contains(", Model::"))
        {
            #region "Model To Model"
            string[] data = list[n].Split(',');
            string   ncc  = data[0].Split(':')[2];
            string   npp  = data[1].Split(':')[2];

            GameObject p = null;
            GameObject c = null;
            if (!models.ContainsKey(npp))
            {
                p = new GameObject(npp);
                if (npp == rootID)
                {
                    p.name = this.setting.paths.filename;
                    p.transform.position   = this.tr.position;
                    p.transform.rotation   = this.tr.rotation;
                    p.transform.localScale = this.tr.localScale;
                }
                models.Add(npp, p);
                UniFBXStads.AddObject();
            }
            else
            {
                p = models[npp];
            }
            if (!models.ContainsKey(ncc))
            {
                c = new GameObject(ncc);
                c.transform.parent = models[npp].transform;
                models.Add(ncc, c);
                UniFBXStads.AddObject();
            }
            else
            {
                c = models[ncc];
                c.transform.parent = models[npp].transform;
            }
            #endregion
        }

        return(true);
    }
 void Update( )
 {
     if (CONNECTION_COUNT > 0)
     {
         var p = 100.0f * ((float)(counter + 1) / CONNECTION_COUNT);
         p = Mathf.Clamp(p, 0.0f, 100.0f);
         this.porcentage = p;
         UniFBXStads.SetPorcentage(this.porcentage);
     }
 }
    private void LoadTextures_JPG(string filename, byte[] bytes, Material material, string channel)
    {
        var tex = new Texture2D(32, 32, TextureFormat.RGB24, true);

        tex.LoadImage(bytes);

        if (channel == "_BumpMap")
        {
            var   nm = new Texture2D(tex.width, tex.height, TextureFormat.RGB24, true);
            Color c  = new Color();
            for (int x = 0; x < tex.width; x++)
            {
                for (int y = 0; y < tex.height; y++)
                {
                    c.r = tex.GetPixel(x, y).g;
                    c.g = c.r;
                    c.b = c.r;
                    //c.a = tex.GetPixel (x, y).r;
                    nm.SetPixel(x, y, c);
                }
            }
            nm.Apply();
            nm.name = filename;
            nm.Compress(false);
            textures.Add(filename, nm);
            material.SetTexture(channel, nm);
            UniFBXStads.AddTexture();
        }
        else
        {
            tex.name = filename;
            tex.Compress(false);
            textures.Add(filename, tex);
            material.SetTexture(channel, tex);
            UniFBXStads.AddTexture();

            #region "Transparence"
            if (setting.materials.shaderType == ShaderType.Standard)
            {
                material.SetFloat("_Mode", 0.0f);
            }
            else if (setting.materials.shaderType == ShaderType.Legacy)
            {
#if UNITY_5
                material.shader = Shader.Find("Legacy Shaders/Transparent/Diffuse");
#else
                material.shader = Shader.Find("Transparent/Diffuse");
#endif
            }
            #endregion
        }
        System.Array.Clear(bytes, 0, bytes.Length - 1);
        bytes = null;
    }
    private void LoadTextures_Default(string filename, byte[] bytes, Material material, string channel)
    {
        var tex = new Texture2D(32, 32, TextureFormat.ARGB32, true);

        tex.LoadImage(bytes);
        tex.name = filename;
        tex.Compress(false);
        textures.Add(filename, tex);
        material.SetTexture(channel, tex);
        UniFBXStads.AddTexture();
    }
Example #6
0
    public string GetStads()
    {
        string s = "";

        s += "Objects: " + UniFBXStads.objectCount.ToString() + "\n";
        s += "Meshes: " + UniFBXStads.meshCount.ToString() + "\n";
        s += "Vertices: " + UniFBXStads.vertexCount.ToString() + "\n";
        s += "Polygones: " + UniFBXStads.polygoneCount.ToString() + "\n";
        s += "Materials: " + UniFBXStads.materialCount.ToString() + "\n";
        s += "Textures: " + UniFBXStads.textureCount.ToString() + "\n";

        if (uimport)
        {
            s += "Status: " + uimport.setting.Status.ToString() + "\n";
        }
        s += "Loaded in " + UniFBXStads.GetLoadTime().ToString("0.0") + " seconds\n";
        s += "Completed: " + UniFBXStads.progress.ToString("0") + "%";
        return(s);
    }
Example #7
0
    private void Run( )
    {
        this.IsDone       = false;
        this.properties70 = new Dictionary <string, Properties70> ();

        var indexes = Enumerable.Range(0, UniFBX.list.Count).Where(x => UniFBX.list[x].Contains("\"Material::")).ToList();

        string[] data = new string[0];
        for (int i = 0; i < indexes.Count; i++)
        {
            Properties70 prop70 = new Properties70();
            var          j      = indexes[i];
            data        = UniFBX.list[j].Split(new char[] { ':', ',', '\"' });
            prop70.id   = data[1].Trim();
            prop70.name = data[5].Trim();

            for (int k = j; k < (j + 10); k++)
            {
                if (UniFBX.list[k].Contains("\"EmissiveColor\""))
                {
                    data = UniFBX.list[k].Split(',');
                    prop70.emissiveColor.r = float.Parse(data[data.Length - 3]);
                    prop70.emissiveColor.g = float.Parse(data[data.Length - 2]);
                    prop70.emissiveColor.b = float.Parse(data[data.Length - 1]);
                    prop70.emissiveColor.a = 1.0f;
                }
                else if (UniFBX.list[k].Contains("\"DiffuseColor\""))
                {
                    data = UniFBX.list[k].Split(',');
                    prop70.diffuseColor.r = float.Parse(data[data.Length - 3]);
                    prop70.diffuseColor.g = float.Parse(data[data.Length - 2]);
                    prop70.diffuseColor.b = float.Parse(data[data.Length - 1]);
                    prop70.diffuseColor.a = 1.0f;
                    break;
                }
            }

            this.properties70.Add(prop70.id, prop70);
            UniFBXStads.AddMaterial();
        }
        this.IsDone = true;
    }
    public byte SetGeometries(int i)
    {
        int n = foo + i;

        if (n >= (list.Count - 1) || list[n].Contains(";Takes section"))
        {
            return(0);
        }

        if (list[n].Contains(";Geometry::") && list[n].Contains(", Model::"))
        {
            #region "Geometry To Model"
            string[] data = list[n].Split(',');
            string   npp  = data[1].Split(':')[2];
            models[npp].AddComponent <UniFBXGeometry> ().Add(models[npp], ugeometries1, ugeometries2, ugeometries3, setting, geometryIndex++);
            UniFBXStads.AddMesh();
            return(1);

            #endregion
        }

        return(2);
    }
    private IEnumerator ILoadWWW()
    {
        string path = this.setting.paths.urlModels + this.setting.paths.filename + ".fbx";

        using (WWW www = new WWW(path))
        {
            this.setting.Status = FBXStatus.Connecting;
            while (!www.isDone)
            {
                yield return(null);
            }
            if (www.error == null)
            {
                string s = www.text;
                if (!s.Contains("<br />"))
                {
                    using (UniFBX fbx = new UniFBX(s, this.setting, this.transform)) {
                        //Read fbx file
                        fbx.Load();
                        while (fbx.IsRunning)
                        {
                            yield return(null);
                        }
                        int Len = (fbx.GetConnectionListCount() / 3) * 2;     //Models and Transform
                        if (this.setting.textures.textureImported == Imported.Yes)
                        {
                            Len += (fbx.GetConnectionListCount() / 3) * 2;
                        }
                        if (this.setting.lights.lightImported == Imported.Yes)
                        {
                            Len += (fbx.GetConnectionListCount() / 3);
                        }
                        if (this.setting.cameras.cameraImported == Imported.Yes)
                        {
                            Len += (fbx.GetConnectionListCount() / 3);
                        }
                        if (this.setting.animations.animationImported == Imported.Yes)
                        {
                            Len += (fbx.GetConnectionListCount() / 3);
                        }
                        CONNECTION_COUNT = Len;
                        int from = 2;
                        int skip = 3;
                        if (fbx.GetSDK() == FBX.SDK2010)
                        {
                            from = 1;
                            skip = 1;
                        }

                        if (this.IsStatusGood() == true)
                        {
                            int frames = 0;

                            //Read geometries and animations
                            #region "FBX Init"
                            if (this.setting.animations.animationImported == Imported.Yes)
                            {
                                fbx.GetAnimations();
                            }
                            if (this.setting.meshes.meshImport == Imported.Yes)
                            {
                                fbx.GetGeometries();
                            }
                            fbx.GetModels();
                            #endregion

                            //Models
                            #region "Models as GameObjects"
                            for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                            {
                                this.counter++;
                                if (fbx.SetModels(i) == false)
                                {
                                    break;
                                }
                                else
                                {
                                    if (++frames == 1024)
                                    {
                                        frames = 0;
                                        yield return(null);
                                    }
                                }
                            }
                            #endregion

                            //Transform
                            #region "Transforms (TRS)"
                            while (!fbx.IsLclTransformReady())
                            {
                                yield return(null);
                            }
                            for (int i = 0; i < fbx.GetModelCount(); i++)
                            {
                                fbx.SetLclTransform(i);
                            }
                            fbx.ClearModels();
                            #endregion

                            //Geometries as Meshes
                            #region "Geometries"
                            if (this.setting.meshes.meshImport == Imported.Yes)
                            {
                                while (!fbx.IsGeometriesReady())
                                {
                                    yield return(null);
                                }
                                yield return(null);

                                yield return(null);

                                frames = 0;
                                for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                                {
                                    this.counter++;
                                    byte status = fbx.SetGeometries(i);
                                    if (status == 0)
                                    {
                                        break;
                                    }
                                }
                                fbx.ClearGeometries();
                            }
                            #endregion

                            //Materials
                            #region "Materials"
                            if (this.setting.materials.materialImported == Imported.Yes)
                            {
                                fbx.GetMaterials();
                                if (this.setting.textures.textureImported == Imported.Yes)
                                {
                                    fbx.GetLayeredTextures();
                                    fbx.GetTextures();
                                }
                                while (!fbx.IsMaterialsReady())
                                {
                                    yield return(null);
                                }
                            }

                            if (this.setting.lights.lightImported == Imported.Yes)
                            {
                                fbx.GetLights();
                            }
                            if (this.setting.cameras.cameraImported == Imported.Yes)
                            {
                                fbx.GetCameras();
                            }
                            #endregion

                            //Textures
                            #region "Textures"
                            if (this.setting.textures.textureImported == Imported.Yes)
                            {
                                while (!fbx.IsLayeredTexturesReady())
                                {
                                    yield return(null);
                                }
                                while (!fbx.IsTexturesReady())
                                {
                                    yield return(null);
                                }

                                frames = 0;
                                for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                                {
                                    this.counter++;
                                    byte status = fbx.GetLayeredTextures(i);
                                    if (status == 0)
                                    {
                                        break;
                                    }
                                }
                                for (int i = 0; i < 20; i++)
                                {
                                    yield return(null);
                                }

                                frames = 0;
                                for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                                {
                                    this.counter++;
                                    byte status = fbx.SetTextures(i);
                                    if (status == 0)
                                    {
                                        break;
                                    }
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_WEBGL
                                    else if (status == 1)
                                    {
                                        if (++frames == 2 * this.setting.paths.objectPerFrame)
                                        {
                                            frames = 0;
                                            yield return(null);
                                        }
                                    }
#endif
                                }

                                fbx.ClearMaterials();
                                fbx.ClearLayeredTextures();
                                fbx.ClearTextures();
                            }
                            #endregion

                            //Lights
                            #region "Lights"
                            if (this.setting.lights.lightImported == Imported.Yes)
                            {
                                while (!fbx.IsLightsReady())
                                {
                                    yield return(null);
                                }
                                frames = 0;
                                for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                                {
                                    this.counter++;
                                    byte status = fbx.SetLights(i);
                                    if (status == 0)
                                    {
                                        break;
                                    }
                                    else if (status == 1)
                                    {
                                        if (++frames == 2 * this.setting.paths.objectPerFrame)
                                        {
                                            frames = 0;
                                            yield return(null);
                                        }
                                    }
                                }
                                fbx.ClearLights();
                            }
                            #endregion

                            //Cameras
                            #region "Cameras"
                            if (this.setting.cameras.cameraImported == Imported.Yes)
                            {
                                while (!fbx.IsCamerasReady())
                                {
                                    yield return(null);
                                }
                                frames = 0;
                                for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                                {
                                    this.counter++;
                                    byte status = fbx.SetCameras(i);
                                    if (status == 0)
                                    {
                                        break;
                                    }
                                    else if (status == 1)
                                    {
                                        if (++frames == this.setting.paths.objectPerFrame)
                                        {
                                            frames = 0;
                                            yield return(null);
                                        }
                                    }
                                }
                                fbx.ClearCameras();
                            }
                            #endregion

                            //Animations
                            #region "Animations"
                            if (this.setting.animations.animationImported == Imported.Yes)
                            {
                                if (this.setting.animations.animationMethode == AnimationMethode.Animation)
                                {
                                    if (fbx.AnimationsExist())
                                    {
                                        while (!fbx.IsAnimationsReady())
                                        {
                                            yield return(null);
                                        }

                                        frames = 0;
                                        for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                                        {
                                            this.counter++;
                                            byte status = fbx.SetAnimationComponent(i);
                                            if (status == 0)
                                            {
                                                break;
                                            }
                                        }

                                        yield return(null);

                                        frames = 0;
                                        for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                                        {
                                            this.counter++;
                                            byte status = fbx.GetAnimations(i);
                                            if (status == 0)
                                            {
                                                break;
                                            }
                                            else if (status == 1)
                                            {
                                                if (++frames == 10 * this.setting.paths.objectPerFrame)
                                                {
                                                    frames = 0;
                                                    yield return(null);
                                                }
                                            }
                                        }
                                        fbx.PlayAnimations();
                                        fbx.ClearAnimations();
                                    }
                                }
#if !UNITY_3_5
                                else if (this.setting.animations.animationMethode == AnimationMethode.Animator)
                                {
                                    fbx.SetAnimatorComponent();
                                }
#endif
                            }
                            #endregion


                            //Success
                            UniFBXStads.TimerStop();
                            this.setting.Status = FBXStatus.Success;
                            fbx.Renderize();
                            this.o = fbx.GetRoot();

                            //Clear all fbx variables
                            yield return(new WaitForSeconds(0.3f));

                            fbx.Clear();
                            yield return(null);

                            Resources.UnloadUnusedAssets();
                            this._isDone = true;
#if UNITY_EDITOR
                            if (this.setting.Status == FBXStatus.Success)
                            {
                                Debug.Log("Success!");
                            }
#endif
                        }
                        else
                        {
                            UniFBXStads.TimerStop();
                            yield return(null);

                            Resources.UnloadUnusedAssets();
                            this._isDone = true;
                        }
                    }
                }
            }
            else
            {
                string e = www.error.ToUpper();
                Debug.Log(www.error);
                if (e.Contains("OPEN FILE"))
                {
                    this.setting.Status = FBXStatus.FileNotFound;
                    UniFBXStads.TimerStop();
#if UNITY_EDITOR
                    Debug.Log("Couldn't open file or file not found");
#endif
                }
                else if (e.Contains("RESOLVE HOST"))
                {
                    this.setting.Status = FBXStatus.InternetNotAvailable;
                    UniFBXStads.TimerStop();
#if UNITY_EDITOR
                    Debug.Log("Internet not available or could not resolve host");
#endif
                }
                else if (www.error.Contains("CONNECTION REFUSED"))
                {
                    this.setting.Status = FBXStatus.InternetNotAvailable;
                    UniFBXStads.TimerStop();
#if UNITY_EDITOR
                    Debug.Log("Internet not available or could not resolve host");
#endif
                }
                else
                {
                    this.setting.Status = FBXStatus.UnknownError;
                    UniFBXStads.TimerStop();
#if UNITY_EDITOR
                    Debug.Log(e);
#endif
                }
                Resources.UnloadUnusedAssets();
                this._isDone = true;
            }
        }
    }
    private IEnumerator ILoad( )
    {
        using (UniFBX fbx = new UniFBX(this.setting, this.transform)) {
            //Read fbx file
            fbx.Load();
            while (fbx.IsRunning)
            {
                yield return(null);
            }
            int Len = (fbx.GetConnectionListCount() / 3) * 2;     //Models and Transform
            if (this.setting.textures.textureImported == Imported.Yes)
            {
                Len += (fbx.GetConnectionListCount() / 3) * 2;
            }
            if (this.setting.lights.lightImported == Imported.Yes)
            {
                Len += (fbx.GetConnectionListCount() / 3);
            }
            if (this.setting.cameras.cameraImported == Imported.Yes)
            {
                Len += (fbx.GetConnectionListCount() / 3);
            }
            if (this.setting.animations.animationImported == Imported.Yes)
            {
                Len += (fbx.GetConnectionListCount() / 3);
            }
            CONNECTION_COUNT = Len;
            int from = 2;
            int skip = 3;
            if (fbx.GetSDK() == FBX.SDK2010)
            {
                from = 1;
                skip = 1;
            }

            if (this.IsStatusGood() == true)
            {
                int frames = 0;

                //Read geometries and animations
                #region "FBX Init"
                if (this.setting.animations.animationImported == Imported.Yes)
                {
                    fbx.GetAnimations();
                }
                if (this.setting.meshes.meshImport == Imported.Yes)
                {
                    fbx.GetGeometries();
                }
                #endregion

                //Models
                #region "Models as GameObjects"
                fbx.GetModels();
                for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                {
                    this.counter++;
                    if (fbx.SetModels(i) == false)
                    {
                        break;
                    }
                    else
                    {
                        if (++frames == 1024)
                        {
                            frames = 0;
                            yield return(null);
                        }
                    }
                }
                #endregion

                //Transform
                #region "Transforms (TRS)"
                while (!fbx.IsLclTransformReady())
                {
                    yield return(null);
                }
                for (int i = 0; i < fbx.GetModelCount(); i++)
                {
                    fbx.SetLclTransform(i);
                }
                fbx.ClearModels();
                #endregion

                //Geometries as Meshes
                #region "Geometries"
                if (this.setting.meshes.meshImport == Imported.Yes)
                {
                    while (!fbx.IsGeometriesReady())
                    {
                        yield return(null);
                    }
                    frames = 0;
                    for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                    {
                        this.counter++;
                        byte status = fbx.SetGeometries(i);
                        if (status == 0)
                        {
                            break;
                        }
                    }
                    //fbx.ClearGeometries ();
                }
                #endregion

                //Materials
                #region "Materials"
                if (this.setting.materials.materialImported == Imported.Yes)
                {
                    fbx.GetMaterials();
                    if (this.setting.textures.textureImported == Imported.Yes)
                    {
                        fbx.GetLayeredTextures();
                        fbx.GetTextures();
                    }
                    while (!fbx.IsMaterialsReady())
                    {
                        yield return(null);
                    }
                }

                if (this.setting.lights.lightImported == Imported.Yes)
                {
                    fbx.GetLights();
                }
                if (this.setting.cameras.cameraImported == Imported.Yes)
                {
                    fbx.GetCameras();
                }
                #endregion

                //Textures
                #region "Textures"
                if (this.setting.textures.textureImported == Imported.Yes)
                {
                    while (!fbx.IsLayeredTexturesReady())
                    {
                        yield return(null);
                    }


                    frames = 0;
                    for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                    {
                        this.counter++;
                        byte status = fbx.GetLayeredTextures(i);
                        if (status == 0)
                        {
                            break;
                        }
                    }
                    while (!fbx.IsTexturesReady())
                    {
                        yield return(null);
                    }
                    for (int i = 0; i < 20; i++)
                    {
                        yield return(null);
                    }

                    frames = 0;
                    for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                    {
                        this.counter++;
                        byte status = fbx.SetTextures(i);
                        if (status == 0)
                        {
                            break;
                        }
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_WEBGL
                        else if (status == 1)
                        {
                            if (++frames == 2 * this.setting.paths.objectPerFrame)
                            {
                                frames = 0;
                                yield return(null);
                            }
                        }
#endif
                    }

                    fbx.ClearMaterials();
                    fbx.ClearLayeredTextures();
                    fbx.ClearTextures();
                }
                #endregion

                //Lights
                #region "Lights"
                if (this.setting.lights.lightImported == Imported.Yes)
                {
                    while (!fbx.IsLightsReady())
                    {
                        yield return(null);
                    }
                    frames = 0;
                    for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                    {
                        this.counter++;
                        byte status = fbx.SetLights(i);
                        if (status == 0)
                        {
                            break;
                        }
                        else if (status == 1)
                        {
                            if (++frames == 2 * this.setting.paths.objectPerFrame)
                            {
                                frames = 0;
                                yield return(null);
                            }
                        }
                    }
                    fbx.ClearLights();
                }
                #endregion

                //Cameras
                #region "Cameras"
                if (this.setting.cameras.cameraImported == Imported.Yes)
                {
                    while (!fbx.IsCamerasReady())
                    {
                        yield return(null);
                    }
                    frames = 0;
                    for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                    {
                        this.counter++;
                        byte status = fbx.SetCameras(i);
                        if (status == 0)
                        {
                            break;
                        }
                        else if (status == 1)
                        {
                            if (++frames == this.setting.paths.objectPerFrame)
                            {
                                frames = 0;
                                yield return(null);
                            }
                        }
                    }
                    fbx.ClearCameras();
                }
                #endregion

                //Animations
                #region "Animations"
                if (this.setting.animations.animationImported == Imported.Yes)
                {
                    if (this.setting.animations.animationMethode == AnimationMethode.Animation)
                    {
                        if (fbx.AnimationsExist())
                        {
                            while (!fbx.IsAnimationsReady())
                            {
                                yield return(null);
                            }

                            frames = 0;
                            for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                            {
                                this.counter++;
                                byte status = fbx.SetAnimationComponent(i);
                                if (status == 0)
                                {
                                    break;
                                }
                            }

                            yield return(null);

                            frames = 0;
                            for (int i = from; i < fbx.GetListCount() - skip; i = i + skip)
                            {
                                this.counter++;
                                byte status = fbx.GetAnimations(i);
                                if (status == 0)
                                {
                                    break;
                                }
                                else if (status == 1)
                                {
                                    if (++frames == 10 * this.setting.paths.objectPerFrame)
                                    {
                                        frames = 0;
                                        yield return(null);
                                    }
                                }
                            }
                            fbx.PlayAnimations();
                            fbx.ClearAnimations();
                        }
                    }
#if !UNITY_3_5
                    else if (this.setting.animations.animationMethode == AnimationMethode.Animator)
                    {
                        fbx.SetAnimatorComponent();
                    }
#endif
                }
                #endregion


                //Success
                UniFBXStads.TimerStop();
                this.setting.Status = FBXStatus.Success;
                fbx.Renderize();
                this.o = fbx.GetRoot();

                //Clear all fbx variables
                yield return(null);

                fbx.Clear();
                Resources.UnloadUnusedAssets();
                this._isDone = true;
#if UNITY_EDITOR
                if (this.setting.Status == FBXStatus.Success)
                {
                    Debug.Log("Success!");
                }
#endif
            }
            else
            {
                UniFBXStads.TimerStop();
                yield return(null);

                Resources.UnloadUnusedAssets();
                this._isDone = true;
            }
        }
    }
 void Start( )
 {
     UniFBXStads.Init();
 }
    private void LoadTextures_TGA(string filename, byte[] bytes, Material material, string channel)
    {
        int width  = 256 * bytes[13] + bytes[12];
        int height = 256 * bytes[15] + bytes[14];
        int depth  = bytes[16];
        int SIZE   = width * height;

        Color32[] colors = new Color32[SIZE];
        int       SKIP   = 18;
        Texture2D tex    = null;

        if (depth == 32)
        {
            tex = new Texture2D(width, height, TextureFormat.ARGB32, true);
            for (int i = 0; i < SIZE; i++)
            {
                byte r = bytes[SKIP++];
                byte g = bytes[SKIP++];
                byte b = bytes[SKIP++];
                byte a = bytes[SKIP++];
                colors[i] = new Color32(b, g, r, a);
            }
        }
        else if (depth == 24)
        {
            tex = new Texture2D(width, height, TextureFormat.RGB24, true);
            for (int i = 0; i < SIZE; i++)
            {
                byte r = bytes[SKIP++];
                byte g = bytes[SKIP++];
                byte b = bytes[SKIP++];
                colors[i] = new Color32(b, g, r, 255);
            }
        }
        else
        {
            Debug.Log("TGA texture don't have 32 or 24 bit depth");
        }
        tex.SetPixels32(colors);
        tex.Apply();

        if (channel == "_BumpMap")
        {
            var   nm = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, true);
            Color c  = new Color();
            for (int x = 0; x < tex.width; x++)
            {
                for (int y = 0; y < tex.height; y++)
                {
                    c.r = tex.GetPixel(x, y).g;
                    c.g = c.r;
                    c.b = c.r;
                    c.a = tex.GetPixel(x, y).r;
                    nm.SetPixel(x, y, c);
                }
            }
            nm.Apply();
            nm.name = filename;
            nm.Compress(false);
            textures.Add(filename, nm);
            material.SetTexture(channel, nm);
            UniFBXStads.AddTexture();
        }
        else
        {
            tex.name = filename;
            tex.Compress(false);
            textures.Add(filename, tex);
            material.SetTexture(channel, tex);
            UniFBXStads.AddTexture();

            if (depth == 32)
            {
                #region "Transparence"
                if (setting.materials.shaderType == ShaderType.Legacy)
                {
#if UNITY_5
                    material.shader = Shader.Find("Legacy Shaders/Transparent/Diffuse");
#else
                    material.shader = Shader.Find("Transparent/Diffuse");
#endif
                }
                #endregion
            }
        }

        System.Array.Clear(bytes, 0, bytes.Length - 1);
        bytes = null;
    }
    private void LoadTextures_DDS(string filename, byte[] bytes, Material material, string channel)
    {
        Texture2D tex          = null;
        byte      ddsSizeCheck = bytes[4];

        if (ddsSizeCheck != 124)
        {
            Debug.LogWarning("Invalid DDS DXTn texture. Unable to read");
            tex = new Texture2D(16, 16);
        }

        int height = bytes[13] * 256 + bytes[12];
        int width  = bytes[17] * 256 + bytes[16];
        int depth  = bytes[87];

        int DDS_HEADER_SIZE = 128;

        byte[] dxtBytes = new byte[bytes.Length - DDS_HEADER_SIZE];
        System.Buffer.BlockCopy(bytes, DDS_HEADER_SIZE, dxtBytes, 0, bytes.Length - DDS_HEADER_SIZE);

        if (depth == 53)
        {
            tex = new Texture2D(width, height, TextureFormat.DXT5, false);
        }
        else
        {
            tex = new Texture2D(width, height, TextureFormat.DXT1, false);
        }
        tex.LoadRawTextureData(dxtBytes);

        if (channel == "_BumpMap")
        {
            var   nm = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, true);
            Color c  = new Color();
            for (int x = 0; x < tex.width; x++)
            {
                for (int y = 0; y < tex.height; y++)
                {
                    c.r = tex.GetPixel(x, tex.height - y - 1).g;
                    c.g = c.r;
                    c.b = c.r;
                    c.a = tex.GetPixel(x, tex.height - y - 1).r;
                    nm.SetPixel(x, y, c);
                }
            }
            nm.Apply();

            nm.name = filename;
            nm.Compress(false);
            textures.Add(filename, nm);
            material.SetTexture(channel, nm);
            UniFBXStads.AddTexture();
        }
        else
        {
            var   cm = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, true);
            Color c  = new Color();
            for (int x = 0; x < tex.width; x++)
            {
                for (int y = 0; y < tex.height; y++)
                {
                    c = tex.GetPixel(x, tex.height - y - 1);
                    cm.SetPixel(x, y, c);
                }
            }
            cm.Apply();
            cm.name = filename;
            cm.Compress(false);
            textures.Add(filename, cm);
            material.SetTexture(channel, cm);
            UniFBXStads.AddTexture();

            if (depth == 53)
            {
                #region "Transparence"
                if (setting.materials.shaderType == ShaderType.Legacy)
                {
#if UNITY_5
                    material.shader = Shader.Find("Legacy Shaders/Transparent/Diffuse");
#else
                    material.shader = Shader.Find("Transparent/Diffuse");
#endif
                }
                #endregion
            }
        }
        System.Array.Clear(bytes, 0, bytes.Length - 1);
        System.Array.Clear(dxtBytes, 0, bytes.Length - 1);
        bytes    = null;
        dxtBytes = null;
    }
        public Mesh ToUnityMesh(FBXSetting setting)
        {
            Mesh mesh = new Mesh();

            if (this.vertices == null)
            {
                return(mesh);
            }

            if (this.vertices.Count >= 65000)
            {
#if UNITY_EDITOR
                Debug.LogWarning("Mesh may not have more then 65000 vertices");
#endif
                return(mesh);
            }
            mesh.vertices = this.vertices.ToArray();
            UniFBXStads.AddVertices(mesh.vertexCount);

            if (this.submeshes != null)
            {
                mesh.subMeshCount = this.submeshes.Length;
                for (int i = 0; i < mesh.subMeshCount; i++)
                {
                    mesh.SetTriangles(this.submeshes[i].triangles.ToArray(), i);
                }
                UniFBXStads.AddTriangles(mesh.triangles.Length / 3);
            }
            else
            {
                if (this.triangles != null)
                {
                    mesh.triangles = this.triangles.ToArray();
                    UniFBXStads.AddTriangles(mesh.triangles.Length / 3);
                }
            }

            if (this.uvs != null)
            {
                if (this.uvs.Count == this.vertices.Count)
                {
                    mesh.uv = this.uvs.ToArray();
                }
                else
                {
#if UNITY_EDITOR
                    Debug.LogWarning("Don't have uvs or the mesh was subdivided in editor");
#endif
                }
            }

            switch (setting.meshes.normalMethode)
            {
            case NormalMethode.Imported: mesh.normals = this.normals.ToArray(); break;

            case NormalMethode.Calculated: mesh.RecalculateNormals(); break;
            }

            if (setting.textures.normalmaps)
            {
                if (this.tangents != null)
                {
                    mesh.tangents = this.tangents.ToArray();
                }
            }
            mesh.RecalculateBounds();
            ;

            return(mesh);
        }