[Bf-blender-cvs] [5fa6cdb77a9] master: Add unit for time stored in seconds

Sergey Sharybin noreply at git.blender.org
Thu Jun 10 12:17:23 CEST 2021


Commit: 5fa6cdb77a9860ce673f685fd29e11b1c3ee8ad8
Author: Sergey Sharybin
Date:   Tue Jun 8 11:50:19 2021 +0200
Branches: master
https://developer.blender.org/rB5fa6cdb77a9860ce673f685fd29e11b1c3ee8ad8

Add unit for time stored in seconds

Allows to define properties which will have proper units displayed
in the interface. The internal storage is expected to be seconds
(which matches how other times are stored in Blender).

Is not immediately used in Blender, but is required for the upcoming
feature in Cycles X (D11526)

The naming does not sound very exciting, but can't think of anything
better either.

For test it probably easiest to define FloatProperty with subdtype
of TIME_ABSOLUTE.

Differential Revision: https://developer.blender.org/D11532

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

M	source/blender/blenkernel/BKE_unit.h
M	source/blender/blenkernel/intern/node.cc
M	source/blender/blenkernel/intern/unit.c
M	source/blender/makesrna/RNA_types.h
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/makesrna/intern/rna_rna.c
M	source/blender/nodes/intern/node_socket.cc
M	source/blender/python/intern/bpy_props.c

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

diff --git a/source/blender/blenkernel/BKE_unit.h b/source/blender/blenkernel/BKE_unit.h
index c4af9ab40e2..b28215a72d1 100644
--- a/source/blender/blenkernel/BKE_unit.h
+++ b/source/blender/blenkernel/BKE_unit.h
@@ -82,12 +82,13 @@ enum {
   B_UNIT_MASS = 4,
   B_UNIT_ROTATION = 5,
   B_UNIT_TIME = 6,
-  B_UNIT_VELOCITY = 7,
-  B_UNIT_ACCELERATION = 8,
-  B_UNIT_CAMERA = 9,
-  B_UNIT_POWER = 10,
-  B_UNIT_TEMPERATURE = 11,
-  B_UNIT_TYPE_TOT = 12,
+  B_UNIT_TIME_ABSOLUTE = 7,
+  B_UNIT_VELOCITY = 8,
+  B_UNIT_ACCELERATION = 9,
+  B_UNIT_CAMERA = 10,
+  B_UNIT_POWER = 11,
+  B_UNIT_TEMPERATURE = 12,
+  B_UNIT_TYPE_TOT = 13,
 };
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 8d8f7b90d3b..f4e78859749 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -1662,6 +1662,8 @@ const char *nodeStaticSocketType(int type, int subtype)
           return "NodeSocketFloatAngle";
         case PROP_TIME:
           return "NodeSocketFloatTime";
+        case PROP_TIME_ABSOLUTE:
+          return "NodeSocketFloatTimeAbsolute";
         case PROP_DISTANCE:
           return "NodeSocketFloatDistance";
         case PROP_NONE:
@@ -1737,6 +1739,8 @@ const char *nodeStaticSocketInterfaceType(int type, int subtype)
           return "NodeSocketInterfaceFloatAngle";
         case PROP_TIME:
           return "NodeSocketInterfaceFloatTime";
