Example #1
0
    public static ulong GetOutputDevice(this CVRSystem system, ETextureType textureType, IntPtr pInstance)
    {
        ulong pnDevice = 0;

        system.GetOutputDevice(ref pnDevice, textureType, pInstance);
        return(pnDevice);
    }
Example #2
0
        public void InitEyeTextures(int resolutionWidth, int resolutionHeight)
        {
            ETextureType textureType = ETextureType.DirectX;

            switch (SystemInfo.graphicsDeviceType)
            {
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore:
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2:
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3:
            case UnityEngine.Rendering.GraphicsDeviceType.Direct3D9:
                throw new InvalidOperationException(SystemInfo.graphicsDeviceType.ToString() + " does not support VR. You must use -force-d3d12");

            case UnityEngine.Rendering.GraphicsDeviceType.Direct3D11:
            case UnityEngine.Rendering.GraphicsDeviceType.Direct3D12:
                textureType = ETextureType.DirectX;
                break;

            default:
                throw new InvalidOperationException(SystemInfo.graphicsDeviceType.ToString() + " not supported");
            }

            RightEyeRenderTexture = new RenderTexture(resolutionWidth, resolutionHeight, 24, RenderTextureFormat.ARGB32);
            RightEyeRenderTexture.Create();
            RightEyeTexture.handle      = RightEyeRenderTexture.GetNativeTexturePtr();
            RightEyeTexture.eColorSpace = EColorSpace.Auto;
            RightEyeTexture.eType       = textureType;

            LeftEyeRenderTexture = new RenderTexture(resolutionWidth, resolutionHeight, 24, RenderTextureFormat.ARGB32);
            LeftEyeRenderTexture.Create();
            LeftEyeTexture.handle      = LeftEyeRenderTexture.GetNativeTexturePtr();
            LeftEyeTexture.eColorSpace = EColorSpace.Auto;
            LeftEyeTexture.eType       = textureType;
        }
    public bool Setup()
    {
        if (openVRInit)
        {
            return(true);
        }

        if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL"))
        {
            textureType = ETextureType.OpenGL;
        }
        else
        {
            textureType = ETextureType.DirectX;
        }

        pose_handler = new OpenVR_Pose_Handler();

        if (!(openVRInit = OpenVR_Setup()))
        {
            SafeDispose();
            return(false);
        }
        else
        {
            return(true);
        }
    }
Example #4
0
    private SteamVR()
    {
        hmd = OpenVR.System;
        MSCLoader.ModConsole.Print("Connected to " + hmd_TrackingSystemName + ":" + hmd_SerialNumber);

        compositor = OpenVR.Compositor;
        overlay    = OpenVR.Overlay;

        // Setup render values
        uint w = 0, h = 0;

        hmd.GetRecommendedRenderTargetSize(ref w, ref h);
        sceneWidth  = (float)w;
        sceneHeight = (float)h;

        float l_left = 0.0f, l_right = 0.0f, l_top = 0.0f, l_bottom = 0.0f;

        hmd.GetProjectionRaw(EVREye.Eye_Left, ref l_left, ref l_right, ref l_top, ref l_bottom);

        float r_left = 0.0f, r_right = 0.0f, r_top = 0.0f, r_bottom = 0.0f;

        hmd.GetProjectionRaw(EVREye.Eye_Right, ref r_left, ref r_right, ref r_top, ref r_bottom);

        tanHalfFov = new Vector2(
            Mathf.Max(-l_left, l_right, -r_left, r_right),
            Mathf.Max(-l_top, l_bottom, -r_top, r_bottom));

        textureBounds = new VRTextureBounds_t[2];

        textureBounds[0].uMin = 0.5f + 0.5f * l_left / tanHalfFov.x;
        textureBounds[0].uMax = 0.5f + 0.5f * l_right / tanHalfFov.x;
        textureBounds[0].vMin = 0.5f - 0.5f * l_bottom / tanHalfFov.y;
        textureBounds[0].vMax = 0.5f - 0.5f * l_top / tanHalfFov.y;

        textureBounds[1].uMin = 0.5f + 0.5f * r_left / tanHalfFov.x;
        textureBounds[1].uMax = 0.5f + 0.5f * r_right / tanHalfFov.x;
        textureBounds[1].vMin = 0.5f - 0.5f * r_bottom / tanHalfFov.y;
        textureBounds[1].vMax = 0.5f - 0.5f * r_top / tanHalfFov.y;

        // Grow the recommended size to account for the overlapping fov
        sceneWidth  = sceneWidth / Mathf.Max(textureBounds[0].uMax - textureBounds[0].uMin, textureBounds[1].uMax - textureBounds[1].uMin);
        sceneHeight = sceneHeight / Mathf.Max(textureBounds[0].vMax - textureBounds[0].vMin, textureBounds[1].vMax - textureBounds[1].vMin);

        aspect      = tanHalfFov.x / tanHalfFov.y;
        fieldOfView = 2.0f * Mathf.Atan(tanHalfFov.y) * Mathf.Rad2Deg;

        eyes = new SteamVR_Utils.RigidTransform[] {
            new SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Left)),
            new SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Right))
        };

        textureType = ETextureType.DirectX;

        SteamVR_Events.Initializing.Listen(OnInitializing);
        SteamVR_Events.Calibrating.Listen(OnCalibrating);
        SteamVR_Events.OutOfRange.Listen(OnOutOfRange);
        SteamVR_Events.DeviceConnected.Listen(OnDeviceConnected);
        SteamVR_Events.NewPoses.Listen(OnNewPoses);
    }
