コード例 #1
0
        // skinning
        private void CreateMeshSkinning(Dictionary <string, List <VertexWeight> > vg, FBXNode pFbxMesh, FBXNode pSkeletonRoot, FBXScene pScene)
        {
            FBXSkin    lFbxSkin          = FBXSkin.Create(pScene, "");
            FBXAMatrix lMeshMatTransform = pFbxMesh.EvaluateGlobalTransform();

            foreach (string key in vg.Keys)
            {
                List <VertexWeight> bvg      = vg[key];
                FBXCluster          lCluster = FBXCluster.Create(pScene, key);
                FBXNode             lFbxBone = pSkeletonRoot.FindChild(key);
                if (lFbxBone != null)
                {
                    lCluster.SetLink(lFbxBone);
                    foreach (VertexWeight v in bvg)
                    {
                        lCluster.AddControlPointIndex(v.vertexIndex, v.weight);
                    }
                    lFbxSkin.AddCluster(lCluster);
                    lCluster.SetTransformMatrix(lMeshMatTransform);
                    FBXAMatrix lBoneMatTransform = lFbxBone.EvaluateGlobalTransform();
                    lCluster.SetTransformLinkMatrix(lBoneMatTransform);
                }
            }

            FBXGeometry lFbxMeshAtt = (FBXGeometry)pFbxMesh.GetNodeAttribute().ToGeometry();

            if (lFbxMeshAtt != null)
            {
                lFbxMeshAtt.AddDeformer(lFbxSkin);
            }
        }
コード例 #2
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
        private void StoreRestPose(FBXScene pScene, FBXNode pSkeletonRoot, SkeletonAsset Skeleton)
        {
            Dictionary <String, FBBone> pose = Skeleton.ModelBones;
            FBXAMatrix lTransformMatrix = new FBXAMatrix();
            FBXVector4 lT, lR, lS;

            lS = new FBXVector4(1.0, 1.0, 1.0, 0);
            FBXPose lPose = FBXPose.Create(pScene, "A Bind Pose");

            lT = new FBXVector4();
            lR = new FBXVector4();
            lTransformMatrix.SetTRS(lT, lR, lS);
            FBXNode lKFbxNode = pSkeletonRoot;

            lPose.Add(lKFbxNode, lTransformMatrix);
            foreach (string key in pose.Keys)
            {
                FBBone     bonePose      = pose[key];
                FBXNode    fbxBone       = pSkeletonRoot.FindChild(key);
                FBXVector4 Forward       = new FBXVector4(bonePose.Forward.members[0], bonePose.Forward.members[1], bonePose.Forward.members[2], 0);
                FBXVector4 Right         = new FBXVector4(bonePose.Right.members[0], bonePose.Right.members[1], bonePose.Right.members[2], 0);
                FBXVector4 Up            = new FBXVector4(bonePose.Up.members[0], bonePose.Up.members[1], bonePose.Up.members[2], 0);
                FBXVector4 Trans         = new FBXVector4(bonePose.Location.members[0] * exportScale, bonePose.Location.members[1] * exportScale, bonePose.Location.members[2] * exportScale, 1);
                FBXAMatrix boneTransform = new FBXAMatrix();
                boneTransform.SetRow(0, Right);
                boneTransform.SetRow(1, Up);
                boneTransform.SetRow(2, Forward);
                boneTransform.SetRow(3, Trans);
                lPose.Add(fbxBone, boneTransform);
            }
            lPose.SetIsBindPose(true);
            pScene.AddPose(lPose);
        }
