private void ExportSkeleton()
{
int numBones = Maxscript.QueryInteger("grnBones.count");
this.File.Bones.Add(new GrnBone(this.File));
this.File.Bones[0].DataExtensionIndex = this.File.AddDataExtension("__Root");
this.File.Bones[0].Rotation = new Quaternion(1, 0, 0, 0);
this.File.Bones[0].ParentIndex = 0;
for (int i = 1; i <= numBones; ++i)
{
try
{
GrnBone bone = new GrnBone(this.File);
bone.DataExtensionIndex = this.File.AddDataExtension(Maxscript.QueryString("grnBones[{0}].name", i));
bone.ParentIndex = Maxscript.QueryInteger("grnBoneParents[{0}]", i);
Maxscript.Command("boneTransMat = grnBones[{0}].transform", i);
if (bone.ParentIndex > 0)
{
Maxscript.Command("boneTransMat = boneTransMat * inverse(grnBones[{0}].parent.transform)", i);
}
Vector3D pos;
Quaternion rot;
Matrix3x3 scale;
this.GetTransformPRS("boneTransMat", out pos, out rot, out scale);
bone.Position = pos;
bone.Rotation = rot;
bone.Scale = scale;
this.File.Bones.Add(bone);
}
catch (Exception ex)
{
throw new Exception("Bone Index = " + i, ex);
}
}
}