Example #5
0
        }         //_UpdateMaterialPictureBox()

        private void radioButtonDiffuseTexture_CheckedChanged(object sender, EventArgs e)
        {
            if (m_eCurrentTextureType != ETextureType.DIFFUSE)
            {
                m_eCurrentTextureType = ETextureType.DIFFUSE;
                _UpdateWhenTextureTypeChanged();
            }//if
        }
Example #6
0
 private void radioButtonReflectionTexture_CheckedChanged(object sender, EventArgs e)
 {
     if (m_eCurrentTextureType != ETextureType.GLOSSINESS)
     {
         m_eCurrentTextureType = ETextureType.GLOSSINESS;
         _UpdateWhenTextureTypeChanged();
     }//if
 }
Example #7
0
 private void radioButtonSpecularTexture_CheckedChanged(object sender, EventArgs e)
 {
     if (m_eCurrentTextureType != ETextureType.SPECULAR)
     {
         m_eCurrentTextureType = ETextureType.SPECULAR;
         _UpdateWhenTextureTypeChanged();
     }//if
 }
Example #8
0
 private void radioButtonBumpTexture_CheckedChanged(object sender, EventArgs e)
 {
     if (m_eCurrentTextureType != ETextureType.BUMP)
     {
         m_eCurrentTextureType = ETextureType.BUMP;
         _UpdateWhenTextureTypeChanged();
     }//if
 }
Example #9
0
 public MDXTexture(byte[] data)
 {
     using (MemoryStream ms = new MemoryStream(data))
     {
         using (BinaryReader br = new BinaryReader(ms))
         {
             this.TextureType    = (ETextureType)br.ReadUInt32();
             this.Flags          = (ETextureFlags)br.ReadUInt32();
             this.FilenameLength = br.ReadUInt32();
             this.FilenameOffset = br.ReadUInt32();
         }
     }
 }
Example #10
0
        //Create a list of all the different textures
        static List <string> Index(ETextureType type, List <string> allFiles)
        {
            string typeName = type.ToString();

            string[] fileNames = Directory.GetFiles(typeName);
            foreach (string file in fileNames)
            {
                string fn = CleanName(file).Replace(typeName, "");
                if (!allFiles.Contains(fn))
                {
                    allFiles.Add(fn);
                }
            }
            return(allFiles);
        }
Example #11
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        // function members
        //
        public FormAtlasMain()
        {
            InitializeComponent();

            m_alistMaterials         = null;// new ArrayList();
            m_strOdmFileName         = "";
            m_eCurrentTextureType    = ETextureType.DIFFUSE;
            m_iSelectedMaterialIndex = -1;

            m_iSelectedAtlasTextureIndex = -1;
            m_textureAtlasInfo           = null;
            m_eIsTextureLocatingMode     = ETextureLocatingMode.NONE;
            //m_pntPickMouseOffset;
            m_fAtlasZoomRatio   = 1.0f;
            m_pntAtlasLeftTop.X = 0;
            m_pntAtlasLeftTop.Y = 0;
        }//FormAtlasMain
Example #12
0
        }//KStdMaterialInfo()

        public string GetTextureFileName(ETextureType eTextureType_)
        {
            switch (eTextureType_)
            {
            case ETextureType.DIFFUSE:
                return(m_strDiffuseTextureName);

            case ETextureType.BUMP:
                return(m_strBumpTextureName);

            case ETextureType.SPECULAR:
                return(m_strSpecularTextureName);

            case ETextureType.GLOSSINESS:
                return(m_strGlossinessTextureName);
            }//switch

            return("");
        } //GetTextureFileName()
Example #13
0
        }//_FindStdMaterialInfo()

        private bool _IsTextureTypeExistInMaterialList(ETextureType eTextureType_)
        {
            foreach (KStdMaterialInfo stdMtrlInfo in m_alistMaterials)
            {
                switch (eTextureType_)
                {
                case ETextureType.DIFFUSE:
                    if (stdMtrlInfo.m_strDiffuseTextureName.Length >= 1)
                    {
                        return(true);
                    }    //if
                    break;

                case ETextureType.BUMP:
                    if (stdMtrlInfo.m_strBumpTextureName.Length >= 1)
                    {
                        return(true);
                    }    //if
                    break;

                case ETextureType.SPECULAR:
                    if (stdMtrlInfo.m_strSpecularTextureName.Length >= 1)
                    {
                        return(true);
                    }    //if
                    break;

                case ETextureType.GLOSSINESS:
                    if (stdMtrlInfo.m_strGlossinessTextureName.Length >= 1)
                    {
                        return(true);
                    }    //if
                    break;
                }//switch
            }//foreach

            return(false);
        }//_IsTextureTypeExistInMaterialList()
