コード例 #1
0
    // Token: 0x06000DDF RID: 3551 RVA: 0x00058090 File Offset: 0x00056290
    private SteamVR_RenderModel.RenderModel LoadRenderModel(CVRRenderModels renderModels, string renderModelName, string baseName)
    {
        IntPtr zero = IntPtr.Zero;
        EVRRenderModelError evrrenderModelError;

        for (;;)
        {
            evrrenderModelError = renderModels.LoadRenderModel_Async(renderModelName, ref zero);
            if (evrrenderModelError != EVRRenderModelError.Loading)
            {
                break;
            }
            SteamVR_RenderModel.Sleep();
        }
        if (evrrenderModelError != EVRRenderModelError.None)
        {
            Debug.LogError(string.Format("Failed to load render model {0} - {1}", renderModelName, evrrenderModelError.ToString()));
            return(null);
        }
        RenderModel_t renderModel_t = this.MarshalRenderModel(zero);

        Vector3[] array          = new Vector3[renderModel_t.unVertexCount];
        Vector3[] array2         = new Vector3[renderModel_t.unVertexCount];
        Vector2[] array3         = new Vector2[renderModel_t.unVertexCount];
        Type      typeFromHandle = typeof(RenderModel_Vertex_t);
        int       num            = 0;

        while ((long)num < (long)((ulong)renderModel_t.unVertexCount))
        {
            RenderModel_Vertex_t renderModel_Vertex_t = (RenderModel_Vertex_t)Marshal.PtrToStructure(new IntPtr(renderModel_t.rVertexData.ToInt64() + (long)(num * Marshal.SizeOf(typeFromHandle))), typeFromHandle);
            array[num]  = new Vector3(renderModel_Vertex_t.vPosition.v0, renderModel_Vertex_t.vPosition.v1, -renderModel_Vertex_t.vPosition.v2);
            array2[num] = new Vector3(renderModel_Vertex_t.vNormal.v0, renderModel_Vertex_t.vNormal.v1, -renderModel_Vertex_t.vNormal.v2);
            array3[num] = new Vector2(renderModel_Vertex_t.rfTextureCoord0, renderModel_Vertex_t.rfTextureCoord1);
            num++;
        }
        uint num2 = renderModel_t.unTriangleCount * 3U;

        short[] array4 = new short[num2];
        Marshal.Copy(renderModel_t.rIndexData, array4, 0, array4.Length);
        int[] array5 = new int[num2];
        int   num3   = 0;

        while ((long)num3 < (long)((ulong)renderModel_t.unTriangleCount))
        {
            array5[num3 * 3]     = (int)array4[num3 * 3 + 2];
            array5[num3 * 3 + 1] = (int)array4[num3 * 3 + 1];
            array5[num3 * 3 + 2] = (int)array4[num3 * 3];
            num3++;
        }
        Mesh mesh = new Mesh();

        mesh.vertices  = array;
        mesh.normals   = array2;
        mesh.uv        = array3;
        mesh.triangles = array5;
        Material material = SteamVR_RenderModel.materials[renderModel_t.diffuseTextureId] as Material;

        if (material == null || material.mainTexture == null)
        {
            IntPtr zero2 = IntPtr.Zero;
            for (;;)
            {
                evrrenderModelError = renderModels.LoadTexture_Async(renderModel_t.diffuseTextureId, ref zero2);
                if (evrrenderModelError != EVRRenderModelError.Loading)
                {
                    break;
                }
                SteamVR_RenderModel.Sleep();
            }
            if (evrrenderModelError == EVRRenderModelError.None)
            {
                RenderModel_TextureMap_t renderModel_TextureMap_t = this.MarshalRenderModel_TextureMap(zero2);
                Texture2D texture2D = new Texture2D((int)renderModel_TextureMap_t.unWidth, (int)renderModel_TextureMap_t.unHeight, TextureFormat.ARGB32, false);
                if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11)
                {
                    texture2D.Apply();
                    for (;;)
                    {
                        evrrenderModelError = renderModels.LoadIntoTextureD3D11_Async(renderModel_t.diffuseTextureId, texture2D.GetNativeTexturePtr());
                        if (evrrenderModelError != EVRRenderModelError.Loading)
                        {
                            break;
                        }
                        SteamVR_RenderModel.Sleep();
                    }
                }
                else
                {
                    byte[] array6 = new byte[(int)(renderModel_TextureMap_t.unWidth * renderModel_TextureMap_t.unHeight * '\u0004')];
                    Marshal.Copy(renderModel_TextureMap_t.rubTextureMapData, array6, 0, array6.Length);
                    Color32[] array7 = new Color32[(int)(renderModel_TextureMap_t.unWidth * renderModel_TextureMap_t.unHeight)];
                    int       num4   = 0;
                    for (int i = 0; i < (int)renderModel_TextureMap_t.unHeight; i++)
                    {
                        for (int j = 0; j < (int)renderModel_TextureMap_t.unWidth; j++)
                        {
                            byte r = array6[num4++];
                            byte g = array6[num4++];
                            byte b = array6[num4++];
                            byte a = array6[num4++];
                            array7[i * (int)renderModel_TextureMap_t.unWidth + j] = new Color32(r, g, b, a);
                        }
                    }
                    texture2D.SetPixels32(array7);
                    texture2D.Apply();
                }
                material             = new Material((this.shader != null) ? this.shader : Shader.Find("Standard"));
                material.mainTexture = texture2D;
                SteamVR_RenderModel.materials[renderModel_t.diffuseTextureId] = material;
                renderModels.FreeTexture(zero2);
            }
            else
            {
                Debug.Log("Failed to load render model texture for render model " + renderModelName);
            }
        }
        base.StartCoroutine(this.FreeRenderModel(zero));
        return(new SteamVR_RenderModel.RenderModel(mesh, material));
    }