Example #1
0
        //Find the cluster that links to the skeleton bone node
        public static FbxCluster FindCluster(FbxNode boneNode, FbxSkin[] skins, out FbxSkin skin)
        {
            for (int i = 0; i < skins.Length; i++)
            {
                skin = skins[i];

                int nClusterCount = skin.GetClusterCount();
                for (int j = 0; j < nClusterCount; j++)
                {
                    FbxCluster fbxCluster = skin.GetCluster(j);
                    if (fbxCluster == null)
                    {
                        continue;
                    }

                    if (fbxCluster.GetLinkMode() == FbxCluster.ELinkMode.eAdditive && fbxCluster.GetAssociateModel() != null)
                    {
                        FbxImportLog.LogMessage(boneNode, "Warning! Associated model.");
                    }

                    if (fbxCluster.GetLink()?.GetUniqueID() == boneNode.GetUniqueID())
                    {
                        return(fbxCluster);
                    }
                }
            }

            skin = null;
            return(null);
        }
Example #2
0
        public new static FbxSkin Create(FbxObject pContainer, string pName)
        {
            global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxSkin_Create__SWIG_1(FbxObject.getCPtr(pContainer), pName);
            FbxSkin ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxSkin(cPtr, false);

            return(ret);
        }
Example #3
0
        public new static FbxSkin Create(FbxManager pManager, string pName)
        {
            global::System.IntPtr cPtr = FbxWrapperNativePINVOKE.FbxSkin_Create__SWIG_0(FbxManager.getCPtr(pManager), pName);
            FbxSkin ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxSkin(cPtr, false);

            return(ret);
        }
Example #4
0
        public void Skin_AddCluster_AddsCluster()
        {
            // given:
            var s = new FbxSkin("");
            var c = new FbxCluster("");

            // require:
            Assert.AreEqual(0, s.GetSrcObjectCount());
            Assert.AreEqual(0, s.GetDstObjectCount());
            Assert.AreEqual(0, s.GetClusterCount());

            Assert.AreEqual(0, c.GetSrcObjectCount());
            Assert.AreEqual(0, c.GetDstObjectCount());

            // when:
            s.AddCluster(c);

            // then:
            Assert.AreEqual(1, s.GetSrcObjectCount());
            Assert.AreSame(c, s.GetSrcObject(0));
            Assert.AreEqual(0, s.GetDstObjectCount());
            Assert.AreEqual(1, s.GetClusterCount());
            Assert.AreSame(c, s.GetCluster(0));

            Assert.AreEqual(0, c.GetSrcObjectCount());
            Assert.AreEqual(1, c.GetDstObjectCount());
            Assert.AreSame(s, c.GetDstObject(0));
        }
Example #5
0
        // key - control point index
        public static Dictionary <int, BoneAssignment> GetBoneAssignments(FbxMesh mesh, Skeleton skeleton)
        {
            var boneAssignments = new Dictionary <int, BoneAssignment>();
            var weightLists     = new Dictionary <int, List <(int, double)> >();

            int skinCount = mesh.GetDeformerCount(FbxDeformer.EDeformerType.eSkin);

            if (skinCount == 0)
            {
                return(null);
            }
            if (1 < skinCount)
            {
                FbxImportLog.LogMessage(mesh.GetNode(), "Warning! Multiple skins for the mesh");                   //??? Может ли быть в одном Mesh несколько Skins? Скорее всего нет, хоть API позволяет.
            }
            FbxSkin pSkin = FbxSkin.Cast(mesh.GetDeformer(0, FbxDeformer.EDeformerType.eSkin));

            int clusterCount = pSkin.GetClusterCount();

            for (int iCluster = 0; iCluster < clusterCount; iCluster++)
            {
                FbxCluster pCluster = pSkin.GetCluster(iCluster);

                FbxNode pLink = pCluster.GetLink();
                if (pLink == null)
                {
                    continue;
                }

                int weightCount = pCluster.GetControlPointIndicesCount();
                if (weightCount == 0)
                {
                    continue;
                }

                int boneIndex = skeleton.GetBoneIndexByNode(pLink);

                var weightIndices = IntArray.frompointer(pCluster.GetControlPointIndices());
                var weightValues  = DoubleArray.frompointer(pCluster.GetControlPointWeights());
                for (int i = 0; i < weightCount; i++)
                {
                    int    vertexIndex = weightIndices.getitem(i);
                    double weight      = weightValues.getitem(i);

                    if (!weightLists.TryGetValue(vertexIndex, out var lst))
                    {
                        lst = new List <(int, double)>();
                        weightLists[vertexIndex] = lst;
                    }

                    lst.Add((boneIndex, weight));
                }
            }

            foreach (var pair in weightLists)
            {
                boneAssignments[pair.Key] = ConvertBoneWeightListToBoneAssignment(pair.Value);
            }
            return(boneAssignments);
        }
