static Matrix FbxsdkCalcTransform(SkeletonNode node)
 {
     var t = Matrix.Identity;
     while (node != null)
     {
         t = t * node.PoseMatrix;
         node = node.Parent;
     }
     return t;
 }
        private void AddBonesInfo(SkeletonNode skeletonNode, StringBuilder sb, int indent, bool skipNodesWithoutName)
        {
            if (skipNodesWithoutName && string.IsNullOrEmpty(skeletonNode.AssimpNode.Name))
            {
                return;
            }

            string indentString = indent == 0 ? "" : new string(' ', indent);


            sb.Append(indentString)
            .Append('"' + skeletonNode.AssimpNode.Name + '"')
            .AppendLine();


            var matrices     = new List <Matrix3D>(4);
            var matrixTitles = new List <string>(4);

            matrices.Add(skeletonNode.AssimpNode.Transform.ToWpfMatrix3D());
            matrixTitles.Add("NodeMatrix:");

            matrices.Add(skeletonNode.CurrentWorldMatrix);
            matrixTitles.Add("CurrentWorldMatrix:");

            if (skeletonNode.AssimpBone != null)
            {
                matrices.Add(skeletonNode.BoneOffsetMatrix);
                matrixTitles.Add("BoneMatrix:");
            }

            matrices.Add(skeletonNode.FinalMatrix);
            matrixTitles.Add("FinalMatrix:");


            var allMatricesText = Ab3d.Utilities.Dumper.FormatMatricesHorizontally(matrices.ToArray(), matrixTitles.ToArray(), new string(' ', indent));

            sb.AppendLine(allMatricesText);

            foreach (var skeletonNodeChild in skeletonNode.Children)
            {
                AddBonesInfo(skeletonNodeChild, sb, indent + 4, skipNodesWithoutName);
            }
        }
        public void CannotCreateRigSkeletonWithInvalidParentIndexes()
        {
            var animationChannel = new IAnimationChannel[] {
                new LocalTranslationChannel {
                    Id = "Root"
                },
                new LocalRotationChannel {
                    Id = "Root"
                },
                new LocalScaleChannel {
                    Id = "Root"
                },
            };

            var skeletonNodes = new SkeletonNode[] {
                new SkeletonNode {
                    ParentIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 0
                },
                new SkeletonNode {
                    ParentIndex = 100
                },
            };

            Assert.Throws <ArgumentOutOfRangeException>(() => RigBuilder.CreateRigDefinition(skeletonNodes, null, animationChannel));


            skeletonNodes = new SkeletonNode[] {
                new SkeletonNode {
                    ParentIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 0
                },
                new SkeletonNode {
                    ParentIndex = -100
                },
            };

            Assert.Throws <ArgumentOutOfRangeException>(() => RigBuilder.CreateRigDefinition(skeletonNodes, null, animationChannel));
        }
        public void RigDefinitionWithDifferentDataHaveDifferentHashCode()
        {
            var animationChannel = new IAnimationChannel[] {
                new LocalTranslationChannel {
                    Id = "Root"
                },
                new LocalTranslationChannel {
                    Id = "Root"
                },
                new LocalTranslationChannel {
                    Id = "Root"
                },
                new LocalRotationChannel {
                    Id = "Root"
                },
                new LocalScaleChannel {
                    Id = "Root"
                },
                new LocalRotationChannel {
                    Id = "Root"
                },
                new LocalTranslationChannel {
                    Id = "Root"
                }
            };

            var skeletonNodes1 = new SkeletonNode[] {
                new SkeletonNode {
                    ParentIndex = -1, AxisIndex = -1, Id = "Root"
                }
            };

            var rig1 = RigBuilder.CreateRigDefinition(skeletonNodes1, null, animationChannel);

            var skeletonNodes2 = new SkeletonNode[] {
                new SkeletonNode {
                    ParentIndex = -1, AxisIndex = -1, Id = "Root1"
                }
            };
            var rig2 = RigBuilder.CreateRigDefinition(skeletonNodes2, null, animationChannel);

            Assert.That(rig1.Value.GetHashCode(), Is.Not.EqualTo(rig2.Value.GetHashCode()));
        }
