示例#1
0
        public async Task SetMaterial(XivMtrl mtrl, StainingTemplateFile dyeFile)
        {
            _mtrl           = mtrl;
            DyeTemplateFile = dyeFile;

            _viewport = _view.ColorsetRowViewport;
            _viewport.BackgroundColor = System.Windows.Media.Colors.Gray;
            _viewport.Background      = Brushes.Gray;

            if (_NeedLights)
            {
                _NeedLights = false;
            }

            _viewport.Camera.UpDirection   = new System.Windows.Media.Media3D.Vector3D(0, 1, 0);
            _viewport.Camera.LookDirection = new System.Windows.Media.Media3D.Vector3D(0, 0, -1);
            _viewport.Camera.Position      = new System.Windows.Media.Media3D.Point3D(0, 0, 3);



            if (TileTextureNormal == null)
            {
                var _tex = new Tex(XivCache.GameInfo.GameDirectory);
                TileTextureNormal = await _tex.GetTexData("chara/common/texture/-tile_n.tex");

                TileTextureDiffuse = await _tex.GetTexData("chara/common/texture/-tile_d.tex");
            }
        }
        /// <summary>
        /// The event handler for the add custom texture button clicked
        /// </summary>
        private async void AddCustomTextureButton_Click(object sender, RoutedEventArgs e)
        {
            var selectedItem = TextureMapComboBox.SelectedItem as ModComboBox;

            var mod = selectedItem.SelectedMod;

            byte[] modData;

            var includedMod = new IncludedMods
            {
                Name     = $"{Path.GetFileNameWithoutExtension(mod.fullPath)} ({((Category)ModListTreeView.SelectedItem).Name})",
                FullPath = mod.fullPath
            };

            var includedModsList = IncludedModsList.Items.Cast <IncludedMods>().ToList();

            var tex = new Tex(_gameDirectory);

            var ddsDirectory = new DirectoryInfo(CustomTextureTextBox.Text);

            if (selectedItem.TexTypePath.Type == XivTexType.ColorSet)
            {
                var mtrl = new Mtrl(_gameDirectory, XivDataFiles.GetXivDataFile(mod.datFile), GetLanguage());

                var xivMtrl = await mtrl.GetMtrlData(mod.data.modOffset, mod.fullPath, int.Parse(Settings.Default.DX_Version));

                modData = tex.DDStoMtrlData(xivMtrl, ddsDirectory, ((Category)ModListTreeView.SelectedItem).Item, GetLanguage());
            }
            else
            {
                var texData = await tex.GetTexData(selectedItem.TexTypePath);

                modData = await tex.DDStoTexData(texData, ((Category)ModListTreeView.SelectedItem).Item, ddsDirectory);
            }

            if (includedModsList.Any(item => item.Name.Equals(includedMod.Name)))
            {
                if (FlexibleMessageBox.Show(
                        string.Format(UIMessages.ExistingOption, includedMod.Name),
                        UIMessages.OverwriteTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                    System.Windows.Forms.DialogResult.Yes)
                {
                    _selectedModOption.Mods[mod.fullPath].ModDataBytes = modData;
                }
            }
            else
            {
                IncludedModsList.Items.Add(includedMod);
                _selectedModOption.Mods.Add(mod.fullPath, new ModData
                {
                    Name         = mod.name,
                    Category     = mod.category,
                    FullPath     = mod.fullPath,
                    ModDataBytes = modData
                });
            }
        }
示例#3
0
        /// <summary>
        /// Gets the data for the texture map
        /// </summary>
        /// <returns>The texure map data</returns>
        private TexMapData GetTexMapData()
        {
            var tex = new Tex(_gameDirectory);

            var texMapData = new TexMapData();

            foreach (var texTypePath in _mtrlData.TextureTypePathList)
            {
                if (texTypePath.Type != XivTexType.ColorSet)
                {
                    var texData = tex.GetTexData(texTypePath);

                    var imageData = tex.GetImageData(texData);

                    switch (texTypePath.Type)
                    {
                    case XivTexType.Diffuse:
                        texMapData.Diffuse = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };
                        break;

                    case XivTexType.Specular:
                        texMapData.Specular = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    case XivTexType.Normal:
                        texMapData.Normal = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    case XivTexType.Multi:
                        texMapData.Multi = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    case XivTexType.Skin:
                        texMapData.Skin = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            foreach (var texPath in _mtrlData.TexturePathList)
            {
                if (texPath.Contains("dummy"))
                {
                    texMapData.HasDummyTextures = true;
                    break;
                }
            }

            if (_mtrlData.ColorSetDataSize > 0)
            {
                var colorSetData = new List <byte>();
                foreach (var half in _mtrlData.ColorSetData)
                {
                    var colorByte = (byte)(half * 255);

                    if (half > 1)
                    {
                        colorByte = 255;
                    }

                    colorSetData.Add(colorByte);
                }

                texMapData.ColorSet = new TexInfo {
                    Width = 4, Height = 16, Data = colorSetData.ToArray()
                };;
            }

            return(texMapData);
        }
示例#4
0
        /// <summary>
        /// Retreives the raw pixel data for each texture, collated into a class to hold them.
        /// </summary>
        /// <returns>The texure map data</returns>
        private static async Task <TexMapData> GetTexMapData(Tex tex, XivMtrl mtrl)
        {
            var texMapData = new TexMapData();

            // Use the function that returns proper sane reuslts.
            var ttps = mtrl.GetTextureTypePathList();

            foreach (var ttp in ttps)
            {
                if (ttp.Type != XivTexType.ColorSet)
                {
                    var texData = await tex.GetTexData(ttp);

                    var imageData = await tex.GetImageData(texData);

                    switch (ttp.Type)
                    {
                    case XivTexType.Diffuse:
                        texMapData.Diffuse = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };
                        break;

                    case XivTexType.Specular:
                    case XivTexType.Multi:
                    case XivTexType.Skin:
                        texMapData.Specular = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    case XivTexType.Normal:
                        texMapData.Normal = new TexInfo {
                            Width = texData.Width, Height = texData.Height, Data = imageData
                        };;
                        break;

                    default:
                        // Do not render textures that we do not know how to use
                        break;
                    }
                }
            }

            if (mtrl.ColorSetDataSize > 0)
            {
                var colorSetData = new List <byte>();
                foreach (var half in mtrl.ColorSetData)
                {
                    var colorByte = (byte)(half * 255);

                    if (half > 1)
                    {
                        colorByte = 255;
                    }

                    colorSetData.Add(colorByte);
                }

                texMapData.ColorSet = new TexInfo {
                    Width = 4, Height = 16, Data = colorSetData.ToArray()
                };;
            }

            return(texMapData);
        }