Init
This commit is contained in:
398
Assets/MindPowerSdk/Model/lwAnimDataInfo.cs
Normal file
398
Assets/MindPowerSdk/Model/lwAnimDataInfo.cs
Normal file
@ -0,0 +1,398 @@
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MindPowerSdk
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public class lwAnimDataInfo
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPStruct)]
|
||||
/* this+0x4 */
|
||||
public lwAnimDataBone anim_bone;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPStruct)]
|
||||
/* this+0x8 */
|
||||
public lwAnimDataMatrix anim_mat;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPStruct)]
|
||||
/* this+0xc */
|
||||
public lwAnimDataMtlOpacitySet anim_mtlopac;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPStruct)]
|
||||
/* this+0x4c */
|
||||
public lwAnimDataTexUVSet anim_tex;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPStruct)]
|
||||
/* this+0x14c */
|
||||
public lwAnimDataTexImgSet anim_img;
|
||||
}
|
||||
|
||||
public enum lwBoneKeyInfoType
|
||||
{
|
||||
BONE_KEY_TYPE_MAT43 = 1,
|
||||
BONE_KEY_TYPE_MAT44 = 2,
|
||||
BONE_KEY_TYPE_QUAT = 3,
|
||||
BONE_KEY_TYPE_INVALID = -1
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct lwBoneBaseInfo
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
|
||||
/* this+0x0 */
|
||||
public char[] name;
|
||||
|
||||
/* this+0x40 */
|
||||
public uint id;
|
||||
|
||||
/* this+0x44 */
|
||||
public uint parent_id;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct lwBoneDummyInfo
|
||||
{
|
||||
/* this+0x0 */
|
||||
public uint id;
|
||||
|
||||
/* this+0x4 */
|
||||
public uint parent_bone_id;
|
||||
|
||||
/* this+0x8 */
|
||||
public Matrix4x4 mat;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public class lwMatrix43
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
|
||||
/* this+0x0 */
|
||||
public float[] m;
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public class lwBoneKeyInfo
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x0 */
|
||||
public lwMatrix43[] mat43_seq;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x4 */
|
||||
public Matrix4x4[] mat44_seq;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x8 */
|
||||
public Vector3[] pos_seq;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0xc */
|
||||
public Quaternion[] quat_seq;
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public class lwAnimDataMatrix
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x4 */
|
||||
public lwMatrix43[] _mat_seq;
|
||||
|
||||
/* this+0x8 */
|
||||
public uint _frame_num;
|
||||
|
||||
public int Load(BinaryReader fp, uint version)
|
||||
{
|
||||
this._frame_num = fp.ReadUInt32();
|
||||
this._mat_seq = StructReader.ReadStructArray<lwMatrix43>(fp, this._frame_num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int Load(BinaryReader fp, uint version, uint frames)
|
||||
{
|
||||
this._frame_num = fp.ReadUInt32();
|
||||
if (frames < _frame_num)
|
||||
_frame_num = frames;
|
||||
this._mat_seq = StructReader.ReadStructArray<lwMatrix43>(fp, this._frame_num);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public class lwAnimDataBone
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
/* this+0x4 */
|
||||
public struct lwBoneInfoHeader
|
||||
{
|
||||
/* this+0x0 */
|
||||
public uint bone_num;
|
||||
|
||||
/* this+0x4 */
|
||||
public uint frame_num;
|
||||
|
||||
/* this+0x8 */
|
||||
public uint dummy_num;
|
||||
|
||||
/* this+0xc */
|
||||
public lwBoneKeyInfoType key_type; // MindPower::lwBoneKeyInfoType
|
||||
};
|
||||
|
||||
/* this+0x4 */
|
||||
public lwBoneInfoHeader _header;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x14 */
|
||||
public lwBoneBaseInfo[] _base_seq;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x18 */
|
||||
public lwBoneDummyInfo[] _dummy_seq;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x1c */
|
||||
public lwBoneKeyInfo[] _key_seq;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x20 */
|
||||
public Matrix4x4[] _invmat_seq;
|
||||
|
||||
public int Load(BinaryReader fp, uint version)
|
||||
{
|
||||
if (version == 0)
|
||||
{
|
||||
uint old_version = fp.ReadUInt32();
|
||||
int x = 0;
|
||||
}
|
||||
|
||||
if (this._base_seq != null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
this._header = StructReader.ReadStruct<lwAnimDataBone.lwBoneInfoHeader>(fp);
|
||||
this._base_seq = StructReader.ReadStructArray<lwBoneBaseInfo>(fp, this._header.bone_num);
|
||||
this._key_seq = new lwBoneKeyInfo[this._header.bone_num];
|
||||
this._invmat_seq = StructReader.ReadStructArray<Matrix4x4>(fp, this._header.bone_num);
|
||||
this._dummy_seq = StructReader.ReadStructArray<lwBoneDummyInfo>(fp, this._header.dummy_num);
|
||||
|
||||
if (this._header.key_type == lwBoneKeyInfoType.BONE_KEY_TYPE_MAT43)
|
||||
{
|
||||
for (uint i = 0; i < this._header.bone_num; i++)
|
||||
{
|
||||
this._key_seq[i] = new lwBoneKeyInfo();
|
||||
lwBoneKeyInfo key = this._key_seq[i];
|
||||
key.mat43_seq = StructReader.ReadStructArray<lwMatrix43>(fp, this._header.frame_num);
|
||||
}
|
||||
}
|
||||
else if (this._header.key_type == lwBoneKeyInfoType.BONE_KEY_TYPE_MAT44)
|
||||
{
|
||||
for (uint i = 0; i < this._header.bone_num; i++)
|
||||
{
|
||||
this._key_seq[i] = new lwBoneKeyInfo();
|
||||
lwBoneKeyInfo key = this._key_seq[i];
|
||||
key.mat44_seq = StructReader.ReadStructArray<Matrix4x4>(fp, this._header.frame_num);
|
||||
}
|
||||
}
|
||||
else if (this._header.key_type == lwBoneKeyInfoType.BONE_KEY_TYPE_QUAT)
|
||||
{
|
||||
if (version >= 0x1003)
|
||||
{
|
||||
for (uint i = 0; i < this._header.bone_num; i++)
|
||||
{
|
||||
this._key_seq[i] = new lwBoneKeyInfo();
|
||||
lwBoneKeyInfo key = this._key_seq[i];
|
||||
key.pos_seq = StructReader.ReadStructArray<Vector3>(fp, this._header.frame_num);
|
||||
key.quat_seq = StructReader.ReadStructArray<Quaternion>(fp, this._header.frame_num);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint i = 0; i < this._header.bone_num; i++)
|
||||
{
|
||||
this._key_seq[i] = new lwBoneKeyInfo();
|
||||
lwBoneKeyInfo key = this._key_seq[i];
|
||||
uint pos_num = this._base_seq[i].parent_id == 0xffffffff ? this._header.frame_num : 1;
|
||||
key.pos_seq = StructReader.ReadStructArray<Vector3>(fp, pos_num);
|
||||
if (pos_num == 1)
|
||||
{
|
||||
for (uint j = 1; j < this._header.frame_num; j++)
|
||||
{
|
||||
key.pos_seq[i] = key.pos_seq[0];
|
||||
}
|
||||
}
|
||||
|
||||
key.quat_seq = StructReader.ReadStructArray<Quaternion>(fp, this._header.frame_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int Load(string file)
|
||||
{
|
||||
int ret = -1;
|
||||
if (!File.Exists(file))
|
||||
return -1;
|
||||
FileStream fs = File.Open(file, FileMode.Open, FileAccess.Read);
|
||||
BinaryReader fp = new BinaryReader(fs);
|
||||
|
||||
uint version = fp.ReadUInt32();
|
||||
if (version < 0x1000)
|
||||
{
|
||||
version = 0;
|
||||
|
||||
Debug.LogError("old animation file: " + file + ", need re-export it");
|
||||
|
||||
fp.Close();
|
||||
fs.Close();
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (this.Load(fp, version) >= 0)
|
||||
{
|
||||
// Overloaded version
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
fp.Close();
|
||||
fs.Close();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct lwKeyFloat
|
||||
{
|
||||
/* this+0x0 */
|
||||
public uint key;
|
||||
|
||||
/* this+0x4 */
|
||||
public uint slerp_type;
|
||||
|
||||
/* this+0x8 */
|
||||
public float data;
|
||||
};
|
||||
|
||||
public interface lwIAnimKeySetFloat
|
||||
{
|
||||
uint SetKeySequence(lwKeyFloat[] seq, uint num);
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public class lwAnimKeySetFloat : lwIAnimKeySetFloat
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x4 */
|
||||
public lwKeyFloat[] _data_seq;
|
||||
|
||||
/* this+0x8 */
|
||||
public uint _data_num;
|
||||
|
||||
/* this+0xc */
|
||||
public uint _data_capacity;
|
||||
|
||||
public uint SetKeySequence(lwKeyFloat[] seq, uint num)
|
||||
{
|
||||
_data_seq = seq;
|
||||
_data_num = num;
|
||||
_data_capacity = num;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct lwAnimDataMtlOpacity
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPStruct)]
|
||||
/* this+0x4 */
|
||||
public lwIAnimKeySetFloat _aks_ctrl;
|
||||
|
||||
public int Load(BinaryReader fp, uint version)
|
||||
{
|
||||
int ret = -1;
|
||||
uint num = fp.ReadUInt32();
|
||||
lwKeyFloat[] seq = StructReader.ReadStructArray<lwKeyFloat>(fp, num);
|
||||
this._aks_ctrl = new lwAnimKeySetFloat();
|
||||
if (this._aks_ctrl.SetKeySequence(seq, num) >= 0)
|
||||
{
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct lwAnimDataTexUV
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x4 */
|
||||
public Matrix4x4[] _mat_seq;
|
||||
|
||||
/* this+0x8 */
|
||||
public uint _frame_num;
|
||||
|
||||
public int Load(BinaryReader fp, uint version)
|
||||
{
|
||||
this._frame_num = fp.ReadUInt32();
|
||||
this._mat_seq = StructReader.ReadStructArray<Matrix4x4>(fp, this._frame_num);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct lwAnimDataTexUVSet
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
|
||||
public lwAnimDataTexUV[] mtl;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public class lwAnimDataTexImg
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPArray)]
|
||||
/* this+0x4 */
|
||||
public lwTexInfo[] _data_seq;
|
||||
|
||||
/* this+0x8 */
|
||||
public uint _data_num;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 260)]
|
||||
/* this+0xc */
|
||||
public char[] _tex_path;
|
||||
|
||||
public int Load(BinaryReader fp, uint version)
|
||||
{
|
||||
int ret = 0;
|
||||
if (version == 0)
|
||||
{
|
||||
Debug.LogError("old version file, need re-export it");
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._data_num = fp.ReadUInt32();
|
||||
this._data_seq = StructReader.ReadStructArray<lwTexInfo>(fp, this._data_num);
|
||||
}
|
||||
|
||||
;
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct lwAnimDataMtlOpacitySet
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
||||
public lwAnimDataMtlOpacity[] mtl;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct lwAnimDataTexImgSet
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
|
||||
public lwAnimDataTexImg[] mtl;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user