예제 #1
0
            public static TextureEntry FromLLSD(LLSD llsd)
            {
                LLSDArray array = (LLSDArray)llsd;
                LLSDMap   faceLLSD;

                if (array.Count > 0)
                {
                    int faceNumber;
                    faceLLSD = (LLSDMap)array[0];
                    TextureEntryFace defaultFace = TextureEntryFace.FromLLSD(faceLLSD, null, out faceNumber);
                    TextureEntry     te          = new TextureEntry(defaultFace);

                    for (int i = 1; i < array.Count; i++)
                    {
                        TextureEntryFace tex = TextureEntryFace.FromLLSD(array[i], defaultFace, out faceNumber);
                        if (faceNumber >= 0 && faceNumber < te.FaceTextures.Length)
                        {
                            te.FaceTextures[faceNumber] = tex;
                        }
                    }

                    return(te);
                }
                else
                {
                    throw new ArgumentException("LLSD contains no elements");
                }
            }
예제 #2
0
        private void LoadMaterials()
        {
            if (isMaterialTabFocused && !hasLoadedMaterials)
            {
                MatViewPanel.Controls.Clear();
                currentMaterials.Clear();
                if (FrameResource.IsFrameType(currentObject))
                {
                    if (currentObject is FrameObjectSingleMesh)
                    {
                        var entry = (currentObject as FrameObjectSingleMesh);
                        MaterialStruct[] materialAssignments = entry.Material.Materials[LODComboBox.SelectedIndex];
                        for (int x = 0; x != materialAssignments.Length; x++)
                        {
                            TextureEntry textEntry = new TextureEntry();

                            var       mat      = materialAssignments[x];
                            IMaterial material = MaterialsManager.LookupMaterialByHash(mat.MaterialHash);

                            textEntry.OnEntrySingularClick += MatViewPanel_TextureEntryOnSingularClick;
                            textEntry.OnEntryDoubleClick   += MatViewPanel_TextureEntryOnDoubleClick;
                            textEntry.SetMaterial(material);

                            currentMaterials.Add(textEntry, mat);
                            MatViewPanel.Controls.Add(textEntry);
                        }
                    }
                }

                hasLoadedMaterials = true;
            }
        }
예제 #3
0
 private static void UpdateLinkDicts(PackageReference pr, IList <Entry> contents)
 {
     for (int i = 0; i < contents.Count; i++)
     {
         TextureEntry te = contents[i] as TextureEntry;
         if (te != null)
         {
             if (TexturesByName.ContainsKey(te.Name))
             {
                 Console.WriteLine("Duplicate Texture entry: " + te.Name + " in " + pr.DisplayName + " and " + TexturesByName[te.Name].ContainingPackage.DisplayName);
             }
             else
             {
                 TexturesByName.Add(te.Name, new EntryReference(i, pr));
             }
             continue;
         }
         AtlasEntry ae = contents[i] as AtlasEntry;
         if (ae != null)
         {
             if (ae.IsReference)
             {
                 AddTo(AtlasesByTextureName, ae.ReferencedTextureName, new EntryReference(i, pr));
             }
             continue;
         }
     }
 }
예제 #4
0
        private void GetViewing(out SubAtlas atlas, out TextureEntry entry)
        {
            atlas = null;
            entry = null;
            if (TreeView == null || TreeView.Selection == null)
            {
                return;
            }
            var rows = TreeView.Selection.GetSelectedRows();

            if (rows.Length != 1)
            {
                return;
            }

            TreeIter iter;

            Model.GetIter(out iter, rows[0]);
            atlas = ((SubAtlas)Model.GetValue(iter, SUBATLAS_COLUMN));
            if (atlas == null)
            {
                return;
            }

            // Get the texture that the sub atlas references.
            if (atlas.Parent.IsReference)
            {
                entry = PackageManager.GetTextureByName(atlas.Parent.ReferencedTextureName);
            }
            else
            {
                entry = atlas.Parent.IncludedTextureEntry;
            }
        }
예제 #5
0
        public void HandleSetAgentAppearance(Message p)
        {
            var m = (AgentSetAppearance)p;

            if (m.AgentID != ID || m.SessionID != m.CircuitSessionID)
            {
                return;
            }

            foreach (var d in m.WearableData)
            {
                TextureHashes[d.TextureIndex] = d.CacheID;
            }

            var te = new TextureEntry(m.ObjectData);
            int tidx;

            if (te.DefaultTexture != null)
            {
                for (tidx = 0; tidx < Math.Min(TextureEntry.MAX_TEXTURE_FACES, NUM_AVATAR_TEXTURES); ++tidx)
                {
                    TextureEntryFace face;
                    Textures[tidx] = te.TryGetValue((uint)tidx, out face) ?
                                     face.TextureID :
                                     te.DefaultTexture.TextureID;
                }
            }

            SetTextureEntryBytes(m.ObjectData);

            VisualParams = m.VisualParams;
            Size         = m.Size;

            HandleAppearanceUpdate(this);
        }
예제 #6
0
        void Read(FileReader reader)
        {
            Textures        = new List <TextureEntry>();
            ConversionInfos = new List <ConversionInfo>();

            reader.ReadSignature(4, MAGIC);
            Version = reader.ReadUInt16();
            ushort numTextures          = reader.ReadUInt16();
            uint   textureDataOffset    = reader.ReadUInt32();
            uint   hashArrayOffset      = reader.ReadUInt32();
            uint   conversionInfoOffset = reader.ReadUInt32();

            reader.Position = 0x20;
            for (int i = 0; i < numTextures; i++)
            {
                TextureEntry entry = new TextureEntry();
                entry.Read(reader);
                Textures.Add(entry);
            }

            reader.SeekBegin(conversionInfoOffset);
            for (int i = 0; i < numTextures; i++)
            {
                ConversionInfos.Add(reader.ReadStruct <ConversionInfo>());
            }

            for (int i = 0; i < numTextures; i++)
            {
                reader.SeekBegin(textureDataOffset + Textures[i].DataOffset);
                Textures[i].ImageData = reader.ReadBytes((int)Textures[i].ImageSize);
            }
        }
