public static void Convert(API_Device D, string a_ObjFile, Vector3 a_Size, string a_ObjColFile = null, string a_Root = null)
        {
            LevelMeshConverter.D = D;
            LevelMeshConverter.MainFolder = a_Root;

            FileInfo F = new FileInfo(a_ObjFile);
            string objn = F.Name.Replace(F.Extension, "");
            FileInfo M = new FileInfo(F.FullName.Replace(F.Extension, "") + ".mtl");
            if (M.Exists)
            {
                WavefrontMaterial[] Mats = WavefrontMaterial.LoadFromFile(M.FullName);
                foreach (WavefrontMaterial m in Mats)
                {
                    if (m.Name == null)
                        continue;
                    if (m.Name.EndsWith("._xmat"))
                        break;
                    EFile e = FileManager.CreateNewPhysicalFile(FileManager.NewFileType.Material, RisenEditorWin32Interop.MeshConverter.MapFilename(m.Name, objn) + "._xmat", false);
                    if (e.IsOpenable)
                        continue;
                    XmatWrapper m2 = null;

                    Func<string, Vector3, eCShaderDefault.GenericSampler> G = (x, y) =>
                    {
                        if (!string.IsNullOrEmpty(x))
                        {
                            x = ConvertImage(x, F.Directory);
                            return new eCShaderDefault.GenericSampler(x);
                        }
                        else return new eCShaderDefault.GenericSampler(new Color4(y));
                    };
                    eCShaderDefault.GenericSampler d = G(m.DiffuseTexture, m.Diffuse), s = G(m.SpecularTexture, m.Specular), sp = new eCShaderDefault.GenericSampler(new Color4(1, m.SpecularPower, m.SpecularPower, m.SpecularPower)), op = new eCShaderDefault.GenericSampler(new Color4(1));
                    m2 = new XmatWrapper(e, d, d, s, sp);
                    m2.ToFile();
                }
            }

            if (a_ObjColFile == null)
                a_ObjColFile = a_ObjFile;
            EFile t0 = FileManager.GetFile(objn + "._xmsh"), t1 = FileManager.GetFile(objn + "_COL._xcom");
            if(t0.IsOpenable && t1.IsOpenable)
                return;
            EFile e0 = FileManager.CreateNewPhysicalFile(FileManager.NewFileType.StaticModel, objn + "._xmsh"), e1 = FileManager.CreateNewPhysicalFile(FileManager.NewFileType.StaticModel, objn + "_COL._xcom");
            MeshConverter.Convert(a_ObjFile, e0.Path, e1.Path, a_Size.X, a_Size.Y, a_Size.Z);
        }
Beispiel #2
0
        public Material LoadMaterial(EFile _File, API_Device D)
        {
            if (_File.IsOpenable)
            {
                ShaderResourceTexture T = null;
                if (_File.Name == "Nat_Stone_Rock_01_Diffuse_01_Specular._xmat")
                    T = new ShaderResourceTexture("Nat_Stone_Rock_01_Diffuse_01._ximg", D);
                else if (_File.Name == "Special_Water_Swamp_01_Diffuse_01._xmat")
                    T = new ShaderResourceTexture("Special_Water_Caustics_01_Diffuse_01._ximg", D);
                else
                {
                    XmatWrapper W = new XmatWrapper(_File);

                    bCGuid src_Diffuse = (W.Mat.dataObj.Class as eCShaderDefault).ColorSrcDiffuse.Token;
                    bCGuid src_Normal = (W.Mat.dataObj.Class as eCShaderDefault).ColorSrcNormal.Token;
                    bCGuid src_Specular = (W.Mat.dataObj.Class as eCShaderDefault).ColorSrcSpecular.Token;
                    if (src_Diffuse.IsValid)
                    {
                        eCShaderDefault shader = (W.Mat.dataObj.Class as eCShaderDefault);
                        eCShaderEllementBase ellement = shader.GetEllementByGuid(shader.ColorSrcDiffuse.Token);
                        if (ellement is subClassBase)
                            T = (ellement as subClassBase).CreateTexture(D);
                    }
                    if (T == null)
                        T = ShaderResourceTexture.WhiteTexture;
                }
                return new Material(T);
            }
            else
            {
                return new Material("42", true, D);
            }
        }