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.Euler(x, 0, 0);
                var yRot = Quaternion.Euler(0, y, 0);
                var zRot = Quaternion.Euler(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;
            });
        }
Exemplo n.º 2
0
        public void Build(BvhNode node)
        {
            foreach (var child in node.Children)
            {
                var childBone = new BvhBone(child.Name, SkeletonLoacalPosition + child.Offset.ToXReversedVector3());
                childBone.Parent = this;
                _children.Add(childBone);

                childBone.Build(child);
            }
        }
Exemplo n.º 3
0
Arquivo: Bvh.cs Projeto: vrm-c/UniVRM
        BvhNode GetParent(BvhNode node)
        {
            foreach (var x in Root.Traverse())
            {
                if (x.Children.Contains(node))
                {
                    return(x);
                }
            }

            return(null);
        }
        static Transform BuildHierarchy(Transform parent, BvhNode node, float toMeter)
        {
            var go = new GameObject(node.Name);

            go.transform.localPosition = node.Offset.ToXReversedVector3() * toMeter;
            go.transform.SetParent(parent, false);

            foreach (var child in node.Children)
            {
                BuildHierarchy(go.transform, child, toMeter);
            }

            return(go.transform);
        }
Exemplo n.º 5
0
        static void BuildHierarchy(Transform parent, BvhNode node, float toMeter)
        {
            var go = new GameObject(node.Name);

            go.transform.localPosition = node.Offset.ToXReversedVector3() * toMeter;
            go.transform.SetParent(parent, false);

            //var gizmo = go.AddComponent<BoneGizmoDrawer>();
            //gizmo.Draw = true;

            foreach (var child in node.Children)
            {
                BuildHierarchy(go.transform, child, toMeter);
            }
        }
Exemplo n.º 6
0
Arquivo: Bvh.cs Projeto: vrm-c/UniVRM
        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()
            ;
        }
        static Transform BuildHierarchy(Transform parent, BvhNode node, float toMeter, Transform sparent)
        {
            //Debug.Log("Part : " + node.Name);
            var go = new GameObject(node.Name);

            go.transform.localPosition = node.Offset.ToXReversedVector3() * toMeter;
            go.transform.SetParent(parent, false);

            GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            sphere.name = node.Name;
            sphere.AddComponent <ShowBone>();
            sphere.GetComponent <ShowBone>().SetTransform(go.transform, true);
            if (sparent != null)
            {
                sphere.transform.SetParent(sparent, false);
                if (node.Name == "head")
                {
                    sphere.transform.localScale = new Vector3(1.1f, 1.1f, 1.1f);
                }
                else if (node.Name == "head" || node.Name == "rThumb1" || node.Name == "rIndex1" ||
                         node.Name == "rMid1" || node.Name == "rRing1" || node.Name == "rPinky1" ||
                         node.Name == "lThumb1" || node.Name == "lIndex1" || node.Name == "lMid1" ||
                         node.Name == "lRing1" || node.Name == "lPinky1" || node.Name == "leftEye" || node.Name == "rightEye")
                {
                    sphere.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                }
                else
                {
                    sphere.transform.localScale = new Vector3(0.9f, 0.9f, 0.9f);
                }
            }
            else
            {
                GlobalData.SetFocusObj(sphere);

                sphere.transform.localScale = sphere.transform.localScale * 0.2f;
                sphere.tag = "sphere";
            }

            foreach (var child in node.Children)
            {
                BuildHierarchy(go.transform, child, toMeter, sphere.transform);
            }

            return(go.transform);
        }
Exemplo n.º 8
0
Arquivo: Bvh.cs Projeto: vrm-c/UniVRM
        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");
        }
Exemplo n.º 9
0
Arquivo: Bvh.cs Projeto: vrm-c/UniVRM
        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()));
        }
Exemplo n.º 10
0
 public CurveSet(BvhNode node)
 {
     Node = node;
 }
Exemplo n.º 11
0
Arquivo: Bvh.cs Projeto: vrm-c/UniVRM
        static BvhNode ParseNode(StringReader r, int level = 0)
        {
            var firstline = r.ReadLine().Trim();
            var split     = firstline.Split();

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

            BvhNode node = null;

            if (split[0] == "ROOT")
            {
                if (level != 0)
                {
                    throw new BvhException("nested ROOT");
                }
                node = new BvhNode(split[1]);
            }
            else if (split[0] == "JOINT")
            {
                if (level == 0)
                {
                    throw new BvhException("should ROOT, but JOINT");
                }
                node = new BvhNode(split[1]);
            }
            else if (split[0] == "End")
            {
                if (level == 0)
                {
                    throw new BvhException("End in level 0");
                }
                node = new EndSite();
            }
            else
            {
                throw new BvhException("unknown type: " + split[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.Children.Add(child);
                }
            }

            return(node);
        }