예제 #7
0
        private void MatViewPanel_TextureEntryOnDoubleClick(object sender, EventArgs e)
        {
            // Get our entry
            TextureEntry Entry = (sender as TextureEntry);

            // Create our browser; once the user has finished with this menu they should? have a material.
            string    MaterialName = "";
            IMaterial OurMaterial  = Entry.GetMaterial();

            if (OurMaterial != null)
            {
                MaterialName = OurMaterial.GetMaterialName();
            }

            MaterialBrowser Browser          = new MaterialBrowser(MaterialName);
            IMaterial       SelectedMaterial = Browser.GetSelectedMaterial();

            // Set the new material data, notify the map editor that a change has been made.
            if (SelectedMaterial != null)
            {
                currentMaterials[Entry].MaterialName = SelectedMaterial.GetMaterialName();
                currentMaterials[Entry].MaterialHash = SelectedMaterial.GetMaterialHash();
                Entry.SetMaterial(SelectedMaterial);
                OnObjectUpdated(sender, e);
            }

            // Yeet the browser into the shadow realm.
            Browser.Dispose();
            Browser          = null;
            Entry.IsSelected = false;
        }
예제 #8
0
        private void ReadGH2Material(AwesomeReader ar, Mat mat, int version)
        {
            // TODO: Better figure out GH2 material structure
            var num = ar.ReadInt32();

            switch (num)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                break;

            default:
                throw new Exception($"Unexpected number, got {num}");
            }

            mat.BaseColor = new Color4()
            {
                R = ar.ReadSingle(),
                G = ar.ReadSingle(),
                B = ar.ReadSingle(),
                A = ar.ReadSingle()
            };

            var alwaysT = ar.ReadBoolean();
            var alwaysF = ar.ReadBoolean();

            var textureCount = ar.ReadInt32(); // Should always be 1

            mat.TextureEntries.Clear();
            mat.TextureEntries.AddRange(RepeatFor(1, () =>
            {
                ar.BaseStream.Position += 2;

                if (version >= 55)
                {
                    // Skip unknown data
                    ar.BaseStream.Position += 4;
                }

                var texEntry = new TextureEntry()
                {
                    Unknown1 = ar.ReadInt32(),
                    Unknown2 = ar.ReadInt32(),
                    Mat      = ReadMatrix(ar),
                    Unknown3 = 0,
                    Texture  = ar.ReadString()
                };

                // TODO: Read normal, specular, environment

                return(texEntry);
            }));
        }
예제 #9
0
            public static TextureEntry Read(BinaryReader br)
            {
                TextureEntry ret = new TextureEntry();

                ret.Id   = br.ReadUInt32();
                ret.Path = br.ReadChars(44);
                ret.Unk1 = br.ReadUInt32();
                ret.Unk2 = br.ReadUInt32();
                return(ret);
            }
예제 #10
0
 private static void StartWorker(TextureEntry viewingLocal, Action <byte[], List <AtlasEntry> > cb)
 {
     (new Thread(() => {
         byte[] decompressedLocal = TextureCache.Get(viewingLocal);
         List <AtlasEntry> atlasEntriesLocal = PackageManager.GetAtlasesByTextureName(viewingLocal.Name);
         Gtk.Application.Invoke((s, e) => {
             cb(decompressedLocal, atlasEntriesLocal);
         });
     })).Start();
 }
예제 #11
0
 public DockPropertyGrid()
 {
     InitializeComponent();
     Localise();
     currentObject        = null;
     currentEntry         = null;
     IsEntryReady         = false;
     isMaterialTabFocused = false;
     hasLoadedMaterials   = false;
     currentMaterials     = new Dictionary <TextureEntry, MaterialStruct>();
 }
        private UpdateChangedFlags ChangedTexParams(TextureEntry oldTex, TextureEntry newTex)
        {
            UpdateChangedFlags flags = ChangedTexParams(oldTex.DefaultTexture, newTex.DefaultTexture);
            uint index;

            for (index = 0; index < 32; ++index)
            {
                flags |= ChangedTexParams(oldTex[index], newTex[index]);
            }
            return(flags);
        }
예제 #13
0
        public static void Flush(TextureEntry e)
        {
            if (disableCache)
            {
                return;
            }

            Dictionary <TextureEntry, byte[]> workingCache = cache;

            workingCache.Remove(e);
        }
예제 #14
0
            private void ApplyCtpkTexture(TextureEntry tex)
            {
                CtpkTexture = tex;
                Width       = tex.Width;
                Height      = tex.Height;
                MipCount    = tex.MipCount;
                ArrayCount  = tex.FaceCount;
                Text        = tex.Name;
                Format      = CTR_3DS.ConvertPICAToGenericFormat(tex.PicaFormat);

                PlatformSwizzle = PlatformSwizzle.Platform_3DS;
            }
 public static BakedTextureIndex FindBakedByImageName(string name)
 {
     for (int i = 0; i < (int)BakedTextureIndex.NumIndices; i++)
     {
         BakedEntry   be = Instance.BakedTextures[(BakedTextureIndex)i];
         TextureEntry te = Instance.Textures[be.TextureIndex];
         if (te.DefaultImageName == name)
         {
             return((BakedTextureIndex)i);
         }
     }
     return(BakedTextureIndex.NumIndices);
 }
