public SceneAnimFolder(BFRES bfres, ResFile resFile, ResDict <SceneAnim> resDict) { foreach (SceneAnim anim in resDict.Values) { var node = new BfresNodeBase(anim.Name); AddChild(node); foreach (CameraAnim camAnim in anim.CameraAnims.Values) { var camnode = new BfresNodeBase(camAnim.Name); camnode.Tag = new BfresCameraAnim(camAnim); node.AddChild(camnode); } foreach (LightAnim lightAnim in anim.LightAnims.Values) { var camnode = new BfresNodeBase(lightAnim.Name); node.AddChild(camnode); } foreach (FogAnim fogAnim in anim.FogAnims.Values) { var camnode = new BfresNodeBase(fogAnim.Name); node.AddChild(camnode); } } }
public TextureFolder(BFRES bfres, ResFile resFile, ResDict <TextureShared> resDict, ExternalFile externalTextureFile) { if (externalTextureFile != null) { var bntxFile = externalTextureFile.LoadedFileData as BntxFile; Tag = new BntxWrapper(bntxFile); } List <TextureAsset> assetList = new List <TextureAsset>(); foreach (TextureShared tex in resDict.Values) { var node = new BfresNodeBase(tex.Name); node.Icon = "/Images/Texture.png"; AddChild(node); if (tex is BfresLibrary.WiiU.Texture) { FtexTexture ftex = new FtexTexture(resFile, (BfresLibrary.WiiU.Texture)tex); bfres.Textures.Add(ftex); node.Tag = ftex; assetList.Add(ftex.TextureAsset); } else { var texture = (BfresLibrary.Switch.SwitchTexture)tex; BntxTexture bntxTexture = new BntxTexture(texture.BntxFile, texture.Texture); bfres.Textures.Add(bntxTexture); node.Tag = bntxTexture; } } }
//Temporary loader atm for map objects to cache quickly and easily public static BfresRender LoadFile(string filePath) { if (!DataCache.ModelCache.ContainsKey(filePath)) { BFRES bfres = new BFRES() { FileInfo = new File_Info() }; bfres.Load(System.IO.File.OpenRead(filePath)); bfres.Renderer.Name = filePath; DataCache.ModelCache.Add(filePath, bfres.Renderer); return((BfresRender)bfres.Renderer); } else { var cached = (BfresRender)DataCache.ModelCache[filePath]; var render = new BfresRender(); render.Name = filePath; render.Models.AddRange(cached.Models); foreach (var tex in cached.Textures) { render.Textures.Add(tex.Key, tex.Value); } return(render); } }
public FMAT(BFRES bfres, FMDL fmdl, Model model, Material material) { Init(); ParentFile = bfres; Material = material; ParentModel = model; ParentBfresModel = fmdl; Reload(material); }
public EmbeddedFolder(BFRES bfres, ResFile resFile, ResDict <ExternalFile> resDict) { foreach (var file in resDict) { var node = new BfresNodeBase(file.Key); node.Tag = new BfresExternalFile(file.Value, file.Key); AddChild(node); } }
/// <summary> /// Searches for the shader archive file in external files, parent archive, and the global shader cache. /// </summary> /// <returns></returns> public virtual SHARCFB TryLoadShaderArchive(BFRES bfres, string shaderFile, string shaderModel) { //Check external files. bfres.UpdateExternalShaderFiles(); foreach (var file in bfres.ShaderFiles) { if (file is SHARCFB && ((SHARCFB)file).Name.Contains(shaderFile)) { ShaderFileState = ShaderState.EmbeddedResource; return((SHARCFB)file); } } //Check global shader cache foreach (var file in GlobalShaderCache.ShaderFiles.Values) { if (file is SHARCFB) { if (((SHARCFB)file).Name.Contains(shaderFile)) { ShaderFileState = ShaderState.Global; return((SHARCFB)file); } } } //Check external archives parenting the file. var archiveFile = bfres.FileInfo.ParentArchive; if (archiveFile == null) { return(null); } foreach (var file in archiveFile.Files) { if (!file.FileName.EndsWith(".sharcfb")) { continue; } if (file.FileName == shaderFile || HasFileName(file.FileData, shaderFile)) { if (file.FileFormat == null) { file.FileFormat = file.OpenFile(); } ShaderFileState = ShaderState.EmbeddedArchive; return((SHARCFB)file.FileFormat); } } return(null); }
public ShapeAnimFolder(BFRES bfres, ResFile resFile, ResDict <ShapeAnim> resDict) { foreach (ShapeAnim anim in resDict.Values) { var node = new BfresNodeBase(anim.Name); AddChild(node); var fsha = new BfresShapeAnim(anim, resFile.Name); node.Tag = fsha; bfres.ShapeAnimations.Add(fsha); } }
public TexturePatternAnimFolder(BFRES bfres, ResFile resFile, ResDict <MaterialAnim> resDict) { foreach (MaterialAnim anim in resDict.Values) { var node = new BfresNodeBase(anim.Name); AddChild(node); var fsha = new BfresMaterialAnim(anim, resFile.Name); node.Tag = fsha; bfres.MaterialAnimations.Add(fsha); } }
public ShaderParamAnimFolder(BFRES bfres, ResFile resFile, ResDict <MaterialAnim> resDict) { foreach (MaterialAnim anim in resDict.Values) { var node = new BfresNodeBase(anim.Name); AddChild(node); var fmaa = new BfresMaterialAnim(anim, resFile.Name); node.Tag = fmaa; bfres.MaterialAnimations.Add(fmaa); } }
public BoneVisibilityAnimFolder(BFRES bfres, ResFile resFile, ResDict <VisibilityAnim> resDict) { foreach (VisibilityAnim anim in resDict.Values) { var node = new BfresNodeBase(anim.Name); AddChild(node); var fsha = new BfresVisibilityAnim(anim, resFile.Name); node.Tag = fsha; bfres.VisibilityAnimations.Add(fsha); } }
public SkeletalAnimFolder(BFRES bfres, ResFile resFile, ResDict <SkeletalAnim> resDict) { foreach (SkeletalAnim anim in resDict.Values) { var node = new BfresNodeBase(anim.Name); node.Icon = "/Images/SkeletonAnimation.png"; AddChild(node); var fska = new BfresSkeletalAnim(resFile, anim, resFile.Name); node.Tag = fska; bfres.SkeletalAnimations.Add(fska); } }
/// <summary> /// Loads the material renderer for the first time. /// </summary> /// <returns></returns> public override void TryLoadShader(BFRES bfres, FMDL fmdl, FSHP mesh, BfresMeshAsset meshAsset) { var sharcfb = TryLoadShaderArchive(bfres, mesh.Material.ShaderArchive, mesh.Material.ShaderModel); if (sharcfb == null) { return; } OnLoad(sharcfb, fmdl, mesh, meshAsset); }
/// <summary> /// Searches for the shader archive file in external files, parent archive, and the global shader cache. /// </summary> /// <returns></returns> public virtual BfshaLibrary.BfshaFile TryLoadShaderArchive(BFRES bfres, string shaderFile, string shaderModel) { //Check external files. bfres.UpdateExternalShaderFiles(); foreach (var file in bfres.ShaderFiles) { if (file is BfshaLibrary.BfshaFile && ((BfshaLibrary.BfshaFile)file).Name.Contains(shaderFile)) { return((BfshaLibrary.BfshaFile)file); } } //Check global shader cache foreach (var file in GlobalShaderCache.ShaderFiles.Values) { if (file is BfshaLibrary.BfshaFile) { if (((BfshaLibrary.BfshaFile)file).Name.Contains(shaderFile)) { return((BfshaLibrary.BfshaFile)file); } } } //Check external archives parenting the file. var archiveFile = bfres.FileInfo.ParentArchive; if (archiveFile == null) { return(null); } foreach (var file in archiveFile.Files) { if (file.FileName.Contains(shaderFile)) { if (file.FileFormat == null) { file.FileFormat = file.OpenFile(); } return(((BFSHA)file.FileFormat).BfshaFile); } } return(null); }
public ModelFolder(BFRES bfres, ResFile resFile, ResDict <Model> resDict) { foreach (Model model in resDict.Values) { var node = new BfresNodeBase(model.Name); node.Icon = "/Images/Model.png"; AddChild(node); var fmdl = new FMDL(node, bfres, model); node.Tag = fmdl; bfres.Models.Add(fmdl); node.AddChild(new BfresNodeBase("Meshes")); node.AddChild(new MaterialFolder("Materials")); node.AddChild(new BfresNodeBase("Skeleton")); foreach (FSHP mesh in fmdl.Meshes) { var meshNode = new BfresNodeBase(mesh.Name) { Tag = mesh, Icon = "/Images/Mesh.png" }; mesh.ParentNode = meshNode; mesh.MeshSelected = (o, s) => { meshNode.IsSelected = (bool)o; }; node.Children[0].AddChild(meshNode); } foreach (FMAT mat in fmdl.Materials) { var matNode = new BfresNodeBase(mat.Name) { Tag = mat, Icon = ((FMAT)mat).Icon, }; mat.ParentNode = matNode; node.Children[1].AddChild(matNode); } foreach (var bone in ((FSKL)fmdl.Skeleton).CreateBoneHierarchy()) { node.Children[2].AddChild(bone); } } }
/// <summary> /// Loads the material renderer for the first time. /// </summary> /// <returns></returns> public override void TryLoadShader(BFRES bfres, FMDL fmdl, FSHP mesh, BfresMeshAsset meshAsset) { var bfsha = TryLoadShaderArchive(bfres, mesh.Material.ShaderArchive, mesh.Material.ShaderModel); if (bfsha == null) { return; } var shaderModel = bfsha.ShaderModels.Values.FirstOrDefault(x => x.Name == mesh.Material.ShaderModel); if (shaderModel != null) { OnLoad(shaderModel, fmdl, mesh, meshAsset); } }
public SHARC.ShaderProgram TryLoadSharcProgram(BFRES bfres, string shaderFile, string shaderModel) { var archiveFile = bfres.FileInfo.ParentArchive; if (archiveFile == null) { return(null); } foreach (var file in archiveFile.Files) { if (file.FileName == $"{shaderFile}.sharc") { var sharc = SHARC.Load(file.FileData); return(sharc.ShaderPrograms.FirstOrDefault(x => x.Name == shaderModel)); } } return(null); }
public void Load(BFRES bfres) { Name = bfres.Header; foreach (var model in bfres.Models) { Models.Add(new BfresModelAsset(bfres, this, model)); } foreach (var tex in bfres.Textures) { Textures.Add(tex.Name, tex); } //Update frame bounding spheres List <Vector3> positons = new List <Vector3>(); foreach (BfresModelAsset model in Models) { foreach (var mesh in model.Meshes) { for (int i = 0; i < mesh.Shape.Vertices.Count; i++) { var pos = mesh.Shape.Vertices[i].Position; if (mesh.SkinCount == 0) { var bone = model.ModelData.Skeleton.Bones[mesh.BoneIndex]; pos = Vector3.TransformPosition(pos, bone.Transform); } if (mesh.SkinCount == 1) { var index = mesh.Shape.Vertices[i].BoneIndices[0]; var bone = model.ModelData.Skeleton.Bones[index]; pos = Vector3.TransformPosition(pos, bone.Transform); } positons.Add(pos); } } } BoundingSphere = GLFrameworkEngine.Utils.BoundingSphereGenerator.GenerateBoundingSphere(positons); positons.Clear(); }
public FMDL(NodeBase node, BFRES bfres, Model model) : base() { NodeUI = node; Model = model; Skeleton = new FSKL(model.Skeleton); foreach (var shape in model.Shapes.Values) { Meshes.Add(new FSHP(bfres.ResFile, (FSKL)Skeleton, this, shape)); } foreach (var mat in model.Materials.Values) { Materials.Add(new FMAT(bfres, this, model, mat)); } foreach (FSHP shape in Meshes) { shape.Material = (FMAT)Materials[shape.Shape.MaterialIndex]; } }
public override BfshaLibrary.BfshaFile TryLoadShaderArchive(BFRES bfres, string shaderFile, string shaderModel) { return(SM3DWShaderLoader.LoadShader(shaderFile)); }
public BfresModelAsset(BFRES bfres, BfresRender render, FMDL model) { ParentRender = render; ModelData = model; Name = model.Name; List <Vector3> positons = new List <Vector3>(); foreach (FSHP mesh in model.Meshes) { //Create a mesh asset for rendering onto var meshAsset = new BfresMeshAsset(mesh); Meshes.Add(meshAsset); foreach (var customRender in BfshaRenders) { var materialRender = (ShaderRenderBase)Activator.CreateInstance(customRender); if (materialRender.UseRenderer( mesh.Material, mesh.Material.ShaderArchive, mesh.Material.ShaderModel)) { materialRender.TryLoadShader(bfres, ResModel, mesh, meshAsset); break; } } //Check for the GX2 shader decompiler as needed for Wii U games if (System.IO.File.Exists("GFD\\gx2shader-decompiler.exe")) { foreach (var customRender in SharcfbRenders) { var materialRender = (SharcFBRenderer)Activator.CreateInstance(customRender); if (materialRender.UseRenderer( mesh.Material, mesh.Material.ShaderArchive, mesh.Material.ShaderModel)) { materialRender.TryLoadShader(bfres, ResModel, mesh, meshAsset); break; } } } mesh.Material.MaterialAsset = (BfresMaterialAsset)meshAsset.MaterialAsset; ((BfresMaterialAsset)meshAsset.MaterialAsset).ParentRenderer = render; ((BfresMaterialAsset)meshAsset.MaterialAsset).ParentModel = this.ResModel; //Calculate total boundings for (int i = 0; i < mesh.Vertices.Count; i++) { positons.Add(mesh.Vertices[i].Position); } } SkeletonRenderer = new SkeletonRenderer(model.Skeleton); //Calculate the total bounding sphere BoundingSphere = GLFrameworkEngine.Utils.BoundingSphereGenerator.GenerateBoundingSphere(positons); positons.Clear(); }
/// <summary> /// Loads the material renderer for the first time. /// </summary> public virtual void TryLoadShader(BFRES bfres, FMDL fmdl, FSHP mesh, BfresMeshAsset meshAsset) { }