Пример #1
0
    private Mesh GetStencilMesh(WVR_Eye eye)
    {
        float[] vertexData = null;
        int[]   indexData = null;
        uint    vertexCount = 0, triangleCount = 0;

        try
        {
            WaveVR_Utils.WVR_GetStencilMesh(eye, ref vertexCount, ref triangleCount, 0, null, 0, null);
            Log.d(TAG, "vertexCount " + vertexCount + " triangleCount " + triangleCount);

            if (vertexCount <= 0 || vertexCount > 0xFF || triangleCount <= 0 || triangleCount > 0xFF)
            {
                return(null);
            }

            vertexData = new float[vertexCount * 3];
            indexData  = new int[triangleCount * 3];
            WaveVR_Utils.WVR_GetStencilMesh(eye, ref vertexCount, ref triangleCount, vertexCount * 3, vertexData, triangleCount * 3, indexData);
        }
        catch (EntryPointNotFoundException e)
        {
            Log.e(TAG, "API doesn't exist:\n" + e.Message);
            return(null);
        }

        int indicesCount = (int)triangleCount * 3;

        if (indexData == null || vertexData == null)
        {
            Log.e(TAG, "Out of memory");
            return(null);
        }

        // create mesh

        float ZDir = 0;

        if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3 ||
            SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES2 ||
            SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLCore)
        {
            ZDir = -1;
        }
        else
        {
            if (SystemInfo.usesReversedZBuffer)
            {
                ZDir = 1;
            }
            else
            {
                ZDir = 0;
            }
        }

        Vector3[] verticesUnity = new Vector3[vertexCount];
        int[]     indicesUnity  = new int[indicesCount];

        for (int i = 0; i < vertexCount; i++)
        {
            verticesUnity[i] = new Vector3(vertexData[3 * i], vertexData[3 * i + 1], ZDir);
        }

        // The mesh from SDK is GL style.  Change to left hand rule.
        for (int i = 0; i < triangleCount; i++)
        {
            int j = i * 3;
            indicesUnity[j]     = indexData[j];
            indicesUnity[j + 1] = indexData[j + 2];
            indicesUnity[j + 2] = indexData[j + 1];
        }

        Mesh mesh = new Mesh()
        {
            name     = "RenderMask",
            vertices = verticesUnity,
        };

        mesh.SetIndices(indicesUnity, MeshTopology.Triangles, 0);
        Log.d(TAG, "RenderMask " + eye + " is loaded");
        return(mesh);
    }