예제 #16
0
        private void TextureEntry_OnSingularClick(object sender, EventArgs e)
        {
            // Add the new selected one
            TextureEntry Entry = (sender as TextureEntry);

            // Remove the previous entry, if it is the same then we select this and exit the browser
            if (SelectedEntry != null)
            {
                SelectedEntry.IsSelected = false;
            }

            SelectedEntry = Entry;
        }
예제 #17
0
 public TextureWrapper(TextureEntry tex)
 {
     Texture    = tex;
     Width      = tex.Info.Width;
     Height     = tex.Info.Height;
     Depth      = tex.Info.Depth;
     ArrayCount = 1;
     MipCount   = tex.Info.MipCount;
     // Format = TextureData.ConvertFormat(tex.Info.Format);
     if (Formats.ContainsKey(tex.Info.Format))
     {
         Format = Formats[tex.Info.Format];
     }
 }
예제 #18
0
        void MatViewPanel_TextureEntryOnSingularClick(object sender, EventArgs e)
        {
            // Set IsSelected for all UCs in the FlowLayoutPanel to false.
            // Add the new selected one
            TextureEntry Entry = (sender as TextureEntry);

            // Remove the previous entry
            if (currentEntry != null)
            {
                currentEntry.IsSelected = false;
            }

            currentEntry = Entry;
        }
예제 #19
0
        private void PopulateBrowser(IMaterial[] materials)
        {
            FlowPanel_Materials.Controls.Clear();

            for (int x = 0; x < materials.Length; x++)
            {
                var          mat       = materials[x];
                TextureEntry textEntry = new TextureEntry();
                textEntry.SetMaterial(mat);
                textEntry.OnEntrySingularClick += TextureEntry_OnSingularClick;
                textEntry.OnEntryDoubleClick   += TextureEntry_OnDoubleClick;
                FlowPanel_Materials.Controls.Add(textEntry);
            }
        }
예제 #20
0
 public WeatherTimeRange(IUndoManager undoManager, L3dFilePath parentFile = null) : base(undoManager)
 {
     _sightDistance    = 10000;
     _brightnessFactor = 1.0f;
     _variables        = new UndoAwareObservableCollection <L3dVariable>(undoManager);
     _textures         = new List <TextureEntry>(5);
     for (int i = 0; i < 5; i++)
     {
         TextureEntry en = new TextureEntry();
         en._texture = L3dFilePath.CreateRelativeToFile(string.Empty, parentFile);
         en._tileU   = 1;
         en._tileV   = 1;
         _textures.Add(en);
     }
 }
예제 #21
0
        public void Init()
        {
            for (int i = 0; i < 1; i++)
            {
                var mtl = MaterialsManager.MTLs.ElementAt(i).Value;

                foreach (var mat in mtl.Materials)
                {
                    var          matValue  = mat.Value;
                    TextureEntry textEntry = new TextureEntry();
                    textEntry.SetMaterialName(matValue.MaterialName);
                    textEntry.SetMaterialTexture(GetThumbnail(matValue));
                    flowLayoutPanel1.Controls.Add(textEntry);
                }
            }
        }
예제 #22
0
        public void Init()
        {
            for (int i = 0; i < 1; i++)
            {
                var mtl = MaterialsManager.MaterialLibraries.ElementAt(i).Value;

                for (int x = 0; x < 20; x++)
                {
                    var          mat       = mtl.Materials.ElementAt(x).Value;
                    TextureEntry textEntry = new TextureEntry();
                    textEntry.SetMaterialName(mat.MaterialName);
                    textEntry.SetMaterialTexture(GetThumbnail(mat));
                    flowLayoutPanel1.Controls.Add(textEntry);
                }
            }
        }
예제 #23
0
 private void SetMaterialTab()
 {
     hasLoadedMaterials = false;
     currentEntry       = null;
     LODComboBox.Items.Clear();
     if (FrameResource.IsFrameType(currentObject))
     {
         if (currentObject is FrameObjectSingleMesh)
         {
             var entry = (currentObject as FrameObjectSingleMesh);
             for (int i = 0; i != entry.Geometry.NumLods; i++)
             {
                 LODComboBox.Items.Add("LOD #" + i);
             }
             LODComboBox.SelectedIndex = 0;
             LoadMaterials();
         }
     }
 }
예제 #24
0
파일: Package.cs 프로젝트: hengtek/Psiga
        public static Entry ReadPackageEntry(MemoryStream chunk, out ReadStatus readStatus)
        {
            int entryType = chunk.ReadByte();

            readStatus = ReadStatus.OK;
            switch (entryType)
            {
            case BINK_ATLAS_CODE:
                return(BinkAtlasEntry.Read(chunk));

            case INCLUDE_PACKAGE_CODE:
                return(IncludePackageEntry.Read(chunk));

            case ATLAS_CODE:
                return(AtlasEntry.Read(chunk, false));

            case BINK_CODE:
                return(BinkEntry.Read(chunk));

            case TEXTURE_CODE:
                return(TextureEntry.Read(chunk));

            case SPINE_CODE:
                return(SpineEntry.Read(chunk));

            case TEXTURE_3D_CODE:
                return(Texture3DEntry.Read(chunk));

            case END_CHUNK_CODE:
                readStatus = ReadStatus.EndOfChunk;
                return(null);

            case (int)byte.MaxValue:
            case -1:
                readStatus = ReadStatus.EndOfFile;
                return(null);

            default:
                throw new PackageReadException(string.Format(ERR_UNKNOWN_PACKAGE_entryType, entryType));
            }
        }
