Esempio n. 1
0
 // Token: 0x0600200E RID: 8206 RVA: 0x0009E6E3 File Offset: 0x0009C8E3
 public void Unpack(ref RenderModel_t unpacked)
 {
     unpacked.rVertexData      = this.rVertexData;
     unpacked.unVertexCount    = this.unVertexCount;
     unpacked.rIndexData       = this.rIndexData;
     unpacked.unTriangleCount  = this.unTriangleCount;
     unpacked.diffuseTextureId = this.diffuseTextureId;
 }
Esempio n. 2
0
        public int    diffuseTextureId;   // 0x18

        // Constructors
        public RenderModel_t_Packed(RenderModel_t unpacked)
        {
            rVertexData      = default;
            unVertexCount    = default;
            rIndexData       = default;
            unTriangleCount  = default;
            diffuseTextureId = default;
        }         // 0x00000001801DA100-0x00000001801DA370
Esempio n. 3
0
 // Token: 0x0600200D RID: 8205 RVA: 0x0009E6A5 File Offset: 0x0009C8A5
 public RenderModel_t_Packed(RenderModel_t unpacked)
 {
     this.rVertexData      = unpacked.rVertexData;
     this.unVertexCount    = unpacked.unVertexCount;
     this.rIndexData       = unpacked.rIndexData;
     this.unTriangleCount  = unpacked.unTriangleCount;
     this.diffuseTextureId = unpacked.diffuseTextureId;
 }
Esempio n. 4
0
 /// <summary>
 /// Helper function to handle the inconvenient fact that the packing for RenderModel_t is
 /// different on Linux/OSX (4) than it is on Windows (8)
 /// </summary>
 /// <param name="pRenderModel">native pointer to the RenderModel_t</param>
 /// <returns></returns>
 private RenderModel_t MarshalRenderModel(System.IntPtr pRenderModel)
 {
     if ((System.Environment.OSVersion.Platform == System.PlatformID.MacOSX) ||
         (System.Environment.OSVersion.Platform == System.PlatformID.Unix))
     {
         var           packedModel = (RenderModel_t_Packed)Marshal.PtrToStructure(pRenderModel, typeof(RenderModel_t_Packed));
         RenderModel_t model       = new RenderModel_t();
         packedModel.Unpack(ref model);
         return(model);
     }
     else
     {
         return((RenderModel_t)Marshal.PtrToStructure(pRenderModel, typeof(RenderModel_t)));
     }
 }
Esempio n. 5
0
	public abstract void FreeRenderModel(ref RenderModel_t pRenderModel);
Esempio n. 6
0
	internal static extern void VR_IVRRenderModels_FreeRenderModel(IntPtr instancePtr, ref RenderModel_t pRenderModel);
Esempio n. 7
0
	public override void FreeRenderModel(ref RenderModel_t pRenderModel)
	{
		CheckIfUsable();
		VRNativeEntrypoints.VR_IVRRenderModels_FreeRenderModel(m_pVRRenderModels,ref pRenderModel);
	}
Esempio n. 8
0
 internal static extern bool VR_IVRRenderModels_LoadRenderModel(IntPtr instancePtr, string pchRenderModelName, ref RenderModel_t pRenderModel);