Example #14
0
        private SteamVR()
        {
            hmd = OpenVR.System;
            Debug.Log("<b>[SteamVR]</b> Initialized. Connected to " + hmd_TrackingSystemName + ":" + hmd_SerialNumber);

            compositor = OpenVR.Compositor;
            overlay    = OpenVR.Overlay;

            // Setup render values
            uint w = 0, h = 0;

            hmd.GetRecommendedRenderTargetSize(ref w, ref h);
            sceneWidth  = (float)w;
            sceneHeight = (float)h;

            float l_left = 0.0f, l_right = 0.0f, l_top = 0.0f, l_bottom = 0.0f;

            hmd.GetProjectionRaw(EVREye.Eye_Left, ref l_left, ref l_right, ref l_top, ref l_bottom);

            float r_left = 0.0f, r_right = 0.0f, r_top = 0.0f, r_bottom = 0.0f;

            hmd.GetProjectionRaw(EVREye.Eye_Right, ref r_left, ref r_right, ref r_top, ref r_bottom);

            tanHalfFov = new Vector2(
                Mathf.Max(-l_left, l_right, -r_left, r_right),
                Mathf.Max(-l_top, l_bottom, -r_top, r_bottom));

            textureBounds = new VRTextureBounds_t[2];

            textureBounds[0].uMin = 0.5f + 0.5f * l_left / tanHalfFov.x;
            textureBounds[0].uMax = 0.5f + 0.5f * l_right / tanHalfFov.x;
            textureBounds[0].vMin = 0.5f - 0.5f * l_bottom / tanHalfFov.y;
            textureBounds[0].vMax = 0.5f - 0.5f * l_top / tanHalfFov.y;

            textureBounds[1].uMin = 0.5f + 0.5f * r_left / tanHalfFov.x;
            textureBounds[1].uMax = 0.5f + 0.5f * r_right / tanHalfFov.x;
            textureBounds[1].vMin = 0.5f - 0.5f * r_bottom / tanHalfFov.y;
            textureBounds[1].vMax = 0.5f - 0.5f * r_top / tanHalfFov.y;

            // Grow the recommended size to account for the overlapping fov
            sceneWidth  = sceneWidth / Mathf.Max(textureBounds[0].uMax - textureBounds[0].uMin, textureBounds[1].uMax - textureBounds[1].uMin);
            sceneHeight = sceneHeight / Mathf.Max(textureBounds[0].vMax - textureBounds[0].vMin, textureBounds[1].vMax - textureBounds[1].vMin);

            aspect      = tanHalfFov.x / tanHalfFov.y;
            fieldOfView = 2.0f * Mathf.Atan(tanHalfFov.y) * Mathf.Rad2Deg;

            eyes = new SteamVR_Utils.RigidTransform[] {
                new SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Left)),
                new SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Right))
            };

            switch (SystemInfo.graphicsDeviceType)
            {
#if (UNITY_5_4)
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGL2:
#endif
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore:
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2:
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3:
                textureType = ETextureType.OpenGL;
                break;

#if !(UNITY_5_4)
            case UnityEngine.Rendering.GraphicsDeviceType.Vulkan:
                textureType = ETextureType.Vulkan;
                break;
#endif
            default:
                textureType = ETextureType.DirectX;
                break;
            }

            SteamVR_Events.Initializing.Listen(OnInitializing);
            SteamVR_Events.Calibrating.Listen(OnCalibrating);
            SteamVR_Events.OutOfRange.Listen(OnOutOfRange);
            SteamVR_Events.DeviceConnected.Listen(OnDeviceConnected);
            SteamVR_Events.NewPoses.Listen(OnNewPoses);
        }
        private void GenerateTextureWithAlpha(string sourceTexturePath, string sourceAlphaMaskPath, ETextureType textureType)
        {
            string finalFileSuffix = null;

            switch (textureType)
            {
                case ETextureType.NORMALS:
                    finalFileSuffix = "_ddna.tif";
                    break;

                case ETextureType.GLOSS:
                    finalFileSuffix = "_ddna.tif";
                    break;

                case ETextureType.HEIGHT:
                    finalFileSuffix = "_displ.tif";
                    break;
            }

            var finalFilePath = m_cibleDirectory + @"\" + m_projectName + finalFileSuffix;

            while (!File.Exists(sourceTexturePath)) ;    //Wait until the source file is recreated
            while (!File.Exists(sourceAlphaMaskPath)) ;    //Wait until the source file is recreated

            //Begin image process thread
            AlphaMaskThread threadHandle = new AlphaMaskThread(sourceTexturePath, sourceAlphaMaskPath, finalFilePath);

            Thread alphaMaskThread = new Thread(new ThreadStart(threadHandle.ProceedImage));
            alphaMaskThread.Start();

            alphaMaskThread.Join();
            alphaMaskThread.Abort();

            new CTextureTiffConvert(finalFilePath, true);

            if (m_isForCrossAppMode)
                Framework.FocusProcess("Editor");

            //File.Delete(finalFilePath);
        }
