Example #1
0
    // Token: 0x060000C7 RID: 199 RVA: 0x00008BFA File Offset: 0x00006DFA
    private global::System.Collections.IEnumerator SetModelAsync(string renderModelName)
    {
        bool flag = string.IsNullOrEmpty(renderModelName);

        if (flag)
        {
            yield break;
        }
        using (global::SteamVR_RenderModel.RenderModelInterfaceHolder holder = new global::SteamVR_RenderModel.RenderModelInterfaceHolder())
        {
            global::Valve.VR.CVRRenderModels renderModels = holder.instance;
            bool flag2 = renderModels == null;
            if (flag2)
            {
                yield break;
            }
            uint     count = renderModels.GetComponentCount(renderModelName);
            bool     flag3 = count > 0U;
            string[] renderModelNames;
            if (flag3)
            {
                renderModelNames = new string[count];
                int i = 0;
                while ((long)i < (long)((ulong)count))
                {
                    uint capacity = renderModels.GetComponentName(renderModelName, (uint)i, null, 0U);
                    bool flag4    = capacity == 0U;
                    if (!flag4)
                    {
                        global::System.Text.StringBuilder componentName = new global::System.Text.StringBuilder((int)capacity);
                        bool flag5 = renderModels.GetComponentName(renderModelName, (uint)i, componentName, capacity) == 0U;
                        if (!flag5)
                        {
                            capacity = renderModels.GetComponentRenderModelName(renderModelName, componentName.ToString(), null, 0U);
                            bool flag6 = capacity == 0U;
                            if (!flag6)
                            {
                                global::System.Text.StringBuilder name = new global::System.Text.StringBuilder((int)capacity);
                                bool flag7 = renderModels.GetComponentRenderModelName(renderModelName, componentName.ToString(), name, capacity) == 0U;
                                if (!flag7)
                                {
                                    string s = name.ToString();
                                    global::SteamVR_RenderModel.RenderModel model = global::SteamVR_RenderModel.models[s] as global::SteamVR_RenderModel.RenderModel;
                                    bool flag8 = model == null || model.mesh == null;
                                    if (flag8)
                                    {
                                        renderModelNames[i] = s;
                                    }
                                    componentName = null;
                                    name          = null;
                                    s             = null;
                                    model         = null;
                                }
                            }
                        }
                    }
                    int num = i;
                    i = num + 1;
                }
            }
            else
            {
                global::SteamVR_RenderModel.RenderModel model2 = global::SteamVR_RenderModel.models[renderModelName] as global::SteamVR_RenderModel.RenderModel;
                bool flag9 = model2 == null || model2.mesh == null;
                if (flag9)
                {
                    renderModelNames = new string[]
                    {
                        renderModelName
                    };
                }
                else
                {
                    renderModelNames = new string[0];
                }
                model2 = null;
            }
            for (;;)
            {
                bool loading = false;
                foreach (string name2 in renderModelNames)
                {
                    bool flag10 = string.IsNullOrEmpty(name2);
                    if (!flag10)
                    {
                        global::System.IntPtr pRenderModel         = global::System.IntPtr.Zero;
                        global::Valve.VR.EVRRenderModelError error = renderModels.LoadRenderModel_Async(name2, ref pRenderModel);
                        bool flag11 = error == global::Valve.VR.EVRRenderModelError.Loading;
                        if (flag11)
                        {
                            loading = true;
                        }
                        else
                        {
                            bool flag12 = error == global::Valve.VR.EVRRenderModelError.None;
                            if (flag12)
                            {
                                global::Valve.VR.RenderModel_t renderModel = (global::Valve.VR.RenderModel_t)global::System.Runtime.InteropServices.Marshal.PtrToStructure(pRenderModel, typeof(global::Valve.VR.RenderModel_t));
                                global::UnityEngine.Material   material    = global::SteamVR_RenderModel.materials[renderModel.diffuseTextureId] as global::UnityEngine.Material;
                                bool flag13 = material == null || material.mainTexture == null;
                                if (flag13)
                                {
                                    global::System.IntPtr pDiffuseTexture = global::System.IntPtr.Zero;
                                    error = renderModels.LoadTexture_Async(renderModel.diffuseTextureId, ref pDiffuseTexture);
                                    bool flag14 = error == global::Valve.VR.EVRRenderModelError.Loading;
                                    if (flag14)
                                    {
                                        loading = true;
                                    }
                                }
                                material = null;
                            }
                        }
                        name2 = null;
                    }
                }
                string[] array  = null;
                bool     flag15 = loading;
                if (!flag15)
                {
                    break;
                }
                yield return(new global::UnityEngine.WaitForSeconds(0.1f));
            }
            renderModels     = null;
            renderModelNames = null;
        }
        global::SteamVR_RenderModel.RenderModelInterfaceHolder holder = null;
        bool success = this.SetModel(renderModelName);

        global::SteamVR_Utils.Event.Send("render_model_loaded", new object[]
        {
            this,
            success
        });
        yield break;
        yield break;
    }
