public bool RevertMod(RspManipulation m) { #if USE_CMP if (Manipulations.Remove(m)) { var def = CmpFile.GetDefault(m.SubRace, m.Attribute); var manip = new RspManipulation(m.SubRace, m.Attribute, def); return(manip.Apply(File !)); } #endif return(false); }
public Texture FindTexture(string name) { if (name == NullTextureName) { return(NullTexture); } if (name == WhiteTextureName) { return(WhiteTexture); } Texture outtex; if ((outtex = textures[name]) == null) { var file = texturefiles[name]; FLLog.Debug("Resources", string.Format("Reloading {0} from {1}", name, file)); if (file.EndsWith(".mat", StringComparison.OrdinalIgnoreCase)) { loadedMatFiles.Remove(file); LoadMat(file); } else if (file.EndsWith(".cmp", StringComparison.OrdinalIgnoreCase)) { var c = new CmpFile(file, this); if (c.MaterialLibrary != null) { AddMaterials(c.MaterialLibrary, file); } AddTextures(c.TextureLibrary, file); } else if (file.EndsWith(".3db", StringComparison.OrdinalIgnoreCase)) { var m = new ModelFile(file, this); if (m.MaterialLibrary != null) { AddMaterials(m.MaterialLibrary, file); } AddTextures(m.TextureLibrary, file); } else if (file.EndsWith(".txm", StringComparison.OrdinalIgnoreCase)) { loadedTxmFiles.Remove(file); LoadTxm(file); } else { textures[name] = ImageLib.Generic.FromFile(file); } outtex = textures[name]; } return(outtex); }
ConstructNode GetNodeCmp(CmpFile c, AbstractConstruct con) { var node = new ConstructNode() { Con = con }; foreach (var p in c.Parts) { if (p.Value.Construct == con) { node.Model = p.Value.Model; } } return(node); }
public void Write(DirectoryInfo dir, GamePath originalPath) { var data = Data switch { EqdpFile eqdp => eqdp.WriteBytes(), EqpFile eqp => eqp.WriteBytes(), GmpFile gmp => gmp.WriteBytes(), EstFile est => est.WriteBytes(), ImcFile imc => imc.WriteBytes(), CmpFile cmp => cmp.WriteBytes(), _ => throw new NotImplementedException(), }; DisposeFile(CurrentFile); CurrentFile = TempFile.WriteNew(dir, data, $"_{originalPath.Filename()}"); Changed = false; }
public CmpFile GetCmp(string filename) { if (!cmps.ContainsKey(filename)) { var file = new CmpFile(filename, this); if (file.TextureLibrary != null) { AddTextures(file.TextureLibrary, filename); } if (file.MaterialLibrary != null) { AddMaterials(file.MaterialLibrary, filename); } if (file.VMeshLibrary != null) { AddMeshes(file.VMeshLibrary); } file.Initialize(this); cmps.Add(filename, file); } return(cmps [filename]); }
ConstructNode GetNodeCmp(CmpFile c, AbstractConstruct con) { var node = new ConstructNode() { Con = con }; foreach (var p in c.Parts) { if (p.Construct == con) { node.Camera = p.Camera; if (node.Camera == null) { node.Model = p.Model; } else if (p.ObjectName.Equals("cockpit cam", StringComparison.OrdinalIgnoreCase)) { cameraPart = p; } } } return(node); }
public static void ExportCollada(CmpFile cmp, ResourceManager resources, string output) { //Build tree InputModel rootModel = null; List <InputModel> parentModels = new List <InputModel>(); foreach (var p in cmp.Parts) { if (p.Construct == null) { rootModel = new InputModel() { Transform = Matrix4x4.Identity, Model = p.Model, Con = "Root" }; break; } } parentModels.Add(rootModel); var q = new Queue <Part>(cmp.Parts); int infiniteDetect = 0; while (q.Count > 0) { var part = q.Dequeue(); if (part.Construct == null) { continue; } bool enqueue = true; foreach (var mdl in parentModels) { if (part.Construct.ParentName == mdl.Con) { var child = new InputModel() { Transform = part.Construct.Rotation * Matrix4x4.CreateTranslation(part.Construct.Origin), Model = part.Model, Con = part.Construct.ChildName }; mdl.Children.Add(child); parentModels.Add(child); enqueue = false; break; } } if (enqueue) { q.Enqueue(part); } infiniteDetect++; if (infiniteDetect > 200000000) { throw new Exception("Infinite cmp loop detected"); } } //Build collada var dae = NewCollada(); var efx = new CL.library_effects(); var mats = new CL.library_materials(); var geos = new CL.library_geometries(); var scenes = new CL.library_visual_scenes(); var vscene = new CL.visual_scene(); vscene.name = vscene.id = "main-scene"; scenes.visual_scene = new CL.visual_scene[] { vscene }; dae.scene = new CL.COLLADAScene(); dae.scene.instance_visual_scene = new CL.InstanceWithExtra() { url = "#main-scene" }; var glist = new List <CL.geometry>(); var mlist = new List <string>(); var matlist = new List <ExportMaterial>(); BuildModel(resources, rootModel, glist, mlist, matlist); geos.geometry = glist.ToArray(); mats.material = mlist.Select((x) => new CL.material() { name = x, id = x + "-material", instance_effect = new CL.instance_effect() { url = "#" + x + "-effect" } }).ToArray(); efx.effect = matlist.Select((x) => new CL.effect() { id = x.Name + "-effect", Items = new[] { new CL.effectFx_profile_abstractProfile_COMMON() { technique = new CL.effectFx_profile_abstractProfile_COMMONTechnique() { id = "common", sid = "common", Item = new CL.effectFx_profile_abstractProfile_COMMONTechniquePhong() { ambient = ColladaColor("ambient", Color4.Black), emission = ColladaColor("emmision", Color4.Black), diffuse = ColladaColor("diffuse", x.Dc), specular = ColladaColor("specular", new Color4(0.25f, 0.25f, 0.25f, 1f)), shininess = ColladaFloat("shininess", 50), index_of_refraction = ColladaFloat("index_of_refraction", 1) } } } } }).ToArray(); var rootNodes = new List <CL.node>(); BuildNodes(rootModel, rootNodes); vscene.node = rootNodes.ToArray(); dae.Items = new object[] { efx, mats, geos, scenes }; using (var stream = File.Create(output)) _xml.Serialize(stream, dae); }
public ModelRenderer(List <Part> drawable, CmpFile parent) { CmpParts = drawable; _parentCmp = parent; }
// Parse a single rgsp file. public static TexToolsMeta FromRgspFile(string filePath, byte[] data) { if (data.Length != 45 && data.Length != 42) { PluginLog.Error("Error while parsing .rgsp file:\n\tInvalid number of bytes."); return(Invalid); } using var s = new MemoryStream(data); using var br = new BinaryReader(s); // The first value is a flag that signifies version. // If it is byte.max, the following two bytes are the version, // otherwise it is version 1 and signifies the sub race instead. var flag = br.ReadByte(); var version = flag != 255 ? ( uint )1 : br.ReadUInt16(); var ret = new TexToolsMeta(filePath, version); // SubRace is offset by one due to Unknown. var subRace = ( SubRace )(version == 1 ? flag + 1 : br.ReadByte() + 1); if (!Enum.IsDefined(typeof(SubRace), subRace) || subRace == SubRace.Unknown) { PluginLog.Error($"Error while parsing .rgsp file:\n\t{subRace} is not a valid SubRace."); return(Invalid); } // Next byte is Gender. 1 is Female, 0 is Male. var gender = br.ReadByte(); if (gender != 1 && gender != 0) { PluginLog.Error($"Error while parsing .rgsp file:\n\t{gender} is neither Male nor Female."); return(Invalid); } // Add the given values to the manipulations if they are not default. void Add(RspAttribute attribute, float value) { var def = CmpFile.GetDefault(subRace, attribute); if (value != def) { ret.MetaManipulations.Add(new RspManipulation(subRace, attribute, value)); } } if (gender == 1) { Add(RspAttribute.FemaleMinSize, br.ReadSingle()); Add(RspAttribute.FemaleMaxSize, br.ReadSingle()); Add(RspAttribute.FemaleMinTail, br.ReadSingle()); Add(RspAttribute.FemaleMaxTail, br.ReadSingle()); Add(RspAttribute.BustMinX, br.ReadSingle()); Add(RspAttribute.BustMinY, br.ReadSingle()); Add(RspAttribute.BustMinZ, br.ReadSingle()); Add(RspAttribute.BustMaxX, br.ReadSingle()); Add(RspAttribute.BustMaxY, br.ReadSingle()); Add(RspAttribute.BustMaxZ, br.ReadSingle()); } else { Add(RspAttribute.MaleMinSize, br.ReadSingle()); Add(RspAttribute.MaleMaxSize, br.ReadSingle()); Add(RspAttribute.MaleMinTail, br.ReadSingle()); Add(RspAttribute.MaleMaxTail, br.ReadSingle()); } return(ret); }