Example #16
0
 public ETextureType SetDashboardIconType(ETextureType textureType)
 {
     return(dashboardIconStruct.eType = textureType);
 }
            m_alistTextureInfo;             // <KTextureInfo>

        public KTextureAtlasInfo()
        {
            m_eTextureType = ETextureType.DIFFUSE;
            m_iAtlasWidth  = 0;
            m_iAtlasHeight = 0;
        }//KTextureAtlasInfo()
Example #18
0
 public Texture(string relativePath, ETextureType textureType = ETextureType.baseTex)
 {
     this._relativePath = relativePath;
     this._textureType  = textureType;
 }
Example #19
0
 // Token: 0x06001EDE RID: 7902 RVA: 0x0009C92B File Offset: 0x0009AB2B
 public void GetOutputDevice(ref ulong pnDevice, ETextureType textureType)
 {
     pnDevice = 0UL;
     this.FnTable.GetOutputDevice(ref pnDevice, textureType);
 }
Example #20
0
        }//LoadDsuMaterialInfo()

        public static void LoadMaterialTextures(ref ArrayList alistMaterials_, ETextureType eTextureType_, string strAlternativePath_, bool bLoadTexture_)
        {
            for (int iMtrl = 0; iMtrl < alistMaterials_.Count; ++iMtrl)
            {
                KStdMaterialInfo stdMtrl = new KStdMaterialInfo();
                stdMtrl = ( KStdMaterialInfo )alistMaterials_[iMtrl];
                //KStdMaterialInfo stdMtrl = ( KStdMaterialInfo )alistMaterials_[iMtrl];
                string strTextureFileName = "";
                bool   bIsFileExist       = false;
                switch (eTextureType_)
                {
                case ETextureType.DIFFUSE:
                    strTextureFileName = stdMtrl.m_strDiffuseTextureName;
                    break;

                case ETextureType.BUMP:
                    strTextureFileName = stdMtrl.m_strBumpTextureName;
                    break;

                case ETextureType.SPECULAR:
                    strTextureFileName = stdMtrl.m_strSpecularTextureName;
                    break;

                case ETextureType.GLOSSINESS:
                    strTextureFileName = stdMtrl.m_strGlossinessTextureName;
                    break;
                }//switch

                // check file existence in original path.
                if (System.IO.File.Exists(strTextureFileName) == false)
                {
                    // when texture file is not exist in original path
                    // try to load alternative path which is program was executed.
                    // - jintaeks on 2013-11-04, 21:09
                    string strFileName = Path.GetFileName(strTextureFileName);
                    string strFilePath = strAlternativePath_ + "\\" + strFileName;
                    if (System.IO.File.Exists(strFilePath) == true)
                    {
                        strTextureFileName = strFilePath;
                        switch (eTextureType_)
                        {
                        case ETextureType.DIFFUSE:
                            stdMtrl.m_strDiffuseTextureName = strTextureFileName;
                            break;

                        case ETextureType.BUMP:
                            stdMtrl.m_strBumpTextureName = strTextureFileName;
                            break;

                        case ETextureType.SPECULAR:
                            stdMtrl.m_strSpecularTextureName = strTextureFileName;
                            break;

                        case ETextureType.GLOSSINESS:
                            stdMtrl.m_strGlossinessTextureName = strTextureFileName;
                            break;
                        } //switch
                        bIsFileExist = true;
                    }     //if
                }
                else
                {
                    bIsFileExist = true;
                }//if.. else..

                if (bIsFileExist == true && bLoadTexture_ == true)
                {
                    // test original Image control. jintaeks on 2013-11-04, 20:28
                    //strTextureFileName = @"F:\techsupport\source\DsuAtlasMaxPlugin\Build001_Test01_Dif01.jpg"; // test
                    //stdMtrl.m_image = Image.FromFile( strTextureFileName );

                    FIBITMAP fiBitmap = FreeImage.LoadEx(strTextureFileName);
                    //FreeImage.SetTransparent( fiBitmap, false );
                    //stdMtrl.m_image = FreeImage.GetBitmap( fiBitmap );
                    Image img = FreeImage.GetBitmap(fiBitmap);
                    //img = Utility.SetImageOpacity( img, 1 );
                    stdMtrl.m_image = img;
                }
                else
                {
                    stdMtrl.m_image = null;
                }//if.. else..

                // update material info. jintaeks on 2013-11-04, 21:09
                alistMaterials_[iMtrl] = stdMtrl;
            } //foreach
        }     //LoadMaterialTextures()
