public static CurveHandle GetCurve(IINode _node, int[] _frames, int _f, int _samplingRate) { CurveHandle result = new CurveHandle(Vector2.Zero, Vector2.Zero); IIGameNode _GNode = maxGlobal.IGameInterface.GetIGameNode(_node); int _ticks_per_frame = maxGlobal.TicksPerFrame; float delta = 0.0f; if (_f > 0) { List <Vector3> _samples = new List <Vector3>(); int nb_of_frames = _frames[_f] - _frames[_f - 1]; for (int i = _frames[_f - 1]; i <= _frames[_f]; i += _samplingRate) { float proportion = 1.0f - ((_frames[_f] - i) / (float)(nb_of_frames)); IGMatrix _node_LGmatrix = _GNode.GetLocalTM(i * _ticks_per_frame); DualQuaternion _node_LDQ = _node_LGmatrix.convertToDQ(Transformation.Rotation); _samples.Add(new Vector3(proportion, Math.Abs(_node_LDQ.RollPitchYaw.X) + Math.Abs(_node_LDQ.RollPitchYaw.Y) + Math.Abs(_node_LDQ.RollPitchYaw.Z), 0)); } List <BezierCurveFitting.BezierPoint> points = BezierCurveFitting.FitCurves.FitCurveBy(BezierCurveFitting.Method.Length, _samples.ToArray(), 0.01f, 2); delta = points[1].point.Y - points[0].point.Y; float val = points[1].foreHandle.Value.X; if (delta != 0) { val = (points[1].point.Y - points[1].foreHandle.Value.Y) / delta; } result.easeIn = new Vector2(points[1].foreHandle.Value.X, val); } else if (_f == 0) { result.easeIn = new Vector2(0.0f, 0.0f); } if (_f < _frames.Length - 1) { List <Vector3> _samples = new List <Vector3>(); int nb_of_frames = _frames[_f + 1] - _frames[_f]; for (int i = _frames[_f]; i <= _frames[_f + 1]; i += _samplingRate) { float proportion = 1.0f - ((_frames[_f + 1] - i) / (float)(nb_of_frames)); IGMatrix _node_LGmatrix = _GNode.GetLocalTM(i * _ticks_per_frame); DualQuaternion _node_LDQ = _node_LGmatrix.convertToDQ(Transformation.Rotation); _samples.Add(new Vector3(proportion, Math.Abs(_node_LDQ.RollPitchYaw.X) + Math.Abs(_node_LDQ.RollPitchYaw.Y) + Math.Abs(_node_LDQ.RollPitchYaw.Z), 0)); } List <BezierCurveFitting.BezierPoint> points = BezierCurveFitting.FitCurves.FitCurveBy(BezierCurveFitting.Method.Length, _samples.ToArray(), 0.01f, 2); delta = points[1].point.Y - points[0].point.Y; float val = points[0].afterHandle.Value.X; if (delta != 0) { val = (points[1].point.Y - points[0].afterHandle.Value.Y) / delta; } result.easeOut = new Vector2(points[0].afterHandle.Value.X, val); } else if (_f == _frames.Length - 1) { result.easeOut = new Vector2(1f, 1f); } return(result); }
public static void BuildLJoint(IINode _node, int _parentId, Pose _pose, int[] _frames, int _f, int _samplingRate, Pose _bindPose) { DualQuaternion LDQ = GetBoneLocalDQ(_node, _frames, _f); CurveHandle curve = GetCurve(_node, _frames, _f, _samplingRate); Joint _joint = new Joint(_pose.joints.Count, _node.Name, _parentId, DualQuaternion.Identity, LDQ, curve); _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, _frames, _f, _samplingRate, _bindPose); } } }