Example #1
0
        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);
        }
Example #2
0
        public static DualQuaternion convertToDQ(this IGMatrix _input)
        {
            Matrix     _matrix = new Matrix(_input.GetRow(0).X, _input.GetRow(0).Y, _input.GetRow(0).Z, 0, _input.GetRow(1).X, _input.GetRow(1).Y, _input.GetRow(1).Z, 0, _input.GetRow(2).X, _input.GetRow(2).Y, _input.GetRow(2).Z, 0, _input.GetRow(3).X, _input.GetRow(3).Y, _input.GetRow(3).Z, 1);
            Quaternion _node_LQ;
            Vector3    _node_LS;
            Vector3    _node_LT;

            _matrix.Decompose(out _node_LS, out _node_LQ, out _node_LT);
            DualQuaternion _output = new DualQuaternion(_node_LQ, _node_LT);

            return(_output);
        }
Example #3
0
        public static DualQuaternion GetBoneWorldDQ(IINode _node, int _frame)
        {
            IInterval interval = maxGlobal.Interval.Create();

            interval.SetInfinite();
            IIGameNode     GNode            = maxGlobal.IGameInterface.GetIGameNode(_node);
            int            _ticks_per_frame = maxGlobal.TicksPerFrame;
            IGMatrix       _node_Gmatrix    = GNode.GetWorldTM(_frame * _ticks_per_frame);
            DualQuaternion DQ = _node_Gmatrix.convertToDQ();

            return(DQ);
        }
Example #4
0
        public static void BuildBind(IINode _node, int _parentId, Pose _pose)
        {
            DualQuaternion DQ     = GetBoneBindDQ(_node);
            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);
                }
            }
        }
Example #5
0
        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);
                }
            }
        }
Example #6
0
        public static DualQuaternion GetBoneLocalDQ(IINode _node, int[] _frames, int _f)
        {
            IINode     _parent_node     = _node.ParentNode;
            IIGameNode _GNode           = maxGlobal.IGameInterface.GetIGameNode(_node);
            IIGameNode _parentGNode     = maxGlobal.IGameInterface.GetIGameNode(_parent_node);
            int        _ticks_per_frame = maxGlobal.TicksPerFrame;

            // node Local Transform
            IGMatrix       _node_LGmatrix = _GNode.GetLocalTM(_frames[_f] * _ticks_per_frame);
            DualQuaternion _node_LDQ      = _node_LGmatrix.convertToDQ(Transformation.Rotation);

            _node_LDQ.Normalize();
            IGMatrix       _node_BLGmatrix = _GNode.GetLocalTM(0);
            DualQuaternion _node_BLDQ      = _node_BLGmatrix.convertToDQ(Transformation.Rotation);

            _node_BLDQ.Normalize();
            DualQuaternion _node_LTDQL = _node_LDQ * DualQuaternion.Conjugate(_node_BLDQ);

            return(_node_LTDQL);
        }
Example #7
0
        public static DualQuaternion convertToDQ(this IGMatrix _input, Transformation _transformation)
        {
            Matrix     _matrix = new Matrix(_input.GetRow(0).X, _input.GetRow(0).Y, _input.GetRow(0).Z, 0, _input.GetRow(1).X, _input.GetRow(1).Y, _input.GetRow(1).Z, 0, _input.GetRow(2).X, _input.GetRow(2).Y, _input.GetRow(2).Z, 0, _input.GetRow(3).X, _input.GetRow(3).Y, _input.GetRow(3).Z, 1);
            Quaternion _node_LQ;
            Vector3    _node_LS;
            Vector3    _node_LT;

            _matrix.Decompose(out _node_LS, out _node_LQ, out _node_LT);
            DualQuaternion _output = DualQuaternion.Identity;

            if (_transformation == Transformation.All)
            {
                _output = new DualQuaternion(_node_LQ, _node_LT);
            }
            if (_transformation == Transformation.Rotation)
            {
                _output = new DualQuaternion(_node_LQ, Vector3.Zero);
            }
            if (_transformation == Transformation.Translation)
            {
                _output = new DualQuaternion(Quaternion.Identity, _node_LT);
            }
            return(_output);
        }
Example #8
0
 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;
 }
Example #9
0
 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;
 }