Ejemplo n.º 1
0
 private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog open = new OpenFileDialog();
     open.Filter = "Nif Files (*.nif)|*.nif|" + "EGM Files (*.egm)|*.egm|" + "TRI Files (*.tri)|*.tri|" + "All files (*.*)|*.*";
     if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         try
         {
             HeadFile nifFile = new HeadFile(open.FileName);
             this.modifiersStages.Clear();
             this.modifiers.Clear();
             this.modifiersStages.Add(nifFile);
             this.modifierPropertiesPanel.Controls.Clear();
             this.modifiersListView.Items.Clear();
             this.addButton.Enabled = true;
             this.deletebutton.Enabled = true;
             this.moveUpButton.Enabled = true;
             this.moveDownbutton.Enabled = true;
             this.clearButton.Enabled = true;
             this.resetButton.Enabled = true;
             this.targetFileTextBox.Text = open.FileName;
         }
         catch (FileNotFoundException)
         {
             MessageBox.Show("Could not load tri file");
         }
         
     }
 }
Ejemplo n.º 2
0
 public override HeadFile Apply()
 {
     if (this.target == null || this.reference == null)
         return this.target;
     HeadFile ret = new HeadFile(this.target);
     for (int i = 0; i < this.target.TRI.Header.VertexCount; i++)
     {
         ret.TRI.Vertices[i] = this.reference.Vertices[i];
     }
     this.applied = true;
     return ret;
 }
Ejemplo n.º 3
0
 public AddEyeMorph()
 {
     this.menu = new AddEyeMorphControl();
     this.menu.openVertexIndexesButton.Click += new EventHandler(openVertexIndexesButton_Click);
     this.menu.openReferenceFileButton.Click += new EventHandler(openReferenceFileButton_Click);
     this.menu.applyButton.Click += new EventHandler(applyButton_Click);
     this.menu.radioButton1.CheckedChanged += new EventHandler(radioButton1_CheckedChanged);
     this.menu.radioButton2.CheckedChanged += new EventHandler(radioButton2_CheckedChanged);
     this.autodetect = false;
     this.applied = false;
     this.targetFile = null;
     this.referenceFile = null;
 }
Ejemplo n.º 4
0
 public void WriteToFile(string fileName)
 {
     if (fileName.ToLower().EndsWith("egm"))
     {
         FileStream stream = new FileStream(fileName, FileMode.Create);
         this.egm.WriteToFile(stream);
         stream.Close();
         stream = new FileStream(HeadFile.ReplaceExtention(fileName, "tri"), FileMode.Create);
         this.tri.WriteToFile(stream);
         stream.Close();
         stream = new FileStream(HeadFile.ReplaceExtention(fileName, "nif"), FileMode.Create);
         this.nif.WriteToFile(stream);
         stream.Close();
     }
     if (fileName.ToLower().EndsWith("tri"))
     {
         FileStream stream = new FileStream(fileName, FileMode.Create);
         this.tri.WriteToFile(stream);
         stream.Close();
         stream = new FileStream(HeadFile.ReplaceExtention(fileName, "egm"), FileMode.Create);
         this.egm.WriteToFile(stream);
         stream.Close();
         stream = new FileStream(HeadFile.ReplaceExtention(fileName, "nif"), FileMode.Create);
         this.nif.WriteToFile(stream);
         stream.Close();
     }
     if (fileName.ToLower().EndsWith("nif"))
     {
         FileStream stream = new FileStream(fileName, FileMode.Create);
         this.nif.WriteToFile(stream);
         stream.Close();
         stream = new FileStream(HeadFile.ReplaceExtention(fileName, "egm"), FileMode.Create);
         this.egm.WriteToFile(stream);
         stream.Close();
         stream = new FileStream(HeadFile.ReplaceExtention(fileName, "tri"), FileMode.Create);
         this.tri.WriteToFile(stream);
         stream.Close();
     }
 }