예제 #25
0
        /// <summary>
        /// A boolean which allows the Import of a Texture if true
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public bool ImportTexture(string path)
        {
            //Import Texture
            FileInfo TextureFileInfo = new FileInfo(path);

            // Create a new Texture Entry and fill it up
            TextureEntry NewEntry = new TextureEntry();

            NewEntry.Name        = TextureFileInfo.Name;
            NewEntry.Description = "Texture that was imported";
            NewEntry.Shader      = Shader.Default;

            // Create a BitmapImage and fill it up
            BitmapImage Texture = new BitmapImage(new Uri(path));

            NewEntry.Texture = getJPGFromImageControl(Texture);

            Model.CurrentLevel.Palette.Entries.Add(Model.CurrentLevel.Palette.Entries.Count, NewEntry);

            return(true);
        }
예제 #26
0
 public Primitive(Primitive prim)
 {
     CollisionPlane = prim.CollisionPlane;
     Flexible       = prim.Flexible;
     Light          = prim.Light;
     LightMap       = prim.LightMap;
     Sculpt         = prim.Sculpt;
     PrimData       = prim.PrimData;
     // FIXME: Get a real copy constructor for TextureEntry instead of serializing to bytes and back
     if (prim.Textures != null)
     {
         byte[] textureBytes = prim.Textures.GetBytes();
         Textures = new TextureEntry(textureBytes, 0, textureBytes.Length);
     }
     else
     {
         Textures = null;
     }
     TextureAnim = prim.TextureAnim;
     //ParticleSys = prim.ParticleSys;
 }
예제 #27
0
        private static byte[] Decompress(TextureEntry e)
        {
            byte[] decompressed = e.Texture.DecompressData();
            for (int i = 0; i < decompressed.Length; i += 4)
            {
                byte r = decompressed[i];
                byte g = decompressed[i + 1];
                byte b = decompressed[i + 2];
                byte a = decompressed[i + 3];

                r = (byte)(((int)r * (int)a) / 255);
                g = (byte)(((int)g * (int)a) / 255);
                b = (byte)(((int)b * (int)a) / 255);

                decompressed[i]     = b;
                decompressed[i + 1] = g;
                decompressed[i + 2] = r;
                decompressed[i + 3] = a;
            }
            return(decompressed);
        }
예제 #28
0
        private void SelectedIndexChanged(object sender, EventArgs e)
        {
            Panel.Controls.Clear();
            if (FrameResource.IsFrameType(currentObject))
            {
                if (currentObject is FrameObjectSingleMesh)
                {
                    var entry = (currentObject as FrameObjectSingleMesh);
                    for (int i = 0; i != entry.Material.NumLods; i++)
                    {
                        for (int x = 0; x != entry.Material.Materials[i].Length; x++)
                        {
                            var          mat       = entry.Material.Materials[i][x];
                            TextureEntry textEntry = new TextureEntry();

                            textEntry.SetMaterialName(mat.MaterialName);
                            textEntry.SetMaterialTexture(GetThumbnail(mat));
                            Panel.Controls.Add(textEntry);
                        }
                    }
                }
            }
        }
예제 #29
0
        /// <summary>
        /// New Level
        /// </summary>
        /// <param name="_name"></param>
        /// <param name="_xDimension"></param>
        /// <param name="_yDimension"></param>
        public void NewLevel(string _name, int _xDimension, int _yDimension)
        {
            // Fill the Model
            Model.CurrentLevel.Name    = _name;
            Model.CurrentLevel.Grid    = new RPGFramework.Grid(new List <RPGFramework.Tile>(), _xDimension, _yDimension);
            Model.CurrentLevel.Palette = new RPGFramework.TexturePalette(new Dictionary <int, RPGFramework.TextureEntry>());

            // Fill the Texture Entry
            TextureEntry FirstEntry = new TextureEntry();

            FirstEntry.Name        = "Unassigned";
            FirstEntry.Description = "Unassigned Tile";
            FirstEntry.Shader      = Shader.Default;

            // Create a Bitmap
            BitmapImage FirstEntryTexture = new BitmapImage(new Uri(Environment.CurrentDirectory + @"\Resources\Unassigned.png"));

            FirstEntry.Texture = getJPGFromImageControl(FirstEntryTexture);

            Model.CurrentLevel.Palette.Entries.Add(0, FirstEntry);

            FillViewportGrid();
        }
예제 #30
0
        /// <summary>
        /// Gets the texture entries data in BGRA format, other wise known as ARGB32 Little endian.
        /// </summary>
        /// <param name="e">The texture entry</param>
        public static byte[] Get(TextureEntry e)
        {
            if (disableCache)
            {
                return(Decompress(e));
            }

            Dictionary <TextureEntry, byte[]> workingCache = cache;

            lock (workingCache) {
                if (workingCache.ContainsKey(e))
                {
                    return(workingCache[e]);
                }
            }

            var decompressed = Decompress(e);

            lock (workingCache) {
                workingCache[e] = decompressed;
                return(decompressed);
            }
        }
