Beispiel #1
0
        void CaptureMesh(ref MeshData data, Mesh mesh, Cloth cloth, GetFlags flags, Material[] materials)
        {
            bool use_cloth = cloth != null;

            if (flags.getPoints)
            {
                data.points = use_cloth ? cloth.vertices : mesh.vertices;
            }
            if (flags.getNormals)
            {
                data.normals = use_cloth ? cloth.normals : mesh.normals;
            }
            if (flags.getTangents)
            {
                data.tangents = mesh.tangents;
            }
            if (flags.getUV)
            {
                data.uv = mesh.uv;
            }
            if (flags.getColors)
            {
                data.colors = mesh.colors;
            }
            if (flags.getIndices)
            {
                if (!flags.getMaterialIDs || materials == null || materials.Length == 0)
                {
                    data.indices = mesh.triangles;
                }
                else
                {
                    int n = mesh.subMeshCount;
                    for (int i = 0; i < n; ++i)
                    {
                        var indices = mesh.GetIndices(i);
                        int mid     = i < materials.Length ? GetMaterialIndex(materials[i]) : 0;
                        data.WriteSubmeshTriangles(indices, mid);
                    }
                }
            }
            if (flags.getBones)
            {
                data.boneWeights = mesh.boneWeights;
                data.bindposes   = mesh.bindposes;
            }
        }
Beispiel #2
0
        void CaptureMesh(ref MeshData data, Mesh mesh, Cloth cloth, GetFlags flags, Material[] materials)
        {
            if (flags.getPoints)
            {
                data.WritePoints(mesh.vertices);
            }
            if (flags.getNormals)
            {
                data.WriteNormals(mesh.normals);
            }
            if (flags.getTangents)
            {
                data.WriteTangents(mesh.tangents);
            }
            if (flags.getUV0)
            {
                data.WriteUV0(mesh.uv);
            }
            if (flags.getUV1)
            {
                data.WriteUV1(mesh.uv2);
            }
            if (flags.getColors)
            {
                data.WriteColors(mesh.colors);
            }
            if (flags.getIndices)
            {
                if (!flags.getMaterialIDs || materials == null || materials.Length == 0)
                {
                    data.WriteIndices(mesh.triangles);
                }
                else
                {
                    int n = mesh.subMeshCount;
                    for (int i = 0; i < n; ++i)
                    {
                        var indices = mesh.GetIndices(i);
                        int mid     = i < materials.Length ? GetMaterialIndex(materials[i]) : 0;
                        data.WriteSubmeshTriangles(indices, mid);
                    }
                }
            }

            // bones & blendshapes are handled by CaptureSkinnedMeshRenderer()
        }
Beispiel #3
0
 void CaptureMesh(ref MeshData data, Mesh mesh, Cloth cloth, GetFlags flags, Material[] materials)
 {
     // todo: cloth?
     if (flags.getPoints)
     {
         data.WritePoints(mesh.vertices);
     }
     if (flags.getNormals)
     {
         data.WriteNormals(mesh.normals);
     }
     if (flags.getTangents)
     {
         data.WriteTangents(mesh.tangents);
     }
     if (flags.getUV0)
     {
         data.WriteUV0(mesh.uv);
     }
     if (flags.getUV1)
     {
         data.WriteUV1(mesh.uv2);
     }
     if (flags.getColors)
     {
         data.WriteColors(mesh.colors);
     }
     if (flags.getIndices)
     {
         if (!flags.getMaterialIDs || materials == null || materials.Length == 0)
         {
             data.WriteIndices(mesh.triangles);
         }
         else
         {
             int n = mesh.subMeshCount;
             for (int i = 0; i < n; ++i)
             {
                 var indices = mesh.GetIndices(i);
                 int mid     = i < materials.Length ? GetMaterialIndex(materials[i]) : 0;
                 data.WriteSubmeshTriangles(indices, mid);
             }
         }
     }
     if (flags.getBones)
     {
         data.WriteWeights(mesh.boneWeights);
         data.bindposes = mesh.bindposes;
     }
     if (flags.getBlendShapes && mesh.blendShapeCount > 0)
     {
         var v = new Vector3[mesh.vertexCount];
         var n = new Vector3[mesh.vertexCount];
         var t = new Vector3[mesh.vertexCount];
         for (int bi = 0; bi < mesh.blendShapeCount; ++bi)
         {
             var bd         = data.AddBlendShape(mesh.GetBlendShapeName(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);
             }
         }
     }
 }