Example #21
0
    private SteamVR()
    {
        hmd = OpenVR.System;
        Debug.Log("Connected to " + hmd_TrackingSystemName + ":" + hmd_SerialNumber);

        compositor = OpenVR.Compositor;
        overlay    = OpenVR.Overlay;

        // Setup render values
        uint w = 0, h = 0;

        hmd.GetRecommendedRenderTargetSize(ref w, ref h);
        sceneWidth  = (float)w;
        sceneHeight = (float)h;

        float l_left = 0.0f, l_right = 0.0f, l_top = 0.0f, l_bottom = 0.0f;

        hmd.GetProjectionRaw(EVREye.Eye_Left, ref l_left, ref l_right, ref l_top, ref l_bottom);

        float r_left = 0.0f, r_right = 0.0f, r_top = 0.0f, r_bottom = 0.0f;

        hmd.GetProjectionRaw(EVREye.Eye_Right, ref r_left, ref r_right, ref r_top, ref r_bottom);

        tanHalfFov = new Vector2(
            Mathf.Max(-l_left, l_right, -r_left, r_right),
            Mathf.Max(-l_top, l_bottom, -r_top, r_bottom));

        textureBounds = new VRTextureBounds_t[2];

        textureBounds[0].uMin = 0.5f + 0.5f * l_left / tanHalfFov.x;
        textureBounds[0].uMax = 0.5f + 0.5f * l_right / tanHalfFov.x;
        textureBounds[0].vMin = 0.5f - 0.5f * l_bottom / tanHalfFov.y;
        textureBounds[0].vMax = 0.5f - 0.5f * l_top / tanHalfFov.y;

        textureBounds[1].uMin = 0.5f + 0.5f * r_left / tanHalfFov.x;
        textureBounds[1].uMax = 0.5f + 0.5f * r_right / tanHalfFov.x;
        textureBounds[1].vMin = 0.5f - 0.5f * r_bottom / tanHalfFov.y;
        textureBounds[1].vMax = 0.5f - 0.5f * r_top / tanHalfFov.y;

#if (UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
        SteamVR.Unity.SetSubmitParams(textureBounds[0], textureBounds[1], EVRSubmitFlags.Submit_Default);
#endif
        // Grow the recommended size to account for the overlapping fov
        sceneWidth  = sceneWidth / Mathf.Max(textureBounds[0].uMax - textureBounds[0].uMin, textureBounds[1].uMax - textureBounds[1].uMin);
        sceneHeight = sceneHeight / Mathf.Max(textureBounds[0].vMax - textureBounds[0].vMin, textureBounds[1].vMax - textureBounds[1].vMin);

        aspect      = tanHalfFov.x / tanHalfFov.y;
        fieldOfView = 2.0f * Mathf.Atan(tanHalfFov.y) * Mathf.Rad2Deg;

        eyes = new SteamVR_Utils.RigidTransform[] {
            new SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Left)),
            new SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Right))
        };

        if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL"))
        {
            textureType = ETextureType.OpenGL;
        }
        else
        {
            textureType = ETextureType.DirectX;
        }

        SteamVR_Events.Initializing.Listen(OnInitializing);
        SteamVR_Events.Calibrating.Listen(OnCalibrating);
        SteamVR_Events.OutOfRange.Listen(OnOutOfRange);
        SteamVR_Events.DeviceConnected.Listen(OnDeviceConnected);
        SteamVR_Events.NewPoses.Listen(OnNewPoses);
    }
Example #22
0
        /// <summary>
        /// Creates the overlay if it is not already created, and applies the current state values, (not the target values), such as <see cref="width"/> and <see cref="opacity"/>
        /// </summary>
        /// <param name="key">The key of the overlay</param>
        /// <returns>Returns true if the overlay is created or already existing</returns>
        public bool CreateAndApplyOverlay(string key = "")
        {
            if (CheckValid())
            {
                return(true);
            }

            if (OpenVR.Overlay == null)
            {
                if (!hasFailedOnce)
                {
                    hasFailedOnce = true;
                    Debug.LogError("OpenVR.Overlay is null! :(");
                }

                return(false);
            }

            //If the supplied key is empty and the overlay had a key in the past, reuse that same key.
            if (!String.IsNullOrEmpty(overlayKey) && key == "")
            {
                key = overlayKey;
            }
            overlayKey   = key;
            _overlayName = key;

            error = OpenVR.Overlay.CreateOverlay(overlayKey, _overlayName, ref handle);

            if (ErrorCheck(error))
            {
                return(false);
            }


            _overlayTextureType = graphicsType;
            //_overlayTextureType = ETextureType.DirectX;

            //_overlayTextureType = ETextureType.DirectX;
            InitOverlayTexture(_overlayTextureType, EColorSpace.Auto);


            //Apply the overlay properties, not the target values

            //OpenVR.Overlay.SetOverlayInputMethod(handle, VROverlayInputMethod.Mouse);
            //OpenVR.Overlay.SetOverlayFlag(handle, VROverlayFlags.ShowTouchPadScrollWheel, true);
            //OpenVR.Overlay.SetOverlayFlag(handle, VROverlayFlags.SendVRSmoothScrollEvents, true);


            //SetTrackedDeviceRelativeIndex(trackedDevice);
            shouldUpdateTrackedDevice?.Invoke();


            SetSBS(useSBS, sbsCrossedMode);

            SetTransform(pos, rot, false);

            SetWidthInMeters(width, false);

            SetSortOrder(sortOrder);

            SetOpacity(opacity, false);

            SetCurvature(curvature, false);

            SetMouseScale(overlayMouseScale);

            SetTexture(_currentTexture);

            SetTextureBounds(textureBounds);

            onCreated?.Invoke();

            return(true);
        }
