예제 #1
0
        public void ReadTextureParams(byte[] raw)
        {
            int count = BitConverter.ToInt32(raw, 24);
            int pos   = 28;

            for (int i = 0; i < count; i++)
            {
                List <PropertyReader.Property> tp = PropertyReader.ReadProp(pcc, raw, pos);
                string       name = pcc.getNameEntry(tp[1].Value.IntValue);
                int          Idx  = tp[2].Value.IntValue;
                TextureParam t    = new TextureParam();
                t.Desc     = name;
                t.TexIndex = Idx;
                if (name.ToLower().Contains("diffuse") && Idx > 0)
                {
                    Texture2D           tex = new Texture2D(pcc, Idx - 1);
                    string              loc = Path.GetDirectoryName(Application.ExecutablePath);
                    Texture2D.ImageInfo inf = new Texture2D.ImageInfo();
                    for (int j = 0; j < tex.imgList.Count(); j++)
                    {
                        if (tex.imgList[j].storageType != Texture2D.storage.empty)
                        {
                            inf = tex.imgList[j];
                            break;
                        }
                    }
                    if (File.Exists(loc + "\\exec\\TempTex.dds"))
                    {
                        File.Delete(loc + "\\exec\\TempTex.dds");
                    }
                    tex.extractImage(inf, ME3Directory.cookedPath, loc + "\\exec\\TempTex.dds");
                    if (File.Exists(loc + "\\exec\\TempTex.dds"))
                    {
                        try
                        {
                            t.Texture = TextureLoader.FromFile(Meshplorer.Preview3D.device, loc + "\\exec\\TempTex.dds");
                        }
                        catch (Direct3DXException e)
                        {
                        }
                    }
                    else
                    {
                        t.Texture = null;
                    }
                }
                else
                {
                    t.Texture = null;
                }
                Textures.Add(t);
                pos = tp[tp.Count - 1].offend;
            }
        }
 public void ReadTextureParams(byte[] raw)
 {
     int count = BitConverter.ToInt32(raw, 24);            
     int pos = 28;
     for (int i = 0; i < count; i++)
     {
         List<PropertyReader.Property> tp = PropertyReader.ReadProp(pcc, raw, pos);
         string name = pcc.getNameEntry(tp[1].Value.IntValue);
         int Idx = tp[2].Value.IntValue;
         TextureParam t = new TextureParam();
         t.Desc = name;
         t.TexIndex = Idx;
         if (name.ToLower().Contains("diffuse") && Idx >0)
         {
             Texture2D tex = new Texture2D(pcc, Idx - 1);
             string loc = Path.GetDirectoryName(Application.ExecutablePath);
             Texture2D.ImageInfo inf = new Texture2D.ImageInfo();
             for (int j = 0; j < tex.imgList.Count(); j++)
                 if (tex.imgList[j].storageType != Texture2D.storage.empty)
                 {
                     inf = tex.imgList[j];
                     break;
                 }
             if (File.Exists(loc + "\\exec\\TempTex.dds"))
                 File.Delete(loc + "\\exec\\TempTex.dds");
             tex.extractImage(inf, ME3Directory.cookedPath, loc + "\\exec\\TempTex.dds");
             if (File.Exists(loc + "\\exec\\TempTex.dds"))
                 try
                 {
                     t.Texture = TextureLoader.FromFile(Meshplorer.Preview3D.device, loc + "\\exec\\TempTex.dds");
                 }
                 catch (Direct3DXException e)
                 {
                 }
             else
                 t.Texture = null;
         }
         else
             t.Texture = null;
         Textures.Add(t);
         pos = tp[tp.Count -1].offend;
     }
 }
예제 #3
0
 public void GenerateMesh()
 {
     if (Mesh.IdxBuf.Indexes.Count() != 0)
     {
         Meshplorer.Preview3D.RawTriangles = new Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured[Mesh.IdxBuf.Indexes.Count()];
         for (int i = 0; i < Mesh.IdxBuf.Indexes.Count(); i++)
         {
             int idx = Mesh.IdxBuf.Indexes[i];
             Vector3 pos = Mesh.Vertices.Points[idx];
             Vector2 UV = Mesh.Edges.UVSet[idx].UVs[0];
             Meshplorer.Preview3D.RawTriangles[i] = new Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured(pos, UV.X, UV.Y);
         }
     }
     else
     {
         Meshplorer.Preview3D.RawTriangles = new Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured[Mesh.RawTris.RawTriangles.Count() * 3];
         for (int i = 0; i < Mesh.RawTris.RawTriangles.Count(); i++)
         {
             int idx = Mesh.RawTris.RawTriangles[i].v0;
             Vector3 pos = Mesh.Vertices.Points[idx];
             Vector2 UV = Mesh.Edges.UVSet[idx].UVs[0];
             Meshplorer.Preview3D.RawTriangles[i * 3] = new Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured(pos, UV.X, UV.Y);
             idx = Mesh.RawTris.RawTriangles[i].v1;
             pos = Mesh.Vertices.Points[idx];
             UV = Mesh.Edges.UVSet[idx].UVs[0];
             Meshplorer.Preview3D.RawTriangles[i * 3 + 1] = new Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured(pos, UV.X, UV.Y);
             idx = Mesh.RawTris.RawTriangles[i].v2;
             pos = Mesh.Vertices.Points[idx];
             UV = Mesh.Edges.UVSet[idx].UVs[0];
             Meshplorer.Preview3D.RawTriangles[i * 3 + 2] = new Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured(pos, UV.X, UV.Y);
         }
     }
     if (Mesh.Mat.MatInst.Count() != 0)
     {
         MaterialInstanceConstant m = Mesh.Mat.MatInst[0];
         Meshplorer.Preview3D.CurrentTex = null;
         for (int i = 0; i < m.Textures.Count(); i++)
             if (m.Textures[i].Desc.ToLower().Contains("diffuse") && Meshplorer.Preview3D.device != null)
             {
                 Texture2D t = new Texture2D(pcc, m.Textures[i].TexIndex - 1);
                 string loc = Path.GetDirectoryName(Application.ExecutablePath);
                 Texture2D.ImageInfo inf = new Texture2D.ImageInfo();
                 for (int j = 0; j < t.imgList.Count(); j++)
                     if (t.imgList[j].storageType != Texture2D.storage.empty)
                     {
                         inf = t.imgList[j];
                         break;
                     }
                 if (File.Exists(loc + "\\exec\\TempTex.dds"))
                     File.Delete(loc + "\\exec\\TempTex.dds");
                 t.extractImage(inf, ME3Directory.cookedPath, loc + "\\exec\\TempTex.dds");
                 if (File.Exists(loc + "\\exec\\TempTex.dds"))
                 {
                     Texture t2 = TextureLoader.FromFile(Meshplorer.Preview3D.device, loc + "\\exec\\TempTex.dds");
                     Meshplorer.Preview3D.CurrentTex = t2;
                 }
                 break;
             }
     }
 }