상속: IJoint
예제 #1
0
        //update JOINT
        private void UpdateJoint(ref int channelIndex, int frameIndex, BVHJoint joint)
        {
            List <float> frame;
            Vector3D     translate, rotate;

            //get MOTION data of frameIndex
            frame = FFrames[frameIndex];

            //init transform
            translate = new Vector3D(0.0);
            rotate    = new Vector3D(0.0);

            //set transform channel count times
            for (int i = 0; i < joint.GetChannelCount(); i++)
            {
                //get one value from MOTION data
                float f = frame[channelIndex++];

                //get target channel
                BVHChannel ch = joint.Channels[i];

                //set value to channel
                if (ch == BVHChannel.X_POSITION)
                {
                    translate.x = f;
                }
                else if (ch == BVHChannel.Y_POSITION)
                {
                    translate.y = f;
                }
                else if (ch == BVHChannel.Z_POSITION)
                {
                    translate.z = f;// -f;   //Right Hand to Left Hand
                }
                else if (ch == BVHChannel.X_ROTATION)
                {
                    //Degrees into Radians
                    rotate.x = f * VMath.DegToRad;
                }
                else if (ch == BVHChannel.Y_ROTATION)
                {
                    //Degrees into Radians
                    rotate.y = f * VMath.DegToRad;
                }
                else if (ch == BVHChannel.Z_ROTATION)
                {
                    //Degrees into Radians
                    rotate.z = f * VMath.DegToRad;
                }
            }

            //update AnimationTransform
            joint.AnimationTransform = VMath.Transform(translate, new Vector3D(1.0), rotate);

            //recusive call all children
            for (int i = 0; i < joint.Children.Count; i++)
            {
                UpdateJoint(ref channelIndex, frameIndex, (BVHJoint)joint.Children[i]);
            }
        }
예제 #2
0
        public IJoint DeepCopy()
        {
            BVHJoint copy = new BVHJoint(Id, Name, Parent);

            copy.BaseTransform      = new Matrix4x4(BaseTransform);
            copy.AnimationTransform = new Matrix4x4(AnimationTransform);

            foreach (IJoint child in Children)
            {
                copy.AddChild(child.DeepCopy());
            }

            for (int i = 0; i < 3; i++)
            {
                copy.Constraints[i] = new Vector2D(Constraints[i]);
            }

            return(copy);
        }
