1
0
mirror of synced 2024-11-13 18:50:50 +01:00

BFRES : Fix some more importing bugs

Only align buffers when using a single buffer.
This commit is contained in:
KillzXGaming 2020-02-11 16:49:27 -05:00
parent cd56a53d0c
commit 946fa08518
6 changed files with 58 additions and 28 deletions

View File

@ -386,7 +386,8 @@ namespace Bfres.Structs
bool UseUVLayer2 = false; bool UseUVLayer2 = false;
//for BOTW if it uses UV layer 2 for normal maps use second UV map //for BOTW if it uses UV layer 2 for normal maps use second UV map
if (shp.GetFMAT().shaderassign.options.ContainsKey("uking_texture2_texcoord")) { if (shp.GetFMAT().shaderassign.options.ContainsKey("uking_texture2_texcoord"))
{
float value = float.Parse(shp.GetFMAT().shaderassign.options["uking_texture2_texcoord"]); float value = float.Parse(shp.GetFMAT().shaderassign.options["uking_texture2_texcoord"]);
if (value == 1) if (value == 1)
@ -505,7 +506,8 @@ namespace Bfres.Structs
} }
else else
{ {
foreach (var shape in shapes) { foreach (var shape in shapes)
{
shape.SaveVertexBuffer(GetResFileU() != null); shape.SaveVertexBuffer(GetResFileU() != null);
} }
UpdateVertexData(); UpdateVertexData();
@ -580,16 +582,18 @@ namespace Bfres.Structs
return textures; return textures;
} }
public override void Replace(string FileName) { public override void Replace(string FileName)
{
AddOjects(FileName, GetResFile(), GetResFileU()); AddOjects(FileName, GetResFile(), GetResFileU());
} }
public void Replace(string FileName, ResFile resFileNX, ResU.ResFile resFileU) { public void Replace(string FileName, ResFile resFileNX, ResU.ResFile resFileU)
{
AddOjects(FileName, resFileNX, resFileU); AddOjects(FileName, resFileNX, resFileU);
} }
//Function addes shapes, vertices and meshes //Function addes shapes, vertices and meshes
public void AddOjects(string FileName, ResFile resFileNX, ResU.ResFile resFileU, bool Replace = true) public void AddOjects(string FileName, ResFile resFileNX, ResU.ResFile resFileU, bool Replace = true)
{ {
//If using original attributes, this to look them up //If using original attributes, this to look them up
Dictionary<string, List<FSHP.VertexAttribute>> AttributeMatcher = new Dictionary<string, List<FSHP.VertexAttribute>>(); Dictionary<string, List<FSHP.VertexAttribute>> AttributeMatcher = new Dictionary<string, List<FSHP.VertexAttribute>>();
@ -684,7 +688,8 @@ namespace Bfres.Structs
{ {
if (csvsettings.LimitSkinCount || if (csvsettings.LimitSkinCount ||
csvsettings.MapOriginalMaterials || csvsettings.MapOriginalMaterials ||
csvsettings.UseOriginalAttributes) { csvsettings.UseOriginalAttributes)
{
for (int i = 0; i < csvModel.objects.Count; i++) for (int i = 0; i < csvModel.objects.Count; i++)
{ {
//Only one match should be found as shapes can't have duped names //Only one match should be found as shapes can't have duped names
@ -699,7 +704,7 @@ namespace Bfres.Structs
} }
if (csvsettings.MapOriginalMaterials && match != null) if (csvsettings.MapOriginalMaterials && match != null)
{ {
csvModel.objects[i].MaterialIndex = match.MaterialIndex; csvModel.objects[i].MaterialIndex = match.MaterialIndex;
} }
@ -750,15 +755,6 @@ namespace Bfres.Structs
else else
shape.vertexAttributes = csvsettings.CreateNewAttributes(); shape.vertexAttributes = csvsettings.CreateNewAttributes();
Console.WriteLine($"ForceSkinInfluence {ForceSkinInfluence}");
if (!ForceSkinInfluence)
shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
else
shape.VertexSkinCount = (byte)ForceSkinInfluenceMax;
Console.WriteLine($"VertexSkinCount { shape.VertexSkinCount}");
shape.BoneIndex = 0; shape.BoneIndex = 0;
shape.Text = obj.ObjectName; shape.Text = obj.ObjectName;
shape.lodMeshes = obj.lodMeshes; shape.lodMeshes = obj.lodMeshes;
@ -768,6 +764,15 @@ namespace Bfres.Structs
shape.ApplyImportSettings(csvsettings, GetMaterial(shape.MaterialIndex)); shape.ApplyImportSettings(csvsettings, GetMaterial(shape.MaterialIndex));
shape.BoneIndices = shape.GetIndices(Skeleton); shape.BoneIndices = shape.GetIndices(Skeleton);
Console.WriteLine($"ForceSkinInfluence {ForceSkinInfluence}");
if (!ForceSkinInfluence)
shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
else
shape.VertexSkinCount = (byte)ForceSkinInfluenceMax;
Console.WriteLine($"VertexSkinCount { shape.VertexSkinCount}");
if (shape.VertexSkinCount == 1) if (shape.VertexSkinCount == 1)
{ {
int boneIndex = shape.BoneIndices[0]; int boneIndex = shape.BoneIndices[0];
@ -827,7 +832,7 @@ namespace Bfres.Structs
string[] shapeSortCheck = shapes.Select(o => o.Text).ToArray(); string[] shapeSortCheck = shapes.Select(o => o.Text).ToArray();
// assimp.objects = assimp.objects.SortBy(shapeSortCheck, c => c.ObjectName).ToList(); // assimp.objects = assimp.objects.SortBy(shapeSortCheck, c => c.ObjectName).ToList();
if (ImportedObjects.Count == 0) if (ImportedObjects.Count == 0)
{ {
@ -1178,6 +1183,8 @@ namespace Bfres.Structs
else else
shape.vertexAttributes = settings.CreateNewAttributes(); shape.vertexAttributes = settings.CreateNewAttributes();
shape.BoneIndex = obj.BoneIndex;
if (obj.MaterialIndex + MatStartIndex < materials.Count && obj.MaterialIndex > 0) if (obj.MaterialIndex + MatStartIndex < materials.Count && obj.MaterialIndex > 0)
shape.MaterialIndex = obj.MaterialIndex + MatStartIndex; shape.MaterialIndex = obj.MaterialIndex + MatStartIndex;
else else
@ -1205,8 +1212,6 @@ namespace Bfres.Structs
shape.SaveShape(IsWiiU); shape.SaveShape(IsWiiU);
shape.SaveVertexBuffer(IsWiiU); shape.SaveVertexBuffer(IsWiiU);
shape.BoneIndex = obj.BoneIndex;
if (IsWiiU) if (IsWiiU)
{ {
shape.ShapeU.SubMeshBoundingIndices = new List<ushort>(); shape.ShapeU.SubMeshBoundingIndices = new List<ushort>();
@ -1298,7 +1303,8 @@ namespace Bfres.Structs
UpdateEditor(); UpdateEditor();
} }
public void UpdateEditor(){ public void UpdateEditor()
{
((BFRES)Parent?.Parent)?.LoadEditors(this); ((BFRES)Parent?.Parent)?.LoadEditors(this);
} }
@ -1317,10 +1323,10 @@ namespace Bfres.Structs
bn.Name = bone.Text; bn.Name = bone.Text;
bn.RigidMatrixIndex = 0; bn.RigidMatrixIndex = 0;
bn.Rotation = new Syroot.Maths.Vector4F( bn.Rotation = new Syroot.Maths.Vector4F(
bone.Rotation.X, bone.Rotation.X,
bone.Rotation.Y, bone.Rotation.Y,
bone.Rotation.Z, bone.Rotation.Z,
bone.Rotation.W); bone.Rotation.W);
bn.Position = new Syroot.Maths.Vector3F( bn.Position = new Syroot.Maths.Vector3F(
bone.Position.X, bone.Position.X,
bone.Position.Y, bone.Position.Y,

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Toolbox.Library.Hash
{
//https://github.com/IcySon55/Kuriimu/blob/master/src/Cetera/Hash/SimpleHash.cs
public class SimpleHash
{
public static uint Create(string input, uint magic, uint hashCount)
{
return Create(input, magic) % hashCount;
}
public static uint Create(string input, uint magic)
{
return input.Aggregate(0u, (hash, c) => hash * magic + c);
}
}
}

View File

@ -389,6 +389,7 @@
<Compile Include="Generics\Texture\ImageParameters.cs" /> <Compile Include="Generics\Texture\ImageParameters.cs" />
<Compile Include="Generics\Texture\STTextureFolder.cs" /> <Compile Include="Generics\Texture\STTextureFolder.cs" />
<Compile Include="HashCalculate\FNV64A1.cs" /> <Compile Include="HashCalculate\FNV64A1.cs" />
<Compile Include="HashCalculate\SimpleHash.cs" />
<Compile Include="Helpers\ArchiveNodeMenuHelper.cs" /> <Compile Include="Helpers\ArchiveNodeMenuHelper.cs" />
<Compile Include="Helpers\DirectoryHelper.cs" /> <Compile Include="Helpers\DirectoryHelper.cs" />
<Compile Include="Helpers\DragHelper.cs" /> <Compile Include="Helpers\DragHelper.cs" />

View File

@ -25,6 +25,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>