Beispiel #1
0
 public Mesh MeshObjectGetMesh()
 {
     return(impl.MeshObjectGetMesh());
 }
Beispiel #2
0
    void vox(IMeshObject obj)
    {
        Mesh mesh = null;

        Material[] mats = null;

        mesh = obj.MeshObjectGetMesh();
        mats = obj.MeshObjectGetMaterials();

        // tris
        int[] tris    = mesh.triangles;
        int   lentris = mesh.triangles.Length;

        for (int i = 0; i < lentris; i++)
        {
            unsafe
            {
                tribuf[numtris + i] = numverts + tris[i];
            }
        }
        numtris += lentris;

        // vertices
        var vertices = mesh.vertices;
        int vertidx  = 0;
        int vertslen = vertices.Length;

        for (int i = 0; i < vertslen; i++)
        {
            Vector3 vert1 = obj.MeshObjectTransformPoint(vertices[i]); // + translationFromZeroCenter;

            vertidx = 3 * (numverts + i);
            unsafe
            {
                vertbuf[vertidx + 0] = vert1.x;
                vertbuf[vertidx + 1] = vert1.y;
                vertbuf[vertidx + 2] = vert1.z;
            }
        }
        numverts += vertices.Length;

        // trimats or color from texture

        if (mats[0].mainTexture == null)
        {
            int lensubmats = mesh.subMeshCount;
            for (int i = 0; i < lensubmats; i++)
            {
                int[] indices    = mesh.GetIndices(i);
                int   indicesLen = indices.Length / 3;
                for (int j = 0; j < indicesLen; j++)
                {
                    unsafe
                    {
                        trimatbuf[j + numtrimats] = nummats + i;
                    }
                }
                numtrimats += indicesLen;
            }
        }
        else
        {
            int lensubmats = mesh.subMeshCount;
            for (int i = 0; i < lensubmats; i++)
            {
                Texture2D t2d    = mats[i].mainTexture as Texture2D;
                Vector2[] uv     = mesh.uv;
                Vector2   target = new Vector2();
                lentris /= 3;
                Color targetColor;
                int   c;

                int[] indices    = mesh.GetIndices(i);
                int   indicesLen = indices.Length / 3;
                for (int j = 0; j < indicesLen; j++)
                {
                    target      = uv[indices[3 * j + 0]] + uv[indices[3 * j + 1]] + uv[indices[3 * j + 2]];
                    target     /= 3;
                    targetColor = t2d.GetPixelBilinear(target.x, target.y);
                    c           = ((int)(255f * targetColor.r)) << 16;
                    c          |= ((int)(255f * targetColor.g)) << 8;
                    c          |= ((int)(255f * targetColor.b));

                    unsafe
                    {
                        trimatbuf[j + numtrimats] = 0x7f000000 | c;
                    }
                }
                numtrimats += indicesLen;
            }
        }

        // mats
        int   intcolor, lenmats = mats.Length;
        Color color;

        for (int i = 0; i < lenmats; i++)
        {
            color     = mats[i].color;
            intcolor  = 0;
            intcolor |= ((int)(color.r * 255)) << 16;
            intcolor |= ((int)(color.g * 255)) << 8;
            intcolor |= ((int)(color.b * 255));
            unsafe
            {
                colorbuf[nummats + i + 1] = intcolor;
            }
        }
        nummats += mats.Length;
    }