[Bf-blender-cvs] [ac23fc69221] soc-2020-fluid-tools: Fluid: Dynamic list generation for coba field

Sriharsha Kotcharlakot noreply at git.blender.org
Fri Jun 12 20:01:35 CEST 2020


Commit: ac23fc692212ec764d328c91b754023e373bf979
Author: Sriharsha Kotcharlakot
Date:   Fri Jun 12 23:28:50 2020 +0530
Branches: soc-2020-fluid-tools
https://developer.blender.org/rBac23fc692212ec764d328c91b754023e373bf979

Fluid: Dynamic list generation for coba field

Coba field items are generated according to domain type.
Set coba field in quick effects according to domain type.

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

M	release/scripts/startup/bl_operators/object_quick_effects.py
M	release/scripts/startup/bl_ui/properties_physics_fluid.py
M	source/blender/blenkernel/BKE_fluid.h
M	source/blender/blenkernel/intern/fluid.c
M	source/blender/makesrna/intern/rna_fluid.c

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

diff --git a/release/scripts/startup/bl_operators/object_quick_effects.py b/release/scripts/startup/bl_operators/object_quick_effects.py
index 71153ba8b74..9149bbce719 100644
--- a/release/scripts/startup/bl_operators/object_quick_effects.py
+++ b/release/scripts/startup/bl_operators/object_quick_effects.py
@@ -399,6 +399,9 @@ class QuickSmoke(ObjectModeOperator, Operator):
         if self.style == 'FIRE' or self.style == 'BOTH':
             obj.modifiers[-1].domain_settings.use_noise = True
 
+        # set color mapping field to show density for smoke
+        obj.modifiers[-1].domain_settings.coba_field = 'DENSITY'
+
         # set correct cache file format for smoke
         obj.modifiers[-1].domain_settings.cache_data_format = 'UNI'
 
@@ -520,6 +523,9 @@ class QuickLiquid(Operator):
         # change domain type, will also allocate and show particle system for FLIP
         obj.modifiers[-1].domain_settings.domain_type = 'LIQUID'
 
+        # set color mapping field to show phi grid for liquid
+        obj.modifiers[-2].domain_settings.coba_field = 'PHI'
+
         # make the domain smooth so it renders nicely
         bpy.ops.object.shade_smooth()
 
diff --git a/release/scripts/startup/bl_ui/properties_physics_fluid.py b/release/scripts/startup/bl_ui/properties_physics_fluid.py
index f0d59e3a898..488f48f84c7 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fluid.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fluid.py
@@ -1292,16 +1292,12 @@ class PHYSICS_PT_viewport_display_color(PhysicButtonsPanel, Panel):
         domain = context.fluid.domain_settings
         col = layout.column()
         col.active = domain.use_color_ramp
-        if (domain.domain_type == "GAS"):
-            col.prop(domain, "coba_field_gas")
-        else:
-            col.prop(domain, "coba_field_liquid")
-
+        col.prop(domain, "coba_field")
         col.prop(domain, "coba_field_scale")
 
         col.use_property_split = False
 
-        if (domain.domain_type == "GAS" or (not domain.coba_field_liquid == "PHI")):
+        if (not domain.coba_field == "PHI"):
             col = col.column()
             col.template_color_ramp(domain, "color_ramp", expand=True)
 
