Fix index out of range issue for importing models
This commit is contained in:
parent
c41ac2f752
commit
b00a3805f1
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -234,6 +234,7 @@ namespace Bfres.Structs
|
||||
|
||||
if (IsWiiU)
|
||||
{
|
||||
fmdl.ModelU = new ResU.Model();
|
||||
fmdl.ModelU = new ResU.Model();
|
||||
fmdl.ModelU.Name = ResourceName;
|
||||
|
||||
@ -243,8 +244,6 @@ namespace Bfres.Structs
|
||||
skeleton.Bones.Add("Root", new ResU.Bone() { Name = "Root" });
|
||||
|
||||
fmdl.ModelU.Skeleton = skeleton;
|
||||
fmdl.ModelU.Shapes.Add("NeShape", new ResU.Shape() { Name = "NeShape" });
|
||||
fmdl.ModelU.VertexBuffers.Add(new ResU.VertexBuffer() { });
|
||||
|
||||
BfresWiiU.ReadModel(fmdl, fmdl.ModelU);
|
||||
((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton);
|
||||
@ -259,8 +258,6 @@ namespace Bfres.Structs
|
||||
skeleton.Bones.Add(new ResNX.Bone() { Name = "Root" });
|
||||
|
||||
fmdl.Model.Skeleton = skeleton;
|
||||
fmdl.Model.Shapes.Add(new ResNX.Shape() { Name = "NeShape" });
|
||||
fmdl.Model.VertexBuffers.Add(new ResNX.VertexBuffer() { });
|
||||
|
||||
BfresSwitch.ReadModel(fmdl, fmdl.Model);
|
||||
((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton);
|
||||
|
@ -563,8 +563,6 @@ namespace Bfres.Structs
|
||||
mdl.Name = Text;
|
||||
BfresSwitch.ReadModel(this, mdl);
|
||||
}
|
||||
UpdateVertexData();
|
||||
|
||||
IsEdited = true;
|
||||
|
||||
Cursor.Current = Cursors.Default;
|
||||
|
@ -903,17 +903,42 @@ namespace Bfres.Structs
|
||||
|
||||
return indices;
|
||||
}
|
||||
public Vector3 TransformLocal(Vector3 position, int BoneIndex, bool IsPos = true)
|
||||
public Vector3 TransformLocal(Vector3 position, int BoneIndex,bool IsSingleBind, bool IsPos = true)
|
||||
{
|
||||
var skel = GetParentModel().Skeleton;
|
||||
var bone = skel.bones[skel.Node_Array[BoneIndex]];
|
||||
try
|
||||
{
|
||||
var skel = GetParentModel().Skeleton;
|
||||
Matrix4 trans = Matrix4.Identity;
|
||||
|
||||
Matrix4 trans = bone.invert;
|
||||
if (IsSingleBind)
|
||||
{
|
||||
if (BoneIndex >= skel.Node_Array.Length || BoneIndex == -1)
|
||||
return position;
|
||||
|
||||
if (IsPos)
|
||||
return Vector3.TransformPosition(position, trans);
|
||||
else
|
||||
return Vector3.TransformNormal(position, trans);
|
||||
var bone = skel.bones[skel.Node_Array[BoneIndex]];
|
||||
trans = bone.invert;
|
||||
|
||||
if (IsPos)
|
||||
return Vector3.TransformPosition(position, trans);
|
||||
else
|
||||
return Vector3.TransformNormal(position, trans);
|
||||
}
|
||||
else
|
||||
{
|
||||
var bone = skel.bones[BoneIndex];
|
||||
trans = bone.invert;
|
||||
|
||||
if (IsPos)
|
||||
return Vector3.TransformPosition(position, trans);
|
||||
else
|
||||
return Vector3.TransformNormal(position, trans);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
STConsole.WriteLine("Failed to bind bone to mesh " + Text, System.Drawing.Color.Red);
|
||||
return position;
|
||||
}
|
||||
}
|
||||
public static Vector3 transform(Vector3 input, Matrix4 matrix)
|
||||
{
|
||||
@ -1071,8 +1096,8 @@ namespace Bfres.Structs
|
||||
boneId = vtx.boneIds[0];
|
||||
|
||||
Console.WriteLine("Old " + vtx.pos);
|
||||
vtx.pos = TransformLocal(vtx.pos, boneId);
|
||||
vtx.nrm = TransformLocal(vtx.nrm, boneId, false);
|
||||
vtx.pos = TransformLocal(vtx.pos, boneId, VertexSkinCount == 1);
|
||||
vtx.nrm = TransformLocal(vtx.nrm, boneId, VertexSkinCount == 1, false);
|
||||
Console.WriteLine("New " + vtx.pos);
|
||||
}
|
||||
//Console.WriteLine($"Weight count {vtx.boneWeights.Count}");
|
||||
|
@ -48,6 +48,7 @@ namespace Bfres.Structs
|
||||
public fsklNode()
|
||||
{
|
||||
Text = "Skeleton";
|
||||
Name = "Skeleton";
|
||||
|
||||
ImageKey = "skeleton";
|
||||
SelectedImageKey = "skeleton";
|
||||
|
@ -89,9 +89,9 @@ namespace FirstPlugin
|
||||
{
|
||||
if (model == null)
|
||||
model = new FMDL();
|
||||
|
||||
model.Text = mdl.Name;
|
||||
model.Skeleton = new FSKL(mdl.Skeleton);
|
||||
|
||||
model.Nodes[2] = model.Skeleton.node;
|
||||
|
||||
model.Model = mdl;
|
||||
@ -100,7 +100,7 @@ namespace FirstPlugin
|
||||
FMAT FMAT = new FMAT();
|
||||
FMAT.Text = mat.Name;
|
||||
FMAT.ReadMaterial(mat);
|
||||
model.Nodes[1].Nodes.Add(FMAT);
|
||||
model.Nodes["FmatFolder"].Nodes.Add(FMAT);
|
||||
model.materials.Add(FMAT.Text, FMAT);
|
||||
}
|
||||
foreach (Shape shp in mdl.Shapes)
|
||||
@ -110,9 +110,10 @@ namespace FirstPlugin
|
||||
ReadShapesVertices(mesh, shp, vertexBuffer, model);
|
||||
mesh.MaterialIndex = shp.MaterialIndex;
|
||||
|
||||
model.Nodes[0].Nodes.Add(mesh);
|
||||
model.Nodes["FshpFolder"].Nodes.Add(mesh);
|
||||
model.shapes.Add(mesh);
|
||||
}
|
||||
|
||||
}
|
||||
public static Shape SaveShape(FSHP fshp)
|
||||
{
|
||||
|
@ -97,6 +97,10 @@ namespace FirstPlugin
|
||||
}
|
||||
public static void ReadModel(FMDL model, Model mdl)
|
||||
{
|
||||
Console.WriteLine("matcount " + mdl.Materials.Count);
|
||||
Console.WriteLine("shpcount " + mdl.Shapes.Count);
|
||||
Console.WriteLine("skelcount " + mdl.Skeleton.Bones.Count);
|
||||
|
||||
if (model == null)
|
||||
model = new FMDL();
|
||||
model.Text = mdl.Name;
|
||||
@ -115,6 +119,7 @@ namespace FirstPlugin
|
||||
}
|
||||
foreach (Shape shp in mdl.Shapes.Values)
|
||||
{
|
||||
|
||||
VertexBuffer vertexBuffer = mdl.VertexBuffers[shp.VertexBufferIndex];
|
||||
Material material = mdl.Materials[shp.MaterialIndex];
|
||||
FSHP mesh = new FSHP();
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -37,8 +37,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="AssimpNet, Version=4.1.0.0, Culture=neutral, PublicKeyToken=0d51b391f59f42a6, processorArchitecture=MSIL">
|
||||
<HintPath>..\Toolbox\Lib\AssimpNet.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
<HintPath>..\packages\AssimpNet.4.1.0\lib\net40\AssimpNet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Be.Windows.Forms.HexBox">
|
||||
<HintPath>..\Toolbox\Lib\Be.Windows.Forms.HexBox.dll</HintPath>
|
||||
@ -961,4 +960,11 @@
|
||||
<None Include="Resources\NumbericUpDownArrow.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\AssimpNet.4.1.0\build\AssimpNet.targets" Condition="Exists('..\packages\AssimpNet.4.1.0\build\AssimpNet.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\AssimpNet.4.1.0\build\AssimpNet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\AssimpNet.4.1.0\build\AssimpNet.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user