Ejemplo n.º 5
0
 public HeadFile(string fileName)
 {
     if (fileName.ToLower().EndsWith("egm"))
     {
         FileStream stream = new FileStream(fileName, FileMode.Open);
         this.egm = new EGMFile(stream);
         stream.Close();
         stream   = new FileStream(HeadFile.ReplaceExtention(fileName, "tri"), FileMode.Open);
         this.tri = new TRIFile(stream);
         stream.Close();
         stream   = new FileStream(HeadFile.ReplaceExtention(fileName, "nif"), FileMode.Open);
         this.nif = new NifFile(stream);
         stream.Close();
     }
     if (fileName.ToLower().EndsWith("tri"))
     {
         FileStream stream = new FileStream(fileName, FileMode.Open);
         this.tri = new TRIFile(stream);
         stream.Close();
         stream   = new FileStream(HeadFile.ReplaceExtention(fileName, "egm"), FileMode.Open);
         this.egm = new EGMFile(stream);
         stream.Close();
         stream   = new FileStream(HeadFile.ReplaceExtention(fileName, "nif"), FileMode.Open);
         this.nif = new NifFile(stream);
         stream.Close();
     }
     if (fileName.ToLower().EndsWith("nif"))
     {
         FileStream stream = new FileStream(fileName, FileMode.Open);
         this.nif = new NifFile(stream);
         stream.Close();
         stream   = new FileStream(HeadFile.ReplaceExtention(fileName, "egm"), FileMode.Open);
         this.egm = new EGMFile(stream);
         stream.Close();
         stream   = new FileStream(HeadFile.ReplaceExtention(fileName, "tri"), FileMode.Open);
         this.tri = new TRIFile(stream);
         stream.Close();
     }
 }
Ejemplo n.º 6
0
 public override HeadFile Apply()
 {
     if (this.target == null)
         return null;
     HeadFile ret = new HeadFile(this.target);
     TRIMorphData targetMorph = null;
     foreach (TRIMorphData morph in ret.TRI.Morphs)
     {
         if(morph.Name.ToLower().StartsWith("vampiremorph"))
         {
             targetMorph = morph;
             break;
         }
     }
     if(targetMorph != null)
     {
         for (int i = 0; i < ret.TRI.Header.VertexCount; i++)
             targetMorph[i] = new VertexDisplacement(0, 0, 0);
         this.applied = true;
         this.menu.appliedLabel.Text = "Applied: True";
     }
     return ret;
 }
Ejemplo n.º 7
0
 void openReferenceFileButton_Click(object sender, EventArgs e)
 {
     OpenFileDialog open = new OpenFileDialog();
     open.Filter = "Nif Files (*.nif)|*.nif|" + "EGM Files (*.egm)|*.egm|" + "TRI Files (*.tri)|*.tri|" + "All files (*.*)|*.*";
     if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         try
         {
             HeadFile nifFile = new HeadFile(open.FileName);
             if (nifFile.TRI.Header.VertexCount == this.targetFile.TRI.Header.VertexCount)
             {
                 this.referenceFile = nifFile;
                 if (this.autodetect == true)
                 {
                     this.AutoDetectVertices();
                 }
             }              
         }
         catch (Exception)
         {
             return;
         }
     }
 }
Ejemplo n.º 8
0
 public abstract HeadFile Apply(HeadFile target);
Ejemplo n.º 9
0
 public override HeadFile Apply()
 {
     if (this.targetFile == null)
     {
         //MessageBox.Show("No target file");
         return this.targetFile;
     }
     if (this.referenceFile == null)
     {
         //MessageBox.Show("No reference file");
         return this.targetFile;
     }
     if (this.vertexIndexes == null || this.vertexIndexes.Count == 0)
     {
         //MessageBox.Show("No vertex indexes");
         return this.targetFile;
     }
     HeadFile ret = new HeadFile(this.targetFile);
     ret.EGM.Append(this.vertexIndexes, this.referenceFile.EGM);
     StringBuilder bld = new StringBuilder(this.menu.nameTextBox.Text);
     bld.Append("\0");
     this.modifierName = bld.ToString();
     ret.TRI.AppendModifier(this.vertexIndexes, this.referenceFile.TRI, bld.ToString());
     this.applied = true;
     return ret;
 }
