[Bf-blender-cvs] [d9c5f0d25fc] master: Cleanup: split Cycles Hair and Mesh classes, with Geometry base class

Brecht Van Lommel noreply at git.blender.org
Fri Feb 7 12:22:06 CET 2020


Commit: d9c5f0d25fc91b069158ae1ab4fddc21bfd85846
Author: Brecht Van Lommel
Date:   Sun Feb 2 12:04:19 2020 +0100
Branches: master
https://developer.blender.org/rBd9c5f0d25fc91b069158ae1ab4fddc21bfd85846

Cleanup: split Cycles Hair and Mesh classes, with Geometry base class

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

M	intern/cycles/app/cycles_xml.cpp
M	intern/cycles/blender/blender_curves.cpp
M	intern/cycles/blender/blender_geometry.cpp
M	intern/cycles/blender/blender_id_map.h
M	intern/cycles/blender/blender_light.cpp
M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_object.cpp
M	intern/cycles/blender/blender_particles.cpp
M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/blender/blender_sync.cpp
M	intern/cycles/blender/blender_sync.h
M	intern/cycles/bvh/bvh.cpp
M	intern/cycles/bvh/bvh.h
M	intern/cycles/bvh/bvh2.cpp
M	intern/cycles/bvh/bvh2.h
M	intern/cycles/bvh/bvh4.cpp
M	intern/cycles/bvh/bvh4.h
M	intern/cycles/bvh/bvh8.cpp
M	intern/cycles/bvh/bvh8.h
M	intern/cycles/bvh/bvh_build.cpp
M	intern/cycles/bvh/bvh_build.h
M	intern/cycles/bvh/bvh_embree.cpp
M	intern/cycles/bvh/bvh_embree.h
M	intern/cycles/bvh/bvh_optix.cpp
M	intern/cycles/bvh/bvh_optix.h
M	intern/cycles/bvh/bvh_params.h
M	intern/cycles/bvh/bvh_split.cpp
M	intern/cycles/bvh/bvh_split.h
M	intern/cycles/bvh/bvh_unaligned.cpp
M	intern/cycles/device/device_optix.cpp
M	intern/cycles/graph/node_type.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/CMakeLists.txt
M	intern/cycles/render/attribute.cpp
M	intern/cycles/render/attribute.h
M	intern/cycles/render/bake.cpp
M	intern/cycles/render/camera.cpp
M	intern/cycles/render/film.cpp
A	intern/cycles/render/geometry.cpp
A	intern/cycles/render/geometry.h
A	intern/cycles/render/hair.cpp
A	intern/cycles/render/hair.h
M	intern/cycles/render/light.cpp
M	intern/cycles/render/mesh.cpp
M	intern/cycles/render/mesh.h
M	intern/cycles/render/mesh_displace.cpp
M	intern/cycles/render/mesh_volume.cpp
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/object.cpp
M	intern/cycles/render/object.h
M	intern/cycles/render/scene.cpp
M	intern/cycles/render/scene.h
M	intern/cycles/render/session.cpp
M	intern/cycles/render/shader.cpp
M	intern/cycles/render/shader.h

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

diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp
index bdb014d31ef..2540786a014 100644
--- a/intern/cycles/app/cycles_xml.cpp
+++ b/intern/cycles/app/cycles_xml.cpp
@@ -380,11 +380,11 @@ static Mesh *xml_add_mesh(Scene *scene, const Transform &tfm)
 {
   /* create mesh */
   Mesh *mesh = new Mesh();
-  scene->meshes.push_back(mesh);
+  scene->geometry.push_back(mesh);
 
   /* create object*/
   Object *object = new Object();
-  object->mesh = mesh;
+  object->geometry = mesh;
   object->tfm = tfm;
   scene->objects.push_back(object);
 
diff --git a/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp
index e42151d8f48..affd5685337 100644
--- a/intern/cycles/blender/blender_curves.cpp
+++ b/intern/cycles/blender/blender_curves.cpp
@@ -17,6 +17,7 @@
 #include "render/attribute.h"
 #include "render/camera.h"
 #include "render/curves.h"
+#include "render/hair.h"
 #include "render/mesh.h"
 #include "render/object.h"
 #include "render/scene.h"
@@ -107,12 +108,12 @@ static void InterpolateKeySegments(
 }
 
 static bool ObtainCacheParticleData(
-    Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool background)
+    Geometry *geom, BL::Mesh *b_mesh, BL::Object *b_ob, ParticleCurveData *CData, bool background)
 {
   int curvenum = 0;
   int keyno = 0;
 
-  if (!(mesh && b_mesh && b_ob && CData))
+  if (!(geom && b_mesh && b_ob && CData))
     return false;
 
   Transform tfm = get_transform(b_ob->matrix_world());
@@ -128,7 +129,7 @@ static bool ObtainCacheParticleData(
 
       if ((b_part.render_type() == BL::ParticleSettings::render_type_PATH) &&
           (b_part.type() == BL::ParticleSettings::type_HAIR)) {
-        int shader = clamp(b_part.material() - 1, 0, mesh->used_shaders.size() - 1);
+        int shader = clamp(b_part.material() - 1, 0, geom->used_shaders.size() - 1);
         int display_step = background ? b_part.render_step() : b_part.display_step();
         int totparts = b_psys.particles.length();
         int totchild = background ? b_psys.child_particles.length() :
@@ -202,14 +203,14 @@ static bool ObtainCacheParticleData(
   return true;
 }
 
-static bool ObtainCacheParticleUV(Mesh *mesh,
+static bool ObtainCacheParticleUV(Geometry *geom,
                                   BL::Mesh *b_mesh,
                                   BL::Object *b_ob,
                                   ParticleCurveData *CData,
                                   bool background,
                                   int uv_num)
 {
-  if (!(mesh && b_mesh && b_ob && CData))
+  if (!(geom && b_mesh && b_ob && CData))
     return false;
 
   CData->curve_uv.clear();
@@ -265,14 +266,14 @@ static bool ObtainCacheParticleUV(Mesh *mesh,
   return true;
 }
 
-static bool ObtainCacheParticleVcol(Mesh *mesh,
+static bool ObtainCacheParticleVcol(Geometry *geom,
                                     BL::Mesh *b_mesh,
                                     BL::Object *b_ob,
                                     ParticleCurveData *CData,
                                     bool background,
                                     int vcol_num)
 {
-  if (!(mesh && b_mesh && b_ob && CData))
+  if (!(geom && b_mesh && b_ob && CData))
     return false;
 
   CData->curve_vcol.clear();
@@ -594,21 +595,55 @@ static void ExportCurveTriangleGeometry(Mesh *mesh, ParticleCurveData *CData, in
   /* texture coords still needed */
 }
 
-static void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CData)
+static void export_hair_motion_validate_attribute(Hair *hair,
+                                                  int motion_step,
+                                                  int num_motion_keys,
+                                                  bool have_motion)
+{
+  Attribute *attr_mP = hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
+  const int num_keys = hair->curve_keys.size();
+
+  if (num_motion_keys != num_keys || !have_motion) {
+    /* No motion or hair "topology" changed, remove attributes again. */
+    if (num_motion_keys != num_keys) {
+      VLOG(1) << "Hair topology changed, removing attribute.";
+    }
+    else {
+      VLOG(1) << "No motion, removing attribute.";
+    }
+    hair->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION);
+  }
+  else if (motion_step > 0) {
+    VLOG(1) << "Filling in new motion vertex position for motion_step " << motion_step;
+
+    /* Motion, fill up previous steps that we might have skipped because
+     * they had no motion, but we need them anyway now. */
+    for (int step = 0; step < motion_step; step++) {
+      float4 *mP = attr_mP->data_float4() + step * num_keys;
+
+      for (int key = 0; key < num_keys; key++) {
+        mP[key] = float3_to_float4(hair->curve_keys[key]);
+        mP[key].w = hair->curve_radius[key];
+      }
+    }
+  }
+}
+
+static void ExportCurveSegments(Scene *scene, Hair *hair, ParticleCurveData *CData)
 {
   int num_keys = 0;
   int num_curves = 0;
 
-  if (mesh->num_curves())
+  if (hair->num_curves())
     return;
 
   Attribute *attr_intercept = NULL;
   Attribute *attr_random = NULL;
 
-  if (mesh->need_attribute(scene, ATTR_STD_CURVE_INTERCEPT))
-    attr_intercept = mesh->curve_attributes.add(ATTR_STD_CURVE_INTERCEPT);
-  if (mesh->need_attribute(scene, ATTR_STD_CURVE_RANDOM))
-    attr_random = mesh->curve_attributes.add(ATTR_STD_CURVE_RANDOM);
+  if (hair->need_attribute(scene, ATTR_STD_CURVE_INTERCEPT))
+    attr_intercept = hair->attributes.add(ATTR_STD_CURVE_INTERCEPT);
+  if (hair->need_attribute(scene, ATTR_STD_CURVE_RANDOM))
+    attr_random = hair->attributes.add(ATTR_STD_CURVE_RANDOM);
 
   /* compute and reserve size of arrays */
   for (int sys = 0; sys < CData->psys_firstcurve.size(); sys++) {
@@ -621,10 +656,10 @@ static void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CDa
   }
 
   if (num_curves > 0) {
-    VLOG(1) << "Exporting curve segments for mesh " << mesh->name;
+    VLOG(1) << "Exporting curve segments for mesh " << hair->name;
   }
 
-  mesh->reserve_curves(mesh->num_curves() + num_curves, mesh->curve_keys.size() + num_keys);
+  hair->reserve_curves(hair->num_curves() + num_curves, hair->curve_keys.size() + num_keys);
 
   num_keys = 0;
   num_curves = 0;
@@ -649,7 +684,7 @@ static void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CDa
             (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1)) {
           radius = 0.0f;
         }
-        mesh->add_curve_key(ickey_loc, radius);
+        hair->add_curve_key(ickey_loc, radius);
         if (attr_intercept)
           attr_intercept->add(time);
 
@@ -660,16 +695,16 @@ static void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CDa
         attr_random->add(hash_uint2_to_float(num_curves, 0));
       }
 
-      mesh->add_curve(num_keys, CData->psys_shader[sys]);
+      hair->add_curve(num_keys, CData->psys_shader[sys]);
       num_keys += num_curve_keys;
       num_curves++;
     }
   }
 
   /* check allocation */
-  if ((mesh->curve_keys.size() != num_keys) || (mesh->num_curves() != num_curves)) {
+  if ((hair->curve_keys.size() != num_keys) || (hair->num_curves() != num_curves)) {
     VLOG(1) << "Allocation failed, clearing data";
-    mesh->clear();
+    hair->clear();
   }
 }
 
@@ -713,24 +748,24 @@ static float4 LerpCurveSegmentMotionCV(ParticleCurveData *CData, int sys, int cu
   return lerp(mP, mP2, remainder);
 }
 
-static void ExportCurveSegmentsMotion(Mesh *mesh, ParticleCurveData *CData, int motion_step)
+static void ExportCurveSegmentsMotion(Hair *hair, ParticleCurveData *CData, int motion_step)
 {
-  VLOG(1) << "Exporting curve motion segments for mesh " << mesh->name << ", motion step "
+  VLOG(1) << "Exporting curve motion segments for hair " << hair->name << ", motion step "
           << motion_step;
 
   /* find attribute */
-  Attribute *attr_mP = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
+  Attribute *attr_mP = hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
   bool new_attribute = false;
 
   /* add new attribute if it doesn't exist already */
   if (!attr_mP) {
     VLOG(1) << "Creating new motion vertex position attribute";
-    attr_mP = mesh->curve_attributes.add(ATTR_STD_MOTION_VERTEX_POSITION);
+    attr_mP = hair->attributes.add(ATTR_STD_MOTION_VERTEX_POSITION);
     new_attribute = true;
   }
 
   /* export motion vectors for curve keys */
-  size_t numkeys = mesh->curve_keys.size();
+  size_t numkeys = hair->curve_keys.size();
   float4 *mP = attr_mP->data_float4() + motion_step * numkeys;
   bool have_motion = false;
   int i = 0;
@@ -741,24 +776,24 @@ static void ExportCurveSegmentsMotion(Mesh *mesh, ParticleCurveData *CData, int
          curve < CData->psys_firstcurve[sys] + CData->psys_curvenum[sys];
          curve++) {
       /* Curve lengths may not match! Curves can be clipped. */
-      int curve_key_end = (num_curves + 1 < (int)mesh->curve_first_key.size() ?
-                               mesh->curve_first_key[num_curves + 1] :
-                               (int)mesh->curve_keys.size());
-      const int num_center_curve_keys = curve_key_end - mesh->curve_first_key[num_curves];
+      int curve_key_end = (num_curves + 1 < (int)hair->curve_first_key.size() ?
+                               hair->curve_first_key[num_curves + 1] :
+                               (int)hair->curve_keys.size());
+      const int num_center_curve_keys = curve_key_end - hair->curve_first_key[num_curves];
       const int is_num_keys_different = CData->curve_keynum[curve] - num_center_curve_keys;
 
       if (!is_num_keys_different) {
         for (int curvekey = CData->curve_firstkey[curve];
              curvekey < CData->curve_firstkey[curve] + CData->curve_keynum[curve];
              curvekey++) {
-          if (i < mesh->curve_keys.size()) {
+          if (i < hair->curve_keys.size()) {
             mP[i] = CurveSegmentMotionCV(CData, sys, curve, curvekey);
             if (!have_motion) {
               /* unlike mesh coordinates, these tend to be slightly different
                * between frames due to particle transforms into/out of object
                * space, so w

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list