diff --git a/source/blender/blenkernel/BKE_fluid.h b/source/blender/blenkernel/BKE_fluid.h
index e06a1a9fb92..f89f104ba23 100644
--- a/source/blender/blenkernel/BKE_fluid.h
+++ b/source/blender/blenkernel/BKE_fluid.h
@@ -94,6 +94,7 @@ void BKE_fluid_flow_type_set(struct Object *object, struct FluidFlowSettings *se
 void BKE_fluid_effector_type_set(struct Object *object,
                                  struct FluidEffectorSettings *settings,
                                  int type);
+void BKE_fluid_coba_field_check(struct Object *object, struct FluidDomainSettings *settings);
 void BKE_fluid_flow_behavior_set(struct Object *object,
                                  struct FluidFlowSettings *settings,
                                  int behavior);
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index a3194605e57..e0cb9c2a15d 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -4663,6 +4663,29 @@ void BKE_fluid_effector_type_set(Object *UNUSED(object), FluidEffectorSettings *
   settings->type = type;
 }
 
+void BKE_fluid_coba_field_check(Object *object, FluidDomainSettings *settings)
+{
+  /* Based on the domain type, the coba field is defaulted accordingly if the selected field
+   * is unsupported. */
+  const char field = settings->coba_field;
+
+  if (settings->type == FLUID_DOMAIN_TYPE_GAS) {
+    if (field == FLUID_DOMAIN_FIELD_PHI) {
+      /* Defaulted to density for gas domain. */
+      settings->coba_field = FLUID_DOMAIN_FIELD_DENSITY;
+    }
+  }
+  else if (settings->type == FLUID_DOMAIN_TYPE_LIQUID) {
+    if (field == FLUID_DOMAIN_FIELD_COLOR_R || field == FLUID_DOMAIN_FIELD_COLOR_G ||
+        field == FLUID_DOMAIN_FIELD_COLOR_B || field == FLUID_DOMAIN_FIELD_DENSITY ||
+        field == FLUID_DOMAIN_FIELD_FLAME || field == FLUID_DOMAIN_FIELD_FUEL ||
+        field == FLUID_DOMAIN_FIELD_HEAT) {
+      /* Defaulted to phi for liquid domain. */
+      settings->coba_field = FLUID_DOMAIN_FIELD_PHI;
+    }
+  }
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/makesrna/intern/rna_fluid.c b/source/blender/makesrna/intern/rna_fluid.c
index a29c08c1853..1905c0cd2a2 100644
--- a/source/blender/makesrna/intern/rna_fluid.c
+++ b/source/blender/makesrna/intern/rna_fluid.c
@@ -632,6 +632,7 @@ static void rna_Fluid_domaintype_set(struct PointerRNA *ptr, int value)
   FluidDomainSettings *settings = (FluidDomainSettings *)ptr->data;
   Object *ob = (Object *)ptr->owner_id;
   BKE_fluid_domain_type_set(ob, settings, value);
+  BKE_fluid_coba_field_check(ob, settings);
 }
 
 static char *rna_FluidDomainSettings_path(PointerRNA *ptr)
@@ -999,6 +1000,112 @@ static void rna_Fluid_flowtype_set(struct PointerRNA *ptr, int value)
   }
 }
 
+static void rna_Fluid_cobafield_set(struct PointerRNA *ptr, int value)
+{
+  FluidDomainSettings *settings = (FluidDomainSettings *)ptr->data;
+
+  if (value != settings->coba_field) {
+    settings->coba_field = value;
+  }
+}
+
+static const EnumPropertyItem *rna_Fluid_cobafield_itemf(bContext *UNUSED(C),
+                                                         PointerRNA *ptr,
+                                                         PropertyRNA *UNUSED(prop),
+                                                         bool *r_free)
+{
+  FluidDomainSettings *settings = (FluidDomainSettings *)ptr->data;
+
+  EnumPropertyItem *item = NULL;
+  EnumPropertyItem tmp = {0, "", 0, "", ""};
+  int totitem = 0;
+
+  tmp.value = FLUID_DOMAIN_FIELD_VELOCITY_X;
+  tmp.identifier = "VELOCITY_X";
+  tmp.icon = 0;
+  tmp.name = "X Velocity";
+  tmp.description = "X component of the velocity field";
+  RNA_enum_item_add(&item, &totitem, &tmp);
+
+  tmp.value = FLUID_DOMAIN_FIELD_VELOCITY_Y;
+  tmp.identifier = "VELOCITY_Y";
+  tmp.icon = 0;
+  tmp.name = "Y Velocity";
+  tmp.description = "Y component of the velocity field";
+  RNA_enum_item_add(&item, &totitem, &tmp);
+
+  tmp.value = FLUID_DOMAIN_FIELD_VELOCITY_Z;
+  tmp.identifier = "VELOCITY_Z";
+  tmp.icon = 0;
+  tmp.name = "Z Velocity";
+  tmp.description = "Z component of the velocity field";
+  RNA_enum_item_add(&item, &totitem, &tmp);
+
+  if (settings->type == FLUID_DOMAIN_TYPE_GAS) {
+    tmp.value = FLUID_DOMAIN_FIELD_COLOR_R;
+    tmp.identifier = "COLOR_R";
+    tmp.icon = 0;
+    tmp.name = "Red";
+    tmp.description = "Red component of the color field";
+    RNA_enum_item_add(&item, &totitem, &tmp);
+
+    tmp.value = FLUID_DOMAIN_FIELD_COLOR_G;
+    tmp.identifier = "COLOR_G";
+    tmp.icon = 0;
+    tmp.name = "Green";
+    tmp.description = "Green component of the color field";
+    RNA_enum_item_add(&item, &totitem, &tmp);
+
+    tmp.value = FLUID_DOMAIN_FIELD_COLOR_B;
+    tmp.identifier = "COLOR_B";
+    tmp.icon = 0;
+    tmp.name = "Blue";
+    tmp.description = "Blue component of the color field";
+    RNA_enum_item_add(&item, &totitem, &tmp);
+
+    tmp.value = FLUID_DOMAIN_FIELD_DENSITY;
+    tmp.identifier = "DENSITY";
+    tmp.icon = 0;
+    tmp.name = "Density";
+    tmp.description = "Quantity of soot in the fluid";
+    RNA_enum_item_add(&item, &totitem, &tmp);
+
+    tmp.value = FLUID_DOMAIN_FIELD_FLAME;
+    tmp.identifier = "FLAME";
+    tmp.icon = 0;
+    tmp.name = "Flame";
+    tmp.description = "Flame field";
+    RNA_enum_item_add(&item, &totitem, &tmp);
+
+    tmp.value = FLUID_DOMAIN_FIELD_FUEL;
+    tmp.identifier = "FUEL";
+    tmp.icon = 0;
+    tmp.name = "Fuel";
+    tmp.description = "Fuel field";
+    RNA_enum_item_add(&item, &totitem, &tmp);
+
+    tmp.value = FLUID_DOMAIN_FIELD_HEAT;
+    tmp.identifier = "HEAT";
+    tmp.icon = 0;
+    tmp.name = "Heat";
+    tmp.description = "Temperature of the fluid";
+    RNA_enum_item_add(&item, &totitem, &tmp);
+  }
+  else if (settings->type == FLUID_DOMAIN_TYPE_LIQUID) {
+    tmp.value = FLUID_DOMAIN_FIELD_PHI;
+    tmp.identifier = "PHI";
+    tmp.icon = 0;
+    tmp.name = "Phi";
+    tmp.description = "Phi grid";
+    RNA_enum_item_add(&item, &totitem, &tmp);
+  }
+
+  RNA_enum_item_end(&item, &totitem);
+  *r_free = true;
+
+  return item;
+}
+
 #else
 
 static void rna_def_fluid_mesh_vertices(BlenderRNA *brna)