Example #23
0
        }//GetRecommendedAtlasWidthHeight()

        public static bool CreateTextureAtlasInfo(ref KTextureAtlasInfo textureAtlasInfo_, ETextureType eTextureType_, ArrayList alistStdMtrlInfo_)
        {
            // create new texture atlas info.
            //
            textureAtlasInfo_ = new KTextureAtlasInfo();
            textureAtlasInfo_.m_alistTextureInfo = new ArrayList();

            int iTotalWidth  = 0;
            int iTotalHeight = 0;

            // set atlas texture info.
            //
            foreach (KStdMaterialInfo stdMtrlInfo in alistStdMtrlInfo_)
            {
                KTextureInfo textrInfo;
                {
                    textrInfo.m_strMtrlName        = "";
                    textrInfo.m_strTextureFileName = "";
                    textrInfo.m_iLeft        = 0;
                    textrInfo.m_iTop         = 0;
                    textrInfo.m_iWidth       = 0;
                    textrInfo.m_iHeight      = 0;
                    textrInfo.m_image        = null;
                    textrInfo.m_bIsRotateCcw = false;
                }//block

                textrInfo.m_strMtrlName        = stdMtrlInfo.m_strMaterialName;
                textrInfo.m_strTextureFileName = stdMtrlInfo.GetTextureFileName(eTextureType_);
                Debug.Assert(stdMtrlInfo.m_image != null);
                //if( stdMtrlInfo.m_image == null )
                //{
                //    //return false;
                //    continue;
                //}//if

                textrInfo.m_image = stdMtrlInfo.m_image;
                if (stdMtrlInfo.m_image != null)
                {
                    textrInfo.m_iWidth  = stdMtrlInfo.m_image.Width;
                    textrInfo.m_iHeight = stdMtrlInfo.m_image.Height;
                    textrInfo.m_iLeft   = 0;
                    textrInfo.m_iTop    = 0;

                    iTotalWidth  += textrInfo.m_iWidth;
                    iTotalHeight += textrInfo.m_iHeight;
                }//if

                textureAtlasInfo_.m_alistTextureInfo.Add(textrInfo);
            }//foreach

            // set texture type, atlas width, and atlas height.
            //
            textureAtlasInfo_.m_eTextureType = eTextureType_;
            GetRecommendedAtlasWidthHeight(ref textureAtlasInfo_.m_iAtlasWidth, ref textureAtlasInfo_.m_iAtlasHeight
                                           , iTotalWidth / 2, iTotalHeight / 2);

            textureAtlasInfo_.AutoAdjustTexturePosition();

            return(true);
        }//CreateTextureAtlasInfo()
Example #24
0
 public void InitOverlayTexture(ETextureType texType, EColorSpace colorSpace = EColorSpace.Auto)
 {
     //TODO: Try different texture types to improve perf
     _overlayTexture_t.eType       = texType;
     _overlayTexture_t.eColorSpace = colorSpace;
 }
Example #25
0
 public ETextureType SetTextureType(ETextureType textureType)
 {
     return(textureStruct.eType = textureType);
 }
