Exemple #1
0
        public static Func <float, float, float, Quaternion> GetEulerToRotation(this BvhNode bvh)
        {
            var order = bvh.Channels.Where(x => x == Channel.Xrotation || x == Channel.Yrotation || x == Channel.Zrotation).ToArray();

            return((x, y, z) =>
            {
                var xRot = Quaternion.CreateFromYawPitchRoll(x, 0, 0);
                var yRot = Quaternion.CreateFromYawPitchRoll(0, y, 0);
                var zRot = Quaternion.CreateFromYawPitchRoll(0, 0, z);

                var r = Quaternion.Identity;
                foreach (var ch in order)
                {
                    switch (ch)
                    {
                    case Channel.Xrotation: r = r * xRot; break;

                    case Channel.Yrotation: r = r * yRot; break;

                    case Channel.Zrotation: r = r * zRot; break;

                    default: throw new BvhException("no rotation");
                    }
                }
                return r;
            });
        }
Exemple #2
0
        BvhNode GetParent(BvhNode node)
        {
            foreach (var x in Root.Traverse())
            {
                if (x.Children.Contains(node))
                {
                    return(x);
                }
            }

            return(null);
        }
Exemple #3
0
        public Bvh(BvhNode root, int frames, float seconds)
        {
            Root      = root;
            FrameTime = TimeSpan.FromSeconds(seconds);
            m_frames  = frames;
            var channelCount = Root.Traverse()
                               .Where(x => x.Channels != null)
                               .Select(x => x.Channels.Length)
                               .Sum();

            Channels = Enumerable.Range(0, channelCount)
                       .Select(x => new ChannelCurve(frames))
                       .ToArray()
            ;
        }
Exemple #4
0
        public ChannelCurve GetChannel(BvhNode target, Channel channel)
        {
            var index = 0;

            foreach (var node in Root.Traverse())
            {
                for (int i = 0; i < node.Channels.Length; ++i, ++index)
                {
                    if (node == target && node.Channels[i] == channel)
                    {
                        return(Channels[index]);
                    }
                }
            }

            throw new BvhException("channel is not found");
        }
Exemple #5
0
        public string GetPath(BvhNode node)
        {
            var list = new List <string>()
            {
                node.Name
            };

            var current = node;

            while (current != null)
            {
                current = GetParent(current);
                if (current != null)
                {
                    list.Insert(0, current.Name);
                }
            }

            return(String.Join("/", list.ToArray()));
        }
Exemple #6
0
 public CurveSet(BvhNode node)
 {
     Node = node;
 }
Exemple #7
0
 public void AddChid(BvhNode child)
 {
     child.Parent = this;
     m_children.Add(child);
 }
Exemple #8
0
        static BvhNode ParseNode(StringReader r, int level = 0)
        {
            var firstline = r.ReadLine().Trim();
            var splitted  = firstline.Split();

            if (splitted.Length != 2)
            {
                if (splitted.Length == 1)
                {
                    if (splitted[0] == "}")
                    {
                        return(null);
                    }
                }
                throw new BvhException(String.Format("splitted to {0}({1})", splitted.Length, firstline));
            }

            BvhNode node = null;

            if (splitted[0] == "ROOT")
            {
                if (level != 0)
                {
                    throw new BvhException("nested ROOT");
                }
                node = new BvhNode(splitted[1]);
            }
            else if (splitted[0] == "JOINT")
            {
                if (level == 0)
                {
                    throw new BvhException("should ROOT, but JOINT");
                }
                node = new BvhNode(splitted[1]);
            }
            else if (splitted[0] == "End")
            {
                if (level == 0)
                {
                    throw new BvhException("End in level 0");
                }
                node = new EndSite();
            }
            else
            {
                throw new BvhException("unknown type: " + splitted[0]);
            }

            if (r.ReadLine().Trim() != "{")
            {
                throw new BvhException("'{' is not found");
            }

            node.Parse(r);

            // child nodes
            while (true)
            {
                var child = ParseNode(r, level + 1);
                if (child == null)
                {
                    break;
                }

                if (!(child is EndSite))
                {
                    node.AddChid(child);
                }
            }

            return(node);
        }