Пример #5
0
        public static SkeletonNode[] ExtractSkeletonNodesFromTransforms(Transform root, Transform[] transforms)
        {
            var skeletonNodes = new List <SkeletonNode>();

            for (int i = 0; i < transforms.Length; i++)
            {
                var skeletonNode = new SkeletonNode
                {
                    Id        = ComputeRelativePath(transforms[i], root),
                    AxisIndex = -1,
                    LocalTranslationDefaultValue = transforms[i].localPosition,
                    LocalRotationDefaultValue    = transforms[i].localRotation,
                    LocalScaleDefaultValue       = transforms[i].localScale,
                    ParentIndex = FindTransformIndex(transforms[i].parent, transforms)
                };
                skeletonNodes.Add(skeletonNode);
            }

            return(skeletonNodes.ToArray());
        }
        public void CannotCreateRigSkeletonWithoutRoot()
        {
            var animationChannel = new IAnimationChannel[] {
                new LocalTranslationChannel {
                    Id = "Root"
                },
                new LocalRotationChannel {
                    Id = "Root"
                },
                new LocalScaleChannel {
                    Id = "Root"
                },
            };

            var skeletonNodes = new SkeletonNode[] {
                new SkeletonNode()
            };

            Assert.Throws <ArgumentException>(() => RigBuilder.CreateRigDefinition(skeletonNodes, null, animationChannel));
        }
Пример #7
0
        public MeshFitterViewModel(RemappedAnimatedBoneConfiguration configuration, List <Rmv2MeshNode> meshNodes, GameSkeleton targetSkeleton, AnimationFile currentSkeletonFile, IComponentManager componentManager) : base(configuration)
        {
            _meshNodes        = meshNodes;
            _dwarfSkeleton    = targetSkeleton;
            _componentManager = componentManager;

            _animationPlayer    = _componentManager.GetComponent <AnimationsContainerComponent>().RegisterAnimationPlayer(new AnimationPlayer(), "Temp animation rerig");
            _humanoid01Skeleton = new GameSkeleton(currentSkeletonFile, _animationPlayer);


            // Build empty animation
            _animationClip = new AnimationClip();
            _animationClip.DynamicFrames.Add(new AnimationClip.KeyFrame());

            for (int i = 0; i < _humanoid01Skeleton.BoneCount; i++)
            {
                _animationClip.DynamicFrames[0].Rotation.Add(_humanoid01Skeleton.Rotation[i]);
                _animationClip.DynamicFrames[0].Position.Add(_humanoid01Skeleton.Translation[i]);
                _animationClip.DynamicFrames[0].Scale.Add(Vector3.One);

                _animationClip.RotationMappings.Add(new AnimationFile.AnimationBoneMapping(i));
                _animationClip.TranslationMappings.Add(new AnimationFile.AnimationBoneMapping(i));
            }


            _animationPlayer.SetAnimation(_animationClip, _humanoid01Skeleton);
            _animationPlayer.Play();


            var resourceLib = _componentManager.GetComponent <ResourceLibary>();

            _currentSkeletonNode = new SkeletonNode(resourceLib.Content, new SimpleSkeletonProvider(_humanoid01Skeleton));
            _componentManager.GetComponent <SceneManager>().RootNode.AddObject(_currentSkeletonNode);


            _oldAnimationPlayer = _meshNodes.First().AnimationPlayer;
            foreach (var mesh in _meshNodes)
            {
                mesh.AnimationPlayer = _animationPlayer;
            }
        }
