Esempio n. 1
0
 public static ModelLoadResult LoadModels(PAKFile file)
 {
     var ret = new ModelLoadResult();
     foreach (var gi in file.FileGroups.Select((g, i) => new {g, i}))
     {
         foreach (var entry in gi.g.Entries)
         {
             string name = gi.i + "_" + entry.OBJ.Name;
             try
             {
                 Model m = LoadModel(file, entry.OBJ);
                 ret.Models.Add(new Tuple<string, Model>(name, m));
             }
             catch (Exception e)
             {
                 ret.Messages.Add("! "+name+": "+e.Message);
             }
         }
     }
     return ret;
 }
Esempio n. 2
0
        public static Model LoadModel(PAKFile file, PAKOBJ obj)
        {
            Model mdl = new Model();

            Func<FaceData, int> offConv = f =>
            {
                int idx = f.ImageOffset/ImageData.RecordSize;
                return 2*idx + (obj.Images[idx].MaybeTransparent ? 1 : 0);
            };

            var faceGroups = obj.Faces.GroupBy(offConv).ToList();
            foreach (var faceGroup in faceGroups)
            {
                var imageIdx = faceGroup.First().ImageOffset/ImageData.RecordSize;
                var image = obj.Images[imageIdx];
                var texture = file.Textures.Single(t => t.Name.EqualsCI(image.ImageName));
                Mesh m = new Mesh();
                m.Material = new Material
                {
                    Transparent = image.MaybeTransparent,
                    TextureName = texture.Name,
                };
                mdl.Textures[m.Material.TextureName] = texture.Image;
                foreach (var face in faceGroup)
                {
                    Face f = new Face();
                    f.Vertices[0] = GetVertex(obj, face.Vertex1Offset, face.Normal1Offset);
                    f.Vertices[1] = GetVertex(obj, face.Vertex2Offset, face.Normal2Offset);
                    f.Vertices[2] = GetVertex(obj, face.Vertex3Offset, face.Normal3Offset);
                    m.Faces.Add(f);
                }
                mdl.Meshes.Add(m);
                mdl.Instances.Add(new MeshInstance
                {
                    MeshIndex = mdl.Meshes.Count - 1,
                    Transform = Matrix3D.Identity
                });
            }
            return mdl;
        }
Esempio n. 3
0
 public static ModelLoadResult LoadModels(IFileAccess access, string name)
 {
     var pak = new PAKFile(access.GetContent(name));
     return LoadModels(pak);
 }
Esempio n. 4
0
 public override void LoadChildren()
 {
     Nodes.Clear();
     try
     {
         PAKFile f = new PAKFile(Content);
         var result = PAKLoader.LoadModels(f);
         foreach (var tuple in result.Models)
         {
             string subgroupName = tuple.Item1;
             Nodes.Add(new ModelTreeNode(subgroupName, ModelFetcher(subgroupName)));
         }
         foreach (var msg in result.Messages)
         {
             Nodes.Add(msg);
             if (!this.Text.EndsWith("!"))
                 this.Text = this.Text + " !";
         }
     }
     catch (Exception e)
     {
         Nodes.Add("!!! " + e.Message);
     }
 }
Esempio n. 5
0
 private Func<Model> ModelFetcher(string sub)
 {
     //I feel like I've done too much javascript when this is a solution...
     return () => {
         PAKFile f = new PAKFile(Content);
         var result = PAKLoader.LoadModels(f);
         return result.Models.FirstOrDefault(t=>t.Item1 == sub).Item2;
     };
 }