2019-05-09 18:49:11 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-07-16 21:35:21 +00:00
|
|
|
|
using Toolbox;
|
2019-05-09 18:49:11 +00:00
|
|
|
|
using System.Windows.Forms;
|
2019-07-16 21:35:21 +00:00
|
|
|
|
using Toolbox.Library;
|
|
|
|
|
using Toolbox.Library.Forms;
|
2019-05-09 18:49:11 +00:00
|
|
|
|
using BcresLibrary;
|
2019-05-11 17:10:39 +00:00
|
|
|
|
using FirstPlugin.Forms;
|
|
|
|
|
using GL_EditorFramework.Interfaces;
|
2019-05-09 18:49:11 +00:00
|
|
|
|
|
|
|
|
|
namespace FirstPlugin
|
|
|
|
|
{
|
|
|
|
|
public class BCRES : TreeNodeFile, IFileFormat
|
|
|
|
|
{
|
|
|
|
|
public FileType FileType { get; set; } = FileType.Layout;
|
|
|
|
|
|
|
|
|
|
public bool CanSave { get; set; }
|
|
|
|
|
public string[] Description { get; set; } = new string[] { "BCRES" };
|
2019-07-25 20:49:04 +00:00
|
|
|
|
public string[] Extension { get; set; } = new string[] { "*.bcres", "*.cgfx" };
|
2019-05-09 18:49:11 +00:00
|
|
|
|
public string FileName { get; set; }
|
|
|
|
|
public string FilePath { get; set; }
|
|
|
|
|
public IFileInfo IFileInfo { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool Identify(System.IO.Stream stream)
|
|
|
|
|
{
|
2019-07-16 21:35:21 +00:00
|
|
|
|
using (var reader = new Toolbox.Library.IO.FileReader(stream, true))
|
2019-05-09 18:49:11 +00:00
|
|
|
|
{
|
|
|
|
|
return reader.CheckSignature(4, "CGFX");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type[] Types
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
List<Type> types = new List<Type>();
|
|
|
|
|
return types.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BcresFile BcresFile;
|
2019-05-10 21:51:59 +00:00
|
|
|
|
public BCRES_Render RenderedBcres;
|
2019-06-06 19:40:32 +00:00
|
|
|
|
public DrawableContainer DrawableContainer = new DrawableContainer();
|
2019-05-09 18:49:11 +00:00
|
|
|
|
|
|
|
|
|
public void Load(System.IO.Stream stream)
|
|
|
|
|
{
|
|
|
|
|
Text = FileName;
|
|
|
|
|
BcresFile = new BcresFile(stream);
|
2019-05-10 21:51:59 +00:00
|
|
|
|
RenderedBcres = new BCRES_Render();
|
2019-05-09 18:49:11 +00:00
|
|
|
|
|
2019-06-06 19:40:32 +00:00
|
|
|
|
DrawableContainer.Name = FileName;
|
|
|
|
|
DrawableContainer.Drawables.Add(RenderedBcres);
|
|
|
|
|
|
2019-05-09 18:49:11 +00:00
|
|
|
|
AddNodeGroup(BcresFile.Data.Models, new BCRESGroupNode(BCRESGroupType.Models));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.Textures, new BCRESGroupNode(BCRESGroupType.Textures));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.Lookups, new BCRESGroupNode(BCRESGroupType.Lookups));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.Shaders, new BCRESGroupNode(BCRESGroupType.Shaders));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.Cameras, new BCRESGroupNode(BCRESGroupType.Cameras));
|
2019-05-13 19:29:40 +00:00
|
|
|
|
AddNodeGroup(BcresFile.Data.Lights, new BCRESGroupNode(BCRESGroupType.Lights));
|
2019-05-09 18:49:11 +00:00
|
|
|
|
AddNodeGroup(BcresFile.Data.Fogs, new BCRESGroupNode(BCRESGroupType.Fogs));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.Scenes, new BCRESGroupNode(BCRESGroupType.Scenes));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.SkeletalAnims, new BCRESGroupNode(BCRESGroupType.SkeletalAnim));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.MaterialAnims, new BCRESGroupNode(BCRESGroupType.MaterialAnim));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.VisibiltyAnims, new BCRESGroupNode(BCRESGroupType.VisibiltyAnim));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.CameraAnims, new BCRESGroupNode(BCRESGroupType.CameraAnim));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.LightAnims, new BCRESGroupNode(BCRESGroupType.LightAnim));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.EmitterAnims, new BCRESGroupNode(BCRESGroupType.EmitterAnim));
|
|
|
|
|
AddNodeGroup(BcresFile.Data.Particles, new BCRESGroupNode(BCRESGroupType.Particles));
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-12 02:05:18 +00:00
|
|
|
|
public override void OnClick(TreeView treeview) {
|
|
|
|
|
LoadEditors(this, null);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-09 18:49:11 +00:00
|
|
|
|
private void AddNodeGroup<T>(ResDict<T> SubSections, BCRESGroupNode Folder)
|
|
|
|
|
where T : CtrObject, new()
|
|
|
|
|
{
|
|
|
|
|
if (SubSections == null || SubSections.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Nodes.Add(Folder);
|
|
|
|
|
|
|
|
|
|
foreach (CtrObject section in SubSections.Values)
|
|
|
|
|
{
|
|
|
|
|
switch (Folder.Type)
|
|
|
|
|
{
|
|
|
|
|
case BCRESGroupType.Models:
|
2019-05-10 21:51:59 +00:00
|
|
|
|
var CMDLWrapper = new CMDLWrapper((Model)section, this);
|
|
|
|
|
Folder.AddNode(CMDLWrapper);
|
|
|
|
|
RenderedBcres.Models.Add(CMDLWrapper);
|
2019-05-09 18:49:11 +00:00
|
|
|
|
break;
|
|
|
|
|
case BCRESGroupType.Textures:
|
2019-05-09 20:14:42 +00:00
|
|
|
|
Folder.AddNode(new TXOBWrapper((Texture)section, this));
|
2019-05-11 22:17:35 +00:00
|
|
|
|
PluginRuntime.bcresTexContainers.Add(Folder);
|
2019-05-09 18:49:11 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 19:40:32 +00:00
|
|
|
|
private bool DrawablesLoaded;
|
2019-05-09 20:05:17 +00:00
|
|
|
|
public void LoadEditors(TreeNode Wrapper, Action OnPropertyChanged)
|
|
|
|
|
{
|
2019-07-11 21:22:59 +00:00
|
|
|
|
BcresEditor bcresEditor = (BcresEditor)LibraryGUI.GetActiveContent(typeof(BcresEditor));
|
2019-05-11 17:10:39 +00:00
|
|
|
|
bool HasModels = RenderedBcres.Models.Count > 0;
|
|
|
|
|
if (bcresEditor == null)
|
|
|
|
|
{
|
|
|
|
|
bcresEditor = new BcresEditor(HasModels);
|
|
|
|
|
bcresEditor.Dock = DockStyle.Fill;
|
2019-07-11 21:22:59 +00:00
|
|
|
|
LibraryGUI.LoadEditor(bcresEditor);
|
2019-05-11 17:10:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 19:40:32 +00:00
|
|
|
|
if (!DrawablesLoaded)
|
2019-05-11 17:10:39 +00:00
|
|
|
|
{
|
2019-06-06 19:40:32 +00:00
|
|
|
|
ObjectEditor.AddContainer(DrawableContainer);
|
2019-05-11 17:10:39 +00:00
|
|
|
|
|
|
|
|
|
for (int m = 0; m < RenderedBcres.Models.Count; m++)
|
2019-05-11 20:11:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (RenderedBcres.Models[m].Skeleton.Renderable != null)
|
2019-06-06 19:40:32 +00:00
|
|
|
|
DrawableContainer.Drawables.Add(RenderedBcres.Models[m].Skeleton.Renderable);
|
2019-05-11 20:11:27 +00:00
|
|
|
|
}
|
2019-06-06 19:40:32 +00:00
|
|
|
|
|
|
|
|
|
DrawablesLoaded = true;
|
2019-05-11 17:10:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Runtime.UseOpenGL)
|
2019-06-06 19:40:32 +00:00
|
|
|
|
bcresEditor.LoadViewport(this, DrawableContainer);
|
2019-05-11 17:10:39 +00:00
|
|
|
|
|
2019-05-12 00:05:27 +00:00
|
|
|
|
if (Wrapper is BcresTextureMapWrapper)
|
|
|
|
|
{
|
|
|
|
|
BcresSamplerEditorSimple editor = (BcresSamplerEditorSimple)bcresEditor.GetActiveEditor(typeof(BcresSamplerEditorSimple));
|
|
|
|
|
if (editor == null)
|
|
|
|
|
{
|
|
|
|
|
editor = new BcresSamplerEditorSimple();
|
|
|
|
|
editor.Dock = DockStyle.Fill;
|
|
|
|
|
bcresEditor.LoadEditor(editor);
|
|
|
|
|
}
|
|
|
|
|
editor.LoadTexture(((BcresTextureMapWrapper)Wrapper));
|
|
|
|
|
}
|
2019-05-12 02:05:18 +00:00
|
|
|
|
else if (Wrapper is BCRES) {
|
|
|
|
|
LoadPropertyGrid(((BCRES)Wrapper).BcresFile, bcresEditor, OnPropertyChanged);
|
|
|
|
|
}
|
2019-05-12 00:05:27 +00:00
|
|
|
|
else if (Wrapper is MTOBWrapper) {
|
2019-05-11 17:10:39 +00:00
|
|
|
|
LoadPropertyGrid(((MTOBWrapper)Wrapper).Material, bcresEditor, OnPropertyChanged);
|
2019-05-09 20:05:17 +00:00
|
|
|
|
}
|
2019-05-12 00:05:27 +00:00
|
|
|
|
else if (Wrapper is CMDLWrapper) {
|
2019-05-11 17:10:39 +00:00
|
|
|
|
LoadPropertyGrid(((CMDLWrapper)Wrapper).Model, bcresEditor, OnPropertyChanged);
|
2019-05-09 20:05:17 +00:00
|
|
|
|
}
|
2019-05-12 00:05:27 +00:00
|
|
|
|
else if (Wrapper is CRESBoneWrapper) {
|
2019-05-11 17:10:39 +00:00
|
|
|
|
LoadPropertyGrid(((CRESBoneWrapper)Wrapper).Bone, bcresEditor, OnPropertyChanged);
|
2019-05-10 23:26:45 +00:00
|
|
|
|
}
|
2019-05-12 00:05:27 +00:00
|
|
|
|
else if (Wrapper is CRESSkeletonWrapper) {
|
2019-05-11 17:10:39 +00:00
|
|
|
|
LoadPropertyGrid(((CRESSkeletonWrapper)Wrapper).Skeleton, bcresEditor, OnPropertyChanged);
|
2019-05-10 23:26:45 +00:00
|
|
|
|
}
|
2019-05-09 20:05:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-11 17:10:39 +00:00
|
|
|
|
private void LoadPropertyGrid(object property, BcresEditor bcresEditor, Action OnPropertyChanged)
|
2019-05-09 20:05:17 +00:00
|
|
|
|
{
|
2019-05-11 17:10:39 +00:00
|
|
|
|
STPropertyGrid editor = (STPropertyGrid)bcresEditor.GetActiveEditor(typeof(STPropertyGrid));
|
2019-05-09 20:05:17 +00:00
|
|
|
|
if (editor == null)
|
|
|
|
|
{
|
|
|
|
|
editor = new STPropertyGrid();
|
|
|
|
|
editor.Dock = DockStyle.Fill;
|
2019-05-11 17:10:39 +00:00
|
|
|
|
bcresEditor.LoadEditor(editor);
|
2019-05-09 20:05:17 +00:00
|
|
|
|
}
|
|
|
|
|
editor.LoadProperty(property, OnPropertyChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-09 18:49:11 +00:00
|
|
|
|
public void Unload()
|
|
|
|
|
{
|
2019-06-06 19:40:32 +00:00
|
|
|
|
ObjectEditor.RemoveContainer(DrawableContainer);
|
2019-05-09 18:49:11 +00:00
|
|
|
|
}
|
2019-08-06 21:35:18 +00:00
|
|
|
|
|
|
|
|
|
public void Save(System.IO.Stream stream)
|
2019-05-09 18:49:11 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|