Esempio n. 1
0
        private static void ConvertJointFrame(JointFrame jfDest, string jointName, FrameElement srcFrame)
        {
            Matrix3D matrix;

            switch (jointName)
            {
            case "hip":
                matrix = jfDest.Matrix;
                JointFrame jfRoot     = srcFrame.GetJointFrame("root");
                Matrix3D   rootMatrix = jfRoot.Matrix;
                rootMatrix.OffsetX *= 4;
                rootMatrix.OffsetY *= 4;
                rootMatrix.OffsetZ *= 4;
                rootMatrix.OffsetY += 12;
                matrix.Append(rootMatrix);
                jfDest.Matrix = matrix;
                break;

            case "abdomen":
                matrix = jfDest.Matrix;
                JointFrame jfLower     = srcFrame.GetJointFrame("lower_body");
                Matrix3D   lowerMatrix = jfLower.Matrix;
                lowerMatrix.Invert();
                matrix.Append(lowerMatrix);
                jfDest.Matrix = matrix;
                break;

            case "lShldr":
                matrix = jfDest.Matrix;
                matrix.RotatePrepend(new Quaternion(new Vector3D(0, 0, 1), -35));
                jfDest.Matrix = matrix;
                break;

            case "lForeArm":
            case "lHand":
                matrix = jfDest.Matrix;
                matrix.RotatePrepend(new Quaternion(new Vector3D(0, 0, 1), -35));
                matrix.Rotate(new Quaternion(new Vector3D(0, 0, 1), 35));
                jfDest.Matrix = matrix;
                break;

            case "rShldr":
                // jfDest.AddValue("Zrotation", 35);
                matrix = jfDest.Matrix;
                matrix.RotatePrepend(new Quaternion(new Vector3D(0, 0, 1), 35));
                jfDest.Matrix = matrix;
                break;

            case "rForeArm":
            case "rHand":
                matrix = jfDest.Matrix;
                matrix.RotatePrepend(new Quaternion(new Vector3D(0, 0, 1), 35));
                matrix.Rotate(new Quaternion(new Vector3D(0, 0, 1), -35));
                jfDest.Matrix = matrix;
                break;
            }
        }
Esempio n. 2
0
        private void UpdateFrame()
        {
            if (m_bvh == null)
            {
                return;
            }

            FrameElement frame = m_bvh.FrameList[(int)slider1.Value];

            foreach (CompositeElement joint in m_bvh.JointList)
            {
                JointFrame        jf        = frame.GetJointFrame(joint.Name);
                Transform3DGroup  tg        = (Transform3DGroup)joint.Visual.Transform;
                MatrixTransform3D transform = (MatrixTransform3D)tg.Children[0];
                transform.Matrix = jf.Matrix;
            }
        }
Esempio n. 3
0
        public BVH Convert()
        {
            BVH dest = SLTemplate();

            dest.Frames.Value    = m_src.Frames.Value + 1;
            dest.FrameTime.Value = m_src.FrameTime.Value;
            dest.FrameList.Clear();

            FrameElement firstFrame = new FrameElement(dest);

            firstFrame.GetJointFrame("hip").SetValue("Yposition", 43.5285);
            dest.FrameList.Add(firstFrame);

            foreach (FrameElement frame in m_src.FrameList)
            {
                dest.FrameList.Add(ConvertFrame(dest, frame));
            }

            return(dest);
        }
Esempio n. 4
0
        private FrameElement ConvertFrame(BVH dest, FrameElement srcFrame)
        {
            FrameElement destFrame = new FrameElement(dest);

            foreach (CompositeElement joint in dest.JointList)
            {
                JointFrame jfDest = destFrame.GetJointFrame(joint.Name);
                JointFrame jfSrc  = srcFrame.GetJointFrame(GetSrcJointName(joint.Name));
                if (jfSrc == null)
                {
                    continue;
                }

                foreach (string channel in new string[] { "Zrotation", "Xrotation", "Yrotation" })
                {
                    jfDest.SetValue(channel, jfSrc.GetValue(channel));
                }

                ConvertJointFrame(jfDest, joint.Name, srcFrame);
            }
            return(destFrame);
        }
Esempio n. 5
0
        private void Add(Element child)
        {
            RootElement root = child as RootElement;

            if (root != null)
            {
                m_root = root;
                return;
            }

            FramesElement frames = child as FramesElement;

            if (frames != null)
            {
                m_frames = frames;
                return;
            }

            FrameTimeElement frame_time = child as FrameTimeElement;

            if (frame_time != null)
            {
                m_frame_time = frame_time;
                return;
            }

            FrameElement frame = child as FrameElement;

            if (frame != null)
            {
                m_frame_list.Add(frame);
                return;
            }

            throw new NotSupportedException();
        }
Esempio n. 6
0
        public void Load(Stream stream)
        {
            using (StreamReader reader = new StreamReader(stream))
            {
                Element         current = null;
                Stack <Element> stack   = new Stack <Element>();

                while (!reader.EndOfStream)
                {
                    string   line   = reader.ReadLine().Trim();
                    string[] fields = line.Split(' ', '\t');
                    switch (fields[0])
                    {
                    case "":
                        continue;

                    case "{":
                        stack.Push(current);
                        continue;

                    case "}":
                        stack.Pop();
                        continue;

                    case "HIERARCHY":
                        continue;

                    case "ROOT":
                        current = new RootElement(this, fields[1]);
                        break;

                    case "JOINT":
                        current = new JointElement(this, fields[1]);
                        break;

                    case "End":
                        current = new EndSiteElement(this, fields[1]);
                        break;

                    case "OFFSET":
                        current = new OffsetElement(fields[1], fields[2], fields[3]);
                        break;

                    case "CHANNELS":
                        current = new ChannelsElement(fields);
                        break;

                    case "MOTION":
                        continue;

                    case "Frames:":
                        current = new FramesElement(fields[1]);
                        break;

                    case "Frame":
                        current = new FrameTimeElement(fields[2]);
                        break;

                    default:
                        current = new FrameElement(this, fields);
                        break;
                    }

                    if (stack.Count == 0)
                    {
                        this.Add(current);
                    }
                    else
                    {
                        CompositeElement parent = stack.Peek() as CompositeElement;
                        parent.Add(current);
                    }
                }
            }
        }