예제 #1
0
        /// <summary>
        /// Creates an XElement suitable for seralizing it in a apx file.
        /// </summary>
        /// <param name="objectcount"></param>
        /// <returns></returns>
        public XElement serialize(CR2WChunk apexChunk, int objectcount)
        {
            var HairWorksInfo = NvidiaXML.CreateStructHeader("", "Ref", "HairWorksInfo", "1.0", checksum);
            var values        = new XElement("struct", new XAttribute("name", ""));

            values.AddNvValue("fileVersion", "String", "1.0");
            values.AddNvValue("toolVersion", "String", "WolvenKit");
            values.AddNvValue("sourcePath", "String", apexChunk.GetVariableByName("importFile").ToString());
            values.AddNvValue("authorName", "String", Environment.UserName);
            values.AddNvValue("lastModified", "String", ((CDateTime)apexChunk.GetVariableByName("importFileTimeStamp")).Date.ToString("f"));
            HairWorksInfo.Add(values);
            return(HairWorksInfo);
        }
예제 #2
0
        public void ParseImageAndPreview(CR2WChunk chunk)
        {
            var image = chunk.GetVariableByName("image").ToString();

            if (!string.IsNullOrEmpty(image))
            {
                try
                {
                    var files = MainController.Get().ImportFile(image, MainController.Get().TextureManager);
                    entityImage.Image = new DdsImage(files[0]).BitmapImage;
                    entimgbox.Image   = new DdsImage(files[1]).BitmapImage;
                }
                catch (Exception ex)
                {
                }
            }
        }
예제 #3
0
        private void createEditor(int depth, CR2WChunk c)
        {
            try {
                if (ChunkEditors.ContainsKey(c))
                {
                    return;
                }

                var editor = GetEditor(c);
                editor.Chunk            = c;
                editor.OnSelectChunk   += editor_OnSelectChunk;
                editor.OnManualMove    += editor_OnMove;
                editor.LocationChanged += editor_LocationChanged;
                editor.OriginalSize     = editor.Size;
                Controls.Add(editor);
                ChunkEditors.Add(c, editor);

                if (depth > maxdepth)
                {
                    maxdepth = depth;
                }

                if (!EditorLayout.ContainsKey(depth))
                {
                    EditorLayout.Add(depth, new List <ChunkEditor>());
                }

                EditorLayout[depth].Add(editor);

                var conns = editor.GetConnections();
                if (conns != null)
                {
                    foreach (var conn in conns)
                    {
                        if (conn.PtrTarget != null)
                        {
                            createEditor(depth + 1, conn.PtrTarget);
                        }
                    }
                }
            }
            catch (Exception e) {
                OnOutput.Invoke(this, e.ToString());
            }
        }
        public XElement serialize(CR2WChunk chunk)
        {
            var ret = NvidiaXML.CreateStructHeader("", "Ref", "HairInstanceDescriptor", "1.0", checksum);
            var materialcontainer = new XElement("struct", new XAttribute("name", ""));

            var materialcount = new List <CArray>(); //TODO: Get the actual mats
            var structs       = new List <XElement>();

            foreach (var mat in materialcount)
            {
                var structelem = new XElement("struct");
                //TODO: Write the actual values!

                structs.Add(structelem);
            }
            materialcontainer.AddNvArray("materials", "Struct", structs.Count.ToString(), structs);
            ret.Add(materialcontainer);
            return(ret);
        }
예제 #5
0
        private string GetDisplayString(CR2WChunk c)
        {
            var str = string.Empty;

            if (c != null)
            {
                var speaker = c.GetVariableByName("voicetag");
                if (speaker != null && speaker is CName)
                {
                    str += ((CName)speaker).Value + ": ";
                }

                var line = c.GetVariableByName("dialogLine");
                if (line != null && line is CLocalizedString)
                {
                    str += ((CLocalizedString)line).Text;
                }
            }

            return(str);
        }
예제 #6
0
        public ChunkEditor GetEditor(CR2WChunk c)
        {
            if (c.data is CStorySceneSection)
            {
                return(new SceneSectionEditor());
            }

            switch (c.Type)
            {
            case "CStorySceneChoice":
                return(new SceneChoiceEditor());

            case "CStorySceneFlowCondition":
                return(new SceneFlowConditionEditor());

            case "CStorySceneRandomizer":
                return(new SceneRandomizerEditor());

            default:
                return(new SceneLinkEditor());
            }
        }
예제 #7
0
        /// <summary>
        /// Convert a CBitmapTexture's image to a DDS image
        /// </summary>
        /// <returns>A proper dds file</returns>
        public static Bitmap Xbm2Dds(CR2WChunk imagechunk)
        {
            try
            {
                var image       = ((CBitmapTexture)(imagechunk.data)).Image;
                var compression = imagechunk.GetVariableByName("compression").ToString();
                var width       = uint.Parse(imagechunk.GetVariableByName("width").ToString());
                var height      = uint.Parse(imagechunk.GetVariableByName("height").ToString());
                var mips        = imagechunk.GetVariableByName("residentMipIndex") != null?uint.Parse(imagechunk.GetVariableByName("residentMipIndex").ToString()) : 0;

                var tempfile = new MemoryStream();

                var dxt = DDSHeader.Format_DXT1;
                switch (compression)
                {
                case "TCM_DXTNoAlpha":
                    dxt = DDSHeader.Format_DXT1;
                    break;

                case "TCM_DXTAlpha":
                    dxt = DDSHeader.Format_DXT5;
                    break;

                case "TCM_NormalsHigh":
                    dxt = DDSHeader.Format_DXT5;
                    break;

                case "TCM_Normals":
                    dxt = DDSHeader.Format_DXT1;
                    break;

                case "TCM_NormalsGloss":
                    dxt = DDSHeader.Format_DXT5;
                    break;

                case "TCM_QualityControl":
                    dxt = DDSHeader.Format_DXT5;
                    break;

                default:
                    throw new Exception("Invalid compression type! [" + compression + "]");
                }

                DDSHeader ddsheader = new DDSHeader();
                using (var bw = new BinaryWriter(tempfile))
                {
                    bw.Write(ddsheader.generate(width, height, mips, dxt).ToArray());
                    //bw.Write(image.Bytes);  // First 20 bytes is garbage
                    bw.Write((new ArraySegment <byte>(image.Bytes, 20, image.Bytes.Length - 20)).ToArray());
                }
                tempfile.Flush();
#if DEBUG
                //File.WriteAllBytes(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\asd.dds",tempfile.ToArray());
#endif
                return(new DdsImage(tempfile.ToArray()).BitmapImage);
            }
            catch (Exception e)
            {
                string            message = e.Message;
                string            caption = "Error!";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                MessageBox.Show(message, caption, buttons);
                return(null);
            }
        }
예제 #8
0
 public void FireSelectEvent(CR2WChunk c)
 {
     OnSelectChunk?.Invoke(this, new SelectChunkArgs {
         Chunk = c
     });
 }