Example #1
0
 /// <summary>
 /// Disposes of the view model data
 /// </summary>
 public void Dispose()
 {
     if (CompositeVM != null)
     {
         CompositeVM.Dispose();
     }
 }
Example #2
0
        /// <summary>
        /// Sets the data for the mesh combo box
        /// </summary>
        private void PartComboBoxChanged()
        {
            is3DLoaded = false;

            if (CompositeVM != null && !disposing)
            {
                disposing = true;
                CompositeVM.Dispose();
            }


            try
            {
                List <ComboBoxInfo> cbi = new List <ComboBoxInfo>();

                MDL mdl = new MDL(selectedItem, selectedCategory, Info.raceID[SelectedRace.Name], SelectedBody.ID, SelectedPart.ID);
                meshList        = mdl.GetMeshList();
                modelName       = mdl.GetModelName();
                materialStrings = mdl.GetMaterialStrings();

                cbi.Add(new ComboBoxInfo()
                {
                    Name = Strings.All, ID = Strings.All, IsNum = false
                });

                if (meshList.Count > 1)
                {
                    for (int i = 0; i < meshList.Count; i++)
                    {
                        cbi.Add(new ComboBoxInfo()
                        {
                            Name = i.ToString(), ID = i.ToString(), IsNum = true
                        });
                    }
                }

                MeshComboBox = new ObservableCollection <ComboBoxInfo>(cbi);
                MeshIndex    = 0;

                if (cbi.Count > 1)
                {
                    MeshEnabled = true;
                }
                else
                {
                    MeshEnabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("[Main] part 3D Error \n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #3
0
        /// <summary>
        /// Sets the reflectivity(Specular Shininess) of the model
        /// </summary>
        /// <param name="obj"></param>
        private void SetReflection(object obj)
        {
            CompositeVM.Reflections(selectedItem.ItemName);

            if (selectedItem.ItemName.Equals(Strings.Face) || selectedItem.ItemName.Equals(Strings.Face))
            {
                ReflectionAmount = String.Format("{0:0.##}", CompositeVM.ModelMaterial.SpecularShininess);
            }
            else
            {
                ReflectionAmount = String.Format("{0:0.##}", CompositeVM.SecondModelMaterial.SpecularShininess);
            }
        }
Example #4
0
        /// <summary>
        /// Gets the model data and sets the display viewmodel
        /// </summary>
        private void MeshComboBoxChanged()
        {
            if (!is3DLoaded)
            {
                disposing = false;

                meshData = new List <MDLTEXData>();

                for (int i = 0; i < meshList.Count; i++)
                {
                    BitmapSource specularBMP = null;
                    BitmapSource diffuseBMP  = null;
                    BitmapSource normalBMP   = null;
                    BitmapSource colorBMP    = null;
                    BitmapSource alphaBMP    = null;
                    BitmapSource maskBMP     = null;

                    TEXData specularData = null;
                    TEXData diffuseData  = null;
                    TEXData normalData   = null;
                    TEXData maskData     = null;

                    bool isBody = false;
                    bool isFace = false;

                    MTRLData mtrlData = MTRL3D(i);

                    if (selectedCategory.Equals(Strings.Character))
                    {
                        if (selectedItem.ItemName.Equals(Strings.Tail) || selectedItem.ItemName.Equals(Strings.Hair))
                        {
                            normalData   = TEX.GetTex(mtrlData.NormalOffset);
                            specularData = TEX.GetTex(mtrlData.SpecularOffset);

                            if (mtrlData.DiffusePath != null)
                            {
                                diffuseData = TEX.GetTex(mtrlData.DiffuseOffset);
                            }

                            var maps = TexHelper.MakeCharacterMaps(normalData, diffuseData, null, specularData);

                            diffuseBMP  = maps[0];
                            specularBMP = maps[1];
                            normalBMP   = maps[2];
                            alphaBMP    = maps[3];

                            specularData.Dispose();
                            normalData.Dispose();
                            if (diffuseData != null)
                            {
                                diffuseData.Dispose();
                            }
                        }

                        if (selectedItem.ItemName.Equals(Strings.Body))
                        {
                            normalData = TEX.GetTex(mtrlData.NormalOffset);
                            //specularTI = TEX.GetTex(mInfo.SpecularOffset);
                            diffuseData = TEX.GetTex(mtrlData.DiffuseOffset);

                            isBody     = true;
                            diffuseBMP = Imaging.CreateBitmapSourceFromHBitmap(diffuseData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                            normalBMP  = Imaging.CreateBitmapSourceFromHBitmap(normalData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        }

                        if (selectedItem.ItemName.Equals(Strings.Face))
                        {
                            normalData = TEX.GetTex(mtrlData.NormalOffset);

                            if (materialStrings[i].Contains("_fac_"))
                            {
                                specularData = TEX.GetTex(mtrlData.SpecularOffset);
                                diffuseData  = TEX.GetTex(mtrlData.DiffuseOffset);

                                var maps = TexHelper.MakeCharacterMaps(normalData, diffuseData, null, specularData);

                                diffuseBMP  = maps[0];
                                specularBMP = maps[1];
                                normalBMP   = maps[2];
                                alphaBMP    = maps[3];
                                isFace      = true;

                                specularData.Dispose();
                                diffuseData.Dispose();
                            }
                            else
                            {
                                specularData = TEX.GetTex(mtrlData.SpecularOffset);
                                var maps = TexHelper.MakeCharacterMaps(normalData, diffuseData, null, specularData);

                                diffuseBMP  = maps[0];
                                specularBMP = maps[1];
                                normalBMP   = maps[2];
                                alphaBMP    = maps[3];
                            }
                        }
                    }
                    else
                    {
                        if (mtrlData.ColorData != null)
                        {
                            var colorBmp = TEX.TextureToBitmap(mtrlData.ColorData, 9312, 4, 16);
                            colorBMP = Imaging.CreateBitmapSourceFromHBitmap(colorBmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        }

                        if (mtrlData.NormalOffset != 0)
                        {
                            normalData = TEX.GetTex(mtrlData.NormalOffset);
                        }

                        if (mtrlData.MaskOffset != 0)
                        {
                            maskData = TEX.GetTex(mtrlData.MaskOffset);
                            maskBMP  = Imaging.CreateBitmapSourceFromHBitmap(maskData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        }

                        if (mtrlData.DiffuseOffset != 0)
                        {
                            diffuseData = TEX.GetTex(mtrlData.DiffuseOffset);
                            if (mtrlData.DiffusePath.Contains("human") && !mtrlData.DiffusePath.Contains("demi"))
                            {
                                isBody     = true;
                                diffuseBMP = Imaging.CreateBitmapSourceFromHBitmap(diffuseData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                                normalBMP  = Imaging.CreateBitmapSourceFromHBitmap(normalData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                            }
                        }

                        if (mtrlData.SpecularOffset != 0)
                        {
                            specularData = TEX.GetTex(mtrlData.SpecularOffset);
                            specularBMP  = Imaging.CreateBitmapSourceFromHBitmap(specularData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        }

                        if (!isBody && specularData == null)
                        {
                            var maps = TexHelper.MakeModelTextureMaps(normalData, diffuseData, maskData, null, colorBMP);
                            diffuseBMP  = maps[0];
                            specularBMP = maps[1];
                            normalBMP   = maps[2];
                            alphaBMP    = maps[3];
                        }
                        else if (!isBody && specularData != null)
                        {
                            var maps = TexHelper.MakeModelTextureMaps(normalData, diffuseData, null, specularData, colorBMP);
                            diffuseBMP  = maps[0];
                            specularBMP = maps[1];
                            normalBMP   = maps[2];
                            alphaBMP    = maps[3];
                        }

                        if (normalData != null)
                        {
                            normalData.Dispose();
                        }

                        if (maskData != null)
                        {
                            maskData.Dispose();
                        }

                        if (diffuseData != null)
                        {
                            diffuseData.Dispose();
                        }

                        if (specularData != null)
                        {
                            specularData.Dispose();
                        }
                    }

                    var mData = new MDLTEXData()
                    {
                        Specular   = specularBMP,
                        ColorTable = colorBMP,
                        Diffuse    = diffuseBMP,
                        Normal     = normalBMP,
                        Alpha      = alphaBMP,
                        Mask       = maskBMP,

                        IsBody = isBody,
                        IsFace = isFace,

                        Mesh = meshList[i]
                    };

                    meshData.Add(mData);
                }

                CompositeVM = new Composite3DViewModel(meshData);

                is3DLoaded = true;

                ReflectionAmount = String.Format("{0:.##}", CompositeVM.SecondModelMaterial.SpecularShininess);

                try
                {
                }
                catch (Exception ex)
                {
                    MessageBox.Show("[Main] mesh 3D Error \n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                CompositeVM.Rendering(SelectedMesh.Name);
            }
        }
Example #5
0
        /// <summary>
        /// Sets the data for the part combo box
        /// </summary>
        private void BodyComboBoxChanged()
        {
            is3DLoaded = false;
            bool isDemiHuman = false;

            if (CompositeVM != null && !disposing)
            {
                disposing = true;
                CompositeVM.Dispose();
            }

            if (selectedItem.PrimaryMTRLFolder != null && selectedItem.PrimaryMTRLFolder.Contains("demihuman"))
            {
                isDemiHuman = true;
            }

            List <ComboBoxInfo> cbi = new List <ComboBoxInfo>();
            string type             = Helper.GetCategoryType(selectedCategory);

            string MDLFolder = "";
            string MDLFile   = "";

            string[] abrParts = null;

            if (type.Equals("character"))
            {
                if (selectedItem.ItemName.Equals(Strings.Body))
                {
                    MDLFolder = string.Format(Strings.BodyMDLFolder, SelectedRace.ID, SelectedBody.ID.PadLeft(4, '0'));
                    MDLFile   = string.Format(Strings.BodyMDLFile, SelectedRace.ID, SelectedBody.ID.PadLeft(4, '0'), "{0}");

                    abrParts = new string[5] {
                        "met", "glv", "dwn", "sho", "top"
                    };
                }
                else if (selectedItem.ItemName.Equals(Strings.Face))
                {
                    MDLFolder = string.Format(Strings.FaceMDLFolder, SelectedRace.ID, SelectedBody.ID.PadLeft(4, '0'));
                    MDLFile   = string.Format(Strings.FaceMDLFile, SelectedRace.ID, SelectedBody.ID.PadLeft(4, '0'), "{0}");

                    abrParts = new string[3] {
                        "fac", "iri", "etc"
                    };
                }
                else if (selectedItem.ItemName.Equals(Strings.Hair))
                {
                    MDLFolder = string.Format(Strings.HairMDLFolder, SelectedRace.ID, SelectedBody.ID.PadLeft(4, '0'));
                    MDLFile   = string.Format(Strings.HairMDLFile, SelectedRace.ID, SelectedBody.ID.PadLeft(4, '0'), "{0}");

                    abrParts = new string[2] {
                        "hir", "acc"
                    };
                }
                else if (selectedItem.ItemName.Equals(Strings.Tail))
                {
                    MDLFolder = string.Format(Strings.TailMDLFolder, SelectedRace.ID, SelectedBody.ID.PadLeft(4, '0'));
                    MDLFile   = string.Format(Strings.TailMDLFile, SelectedRace.ID, SelectedBody.ID.PadLeft(4, '0'), "{0}");

                    abrParts = new string[1] {
                        "til"
                    };
                }

                var fileHashList = Helper.GetAllFilesInFolder(FFCRC.GetHash(MDLFolder));

                foreach (string abrPart in abrParts)
                {
                    var file = String.Format(MDLFile, abrPart);

                    if (fileHashList.Contains(FFCRC.GetHash(file)))
                    {
                        if (selectedItem.ItemName.Equals(Strings.Body))
                        {
                            cbi.Add(new ComboBoxInfo()
                            {
                                Name = Info.slotAbr.FirstOrDefault(x => x.Value == abrPart).Key, ID = abrPart, IsNum = false
                            });
                        }
                        else if (selectedItem.ItemName.Equals(Strings.Face))
                        {
                            cbi.Add(new ComboBoxInfo()
                            {
                                Name = Info.FaceTypes.FirstOrDefault(x => x.Value == abrPart).Key, ID = abrPart, IsNum = false
                            });
                        }
                        else if (selectedItem.ItemName.Equals(Strings.Hair))
                        {
                            cbi.Add(new ComboBoxInfo()
                            {
                                Name = Info.HairTypes.FirstOrDefault(x => x.Value == abrPart).Key, ID = abrPart, IsNum = false
                            });
                        }
                        else if (selectedItem.ItemName.Equals(Strings.Tail))
                        {
                            cbi.Add(new ComboBoxInfo()
                            {
                                Name = Strings.Tail, ID = abrPart, IsNum = false
                            });
                        }
                    }
                }
            }
            else if (isDemiHuman)
            {
                MDLFolder = string.Format(Strings.DemiMDLFolder, selectedItem.PrimaryModelID, selectedItem.PrimaryModelBody);
                MDLFile   = string.Format(Strings.DemiMDLFile, selectedItem.PrimaryModelID, selectedItem.PrimaryModelBody, "{0}");

                abrParts = new string[5] {
                    "met", "glv", "dwn", "sho", "top"
                };

                var fileHashList = Helper.GetAllFilesInFolder(FFCRC.GetHash(MDLFolder));

                foreach (string abrPart in abrParts)
                {
                    var file = String.Format(MDLFile, abrPart);

                    if (fileHashList.Contains(FFCRC.GetHash(file)))
                    {
                        cbi.Add(new ComboBoxInfo()
                        {
                            Name = Info.slotAbr.FirstOrDefault(x => x.Value == abrPart).Key, ID = abrPart, IsNum = false
                        });
                    }
                }
            }
            else if (type.Equals("weapon"))
            {
                if (selectedItem.SecondaryModelID != null)
                {
                    cbi.Add(new ComboBoxInfo()
                    {
                        Name = "Primary", ID = "Primary", IsNum = false
                    });
                    cbi.Add(new ComboBoxInfo()
                    {
                        Name = "Secondary", ID = "Secondary", IsNum = false
                    });
                }
                else
                {
                    cbi.Add(new ComboBoxInfo()
                    {
                        Name = "Primary", ID = "Primary", IsNum = false
                    });
                }
            }
            else if (type.Equals("monster"))
            {
                cbi.Add(new ComboBoxInfo()
                {
                    Name = "1", ID = "1", IsNum = false
                });
            }
            else
            {
                cbi.Add(new ComboBoxInfo()
                {
                    Name = "-", ID = "-", IsNum = false
                });
            }

            PartComboBox = new ObservableCollection <ComboBoxInfo>(cbi);
            PartIndex    = 0;

            if (cbi.Count <= 1)
            {
                PartEnabled = false;
            }
            else
            {
                PartEnabled = true;
            }
        }
Example #6
0
        /// <summary>
        /// Sets the data for the body combo box
        /// </summary>
        private void RaceComboBoxChanged()
        {
            is3DLoaded = false;

            if (CompositeVM != null && !disposing)
            {
                disposing = true;
                CompositeVM.Dispose();
            }

            List <ComboBoxInfo> cbi = new List <ComboBoxInfo>();
            string categoryType     = Helper.GetCategoryType(selectedCategory);
            string MDLFolder        = "";

            if (categoryType.Equals("weapon"))
            {
                cbi.Add(new ComboBoxInfo()
                {
                    Name = selectedItem.PrimaryModelBody, ID = selectedItem.PrimaryModelBody, IsNum = false
                });
            }
            else if (categoryType.Equals("food"))
            {
                cbi.Add(new ComboBoxInfo()
                {
                    Name = selectedItem.PrimaryModelBody, ID = selectedItem.PrimaryModelBody, IsNum = false
                });
            }
            else if (categoryType.Equals("accessory"))
            {
                cbi.Add(new ComboBoxInfo()
                {
                    Name = "-", ID = "-", IsNum = false
                });
            }
            else if (categoryType.Equals("character"))
            {
                if (selectedItem.ItemName.Equals(Strings.Body))
                {
                    MDLFolder = string.Format(Strings.BodyMDLFolder, SelectedRace.ID, "{0}");
                }
                else if (selectedItem.ItemName.Equals(Strings.Face))
                {
                    MDLFolder = string.Format(Strings.FaceMDLFolder, SelectedRace.ID, "{0}");
                }
                else if (selectedItem.ItemName.Equals(Strings.Hair))
                {
                    MDLFolder = string.Format(Strings.HairMDLFolder, SelectedRace.ID, "{0}");
                }
                else if (selectedItem.ItemName.Equals(Strings.Tail))
                {
                    MDLFolder = string.Format(Strings.TailMDLFolder, SelectedRace.ID, "{0}");
                }
            }
            else if (categoryType.Equals("monster"))
            {
                cbi.Add(new ComboBoxInfo()
                {
                    Name = selectedItem.PrimaryModelBody, ID = selectedItem.PrimaryModelBody, IsNum = false
                });
            }
            else
            {
                cbi.Add(new ComboBoxInfo()
                {
                    Name = "-", ID = "-", IsNum = false
                });
            }


            if (categoryType.Equals("character"))
            {
                for (int i = 0; i < 50; i++)
                {
                    string folder = String.Format(MDLFolder, i.ToString().PadLeft(4, '0'));

                    if (Helper.FolderExists(FFCRC.GetHash(folder)))
                    {
                        cbi.Add(new ComboBoxInfo()
                        {
                            Name = i.ToString(), ID = i.ToString(), IsNum = true
                        });

                        if (selectedItem.ItemName.Equals(Strings.Body))
                        {
                            break;
                        }
                    }
                }
            }

            BodyComboBox = new ObservableCollection <ComboBoxInfo>(cbi);
            BodyIndex    = 0;

            if (cbi.Count <= 1)
            {
                BodyEnabled = false;
            }
            else
            {
                BodyEnabled = true;
            }
        }
Example #7
0
 /// <summary>
 /// Sets the lighting of the scene
 /// </summary>
 /// <param name="obj"></param>
 private void SetLighting(object obj)
 {
     CompositeVM.Lighting();
 }
Example #8
0
 /// <summary>
 /// Sets the transparency of the model
 /// </summary>
 /// <param name="obj"></param>
 private void SetTransparency(object obj)
 {
     CompositeVM.Transparency();
 }