Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
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);
            }
        }