internal static extern void SteamAPI_vr_IVRSystem_FreeRenderModel(IntPtr instancePtr, ref RenderModel_t pRenderModel);
Esempio n. 10
0
internal static extern bool SteamAPI_vr_IVRSystem_LoadRenderModel(IntPtr instancePtr, string pchRenderModelName, ref RenderModel_t pRenderModel);
Esempio n. 11
0
            public static GLRenderModel Create(string name, RenderModel_t renderModel, RenderModel_TextureMap_t diffuseTexture)
            {
                // create and bind a VAO to hold the state for this model
                int vao = OpenGLUtil.CreateVertexArrayObject();
                GL.BindVertexArray(vao);

                // populate the vertex buffer
                int vbo = OpenGLUtil.CreateBufferObject();
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
                GL.BufferData(BufferTarget.ArrayBuffer, Marshal.SizeOf<RenderModel_Vertex_t>() * (int)renderModel.unVertexCount, renderModel.rVertexData, BufferUsageHint.StaticDraw);

                // identity the components in teh vertex buffer
                GL.EnableVertexAttribArray(0);
                GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Marshal.SizeOf<RenderModel_Vertex_t>(), Marshal.OffsetOf<RenderModel_Vertex_t>("vPosition")); // this might have to be size of 4?
                GL.EnableVertexAttribArray(1);
                GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, Marshal.SizeOf<RenderModel_Vertex_t>(), Marshal.OffsetOf<RenderModel_Vertex_t>("vNormal"));
                GL.EnableVertexAttribArray(2);
                GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, Marshal.SizeOf<RenderModel_Vertex_t>(), Marshal.OffsetOf<RenderModel_Vertex_t>("rfTextureCoord0"));

                // create and populate the index buffer
                int indexBuffer = OpenGLUtil.CreateBufferObject();
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer);
                GL.BufferData(BufferTarget.ElementArrayBuffer, Marshal.SizeOf<ushort>() * (int)renderModel.unTriangleCount * 3, renderModel.rIndexData, BufferUsageHint.StaticDraw);

                GL.BindVertexArray(0);

                // create and populate the texture
                int texture = OpenGLUtil.CreateTexture();
                GL.BindTexture(TextureTarget.Texture2D, texture);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, diffuseTexture.unWidth, diffuseTexture.unHeight,
                    0, PixelFormat.Rgba, PixelType.UnsignedByte, diffuseTexture.rubTextureMapData);
                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

                GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, new[] { (int)TextureParameterName.ClampToEdge });
                GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, new[] { (int)TextureParameterName.ClampToEdge });
                GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, new[] { (int)TextureMagFilter.Linear });
                GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, new[] { (int)TextureMinFilter.LinearMipmapLinear });

                // *****missing stuff about anisotropy ***** // not sure if this is right
                float largest = GL.GetFloat((GetPName)0x84FF);
                GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)0x84FE, largest);

                GL.BindTexture(TextureTarget.Texture2D, 0);

                return new GLRenderModel(vbo, indexBuffer, vao, texture, (int)renderModel.unTriangleCount * 3, name);
            }
    static RenderModel LoadRenderModel(string renderModelName)
    {
        var error = HmdError.None;
        if (!SteamVR.active)
        {
            OpenVR.Init(ref error);
            if (error != HmdError.None)
                return null;
        }

        var pRenderModels = OpenVR.GetGenericInterface(OpenVR.IVRRenderModels_Version, ref error);
        if (pRenderModels == System.IntPtr.Zero || error != HmdError.None)
        {
            if (!SteamVR.active)
                OpenVR.Shutdown();
            return null;
        }

        var renderModels = new CVRRenderModels(pRenderModels);

        var renderModel = new RenderModel_t();
        if (!renderModels.LoadRenderModel(renderModelName, ref renderModel))
        {
            Debug.LogError("Failed to load render model " + renderModelName);

            if (!SteamVR.active)
                OpenVR.Shutdown();
            return null;
        }

        var vertices = new Vector3[renderModel.unVertexCount];
        var normals = new Vector3[renderModel.unVertexCount];
        var uv = new Vector2[renderModel.unVertexCount];

        var type = typeof(RenderModel_Vertex_t);
        for (int iVert = 0; iVert < renderModel.unVertexCount; iVert++)
        {
            var ptr = new System.IntPtr(renderModel.rVertexData.ToInt64() + iVert * Marshal.SizeOf(type));
            var vert = (RenderModel_Vertex_t)Marshal.PtrToStructure(ptr, type);

            vertices[iVert] = new Vector3(vert.vPosition.v[0], vert.vPosition.v[1], -vert.vPosition.v[2]);
            normals[iVert] = new Vector3(vert.vNormal.v[0], vert.vNormal.v[1], -vert.vNormal.v[2]);
            uv[iVert] = new Vector2(vert.rfTextureCoord[0], vert.rfTextureCoord[1]);
        }

        int indexCount = (int)renderModel.unTriangleCount * 3;
        var indices = new short[indexCount];
        Marshal.Copy(renderModel.rIndexData, indices, 0, indices.Length);

        var triangles = new int[indexCount];
        for (int iTri = 0; iTri < renderModel.unTriangleCount; iTri++)
        {
            triangles[iTri * 3 + 0] = (int)indices[iTri * 3 + 2];
            triangles[iTri * 3 + 1] = (int)indices[iTri * 3 + 1];
            triangles[iTri * 3 + 2] = (int)indices[iTri * 3 + 0];
        }

        var mesh = new Mesh();
        mesh.vertices = vertices;
        mesh.normals = normals;
        mesh.uv = uv;
        mesh.triangles = triangles;

        mesh.Optimize();
        //mesh.hideFlags = HideFlags.DontUnloadUnusedAsset;

        var textureMapData = new byte[renderModel.diffuseTexture.unWidth * renderModel.diffuseTexture.unHeight * 4]; // RGBA
        Marshal.Copy(renderModel.diffuseTexture.rubTextureMapData, textureMapData, 0, textureMapData.Length);

        var colors = new Color32[renderModel.diffuseTexture.unWidth * renderModel.diffuseTexture.unHeight];
        int iColor = 0;
        for (int iHeight = 0; iHeight < renderModel.diffuseTexture.unHeight; iHeight++)
        {
            for (int iWidth = 0; iWidth < renderModel.diffuseTexture.unWidth; iWidth++)
            {
                var r = textureMapData[iColor++];
                var g = textureMapData[iColor++];
                var b = textureMapData[iColor++];
                var a = textureMapData[iColor++];
                colors[iHeight * renderModel.diffuseTexture.unWidth + iWidth] = new Color32(r, g, b, a);
            }
        }

        var texture = new Texture2D(renderModel.diffuseTexture.unWidth, renderModel.diffuseTexture.unHeight, TextureFormat.ARGB32, true);
        texture.SetPixels32(colors);
        texture.Apply();

        //texture.hideFlags = HideFlags.DontUnloadUnusedAsset;

        renderModels.FreeRenderModel(ref renderModel);

        if (!SteamVR.active)
            OpenVR.Shutdown();

        return new RenderModel(mesh, texture);
    }