Example #6
0
        public void Skin_SetGeometry_SetsGeometry()
        {
            // given:
            var skin = new FbxSkin("");
            var mesh = new FbxMesh("");

            // require:
            Assert.AreEqual(0, skin.GetSrcObjectCount());
            Assert.AreEqual(0, skin.GetDstObjectCount());
            Assert.AreEqual(null, skin.GetGeometry());

            Assert.AreEqual(0, mesh.GetSrcObjectCount());
            Assert.AreEqual(0, mesh.GetDstObjectCount());
            Assert.AreEqual(0, mesh.GetDeformerCount());

            // when:
            skin.SetGeometry(mesh);

            // then:
            Assert.AreEqual(0, skin.GetSrcObjectCount());
            Assert.AreEqual(1, skin.GetDstObjectCount());
            Assert.AreSame(mesh, skin.GetGeometry());

            Assert.AreEqual(1, mesh.GetSrcObjectCount());
            Assert.AreEqual(0, mesh.GetDstObjectCount());
            Assert.AreEqual(1, mesh.GetDeformerCount());
            Assert.AreSame(skin, mesh.GetDeformer(0));
        }
Example #7
0
        public static FbxSkin Cast(FbxObject arg0)
        {
            global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxSkin_Cast(FbxObject.getCPtr(arg0));
            FbxSkin ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxSkin(cPtr, false);

            return(ret);
        }
Example #8
0
        public void Skin_Create_HasNamespacePrefix()
        {
            // given:
            var obj = new FbxSkin("asdf");

            // then:
            Assert.AreEqual("Deformer::", obj.GetNameSpacePrefix());
        }
Example #9
0
 public bool Equals(FbxSkin other)
 {
     if (object.ReferenceEquals(other, null))
     {
         return(false);
     }
     return(this.swigCPtr.Handle.Equals(other.swigCPtr.Handle));
 }
Example #10
0
        protected void LinkMeshToSkeleton(FbxScene scene, FbxNode meshNode, FbxNode skelRootNode)
        {
            FbxNode limb1 = skelRootNode.GetChild(0);
            FbxNode limb2 = limb1.GetChild(0);

            FbxCluster rootCluster = FbxCluster.Create(scene, "RootCluster");

            rootCluster.SetLink(skelRootNode);
            rootCluster.SetLinkMode(FbxCluster.ELinkMode.eTotalOne);
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    rootCluster.AddControlPointIndex(4 * i + j, 1.0 - 0.25 * i);
                }
            }

            FbxCluster limb1Cluster = FbxCluster.Create(scene, "Limb1Cluster");

            limb1Cluster.SetLink(limb1);
            limb1Cluster.SetLinkMode(FbxCluster.ELinkMode.eTotalOne);
            for (int i = 1; i < 6; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    limb1Cluster.AddControlPointIndex(4 * i + j, (i == 1 || i == 5 ? 0.25 : 0.5));
                }
            }

            FbxCluster limb2Cluster = FbxCluster.Create(scene, "Limb2Cluster");

            limb2Cluster.SetLink(limb2);
            limb2Cluster.SetLinkMode(FbxCluster.ELinkMode.eTotalOne);
            for (int i = 3; i < 7; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    limb2Cluster.AddControlPointIndex(4 * i + j, 0.25 * (i - 2));
                }
            }

            FbxAMatrix globalTransform = meshNode.EvaluateGlobalTransform();

            rootCluster.SetTransformMatrix(globalTransform);
            limb1Cluster.SetTransformMatrix(globalTransform);
            limb2Cluster.SetTransformMatrix(globalTransform);

            rootCluster.SetTransformLinkMatrix(skelRootNode.EvaluateGlobalTransform());
            limb1Cluster.SetTransformLinkMatrix(limb1.EvaluateGlobalTransform());
            limb2Cluster.SetTransformLinkMatrix(limb2.EvaluateGlobalTransform());

            FbxSkin skin = FbxSkin.Create(scene, "Skin");

            skin.AddCluster(rootCluster);
            skin.AddCluster(limb1Cluster);
            skin.AddCluster(limb2Cluster);
            meshNode.GetMesh().AddDeformer(skin);
        }
