Exemplo n.º 1
0
    public int Parse(Bvh bvh)
    {
        _bvh = bvh;

        string token = tokens[tokenIndex];  //get Hierarchy

        tokenIndex++;
        if (token == KeyWord.kHierarchy)
        {
            int ret = Parse_Hierarchy();
            if (ret < 0)
            {
                if (_debug)
                {
                    Debug.Log("Parsing Hierarchy Error!");
                }
                return(ret);
            }
        }
        else
        {
            if (_debug)
            {
                Debug.Log("Bad structure of .bvh file. " + KeyWord.kHierarchy + " should be on the top of the file");
            }
            return(-1);
        }

        if (_debug)
        {
            Debug.Log("Successfully parse file");
        }
        return(0);
    }
Exemplo n.º 2
0
    public void Parse(string info)
    {
        _bvh        = new Bvh();
        _bp         = new BvhParser();
        _frameIndex = 0;
        _pathIndex  = 0;

        _bp.GetTokenInfo(info);
        if (_bp.Parse(_bvh) == 0)
        {
            _bvh.Cal();
            return(0);
        }
        return(-1);
    }
Exemplo n.º 3
0
    void Start()
    {
        _bvh        = new Bvh();
        _bp         = new BvhParser();
        _frameIndex = 0;

        Parse();

        //Generate By World Transform Matrix

        /*
         * GenerateJointBone();
         * StartCoroutine(PlayAnimation());
         */

        //Generate By Local
        GenerateJointBone1();
        StartCoroutine(PlayAnimation());
    }
Exemplo n.º 4
0
    public static void Import(ImporterContext context)
    {
        //
        // parse
        //
        // context.Source = File.ReadAllText(context.Path, Encoding.UTF8);
        context.Bvh = Bvh.Parse(context.Source);
        Debug.LogFormat("parsed {0}", context.Bvh);

        //
        // build hierarchy
        //
        context.Root = new GameObject(Path.GetFileNameWithoutExtension(context.Path));

        BuildHierarchy(context.Root.transform, context.Bvh.Root, 1.0f);

        var hips        = context.Root.transform.GetChild(0);
        var estimater   = new BvhSkeletonEstimator();
        var skeleton    = estimater.Detect(hips.transform);
        var description = AvatarDescription.Create();

        //var values= ((HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones)));
        description.SetHumanBones(skeleton.ToDictionary(hips.Traverse().ToArray()));

        //
        // scaling. reposition
        //
        float scaling = 1.0f;

        {
            //var foot = animator.GetBoneTransform(HumanBodyBones.LeftFoot);
            var foot      = hips.Traverse().Skip(skeleton.GetBoneIndex(HumanBodyBones.LeftFoot)).First();
            var hipHeight = hips.position.y - foot.position.y;
            // hips height to a meter
            scaling = 1.0f / hipHeight;
            foreach (var x in context.Root.transform.Traverse())
            {
                x.localPosition *= scaling;
            }

            var scaledHeight = hipHeight * scaling;
            hips.position = new Vector3(0, scaledHeight, 0); // foot to ground
        }

        //
        // avatar
        //
        context.Avatar            = description.CreateAvatar(context.Root.transform);
        context.Avatar.name       = "Avatar";
        context.AvatarDescription = description;
        var animator = context.Root.AddComponent <Animator>();

        animator.avatar = context.Avatar;

        //
        // create AnimationClip
        //
        context.Animation          = BvhAnimation.CreateAnimationClip(context.Bvh, scaling);
        context.Animation.name     = context.Root.name;
        context.Animation.legacy   = true;
        context.Animation.wrapMode = WrapMode.Loop;

        var animation = context.Root.AddComponent <Animation>();

        animation.AddClip(context.Animation, context.Animation.name);
        animation.clip = context.Animation;
        animation.Play();

        var humanPoseTransfer = context.Root.AddComponent <HumanPoseTransfer>();

        humanPoseTransfer.Avatar = context.Avatar;

        // create SkinnedMesh for bone visualize
        var renderer = SkeletonMeshUtility.CreateRenderer(animator);

        context.Material        = new Material(Shader.Find("Standard"));
        renderer.sharedMaterial = context.Material;
        context.Mesh            = renderer.sharedMesh;
        context.Mesh.name       = "box-man";

        context.Root.AddComponent <BoneMapping>();
    }