Example #1
0
        bool IsEstimatedLocalTranslation()
        {
            BvhBone hip = null;

            foreach (var bone in bones)
            {
                if (bone.isHipBone)
                {
                    hip = bone;
                }
            }
            if (hip == null)
            {
                return(true);    // best estimate without a hip bone
            }
            var index = hip.frameOffset + 1;
            // Use hip 'y' to estimate the translation mode (local or "absolute")
            float sum = 0;

            for (var i = 0; i < nFrames; i++)
            {
                var data = frames[i];
                sum += data[index];
            }
            float average  = sum / nFrames;
            float absScore = Mathf.Abs(hip.offset.y - average); // absolute will have average close to offset
            float locScore = Mathf.Abs(average);                // lowest score wins

            return(locScore < absScore);
        }
Example #2
0
        BvhBone[] ReadHierarchy(string[] lines)
        {
            char[]  delims      = { ' ', '\t' };
            var     boneList    = new List <BvhBone>();
            BvhBone current     = null;
            int     frameOffset = 0;

            for (var i = 0; i < lines.Length; i++)
            {
                if (lines[i] == "MOTION")
                {
                    break;
                }
                var parts = lines[i].Split(delims, System.StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length >= 2 && (parts[0] == "JOINT" || parts[0] == "ROOT"))
                {
                    current             = new BvhBone();
                    current.name        = parts[1];
                    current.offset      = Vector3.zero;
                    current.frameOffset = frameOffset;
                    if (current.name == "hip")
                    {
                        current.isHipBone = true;
                    }
                    boneList.Add(current);
                }
                if (parts.Length >= 4 && parts[0] == "OFFSET" && current != null)
                {
                    current.offset = new Vector3(-float.Parse(parts[1]), float.Parse(parts[2]), float.Parse(parts[3])) * 0.01f;
                }
                if (parts.Length >= 2 && parts[0] == "CHANNELS" && current != null)
                {
                    var nChannels = int.Parse(parts[1]);
                    frameOffset += nChannels;
                    // XXX: examples may exist that are not covered here (but I think they're rare) -- Found some!
                    // We now support 6 channels with X,Y,Zpos in first 3 and any rotation order
                    // Or 3 channels with any rotation order
                    if (nChannels == 3)
                    {
                        current.hasPosition   = false;
                        current.hasRotation   = true;
                        current.rotationOrder = GetRotationOrder(parts[2], parts[3], parts[4]);
                    }
                    else if (nChannels == 6)
                    {
                        current.hasPosition   = true;
                        current.hasRotation   = true;
                        current.rotationOrder = GetRotationOrder(parts[5], parts[6], parts[7]);
                    }
                    else
                    {
                        SuperController.LogError(string.Format("Unexpect number of channels in BVH Hierarchy {1} {0}", nChannels, current.name));
                    }
                }
                if (parts.Length >= 2 && parts[0] == "End" && parts[1] == "Site")
                {
                    current = null;
                }
            }
            return(boneList.ToArray());
        }