예제 #3
0
        //parse JOINT
        private void ParseJoint(ref int index, ref List <string> tokens, BVHJoint parent)
        {
            //NOTE: can't assign same joint name in vvvv Skeleton!
            string name = tokens[index++];
            string tmpName;
            int    num = 2;

            //set name without number as temp
            tmpName = name;

            //rename while enable
            while (FSkeleton.JointTable.ContainsKey(name))
            {
                name = tmpName + num.ToString();
                num++;
            }

            //create BVHJoint
            BVHJoint joint = new BVHJoint(FJointCounter++, name, parent);

            if (parent != null)
            {
                FSkeleton.InsertJoint(parent.Name, joint);
            }
            else
            {
                //"parent == null" means ROOT

                FSkeleton.InsertJoint("", joint);

                FSkeleton.Root = joint;

                FSkeleton.BuildJointTable();    //what's happen here?
            }

            while (index < tokens.Count)
            {
                //get token
                string token = tokens[index++];

                if (token == "OFFSET")
                {
                    Vector3D translate = new Vector3D();

                    //set offset(=initial) position

                    //This is not working with some culture settings
                    //translate.x = double.Parse(tokens[index++]);
                    //translate.y = double.Parse(tokens[index++]);
                    //translate.z = double.Parse(tokens[index++]);// *-1;   //Right Hand to Left Hand

                    //to solve that, use InvariantInfo
                    translate.x = double.Parse(tokens[index++], NumberFormatInfo.InvariantInfo);
                    translate.y = double.Parse(tokens[index++], NumberFormatInfo.InvariantInfo);
                    translate.z = double.Parse(tokens[index++], NumberFormatInfo.InvariantInfo);


                    //set BaseTransform
                    joint.BaseTransform = VMath.Translate(translate);
                    //joint.AnimationTransform = VMath.Translate(translate);
                }
                else if (token == "CHANNELS")
                {
                    //get channel count from token
                    //int channelCount = int.Parse(tokens[index++]);
                    int channelCount = int.Parse(tokens[index++], NumberFormatInfo.InvariantInfo);

                    //set channel count
                    joint.SetChannelCount(channelCount);

                    //update total count of Skeleton's channels
                    FChannelCountOfSkeleton += channelCount;

                    //processing each channel
                    for (int i = 0; i < channelCount; i++)
                    {
                        //to lower case
                        string channel = tokens[index++].ToLower();

                        //detect axis and tranform type by first two char
                        char axis  = channel[0];
                        char trans = channel[1];
                        switch (trans)
                        {
                        case 'p':       //position
                            switch (axis)
                            {
                            case 'x': joint.SetChannel(i, BVHChannel.X_POSITION); break;

                            case 'y': joint.SetChannel(i, BVHChannel.Y_POSITION); break;

                            case 'z': joint.SetChannel(i, BVHChannel.Z_POSITION); break;
                            }
                            break;

                        case 'r':       //rotation
                            switch (axis)
                            {
                            case 'x': joint.SetChannel(i, BVHChannel.X_ROTATION); break;

                            case 'y': joint.SetChannel(i, BVHChannel.Y_ROTATION); break;

                            case 'z': joint.SetChannel(i, BVHChannel.Z_ROTATION); break;
                            }
                            break;
                        }
                    }
                }
                else if (token == "JOINT")
                {
                    //recusive call
                    ParseJoint(ref index, ref tokens, joint);
                }
                else if (token == "End")
                {
                    //recusive call
                    ParseJoint(ref index, ref tokens, joint);
                }
                else if (token == "}")
                {
                    //go next
                    break;
                }
            }
        }
예제 #4
0
        //update JOINT
        private void UpdateJoint(ref int channelIndex, int frameIndex, BVHJoint joint)
        {
            List<float> frame;
            Vector3D translate, rotate;

            //get MOTION data of frameIndex
            frame = FFrames[frameIndex];

            //init transform
            translate = new Vector3D(0.0);
            rotate = new Vector3D(0.0);

            //set transform channel count times
            for (int i = 0; i < joint.GetChannelCount(); i++)
            {
                //get one value from MOTION data
                float f = frame[channelIndex++];

                //get target channel
                BVHChannel ch = joint.Channels[i];

                //set value to channel
                if (ch == BVHChannel.X_POSITION)
                {
                    translate.x = f;
                }
                else if (ch == BVHChannel.Y_POSITION)
                {
                    translate.y = f;
                }
                else if (ch == BVHChannel.Z_POSITION)
                {
                    translate.z = f;// -f;   //Right Hand to Left Hand
                }
                else if (ch == BVHChannel.X_ROTATION)
                {
                    //Degrees into Radians
                    rotate.x = f * VMath.DegToRad;
                }
                else if (ch == BVHChannel.Y_ROTATION)
                {
                    //Degrees into Radians
                    rotate.y = f * VMath.DegToRad;
                }
                else if (ch == BVHChannel.Z_ROTATION)
                {
                    //Degrees into Radians
                    rotate.z = f * VMath.DegToRad;
                }
            }

            //update AnimationTransform
            joint.AnimationTransform = VMath.Transform(translate, new Vector3D(1.0), rotate);

            //recusive call all children
            for (int i = 0; i < joint.Children.Count; i++)
            {
                UpdateJoint(ref channelIndex, frameIndex, (BVHJoint)joint.Children[i]);
            }
        }
