Commit: 506dfd65eb95f6bcae434505dc0ade43ebe82120
Author: Julian Eisel
Date:   Wed Jun 8 19:42:03 2016 +0200
Branches: HMD_viewport
https://developer.blender.org/rB506dfd65eb95f6bcae434505dc0ade43ebe82120

Only allow using Device IPD if it's available

===================================================================

M       intern/ghost/intern/GHOST_OpenHMDManager.cpp
M       source/blender/blenkernel/intern/camera.c
M       source/blender/makesrna/intern/rna_camera.c

===================================================================

diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.cpp 
b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
index fd103a0..5228bf4 100644
--- a/intern/ghost/intern/GHOST_OpenHMDManager.cpp
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
@@ -402,6 +402,9 @@ float GHOST_OpenHMDManager::getRightEyeAspectRatio() const
        return val;
 }
 
+/**
+ * \returns -1 if not found.
+ */
 float GHOST_OpenHMDManager::getEyeIPD() const
 {
        if (!m_device) {
diff --git a/source/blender/blenkernel/intern/camera.c 
b/source/blender/blenkernel/intern/camera.c
index 23a8cea..b733460 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -719,7 +719,9 @@ static void camera_model_matrix(Object *camera, float 
r_modelmat[4][4])
        copy_m4_m4(r_modelmat, camera->obmat);
 }
 
-static void camera_stereo3d_model_matrix(Object *camera, const bool is_left, 
float r_modelmat[4][4])
+static void camera_stereo3d_model_matrix(
+        Object *camera, const bool is_left, const bool is_hmd,
+        float r_modelmat[4][4])
 {
        Camera *data = (Camera *)camera->data;
        float sizemat[4][4];
@@ -727,16 +729,21 @@ static void camera_stereo3d_model_matrix(Object *camera, 
const bool is_left, flo
        float fac = 1.0f;
        float fac_signed;
 
-       const float interocular_distance =
-#ifdef WITH_INPUT_HMD
-               (data->stereo.flag & CAM_S3D_CUSTOM_IPD) ? 
WM_device_HMD_IPD_get() : data->stereo.interocular_distance;
-#else
-               data->stereo.interocular_distance;
-#endif
+       float interocular_distance = data->stereo.interocular_distance;
        const float convergence_distance = data->stereo.convergence_distance;
        const short convergence_mode = data->stereo.convergence_mode;
        const short pivot = data->stereo.pivot;
 
+#ifdef WITH_INPUT_HMD
+       /* Try to get the interocular distance from the HMD */
+       if (is_hmd && U.hmd_device != -1 && !(data->stereo.flag & 
CAM_S3D_CUSTOM_IPD)) {
+               const float device_ipd = WM_device_HMD_IPD_get();
+               if (device_ipd != -1) {
+                       interocular_distance = device_ipd;
+               }
+       }
+#endif
+
        if (((pivot == CAM_S3D_PIVOT_LEFT) && is_left) ||
            ((pivot == CAM_S3D_PIVOT_RIGHT) && !is_left))
        {
@@ -847,7 +854,7 @@ void BKE_camera_multiview_model_matrix(RenderData *rd, 
Object *camera, const cha
        }
        else { /* SCE_VIEWS_SETUP_BASIC */
                const bool is_left = camera_is_left(viewname);
-               camera_stereo3d_model_matrix(camera, is_left, r_modelmat);
+               camera_stereo3d_model_matrix(camera, is_left, rd->views_format 
== SCE_VIEWS_FORMAT_HMD, r_modelmat);
        }
        normalize_m4(r_modelmat);
 }
diff --git a/source/blender/makesrna/intern/rna_camera.c 
b/source/blender/makesrna/intern/rna_camera.c
index c544449..54df6bc 100644
--- a/source/blender/makesrna/intern/rna_camera.c
+++ b/source/blender/makesrna/intern/rna_camera.c
@@ -42,6 +42,20 @@
 #include "BKE_object.h"
 #include "BKE_depsgraph.h"
 
+#include "WM_api.h"
+
+static int rna_camera_stereo_use_device_ipd_editeable(PointerRNA *ptr)
+{
+#ifdef WITH_INPUT_HMD
+       if (U.hmd_device == -1 || WM_device_HMD_IPD_get() == -1) {
+               Camera *cam = ptr->id.data;
+               cam->stereo.flag |= CAM_S3D_CUSTOM_IPD;
+               return false;
+       }
+#endif
+       return PROP_EDITABLE;
+}
+
 static float rna_Camera_angle_get(PointerRNA *ptr)
 {
        Camera *cam = ptr->id.data;
@@ -134,6 +148,7 @@ static void rna_def_camera_stereo_data(BlenderRNA *brna)
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", 
CAM_S3D_CUSTOM_IPD);
        RNA_def_property_ui_text(prop, "Interocular Distance from HMD",
                                 "Request the interocular distance (distance 
between eyes) from the HMD driver");
+       RNA_def_property_editable_func(prop, 
"rna_camera_stereo_use_device_ipd_editeable");
        RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
 
        prop = RNA_def_property(srna, "interocular_distance", PROP_FLOAT, 
PROP_DISTANCE);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to