예제 #31
0
            public static TextureEntry FromOSD(OSD osd)
            {
                OSDArray array = (OSDArray)osd;
                OSDMap faceSD;

                if (array.Count > 0)
                {
                    int faceNumber;
                    faceSD = (OSDMap)array[0];
                    TextureEntryFace defaultFace = TextureEntryFace.FromOSD(faceSD, null, out faceNumber);
                    TextureEntry te = new TextureEntry(defaultFace);

                    for (int i = 1; i < array.Count; i++)
                    {
                        TextureEntryFace tex = TextureEntryFace.FromOSD(array[i], defaultFace, out faceNumber);
                        if (faceNumber >= 0 && faceNumber < te.FaceTextures.Length)
                            te.FaceTextures[faceNumber] = tex;
                    }

                    return te;
                }
                else
                {
                    throw new ArgumentException("SD contains no elements");
                }
            }
예제 #32
0
 public void LoadTextures()
 {
     DialogResult r = MessageBox.Show("Load textures too?","", MessageBoxButtons.YesNo);
     if (r == DialogResult.No)
     {
         for (int i = 0; i < UStat.Count; i++)
             UStat[i].LP.textureindex = -1;
         return;
     }
     r = MessageBox.Show("Load from tfcs?", "", MessageBoxButtons.YesNo);
     string ptex = "", pctex = "";
     if (r == DialogResult.Yes)
     {
         OpenFileDialog d = new OpenFileDialog();
         d.Filter = "Textures.tfc|Textures.tfc";
         if (d.ShowDialog() == DialogResult.OK)
             ptex = d.FileName;
         d.Filter = "CharTextures.tfc|CharTextures.tfc";
         if (d.ShowDialog() == DialogResult.OK)
             pctex = d.FileName;
     }
     int count = 50;
     int counttex = 0;
     int countmat = 0;
     for (int i = 0; i < UStat.Count; i++)
         if (UStat[i].Materials == null || UStat[i].Materials.Count() == 0)
         {
             if (count < 49)
                 count++;
             else
             {
                 count = 0;
                 TextOut("\n" + i.ToString() + "\t");
             }
             TextOut("x");
             UStat[i].LP.textureindex = -1;
         }
         else
         {                    
             if (count < 49)
                 count++;
             else
             {
                 count = 0;
                 TextOut("\n" + i.ToString() + "\t");
             }
             UStat[i].LP.textureindex = -1;
             int stype = -1;//0=MIC 1=MAT
             int index = -1;
             for (int k = 0; k < UStat[i].Materials.Count; k++)
             {
                 byte[] buff = UStat[i].Materials[k].raw;                        
                 for (int j = 0; j < 11; j++)
                 {
                     int idx = BitConverter.ToInt32(buff, j * 4);
                     if (idx > 0 && idx < pcc.Header.ExportCount)
                     {
                         string s = pcc.getClassName(pcc.Export[idx].Class);
                         if (s == "MaterialInstanceConstant")
                         {
                             index = idx;
                             stype = 0;
                             break;
                         }
                         if (s == "Material")
                         {
                             index = idx;
                             stype = 1;
                             break;
                         }
                     }
                 }
             }
             if (index < 0)
             {
                 TextOut("?");
                 continue;
             }
             #region MIC
             if (stype == 0)
             {
                 UnrealObject UOb = new UnrealObject(pcc.EntryToBuff(index), pcc.getClassName(pcc.Export[index].Class), pcc.names);
                 string l = Path.GetDirectoryName(Application.ExecutablePath);
                 UOb.UUkn.UPR = UPR;
                 UOb.UUkn.Deserialize();
                 int entry = UPR.FindProperty("TextureParameterValues", UOb.UUkn.Properties);
                 if (entry != -1)
                 {
                     entry += 4;
                     index = -1;
                     bool stopme = false;
                     while (entry < UOb.UUkn.Properties.Count() && UOb.UUkn.Properties[entry].name == "ParameterValue" && !stopme)
                     {
                         entry++;
                         int n = BitConverter.ToInt32(UOb.UUkn.Properties[entry].raw, UOb.UUkn.Properties[entry].raw.Length - 4) - 1;
                         if (n > 0)
                         {
                             index = n;
                             if (pcc.names[pcc.Export[n].Name].ToLower().Contains("diff"))
                                 stopme = true;
                         }
                         entry += 5;
                     }
                     if (index != -1)
                     {
                         bool found = false;
                         for (int j = 0; j < Tex.Count(); j++)
                             if (index == Tex[j].index)
                             {
                                 UStat[i].LP.textureindex = j;
                                 TextOut("f");
                                 found = true;
                                 break;
                             }
                         if (!found)
                         {
                             UOb = new UnrealObject(pcc.EntryToBuff(index), "Texture2D", pcc.names);
                             TextureEntry t = new TextureEntry();
                             int tfc = -1;
                             for (int j = 0; j < UOb.UTex2D.TextureTFCs.Count; j++)
                                 if (UOb.UTex2D.TextureTFCs[j].size > 0 &&
                                     UOb.UTex2D.TextureTFCs[j].offset > 0 &&
                                     UOb.UTex2D.TextureTFCs[j].size != UOb.UTex2D.TextureTFCs[j].offset)
                                 {
                                     tfc = j;
                                     break;
                                 }
                             t.tex = UOb.UTex2D.ExportToTexture(device, tfc, ptex, pctex);
                             t.index = index;
                             t.name = pcc.names[pcc.Export[t.index].Name];
                             t.name = t.name.Substring(0, t.name.Length - 1);
                             Tex.Add(t);
                             UStat[i].LP.textureindex = Tex.Count - 1;
                             TextOut("l");
                             counttex++;
                         }
                     }
                     else TextOut("?");
                 }
                 else TextOut("?");
             }
             #endregion
             if (stype == 1)
             {
                 UnrealObject UOb = new UnrealObject(pcc.EntryToBuff(index), pcc.getClassName(pcc.Export[index].Class), pcc.names);
                 string l = Path.GetDirectoryName(Application.ExecutablePath);
                 UOb.UMat.UPR = UPR;
                 UOb.UMat.Deserialize();
                 int entry = UPR.FindProperty("Expressions", UOb.UMat.props);
                 if (entry == 0)
                 {
                     entry ++;
                     int len = UOb.UMat.props[1].raw.Length;
                     int cnt = (len - 20) / 4;
                     index =-1;
                     for(int j=0;j<cnt;j++)
                     {
                         index = BitConverter.ToInt32(UOb.UMat.props[1].raw, 20 + j * 4)-1;
                         if (pcc.getClassName(pcc.Export[index].Class) == "MaterialExpressionTextureSampleParamter2D")
                             break;
                     }
                     if (index == -1)
                     {
                         TextOut("?");
                         continue;
                     }
                     UnrealObject UUOb2 = new UnrealObject(pcc.EntryToBuff(index), "MaterialExpressionTextureSampleParameter2D",pcc.names);
                     UUOb2.UUkn.UPR = UPR;
                     UUOb2.UUkn.Deserialize();
                     index = -1;
                     for (int j = 0; j < UUOb2.UUkn.Properties.Count; j++)
                         if (UUOb2.UUkn.Properties[j].name == "Texture")
                             index = PropToInt(UUOb2.UUkn.Properties[j].raw);
                     if (index != -1 && !(index<0))
                     {
                         index--;
                         bool found = false;
                         for (int j = 0; j < Tex.Count(); j++)
                             if (index == Tex[j].index)
                             {
                                 UStat[i].LP.textureindex = j;
                                 TextOut("F");
                                 found = true;
                                 break;
                             }
                         if (!found)
                         {
                             UOb = new UnrealObject(pcc.EntryToBuff(index), "Texture2D", pcc.names);
                             TextureEntry t = new TextureEntry();
                             int tfc = -1;
                             for (int j = 0; j < UOb.UTex2D.TextureTFCs.Count; j++)
                                 if (UOb.UTex2D.TextureTFCs[j].size > 0 &&
                                     UOb.UTex2D.TextureTFCs[j].offset > 0 &&
                                     UOb.UTex2D.TextureTFCs[j].size != UOb.UTex2D.TextureTFCs[j].offset)
                                 {
                                     tfc = j;
                                     break;
                                 }
                             t.tex = UOb.UTex2D.ExportToTexture(device, tfc, ptex, pctex);
                             t.index = index;
                             t.name = pcc.names[pcc.Export[t.index].Name];
                             t.name = t.name.Substring(0, t.name.Length - 1);
                             Tex.Add(t);
                             UStat[i].LP.textureindex = Tex.Count - 1;
                             TextOut("M");
                             countmat++;
                         }
                     }
                     else TextOut("?");
                 }
                 else TextOut("?");
             }
         }
     TextOut("\nLoaded Textures: " + counttex.ToString());
     TextOut("\nLoaded Materials: " + countmat.ToString());
 }