@@ -2275,61 +2382,16 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
       "Render a simulation field while mapping its voxels values to the colors of a ramp");
   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
 
-  static const EnumPropertyItem coba_field_gas_items[] = {
-      {FLUID_DOMAIN_FIELD_COLOR_R, "COLOR_R", 0, "Red", "Red component of the color field"},
-      {FLUID_DOMAIN_FIELD_COLOR_G, "COLOR_G", 0, "Green", "Green component of the color field"},
-      {FLUID_DOMAIN_FIELD_COLOR_B, "COLOR_B", 0, "Blue", "Blue component of the color field"},
-      {FLUID_DOMAIN_FIELD_DENSITY, "DENSITY", 0, "Density", "Quantity of soot in the fluid"},
-      {FLUID_DOMAIN_FIELD_FLAME, "FLAME", 0, "Flame", "Flame field"},
-      {FLUID_DOMAIN_FIELD_FUEL, "FUEL", 0, "Fuel", "Fuel field"},
-      {FLUID_DOMAIN_FIELD_HEAT, "HEAT", 0, "Heat", "Temperature of the fluid"},
-      {FLUID_DOMAIN_FIELD_VELOCITY_X,
-       "VELOCITY_X",
-       0,
-       "X Velocity",
-       "X component of the velocity field"},
-      {FLUID_DOMAIN_FIELD_VELOCITY_Y,
-       "VELOCITY_Y",
-       0,
-       "Y Velocity",
-       "Y component of the velocity field"},
-      {FLUID_DOMAIN_FIELD_VELOCITY_Z,
-       "VELOCITY_Z",
-       0,
-       "Z Velocity",
-       "Z component of the velocity field"},
-      {0, NULL, 0, NULL, NULL},
-  };
-
-  static const EnumPropertyItem coba_field_liquid_items[] = {
-      {FLUID_DOMAIN_FIELD_VELOCITY_X,
-       "VELOCITY_X",
-       0,
-       "X Velocity",
-       "X component of the velocity field"},
-      {FLUID_DOMAIN_FIELD_VELOCITY_Y,
-       "VELOCITY_Y",
-       0,
-       "Y Velocity",
-       "Y component of the velocity field"},
-      {FLUID_DOMAIN_FIELD_VELOCITY_Z,
-       "VE

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list