+        case PROP_TIME_ABSOLUTE:
+          return "NodeSocketInterfaceFloatTimeAbsolute";
         case PROP_DISTANCE:
           return "NodeSocketInterfaceFloatDistance";
         case PROP_NONE:
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index 3612a26315c..5cf76bb6452 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -358,6 +358,7 @@ static const struct bUnitCollection *bUnitSystems[][B_UNIT_TYPE_TOT] = {
      NULL,
      &buNaturalRotCollection,
      &buNaturalTimeCollection,
+     &buNaturalTimeCollection,
      NULL,
      NULL,
      NULL,
@@ -371,6 +372,7 @@ static const struct bUnitCollection *bUnitSystems[][B_UNIT_TYPE_TOT] = {
      &buMetricMassCollection,
      &buNaturalRotCollection,
      &buNaturalTimeCollection,
+     &buNaturalTimeCollection,
      &buMetricVelCollection,
      &buMetricAclCollection,
      &buCameraLenCollection,
@@ -384,12 +386,13 @@ static const struct bUnitCollection *bUnitSystems[][B_UNIT_TYPE_TOT] = {
      &buImperialMassCollection,
      &buNaturalRotCollection,
      &buNaturalTimeCollection,
+     &buNaturalTimeCollection,
      &buImperialVelCollection,
      &buImperialAclCollection,
      &buCameraLenCollection,
      &buPowerCollection,
      &buImperialTempCollection},
-    {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+    {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
 };
 
 static const bUnitCollection *unit_get_system(int system, int type)
diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index 4a6d6dddec7..8e1cfafcc42 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -82,17 +82,18 @@ typedef enum PropertyType {
 /* also update rna_property_subtype_unit when you change this */
 typedef enum PropertyUnit {
   PROP_UNIT_NONE = (0 << 16),
-  PROP_UNIT_LENGTH = (1 << 16),       /* m */
-  PROP_UNIT_AREA = (2 << 16),         /* m^2 */
-  PROP_UNIT_VOLUME = (3 << 16),       /* m^3 */
-  PROP_UNIT_MASS = (4 << 16),         /* kg */
-  PROP_UNIT_ROTATION = (5 << 16),     /* radians */
-  PROP_UNIT_TIME = (6 << 16),         /* frame */
-  PROP_UNIT_VELOCITY = (7 << 16),     /* m/s */
-  PROP_UNIT_ACCELERATION = (8 << 16), /* m/(s^2) */
-  PROP_UNIT_CAMERA = (9 << 16),       /* mm */
-  PROP_UNIT_POWER = (10 << 16),       /* W */
-  PROP_UNIT_TEMPERATURE = (11 << 16), /* C */
+  PROP_UNIT_LENGTH = (1 << 16),        /* m */
+  PROP_UNIT_AREA = (2 << 16),          /* m^2 */
+  PROP_UNIT_VOLUME = (3 << 16),        /* m^3 */
+  PROP_UNIT_MASS = (4 << 16),          /* kg */
+  PROP_UNIT_ROTATION = (5 << 16),      /* radians */
+  PROP_UNIT_TIME = (6 << 16),          /* frame */
+  PROP_UNIT_TIME_ABSOLUTE = (7 << 16), /* time in seconds (independent of scene) */
+  PROP_UNIT_VELOCITY = (8 << 16),      /* m/s */
+  PROP_UNIT_ACCELERATION = (9 << 16),  /* m/(s^2) */
+  PROP_UNIT_CAMERA = (10 << 16),       /* mm */
+  PROP_UNIT_POWER = (11 << 16),        /* W */
+  PROP_UNIT_TEMPERATURE = (12 << 16),  /* C */
 } PropertyUnit;
 
 /**
@@ -157,6 +158,7 @@ typedef enum PropertySubType {
   PROP_FACTOR = 15,
   PROP_ANGLE = 16 | PROP_UNIT_ROTATION,
   PROP_TIME = 17 | PROP_UNIT_TIME,
+  PROP_TIME_ABSOLUTE = 17 | PROP_UNIT_TIME_ABSOLUTE,
   /** Distance in 3d space, don't use for pixel distance for eg. */
   PROP_DISTANCE = 18 | PROP_UNIT_LENGTH,
   PROP_DISTANCE_CAMERA = 19 | PROP_UNIT_CAMERA,
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index efe12114d55..7a9cfa79324 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -3201,6 +3201,8 @@ static const char *rna_property_subtypename(PropertySubType type)
       return "PROP_ANGLE";
     case PROP_TIME:
       return "PROP_TIME";
+    case PROP_TIME_ABSOLUTE:
+      return "PROP_TIME_ABSOLUTE";
     case PROP_DISTANCE:
       return "PROP_DISTANCE";
     case PROP_DISTANCE_CAMERA:
@@ -3266,6 +3268,8 @@ static const char *rna_property_subtype_unit(PropertySubType type)
       return "PROP_UNIT_ROTATION";
     case PROP_UNIT_TIME:
       return "PROP_UNIT_TIME";
+    case PROP_UNIT_TIME_ABSOLUTE:
+      return "PROP_UNIT_TIME_ABSOLUTE";
     case PROP_UNIT_VELOCITY:
       return "PROP_UNIT_VELOCITY";
     case PROP_UNIT_ACCELERATION:
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 2bafbd57e11..6a38a22f9b2 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -10831,6 +10831,8 @@ static void rna_def_node_socket_standard_types(BlenderRNA *brna)
       brna, "NodeSocketFloatAngle", "NodeSocketInterfaceFloatAngle", PROP_ANGLE);
   rna_def_node_socket_float(
       brna, "NodeSocketFloatTime", "NodeSocketInterfaceFloatTime", PROP_TIME);
+  rna_def_node_socket_float(
+      brna, "NodeSocketFloatTimeAbsolute", "NodeSocketInterfaceFloatTimeAbsolute", PROP_TIME_ABSOLUTE);
   rna_def_node_socket_float(
       brna, "NodeSocketFloatDistance", "NodeSocketInterfaceFloatDistance", PROP_DISTANCE);
 
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index f7a7b745493..9e7d0f99dfa 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -81,7 +81,16 @@ const EnumPropertyItem rna_enum_property_subtype_items[] = {
     {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""},
     {PROP_FACTOR, "FACTOR", 0, "Factor", ""},
     {PROP_ANGLE, "ANGLE", 0, "Angle", ""},
-    {PROP_TIME, "TIME", 0, "Time", ""},
+    {PROP_TIME,
+     "TIME",
+     0,
+     "Time (Scene Relative)",
+     "Time specified in frames, converted to seconds based on scene frame rate"},
+    {PROP_TIME_ABSOLUTE,
+     "TIME_ABSOLUTE",
+     0,
+     "Time (Absolute)",
+     "Time specified in seconds, independent of the scene"},
     {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""},
     {PROP_DISTANCE_CAMERA, "DISTANCE_CAMERA", 0, "Camera Distance", ""},
     {PROP_POWER, "POWER", 0, "Power", ""},
diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc
index 052896d2f48..d00bf636e15 100644
--- a/source/blender/nodes/intern/node_socket.cc
+++ b/source/blender/nodes/intern/node_socket.cc
@@ -727,6 +727,7 @@ void register_standard_node_socket_types(void)
   nodeRegisterSocketType(make_socket_type_float(PROP_FACTOR));
   nodeRegisterSocketType(make_socket_type_float(PROP_ANGLE));
   nodeRegisterSocketType(make_socket_type_float(PROP_TIME));
+  nodeRegisterSocketType(make_socket_type_float(PROP_TIME_ABSOLUTE));
   nodeRegisterSocketType(make_socket_type_float(PROP_DISTANCE));
 
   nodeRegisterSocketType(make_socket_type_int(PROP_NONE));
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index c21c635913f..6ad80f9160b 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -147,7 +147,17 @@ static const EnumPropertyItem property_subtype_number_items[] = {
     {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""},
     {PROP_FACTOR, "FACTOR", 0, "Factor", ""},
     {PROP_ANGLE, "ANGLE", 0, "Angle", ""},
-    {PROP_TIME, "TIME", 0, "Time", ""},
+    {PROP_TIME,
+     "TIME",
+     0,
+     "Time (Scene Relative)",
+     "Time specified in frames, converted to seconds based on scene frame rate"},
+    {PROP_TIME_ABSOLUTE,
+     "TIME_ABSOLUTE",
+     0,
+     "Time (Absolute)",
+     "Time specified in seconds, independent of the scene"},
+    {PROP_TIME_ABSOLUTE, "TIME_ABSOLUTE", 0, "Time Absolute", ""},
     {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""},
     {PROP_DISTANCE_CAMERA, "DISTANCE_CAMERA", 0, "Camera Distance", ""},
     {PROP_POWER, "POWER", 0, "Power", ""},



More information about the Bf-blender-cvs mailing list