Files
PCK-Studio/PckStudio.Core/Misc/OpenFolderDialog.cs
Miku-666 8dfe9cf5b0 3d skin renderer (#50)
* 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
2025-11-11 21:53:32 +01:00

203 lines
7.9 KiB
C#

/*
* Source by: Simon Mourier(https://stackoverflow.com/users/403671/simon-mourier)
*/
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
namespace PckStudio.Core.Misc
{
public class OpenFolderDialog
{
public virtual string ResultPath { get; protected set; }
public virtual string ResultName { get; protected set; }
public virtual string InputPath { get; set; }
public virtual bool ForceFileSystem { get; set; }
public virtual string Title { get; set; }
public virtual string OkButtonLabel { get; set; }
public virtual string FileNameLabel { get; set; }
protected virtual int SetOptions(int options)
{
if (ForceFileSystem)
{
options |= (int)FOS.FOS_FORCEFILESYSTEM;
}
return options;
}
// for all .NET
public virtual bool? ShowDialog(IntPtr owner, bool throwOnError = false)
{
var dialog = (IFileOpenDialog)new FileOpenDialog();
if (!string.IsNullOrEmpty(InputPath))
{
if (CheckHr(SHCreateItemFromParsingName(InputPath, null, typeof(IShellItem).GUID, out IShellItem item), throwOnError) != 0)
return null;
dialog.SetFolder(item);
}
FOS options = FOS.FOS_PICKFOLDERS;
options = (FOS)SetOptions((int)options);
dialog.SetOptions(options);
if (Title != null)
{
dialog.SetTitle(Title);
}
if (OkButtonLabel != null)
{
dialog.SetOkButtonLabel(OkButtonLabel);
}
if (FileNameLabel != null)
{
dialog.SetFileName(FileNameLabel);
}
if (owner == IntPtr.Zero)
{
owner = Process.GetCurrentProcess().MainWindowHandle;
if (owner == IntPtr.Zero)
{
owner = GetDesktopWindow();
}
}
var hr = dialog.Show(owner);
if (hr == ERROR_CANCELLED)
return null;
if (CheckHr(hr, throwOnError) != 0)
return null;
if (CheckHr(dialog.GetResult(out IShellItem result), throwOnError) != 0)
return null;
if (CheckHr(result.GetDisplayName(SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out var path), throwOnError) != 0)
return null;
ResultPath = path;
if (CheckHr(result.GetDisplayName(SIGDN.SIGDN_DESKTOPABSOLUTEEDITING, out path), false) == 0)
{
ResultName = path;
}
return true;
}
private static int CheckHr(int hr, bool throwOnError)
{
if (hr != 0)
{
if (throwOnError)
Marshal.ThrowExceptionForHR(hr);
}
return hr;
}
[DllImport("shell32")]
private static extern int SHCreateItemFromParsingName([MarshalAs(UnmanagedType.LPWStr)] string pszPath, IBindCtx pbc, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IShellItem ppv);
[DllImport("user32")]
private static extern IntPtr GetDesktopWindow();
#pragma warning disable IDE1006 // Naming Styles
private const int ERROR_CANCELLED = unchecked((int)0x800704C7);
#pragma warning restore IDE1006 // Naming Styles
[ComImport, Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")] // CLSID_FileOpenDialog
private class FileOpenDialog
{
}
[ComImport, Guid("42f85136-db7e-439c-85f1-e4075d135fc8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IFileOpenDialog
{
[PreserveSig] int Show(IntPtr parent); // IModalWindow
[PreserveSig] int SetFileTypes(); // not fully defined
[PreserveSig] int SetFileTypeIndex(int iFileType);
[PreserveSig] int GetFileTypeIndex(out int piFileType);
[PreserveSig] int Advise(); // not fully defined
[PreserveSig] int Unadvise();
[PreserveSig] int SetOptions(FOS fos);
[PreserveSig] int GetOptions(out FOS pfos);
[PreserveSig] int SetDefaultFolder(IShellItem psi);
[PreserveSig] int SetFolder(IShellItem psi);
[PreserveSig] int GetFolder(out IShellItem ppsi);
[PreserveSig] int GetCurrentSelection(out IShellItem ppsi);
[PreserveSig] int SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName);
[PreserveSig] int GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);
[PreserveSig] int SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
[PreserveSig] int SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText);
[PreserveSig] int SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
[PreserveSig] int GetResult(out IShellItem ppsi);
[PreserveSig] int AddPlace(IShellItem psi, int alignment);
[PreserveSig] int SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
[PreserveSig] int Close(int hr);
[PreserveSig] int SetClientGuid(); // not fully defined
[PreserveSig] int ClearClientData();
[PreserveSig] int SetFilter([MarshalAs(UnmanagedType.IUnknown)] object pFilter);
[PreserveSig] int GetResults([MarshalAs(UnmanagedType.IUnknown)] out object ppenum);
[PreserveSig] int GetSelectedItems([MarshalAs(UnmanagedType.IUnknown)] out object ppsai);
}
[ComImport, Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IShellItem
{
[PreserveSig] int BindToHandler(); // not fully defined
[PreserveSig] int GetParent(); // not fully defined
[PreserveSig] int GetDisplayName(SIGDN sigdnName, [MarshalAs(UnmanagedType.LPWStr)] out string ppszName);
[PreserveSig] int GetAttributes(); // not fully defined
[PreserveSig] int Compare(); // not fully defined
}
#pragma warning disable CA1712 // Do not prefix enum values with type name
private enum SIGDN : uint
{
SIGDN_DESKTOPABSOLUTEEDITING = 0x8004c000,
SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000,
SIGDN_FILESYSPATH = 0x80058000,
SIGDN_NORMALDISPLAY = 0,
SIGDN_PARENTRELATIVE = 0x80080001,
SIGDN_PARENTRELATIVEEDITING = 0x80031001,
SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8007c001,
SIGDN_PARENTRELATIVEPARSING = 0x80018001,
SIGDN_URL = 0x80068000
}
[Flags]
private enum FOS
{
FOS_OVERWRITEPROMPT = 0x2,
FOS_STRICTFILETYPES = 0x4,
FOS_NOCHANGEDIR = 0x8,
FOS_PICKFOLDERS = 0x20,
FOS_FORCEFILESYSTEM = 0x40,
FOS_ALLNONSTORAGEITEMS = 0x80,
FOS_NOVALIDATE = 0x100,
FOS_ALLOWMULTISELECT = 0x200,
FOS_PATHMUSTEXIST = 0x800,
FOS_FILEMUSTEXIST = 0x1000,
FOS_CREATEPROMPT = 0x2000,
FOS_SHAREAWARE = 0x4000,
FOS_NOREADONLYRETURN = 0x8000,
FOS_NOTESTFILECREATE = 0x10000,
FOS_HIDEMRUPLACES = 0x20000,
FOS_HIDEPINNEDPLACES = 0x40000,
FOS_NODEREFERENCELINKS = 0x100000,
FOS_OKBUTTONNEEDSINTERACTION = 0x200000,
FOS_DONTADDTORECENT = 0x2000000,
FOS_FORCESHOWHIDDEN = 0x10000000,
FOS_DEFAULTNOMINIMODE = 0x20000000,
FOS_FORCEPREVIEWPANEON = 0x40000000,
FOS_SUPPORTSTREAMABLEITEMS = unchecked((int)0x80000000)
}
#pragma warning restore CA1712 // Do not prefix enum values with type name
}
}