Exemple #1
0
        public override IEnumerator AsyncBuild(string path)
        {
            this.objList = null;
            ObjAssetStream stream = new ObjAssetStream();

            stream.AsyncRead(path);
            while (false == stream.asyncReadComplete)
            {
                yield return(null);
            }
            ObjAssetFormat format = stream.data;

            this.hasMaterial = (0 < format.mtllibList.Count);
            if (false != this.hasMaterial)
            {
                this.mtlAssetName = format.mtllibList[0].name;
            }
            this.usemtlDictionary = format.usemtlDictionary;
            ObjAssetMeshBuilder builder = new ObjAssetMeshBuilder();

            builder.SetFormat(format);
            List <GameObject> objGameObjectList = new List <GameObject>();

            foreach (ObjAssetObjectFormat oformat in format.oList)
            {
                if (false == format.gDictionary.ContainsKey(oformat.name))
                {
                    continue;
                }
                GameObject objGameObject = new GameObject();
                objGameObject.name = oformat.name;
                List <ObjAssetGroupFormat> glist = format.gDictionary[oformat.name];
                foreach (ObjAssetGroupFormat gformat in glist)
                {
                    string      groupPath = Path.Combine(oformat.name, gformat.name);
                    List <Mesh> meshList  = builder.SetGroupPath(groupPath).Build();
                    if (0 == meshList.Count)
                    {
                        continue;
                    }
                    for (int meshCount = 0; meshCount < meshList.Count; meshCount++)
                    {
                        GameObject groupGameObject = new GameObject();
                        groupGameObject.name = gformat.name;
                        groupGameObject.transform.position = objGameObject.transform.position;
                        groupGameObject.transform.parent   = objGameObject.transform;
                        groupGameObject.AddComponent <MeshRenderer>();
                        MeshFilter meshFilter = groupGameObject.AddComponent <MeshFilter>();
                        meshFilter.mesh = meshList[meshCount];
                    }
                }
                objGameObjectList.Add(objGameObject);
                yield return(null);
            }
            this.objList = objGameObjectList;
            yield return(null);
        }
 public ObjAssetMeshBuilder SetFormat(ObjAssetFormat format)
 {
     this.format = format;
     return(this);
 }