public Texture2D CreateTexture(BSPLoader.dmiptex_t tex, int structOffset) { int num = this.Header.lumps[2].fileofs + structOffset; Texture2D texture2D = new Texture2D(tex.width, tex.height, TextureFormat.RGBA32, true); int num2 = tex.offsets[3] + tex.width / 8 * (tex.height / 8) + 2; Color32[] array = new Color32[256]; this.BR.BaseStream.Seek((long)(num2 + num), SeekOrigin.Begin); for (int i = 0; i < 256; i++) { array[i] = new Color32(this.BR.ReadByte(), this.BR.ReadByte(), this.BR.ReadByte(), 255); if (array[i] == Color.blue) { array[i] = Color.clear; } } texture2D.name = tex.name; Color32[] array2 = new Color32[tex.width * tex.height]; this.BR.BaseStream.Seek((long)(num + tex.offsets[0]), SeekOrigin.Begin); for (int j = 0; j < tex.width * tex.height; j++) { int num3 = (int)this.BR.ReadByte(); array2[j] = array[num3]; } texture2D.SetPixels32(array2); texture2D.filterMode = FilterMode.Bilinear; texture2D.Apply(); return texture2D; }
private void Awake() { GameManager.Ins = this; this.pl = GameObject.FindWithTag("Player"); this.BSP = base.GetComponent<BSPLoader>(); if (!this.debug) { this.patch = Application.persistentDataPath; } }
/// <summary> /// Draws a button to start the import process. /// </summary> protected virtual void DrawImportButton() { if (GUILayout.Button("Import")) { BSPLoader loader = new BSPLoader() { settings = settings }; loader.LoadBSP(); } }
public IReadOnlyList<IModel> Load(string name, IFileSystem fileSystem, Scene scene, BinaryReader reader, bool computeCRC) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } //Check if we can actually load this //TODO: because BSP files don't have a separate identifier, this will fail on invalid BSP versions //Should remove this once the other formats can be loaded if (!BSPLoader.IsBSPFile(reader)) { return null; } var loader = new BSPLoader(reader); var bspFile = loader.ReadBSPFile(); uint crc = 0; if (computeCRC) { crc = loader.ComputeCRC(); } var hull0 = MakeHull0(bspFile); var models = new BSPModel[bspFile.Models.Count]; models[0] = new BSPModel(name, crc, bspFile, bspFile.Models[0], hull0); //add all of its submodels //First submodel (0) is the world for (var i = 1; i < bspFile.Models.Count; ++i) { models[i] = new BSPModel($"{_bspModelNamePrefix}{i}", crc, bspFile, bspFile.Models[i], hull0); } if (scene != null) { foreach (var model in models) { model.ResourceContainer = new BSPModelResourceContainer(scene, model); scene.AddContainer(model.ResourceContainer); } } return models; }
public IModel Load(string name, IFileSystem fileSystem, BinaryReader reader, Delegates.AddModel addModelCallback, bool computeCRC) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } //Check if we can actually load this //TODO: because BSP files don't have a separate identifier, this will fail on invalid BSP versions //Should remove this once the other formats can be loaded if (!BSPLoader.IsBSPFile(reader)) { return(null); } var loader = new BSPLoader(reader); var bspFile = loader.ReadBSPFile(); uint crc = 0; if (computeCRC) { crc = loader.ComputeCRC(); } var hull0 = MakeHull0(bspFile); //add all of its submodels //First submodel (0) is the world for (var i = 1; i < bspFile.Models.Count; ++i) { var subModelName = $"{_bspModelNamePrefix}{i}"; addModelCallback(subModelName, new BSPModel(subModelName, crc, bspFile, bspFile.Models[i], hull0)); } return(new BSPModel(name, crc, bspFile, bspFile.Models[0], hull0)); }
public BSPMeshComponent(Asset asset) { bspLoader = new BSPLoader(asset); }
private Texture2D CreateLightmapTex(BSPLoader.face f) { Texture2D texture2D = new Texture2D(f.lightMapW, f.lightMapH, TextureFormat.RGBA32, false); Color32[] array = new Color32[f.lightMapW * f.lightMapH]; int lightofs = this.facesLump[f.index].lightofs; int num = 0; for (int i = 0; i < f.lightMapW * f.lightMapH; i++) { byte r = this.lightingLump[lightofs + num++]; byte g = this.lightingLump[lightofs + num++]; byte b = this.lightingLump[lightofs + num++]; array[i] = new Color32(r, g, b, 255); } texture2D.SetPixels32(array); texture2D.Apply(); return texture2D; }