[Bf-blender-cvs] [5d4f8d31a5b] vr_scene_inspection: Allow setting any object as "anchor" (to set base location/rotation)

Julian Eisel noreply at git.blender.org
Mon Feb 3 19:50:33 CET 2020


Commit: 5d4f8d31a5b489d3fb4542542d2c3fd92d4fc89e
Author: Julian Eisel
Date:   Mon Feb 3 19:47:41 2020 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rB5d4f8d31a5b489d3fb4542542d2c3fd92d4fc89e

Allow setting any object as "anchor" (to set base location/rotation)

Not sure how much of this will actually stay in, but it should allow us
experimenting with different ways to set the base position.
Also, when an anchor is set, the location/rotation of it and the VR base
position are synched.

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

M	source/blender/blenloader/intern/readfile.c
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/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index cb83a28e87a..40cb69ce2d8 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7826,6 +7826,12 @@ static void direct_link_wm_xr_data(FileData *fd, wmXrData *xr_data)
   direct_link_view3dshading(fd, &xr_data->session_settings.shading);
 }
 
+static void lib_link_wm_xr_data(FileData *fd, ID *parent_id, wmXrData *xr_data)
+{
+  xr_data->session_settings.anchor_object = newlibadr(
+      fd, parent_id->lib, xr_data->session_settings.anchor_object);
+}
+
 #endif
 
 /** \} */
@@ -7935,6 +7941,8 @@ static void lib_link_windowmanager(FileData *fd, Main *main)
         }
       }
 
+      lib_link_wm_xr_data(fd, &wm->id, &wm->xr);
+
       wm->id.tag &= ~LIB_TAG_NEED_LINK;
     }
   }
diff --git a/source/blender/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index 79c366ebda7..0eff72ae248 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -24,8 +24,12 @@
 #include "DNA_view3d_types.h"
 
 typedef struct bXrSessionSettings {
+  /** Shading settings, struct shared with 3D-View so settings are the same. */
   struct View3DShading shading;
 
+  /** Object to take the location and rotation as base position from. */
+  Object *anchor_object;
+
   /** View3D draw flags (V3D_OFSDRAW_NONE, V3D_OFSDRAW_SHOW_ANNOTATION, ...). */
   char draw_flags;
   char _pad[3];
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index 0967ff1639e..79abe00293d 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -83,6 +83,12 @@ 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, "anchor_object", PROP_POINTER, PROP_NONE);
+  RNA_def_property_flag(prop, PROP_EDITABLE);
+  RNA_def_property_ui_text(
+      prop, "Anchor Object", "Object to take the location and rotation as base position from");
+  RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
+
   prop = RNA_def_property(srna, "show_floor", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "draw_flags", V3D_OFSDRAW_SHOW_GRIDFLOOR);
   RNA_def_property_ui_text(prop, "Display Grid Floor", "Show the ground plane grid");
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index e595f6b66bc..75f7bb18c61 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -225,6 +225,13 @@ static void wm_xr_runtime_session_state_update(bXrRuntimeSessionState *state,
                                          (settings->flag & XR_SESSION_USE_POSITION_TRACKING);
   const bool use_position_tracking = settings->flag & XR_SESSION_USE_POSITION_TRACKING;
 
+  if (settings->anchor_object) {
+    copy_v3_v3(state->reference_pose.position, settings->anchor_object->obmat[3]);
+    mat4_to_quat(state->reference_pose.orientation_quat, settings->anchor_object->obmat);
+
+    copy_v3_v3(state->final_reference_pose.position, state->reference_pose.position);
+  }
+
   copy_v4_v4(state->final_reference_pose.orientation_quat, state->reference_pose.orientation_quat);
 
   if (position_tracking_toggled) {



More information about the Bf-blender-cvs mailing list