Ejemplo n.º 10
0
 public HeadFile(HeadFile file)
 {
     this.tri = new TRIFile(file.TRI);
     this.egm = new EGMFile(file.EGM);
     this.nif = new NifFile(file.Nif);
 }
        private HeadFile ApplyAbsolute()
        {
            Dictionary<Expression, List<Triple<double, double, double>>> offsets = new Dictionary<Expression, List<Triple<double, double, double>>>();
            foreach (KeyValuePair<Expression, MeshBase> expression in this.expressions)
            {
                offsets.Add(expression.Key, this.CalculateOffsets(this.target.TRI.Vertices, expression.Value.Vertices));
            }
            Dictionary<Morph, List<VertexPosition>> unmorphs = new Dictionary<Morph, List<VertexPosition>>();
            for (int i = 0; i < 4; i++)
            {
                Morph morph = (Morph)i;
                List<Triple<double, double, double>> unmorph = new List<Triple<double, double, double>>();
                for (int j = 0; j < this.target.TRI.Header.VertexCount; j++)
                {
                    unmorph.Add(new Triple<double, double, double>());
                }
                foreach (KeyValuePair<Expression, Dictionary<Morph, double>> weight in this.weights)
                {
                    if (weight.Value.ContainsKey(morph))
                    {
                        List<Triple<double, double, double>> mlist = offsets[weight.Key];
                        double w = weight.Value[morph];
                        for (int k = 0; k < mlist.Count; k++)
                        {
                            Triple<double, double, double> aux = unmorph[k];
                            aux.X = aux.X + w * (double)(mlist[k].X);
                            aux.Y = aux.Y + w * (double)(mlist[k].Y);
                            aux.Z = aux.Z + w * (double)(mlist[k].Z);
                            unmorph[k] = aux;
                        }
                    }
                }
                List<VertexPosition> unmorph2 = new List<VertexPosition>();
                for (int j = 0; j < unmorph.Count; j++)
                {
                    Triple<double, double, double> aux = unmorph[j];
                    VertexPosition pos = new VertexPosition();
                    pos.X = this.target.TRI.Vertices[j].X - (float)(aux.X / 100d);
                    pos.Y = this.target.TRI.Vertices[j].Y - (float)(aux.Y / 100d);
                    pos.Z = this.target.TRI.Vertices[j].Z - (float)(aux.Z / 100d);
                    unmorph2.Add(pos);
                }

                unmorphs.Add(morph, unmorph2);
            }
            Dictionary<Morph, List<VertexDisplacement>> displacements = new Dictionary<Morph, List<VertexDisplacement>>();
            for (int i = 0; i < 4; i++)
            {
                Morph morph = (Morph)i;
                displacements.Add(morph, this.CalculateDisplacements(this.target.TRI.Vertices, unmorphs[morph], this.ignoreList, this.accuracy));
            }
            HeadFile ret = new HeadFile(this.target);
            try
            {
                foreach (KeyValuePair<Morph, List<VertexDisplacement>> keypair in displacements)
                {
                    foreach (TRIMorphData morph in ret.TRI.Morphs)
                    {
                        if (morph.Name.ToLower().StartsWith(keypair.Key.ToString().ToLower()))
                        {
                            for (int i = 0; i < ret.TRI.Header.VertexCount; i++)
                                morph[i] = keypair.Value[i];
                        }
                    }
                }
            }
            catch (Exception)
            {
                return this.target;
            }
            this.applied = true;
            return ret;
        }
