Exemple #1
0
    ///Main Loop
    public IEnumerator Load(string path)
    {
        WWW loader = new WWW(path);

        yield return(loader);

        if (loader.error != null)
        {
            Debug.Log("File Not Found");               //!!!!!
        }
        else
        {
            SetGeometryData(loader.text);
        }

        if (buffer.Check(true, false))          //buffer.Trace(AutoResolveVLimit)
        {
            if (hasMaterials)
            {
                loader = new WWW(ResolvePath(mtllib, basepath));
                yield return(loader);

                if (loader.error != null)
                {
                    Debug.Log("failed to resolve material library path" + basepath + mtllib);                  //!!!!!
                    string[] emats = buffer.ReturnMaterialNames();
                    materialData = new List <MaterialData>();
                    MaterialData nmd = new MaterialData();
                    foreach (string mname in emats)
                    {
                        nmd            = new MaterialData();
                        nmd.name       = mname;
                        nmd.ShaderName = "Diffuse";
                        nmd.diffuse    = new Color(0.5f, 0.5f, 0.5f, 1.0f);
                        materialData.Add(nmd);
                    }
                }
                else
                {
                    SetMaterialData(loader.text);
                    TMPTextures = new Texture2D[TextureList.Count];
                    foreach (KeyValuePair <string, int> txt in TextureList)
                    {
                        string imgext = Path.GetExtension(txt.Key);
                        if (imgext == ".jpg" || imgext == ".jpeg" || imgext == ".png")
                        {
                            WWW texloader = new WWW(ResolvePath(txt.Key, basepath));
                            yield return(texloader);

                            if (texloader.error != null)
                            {
                                Debug.Log("failed to resolve texture path" + basepath + txt.Key);
                            }
                            else
                            {
                                TMPTextures[txt.Value] = texloader.texture;
                            }
                        }
                        else
                        {
                            Debug.Log(txt.Key + ": image not correct file type please use jpeg or png");                            //!!!!
                        }
                    }
                    SolveMaterials();
                }
            }
            CheckScale();
            Build();
        }
        else
        {
            Debug.Log("Too many poly's");
        }
        Destroy(this);
    }