mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-31 11:44:47 +00:00
* Add 'Validate Skin Dimension' setting * AddNewSkin - Fix cape box not showing after skin selection * Extended ResourceLocation for better atlas handling * ModelImporter - Add block bench export for models inside models.bin * ModelIporter - Rename 'GetPivot' to 'GetSkinBoxPivot' * ModelImporter - Fix ANIM2BOX to properly support slim skin models * ModelImporter - Update BedrockModel json class * ModelImporter - Update 'FixTexture' to be more generic * Update ModelContainer API inside OMI-Lib * Update skin vertex shader to not swap yz * Update CubeMesh class * SkinRenderer - Move framebuffer and error checking function to SceneViewport * SceneViewport - Change OnUpdate parameter * SkinRenderer - Fix Highlight part having wrong transform * SkinRenderer - Move call to 'SwapBuffers' into SceneViewport.OnUpdate * AppSettingsForm - Update API to be more flexible * SkinBOXExtensions - Update 'GetUVGraphicsPath' * SkinRenderer - Update 'OnUpdate' function * SkinRenderer - Add 'LockMousePosition' option * CustomSkinEditor - Update HighlightlingColor when selecting a part * CustomSkinEditor - Add render settings * CustomSkinEditor - Small non-technical changes * SkinRenderer - Small non-technical changes * CustomSkinEditor - Load render settings when 'OnLoad' is called * SkinRenderer - Fix centering leg0/1 * SkinRenderer - Update 'ReInitialzeSkinData' to upload new data to shader * Rename 'ModelImporter' -> 'SkinModelImporter' and add api interface to add custom import/export providers * CubeGroupMesh - Fix overlay parts not showing proerly * SkinRenderer - Fix part highlighting respecting inflate * Split up model and skin importer into seperate classes and improved api * IModelImportProvider - Add 'SupportImport' and 'SupportExport' property fields * ModelImporter - Rename 'SimpleSkinImportProvider' to 'InternalImportProvider' * modelTextureLocations.json - Add todo * SkinModelImporter - Move 'ModelTextureLocations' to GameModelImporter * CustomSkinEditor - Add SettingsManager for RenderSettings * ModelImporter::Import - Check if file exists * Rename 'modelTextureLocations' to 'modelMetaData' * GameModelImporter - Change blockbench name when exporting * SettingsManager - Add functionality to create internal settings object and add settings to it * GameModelImporter - Fully implemented game-model export to block bench * AppSettingsForm - Fix re-adding settings description to default settings * AppSettingsForm - Add settings description to 'ValidateImageDimension' * GameModelImporter - Add copyright notice and remove unnecessary using statements * ModelImporter - Add copyright notice and remove unnecessary using statements * BlockBenchModel - Fix Texture class json deserialization * SkinModelImporter - Add 'TryConvertToSkinBoxType' function * modelMetaData - Remove comments * SkinModelImporter - Fix 'GetSkinBoxPivot' function * SkinModelImporter - Add null check in 'FixTexture' function * SkinModelImporter - Add offset detection when importing skin model * CustomSkinEditor - Add 'export template' button * GameModelImporter - Rename 'ModelTextureLocations' -> 'ModelMetaData' * ModelImporter - Add summary to 'SupportedModelFileFormatsFilter' property * GameModelImporter - Change function signature of 'CreateElement' * GameModelImporter - Add options to create root outline * GameModelImporter - Update Debug message in 'TraverseChildren' * MainForm - Small code refactor * Rename class 'Meta' ->'BlockBenchFormatInfo' and update BlockBenchModel.Create function signature * MainForm - Update 'GetModelTextures' local function * GameModelImporter - Check model metadata before conversion * GameModelInfo - Mark class as sealed * SkinModelImporter - Check if blockbench model uses box uv * BlockBenchModel - Add export property to class 'Element' * CustomSkinEditor - Remove unused 'PreviewImage' property * CustomSkinEditor - Change highlight color on texture * SkinModelImporter - Fix Block Bench Model import * modelMetaData - Add meta data for 1.14 models * SkinModelImporter - Update 'TryConvertToSkinBoxType' function * SkinModelExporter - Fix model export for bbmodel and bedrock model * SkinRenderer - Fix order of applying anim animations to match the game * SkinModelImporter - Fix exception thrown in 'FixTexture' * CustomSkinEditor - Add Anim editor button and fix anim not being updated when exporting * SkinModelImporter - Fix offset detection when importing * SkinModelImporter - Swap box bottom texture when texture is available * GameModelImporter - Sort using statements * SkinModelImporter - Small code clean up inside 'ImportBedrockJson' * SkinModelImporter - Update 'AddBone' function inside 'ExportBedrockJson' * SkinModelImporter - Fix bottom texture swaping being done bofre parts where imported * SkinMoelImporter - Rename 'GetSkinBoxPivot' to 'GetSkinPartPivot' * SceneViewport - Rename 'Init' to 'Initialize' * SkinModelImporter - Add texture import in 'ImportBedrockJson' * SkinModelImporter - Fix becrock model import * Skin-/GameModelImporter - Rename 'fileName' parameter to 'filepath' * Add ModelEditor * modelMetaData - Add cavespider texture location * GameModelImporter - Update 'ExportBlockBenchModel' function * GameModelImporter - Mark 'ModelExportSettings' as sealed * ModelEditor -Add Save tool menu item & add TrySetTexture Delegate * ModelEditor - Add model node icons * Update CubeMesh & rename CubeGroupMesh to CubeMeshCollection * ModelEditor - Rename 'GetModelNodes' & 'GetModelPartNodeChildren' * Update GenericMesh & mesh rendering * Move Cube conversion into SkinBOXExtensions * GenericMesh - Made 'Transform' property abstract * SceneViewport - Add shaderLibrary and api to it * Rename 'skin...' shaders to 'texturedCube...' * Update modelMetaData part hierarchy structure * ShaderProgram - Add 'SetUniform2' overload for System.Drawing.Size * ModelEditor - Create factory methods for custom model treenodes * modelMetaData - Add 'slime.armor' texture location & pattern texture locations for 'tropicalfish_-a/-b' * Move Debug & Camera control into SceneViewport * Update BoundingBox * Add ModelRenderer * ShaderProgram - Update GetUniformLocation to retrive all active uniforms when linking program * ModelEditor - Add option to show bounding box of the model * SceneViewport - Add OnPaint override to clear color and depth buffer and enable depth testing * Update OMI submodule * Update Texture base class to accept slot when calling Bind * Plain color fragment shader - Update uniform names to be PascalCase * SceneViewport - Add 'ResetCamera' virtual function * CustomSkinEditor - Add missing render setting 'Show Armor' * ModelRenderer - Fix centering model after selecting * Move 'SceneViewport.GetBounds' to 'BoundingBox.GetEnclosingBoundingBox' * CubeMeshCollection - Implemented 'GetBounds' * SkinRenderer - Add option to show skins bounding box * ModelEditor - Update 'GetModelImageIndex' * SceneViewport - Disable blend when rendering debug graphics * ModelEditor - Remove 'Model' property in favor to 'LoadModel' function * JsonModelMetaData - Initialize 'RootParts' to empty array * BoundingBox - Fix exception when empty enumerable was passed * CubeMesh - Remove 'SetName' and add constructor with 'name' parameter * SkinBOX - Change class to record & make member properties getter only * BoundingBox - Move 'Abs' function into extension class * SceneViewport - Change 'Transform' to 'GetTransform' * BoundingBox - Make 'GetVertices' static & add GetTransform * SkinRenderer - Fix bounds calculation when offset is set & fix part highlighting * CubeMesh - Move translation & scaling into 'GetTransform' * CubeMeshCollection - Update 'Contains' overload function & 'SetVisible' * ModelRenderer - Fix pivot point rendering * ModelRenderer - Add part highlighting * modelMetaData - Add missing part to dolphin * modelMetaData - Add missing parts to dragon * CubeMesh - Fix 'GetTransform' function * ModelRenderer - Fix model rotation, pivot & translation issues * ModelRenderer - Add offset to render transform & camera * ModelRenderer - Tried fixing alpha rendering issues * modelMetaData - Add missing part to dragon & add comment * Add 'ITryGetSet.cs' and useful wrappers for it * ModelRenderer - Rename 'HighlightInfo.Pivot' to 'HighlightInfo.Translation' * ITryGetSet - mark classes and interfaces public * ModelEditor - Add material render support * ModelRenderer - Add 'TryGetModelMetaData' method * Fix rendering invisible vertecies * ModelRenderer - Simplefied populating 'metaData.RootParts' property * ModelRenderer - Add 'modelOffset' field * ModelRenderer - Update 'SetModelMaterial' * ModelRenderer - Add simple way of rendering a 2nd layer of a model(the bed model only for now) * ModelRenderer - Fix pivot points not working on horse model properly * ResourceLocation - Add 'Unknown' ResourceLocation instance & improved 'ResourceLocation.GetFromPath' * ResourceCategory - Add 'MobEntityTextures' & 'ItemEntityTextures' * Add default model handling (defaults unfinished) * Add Default Bed model * Add default chicken model * Add default cow model * AddSkinPrompt - Fix Custom skin editor not having anim flag properly set * SceneViewport - Fix Designer crashing when trying to call 'OnPaint' * Update OMI submodule * SceneViewport - Call 'base.OnMouseUp' before our own code * BlockBenchModel - Fix 'Texture.Name' being null * ItemSelectionPopUp - Fix 'okBtn_Click' condition * MainForm - Add export function for default models * MainForm - Fix model selector ignoring cancel button * MainForm - Remove unnecessary wrapper for 'entityMaterials.TryGetValue' * ModelEditor - Add remove model to context menu * ModelEditor - Add 'GetModelContainer' function * GameModelImporter - Add import functionality * MainForm - Add texture when exporting default models * Add default model for: redcow, pig, snowgolem & dragon head * Add SkinModel & SkinIdentifier class * Refactor Skin.cs - Move texture from 'SkinModel' to Skin.cs - Move 'Id' from SkinMetaData into it's own class(SkinIdentifier.cs) - Create SkinModelInfo class for keeping skin conversion simple * Skin.cs - Rename 'ANIM' property to 'Anim' * Move 'hasInvalidEntries' into 'MaterialExtensions.HasInvalidEntries' * Add ISaveContext * PckAssetExt - Rename parameter names for 'GetSkin' * Add Editor.cs * Update most editors to use new Editor class and save context * CustomSkinEditor - Use Editor as base class * SkinMetaData - Change to Immutable data type * PckAssetExtension - [SetSkin] Change adding loc key to setting loc key * ImageDeserializer - Add format check when deserializing * MainForm - [HandleSkinFile] Rename some varibale names * ModelEditor - Use Editor as base class * Move static variables from 'ModelPartSpecifics' to 'GameConstants' * Texture.cs - Add IDisposable interface * PckAssetExtensions - [SetSkin] Add null check for loc file * AnimationEditor - Fix auto save check * TextureAtlasEditor - Refactor animation access control * TextureAtlasEditor - Sort using directives * MainForm - [HandleTextureFile] Add Debug message when animation has no frames to save * AddSkinPrompt - Update save context for custom skin editor * Editor - Move autosave check in 'OnFormClosing' * ModelRenderer - Update designer specifics * Merge 'multi-pck-files-feature' into '3dSkinRenderer' * [WIP] Sub-pck in new tab with savecontext etc. * SceneViewport - Change base refresh rate to 60 fps * CustomSkinEditor - Move max offset value into a constant * ModelEditor - Add highlighting of sinfgle model boxes * MainForm - Add constant for max pck id value * CustomSkinEditor - Remove fps slider and re-ordered ui * EditorForm - Remove abstract from class declaration * EditorControl - Made virtual funtion throw `NotImplementedException` * CustomSkinEditor - Fix naming violations * CustomSkinEditor - Move initialization of render settings into a seperate funtion & remove `show armor` setting * Move Common functionality to Core project & rendering and Model support as well * Change namespace of EditorForm & EditorControl * Add Constant 'NDEBUG' to Core, Rendering & ModelSupport project * PckStudio.csproj - Remove `defaultModels.json` & `modelMetaData.json` - files were moved to PckStuido.ModelSupport * PckStudio.csproj - Remove unused `ApplicationBuildInfo.cs` * PckStudio.Core - Add NamedData.cs * PckStudio - Move some Resources to Core * Add Altas class & refactored Atlas editor * Update OMI Submodule * TextureAtlasEditor - Fix clear button not reseting color * Fix PackInfo.cs - OMI.Endianess -> OMI.ByteOrder * TextureAtlas - Impl extraction&import of large tiles * PckStudio.Core - Remove duplicated resources * LOCEditor - Added menu item for copying loc id * Core - Move 'MAX_PACK_ID' into GameConstants * TextureAtlasEditor - small refactor + TODOs * Update OMI submodule ref
343 lines
14 KiB
C#
343 lines
14 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Drawing;
|
|
using System.Diagnostics;
|
|
using System.Windows.Forms;
|
|
using System.Collections.Generic;
|
|
|
|
using OMI.Formats.Model;
|
|
using MetroFramework.Forms;
|
|
|
|
using PckStudio.Controls;
|
|
using PckStudio.Interfaces;
|
|
using OMI.Formats.Material;
|
|
using PckStudio.ModelSupport;
|
|
using PckStudio.Core.Json;
|
|
using PckStudio.Core.Extensions;
|
|
using PckStudio.Internal.App;
|
|
using PckStudio.Core;
|
|
|
|
namespace PckStudio.Forms.Editor
|
|
{
|
|
public partial class ModelEditor : EditorForm<ModelContainer>
|
|
{
|
|
private readonly ITryGetSet<string, Image> _textures;
|
|
private readonly ITryGet<string, MaterialContainer.Material> _tryGetEntityMaterial;
|
|
|
|
public ModelEditor(ModelContainer models, ISaveContext<ModelContainer> saveContext, ITryGetSet<string, Image> tryGetSetTextures, ITryGet<string, MaterialContainer.Material> tryGetEntityMaterial)
|
|
: base(models, saveContext)
|
|
{
|
|
InitializeComponent();
|
|
_textures = tryGetSetTextures;
|
|
_tryGetEntityMaterial = tryGetEntityMaterial;
|
|
modelTreeView.ImageList = new ImageList
|
|
{
|
|
ColorDepth = ColorDepth.Depth32Bit,
|
|
ImageSize = new Size(32, 32)
|
|
};
|
|
modelTreeView.ImageList.Images.AddRange(ApplicationScope.EntityImages);
|
|
}
|
|
|
|
private const int InvalidImageIndex = 127;
|
|
// TODO: move to json file. -miku
|
|
private static Dictionary<string, int> ModelImageIndex = new Dictionary<string, int>()
|
|
{
|
|
["bat"] = 3,
|
|
["blaze"] = 4,
|
|
["boat"] = 5,
|
|
["cat"] = 6,
|
|
["spider"] = 107,
|
|
["chicken"] = 9,
|
|
["cod"] = 10,
|
|
["cow"] = 12,
|
|
["creeper"] = 13,
|
|
["creeper_head"] = 13,
|
|
["dolphin"] = 14,
|
|
["horse.v2"] = 110,
|
|
["guardian"] = 109,
|
|
["bed"] = 108,
|
|
["dragon"] = 21,
|
|
["dragon_head"] = 21,
|
|
["enderman"] = 23,
|
|
["ghast"] = 34,
|
|
["irongolem"] = 40,
|
|
["lavaslime"] = 46,
|
|
["llama"] = 44,
|
|
["llamaspit"] = 45,
|
|
["minecart"] = 47,
|
|
["ocelot"] = 50,
|
|
["parrot"] = 53,
|
|
["phantom"] = 54,
|
|
["pig"] = 55,
|
|
["pigzombie"] = 94,
|
|
["polarbear"] = 57,
|
|
["rabbit"] = 60,
|
|
["sheep"] = 63,
|
|
["sheep.sheared"] = 113,
|
|
["shulker"] = 64,
|
|
["silverfish"] = 66,
|
|
["skeleton"] = 67,
|
|
["skeleton_head"] = 67,
|
|
["skeleton.stray"] = 77,
|
|
["skeleton.wither"] = 89,
|
|
["skeleton_wither_head"] = 89,
|
|
["slime"] = 115,
|
|
["slime.armor"] = 116,
|
|
|
|
["snowgolem"] = 71,
|
|
["squid"] = 76,
|
|
["trident"] = 80,
|
|
["turtle"] = 82,
|
|
["villager"] = 84,
|
|
["villager.witch"] = 87,
|
|
|
|
["vex"] = 83,
|
|
["evoker"] = 25,
|
|
["vindicator"] = 25,
|
|
["witherBoss"] = 88,
|
|
["wolf"] = 91,
|
|
["zombie"] = 92,
|
|
["zombie_head"] = 92,
|
|
["zombie.husk"] = 39,
|
|
["zombie.villager"] = 95,
|
|
["zombie.drowned"] = 17,
|
|
["endermite"] = 24,
|
|
["pufferfish.small"] = 111,
|
|
["pufferfish.mid"] = 112,
|
|
["pufferfish.large"] = 59,
|
|
["salmon"] = 62,
|
|
["stray.armor"] = 118,
|
|
["stray_armor"] = 118,
|
|
["tropicalfish_a"] = 81,
|
|
["tropicalfish_b"] = 81,
|
|
["mooshroom"] = 48,
|
|
["witherBoss.armor"] = 90,
|
|
|
|
// 1.14 models
|
|
["panda"] = 52,
|
|
["ravager"] = 61,
|
|
["pillager"] = 56,
|
|
["villager_v2"] = 101,
|
|
["zombie.villager_v2"] = 102,
|
|
};
|
|
|
|
private static int GetModelImageIndex(string name) => ModelImageIndex.TryGetValue(name, out int index) ? index : InvalidImageIndex;
|
|
|
|
private class ModelNode : TreeNode
|
|
{
|
|
private Model _model;
|
|
public Model Model => _model;
|
|
|
|
private ModelNode(Model model)
|
|
: base(model.Name)
|
|
{
|
|
_model = model;
|
|
ImageIndex = GetModelImageIndex(model.Name);
|
|
SelectedImageIndex = GetModelImageIndex(model.Name);
|
|
Nodes.AddRange(GetModelPartNodes(_model.GetParts()).ToArray());
|
|
}
|
|
private static IEnumerable<TreeNode> GetModelPartNodes(IEnumerable<ModelPart> parts) => parts.Select(ModelPartNode.Create);
|
|
|
|
internal static ModelNode Create(Model model) => new ModelNode(model);
|
|
}
|
|
|
|
private class ModelPartNode : TreeNode
|
|
{
|
|
private ModelPart _part;
|
|
|
|
public ModelPart Part => _part;
|
|
|
|
private ModelPartNode(ModelPart part)
|
|
: base($"{part.Name} Pivot:{part.Translation * -1} Rot:{part.Rotation + part.AdditionalRotation} ")
|
|
{
|
|
_part = part;
|
|
ImageIndex = 126;
|
|
SelectedImageIndex = 126;
|
|
Nodes.AddRange(GetModelBoxNodes(part.GetBoxes()).ToArray());
|
|
}
|
|
private static IEnumerable<TreeNode> GetModelBoxNodes(IEnumerable<ModelBox> boxes) => boxes.Select(ModelBoxNode.Create);
|
|
|
|
internal static ModelPartNode Create(ModelPart part) => new ModelPartNode(part);
|
|
}
|
|
|
|
private class ModelBoxNode : TreeNode
|
|
{
|
|
private ModelBox _modelBox;
|
|
public ModelBox Box => _modelBox;
|
|
private ModelBoxNode(ModelBox modelBox)
|
|
: base($"Box: pos:{modelBox.Position} size:{modelBox.Size}")
|
|
{
|
|
ImageIndex = 126;
|
|
SelectedImageIndex = 126;
|
|
_modelBox = modelBox;
|
|
}
|
|
|
|
internal static ModelBoxNode Create(ModelBox modelBox) => new ModelBoxNode(modelBox);
|
|
}
|
|
|
|
private class NamedTextureTreeNode : TreeNode
|
|
{
|
|
private readonly NamedData<Image> _namedTexture;
|
|
|
|
public NamedTextureTreeNode(NamedData<Image> namedTexture)
|
|
: base(namedTexture.Name)
|
|
{
|
|
Tag = namedTexture;
|
|
_namedTexture = namedTexture;
|
|
}
|
|
|
|
public Image GetTexture() => _namedTexture.Value;
|
|
}
|
|
|
|
private void LoadModels()
|
|
{
|
|
modelTreeView.Nodes.Clear();
|
|
modelTreeView.Nodes.AddRange(EditorValue.Select(ModelNode.Create).ToArray());
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
LoadModels();
|
|
}
|
|
|
|
private void exportToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (modelTreeView.SelectedNode is ModelNode modelNode)
|
|
{
|
|
Model model = modelNode.Model;
|
|
Debug.Write(model.Name + "; ");
|
|
Debug.WriteLine(model.TextureSize);
|
|
|
|
GameModelImporter.Default.ExportSettings.CreateModelOutline =
|
|
MessageBox.Show(
|
|
$"Do you wish to have all model parts contained in a group called '{model.Name}'?",
|
|
"Group model parts", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
|
|
|
|
using SaveFileDialog openFileDialog = new SaveFileDialog();
|
|
openFileDialog.FileName = model.Name;
|
|
openFileDialog.Filter = GameModelImporter.Default.SupportedModelFileFormatsFilter;
|
|
|
|
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
|
|
{
|
|
IEnumerable<NamedData<Image>> textures = GetModelTextures(model.Name);
|
|
var modelInfo = new GameModelInfo(model, textures);
|
|
GameModelImporter.Default.Export(openFileDialog.FileName, modelInfo);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void modelTreeView_BeforeSelect(object sender, TreeViewCancelEventArgs e)
|
|
{
|
|
exportToolStripMenuItem.Visible = e.Node is ModelNode;
|
|
removeToolStripMenuItem.Visible = e.Node is ModelNode;
|
|
editToolStripMenuItem.Visible = e.Node is ModelBoxNode;
|
|
//removeToolStripMenuItem.Visible = e.Node is ModelPartNode || e.Node is ModelBoxNode;
|
|
if (e.Node is ModelNode modelNode && modelNode.Model.Name != modelViewport.CurrentModelName)
|
|
{
|
|
NamedData<Image>[] textures = GetModelTextures(modelNode.Model.Name).ToArray();
|
|
|
|
textureImageList.Images.Clear();
|
|
namedTexturesTreeView.Nodes.Clear();
|
|
|
|
foreach ((int i, NamedData<Image> item) in textures.enumerate())
|
|
{
|
|
textureImageList.Images.Add(item.Value);
|
|
namedTexturesTreeView.Nodes.Add(new NamedTextureTreeNode(item) { ImageIndex = i, SelectedImageIndex = i });
|
|
}
|
|
if (textures.Length != 0)
|
|
modelViewport.Texture = textures[0].Value;
|
|
|
|
modelViewport.LoadModel(modelNode.Model);
|
|
if (GameModelImporter.ModelMetaData.TryGetValue(modelNode.Model.Name, out JsonModelMetaData modelMetaData) && !string.IsNullOrEmpty(modelMetaData.MaterialName) &&
|
|
_tryGetEntityMaterial.TryGet(modelMetaData.MaterialName, out MaterialContainer.Material entityMaterial) ||
|
|
_tryGetEntityMaterial.TryGet(modelNode.Model.Name, out entityMaterial))
|
|
{
|
|
modelViewport.SetModelMaterial(entityMaterial);
|
|
}
|
|
modelViewport.ResetCamera();
|
|
}
|
|
if (e.Node is ModelPartNode modelPartNode && modelPartNode.Parent is ModelNode parentNode && modelViewport.CurrentModelName == parentNode.Model.Name)
|
|
{
|
|
modelViewport.Highlight(modelPartNode.Part);
|
|
}
|
|
|
|
if (e.Node is ModelBoxNode modelBoxNode && modelBoxNode.Parent is ModelPartNode parentPartNode && parentPartNode.Parent is ModelNode parentNode1 &&
|
|
modelViewport.CurrentModelName == parentNode1.Model.Name)
|
|
{
|
|
modelViewport.Highlight(modelBoxNode.Box, parentPartNode.Part);
|
|
}
|
|
}
|
|
|
|
private IEnumerable<NamedData<Image>> GetModelTextures(string modelName)
|
|
{
|
|
if (!GameModelImporter.ModelMetaData.ContainsKey(modelName) || GameModelImporter.ModelMetaData[modelName]?.TextureLocations?.Length <= 0)
|
|
yield break;
|
|
foreach (var textureLocation in GameModelImporter.ModelMetaData[modelName].TextureLocations)
|
|
{
|
|
if (_textures.TryGet(textureLocation, out Image img))
|
|
yield return new NamedData<Image>(Path.GetFileName(textureLocation), img);
|
|
}
|
|
yield break;
|
|
}
|
|
|
|
private void importToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog fileDialog = new OpenFileDialog();
|
|
fileDialog.Filter = GameModelImporter.Default.SupportedModelFileFormatsFilter;
|
|
fileDialog.Title = "Select model";
|
|
if (fileDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
GameModelInfo modelInfo = GameModelImporter.Default.Import(fileDialog.FileName);
|
|
if (modelInfo is null)
|
|
{
|
|
MessageBox.Show("Import failed.", ProductName);
|
|
return;
|
|
}
|
|
|
|
//if (models.Version < modelInfo.ModelVersion)
|
|
//{
|
|
// MessageBox.Show("Model container version does not match with the model version.", ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
// return;
|
|
//}
|
|
|
|
EditorValue.SetModel(modelInfo.Model);
|
|
|
|
foreach (NamedData<Image> texture in modelInfo.Textures)
|
|
{
|
|
_textures.TrySet(texture.Name, texture.Value);
|
|
}
|
|
|
|
LoadModels();
|
|
}
|
|
}
|
|
|
|
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
Save();
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
|
|
private void namedTexturesTreeView_AfterSelect(object sender, TreeViewEventArgs e)
|
|
{
|
|
if (namedTexturesTreeView.SelectedNode is NamedTextureTreeNode namedTextureNode)
|
|
modelViewport.Texture = namedTextureNode.GetTexture();
|
|
}
|
|
|
|
private void showModelBoundsToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
modelViewport.RenderModelBounds = showModelBoundsToolStripMenuItem.Checked;
|
|
}
|
|
|
|
private void removeToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (modelTreeView?.SelectedNode is ModelNode modelNode && EditorValue.Remove(modelNode.Model))
|
|
{
|
|
modelNode.Remove();
|
|
}
|
|
}
|
|
}
|
|
}
|