[Bf-blender-cvs] [78643f07671] vr_scene_inspection: Support inputting custom base pose location and Z-Axis rotation
Julian Eisel
noreply at git.blender.org
Sat Feb 15 03:29:29 CET 2020
Commit: 78643f076715ece1e9f36c01f42ef8eccb9c14e1
Author: Julian Eisel
Date: Sat Feb 15 03:24:10 2020 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rB78643f076715ece1e9f36c01f42ef8eccb9c14e1
Support inputting custom base pose location and Z-Axis rotation
===================================================================
M source/blender/makesdna/DNA_xr_types.h
M source/blender/makesrna/intern/rna_xr.c
M source/blender/windowmanager/intern/wm_xr.c
===================================================================
diff --git a/source/blender/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index b633d97dd00..f3d6f3deadc 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -27,12 +27,17 @@ typedef struct bXrSessionSettings {
/** Shading settings, struct shared with 3D-View so settings are the same. */
struct View3DShading shading;
+ char _pad[7];
+
+ char base_pose_type; /* eXRSessionBasePoseType */
/** Object to take the location and rotation as base position from. */
Object *base_pose_object;
+ float base_pose_location[3];
+ float base_pose_angle;
/** View3D draw flags (V3D_OFSDRAW_NONE, V3D_OFSDRAW_SHOW_ANNOTATION, ...). */
char draw_flags;
- char _pad[3];
+ char _pad2[3];
/** Clipping distance. */
float clip_start, clip_end;
@@ -44,4 +49,10 @@ typedef enum eXrSessionFlag {
XR_SESSION_USE_POSITION_TRACKING = (1 << 0),
} eXrSessionFlag;
+typedef enum eXRSessionBasePoseType {
+ XR_BASE_POSE_SCENE_CAMERA = 0,
+ XR_BASE_POSE_OBJECT = 1,
+ XR_BASE_POSE_CUSTOM = 2,
+} eXRSessionBasePoseType;
+
#endif /* __DNA_XR_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index ef5f11ed91b..f4aa31859c3 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -74,6 +74,25 @@ static void rna_def_xr_session_settings(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
+ static const EnumPropertyItem base_pose_types[] = {
+ {XR_BASE_POSE_SCENE_CAMERA,
+ "SCENE_CAMERA",
+ 0,
+ "Scene Camera",
+ "Follow the active scene camera to define the VR view's reference pose"},
+ {XR_BASE_POSE_OBJECT,
+ "OBJECT",
+ 0,
+ "Object",
+ "Follow an transformation of an object to define the VR view's reference pose"},
+ {XR_BASE_POSE_CUSTOM,
+ "CUSTOM",
+ 0,
+ "Custom",
+ "Follow a custom transformation to define the VR view's reference pose"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
srna = RNA_def_struct(brna, "XrSessionSettings", NULL);
RNA_def_struct_sdna(srna, "bXrSessionSettings");
RNA_def_struct_ui_text(srna, "XR-Session Settings", "");
@@ -83,10 +102,28 @@ static void rna_def_xr_session_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Shading Settings", "");
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
+ prop = RNA_def_property(srna, "base_pose_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_enum_items(prop, base_pose_types);
+ RNA_def_property_ui_text(
+ prop, "Base Pose Type", "Define where the base pose for the VR view comes from");
+ RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
+
prop = RNA_def_property(srna, "base_pose_object", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop,
+ "Base Pose Object",
+ "Object to take the location and rotation as reference position from");
+ RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
+
+ prop = RNA_def_property(srna, "base_pose_location", PROP_FLOAT, PROP_TRANSLATION);
+ RNA_def_property_ui_text(prop, "Base Pose Location", "");
+ RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
+ RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
+
+ prop = RNA_def_property(srna, "base_pose_angle", PROP_FLOAT, PROP_AXISANGLE);
RNA_def_property_ui_text(
- prop, "Anchor Object", "Object to take the location and rotation as base position from");
+ prop, "Base Pose Angle", "Rotation angle around the Z-Axis to apply to the reference pose");
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
prop = RNA_def_property(srna, "show_floor", PROP_BOOLEAN, PROP_NONE);
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index acdd00f8fb0..899ebfd0626 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -203,25 +203,36 @@ static void wm_xr_reference_pose_calc(const Scene *scene,
const bXrSessionSettings *settings,
GHOST_XrPose *r_pose)
{
- const Object *base_pose_object = settings->base_pose_object ? settings->base_pose_object :
- scene->camera;
- float tmp_quat[4];
- float tmp_eul[3];
+ const Object *base_pose_object = ((settings->base_pose_type == XR_BASE_POSE_OBJECT) &&
+ settings->base_pose_object) ?
+ settings->base_pose_object :
+ scene->camera;
+
+ if (settings->base_pose_type == XR_BASE_POSE_CUSTOM) {
+ float tmp_quatx[4], tmp_quatz[4];
+
+ copy_v3_v3(r_pose->position, settings->base_pose_location);
+ axis_angle_to_quat_single(tmp_quatx, 'X', M_PI_2);
+ axis_angle_to_quat_single(tmp_quatz, 'Z', settings->base_pose_angle);
+ mul_qt_qtqt(r_pose->orientation_quat, tmp_quatz, tmp_quatx);
+ }
+ else if (base_pose_object) {
+ float tmp_quat[4];
+ float tmp_eul[3];
- if (base_pose_object) {
copy_v3_v3(r_pose->position, base_pose_object->obmat[3]);
mat4_to_quat(tmp_quat, base_pose_object->obmat);
+
+ /* Only use rotation around Z-axis to align view with floor. */
+ quat_to_eul(tmp_eul, tmp_quat);
+ tmp_eul[0] = M_PI_2;
+ tmp_eul[1] = 0;
+ eul_to_quat(r_pose->orientation_quat, tmp_eul);
}
else {
copy_v3_fl(r_pose->position, 0.0f);
- unit_qt(tmp_quat);
+ unit_qt(r_pose->orientation_quat);
}
-
- /* Only use rotation around Z-axis to align view with floor. */
- quat_to_eul(tmp_eul, tmp_quat);
- tmp_eul[0] = M_PI_2;
- tmp_eul[1] = 0;
- eul_to_quat(r_pose->orientation_quat, tmp_eul);
}
static void wm_xr_runtime_session_state_update(bXrRuntimeSessionState *state,
More information about the Bf-blender-cvs
mailing list