Пример #8
0
        /*
         * Used as the listener for setOnTapArPlaneListener.
         */
        private void OnPlaneTap(HitResult hitResult, Google.AR.Core.Plane unusedPlane, MotionEvent unusedMotionEvent)
        {
            if (andyRenderable == null || hatRenderable == null)
            {
                return;
            }
            // Create the Anchor.
            Anchor anchor = hitResult.CreateAnchor();

            if (anchorNode == null)
            {
                anchorNode = new AnchorNode(anchor);
                anchorNode.SetParent(arFragment.ArSceneView.Scene);

                andy = new SkeletonNode();

                andy.SetParent(anchorNode);
                andy.Renderable = andyRenderable;
                hatNode         = new Node();

                // Attach a node to the bone.  This node takes the internal scale of the bone, so any
                // renderables should be added to child nodes with the world pose reset.
                // This also allows for tweaking the position relative to the bone.
                Node boneNode = new Node();
                boneNode.SetParent(andy);
                andy.SetBoneAttachment(HAT_BONE_NAME, boneNode);
                hatNode.Renderable = hatRenderable;
                hatNode.SetParent(boneNode);
                hatNode.WorldScale    = Vector3.One();
                hatNode.WorldRotation = Quaternion.Identity();
                Vector3 pos = hatNode.WorldPosition;

                // Lower the hat down over the antennae.
                pos.Y -= .1f;

                hatNode.WorldPosition = pos;
            }
        }
        public void CanRemoveDuplicateChannelFromRigDefinition()
        {
            var animationChannel = new IAnimationChannel[] {
                new LocalTranslationChannel {
                    Id = "Root"
                },
                new LocalTranslationChannel {
                    Id = "Root"
                },
                new LocalTranslationChannel {
                    Id = "Root"
                },
                new LocalRotationChannel {
                    Id = "Root"
                },
                new LocalScaleChannel {
                    Id = "Root"
                },
                new LocalRotationChannel {
                    Id = "Root"
                },
                new LocalTranslationChannel {
                    Id = "Root"
                }
            };

            var skeletonNodes = new SkeletonNode[] {
                new SkeletonNode {
                    ParentIndex = -1, AxisIndex = -1, Id = "Root"
                }
            };

            var rig = RigBuilder.CreateRigDefinition(skeletonNodes, null, animationChannel);

            Assert.That(rig.Value.Bindings.TranslationBindings.Length, Is.EqualTo(1));
            Assert.That(rig.Value.Bindings.RotationBindings.Length, Is.EqualTo(1));
            Assert.That(rig.Value.Bindings.ScaleBindings.Length, Is.EqualTo(1));
        }
Пример #10
0
        void GenerateSkeleton(GameObject a_parent, SkeletonNode a_node)
        {
            GameObject obj = a_parent.GetChild(a_node.Name);

            if (obj == null)
            {
                obj = new GameObject();

                obj.Transform.Parent = a_parent.Transform;
                obj.Name             = a_node.Name;
            }

            Transform transform = obj.Transform;

            m_transforms[a_node.Index] = transform;
            transform.FromMatrix(a_node.Transform);

            IEnumerable <SkeletonNode> children = a_node.Children;

            foreach (SkeletonNode child in children)
            {
                GenerateSkeleton(obj, child);
            }
        }
Пример #11
0
 void FbxsdkBuildHierachy(FBXNode fbxNode, SkeletonNode parentNode, Dictionary<SkeletonNode, FBXMesh> outputMeshDict)
 {
     var node = new SkeletonNode();
     node.Name = fbxNode.GetName();
     node.PoseMatrix = FbxsdkConvertMatrix(fbxNode.GetLocalTransform());
     node.Parent = parentNode;
     if (parentNode == null) skeleton = node;
     else parentNode.Children.Add(node);
     var mesh = fbxNode.GetMesh() ;
     if(mesh != null)
     {
         outputMeshDict[node] = mesh;
     }
     if (skeletonNodeDict.ContainsKey(node.Name))
     {
         Debug.Log("Found duplicated skeleton node name: " + node.Name);
     }
     else
     {
         skeletonNodeDict.Add(node.Name, node);
     }
     for (int i = 0; i < fbxNode.GetChildCount(); ++i)
     {
         FbxsdkBuildHierachy(fbxNode.GetChild(i), node, outputMeshDict);
     }
 }
Пример #12
0
 void DrawSkeletonRecursively(SkeletonNode node)
 {
     if (!node.DbgDrawBone) return;
     var matrix = TransformMatrix;
     Vector3 from;
     if(node.Parent != null) from = Vector3.TransformCoordinate(Vector3.Zero, node.Parent.GlobalTransform* matrix);
     else from = Vector3.TransformCoordinate(Vector3.Zero, matrix);
     var to = Vector3.TransformCoordinate(Vector3.Zero, node.GlobalTransform * matrix);
     Debug.Line(from, to, Color.Red);
     for(int i=0;i<node.Children.Count;++i)
     {
         DrawSkeletonRecursively(node.Children[i]);
     }
 }
Пример #13
0
 public SkeletonSceneNodeViewModel(SkeletonNode node, PackFileService pf, SkeletonAnimationLookUpHelper animLookUp)
 {
     _meshNode = node;
 }
Пример #14
0
 public PoseBlendNode(SkeletonNode node)
 {
     Node = node;
 }