예제 #33
0
        private void Run(Settings settings, ProgressDialog dialog)
        {
            for (int i = 0; i < fileList.Count; i++)
            {
                string file = fileList[i];
                string description;

                if (fileList.Count == 1)
                {
                    description = String.Format("Processing {0}", Path.GetFileName(file));
                }
                else
                {
                    description = String.Format("Processing {0} ({1:N0} of {2:N0})", Path.GetFileName(file), i + 1, fileList.Count);
                }

                dialog.ReportProgress(i * 100 / fileList.Count, description);

                // Let's open the file.
                // But, we're going to do this in a try catch in case any errors happen.
                try
                {
                    ArchiveFormat format;
                    string outPath, outName;
                    Queue<TextureEntry> textureFileQueue = null;

                    using (FileStream inStream = File.OpenRead(file))
                    {
                        // Set source to inStream
                        // The reason we do it like this is because source does not always equal inStream.
                        // You'll see why very soon.
                        Stream source = inStream;

                        // Get the format of the archive
                        format = Archive.GetFormat(source, Path.GetFileName(file));
                        if (format == ArchiveFormat.Unknown)
                        {
                            // Maybe it's compressed? Let's check.
                            // But first, we need to make sure we want to check
                            if (settings.DecompressSourceArchive)
                            {
                                // Get the compression format, if it is compressed that is.
                                CompressionFormat compressionFormat = Compression.GetFormat(source, Path.GetFileName(file));
                                if (compressionFormat != CompressionFormat.Unknown)
                                {
                                    // Ok, it appears to be compressed. Let's decompress it, and then check the format again
                                    source = new MemoryStream();
                                    Compression.Decompress(inStream, source, compressionFormat);

                                    source.Position = 0;
                                    format = Archive.GetFormat(source, Path.GetFileName(file));
                                }
                            }

                            // If we still don't know what the archive format is, just skip the file.
                            if (format == ArchiveFormat.Unknown)
                            {
                                continue;
                            }
                        }

                        // Now that we know its format, let's open it and start working with it.
                        ArchiveReader archive = Archive.Open(source, format);

                        // Get the appropiate output directory
                        if (settings.ExtractToSourceDirectory)
                        {
                            // Extract to the same directory as the source archive
                            outPath = Path.GetDirectoryName(file);
                        }
                        else if (settings.ExtractToSameNameDirectory)
                        {
                            // Extract to a directory of the same name
                            outPath = file + "." + Path.GetRandomFileName();
                        }
                        else
                        {
                            // Just the standard output path
                            outPath = Path.Combine(Path.Combine(Path.GetDirectoryName(file), "Extracted Files"), Path.GetFileNameWithoutExtension(file));
                        }

                        // Create the output directory if it does not exist
                        if (!Directory.Exists(outPath))
                        {
                            Directory.CreateDirectory(outPath);
                        }

                        // Now we can start extracting the files
                        for (int j = 0; j < archive.Entries.Count; j++)
                        {
                            if (fileList.Count == 1)
                            {
                                // If there is just one file in the file list, then the progress will be
                                // based on how many files are being extracted from the archive, not
                                // how many archives we are extracting.
                                dialog.ReportProgress(j * 100 / archive.Entries.Count, description + "\n\n" + String.Format("{0:N0} of {1:N0} extracted", j + 1, archive.Entries.Count));
                            }
                            else
                            {
                                dialog.Description = description + "\n\n" + String.Format("{0:N0} of {1:N0} extracted", j + 1, archive.Entries.Count);
                            }

                            ArchiveEntry entry = archive.Entries[j];
                            Stream entryData = entry.Open();

                            // Get the output name for this file
                            if (settings.FileNumberAsFilename || entry.Name == String.Empty)
                            {
                                // Use the file number as its filename
                                outName = j.ToString("D" + archive.Entries.Count.ToString().Length) + Path.GetExtension(entry.Name);
                            }
                            else if (settings.AppendFileNumber)
                            {
                                // Append the file number to its filename
                                outName = Path.GetFileNameWithoutExtension(entry.Name) + j.ToString("D" + archive.Entries.Count.ToString().Length) + Path.GetExtension(entry.Name);
                            }
                            else
                            {
                                // Just use the filename as defined in the archive
                                outName = entry.Name;
                            }

                            // What we're going to do here may seem a tiny bit hackish, but it'll make my job much simplier.
                            // First, let's check to see if the file is compressed, and if we want to decompress it.
                            if (settings.DecompressExtractedFiles)
                            {
                                // Get the compression format, if it is compressed that is.
                                CompressionFormat compressionFormat = Compression.GetFormat(entryData, entry.Name);
                                if (compressionFormat != CompressionFormat.Unknown)
                                {
                                    // Ok, it appears to be compressed. Let's decompress it, and then edit the entry
                                    MemoryStream decompressedData = new MemoryStream();
                                    Compression.Decompress(entryData, decompressedData, compressionFormat);

                                    entryData = decompressedData;
                                    entryData.Position = 0;
                                }
                            }

                            // Check to see if this file is a texture. If so, let's convert it to a PNG and then edit the entry
                            if (settings.ConvertExtractedTextures)
                            {
                                // Get the texture format, if it is a texture that is.
                                TextureFormat textureFormat = Texture.GetFormat(entryData, entry.Name);
                                if (textureFormat != TextureFormat.Unknown)
                                {
                                    // Ok, it appears to be a texture. We're going to attempt to convert it here.
                                    // If we get a TextureNeedsPalette exception, we'll wait until after we extract
                                    // all the files in this archive before we process it.
                                    try
                                    {
                                        MemoryStream textureData = new MemoryStream();
                                        Texture.Read(entryData, textureData, textureFormat);

                                        // If no exception was thrown, then we are all good doing what we need to do
                                        entryData = textureData;
                                        entryData.Position = 0;

                                        outName = Path.GetFileNameWithoutExtension(outName) + ".png";
                                    }
                                    catch (TextureNeedsPaletteException)
                                    {
                                        // Uh oh, looks like we need a palette.
                                        // What we are going to do is add it to textureFileQueue, then convert it
                                        // after we extract all of the files.
                                        if (textureFileQueue == null)
                                        {
                                            textureFileQueue = new Queue<TextureEntry>();
                                        }

                                        TextureEntry textureEntry = new TextureEntry();
                                        textureEntry.Format = textureFormat;
                                        textureEntry.Filename = Path.Combine(outPath, outName);

                                        textureFileQueue.Enqueue(textureEntry);
                                    }
                                }
                            }

                            // Time to write out the file
                            using (FileStream destination = File.Create(Path.Combine(outPath, outName)))
                            {
                                PTStream.CopyTo(entryData, destination, (int)entryData.Length);
                            }

                            // Let's check to see if this is an archive. If it is an archive, add it to the file list.
                            entryData.Position = 0;
                            if (settings.ExtractExtractedArchives)
                            {
                                ArchiveFormat archiveFormat = Archive.GetFormat(entryData, entry.Name);
                                if (archiveFormat != ArchiveFormat.Unknown)
                                {
                                    // It appears to be an archive. Let's add it to the file list
                                    if (settings.ExtractToSameNameDirectory)
                                    {
                                        // If we're adding to a directory of the same name, the outPath will be different.
                                        // We should remember that.
                                        fileList.Add(Path.Combine(file, outName));
                                    }
                                    else
                                    {
                                        fileList.Add(Path.Combine(outPath, outName));
                                    }

                                    if (fileList.Count == 2)
                                    {
                                        // If there was one archive in the file list, and now there is more,
                                        // adjust the progress bar and the description
                                        description = String.Format("Processing {0} ({1:N0} of {2:N0})", Path.GetFileName(file), i + 1, fileList.Count);
                                        dialog.ReportProgress(i * 100 / fileList.Count, description + "\n\n" + String.Format("{0:N0} of {1:N0} extracted", j + 1, archive.Entries.Count));
                                    }
                                }
                            }
                        }
                    }

                    // Let's see if we have any textures we still need to convert.
                    if (settings.ConvertExtractedTextures && textureFileQueue != null)
                    {
                        // Ok, it appears we do. So, let's loop through the queue until it is empty.
                        while (textureFileQueue.Count > 0)
                        {
                            TextureEntry textureEntry = textureFileQueue.Dequeue();

                            // Get the palette file name, and the out file name
                            string paletteName = Path.Combine(Path.GetDirectoryName(textureEntry.Filename), Path.GetFileNameWithoutExtension(textureEntry.Filename)) + Texture.Formats[textureEntry.Format].PaletteFileExtension;
                            string textureOutName = Path.Combine(Path.GetDirectoryName(textureEntry.Filename), Path.GetFileNameWithoutExtension(textureEntry.Filename)) + ".png";

                            // Make sure the two files exist before we attempt to open them.
                            // Wrap the whole thing in a try catch in case for some reason the texture file was modifed.
                            // That way, it'll fail peacefully and not screw over last minute things that need to be done to the archive.

                            // Open up the archive and test to make sure it's still a valid texture.
                            // You know, in case somehow it was edited or not extracted properly.
                            if (File.Exists(textureEntry.Filename) && File.Exists(paletteName))
                            {
                                try
                                {
                                    using (FileStream inTextureStream = File.OpenRead(textureEntry.Filename))
                                    {
                                        if (!Texture.Formats[textureEntry.Format].Is(inTextureStream, (int)inTextureStream.Length, textureEntry.Filename))
                                        {
                                            // Oh dear, somehow this isn't a texture anymore. Just skip over it
                                            continue;
                                        }

                                        // Ok, now we can load the palette data and try to convert it.
                                        using (FileStream inPaletteStream = File.OpenRead(paletteName),
                                        outTextureStream = File.Create(textureOutName))
                                        {
                                            TextureBase texture = Texture.Formats[textureEntry.Format];
                                            texture.PaletteStream = inPaletteStream;
                                            texture.PaletteLength = (int)inPaletteStream.Length;
                                            texture.Read(inTextureStream, outTextureStream, (int)inTextureStream.Length);
                                        }
                                    }

                                    // Now we can delete those two files
                                    File.Delete(textureEntry.Filename);
                                    File.Delete(paletteName);
                                }
                                catch
                                {
                                    // Something happened! But we'll just ignore it.
                                }
                            }
                        }
                    }

                    // Delete the source archive if the user chose to
                    if (settings.DeleteSourceArchive)
                    {
                        File.Delete(file);
                    }

                    // If we're extracting to a directory of the same name, we can now rename the directory
                    if (settings.ExtractToSameNameDirectory)
                    {
                        Directory.Move(outPath, file);
                    }
                }
                catch
                {
                    // Meh, just ignore the error.
                }
            }
        }
