Code cleanup: simpler and faster detection of BVH refit.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 25 Jan 2018 15:11:06 +0000 (16:11 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 26 Jan 2018 07:41:19 +0000 (08:41 +0100)
intern/cycles/blender/blender_mesh.cpp
intern/cycles/util/util_vector.h

index cfbc868938ebc62a1e64d1b81fb97d8e4a4666a5..3b07464cd960f1739b6b2034588525e2f78a2f11 100644 (file)
@@ -1138,12 +1138,19 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
        mesh_synced.insert(mesh);
 
        /* create derived mesh */
-       array<int> oldtriangle = mesh->triangles;
+       array<int> oldtriangles;
+       array<Mesh::SubdFace> oldsubd_faces;
+       array<int> oldsubd_face_corners;
+       oldtriangles.steal_data(mesh->triangles);
+       oldsubd_faces.steal_data(mesh->subd_faces);
+       oldsubd_face_corners.steal_data(mesh->subd_face_corners);
 
        /* compares curve_keys rather than strands in order to handle quick hair
         * adjustments in dynamic BVH - other methods could probably do this better*/
-       array<float3> oldcurve_keys = mesh->curve_keys;
-       array<float> oldcurve_radius = mesh->curve_radius;
+       array<float3> oldcurve_keys;
+       array<float> oldcurve_radius;
+       oldcurve_keys.steal_data(mesh->curve_keys);
+       oldcurve_radius.steal_data(mesh->curve_radius);
 
        mesh->clear();
        mesh->used_shaders = used_shaders;
@@ -1206,28 +1213,11 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
        sync_mesh_fluid_motion(b_ob, scene, mesh);
 
        /* tag update */
-       bool rebuild = false;
-
-       if(oldtriangle.size() != mesh->triangles.size())
-               rebuild = true;
-       else if(oldtriangle.size()) {
-               if(memcmp(&oldtriangle[0], &mesh->triangles[0], sizeof(int)*oldtriangle.size()) != 0)
-                       rebuild = true;
-       }
-
-       if(oldcurve_keys.size() != mesh->curve_keys.size())
-               rebuild = true;
-       else if(oldcurve_keys.size()) {
-               if(memcmp(&oldcurve_keys[0], &mesh->curve_keys[0], sizeof(float3)*oldcurve_keys.size()) != 0)
-                       rebuild = true;
-       }
-
-       if(oldcurve_radius.size() != mesh->curve_radius.size())
-               rebuild = true;
-       else if(oldcurve_radius.size()) {
-               if(memcmp(&oldcurve_radius[0], &mesh->curve_radius[0], sizeof(float)*oldcurve_radius.size()) != 0)
-                       rebuild = true;
-       }
+       bool rebuild = (oldtriangles != mesh->triangles) ||
+                      (oldsubd_faces != mesh->subd_faces) ||
+                      (oldsubd_face_corners != mesh->subd_face_corners) ||
+                      (oldcurve_keys != mesh->curve_keys) ||
+                      (oldcurve_radius != mesh->curve_radius);
 
        mesh->tag_update(scene, rebuild);
 
index 67bf82b47a5c05eedb82919a4ca79e0c47bebbb8..625c19c7c46422c156daddc8e7861058e3fd2cc8 100644 (file)
@@ -162,6 +162,11 @@ public:
                return memcmp(data_, other.data_, datasize_*sizeof(T)) == 0;
        }
 
+       bool operator!=(const array<T>& other) const
+       {
+               return !(*this == other);
+       }
+
        void steal_data(array& from)
        {
                if(this != &from) {