Skip to content

Commit

Permalink
Skin-/GameModelImporter - Rename 'fileName' parameter to 'filepath'
Browse files Browse the repository at this point in the history
  • Loading branch information
NessieHax committed Aug 30, 2024
1 parent 14bf673 commit 1f5f24b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions PCK-Studio/Internal/GameModelImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private GameModelImporter()
InternalAddProvider(new FileDialogFilter("Block bench model(*.bbmodel)", "*.bbmodel"), null, ExportBlockBenchModel);
}

private void ExportBlockBenchModel(string fileName, GameModelInfo modelInfo)
private void ExportBlockBenchModel(string filepath, GameModelInfo modelInfo)
{
BlockBenchModel blockBenchModel = BlockBenchModel.Create(BlockBenchFormatInfos.BedrockEntity, modelInfo.Model.Name, modelInfo.Model.TextureSize, modelInfo.Textures.Select(nt => (Texture)nt));

Expand Down Expand Up @@ -95,7 +95,7 @@ private void ExportBlockBenchModel(string fileName, GameModelInfo modelInfo)
blockBenchModel.Outliner = JArray.FromObject(outlines);

string content = JsonConvert.SerializeObject(blockBenchModel, Formatting.Indented);
File.WriteAllText(fileName, content);
File.WriteAllText(filepath, content);
}

private static void TraverseChildren(IReadOnlyDictionary<string, JArray> keyValues, ref Dictionary<string, Outline> outliners)
Expand Down
50 changes: 25 additions & 25 deletions PCK-Studio/Internal/SkinModelImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ private SkinModelImporter()
InternalAddProvider(new("Bedrock (Legacy) Model(*.geo.json;*.json)", "*.geo.json;*.json"), ImportBedrockJson, ExportBedrockJson);
}

internal static SkinModelInfo ImportPsm(string fileName)
internal static SkinModelInfo ImportPsm(string filepath)
{
var reader = new PSMFileReader();
PSMFile csmbFile = reader.FromFile(fileName);
PSMFile csmbFile = reader.FromFile(filepath);
return new SkinModelInfo(null, csmbFile.SkinANIM, csmbFile.Parts, csmbFile.Offsets);
}

internal static void ExportPsm(string fileName, SkinModelInfo modelInfo)
internal static void ExportPsm(string filepath, SkinModelInfo modelInfo)
{
PSMFile psmFile = new PSMFile(PSMFile.CurrentVersion, modelInfo.ANIM);
psmFile.Parts.AddRange(modelInfo.AdditionalBoxes);
psmFile.Offsets.AddRange(modelInfo.PartOffsets);
var writer = new PSMFileWriter(psmFile);
writer.WriteToFile(fileName);
writer.WriteToFile(filepath);
}