Ejemplo n.º 12
0
 public override HeadFile Apply(HeadFile target)
 {
     throw new NotImplementedException();
 }
 private HeadFile ApplyRelative()
 {
     Dictionary<Expression, List<VertexDisplacement>> displacements = new Dictionary<Expression, List<VertexDisplacement>>();
     for (int j = 0; j < 5; j++)
     {
         Expression exp = (Expression)j;
         displacements.Add(exp, this.CalculateDisplacements(this.target.TRI.Vertices, this.expressions[exp].Vertices, this.ignoreList, this.accuracy));
     }
     Dictionary<Morph, List<Triple<double, double, double>>> unmorphs = new Dictionary<Morph, List<Triple<double, double, double>>>();
     for (int i = 0; i < 4; i++)
     {
         Morph morph = (Morph)i;
         List<Triple<double, double, double>> unmorph = new List<Triple<double, double, double>>();
         for (int j = 0; j < this.target.TRI.Header.VertexCount; j++)
         {
             unmorph.Add(new Triple<double, double, double>());
         }
         foreach (KeyValuePair<Expression, Dictionary<Morph, double>> weight in this.weights)
         {
             if (weight.Value.ContainsKey(morph))
             {
                 List<VertexDisplacement> mlist = displacements[weight.Key];
                 double w = weight.Value[morph];
                 for (int k = 0; k < mlist.Count; k++)
                 {
                     Triple<double, double, double> aux = unmorph[k];
                     aux.X = aux.X + w * (double)(mlist[k].X);
                     aux.Y = aux.Y + w * (double)(mlist[k].Y);
                     aux.Z = aux.Z + w * (double)(mlist[k].Z);
                     unmorph[k] = aux;
                 }
             }
         }
         for (int j = 0; j < unmorph.Count; j++)
         {
             Triple<double, double, double> aux = unmorph[j];
             aux.X = aux.X / 100d;
             aux.Y = aux.Y / 100d;
             aux.Z = aux.Z / 100d;
             unmorph[j] = aux;
         }
         unmorphs.Add(morph, unmorph);
     }
     Dictionary<Morph, List<VertexDisplacement>> morphs = new Dictionary<Morph, List<VertexDisplacement>>();
     foreach (KeyValuePair<Morph, List<Triple<double, double, double>>> keypair in unmorphs)
     {
         double totalscale = 0;
         foreach (KeyValuePair<Expression, Dictionary<Morph, double>> weight in this.weights)
         {
             if (weight.Value.ContainsKey(keypair.Key))
                 totalscale += weight.Value[keypair.Key];
         }
         if (totalscale > 100)
         {
             List<VertexDisplacement> morph = new List<VertexDisplacement>();
             double max = 100 / totalscale;
             for (int i = 0; i < keypair.Value.Count; i++)
             {
                 Triple<double, double, double> triple = keypair.Value[i];
                 morph.Add(new VertexDisplacement((short)(Math.Min(triple.X * max, short.MaxValue)), (short)(Math.Min(triple.Y * max, short.MaxValue)), (short)(Math.Min(triple.Z * max, short.MaxValue))));
             }
             morphs.Add(keypair.Key, morph);
         }
         else
         {
             List<VertexDisplacement> morph = new List<VertexDisplacement>();
             for (int i = 0; i < keypair.Value.Count; i++)
             {
                 Triple<double, double, double> triple = keypair.Value[i];
                 morph.Add(new VertexDisplacement((short)(triple.X), (short)(triple.Y), (short)(triple.Z)));
             }
             morphs.Add(keypair.Key, morph);
         }
     }
     HeadFile ret = new HeadFile(this.target);
     try
     {
         foreach (KeyValuePair<Morph, List<VertexDisplacement>> keypair in morphs)
         {
             List<VertexDisplacement> morph2 = keypair.Value;
             foreach (TRIMorphData morph in ret.TRI.Morphs)
             {
                 if (morph.Name.ToLower().StartsWith(keypair.Key.ToString().ToLower()))
                 {
                     for (int i = 0; i < ret.TRI.Header.VertexCount; i++)
                     {
                         morph[i] = morph2[i];
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
         return this.target;
     }
     this.applied = true;
     return ret;
 }
Ejemplo n.º 14
0
       public override HeadFile Apply()
       {
           if (this.reference == null || this.targetMorph == null)
               return this.target;
           if(this.reference.Vertices.Count != this.target.TRI.Header.VertexCount)
               return this.target;
           if(!(this.targetMorph.StartsWith("SYM") || this.targetMorph.StartsWith("ASYM")))
               return this.target;
           List<VertexDisplacement> morphList = this.CalculateDisplacements(this.target.TRI.Vertices, this.reference.Vertices, this.ignoreList, this.accuracy);
           HeadFile ret = new HeadFile(this.target);
           try
           {
               int number = int.Parse(this.targetMorph.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)[1]);
               if (this.targetMorph.StartsWith("SYM"))
               {
                   for (int i = 0; i < ret.TRI.Header.VertexCount; i++)
                       ret.EGM.SymMorps[number][i] = morphList[i];
                   //ret.EGM.SymMorps[number].Unknown = BitConverter.GetBytes(((float)(scale))).Reverse<byte>().ToArray<byte>();
               }
               if (this.targetMorph.StartsWith("ASYM"))
               {
                   for (int i = 0; i < ret.TRI.Header.VertexCount; i++)
                       ret.EGM.AsymMorps[number][i] = morphList[i];
                   //ret.EGM.AsymMorps[number].Unknown = BitConverter.GetBytes(((float)(scale))).Reverse<byte>().ToArray<byte>();
               }
               this.applied = true;
           }
           catch (Exception)
           {
 
           }
           return ret;
       }
Ejemplo n.º 15
0
 public override HeadFile Apply()
 {
     if (this.reference == null || this.targetExpression == null)
         return this.target;
     if (this.reference.Vertices.Count != this.target.TRI.Header.VertexCount)
         return this.target;
     if (this.targetExpression.Length < 1)
         return this.target;
     List<VertexDisplacement> morphList = this.CalculateDisplacements(this.target.TRI.Vertices, this.reference.Vertices, this.ignoreList, this.accuracy);
     HeadFile ret = new HeadFile(this.target);
     try
     {
         foreach (TRIMorphData morph in ret.TRI.Morphs)
         {
             if(morph.Name.StartsWith(this.targetExpression))
             {
                 for(int i = 0;i < ret.TRI.Header.VertexCount; i++)
                     morph[i] = morphList[i];
                 break;
             }
         }
     }
     catch (Exception)
     {
         return this.target;
     }
     this.applied = true;
     return ret;
 }
Ejemplo n.º 16
0
 public HeadFile(HeadFile file)
 {
     this.tri = new TRIFile(file.TRI);
     this.egm = new EGMFile(file.EGM);
     this.nif = new NifFile(file.Nif);
 }
Ejemplo n.º 17
0
 public abstract HeadFile Apply(HeadFile target);