public static DualQuaternion GetBoneLocalDQ(IINode _node, int _frame, ROD_ExportG r) { IINode _parent_node = _node.ParentNode; IIGameNode _GNode = r.maxGlobal.IGameInterface.GetIGameNode(_node); IIGameNode _parentGNode = r.maxGlobal.IGameInterface.GetIGameNode(_parent_node); int _ticks_per_frame = r.maxGlobal.TicksPerFrame; IGMatrix _node_Gmatrix = _GNode.GetWorldTM(_frame * _ticks_per_frame); IGMatrix _parent_Gmatrix = r.maxGlobal.GMatrix.Create(); if (_parentGNode != null) { _parent_Gmatrix = _parentGNode.GetWorldTM(_frame * _ticks_per_frame); } IGMatrix _inverse_parent_Gmatrix = _parent_Gmatrix.Inverse; IGMatrix _local_node_Gmatrix = _inverse_parent_Gmatrix.MultiplyBy(_node_Gmatrix); Matrix sharpM = _local_node_Gmatrix.convertTo(); Quaternion sharpQM; Vector3 sharpSc; Vector3 sharpTr; sharpM.Decompose(out sharpSc, out sharpQM, out sharpTr); Vector3 sharpT = _local_node_Gmatrix.Translation.convertToVector3(); DualQuaternion DQ = new DualQuaternion(sharpQM, sharpT); DQ.Normalize(); return DQ; }
public static DualQuaternion GetBoneWorldDQ(IINode _node, int _frame, ROD_ExportG r) { IInterval interval = r.maxGlobal.Interval.Create(); interval.SetInfinite(); IIGameNode GNode = r.maxGlobal.IGameInterface.GetIGameNode(_node); int _ticks_per_frame = r.maxGlobal.TicksPerFrame; IGMatrix _node_Gmatrix = GNode.GetWorldTM(_frame * _ticks_per_frame); Matrix sharpM = _node_Gmatrix.convertTo(); Quaternion sharpQM; Vector3 sharpSc; Vector3 sharpTr; sharpM.Decompose(out sharpSc, out sharpQM, out sharpTr); Vector3 sharpT = _node_Gmatrix.Translation.convertToVector3(); DualQuaternion DQ = new DualQuaternion(new Quaternion(sharpQM.X, sharpQM.Y, sharpQM.Z, sharpQM.W), sharpT); return DQ; }
public static DualQuaternion GetBoneBindDQ(IINode _node, ROD_ExportG r) { return GetBoneWorldDQ(_node, 0, r); }
public static bool Export_To(string _filepath) { ROD_ExportG r = new ROD_ExportG(); foreach (uint _handle in SelectedNodes) { IINode _node = r.maxInterface.GetINodeByHandle(_handle); IIDerivedObject _gObject = (IIDerivedObject)_node.ObjectRef; IClass_ID classID = r.maxGlobal.Class_ID.Create((uint)BuiltInClassIDA.TRIOBJ_CLASS_ID, 0); ITriObject _mObject = (ITriObject)_gObject.ObjRef.ConvertToType(0, classID); IMesh _mMesh = _mObject.Mesh; _mMesh.BuildNormals(); IIDerivedObject theObj = (IIDerivedObject)_node.ObjectRef; for (int m = 0; m < theObj.Modifiers.Count; m++) { IModifier theModifier = theObj.GetModifier(m); if (theModifier.ClassName == "Skin") { IISkin _skin = (IISkin)theModifier.GetInterface((InterfaceID)(0x00010000)); IISkinContextData _skinContext = _skin.GetContextInterface(_node); ComputeVertexData(_mMesh, _skinContext, semantic, _filepath); } } } return true; }
public static void BuildLJoint(IINode _node, int _parentId, Pose _pose, int _frame, ROD_ExportG r) { DualQuaternion WDQ = GetBoneWorldDQ(_node, _frame, r); DualQuaternion LDQ = GetBoneLocalDQ(_node, _frame, r); Joint _joint = new Joint(_pose.joints.Count, _node.Name, _parentId, WDQ, LDQ); _pose.joints.Add(_joint); int childrensNb = _node.NumberOfChildren; for (int i = 0; i < childrensNb; i++) { if (!_node.GetChildNode(i).Name.EndsWith("Nub")) { BuildLJoint(_node.GetChildNode(i), _joint.id, _pose, _frame, r); } } }
public static void BuildBind(IINode _node, int _parentId, Pose _pose, ROD_ExportG r) { DualQuaternion DQ = GetBoneBindDQ(_node, r); Joint _joint = new Joint(_pose.joints.Count, _node.Name, _parentId, DQ, DualQuaternion.Identity); _pose.joints.Add(_joint); int childrensNb = _node.NumberOfChildren; for (int i = 0; i < childrensNb; i++) { if (!_node.GetChildNode(i).Name.EndsWith("Nub")) { BuildBind(_node.GetChildNode(i), _joint.id, _pose, r); } } }
public static bool Bone_To(List<int> _frames, string _filename, string _filenameSkeleton) { ROD_ExportG r = new ROD_ExportG(); foreach (uint _handle in SelectedNodes) { IINode _node = r.maxInterface.GetINodeByHandle(_handle); IIDerivedObject theObj = (IIDerivedObject)_node.ObjectRef; IInterval interval = r.maxGlobal.Interval.Create(); interval.SetInfinite(); r.maxGlobal.IGameInterface.InitialiseIGame(false); for (int m = 0; m < theObj.Modifiers.Count; m++) { IModifier theModifier = theObj.GetModifier(m); if (theModifier.ClassName == "Skin") { IISkin _skin = (IISkin)theModifier.GetInterface((InterfaceID)(0x00010000)); IINode _bone = _skin.GetBone(0); int nbBones = _skin.NumBones; List<string> boneName = new List<string>(); for (int b = 0; b < nbBones; b++) { boneName.Add(_skin.GetBone(b).Name); } #region create bindPose World Pose bindPose = new Pose("bindPose"); BuildBind(_bone, -1, bindPose, r); #endregion #region create bindPose Local off /* Joint BLjoint = BuildBindLocal(_bone, null, r); List<Joint> jointsBL = BLjoint.GetEnumerable().ToList(); for (int i = 0; i < jointsBL.Count; i++) { int Id = boneName.IndexOf(jointsBL[i].name); jointsBL[i].id = Id; } Pose TposeL = new Pose("TPoseL", BLjoint); */ #endregion Skeleton skelete = new Skeleton("skelete", bindPose); skelete.saveToFile(_filenameSkeleton); ROD_core.Graphics.Animation.Clip_Skinning clip = new ROD_core.Graphics.Animation.Clip_Skinning(); clip.sequencesData = new List<Pose>(); clip.sequencesTiming = new List<TimeSpan>(); for (int f = 0; f < _frames.Count; f++) { // create Pose at frame (_frame) Pose _pose = new Pose("frame" + _frames[f].ToString()); BuildLJoint(_bone, -1, _pose, _frames[f], r); clip.sequencesData.Add(_pose); clip.sequencesTiming.Add(TimeSpan.FromSeconds(_frames[f] / 3)); } clip.saveToFile(_filename); } } } return true; }