public static Texture2D GetTextureFromImg(string name, out DFPosition offset, TextureFormat format = TextureFormat.ARGB32) { offset = new DFPosition(); DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) { return(null); } ImgFile imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, name), FileUsage.UseMemory, true); Texture2D texture = null; // Custom texture if (TextureReplacement.CustomImageExist(name)) { texture = TextureReplacement.LoadCustomImage(name); } // Daggerfall texture else { imgFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, imgFile.PaletteName)); texture = GetTextureFromImg(imgFile, format); } texture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; offset = imgFile.ImageOffset; return(texture); }
/// <summary> /// Loads IMG file to texture using a subrect of source image. /// Origin of source image (0,0) is bottom-left corner. /// </summary> public static Texture2D GetTextureFromImg(string name, Rect subRect, TextureFormat format = TextureFormat.ARGB32, bool readOnly = true) { ImgFile imgFile = new ImgFile(Path.Combine(DaggerfallUnity.Instance.Arena2Path, name), FileUsage.UseMemory, readOnly); imgFile.LoadPalette(Path.Combine(DaggerfallUnity.Instance.Arena2Path, imgFile.PaletteName)); DFBitmap bitmap = imgFile.GetDFBitmap(); Color32[] colors = imgFile.GetColor32(bitmap, 0); // Invert Y as Unity textures have origin 0,0 at bottom-left and UI expects top-left subRect.y = bitmap.Height - subRect.height; Color32[] newColors = new Color32[(int)subRect.width * (int)subRect.height]; ImageProcessing.CopyColors( ref colors, ref newColors, new DFSize(bitmap.Width, bitmap.Height), new DFSize((int)subRect.width, (int)subRect.height), new DFPosition((int)subRect.x, (int)subRect.y), new DFPosition(0, 0), new DFSize((int)subRect.width, (int)subRect.height)); Texture2D texture = new Texture2D((int)subRect.width, (int)subRect.height, format, false); texture.SetPixels32(newColors, 0); texture.Apply(false, true); texture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; return(texture); }
void LoadResources() { // Get background image and store base palette ImgFile img = new ImgFile(Path.Combine(DaggerfallUnity.Arena2Path, backgroundFile), FileUsage.UseMemory, true); backgroundBitmap = img.GetDFBitmap(0, 0); basePalette = backgroundBitmap.Palette; // Get scroll images and set palette GfxFile scroll0 = new GfxFile(Path.Combine(DaggerfallUnity.Arena2Path, scroll0File), FileUsage.UseMemory, true); GfxFile scroll1 = new GfxFile(Path.Combine(DaggerfallUnity.Arena2Path, scroll1File), FileUsage.UseMemory, true); scroll0.Palette = basePalette; scroll1.Palette = basePalette; // Build color buffers for all scroll frames ahead of time scrollFrames = new ScrollFrame[scrollFrameCount]; for (int frame = 0; frame < scrollFrameCount; frame++) { if (frame < 8) { scrollFrames[frame].colors = scroll0.GetColor32(0, frame); } else { scrollFrames[frame].colors = scroll1.GetColor32(0, frame - 8); } } }
void LoadAssets() { const string compassFilename = "COMPASS.IMG"; const string compassBoxFilename = "COMPBOX.IMG"; if (!dfUnity.IsReady) { return; } if (!compassTexture) { ImgFile file = new ImgFile(Path.Combine(dfUnity.Arena2Path, compassFilename), FileUsage.UseMemory, true); file.LoadPalette(Path.Combine(dfUnity.Arena2Path, file.PaletteName)); compassTexture = GetTextureFromImg(file); compassTexture.filterMode = dfUnity.MaterialReader.MainFilterMode; } if (!compassBoxTexture) { ImgFile file = new ImgFile(Path.Combine(dfUnity.Arena2Path, compassBoxFilename), FileUsage.UseMemory, true); file.LoadPalette(Path.Combine(dfUnity.Arena2Path, file.PaletteName)); compassBoxTexture = GetTextureFromImg(file); compassBoxTexture.filterMode = dfUnity.MaterialReader.MainFilterMode; } assetsLoaded = true; }
/**/ public string SubirImage() { string imgName = ""; int imgSize = 0; string imgPath = ""; if (ImgFile.PostedFile != null && ImgFile.FileName != " ") { imgName = ImgFile.FileName; imgPath = "Images/" + imgName; imgSize = ImgFile.PostedFile.ContentLength; if (imgSize > 10240) { return("error"); } else { String dir = Server.MapPath(imgPath).Replace("\\PaginasInstructor", ""); ImgFile.SaveAs(dir); return(imgPath); } } return("error"); }
private static void ExportImg(string imgPath, string saveDirectory) { if (string.IsNullOrEmpty(imgPath) || string.IsNullOrEmpty(saveDirectory)) { return; } using (new Timing("Exporting Img")) using (new MemoryCounter()) using (new AssetEditing()) using (var progress = new ProgressBar("Exporting Img", 0, 32)) { var img = new ImgFile(imgPath); progress.Count = img.EntriesCount; foreach (var entry in img) { try { using (new Timing("Writing File")) File.WriteAllBytes(Path.Combine(saveDirectory, entry.FileName), entry.GetData()); progress.Increment(entry.FileName); if (progress.Canceled) { break; } } catch { Log.Error("Failed to write: {0}", entry); } } } }
public static Texture2D GetTextureFromImg(string name, out DFPosition offset, TextureFormat format = TextureFormat.ARGB32, bool readOnly = true) { offset = new DFPosition(); DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) { return(null); } ImgFile imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, name), FileUsage.UseMemory, readOnly); Texture2D texture; if (!TextureReplacement.TryImportImage(name, out texture)) { imgFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, imgFile.PaletteName)); texture = GetTextureFromImg(imgFile, format, readOnly); } texture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; offset = imgFile.ImageOffset; return(texture); }
public override ArchiveFile LoadArchive(string filepath) { ImgFile img = new ImgFile(filepath); img.Load(); return(img); }
Texture2D GetTextureFromImg(ImgFile img) { DFBitmap bitmap = img.GetDFBitmap(); Texture2D texture = new Texture2D(bitmap.Width, bitmap.Height, TextureFormat.ARGB32, false); texture.SetPixels32(img.GetColor32(bitmap, 0)); texture.Apply(false, true); return(texture); }
public static Texture2D GetTextureFromImg(ImgFile img, TextureFormat format = TextureFormat.ARGB32, bool readOnly = true) { DFBitmap bitmap = img.GetDFBitmap(); Texture2D texture = new Texture2D(bitmap.Width, bitmap.Height, format, false); texture.SetPixels32(img.GetColor32(bitmap, 0)); texture.Apply(false, readOnly); texture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; return(texture); }
public void Add(ImgFile img) { using (new Timing("Adding Textures (img)")) foreach (var entry in img) { if (entry.FileName.EndsWith(".txd", StringComparison.Ordinal)) { Add(new TxdFile(entry)); } } }
public void Add(ImgFile img) { using (new Timing("Adding Models (img)")) foreach (var entry in img) { if (entry.FileName.EndsWith(".dff", StringComparison.OrdinalIgnoreCase)) { Add(new DffFile(entry)); } } }
public static DFBitmap GetImgBitmap(string name) { DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) { return(null); } ImgFile imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, name), FileUsage.UseMemory, true); return(imgFile.GetDFBitmap()); }
public static Bitmap Decode(byte[] data) { try { GimFile file = new GimFile(data); ImgFile file2 = new ImgFile(file.GetDecompressedData(), file.GetWidth(), file.GetHeight(), ImageFormat.Png); return(new Bitmap(new MemoryStream(file2.GetCompressedData()))); } catch { return(null); } }
public void Add(ImgFile img) { if (img.Version < GtaVersion.SanAndreas) { Log.Message("Ignoring streaming placements because img version is below 2.0 ({0})", img.FilePath); return; } allPlacements = new List <ItemPlacement>(); using (new Timing("Adding Placements (streaming)")) foreach (var kvp in textIPLs) { var textIplName = kvp.Key; var placements = new List <ItemPlacement>(kvp.Value); try { for (var i = 0; ;) { var binaryIplName = string.Format(STREAMING_IPL_NAME_FORMAT, textIplName, i++); placements.AddRange(new BinaryIpl(img[binaryIplName])); } } catch (KeyNotFoundException) { } catch (Exception e) { Log.Exception(e); } using (new Timing("Resolving LODs")) for (var i = 0; i < placements.Count; i++) { var placement = placements[i]; if (placement.LodDefinitionID < 0) { continue; } try { var lodVersion = placements[placement.LodDefinitionID]; lodVersion.IsLOD = true; lodLinks.Add(placement, placements[placement.LodDefinitionID] = lodVersion); } catch (Exception e) { Log.Error("Failed to resolve LOD link, object {0}({1}) with lod {2}: {3}", placement.ItemName, placement.DefinitionID, placement.LodDefinitionID, e); } } allPlacements.AddRange(placements); } NonLodPlacements = (from plac in allPlacements where !plac.IsLOD select plac).ToArray(); }
public PhysicsWorld CreatePhysicsWorldFromDat(string root, DatFile datFile, ImgFile imgFile, PhysicsModelLoadMode loadMode = PhysicsModelLoadMode.LowDetail, Action <PhysicsWorldBuilder>?builderAction = null ) { var world = CreateWorld(builder => { builder.AddImg(imgFile.Img); foreach (var ide in datFile.Dat.Ides) { var path = Path.Join(root, ide).TrimEnd('\r'); if (File.Exists(path)) { builder.AddIde(Path.GetFileNameWithoutExtension(path), new IdeFile(path).Ide, loadMode); } else { this.logger.LogWarning($"Unable to find .ide file {path}"); } } foreach (var ipl in datFile.Dat.Ipls) { var path = Path.Join(root, ipl).TrimEnd('\r'); if (File.Exists(path)) { builder.AddIpl(new IplFile(path).Ipl, loadMode); } else { this.logger.LogWarning($"Unable to find .ipl file {path}"); } } foreach (var ipl in imgFile.Img.IplFiles) { builder.AddIpl(new BinaryIplFile(imgFile.Img.DataEntries[ipl].Data).BinaryIpl, loadMode); } builderAction?.Invoke(builder); }); imgFile.Dispose(); return(world); }
private string UploadFile() { string uniqueFileName = null; if (ImgFile != null) { uniqueFileName = Guid.NewGuid().ToString() + Path.GetExtension(ImgFile.FileName); string filePath = Path.Combine("wwwroot/Images", uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { ImgFile.CopyTo(fileStream); } } return(uniqueFileName); }
public LeftRightSpinner() { DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) { return; } // Load IMG texture ImgFile imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, nativeImgName), FileUsage.UseMemory, true); imgFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, imgFile.PaletteName)); nativeTexture = TextureReader.CreateFromAPIImage(imgFile, 0, 0, 0); nativeTexture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; // Setup spinner panel Size = TextureReplacement.GetSize(nativeTexture, nativeImgName); backgroundTexture = nativeTexture; // Add up/down buttons Components.Add(leftButton); Components.Add(rightButton); leftButton.Position = new Vector2(0, 0); leftButton.Size = new Vector2(11, 9); leftButton.OnMouseClick += LeftButton_OnMouseClick; leftButton.OnMouseDown += LeftButton_OnMouseDown; leftButton.OnMouseUp += LeftRightButtons_OnMouseUp; rightButton.Position = new Vector2(26, 0); rightButton.Size = new Vector2(11, 9); rightButton.OnMouseClick += RightButton_OnMouseClick; rightButton.OnMouseDown += RightButton_OnMouseDown; rightButton.OnMouseUp += LeftRightButtons_OnMouseUp; // Add value label Components.Add(valueLabel); valueLabel.Position = new Vector2(0, 2); valueLabel.Size = new Vector2(15, 9); valueLabel.HorizontalAlignment = HorizontalAlignment.Center; valueLabel.ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; SetValue(this.value); }
public async Task <IActionResult> OnPost() { if (PdfFile == null || ImgFile == null) { return(BadRequest()); } else { Book.CreationDate = DateTime.Now; if (ModelState.IsValid) { #region pdf file string pdfFileName = Guid.NewGuid().ToString() + Path.GetFileName(PdfFile.FileName); string pdfFilePath = Path.Combine(env.WebRootPath, "files"); string fullPath = Path.Combine(pdfFilePath, pdfFileName); Book.Url = pdfFileName; await PdfFile.CopyToAsync(new FileStream(fullPath, FileMode.Create)); #endregion #region img file string imgFileName = Guid.NewGuid().ToString() + Path.GetFileName(ImgFile.FileName); string imgFilePath = Path.Combine(env.WebRootPath, "imgs"); string imgFullPath = Path.Combine(imgFilePath, imgFileName); Book.ImgUrl = imgFileName; await ImgFile.CopyToAsync(new FileStream(imgFullPath, FileMode.Create)); #endregion await db.Books.AddAsync(Book); await db.SaveChangesAsync(); return(RedirectToPage("index")); } return(Page()); } }
public UpDownSpinner() { DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) { return; } // Load IMG texture ImgFile imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, nativeImgName), FileUsage.UseMemory, true); imgFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, imgFile.PaletteName)); nativeTexture = TextureReader.CreateFromAPIImage(imgFile, 0, 0, 0); nativeTexture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; // Setup spinner panel Size = new Vector2(15, 20); backgroundTexture = nativeTexture; // Add up/down buttons Components.Add(upButton); Components.Add(downButton); upButton.Position = new Vector2(0, 0); upButton.Size = new Vector2(15, 7); upButton.OnMouseClick += UpButton_OnMouseClick; downButton.Position = new Vector2(0, 13); downButton.Size = new Vector2(15, 7); downButton.OnMouseClick += DownButton_OnMouseClick; // Add value label Components.Add(valueLabel); valueLabel.Position = new Vector2(0, 7); valueLabel.Size = new Vector2(15, 6); valueLabel.HorizontalAlignment = HorizontalAlignment.Center; valueLabel.ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; SetValue(this.value); }
void SetupControl() { dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) { return; } // Load highlight texture ImgFile imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, highlightImgName), FileUsage.UseMemory, true); imgFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, imgFile.PaletteName)); highlightTexture = TextureReader.CreateFromAPIImage(imgFile, 0, 0, 0); highlightTexture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; // Add buttons Vector2 buttonPos = new Vector2(0, 0); Vector2 buttonSize = new Vector2(66, 9); for (int i = 0; i < 5; i++) { selectButtons[i] = new Button(); this.Components.Add(selectButtons[i]); selectButtons[i].Position = buttonPos; selectButtons[i].Size = buttonSize; selectButtons[i].Tag = i; selectButtons[i].OnMouseClick += ReflexButton_OnMouseClick; buttonPos.y += buttonSize.y; } // Set size of this panel Size = new Vector2(66, 45); // Set starting value PlayerReflexes = PlayerReflexes.Average; }
private void LoadNightSky() { const int width = 512; const int height = 219; // Get night sky matching sky index int nightSky; if (SkyIndex >= 0 && SkyIndex <= 7) { nightSky = 3; } else if (SkyIndex >= 8 && SkyIndex <= 15) { nightSky = 1; } else if (SkyIndex >= 16 && SkyIndex <= 23) { nightSky = 2; } else { nightSky = 0; } string filename = string.Format("NITE{0:00}I0.IMG", nightSky); imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); imgFile.Palette.Load(Path.Combine(dfUnity.Arena2Path, imgFile.PaletteName)); // Get sky bitmap DFBitmap dfBitmap = imgFile.GetDFBitmap(0, 0); // Draw stars if (ShowStars) { for (int i = 0; i < dfBitmap.Data.Length; i++) { // Stars should only be drawn over clear sky indices int index = dfBitmap.Data[i]; if (index > 16 && index < 32) { if (random.NextDouble() < starChance) { dfBitmap.Data[i] = starColorIndices[random.Next(0, starColorIndices.Length)]; } } } } // Get sky colour array Color32[] colors = imgFile.GetColor32(dfBitmap); // Fix seam on right side of night skies for (int y = 0; y < height; y++) { int pos = y * width + width - 2; colors[pos + 1] = colors[pos]; } skyColors.west = colors; skyColors.east = colors; skyColors.clearColor = skyColors.west[0]; }
public void Load() { using (new Timing("Loading " + Version.GetFormatedGTAName(true))) using (new TempCultureInfo(CultureInfo.InvariantCulture)) using (new MemoryCounter()) using (var workingFolder = new TempWorkingFolder(Path)) using (var progress = new ProgressBar("Loading " + Version.GetFormatedGTAName() + " map", 0, workingFolder, 32)) try { DefaultData = DataFile.GetMainData(Version); SpecificData = DataFile.GetVersionSpecificData(Version); Gta3img = ImgFile.GetMainImg(Version); IdeCollection = new DefinitionCollection() { DefaultData, SpecificData }; IplCollection = new PlacementCollection() { DefaultData, SpecificData, Gta3img }; TxdCollection = new TextureCollection() { DefaultData, SpecificData, Gta3img }; ModelCollection = new ModelCollection() { DefaultData, SpecificData, Gta3img }; TxdCollection.AddTextureParent(DefaultData); TxdCollection.AddTextureParent(SpecificData); //ItemDefinition.TransformModifiers += SetStatic; progress.Count = IplCollection.AllPlacements.Count(); foreach (var placement in IplCollection) { Place(placement, progress); if (progress.Canceled) { return; } } if (!Camera.main.GetComponent <FreeCamera>()) { Camera.main.gameObject.AddComponent <FreeCamera>(); } if (!Camera.main.GetComponent <CameraLod>()) { Camera.main.gameObject.AddComponent <CameraLod>(); } } catch (Exception e) { Log.Error("FAILED TO LOAD"); Log.Exception(e); }finally { ItemDefinition.TransformModifiers -= SetStatic; #if UNITY_EDITOR UnityEditor.Lightmapping.bakedGI = false; UnityEditor.Lightmapping.realtimeGI = false; UnityEditor.EditorApplication.Beep(); #endif } }
protected override void Setup() { if (IsSetup) { return; } // Set background backgroundImg = new ImgFile(Path.Combine(DaggerfallUnity.Arena2Path, nativeImgName), FileUsage.UseMemory, true); backgroundBitmap = backgroundImg.GetDFBitmap(0, 0); nativeTexture = new Texture2D(backgroundBitmap.Width, backgroundBitmap.Height, TextureFormat.ARGB32, false); if (!nativeTexture) { throw new Exception("CreateCharClassQuestions: Could not load native texture."); } nativeTexture.SetPixels32(backgroundImg.GetColor32(backgroundBitmap, 0)); nativeTexture.Apply(false, true); nativeTexture.filterMode = DaggerfallUI.Instance.GlobalFilterMode; NativePanel.BackgroundTexture = nativeTexture; // Load both scroll images as one contiguous list of textures scrollFile0 = new GfxFile(Path.Combine(DaggerfallUnity.Instance.Arena2Path, scroll0FileName), FileUsage.UseMemory, true); scrollFile1 = new GfxFile(Path.Combine(DaggerfallUnity.Instance.Arena2Path, scroll1FileName), FileUsage.UseMemory, true); scrollFile0.Palette = backgroundBitmap.Palette; scrollFile1.Palette = backgroundBitmap.Palette; scrollTextures = new List <Texture2D>(); for (int i = 0; i < scrollFile0.frames.Length; i++) { scrollTextures.Add(TextureReader.CreateFromAPIImage(scrollFile0, 0, i, 0)); scrollTextures.Last().filterMode = DaggerfallUI.Instance.GlobalFilterMode; } for (int i = scrollFile0.frames.Length; i < scrollFile0.frames.Length + scrollFile1.frames.Length; i++) { scrollTextures.Add(TextureReader.CreateFromAPIImage(scrollFile1, 0, i - scrollFile0.frames.Length, 0)); scrollTextures.Last().filterMode = DaggerfallUI.Instance.GlobalFilterMode; } // Position scroll image on screen questionScroll.Position = new Vector2(0, 120f); questionScroll.Size = new Vector2(scrollTextures[0].width, scrollTextures[0].height); questionScroll.BackgroundTexture = scrollTextures[0]; questionScroll.Parent = NativePanel; textArea.Position = new Vector2(leftTextOffset, 120f + topTextOffset); textArea.Size = new Vector2(scrollTextures[0].width, scrollTextures[0].height - topTextOffset * 2f); textArea.Parent = NativePanel; NativePanel.Components.Add(textArea); NativePanel.Components.Add(questionScroll); // Setup question label questionIndices = GetQuestions(); DisplayQuestion(questionIndices[questionsAnswered]); // Handle scrolling NativePanel.OnMouseScrollDown += NativePanel_OnMouseScrollDown; NativePanel.OnMouseScrollUp += NativePanel_OnMouseScrollUp; questionScroll.OnMouseDown += QuestionScroll_OnMouseDown; questionScroll.OnMouseUp += QuestionScroll_OnMouseUp; // Setup animations rogueAnim.SetTransparentColor(0, 0, 10); rogueAnim.TransparencyEnabled = true; rogueAnim.Load("ROGUE.CEL"); rogueAnim.Size = new Vector2(rogueAnim.FLCFile.Header.Width, rogueAnim.FLCFile.Header.Height); rogueAnim.Position = new Vector2(1f, 1f); rogueAnim.BackgroundColor = Color.clear; rogueAnim.OnAnimEnd += CEL_OnAnimEnd; mageAnim.SetTransparentColor(0, 0, 10); mageAnim.TransparencyEnabled = true; mageAnim.Load("MAGE.CEL"); mageAnim.Size = new Vector2(mageAnim.FLCFile.Header.Width, mageAnim.FLCFile.Header.Height); mageAnim.Position = new Vector2(79f, 1f); mageAnim.BackgroundColor = Color.clear; mageAnim.OnAnimEnd += CEL_OnAnimEnd; warriorAnim.SetTransparentColor(0, 0, 10); warriorAnim.TransparencyEnabled = true; warriorAnim.Load("WARRIOR.CEL"); warriorAnim.Size = new Vector2(warriorAnim.FLCFile.Header.Width, warriorAnim.FLCFile.Header.Height); warriorAnim.Position = new Vector2(110f, 1f); warriorAnim.BackgroundColor = Color.clear; warriorAnim.OnAnimEnd += CEL_OnAnimEnd; rogueAnim.Loop = mageAnim.Loop = warriorAnim.Loop = false; NativePanel.Components.Add(rogueAnim); NativePanel.Components.Add(mageAnim); NativePanel.Components.Add(warriorAnim); IsSetup = true; }
private static void TakeTextures() { string[] files = Directory.GetFiles( EditorUtility.OpenFolderPanel("Select Texture Folder", "", "") ).OrderBy(x => x).ToArray(); if (files.Length == 0) { return; } IOFilePaths paths; paths.localDirectory = ASSETS_DIRECTORY; paths.writeDirectory = AddPath(paths.localDirectory, ExportFolder); if (!AssetDatabase.IsValidFolder(paths.writeDirectory)) { AssetDatabase.CreateFolder(paths.localDirectory, ExportFolder); } string currentMaterialName = ""; Texture texture = null; Material material = null; bool isNewMaterial = false; ImgFile imgFile = new ImgFile(); int totalTexturesImported = 0; int totalMaterialsCreated = 0; foreach (string file in files) { imgFile.lastDot = file.LastIndexOf(DOT); if (!ArrayUtility.Contains <string>(fileTypes, file.Substring(imgFile.lastDot + 1).ToUpper())) { return; } imgFile.lastSlash = LastSlash(file); imgFile.fileName = file.Substring(imgFile.lastSlash + 1, file.Length - imgFile.lastSlash - 1); imgFile.lastToken = file.LastIndexOf(SuffixToken); if (imgFile.lastToken < 0) { return; } imgFile.name = file.Substring(imgFile.lastSlash + 1, imgFile.lastToken - imgFile.lastSlash - 1); imgFile.suffix = file.Substring(imgFile.lastToken + 1, imgFile.lastDot - imgFile.lastToken - 1); if (imgFile.name != currentMaterialName) { if (material != null) { if (CreateNewMaterial(material, AddPath(paths.writeDirectory, currentMaterialName), isNewMaterial)) { totalMaterialsCreated++; } } material = MakeOrGetMaterial(paths.writeDirectory, imgFile.name, out isNewMaterial); currentMaterialName = imgFile.name; } string fileNewPath = AddPath(paths.writeDirectory, imgFile.fileName); try { File.Copy(file, fileNewPath, true); totalTexturesImported++; } catch { } AssetDatabase.Refresh(); //must refresh before this texture can be assigned texture = (Texture2D)AssetDatabase.LoadAssetAtPath(fileNewPath, typeof(Texture2D)); material.SetTexture(SuffixToParameter(imgFile.suffix.ToString(), imgFile.fileName), texture); } if (CreateNewMaterial(material, AddPath(paths.writeDirectory, currentMaterialName), isNewMaterial)) { totalMaterialsCreated++; } Debug.Log("(TTaker) " + totalTexturesImported + " Textures taken, " + totalMaterialsCreated + " Materials created."); }
/// <summary> /// Reads any Daggerfall image file to ImageData package. /// </summary> /// <param name="filename">Name of standalone file as it appears in arena2 folder.</param> /// <param name="record">Which image record to read for multi-image files.</param> /// <param name="frame">Which frame to read for multi-frame images.</param> /// <param name="hasAlpha">Enable this for image cutouts.</param> /// <param name="createTexture">Create a Texture2D.</param> /// <returns>ImageData. If result.type == ImageTypes.None then read failed.</returns> public static ImageData GetImageData(string filename, int record = 0, int frame = 0, bool hasAlpha = false, bool createTexture = true) { // Check API ready DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) { return(new ImageData()); } // Parse image file type ImageTypes fileType; try { fileType = ParseFileType(filename); } catch { return(new ImageData()); } // Create base image data ImageData imageData = new ImageData(); imageData.type = fileType; imageData.filename = filename; imageData.record = record; imageData.frame = frame; imageData.hasAlpha = hasAlpha; // Read supported image files DFBitmap dfBitmap = null; switch (fileType) { case ImageTypes.TEXTURE: TextureFile textureFile = new TextureFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); textureFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, textureFile.PaletteName)); dfBitmap = textureFile.GetDFBitmap(record, frame); imageData.offset = textureFile.GetOffset(record); imageData.scale = textureFile.GetScale(record); imageData.size = textureFile.GetSize(record); break; case ImageTypes.IMG: ImgFile imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); imgFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, imgFile.PaletteName)); dfBitmap = imgFile.GetDFBitmap(); imageData.offset = imgFile.ImageOffset; imageData.scale = new DFSize(); imageData.size = imgFile.GetSize(0); break; case ImageTypes.CIF: case ImageTypes.RCI: CifRciFile cifFile = new CifRciFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); cifFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, cifFile.PaletteName)); dfBitmap = cifFile.GetDFBitmap(record, frame); imageData.offset = cifFile.GetOffset(record); imageData.scale = new DFSize(); imageData.size = cifFile.GetSize(record); break; default: return(new ImageData()); } // Store bitmap imageData.dfBitmap = dfBitmap; imageData.width = dfBitmap.Width; imageData.height = dfBitmap.Height; // Create Texture2D if (createTexture) { // Get colors array Color32[] colors = GetColors(imageData); if (colors == null) { return(new ImageData()); } // Create new Texture2D imageData.texture = GetTexture(colors, imageData.width, imageData.height); } return(imageData); }
public IActionResult OnPost() { ActiveRecord = new SessionActive(); ActiveRecord.Active_SessionID = HttpContext.Session.GetString(Session_SessionID); ActiveRecord.Active_EmailAddress = HttpContext.Session.GetString(Session_EmailAddress); ActiveRecord.Active_FirstName = HttpContext.Session.GetString(Session_FirstName); ActiveRecord.Active_ModLevel = HttpContext.Session.GetInt32(Session_ModLevel); // if session isn't active then redirect to login page if (string.IsNullOrEmpty(ActiveRecord.Active_EmailAddress) && string.IsNullOrEmpty(ActiveRecord.Active_FirstName) && string.IsNullOrEmpty(ActiveRecord.Active_SessionID)) { ActiveRecord.Active_Sesson = false; return(RedirectToPage("/Login/Login")); } else { ActiveRecord.Active_Sesson = true; } // get database connection DBConnect G24database_connection = new DBConnect(); string DBconnection = G24database_connection.DatabaseString(); SqlConnection connect = new SqlConnection(DBconnection); connect.Open(); //create the file path to upload the image to const string Path2 = "ImgUploads"; var FileToUpload = Path.Combine(_env.WebRootPath, Path2, ImgFile.FileName); // upload the image on the filestream using (var Fstream = new FileStream(FileToUpload, FileMode.Create)) { ImgFile.CopyTo(Fstream); } using (SqlCommand command = new SqlCommand()) { command.Connection = connect; // insert the images data into the database command.CommandText = @"INSERT INTO Images ( ImgURL, Type, ImgName, UserID) VALUES ( @ImgURL, @Type, @ImgName, @UserID)"; command.Parameters.AddWithValue("@ImgURL", ImgFile.FileName); command.Parameters.AddWithValue("@Type", Tidy_case(ImgRecord.Type)); command.Parameters.AddWithValue("@ImgName", ImgRecord.ImgName); command.Parameters.AddWithValue("@UserID", ImgRecord.UserID); command.ExecuteNonQuery(); } using (SqlCommand ID_command = new SqlCommand()) { ID_command.Connection = connect; ID_command.CommandText = @"SELECT ImgID FROM Images WHERE ImgURL = @ImgURL"; ID_command.Parameters.AddWithValue("@ImgURL", ImgFile.FileName); SqlDataReader ID_reader = ID_command.ExecuteReader(); while (ID_reader.Read()) { uploadID = ID_reader.GetInt32(0); } } //close database connection connect.Close(); // redirects to the image page for the image uploaded passing through the image ID return(RedirectToPage("/ImgController/Index", new { imgid = uploadID })); }
/// <summary> /// Reads any Daggerfall image file to ImageData package. /// </summary> /// <param name="filename">Name of standalone file as it appears in arena2 folder.</param> /// <param name="record">Which image record to read for multi-image files.</param> /// <param name="frame">Which frame to read for multi-frame images.</param> /// <param name="hasAlpha">Enable this for image cutouts.</param> /// <param name="createTexture">Create a Texture2D.</param> /// <param name="createAllFrameTextures">Creates a Texture2D for every frame in a TEXTURE file (if greater than 1 frames).</param> /// <param name="alphaIndex">Set palette index for alpha checks (default is 0).</param> /// <returns>ImageData. If result.type == ImageTypes.None then read failed.</returns> public static ImageData GetImageData(string filename, int record = 0, int frame = 0, bool hasAlpha = false, bool createTexture = true, bool createAllFrameTextures = false, int alphaIndex = 0) { // Check API ready DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) { return(new ImageData()); } // Parse image file type ImageTypes fileType; try { fileType = ParseFileType(filename); } catch { return(new ImageData()); } // Create base image data ImageData imageData = new ImageData(); imageData.type = fileType; imageData.filename = filename; imageData.record = record; imageData.frame = frame; imageData.hasAlpha = hasAlpha; imageData.alphaIndex = alphaIndex; // Read supported image files DFBitmap dfBitmap = null; DFBitmap[] dfBitmapAllFrames = null; switch (fileType) { case ImageTypes.TEXTURE: TextureFile textureFile = new TextureFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); textureFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, textureFile.PaletteName)); dfBitmap = textureFile.GetDFBitmap(record, frame); int frameCount = textureFile.GetFrameCount(record); if (createAllFrameTextures && frameCount > 1) { dfBitmapAllFrames = new DFBitmap[frameCount]; for (int i = 0; i < frameCount; i++) { dfBitmapAllFrames[i] = textureFile.GetDFBitmap(record, i); } } imageData.offset = textureFile.GetOffset(record); imageData.scale = textureFile.GetScale(record); imageData.size = textureFile.GetSize(record); // Texture pack support int archive = AssetInjection.TextureReplacement.FileNameToArchive(filename); if (createTexture && AssetInjection.TextureReplacement.TryImportTexture(archive, record, frame, out imageData.texture)) { createTexture = false; } if (createAllFrameTextures && frameCount > 1 && AssetInjection.TextureReplacement.TryImportTexture(archive, record, out imageData.animatedTextures)) { createAllFrameTextures = false; } break; case ImageTypes.IMG: ImgFile imgFile = new ImgFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); imgFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, imgFile.PaletteName)); dfBitmap = imgFile.GetDFBitmap(); imageData.offset = imgFile.ImageOffset; imageData.scale = new DFSize(); imageData.size = imgFile.GetSize(0); // Texture pack support if (createTexture && AssetInjection.TextureReplacement.TryImportImage(filename, false, out imageData.texture)) { createTexture = false; } break; case ImageTypes.CIF: case ImageTypes.RCI: CifRciFile cifFile = new CifRciFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); cifFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, cifFile.PaletteName)); dfBitmap = cifFile.GetDFBitmap(record, frame); imageData.offset = cifFile.GetOffset(record); imageData.scale = new DFSize(); imageData.size = cifFile.GetSize(record); // Texture pack support if (createTexture && AssetInjection.TextureReplacement.TryImportCifRci(filename, record, frame, false, out imageData.texture)) { createTexture = false; } break; case ImageTypes.CFA: CfaFile cfaFile = new CfaFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); cfaFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, cfaFile.PaletteName)); dfBitmap = cfaFile.GetDFBitmap(record, frame); imageData.offset = new DFPosition(0, 0); imageData.scale = new DFSize(); imageData.size = cfaFile.GetSize(record); // Texture pack support if (createTexture && AssetInjection.TextureReplacement.TryImportCifRci(filename, record, frame, false, out imageData.texture)) { createTexture = false; } break; case ImageTypes.BSS: BssFile bssFile = new BssFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); bssFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, bssFile.PaletteName)); dfBitmap = bssFile.GetDFBitmap(record, frame); imageData.offset = new DFPosition(0, 0); imageData.scale = new DFSize(); imageData.size = bssFile.GetSize(record); // Texture pack support if (createTexture && AssetInjection.TextureReplacement.TryImportCifRci(filename, record, frame, false, out imageData.texture)) { createTexture = false; } break; case ImageTypes.GFX: GfxFile gfxFile = new GfxFile(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); gfxFile.LoadPalette(Path.Combine(dfUnity.Arena2Path, gfxFile.PaletteName)); dfBitmap = gfxFile.GetDFBitmap(record, frame); imageData.offset = new DFPosition(0, 0); imageData.scale = new DFSize(); imageData.size = gfxFile.GetSize(record); // Texture pack support if (createTexture && AssetInjection.TextureReplacement.TryImportCifRci(filename, record, frame, false, out imageData.texture)) { createTexture = false; } break; default: return(new ImageData()); } // Store bitmap imageData.dfBitmap = dfBitmap; imageData.width = dfBitmap.Width; imageData.height = dfBitmap.Height; // Create Texture2D if (createTexture) { // Get colors array Color32[] colors = GetColors(imageData); if (colors == null) { return(new ImageData()); } // Create new Texture2D imageData.texture = GetTexture(colors, imageData.width, imageData.height); } // Create animated Texture2D frames if (createAllFrameTextures && dfBitmapAllFrames != null) { imageData.animatedTextures = new Texture2D[dfBitmapAllFrames.Length]; for (int i = 0; i < dfBitmapAllFrames.Length; i++) { ImageData curFrame = imageData; curFrame.dfBitmap = dfBitmapAllFrames[i]; Color32[] colors = GetColors(curFrame); imageData.animatedTextures[i] = GetTexture(colors, imageData.width, imageData.height); } } return(imageData); }
/// <summary> /// Index all files of specified library type. /// </summary> /// <param name="FilePaths">Array of absolute paths to files.</param> /// <param name="Type">Library type.</param> /// <returns></returns> private bool IndexLibrary(ref string[] FilePaths, LibraryTypes Type) { // Create file name arrays switch (Type) { case LibraryTypes.Texture: TextureFileNames = new string[(FilePaths.Length - Arena2.TextureFile.UnsupportedFilenames.Length)]; break; case LibraryTypes.Img: ImgFileNames = new string[(FilePaths.Length - Arena2.TextureFile.UnsupportedFilenames.Length)]; break; case LibraryTypes.Cif: CifFileNames = new string[FilePaths.Length]; break; case LibraryTypes.Rci: RciFileNames = new string[FilePaths.Length]; break; case LibraryTypes.Sky: SkyFileNames = new string[FilePaths.Length]; break; } // Index and hash files int Index = 0; TextureFile TextureFile = new TextureFile(); ImgFile ImgFile = new ImgFile(); foreach (string FilePath in FilePaths) { // Get filename only string FileName = Path.GetFileName(FilePath); // Handle unsupported TEXTURE files if (LibraryTypes.Texture == Type) { if (!TextureFile.IsFilenameSupported(FileName)) { continue; } } // Handle unsupported IMG files if (LibraryTypes.Img == Type) { if (!ImgFile.IsFilenameSupported(FileName)) { continue; } } // Store file name in array switch (Type) { case LibraryTypes.Texture: TextureFileNames[Index] = FileName; break; case LibraryTypes.Img: ImgFileNames[Index] = FileName; break; case LibraryTypes.Cif: CifFileNames[Index] = FileName; break; case LibraryTypes.Rci: RciFileNames[Index] = FileName; break; case LibraryTypes.Sky: SkyFileNames[Index] = FileName; break; } // Create file item ImageFileItem Item = new ImageFileItem(); Item.FileName = FileName; Item.LibraryType = Type; Item.ImageFile = null; // Add file item based on type switch (Type) { case LibraryTypes.Texture: TextureFileItems.Add(Item); break; case LibraryTypes.Img: ImgFileItems.Add(Item); break; case LibraryTypes.Cif: CifFileItems.Add(Item); break; case LibraryTypes.Rci: RciFileItems.Add(Item); break; case LibraryTypes.Sky: SkyFileItems.Add(Item); break; } // Hash file index based on type switch (Type) { case LibraryTypes.Texture: TextureHashtable.Add(FileName, Index); break; case LibraryTypes.Img: ImgHashtable.Add(FileName, Index); break; case LibraryTypes.Cif: CifHashtable.Add(FileName, Index); break; case LibraryTypes.Rci: RciHashtable.Add(FileName, Index); break; case LibraryTypes.Sky: SkyHashtable.Add(FileName, Index); break; } // Increment index Index++; } return(true); }
public PhysicsImg(string path) { this.imgFile = new ImgFile(path); }