Example #26
0
        /// <summary>
        /// Initialize HMD using OpenVR API calls.
        /// </summary>
        /// <returns>True on success, false otherwise. Errors logged.</returns>
        private bool InitHMD()
        {
            bool retVal = false;

            // return if HMD has already been initialized
            if (hmdIsInitialized)
            {
                return(true);
            }

            // set the location of the OpenVR DLL
            SetDllDirectory(Globals.OpenVRDllPath);

            // check if HMD is connected on the system
            retVal = OpenVR.IsHmdPresent();
            if (!retVal)
            {
                Utils.LogError("HMD not found on this system.");
                return(retVal);
            }

            // check if SteamVR runtime is installed
            retVal = OpenVR.IsRuntimeInstalled();
            if (!retVal)
            {
                Utils.LogError("SteamVR runtime not found on this system.");
                return(retVal);
            }

            // initialize HMD
            EVRInitError hmdInitErrorCode = EVRInitError.None;

            OpenVR.Init(ref hmdInitErrorCode, EVRApplicationType.VRApplication_Scene);
            retVal = (hmdInitErrorCode == EVRInitError.None);
            if (!retVal)
            {
                Utils.LogError("Failed to initialize HMD. Init returned: " + OpenVR.GetStringForHmdError(hmdInitErrorCode));
                return(retVal);
            }

            // reset "seated position" and capture initial position. this means you should hold the HMD in
            // the position you would like to consider "seated", before running this code.
            ResetInitialHmdPosition();

            // get HMD render target size
            uint renderTextureWidth  = 0;
            uint renderTextureHeight = 0;

            OpenVR.System.GetRecommendedRenderTargetSize(ref renderTextureWidth, ref renderTextureHeight);

            // at the moment, only Direct3D12 is working with Kerbal Space Program
            ETextureType textureType = ETextureType.DirectX;

            switch (SystemInfo.graphicsDeviceType)
            {
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore:
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2:
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3:
                textureType = ETextureType.OpenGL;
                break;     // doesn't work

            case UnityEngine.Rendering.GraphicsDeviceType.Direct3D9:
            case UnityEngine.Rendering.GraphicsDeviceType.Direct3D11:
                textureType = ETextureType.DirectX;
                break;     // doesn't work

            case UnityEngine.Rendering.GraphicsDeviceType.Direct3D12:
                textureType = ETextureType.DirectX;     // do not use DirectX12
                break;

            default:
                throw (new Exception(SystemInfo.graphicsDeviceType.ToString() + " not supported"));
            }

            openvrTexture             = new Texture_t();
            openvrTexture.eType       = textureType;
            openvrTexture.eColorSpace = EColorSpace.Auto;

            Debug.Log("Graphics Type: " + SystemInfo.graphicsDeviceType);

            // initialize render textures (for displaying on HMD)

            rightEyeRenderTextures[0] = new Texture2D((int)(renderTextureWidth * 1.5), (int)(renderTextureHeight * 1.5), TextureFormat.ARGB32, false);
            leftEyeRenderTextures[0]  = new Texture2D((int)(renderTextureWidth * 1.5), (int)(renderTextureHeight * 1.5), TextureFormat.ARGB32, false);
            renderTextures[0]         = new RenderTexture((int)(renderTextureWidth * 1.5), (int)(renderTextureHeight * 1.5), 24, RenderTextureFormat.ARGB32);

            rightEyeRenderTextures[1] = new Texture2D((int)(renderTextureWidth), (int)(renderTextureHeight), TextureFormat.ARGB32, false);
            leftEyeRenderTextures[1]  = new Texture2D((int)(renderTextureWidth), (int)(renderTextureHeight), TextureFormat.ARGB32, false);
            renderTextures[1]         = new RenderTexture((int)(renderTextureWidth), (int)(renderTextureHeight), 24, RenderTextureFormat.ARGB32);

            rightEyeRenderTextures[2] = new Texture2D((int)(renderTextureWidth * .75), (int)(renderTextureHeight * .75), TextureFormat.ARGB32, false);
            leftEyeRenderTextures[2]  = new Texture2D((int)(renderTextureWidth * .75), (int)(renderTextureHeight * .75), TextureFormat.ARGB32, false);
            renderTextures[2]         = new RenderTexture((int)(renderTextureWidth * .75), (int)(renderTextureHeight * .75), 24, RenderTextureFormat.ARGB32);

            rightEyeRenderTextures[3] = new Texture2D((int)(renderTextureWidth * .5), (int)(renderTextureHeight * .5), TextureFormat.ARGB32, false);
            leftEyeRenderTextures[3]  = new Texture2D((int)(renderTextureWidth * .5), (int)(renderTextureHeight * .5), TextureFormat.ARGB32, false);
            renderTextures[3]         = new RenderTexture((int)(renderTextureWidth * .5), (int)(renderTextureHeight * .5), 24, RenderTextureFormat.ARGB32);

            rightEyeRenderTextures[4] = new Texture2D((int)(renderTextureWidth * .25), (int)(renderTextureHeight * .25), TextureFormat.ARGB32, false);
            leftEyeRenderTextures[4]  = new Texture2D((int)(renderTextureWidth * .25), (int)(renderTextureHeight * .25), TextureFormat.ARGB32, false);
            renderTextures[4]         = new RenderTexture((int)(renderTextureWidth * .25), (int)(renderTextureHeight * .25), 24, RenderTextureFormat.ARGB32);

            // set rendering bounds on texture to render
            hmdTextureBounds.uMin = 0.0f;
            hmdTextureBounds.uMax = 1.0f;
            hmdTextureBounds.vMin = 1.0f; // flip the vertical coordinate for some reason
            hmdTextureBounds.vMax = 0.0f;


            hmdIsInitialized = true;

            return(retVal);
        }
        private void GenerateBitmapTexture(string sourceTexturePath, ETextureType textureType)
        {
            string finalFileSuffix = null;

            switch (textureType)
            {
                case ETextureType.DIFFUSE:
                    finalFileSuffix = "_diff.jpg";
                    break;

                case ETextureType.SPECULAR:
                    finalFileSuffix = "_spec.jpg";
                    break;
            }

            var finalFilePath = m_cibleDirectory + @"\" + m_projectName + finalFileSuffix;

            if (File.Exists(finalFilePath))
                File.Delete(finalFilePath);

            while (!File.Exists(sourceTexturePath));    //Wait until the source file is recreated
            File.Copy(sourceTexturePath, finalFilePath);

            new CTextureTiffConvert(finalFilePath, true);

            if (m_isForCrossAppMode)
                Framework.FocusProcess("Editor");

            File.Delete(finalFilePath);
        }
Example #28
0
 public MDXTexture(byte[] data)
 {
     using (MemoryStream ms = new MemoryStream(data))
     {
         using (BinaryReader br = new BinaryReader(ms))
         {
             this.TextureType = (ETextureType)br.ReadUInt32();
             this.Flags = (ETextureFlags)br.ReadUInt32();
             this.FilenameLength = br.ReadUInt32();
             this.FilenameOffset = br.ReadUInt32();
         }
     }
 }