Пример #15
0
        private static Skeleton CombineSkeletons([NotNull, ItemNotNull] IEnumerable <Skeleton> skeletons)
        {
            var nodeIDList = new List <uint>();
            var nodeList   = new List <SkeletonNode>();

            var nodeStart = 0;
            var counter   = 0;

            foreach (var skeleton in skeletons)
            {
                Debug.Assert(skeleton.NodeIDs.Length == skeleton.Nodes.Length);

                var nodeCount = skeleton.NodeIDs.Length;

                foreach (var id in skeleton.NodeIDs)
                {
                    if (id == 0)
                    {
                        if (nodeIDList.Count == 0)
                        {
                            nodeIDList.Add(id);
                        }
                    }
                    else
                    {
                        nodeIDList.Add(id);
                    }
                }

                var isFirstNode = true;

                foreach (var node in skeleton.Nodes)
                {
                    if (isFirstNode)
                    {
                        if (nodeList.Count > 0)
                        {
                            isFirstNode = false;
                            continue;
                        }
                    }

                    int parentIndex;

                    if (counter == 0)
                    {
                        parentIndex = node.ParentIndex;
                    }
                    else
                    {
                        if (node.ParentIndex <= 0)
                        {
                            parentIndex = node.ParentIndex;
                        }
                        else
                        {
                            parentIndex = node.ParentIndex + nodeStart - 1;
                        }
                    }

                    var n = new SkeletonNode(parentIndex, node.AxisIndex);

                    nodeList.Add(n);

                    isFirstNode = false;
                }

                if (counter == 0)
                {
                    nodeStart += nodeCount;
                }
                else
                {
                    // From the second time, "" (empty name) bone is filtered out because it will duplicate.
                    nodeStart += nodeCount - 1;
                }

                ++counter;
            }

            var result = new Skeleton();

            result.NodeIDs = nodeIDList.ToArray();
            result.Nodes   = nodeList.ToArray();

            return(result);
        }
        protected void OneTimeSetUp()
        {
            var srcSkeletonNodes = new SkeletonNode[]
            {
                new SkeletonNode {
                    Id = "Root", ParentIndex = -1, AxisIndex = -1
                },
                new SkeletonNode {
                    Id = "Hips", ParentIndex = 0, AxisIndex = -1
                },
                new SkeletonNode {
                    Id = "LeftUpLeg", ParentIndex = 1, AxisIndex = -1
                },
                new SkeletonNode {
                    Id = "RightUpLeg", ParentIndex = 1, AxisIndex = -1
                },
            };
            var srcChannels = new IAnimationChannel[]
            {
                new LocalTranslationChannel {
                    Id = "Velocity"
                },
                new LocalRotationChannel {
                    Id = "AngularVelocity"
                },
                new FloatChannel {
                    Id = "Intensity"
                },
                new FloatChannel {
                    Id = "Radius"
                },
                new IntChannel {
                    Id = "Index"
                },
                new IntChannel {
                    Id = "Mode"
                },
            };

            var dstSkeletonNodes = new SkeletonNode[]
            {
                new SkeletonNode {
                    Id = "AnotherRoot", ParentIndex = -1, AxisIndex = -1
                },
                new SkeletonNode {
                    Id = "AnotherHips", ParentIndex = 0, AxisIndex = -1
                },
                new SkeletonNode {
                    Id = "AnotherLeftUpLeg", ParentIndex = 1, AxisIndex = -1
                },
                new SkeletonNode {
                    Id = "AnotherRightUpLeg", ParentIndex = 1, AxisIndex = -1
                },
            };
            var dstChannels = new IAnimationChannel[]
            {
                new LocalTranslationChannel {
                    Id = "AnotherVelocity"
                },
                new LocalRotationChannel {
                    Id = "AnotherAngularVelocity"
                },
                new FloatChannel {
                    Id = "AnotherIntensity"
                },
                new FloatChannel {
                    Id = "AnotherRadius"
                },
                new IntChannel {
                    Id = "AnotherIndex"
                },
                new IntChannel {
                    Id = "AnotherMode"
                },
            };

            m_SourceRig      = RigBuilder.CreateRigDefinition(srcSkeletonNodes, null, srcChannels);
            m_DestinationRig = RigBuilder.CreateRigDefinition(dstSkeletonNodes, null, dstChannels);
        }