コード例 #3
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
        private void StoreBindPose(FBXScene pScene, FBXNode pMesh)
        {
            List <FBXNode>   lClusteredFbxNodes = new List <FBXNode>();
            int              i, j;
            FBXNodeAttribute att = pMesh.GetNodeAttribute();

            if (pMesh != null && att != null)
            {
                int lSkinCount    = 0;
                int lClusterCount = 0;
                switch (pMesh.GetNodeAttribute().GetAttributeType())
                {
                default:
                    break;

                case NodeAttribType.eMesh:
                case NodeAttribType.eNurbs:
                case NodeAttribType.ePatch:
                    FBXGeometry geo = (FBXGeometry)att.ToGeometry();
                    lSkinCount = geo.GetDeformerCount(EDeformerType.eSkin);
                    for (i = 0; i < lSkinCount; ++i)
                    {
                        FBXSkin lSkin = geo.GetSkinDeformer(i);
                        lClusterCount += lSkin.GetClusterCount();
                    }
                    break;
                }
                if (lClusterCount != 0)
                {
                    for (i = 0; i < lSkinCount; ++i)
                    {
                        FBXGeometry geo   = (FBXGeometry)att.ToGeometry();
                        FBXSkin     lSkin = geo.GetSkinDeformer(i);
                        lClusterCount = lSkin.GetClusterCount();
                        for (j = 0; j < lClusterCount; ++j)
                        {
                            FBXNode lClusterNode = lSkin.GetClusterLink(j);
                            AddNodeRecursively(lClusteredFbxNodes, lClusterNode);
                        }
                    }
                    lClusteredFbxNodes.Add(pMesh);
                }
            }
            if (lClusteredFbxNodes.Count != 0)
            {
                FBXPose lPose = FBXPose.Create(pScene, "pose");
                lPose.SetIsBindPose(true);
                for (i = 0; i < lClusteredFbxNodes.Count; i++)
                {
                    FBXNode    lKFbxNode   = lClusteredFbxNodes[i];
                    FBXAMatrix lBindMatrix = lKFbxNode.EvaluateGlobalTransform();
                    lPose.Add(lKFbxNode, lBindMatrix);
                }
                pScene.AddPose(lPose);
            }
        }
コード例 #4
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
        private FBXVector4 CalculateBoneRotation(FBBone bone)
        {
            FBXAMatrix fbxrotMat = new FBXAMatrix();
            FBXVector4 Forward   = new FBXVector4(bone.Forward.members[0], bone.Forward.members[1], bone.Forward.members[2], 0);
            FBXVector4 Right     = new FBXVector4(bone.Right.members[0], bone.Right.members[1], bone.Right.members[2], 0);
            FBXVector4 Up        = new FBXVector4(bone.Up.members[0], bone.Up.members[1], bone.Up.members[2], 0);

            fbxrotMat.SetRow(0, Right);
            fbxrotMat.SetRow(1, Up);
            fbxrotMat.SetRow(2, Forward);
            fbxrotMat.SetRow(3, new FBXVector4(0, 0, 0, 1));
            FBXVector4 boneRot = fbxrotMat.getR();

            return(boneRot);
        }
コード例 #5
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
        private void SetBoneTransform(SkeletonAsset Skeleton, FBXNode pSkeletonRoot)
        {
            Dictionary <String, FBBone> pose = Skeleton.ModelBones;

            foreach (string key in pose.Keys)
            {
                FBBone     bonePose      = pose[key];
                FBXNode    fbxBone       = pSkeletonRoot.FindChild(key);
                FBXVector4 ForwardM      = new FBXVector4(bonePose.Forward.members[0], bonePose.Forward.members[1], bonePose.Forward.members[2], 0);
                FBXVector4 RightM        = new FBXVector4(bonePose.Right.members[0], bonePose.Right.members[1], bonePose.Right.members[2], 0);
                FBXVector4 UpM           = new FBXVector4(bonePose.Up.members[0], bonePose.Up.members[1], bonePose.Up.members[2], 0);
                FBXVector4 TransM        = new FBXVector4(bonePose.Location.members[0] * exportScale, bonePose.Location.members[1] * exportScale, bonePose.Location.members[2] * exportScale, 1);
                FBXAMatrix transfoMatrix = new FBXAMatrix();
                transfoMatrix.SetRow(0, RightM);
                transfoMatrix.SetRow(1, UpM);
                transfoMatrix.SetRow(2, ForwardM);
                transfoMatrix.SetRow(3, TransM);
                FBXHelper.SetGlobalDefaultPosition(fbxBone, transfoMatrix);
            }
        }