Example #29
0
 public EVROverlayError SetOverlayFromFile(ulong ulOverlayHandle, string pchFilePath) => default;                                                                                                                                                                                                // 0x00000001811DEC50-0x00000001811DEC80
 public EVROverlayError GetOverlayTexture(ulong ulOverlayHandle, ref IntPtr pNativeTextureHandle, IntPtr pNativeTextureRef, ref uint pWidth, ref uint pHeight, ref uint pNativeFormat, ref ETextureType pAPIType, ref EColorSpace pColorSpace, ref VRTextureBounds_t pTextureBounds) => default; // 0x00000001811DE590-0x00000001811DE5E0
Example #30
0
        }                                                                // 0x00000001811E0550-0x00000001811E0580

        public void GetOutputDevice(ref ulong pnDevice, ETextureType textureType)
        {
        }                                                                      // 0x00000001811E0790-0x00000001811E07C0
Example #31
0
        /// <summary>
        /// Initialize HMD using OpenVR API calls.
        /// </summary>
        /// <returns>True on successful initialization, false otherwise.</returns>
        private static void InitializeOpenVR()
        {
            // return if HMD has already been initialized
            if (hmdState == HmdState.Initialized)
            {
                return;
            }

            // set the location of the OpenVR DLL
            SetDllDirectory(Globals.OpenVRDllPath);

            // check if HMD is connected on the system
            if (!OpenVR.IsHmdPresent())
            {
                throw new InvalidOperationException("HMD not found on this system");
            }

            // check if SteamVR runtime is installed
            if (!OpenVR.IsRuntimeInstalled())
            {
                throw new InvalidOperationException("SteamVR runtime not found on this system");
            }

            // initialize HMD
            EVRInitError hmdInitErrorCode = EVRInitError.None;

            OpenVR.Init(ref hmdInitErrorCode, EVRApplicationType.VRApplication_Scene);
            if (hmdInitErrorCode != EVRInitError.None)
            {
                throw new Exception("OpenVR error: " + OpenVR.GetStringForHmdError(hmdInitErrorCode));
            }

            // reset "seated position" and capture initial position. this means you should hold the HMD in
            // the position you would like to consider "seated", before running this code.
            ResetInitialHmdPosition();

            // get HMD render target size
            uint renderTextureWidth  = 0;
            uint renderTextureHeight = 0;

            OpenVR.System.GetRecommendedRenderTargetSize(ref renderTextureWidth, ref renderTextureHeight);

            // at the moment, only Direct3D12 is working with Kerbal Space Program
            ETextureType textureType = ETextureType.DirectX;

            switch (SystemInfo.graphicsDeviceType)
            {
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore:
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2:
            case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3:
                textureType = ETextureType.OpenGL;
                throw new InvalidOperationException(SystemInfo.graphicsDeviceType.ToString() + " does not support VR. You must use -force-d3d12");

            case UnityEngine.Rendering.GraphicsDeviceType.Direct3D9:
                throw new InvalidOperationException(SystemInfo.graphicsDeviceType.ToString() + " does not support VR. You must use -force-d3d12");

            case UnityEngine.Rendering.GraphicsDeviceType.Direct3D11:
                textureType = ETextureType.DirectX;
                break;

            case UnityEngine.Rendering.GraphicsDeviceType.Direct3D12:
                textureType = ETextureType.DirectX;
                break;

            default:
                throw new InvalidOperationException(SystemInfo.graphicsDeviceType.ToString() + " not supported");
            }

            // initialize render textures (for displaying on HMD)
            for (int i = 0; i < 2; i++)
            {
                hmdEyeRenderTexture[i] = new RenderTexture((int)renderTextureWidth, (int)renderTextureHeight, 24, RenderTextureFormat.ARGB32);
                hmdEyeRenderTexture[i].Create();
                hmdEyeTexture[i].handle      = hmdEyeRenderTexture[i].GetNativeTexturePtr();
                hmdEyeTexture[i].eColorSpace = EColorSpace.Auto;
                hmdEyeTexture[i].eType       = textureType;
            }

            // set rendering bounds on texture to render
            hmdTextureBounds.uMin = 0.0f;
            hmdTextureBounds.uMax = 1.0f;
            hmdTextureBounds.vMin = 1.0f; // flip the vertical coordinate for some reason
            hmdTextureBounds.vMax = 0.0f;
        }
Example #32
0
 // Token: 0x06001FBA RID: 8122 RVA: 0x0009DE54 File Offset: 0x0009C054
 public EVROverlayError GetOverlayTexture(ulong ulOverlayHandle, ref IntPtr pNativeTextureHandle, IntPtr pNativeTextureRef, ref uint pWidth, ref uint pHeight, ref uint pNativeFormat, ref ETextureType pAPIType, ref EColorSpace pColorSpace, ref VRTextureBounds_t pTextureBounds)
 {
     pWidth        = 0U;
     pHeight       = 0U;
     pNativeFormat = 0U;
     return(this.FnTable.GetOverlayTexture(ulOverlayHandle, ref pNativeTextureHandle, pNativeTextureRef, ref pWidth, ref pHeight, ref pNativeFormat, ref pAPIType, ref pColorSpace, ref pTextureBounds));
 }