Example #11
0
        public new static FbxSkin Create(FbxObject pContainer, string pName)
        {
            global::System.IntPtr cPtr = NativeMethods.FbxSkin_Create__SWIG_1(FbxObject.getCPtr(pContainer), pName);
            FbxSkin ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxSkin(cPtr, false);

            if (NativeMethods.SWIGPendingException.Pending)
            {
                throw NativeMethods.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
        override public void TestBasics(T fbxGeometry, FbxNodeAttribute.EType typ)
        {
            base.TestBasics(fbxGeometry, typ);

            int origCount = fbxGeometry.GetDeformerCount();

            // test get blendshape deformer
            FbxBlendShape blendShape = FbxBlendShape.Create(Manager, "blendShape");
            int           index      = fbxGeometry.AddDeformer(blendShape);

            Assert.GreaterOrEqual(index, 0);
            origCount++;

            // TODO: (UNI-19581): If we add the blendShape after the skin, then the below
            //                    tests fail.
            Assert.AreEqual(blendShape, fbxGeometry.GetBlendShapeDeformer(index));
            Assert.AreEqual(blendShape, fbxGeometry.GetBlendShapeDeformer(index, null));
            Assert.AreEqual(blendShape, fbxGeometry.GetDeformer(index, FbxDeformer.EDeformerType.eBlendShape));
            Assert.AreEqual(1, fbxGeometry.GetDeformerCount(FbxDeformer.EDeformerType.eBlendShape));

            // test add deformer
            FbxSkin skin      = FbxSkin.Create(Manager, "skin");
            int     skinIndex = fbxGeometry.AddDeformer(skin);

            Assert.GreaterOrEqual(skinIndex, 0);
            Assert.AreEqual(skin, fbxGeometry.GetDeformer(skinIndex));

            // test get invalid deformer index doesn't crash
            fbxGeometry.GetDeformer(-1, new FbxStatus());
            fbxGeometry.GetDeformer(int.MaxValue, new FbxStatus());

            // test get deformer null FbxStatus
            fbxGeometry.GetDeformer(0, null);

            // check right index but wrong type
            Assert.IsNull(fbxGeometry.GetDeformer(skinIndex, FbxDeformer.EDeformerType.eVertexCache, null));

            Assert.AreEqual(origCount + 1, fbxGeometry.GetDeformerCount());

            // test add null deformer
            Assert.That(() => fbxGeometry.AddDeformer(null), Throws.Exception.TypeOf <System.ArgumentNullException>());

            // test add invalid deformer
            skin.Destroy();
            Assert.That(() => fbxGeometry.AddDeformer(skin), Throws.Exception.TypeOf <System.ArgumentNullException>());
        }
Example #13
0
        public void Geometry_AddSrcConnection_AddsDeformer()
        {
            // given:
            var g    = new FbxMesh("");
            var skin = new FbxSkin("");

            // require:
            Assert.AreEqual(0, g.GetDeformerCount());
            Assert.AreEqual(0, g.GetSrcObjectCount());

            // when:
            g.ConnectSrcObject(skin);

            // then:
            Assert.AreEqual(1, g.GetDeformerCount());
            Assert.AreSame(skin, g.GetDeformer(0));
            Assert.AreEqual(1, g.GetSrcObjectCount());
            Assert.AreSame(skin, g.GetSrcObject(0));
        }
Example #14
0
        public void Geometry_DisconnectSrcObject_RemovesDeformer()
        {
            // given:
            var g    = new FbxMesh("");
            var skin = new FbxSkin("");

            g.AddDeformer(skin);

            // require:
            Assert.AreEqual(1, g.GetDeformerCount());
            Assert.AreEqual(1, g.GetSrcObjectCount());

            // when:
            g.DisconnectSrcObject(skin);

            // then:
            Assert.AreEqual(0, g.GetDeformerCount());
            Assert.AreEqual(0, g.GetSrcObjectCount());
        }
Example #15
0
            /// <summary>
            /// Export binding of mesh to skeleton
            /// </summary>
            protected void ExportSkin(MeshInfo meshInfo, FbxScene fbxScene, FbxMesh fbxMesh,
                                      FbxNode fbxRootNode,
                                      Dictionary <Transform, FbxNode> boneNodes)
            {
                SkinnedMeshRenderer unitySkinnedMeshRenderer
                    = meshInfo.renderer as SkinnedMeshRenderer;

                FbxSkin fbxSkin = FbxSkin.Create(fbxScene, (meshInfo.unityObject.name + "_Skin"));

                FbxAMatrix fbxMeshMatrix = fbxRootNode.EvaluateGlobalTransform();

                // keep track of the bone index -> fbx cluster mapping, so that we can add the bone weights afterwards
                Dictionary <int, FbxCluster> boneCluster = new Dictionary <int, FbxCluster> ();

                for (int i = 0; i < unitySkinnedMeshRenderer.bones.Length; i++)
                {
                    FbxNode fbxBoneNode = boneNodes [unitySkinnedMeshRenderer.bones[i]];

                    // Create the deforming cluster
                    FbxCluster fbxCluster = FbxCluster.Create(fbxScene, "BoneWeightCluster");

                    fbxCluster.SetLink(fbxBoneNode);
                    fbxCluster.SetLinkMode(FbxCluster.ELinkMode.eTotalOne);

                    boneCluster.Add(i, fbxCluster);

                    // set the Transform and TransformLink matrix
                    fbxCluster.SetTransformMatrix(fbxMeshMatrix);

                    FbxAMatrix fbxLinkMatrix = fbxBoneNode.EvaluateGlobalTransform();
                    fbxCluster.SetTransformLinkMatrix(fbxLinkMatrix);

                    // add the cluster to the skin
                    fbxSkin.AddCluster(fbxCluster);
                }

                // set the vertex weights for each bone
                SetVertexWeights(meshInfo, boneCluster);

                // Add the skin to the mesh after the clusters have been added
                fbxMesh.AddDeformer(fbxSkin);
            }
Example #16
0
        static void LoadSkinsFromNodeRecursive(FbxNode pNode, List <FbxSkin> skinsResult)
        {
            FbxNodeAttribute pNodeAttribute = pNode.GetNodeAttribute();

            if (pNodeAttribute?.GetAttributeType() == FbxNodeAttribute.EType.eMesh)
            {
                FbxMesh pMesh     = pNode.GetMesh();
                int     skinCount = pMesh.GetDeformerCount(FbxDeformer.EDeformerType.eSkin);
                for (int i = 0; i < skinCount; i++)
                {
                    FbxSkin pSkin = FbxSkin.Cast(pMesh.GetDeformer(i, FbxDeformer.EDeformerType.eSkin));
                    skinsResult.Add(pSkin);
                }
            }

            for (int i = 0; i < pNode.GetChildCount(); i++)
            {
                LoadSkinsFromNodeRecursive(pNode.GetChild(i), skinsResult);
            }
        }
Example #17
0
        protected void CheckMeshLinkedToSkeleton(FbxMesh origMesh, FbxMesh importMesh)
        {
            FbxSkin origSkin = origMesh.GetDeformer(0, new FbxStatus()) as FbxSkin;

            Assert.IsNotNull(origSkin);

            FbxSkin importSkin = origMesh.GetDeformer(0, new FbxStatus()) as FbxSkin;

            Assert.IsNotNull(importSkin);

            ClusterPair[] clusters = new ClusterPair[3];

            for (int i = 0; i < 3; i++)
            {
                FbxCluster origCluster = origSkin.GetCluster(i);
                Assert.IsNotNull(origCluster);

                FbxCluster importCluster = importSkin.GetCluster(i);
                Assert.IsNotNull(importCluster);

                clusters [i] = new ClusterPair(origCluster, importCluster);
            }

            foreach (var c in clusters)
            {
                FbxAMatrix origTransformMatrix   = null;
                FbxAMatrix importTransformMatrix = null;
                Assert.AreEqual(c.orig.GetTransformMatrix(origTransformMatrix), c.import.GetTransformMatrix(importTransformMatrix));
                Assert.AreEqual(c.orig.GetTransformLinkMatrix(origTransformMatrix), c.import.GetTransformLinkMatrix(importTransformMatrix));

                Assert.AreEqual(c.orig.GetLink(), c.import.GetLink());
                Assert.AreEqual(c.orig.GetLinkMode(), c.import.GetLinkMode());
                Assert.AreEqual(c.orig.GetControlPointIndicesCount(), c.import.GetControlPointIndicesCount());

                for (int i = 0; i < c.orig.GetControlPointIndicesCount(); i++)
                {
                    Assert.AreEqual(c.orig.GetControlPointIndexAt(i), c.import.GetControlPointIndexAt(i));
                    Assert.AreEqual(c.orig.GetControlPointWeightAt(i), c.import.GetControlPointWeightAt(i));
                }
            }
        }
Example #18
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FbxSkin obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }