Esempio n. 1
0
        bool CaptureSkinnedMeshRenderer(ref MeshData dst, SkinnedMeshRenderer smr, GetMessage mes, ref Mesh mesh)
        {
            mesh = smr.sharedMesh;
            if (mesh == null)
            {
                return(false);
            }

            if (!mes.bakeSkin && !mesh.isReadable)
            {
                Debug.LogWarning("Mesh " + smr.name + " is not readable and be ignored");
                return(false);
            }

            Cloth cloth = smr.GetComponent <Cloth>();

            if (cloth != null && mes.bakeCloth)
            {
                CaptureMesh(ref dst, mesh, cloth, mes.flags, smr.sharedMaterials);
            }

            if (mes.bakeSkin)
            {
                Mesh tmp = new Mesh();
                smr.BakeMesh(tmp);
                CaptureMesh(ref dst, tmp, null, mes.flags, smr.sharedMaterials);
            }
            else
            {
                CaptureMesh(ref dst, mesh, null, mes.flags, smr.sharedMaterials);

                // bones
                if (mes.flags.getBones)
                {
                    dst.SetBonePaths(this, smr.bones);
                    dst.bindposes = mesh.bindposes;

                    NativeArray <byte>        bonesPerVertex = mesh.GetBonesPerVertex();
                    NativeArray <BoneWeight1> weights        = mesh.GetAllBoneWeights();
                    dst.WriteBoneWeightsV(ref bonesPerVertex, ref weights);
                }

                // blendshapes
                if (mes.flags.getBlendShapes && mesh.blendShapeCount > 0)
                {
                    Vector3[] v = new Vector3[mesh.vertexCount];
                    Vector3[] n = new Vector3[mesh.vertexCount];
                    Vector3[] t = new Vector3[mesh.vertexCount];
                    for (int bi = 0; bi < mesh.blendShapeCount; ++bi)
                    {
                        BlendShapeData bd = dst.AddBlendShape(mesh.GetBlendShapeName(bi));
                        bd.weight = smr.GetBlendShapeWeight(bi);
                        int frameCount = mesh.GetBlendShapeFrameCount(bi);
                        for (int fi = 0; fi < frameCount; ++fi)
                        {
                            mesh.GetBlendShapeFrameVertices(bi, fi, v, n, t);
                            float w = mesh.GetBlendShapeFrameWeight(bi, fi);
                            bd.AddFrame(w, v, n, t);
                        }
                    }
                }
            }
            return(true);
        }