[Bf-blender-cvs] [c5fc10b] HMD_viewport: Add UserPref option to change HMD device
Julian Eisel
noreply at git.blender.org
Mon Mar 28 15:17:53 CEST 2016
Commit: c5fc10ba3f27115ce930a588ff8a81c9fd90a28b
Author: Julian Eisel
Date: Mon Mar 28 15:13:46 2016 +0200
Branches: HMD_viewport
https://developer.blender.org/rBc5fc10ba3f27115ce930a588ff8a81c9fd90a28b
Add UserPref option to change HMD device
A new file wm_device.c is added with this, think this is good to have.
NOTE: Couldn't really test if changing device actually works as I don't have one. Without a device available everything seems to work though.
===================================================================
M intern/ghost/GHOST_C-api.h
M intern/ghost/intern/GHOST_C-api.cpp
M intern/ghost/intern/GHOST_OpenHMDManager.cpp
M intern/ghost/intern/GHOST_OpenHMDManager.h
M release/scripts/startup/bl_ui/space_userpref.py
M source/blender/blenkernel/BKE_blender.h
M source/blender/blenkernel/intern/camera.c
M source/blender/blenloader/intern/versioning_270.c
M source/blender/editors/interface/resources.c
M source/blender/makesdna/DNA_userdef_types.h
M source/blender/makesrna/intern/rna_userdef.c
M source/blender/windowmanager/CMakeLists.txt
M source/blender/windowmanager/WM_api.h
A source/blender/windowmanager/intern/wm_device.c
M source/blender/windowmanager/intern/wm_operators.c
M source/blender/windowmanager/intern/wm_stereo.c
===================================================================
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 73a2e3e..7a43f0d 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -930,9 +930,12 @@ extern void GHOST_BeginIME(GHOST_WindowHandle windowhandle,
*/
extern void GHOST_EndIME(GHOST_WindowHandle windowhandle);
-extern void GHOST_HMDopenDevice(int index);
-extern void GHOST_HMDcloseDevice(void);
-extern float GHOST_HMDgetDeviceIPD(void);
+extern int GHOST_HMDgetNumDevices(void);
+extern void GHOST_HMDopenDevice(int index);
+extern void GHOST_HMDcloseDevice(void);
+extern int GHOST_HMDgetOpenDeviceIndex(void);
+extern const char *GHOST_HMDgetDeviceName(int index);
+extern float GHOST_HMDgetDeviceIPD(void);
#ifdef __cplusplus
}
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 13abbdd..1435894 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -935,6 +935,13 @@ void GHOST_EndIME(GHOST_WindowHandle windowhandle)
#ifdef WITH_OPENHMD
+int GHOST_HMDgetNumDevices()
+{
+ GHOST_ISystem *system = GHOST_ISystem::getSystem();
+ GHOST_OpenHMDManager *ohmd = system->getOpenHMDManager();
+ return ohmd->getNumDevices();
+}
+
void GHOST_HMDopenDevice(int index)
{
GHOST_ISystem *system = GHOST_ISystem::getSystem();
@@ -949,6 +956,20 @@ void GHOST_HMDcloseDevice()
ohmd->closeDevice();
}
+int GHOST_HMDgetOpenDeviceIndex()
+{
+ GHOST_ISystem *system = GHOST_ISystem::getSystem();
+ GHOST_OpenHMDManager *ohmd = system->getOpenHMDManager();
+ return ohmd->getDeviceIndex();
+}
+
+const char *GHOST_HMDgetDeviceName(int index)
+{
+ GHOST_ISystem *system = GHOST_ISystem::getSystem();
+ GHOST_OpenHMDManager *ohmd = system->getOpenHMDManager();
+ return ohmd->getDeviceName(index);
+}
+
float GHOST_HMDgetDeviceIPD()
{
GHOST_ISystem *system = GHOST_ISystem::getSystem();
diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.cpp b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
index 9eb7933..2d2549b 100644
--- a/intern/ghost/intern/GHOST_OpenHMDManager.cpp
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
@@ -135,6 +135,11 @@ bool GHOST_OpenHMDManager::openDevice(int index)
return false;
}
+ /* Blender only allows one opened device at a time */
+ if (getOpenHMDDevice()) {
+ closeDevice();
+ }
+
//can't fail to open the device
m_deviceIndex = index;
m_device = ohmd_list_open_device(m_context, index);
@@ -180,6 +185,14 @@ const char *GHOST_OpenHMDManager::getDeviceName() const
return ohmd_list_gets(m_context, m_deviceIndex, OHMD_PRODUCT);
}
+const char *GHOST_OpenHMDManager::getDeviceName(int index) const
+{
+ if (!m_available)
+ return NULL;
+
+ return ohmd_list_gets(m_context, index, OHMD_PRODUCT);
+}
+
const char *GHOST_OpenHMDManager::getVendorName() const
{
if (!m_available)
diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.h b/intern/ghost/intern/GHOST_OpenHMDManager.h
index c188938..48b3f05 100644
--- a/intern/ghost/intern/GHOST_OpenHMDManager.h
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.h
@@ -93,6 +93,12 @@ public:
const char *getDeviceName() const;
/**
+ * \return A c-style string with the human-readable name of the device at \a index.
+ * NULL is returned if available() is false.
+ */
+ const char *getDeviceName(int index) const;
+
+ /**
* \return A c-style string with the human-readable name of the vendor of the the current device.
* NULL is returned if available() is false.
*/
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 0100385..7226d83 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -440,6 +440,11 @@ class USERPREF_PT_system(Panel):
col.label(text="OpenSubdiv compute:")
col.row().prop(system, "opensubdiv_compute_type", text="")
+ col.separator()
+
+ col.label(text="Head Mounted Displays:")
+ col.prop(system, "hmd_device")
+
# 2. Column
column = split.column()
colsplit = column.split(percentage=0.85)
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index fdb3474..3eb1c30 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -42,7 +42,7 @@ extern "C" {
* and keep comment above the defines.
* Use STRINGIFY() rather than defining with quotes */
#define BLENDER_VERSION 277
-#define BLENDER_SUBVERSION 0
+#define BLENDER_SUBVERSION 1
/* Several breakages with 270, e.g. constraint deg vs rad */
#define BLENDER_MINVERSION 270
#define BLENDER_MINSUBVERSION 6
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 679342a..be6593e 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -726,7 +726,7 @@ static void camera_stereo3d_model_matrix(Object *camera, const bool is_left, flo
float fac_signed;
const bool use_device_ipd = data->stereo.flag & CAM_S3D_CUSTOM_IPD;
- float interocular_distance = use_device_ipd ? WM_HMD_device_IPD_get() : data->stereo.interocular_distance;
+ float interocular_distance = use_device_ipd ? WM_device_HMD_IPD_get() : data->stereo.interocular_distance;
float convergence_distance = data->stereo.convergence_distance;
short convergence_mode = data->stereo.convergence_mode;
short pivot = data->stereo.pivot;
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index ecf76f0..80a2127 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -1072,9 +1072,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
}
- }
- {
for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
if (scene->r.hmd_view_shade == 0) {
scene->r.hmd_view_shade = OB_MATERIAL;
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index b1d2e32..4ad1446 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -2704,6 +2704,10 @@ void init_userdef_do_versions(void)
}
}
+ if (!USER_VERSION_ATLEAST(277, 1)) {
+ U.hmd_device = -1;
+ }
+
/**
* Include next version bump.
*
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index af1dfc6..0b05271 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -566,7 +566,9 @@ typedef struct UserDef {
struct WalkNavigation walk_navigation;
short opensubdiv_compute_type;
- char pad5[6];
+
+ short hmd_device; /* HMD device index */
+ char pad5[4];
} UserDef;
extern UserDef U; /* from blenkernel blender.c */
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 924bed3..8ca61f6 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -88,6 +88,11 @@ static EnumPropertyItem audio_device_items[] = {
{0, NULL, 0, NULL, NULL}
};
+static EnumPropertyItem hmd_device_items[] = {
+ {-1, "NONE", 0, "None", "Don't use any HMD device"},
+ {0, NULL, 0, NULL, NULL}
+};
+
EnumPropertyItem rna_enum_navigation_mode_items[] = {
{VIEW_NAVIGATION_WALK, "WALK", 0, "Walk", "Interactively walk or free navigate around the scene"},
{VIEW_NAVIGATION_FLY, "FLY", 0, "Fly", "Use fly dynamics to navigate the scene"},
@@ -638,6 +643,44 @@ static EnumPropertyItem *rna_userdef_audio_device_itemf(bContext *UNUSED(C), Poi
return item;
}
+static EnumPropertyItem *rna_userdef_hmd_device_itemf(
+ bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop),
+ bool *r_free)
+{
+ EnumPropertyItem *item = NULL;
+ int totitem = 0;
+
+ /* 'None' element */
+ RNA_enum_item_add(&item, &totitem, &hmd_device_items[0]);
+ /* add devices */
+ for (int i = 0; i < WM_device_HMD_num_devices_get(); i++) {
+ EnumPropertyItem tmp = {i, "", 0, "", ""};
+ tmp.identifier = tmp.name = WM_device_HMD_name_get(i);
+ RNA_enum_item_add(&item, &totitem, &tmp);
+ }
+
+ RNA_enum_item_end(&item, &totitem);
+ *r_free = true;
+
+ return item;
+}
+
+static void rna_userdef_hmd_device_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
+{
+ const int act_device = WM_device_HMD_current_get();
+
+ /* a device is already open */
+ if (act_device >= 0) {
+ if (U.hmd_device < 0) {
+ WM_device_HMD_state_set(U.hmd_device, false);
+ }
+ /* change device */
+ else if (act_device != U.hmd_device) {
+ WM_device_HMD_state_set(U.hmd_device, true);
+ }
+ }
+}
+
#ifdef WITH_INTERNATIONAL
static EnumPropertyItem *rna_lang_enum_properties_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr),
PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
@@ -4305,6 +4348,13 @@ static void rna_def_userdef_system(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "OpenSubdiv Compute Type", "Type of computer back-end used with OpenSubdiv");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_PROPERTIES, "rna_userdef_opensubdiv_update");
#endif
+
+ prop = RNA_def_property(srna, "hmd_device", PROP_ENUM, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
+ RNA_def_property_enum_items(prop, hmd_device_items);
+ RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_userdef_hmd_device_itemf");
+ RNA_def_property_ui_text(prop, "HMD Device", "Device to use for HMD view interaction");
+ RNA_def_property_update(prop, 0, "rna_userdef_hmd_device_update");
}
static void rna_def_userdef_input(BlenderRNA *brna)
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index af8a7cc..9df84c9 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -67,6 +67,7 @@ set(SRC
intern/wm_subwindow.c
intern/wm_window.c
intern/wm_stereo.c
+ intern/wm_device.c
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list