Esempio n. 13
0
	public abstract bool LoadRenderModel(string pchRenderModelName,ref RenderModel_t pRenderModel);
Esempio n. 14
0
	public override bool LoadRenderModel(string pchRenderModelName,ref RenderModel_t pRenderModel)
	{
		CheckIfUsable();
		bool result = VRNativeEntrypoints.VR_IVRRenderModels_LoadRenderModel(m_pVRRenderModels,pchRenderModelName,ref pRenderModel);
		return result;
	}
Esempio n. 15
0
        }         // 0x00000001801DA100-0x00000001801DA370

        // Methods
        public void Unpack(ref RenderModel_t unpacked)
        {
        }                                                         // 0x00000001801DA0D0-0x00000001801DA100
    private void SetModel(string renderModelName)
    {
        if (!models.Contains(renderModelName))
        {
            Debug.Log("Loading render model " + renderModelName);

            var vr = SteamVR.instance;
            if (vr == null)
                return;

            var renderModel = new Valve.VR.RenderModel_t();
            if (!vr.hmd.LoadRenderModel(renderModelName, ref renderModel))
            {
                Debug.LogError("Failed to load render model " + renderModelName);
                return;
            }

            var vertices = new Vector3[renderModel.unVertexCount];
            var normals = new Vector3[renderModel.unVertexCount];
            var uv = new Vector2[renderModel.unVertexCount];

            var type = typeof(Valve.VR.RenderModel_Vertex_t);
            for (int iVert = 0; iVert < renderModel.unVertexCount; iVert++)
            {
                var ptr = new System.IntPtr(renderModel.rVertexData.ToInt64() + iVert * Marshal.SizeOf(type));
                var vert = (Valve.VR.RenderModel_Vertex_t)Marshal.PtrToStructure(ptr, type);

                vertices[iVert] = new Vector3(vert.vPosition.v[0], vert.vPosition.v[1], -vert.vPosition.v[2]);
                normals[iVert] = new Vector3(vert.vNormal.v[0], vert.vNormal.v[1], -vert.vNormal.v[2]);
                uv[iVert] = new Vector2(vert.rfTextureCoord[0], vert.rfTextureCoord[1]);
            }

            int indexCount = (int)renderModel.unTriangleCount * 3;
            var indices = new short[indexCount];
            Marshal.Copy(renderModel.rIndexData, indices, 0, indices.Length);

            var triangles = new int[indexCount];
            for (int iTri = 0; iTri < renderModel.unTriangleCount; iTri++)
            {
                triangles[iTri * 3 + 0] = (int)indices[iTri * 3 + 2];
                triangles[iTri * 3 + 1] = (int)indices[iTri * 3 + 1];
                triangles[iTri * 3 + 2] = (int)indices[iTri * 3 + 0];
            }

            var mesh = new Mesh();
            mesh.vertices = vertices;
            mesh.normals = normals;
            mesh.uv = uv;
            mesh.triangles = triangles;

            var textureMapData = new byte[renderModel.diffuseTexture.unWidth * renderModel.diffuseTexture.unHeight * 4]; // RGBA
            Marshal.Copy(renderModel.diffuseTexture.rubTextureMapData, textureMapData, 0, textureMapData.Length);

            var colors = new Color32[renderModel.diffuseTexture.unWidth * renderModel.diffuseTexture.unHeight];
            int iColor = 0;
            for (int iHeight = 0; iHeight < renderModel.diffuseTexture.unHeight; iHeight++)
            {
                for (int iWidth = 0; iWidth < renderModel.diffuseTexture.unWidth; iWidth++)
                {
                    var r = textureMapData[iColor++];
                    var g = textureMapData[iColor++];
                    var b = textureMapData[iColor++];
                    var a = textureMapData[iColor++];
                    colors[iHeight * renderModel.diffuseTexture.unWidth + iWidth] = new Color32(r, g, b, a);
                }
            }

            var texture = new Texture2D(renderModel.diffuseTexture.unWidth, renderModel.diffuseTexture.unHeight, TextureFormat.ARGB32, true);
            texture.SetPixels32(colors);
            texture.Apply();

            models[renderModelName] = new RenderModel(mesh, texture);

            vr.hmd.FreeRenderModel(ref renderModel);
        }

        var model = models[renderModelName] as RenderModel;
        GetComponent<MeshFilter>().mesh = model.mesh;
        GetComponent<MeshRenderer>().material = model.material;
    }