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); } } }
private string GetBoneLocalTransform(GrnBone bone, string nameM3) { Maxscript.Command("{0} = matrix3 1", nameM3); Maxscript.Command("{0} = transmatrix {1}", nameM3, Maxscript.Point3Literal(bone.Position)); Maxscript.Command("{0} = (inverse(quat {1} {2} {3} {4}) as matrix3) * {0}", nameM3, bone.Rotation.X, bone.Rotation.Y, bone.Rotation.Z, bone.Rotation.W); Maxscript.Command("{0} = (matrix3 [{1}, {2}, {3}] [{4}, {5}, {6}] [{7}, {8}, {9}] [0,0,0]) * {0}", nameM3, bone.Scale.A1, bone.Scale.A2, bone.Scale.A3, bone.Scale.B1, bone.Scale.B2, bone.Scale.B3, bone.Scale.C1, bone.Scale.C2, bone.Scale.C3); return nameM3; }
private string CreateBone(GrnBone bone) { string boneNode = "boneNode"; Maxscript.Command("boneNode = dummy name:\"{0}\" boxsize:[0.25,0.25,0.25]", bone.Name); Maxscript.Command("boneNode.transform = {0}", this.GetBoneLocalTransform(bone, "boneTransMat")); //this.GetBoneLocalTransform(bone, "tfm"); //Maxscript.Command("boneNode = bonesys.createbone tfm.row4 (tfm.row4 + 0.01 * (normalize tfm.row1)) (normalize tfm.row3)"); //Maxscript.Command("boneNode.name = \"{0}\"", bone.Name); //Maxscript.Command("boneNode.width = 0.1"); //Maxscript.Command("boneNode.height = 0.1"); //Maxscript.Command("boneNode.wirecolor = yellow"); //Maxscript.Command("boneNode.showlinks = true"); //Maxscript.Command("boneNode.setBoneEnable false 0"); //Maxscript.Command("boneNode.pos.controller = TCB_position ()"); //Maxscript.Command("boneNode.rotation.controller = TCB_rotation ()"); return boneNode; }