Esempio n. 1
0
        public static MeshData[] ProcMesh(FbxManager manager, FbxNode node, FbxMesh mesh, ImportOptions importOptions, Matrix4 additionalTransform)
        {
            var transform = additionalTransform * FbxMath.EvaluateGlobalTransform(node).ToMatrix4();

            transform = transform * FbxMath.GetGeometryOffset(node).ToMatrix4();
            var  converter = new FbxGeometryConverter(manager);
            bool success   = false;

            try
            {
                mesh    = FbxMesh.Cast(converter.Triangulate(mesh, false));                  //ToDo :? Может true? Чтобы не создавать второй mesh в Attribute
                success = true;
            }
            catch (Exception ex)
            {
                FbxImportLog.LogError(node, "Inside Triangulate error: " + ex);
            }
            if (!success || mesh == null)
            {
                return(null);
            }
            MeshData data = ReadTriangles(mesh, node);
            var      ret  = ReadMaterialsAndSplitByMaterials(data);

            foreach (var m in ret)
            {
                ReadMeshElements(m, importOptions, ref transform);
            }

            return(ret);
        }
Esempio n. 2
0
        //ToDo : учет associate model?
        // GlobalTransform of the bone at the binding moment.
        //
        // (Comments from fbxcluster.h)
        // Transformation matrices. A link has three transformation matrices:
        // - Transform refers to the global initial transform of the geometry node(geometry is the attribute of the node) that contains the link node.
        // - TransformLink refers to global initial transform of the link(bone) node.
        // - TransformAssociateModel refers to the global initial transform of the associate model.
        //
        // For example, given a mesh binding with several bones(links), Transform is the global transform
        // of the mesh at the binding moment, TransformLink is the global transform of the bone(link)
        // at the binding moment, TransformAssociateModel is the global transform of the associate model
        // at the binding moment.

        FbxAMatrix GetInitialTransform()
        {
            if (cluster == null)
            {
                return(FbxMath.EvaluateGlobalTransform(Node));
            }

            //Each cluster is associated with a FbxNode (bone)
            //cluster.GetLink().GetUniqueID() == Node.GetUniqueID();


            //??? Учитывать ли AxisSystem?
            //??? Не совсем понятны отличаи globalMeshTransform == skin.GetGeometry().GetNode().EvaluateGlobalTransform(), от cluster.GetTransformMatrix()

            //matrix associated with the geometry node containing the link. (global transform of the mesh at the binding moment)
            FbxAMatrix globalMeshInitialTransform = new FbxAMatrix();

            cluster.GetTransformMatrix(globalMeshInitialTransform);

            //Get matrix associated with the link node (bind pose,  bone transform) at the binding moment
            FbxAMatrix boneInitialTransform = new FbxAMatrix();

            cluster.GetTransformLinkMatrix(boneInitialTransform);
            //Дополнительная матрица которую cluster ассоциирует с Node - Трансформация в момент привязки.

            //bind pose matrix that is local for the mesh = Inverse(TransformMatrix) * TransformLinkMatrix
            FbxAMatrix localBindPose = (globalMeshInitialTransform.mul(geometryOffset).Inverse()).mul(boneInitialTransform);

            //globalMeshTransform * Inverse(globalMeshInitialTransform) * boneInitialTransform
            return(globalMeshTransform.mul(geometryOffset).mul(localBindPose));
        }