Ejemplo n.º 1
0
        private bool MapNodes(BvhNode bvhNode, SceneNode sceneNode)
        {
            bool mapped = false;

            if (bvhNode.IsRoot && sceneNode.IsBoneRoot)
            {
                List <SceneNode> list;
                if (!nodesMap.TryGetValue(bvhNode.Name, out list))
                {
                    list = new List <SceneNode>();
                    nodesMap[bvhNode.Name] = list;
                }
                list.Add(sceneNode);
                mapped = true;
            }
            else
            {
                foreach (var name in namesMap[bvhNode.Name])
                {
                    SceneNode mapNode;
                    if ((mapNode = sceneNode.GetNode(x => x.Name.Contains(name))) != null)
                    {
                        List <SceneNode> list;
                        if (!nodesMap.TryGetValue(bvhNode.Name, out list))
                        {
                            list = new List <SceneNode>();
                            nodesMap[bvhNode.Name] = list;
                        }
                        list.Add(mapNode);
                        mapped = true;
                        break;
                    }
                }
            }

            foreach (var child in bvhNode.Nodes)
            {
                foreach (var nodeChild in sceneNode.Childrens)
                {
                    if (MapNodes(child, nodeChild))
                    {
                        break;
                    }
                }
            }

            return(mapped);
        }
Ejemplo n.º 2
0
        private AnimationNode CrateAnimationNode(BvhNode bvhNode)
        {
            var nodeList = nodesMap[bvhNode.Name];

            if (nodeList == null || nodeList.Count == 0)
            {
                return(null);
            }

            AnimationNode animNode = new AnimationNode(bvhNode.Name);

            animNode.Curves = new AnimationCurve[] {
                new AnimationCurve()
                {
                    Name              = "Translation",
                    Output            = new float[doc.Motion.FrameCount * 3],
                    InterpolationType = InterpolationMethod.LINEAR,
                    OutputDim         = 3,
                    CurveOutput       = TranslationOuput
                },
                new AnimationCurve()
                {
                    Name              = "Rotation",
                    Output            = new float[doc.Motion.FrameCount * 4],
                    InterpolationType = InterpolationMethod.QUATSLERP,
                    OutputDim         = 4,
                    CurveOutput       = RotationOutput
                }
            };
            var channels = bvhNode.Channels;

            //set the animation context
            animNode.KeysIndices = new int[animNode.Curves.Length];
            animNode.Context     = AnimationManager.GetContext <SceneNodeTransforms>(nodeList[0]);
            for (int i = 1; i < nodeList.Count; i++)
            {
                animNode.Context.Next = AnimationManager.GetContext <SceneNodeTransforms>(nodeList[i]);
            }
            return(animNode);
        }
Ejemplo n.º 3
0
        // $ANTLR start document
        // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:73:1: document returns [BvhDocument doc = new BvhDocument()] : HEIRARCHY root= heirarchy[doc] m= motion ;
        public BvhDocument document() // throws RecognitionException [1]
        {
            BvhDocument doc = new BvhDocument();

            BvhNode root = null;

            BvhMotion m = null;


            try
            {
                // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:74:2: ( HEIRARCHY root= heirarchy[doc] m= motion )
                // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:74:4: HEIRARCHY root= heirarchy[doc] m= motion
                {
                    Match(input, HEIRARCHY, FOLLOW_HEIRARCHY_in_document485);
                    PushFollow(FOLLOW_heirarchy_in_document496);
                    root = heirarchy(doc);
                    followingStackPointer_--;

                    doc.Root = root;
                    PushFollow(FOLLOW_motion_in_document507);
                    m = motion();
                    followingStackPointer_--;

                    doc.Motion = m;
                }
            }
            catch (RecognitionException re)
            {
                ReportError(re);
                Recover(input, re);
            }
            finally
            {
            }
            return(doc);
        }