internal static SkinModelInfo ImportBlockBenchModel(string fileName)
internal static SkinModelInfo ImportBlockBenchModel(string filepath)
{
BlockBenchModel blockBenchModel = JsonConvert.DeserializeObject<BlockBenchModel>(File.ReadAllText(fileName));
BlockBenchModel blockBenchModel = JsonConvert.DeserializeObject<BlockBenchModel>(File.ReadAllText(filepath));
if (!blockBenchModel.Format.UseBoxUv)
{
Trace.TraceError($"[{nameof(SkinModelImporter)}:{nameof(ImportBlockBenchModel)}] Failed to import skin '{blockBenchModel.Name}': Skin does not use box uv.");
Expand Down Expand Up @@ -171,10 +171,10 @@ private static SkinBOX LoadElement(Element element, string outlineName)
return box;
}

internal static void ExportBlockBenchModel(string fileName, SkinModelInfo modelInfo)
internal static void ExportBlockBenchModel(string filepath, SkinModelInfo modelInfo)
{
Image exportTexture = SwapBoxBottomTexture(modelInfo);
BlockBenchModel blockBenchModel = BlockBenchModel.Create(BlockBenchFormatInfos.BedrockEntity, Path.GetFileNameWithoutExtension(fileName), new Size(64, exportTexture.Width == exportTexture.Height ? 64 : 32), [exportTexture]);
BlockBenchModel blockBenchModel = BlockBenchModel.Create(BlockBenchFormatInfos.BedrockEntity, Path.GetFileNameWithoutExtension(filepath), new Size(64, exportTexture.Width == exportTexture.Height ? 64 : 32), [exportTexture]);

Dictionary<string, Outline> outliners = new Dictionary<string, Outline>(5);
List<Element> elements = new List<Element>(modelInfo.AdditionalBoxes.Count);
Expand Down Expand Up @@ -213,7 +213,7 @@ void AddElement(SkinBOX box)
blockBenchModel.Outliner = JArray.FromObject(outliners.Values);

string content = JsonConvert.SerializeObject(blockBenchModel);
File.WriteAllText(fileName, content);
File.WriteAllText(filepath, content);
}

private static Element CreateElement(SkinBOX box)
Expand All @@ -230,12 +230,12 @@ private static Element CreateElement(Vector2 uvOffset, Vector3 pos, Vector3 size
return Element.CreateCube("cube", uvOffset, pos, size, inflate, mirror);
}

private static Geometry GetGeometry(string fileName)
private static Geometry GetGeometry(string filepath)
{
// Bedrock Entity (Model)
if (fileName.EndsWith(".geo.json"))
if (filepath.EndsWith(".geo.json"))
{
BedrockModel bedrockModel = JsonConvert.DeserializeObject<BedrockModel>(File.ReadAllText(fileName));
BedrockModel bedrockModel = JsonConvert.DeserializeObject<BedrockModel>(File.ReadAllText(filepath));
var availableModels = bedrockModel.Models.Select(m => m.Description.Identifier).ToArray();
if (availableModels.Length < 2)
return availableModels.Length == 1 ? bedrockModel.Models[0] : null;
Expand All @@ -248,9 +248,9 @@ private static Geometry GetGeometry(string fileName)
}

// Bedrock Legacy Model
else if (fileName.EndsWith(".json"))
else if (filepath.EndsWith(".json"))
{
BedrockLegacyModel bedrockModel = JsonConvert.DeserializeObject<BedrockLegacyModel>(File.ReadAllText(fileName));
BedrockLegacyModel bedrockModel = JsonConvert.DeserializeObject<BedrockLegacyModel>(File.ReadAllText(filepath));
var availableModels = bedrockModel.Select(m => m.Key).ToArray();
if (availableModels.Length < 2)
return availableModels.Length == 1 ? bedrockModel[availableModels[0]] : null;
Expand All @@ -264,17 +264,17 @@ private static Geometry GetGeometry(string fileName)
return null;
}

private static SkinModelInfo ImportBedrockJson(string fileName)
private static SkinModelInfo ImportBedrockJson(string filepath)
{
Geometry geometry = GetGeometry(fileName);
Geometry geometry = GetGeometry(filepath);
if (geometry is null)
return null;

(IEnumerable<SkinBOX> boxes, IEnumerable<SkinPartOffset> partOffsets) = LoadGeometry(geometry);

SkinModelInfo modelInfo = CreateSkinModelInfo(boxes, partOffsets);

string texturePath = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)) + ".png";
string texturePath = Path.Combine(Path.GetDirectoryName(filepath), Path.GetFileNameWithoutExtension(filepath)) + ".png";
if (File.Exists(texturePath))
{
modelInfo.Texture = Image.FromFile(texturePath).ReleaseFromFile();
Expand Down Expand Up @@ -315,9 +315,9 @@ private static (IEnumerable<SkinBOX> boxes, IEnumerable<SkinPartOffset> partOffs
return (boxes, skinPartOffsets);
}

internal static void ExportBedrockJson(string fileName, SkinModelInfo modelInfo)
internal static void ExportBedrockJson(string filepath, SkinModelInfo modelInfo)
{
if (string.IsNullOrEmpty(fileName) || !fileName.EndsWith(".json"))
if (string.IsNullOrEmpty(filepath) || !filepath.EndsWith(".json"))
return;

Dictionary<string, Bone> bones = new Dictionary<string, Bone>(5);
Expand Down Expand Up @@ -362,11 +362,11 @@ void AddBone(SkinBOX box)
selectedGeometry.Bones.AddRange(bones.Values);
object bedrockModel = null;
// Bedrock Entity (Model)
if (fileName.EndsWith(".geo.json"))
if (filepath.EndsWith(".geo.json"))
{
selectedGeometry.Description = new GeometryDescription()
{
Identifier = $"geometry.{Application.ProductName}.{Path.GetFileNameWithoutExtension(fileName)}",
Identifier = $"geometry.{Application.ProductName}.{Path.GetFileNameWithoutExtension(filepath)}",
TextureSize = modelInfo.Texture.Size,
};
bedrockModel = new BedrockModel
Expand All @@ -376,11 +376,11 @@ void AddBone(SkinBOX box)
};
}
// Bedrock Legacy Model
else if (fileName.EndsWith(".json") && modelInfo.Texture.Height == modelInfo.Texture.Width)
else if (filepath.EndsWith(".json") && modelInfo.Texture.Height == modelInfo.Texture.Width)
{
bedrockModel = new BedrockLegacyModel
{
{ $"geometry.{Application.ProductName}.{Path.GetFileNameWithoutExtension(fileName)}", selectedGeometry }
{ $"geometry.{Application.ProductName}.{Path.GetFileNameWithoutExtension(filepath)}", selectedGeometry }
};
}
else
Expand All @@ -392,8 +392,8 @@ void AddBone(SkinBOX box)
if (bedrockModel is not null)
{
string content = JsonConvert.SerializeObject(bedrockModel);
File.WriteAllText(fileName, content);
string texturePath = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)) + ".png";
File.WriteAllText(filepath, content);
string texturePath = Path.Combine(Path.GetDirectoryName(filepath), Path.GetFileNameWithoutExtension(filepath)) + ".png";
SwapBoxBottomTexture(modelInfo).Save(texturePath, ImageFormat.Png);
}
}
Expand Down

0 comments on commit 1f5f24b

Please sign in to comment.