private static Vector3[] ExtractBuffer3(vts.Mesh m, int attributeIndex)
    {
        var a = m.attributes[attributeIndex];

        if (!a.enable)
        {
            return(null);
        }
        Debug.Assert(a.components == 3);
        uint typeSize = Util.GpuTypeSize(a.type);

        Vector3[] r      = new Vector3[m.verticesCount];
        int       stride = (int)(a.stride == 0 ? typeSize * a.components : a.stride);
        int       start  = (int)a.offset;

        for (int i = 0; i < m.verticesCount; i++)
        {
            r[i] = new Vector3(
                ExtractFloat(m, start + i * stride + 0 * (int)typeSize, a.type, a.normalized),
                ExtractFloat(m, start + i * stride + 1 * (int)typeSize, a.type, a.normalized),
                ExtractFloat(m, start + i * stride + 2 * (int)typeSize, a.type, a.normalized)
                );
        }
        return(r);
    }
 private void LoadLinesIndices(vts.Mesh m)
 {
     topology = MeshTopology.Lines;
     if (m.indices != null)
     {
         indices = Array.ConvertAll(m.indices, Convert.ToInt32);
     }
     else
     {
         indices = new int[m.verticesCount];
         for (int i = 0; i < m.verticesCount; i++)
         {
             indices[i] = i;
         }
     }
 }
    private static float ExtractFloat(vts.Mesh m, int byteOffset, GpuType type, bool normalized)
    {
        switch (type)
        {
        case GpuType.Float:
            Debug.Assert(!normalized);
            return(BitConverter.ToSingle(m.vertices, byteOffset));

        case GpuType.UnsignedShort:
            Debug.Assert(normalized);
            return(BitConverter.ToUInt16(m.vertices, byteOffset) / 65535.0f);

        default:
            throw new VtsException(-17, "Unsupported gpu type");
        }
    }
 private void LoadTrianglesIndices(vts.Mesh m)
 {
     topology = MeshTopology.Triangles;
     if (m.indices != null)
     {
         indices = Array.ConvertAll(m.indices, Convert.ToInt32);
     }
     else
     {
         indices = new int[m.verticesCount];
         for (int i = 0; i < m.verticesCount; i += 3)
         {
             indices[i + 0] = i + 0;
             indices[i + 1] = i + 1;
             indices[i + 2] = i + 2;
         }
     }
 }
Пример #5
0
    public VtsMesh(vts.Mesh m)
    {
        // assume that attribute 0 is vertex positions
        vertices = ExtractBuffer3(m, 0);
        // assume that attribute 1 is internal texture coordinates (used with textures that are packed with the mesh)
        uv0 = ExtractBuffer2(m, 1);
        // assume that attribute 2 is external texture coordinates (used with textures that come from bound layers)
        uv1 = ExtractBuffer2(m, 2);
        // indices
        switch (m.faceMode)
        {
        case FaceMode.Triangles:
            LoadTrianglesIndices(m);
            break;

        case FaceMode.Lines:
            LoadLinesIndices(m);
            break;

        default:
            throw new VtsException(-19, "Unsupported mesh face mode");
        }
    }
 public static System.Object LoadMesh(vts.Mesh m)
 {
     return(new VtsMesh(m));
 }