Example #2
0
    // Token: 0x060000C9 RID: 201 RVA: 0x00008D80 File Offset: 0x00006F80
    private global::SteamVR_RenderModel.RenderModel LoadRenderModel(global::Valve.VR.CVRRenderModels renderModels, string renderModelName, string baseName)
    {
        global::System.IntPtr zero = global::System.IntPtr.Zero;
        global::Valve.VR.EVRRenderModelError evrrenderModelError;
        for (;;)
        {
            evrrenderModelError = renderModels.LoadRenderModel_Async(renderModelName, ref zero);
            bool flag = evrrenderModelError != global::Valve.VR.EVRRenderModelError.Loading;
            if (flag)
            {
                break;
            }
            global::System.Threading.Thread.Sleep(1);
        }
        bool flag2 = evrrenderModelError > global::Valve.VR.EVRRenderModelError.None;

        global::SteamVR_RenderModel.RenderModel result;
        if (flag2)
        {
            global::UnityEngine.Debug.LogError(string.Format("Failed to load render model {0} - {1}", renderModelName, evrrenderModelError.ToString()));
            result = null;
        }
        else
        {
            global::Valve.VR.RenderModel_t renderModel_t  = (global::Valve.VR.RenderModel_t)global::System.Runtime.InteropServices.Marshal.PtrToStructure(zero, typeof(global::Valve.VR.RenderModel_t));
            global::UnityEngine.Vector3[]  array          = new global::UnityEngine.Vector3[renderModel_t.unVertexCount];
            global::UnityEngine.Vector3[]  array2         = new global::UnityEngine.Vector3[renderModel_t.unVertexCount];
            global::UnityEngine.Vector2[]  array3         = new global::UnityEngine.Vector2[renderModel_t.unVertexCount];
            global::System.Type            typeFromHandle = typeof(global::Valve.VR.RenderModel_Vertex_t);
            int num = 0;
            while ((long)num < (long)((ulong)renderModel_t.unVertexCount))
            {
                global::System.IntPtr intPtr;
                intPtr..ctor(renderModel_t.rVertexData.ToInt64() + (long)(num * global::System.Runtime.InteropServices.Marshal.SizeOf(typeFromHandle)));
                global::Valve.VR.RenderModel_Vertex_t renderModel_Vertex_t = (global::Valve.VR.RenderModel_Vertex_t)global::System.Runtime.InteropServices.Marshal.PtrToStructure(intPtr, typeFromHandle);
                array[num]  = new global::UnityEngine.Vector3(renderModel_Vertex_t.vPosition.v0, renderModel_Vertex_t.vPosition.v1, -renderModel_Vertex_t.vPosition.v2);
                array2[num] = new global::UnityEngine.Vector3(renderModel_Vertex_t.vNormal.v0, renderModel_Vertex_t.vNormal.v1, -renderModel_Vertex_t.vNormal.v2);
                array3[num] = new global::UnityEngine.Vector2(renderModel_Vertex_t.rfTextureCoord0, renderModel_Vertex_t.rfTextureCoord1);
                num++;
            }
            int     num2   = (int)(renderModel_t.unTriangleCount * 3U);
            short[] array4 = new short[num2];
            global::System.Runtime.InteropServices.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++;
            }
            global::UnityEngine.Mesh mesh = new global::UnityEngine.Mesh();
            mesh.vertices  = array;
            mesh.normals   = array2;
            mesh.uv        = array3;
            mesh.triangles = array5;
            mesh.Optimize();
            global::UnityEngine.Material material = global::SteamVR_RenderModel.materials[renderModel_t.diffuseTextureId] as global::UnityEngine.Material;
            bool flag3 = material == null || material.mainTexture == null;
            if (flag3)
            {
                global::System.IntPtr zero2 = global::System.IntPtr.Zero;
                for (;;)
                {
                    evrrenderModelError = renderModels.LoadTexture_Async(renderModel_t.diffuseTextureId, ref zero2);
                    bool flag4 = evrrenderModelError != global::Valve.VR.EVRRenderModelError.Loading;
                    if (flag4)
                    {
                        break;
                    }
                    global::System.Threading.Thread.Sleep(1);
                }
                bool flag5 = evrrenderModelError == global::Valve.VR.EVRRenderModelError.None;
                if (flag5)
                {
                    global::Valve.VR.RenderModel_TextureMap_t renderModel_TextureMap_t = (global::Valve.VR.RenderModel_TextureMap_t)global::System.Runtime.InteropServices.Marshal.PtrToStructure(zero2, typeof(global::Valve.VR.RenderModel_TextureMap_t));
                    global::UnityEngine.Texture2D             texture2D = new global::UnityEngine.Texture2D((int)renderModel_TextureMap_t.unWidth, (int)renderModel_TextureMap_t.unHeight, 5, false);
                    bool flag6 = global::UnityEngine.SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL");
                    if (flag6)
                    {
                        byte[] array6 = new byte[(int)(renderModel_TextureMap_t.unWidth * renderModel_TextureMap_t.unHeight * '\u0004')];
                        global::System.Runtime.InteropServices.Marshal.Copy(renderModel_TextureMap_t.rubTextureMapData, array6, 0, array6.Length);
                        global::UnityEngine.Color32[] array7 = new global::UnityEngine.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 b  = array6[num4++];
                                byte b2 = array6[num4++];
                                byte b3 = array6[num4++];
                                byte b4 = array6[num4++];
                                array7[i * (int)renderModel_TextureMap_t.unWidth + j] = new global::UnityEngine.Color32(b, b2, b3, b4);
                            }
                        }
                        texture2D.SetPixels32(array7);
                        texture2D.Apply();
                    }
                    else
                    {
                        texture2D.Apply();
                        for (;;)
                        {
                            evrrenderModelError = renderModels.LoadIntoTextureD3D11_Async(renderModel_t.diffuseTextureId, texture2D.GetNativeTexturePtr());
                            bool flag7 = evrrenderModelError != global::Valve.VR.EVRRenderModelError.Loading;
                            if (flag7)
                            {
                                break;
                            }
                            global::System.Threading.Thread.Sleep(1);
                        }
                    }
                    material             = new global::UnityEngine.Material((this.shader != null) ? this.shader : global::EscalationVR.UnityHelper.GetShader("Standard"));
                    material.mainTexture = texture2D;
                    global::SteamVR_RenderModel.materials[renderModel_t.diffuseTextureId] = material;
                    renderModels.FreeTexture(zero2);
                }
                else
                {
                    global::UnityEngine.Debug.Log("Failed to load render model texture for render model " + renderModelName);
                }
            }
            base.StartCoroutine(this.FreeRenderModel(zero));
            result = new global::SteamVR_RenderModel.RenderModel(mesh, material);
        }
        return(result);
    }