예제 #5
0
        //parse JOINT
        private void ParseJoint(ref int index, ref List<string> tokens, BVHJoint parent)
        {
            //NOTE: can't assign same joint name in vvvv Skeleton!
            string name = tokens[index++];
            string tmpName;
            int num = 2;

            //set name without number as temp
            tmpName = name;

            //rename while enable
            while (FSkeleton.JointTable.ContainsKey(name))
            {
                name = tmpName + num.ToString();
                num++;
            }

            //create BVHJoint
            BVHJoint joint = new BVHJoint(FJointCounter++, name, parent);

            if (parent != null)
            {
                FSkeleton.InsertJoint(parent.Name, joint);
            }
            else
            {
                //"parent == null" means ROOT

                FSkeleton.InsertJoint("", joint);

                FSkeleton.Root = joint;

                FSkeleton.BuildJointTable();    //what's happen here?
            }

            while (index < tokens.Count)
            {
                //get token
                string token = tokens[index++];

                if (token == "OFFSET")
                {
                    Vector3D translate = new Vector3D();

                    //set offset(=initial) position

                    //This is not working with some culture settings
                    //translate.x = double.Parse(tokens[index++]);
                    //translate.y = double.Parse(tokens[index++]);
                    //translate.z = double.Parse(tokens[index++]);// *-1;   //Right Hand to Left Hand

                    //to solve that, use InvariantInfo
                    translate.x = double.Parse(tokens[index++], NumberFormatInfo.InvariantInfo);
                    translate.y = double.Parse(tokens[index++], NumberFormatInfo.InvariantInfo);
                    translate.z = double.Parse(tokens[index++], NumberFormatInfo.InvariantInfo);

                    //set BaseTransform
                    joint.BaseTransform = VMath.Translate(translate);
                    //joint.AnimationTransform = VMath.Translate(translate);
                }
                else if (token == "CHANNELS")
                {
                    //get channel count from token
                    //int channelCount = int.Parse(tokens[index++]);
                    int channelCount = int.Parse(tokens[index++], NumberFormatInfo.InvariantInfo);

                    //set channel count
                    joint.SetChannelCount(channelCount);

                    //update total count of Skeleton's channels
                    FChannelCountOfSkeleton += channelCount;

                    //processing each channel
                    for (int i = 0; i < channelCount; i++)
                    {
                        //to lower case
                        string channel = tokens[index++].ToLower();

                        //detect axis and tranform type by first two char
                        char axis = channel[0];
                        char trans = channel[1];
                        switch (trans)
                        {
                            case 'p':   //position
                                switch (axis)
                                {
                                    case 'x': joint.SetChannel(i, BVHChannel.X_POSITION); break;
                                    case 'y': joint.SetChannel(i, BVHChannel.Y_POSITION); break;
                                    case 'z': joint.SetChannel(i, BVHChannel.Z_POSITION); break;
                                }
                                break;
                            case 'r':   //rotation
                                switch (axis)
                                {
                                    case 'x': joint.SetChannel(i, BVHChannel.X_ROTATION); break;
                                    case 'y': joint.SetChannel(i, BVHChannel.Y_ROTATION); break;
                                    case 'z': joint.SetChannel(i, BVHChannel.Z_ROTATION); break;
                                }
                                break;
                        }
                    }
                }
                else if (token == "JOINT")
                {
                    //recusive call
                    ParseJoint(ref index, ref tokens, joint);
                }
                else if (token == "End")
                {
                    //recusive call
                    ParseJoint(ref index, ref tokens, joint);
                }
                else if (token == "}")
                {
                    //go next
                    break;
                }
            }
        }
예제 #6
0
        public IJoint DeepCopy()
        {
            BVHJoint copy = new BVHJoint(Id, Name, Parent);
            copy.BaseTransform = new Matrix4x4(BaseTransform);
            copy.AnimationTransform = new Matrix4x4(AnimationTransform);

            foreach (IJoint child in Children)
                copy.AddChild(child.DeepCopy());

            for (int i = 0; i < 3; i++)
                copy.Constraints[i] = new Vector2D(Constraints[i]);

            return copy;
        }