Ejemplo n.º 4
0
        // $ANTLR end values


        // $ANTLR start heirarchy
        // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:89:1: heirarchy[BvhDocument d] returns [BvhNode node = new BvhNode()] : ( ROOT | JOINT ) ID LCURLY v= offsets ch= channels ( (child= heirarchy[d] )+ | end= endsite ) RCURLY ;
        public BvhNode heirarchy(BvhDocument d) // throws RecognitionException [1]
        {
            BvhNode node = new BvhNode();

            IToken  ID1 = null;
            Vector3?v   = null;

            List <FODChannel> ch = null;

            BvhNode child = null;

            EndSite end = null;



            d.Nodes.Add(node);

            try
            {
                // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:94:2: ( ( ROOT | JOINT ) ID LCURLY v= offsets ch= channels ( (child= heirarchy[d] )+ | end= endsite ) RCURLY )
                // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:94:4: ( ROOT | JOINT ) ID LCURLY v= offsets ch= channels ( (child= heirarchy[d] )+ | end= endsite ) RCURLY
                {
                    // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:94:4: ( ROOT | JOINT )
                    int alt2  = 2;
                    int LA2_0 = input.LA(1);

                    if ((LA2_0 == ROOT))
                    {
                        alt2 = 1;
                    }
                    else if ((LA2_0 == JOINT))
                    {
                        alt2 = 2;
                    }
                    else
                    {
                        NoViableAltException nvae_d2s0 =
                            new NoViableAltException("94:4: ( ROOT | JOINT )", 2, 0, input);

                        throw nvae_d2s0;
                    }
                    switch (alt2)
                    {
                    case 1:
                        // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:94:5: ROOT
                    {
                        Match(input, ROOT, FOLLOW_ROOT_in_heirarchy611);
                        node.IsRoot = true;
                    }
                    break;

                    case 2:
                        // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:94:33: JOINT
                    {
                        Match(input, JOINT, FOLLOW_JOINT_in_heirarchy616);
                    }
                    break;
                    }

                    ID1 = (IToken)input.LT(1);
                    Match(input, ID, FOLLOW_ID_in_heirarchy619);
                    node.Name = ID1.Text;
                    Match(input, LCURLY, FOLLOW_LCURLY_in_heirarchy627);
                    PushFollow(FOLLOW_offsets_in_heirarchy635);
                    v = offsets();
                    followingStackPointer_--;

                    node.Offset = (Vector3)v;
                    PushFollow(FOLLOW_channels_in_heirarchy646);
                    ch = channels();
                    followingStackPointer_--;

                    node.Channels = ch.ToArray();
                    // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:98:6: ( (child= heirarchy[d] )+ | end= endsite )
                    int alt4  = 2;
                    int LA4_0 = input.LA(1);

                    if (((LA4_0 >= ROOT && LA4_0 <= JOINT)))
                    {
                        alt4 = 1;
                    }
                    else if ((LA4_0 == END_SITE))
                    {
                        alt4 = 2;
                    }
                    else
                    {
                        NoViableAltException nvae_d4s0 =
                            new NoViableAltException("98:6: ( (child= heirarchy[d] )+ | end= endsite )", 4, 0, input);

                        throw nvae_d4s0;
                    }
                    switch (alt4)
                    {
                    case 1:
                        // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:98:8: (child= heirarchy[d] )+
                    {
                        // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:98:8: (child= heirarchy[d] )+
                        int cnt3 = 0;
                        do
                        {
                            int alt3  = 2;
                            int LA3_0 = input.LA(1);

                            if (((LA3_0 >= ROOT && LA3_0 <= JOINT)))
                            {
                                alt3 = 1;
                            }


                            switch (alt3)
                            {
                            case 1:
                                // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:98:9: child= heirarchy[d]
                            {
                                PushFollow(FOLLOW_heirarchy_in_heirarchy660);
                                child = heirarchy(d);
                                followingStackPointer_--;

                                node.Nodes.Add(child);
                            }
                            break;

                            default:
                                if (cnt3 >= 1)
                                {
                                    goto loop3;
                                }
                                EarlyExitException eee =
                                    new EarlyExitException(3, input);
                                throw eee;
                            }
                            cnt3++;
                        } while (true);

loop3:
                        ;                       // Stops C# compiler whinging that label 'loop3' has no statements
                    }
                    break;

                    case 2:
                        // F:\\Projects\\Igneel\\Igneel\\Importers\\BVH\\bvh.g:99:8: end= endsite
                    {
                        PushFollow(FOLLOW_endsite_in_heirarchy677);
                        end = endsite();
                        followingStackPointer_--;

                        node.End = end;
                    }
                    break;
                    }

                    Match(input, RCURLY, FOLLOW_RCURLY_in_heirarchy685);
                }
            }
            catch (RecognitionException re)
            {
                ReportError(re);
                Recover(input, re);
            }
            finally
            {
            }
            return(node);
        }
Ejemplo n.º 5
0
        private void ReadFrameOutputs(AnimationNode animNode, BvhNode bvhNode, int offset, List <float> data, int iframe)
        {
            AnimationCurve translations = animNode.Curves.SingleOrDefault(x => x.OutputDim == 3);
            AnimationCurve rotations    = animNode.Curves.SingleOrDefault(x => x.OutputDim == 4);

            Matrix  frameTransform = Matrix.Identity;
            Matrix  rotation;
            Vector3 translation = new Vector3(); //bvhNode.Offset;

            for (int i = bvhNode.Channels.Length - 1; i >= 0; i--)
            {
                var ch    = bvhNode.Channels[i];
                var value = data[offset + i];
                switch (ch)
                {
                case FODChannel.XPosition:
                    translation.X += value;
                    break;

                case FODChannel.YPosition:
                    translation.Y += value;
                    break;

                case FODChannel.ZPosition:
                    translation.Z += value;
                    break;

                case FODChannel.XRotation:
                    frameTransform *= Matrix.RotationAxis(Vector3.UnitX, -Numerics.ToRadians(value));
                    break;

                case FODChannel.YRotation:
                    frameTransform *= Matrix.RotationAxis(Vector3.UnitY, -Numerics.ToRadians(value));
                    break;

                case FODChannel.ZRotation:
                    frameTransform *= Matrix.RotationAxis(Vector3.UnitZ, -Numerics.ToRadians(value));
                    break;
                }
            }
            rotation = frameTransform;
            frameTransform.Translation = translation;

            ////bvhNode.LocalTransform * relativeToLocalTransform = frameTransform
            //Matrix relativeToLocalTransform = Matrix.Invert(bvhNode.LocalTransform) * frameTransform;

            var nodes = nodesMap[bvhNode.Name];

            //Matrix nodeFramePose = nodes[0].LocalPose * relativeToLocalTransform;

            //////decompose nodeFramePose for store into the curves
            //var comp = nodeFramePose.GetComposition();

            unsafe
            {
                if (rotations != null)
                {
                    fixed(float *pter = rotations.Output)
                    {
                        *(Quaternion *)(pter + 4 * iframe) = Quaternion.RotationMatrix(rotation);
                    }
                }

                if (translations != null)
                {
                    fixed(float *pter = translations.Output)
                    {
                        *(Vector3 *)(pter + 3 * iframe) = nodes[0].LocalPose.Translation;
                    }
                }
            }
        }