예제 #34
0
            public static TextureEntry FromOSD(OSD osd)
            {
                if (osd.Type == OSDType.Array)
                {
                    OSDArray array = (OSDArray)osd;
                    OSDMap faceSD;

                    if (array.Count > 0)
                    {
                        int faceNumber;
                        faceSD = (OSDMap)array[0];
                        TextureEntryFace defaultFace = TextureEntryFace.FromOSD(faceSD, null, out faceNumber);
                        TextureEntry te = new TextureEntry(defaultFace);

                        for (int i = 1; i < array.Count; i++)
                        {
                            TextureEntryFace tex = TextureEntryFace.FromOSD(array[i], defaultFace, out faceNumber);
                            if (faceNumber >= 0 && faceNumber < te.FaceTextures.Length)
                                te.FaceTextures[faceNumber] = tex;
                        }

                        return te;
                    }
                }

                return new TextureEntry(UUID.Zero);
            }
예제 #35
0
        public async Task SetModAsync(ModData mod)
        {
            Bind();

            _textures.Clear();
            _textures.Add(null);
            foreach (var texture in mod.Materials.Select(m => m.Texture))
            {
                texture.Index = _textures.Count;
                _textures.Add(texture);
            }

            _count = _textures.Count;

            // Find a texture size that fits all material textures.
            for (_size = 1; _size * _size < _count; _size += _size) { }

            _textureEntries = new TextureEntry[_count];

            double tf = (double)ushort.MaxValue / _size;
            double to = (double)ushort.MaxValue / (_size * TextureSize);

            await TextureHelper.DrawTextureAsync(
                _textureId,
                _size * TextureSize,
                _size * TextureSize,
                graphics =>
                {
                    int x = 0, y = 0;
                    for (int i = 0; i < _count; ++i)
                    {
                        var texture = _textures[i];

                        System.Drawing.Brush brush;
                        if (texture == null)
                        {
                            brush = System.Drawing.Brushes.White;
                        }
                        else
                        {
                            var color = new Color(texture.Color);
                            brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb((int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)));
                        }

                        var x0 = x * TextureSize;
                        var y0 = y * TextureSize;

                        graphics.FillRectangle(brush, new System.Drawing.Rectangle(x0, y0, TextureSize, TextureSize));

                        _textureEntries[i] = new TextureEntry
                        {
                            PixelX0 = x0,
                            PixelY0 = y0,
                            PixelX1 = x0 + TextureSize,
                            PixelY1 = y0 + TextureSize,
                            X0 = (ushort)(x * tf + to),
                            Y0 = (ushort)(y * tf + to),
                            X1 = (ushort)((x + 1) * tf - to),
                            Y1 = (ushort)((y + 1) * tf - to),
                        };

                        ++x;
                        if (x == _size)
                        {
                            x = 0;
                            ++y;
                        }
                    }
                },
                null);

            RunTextureGeneration();
        }