Merge branch 'master' into blender2.8
[blender.git] / intern / cycles / blender / blender_curves.cpp
index 39521c841d133d05b92542eb80a07cb7691ef0c2..7b9d4f2ecdfe88e1d9cd721a88f1301df816d2fe 100644 (file)
@@ -134,10 +134,7 @@ void ExportCurveTrianglePlanes(Mesh *mesh, ParticleCurveData *CData,
                }
        }
 
-       mesh->verts.reserve(mesh->verts.size() + numverts);
-       mesh->triangles.reserve(mesh->triangles.size() + numtris);
-       mesh->shader.reserve(mesh->shader.size() + numtris);
-       mesh->smooth.reserve(mesh->smooth.size() + numtris);
+       mesh->reserve_mesh(mesh->verts.size() + numverts, mesh->num_triangles() + numtris);
 
        /* actually export */
        for(int sys = 0; sys < CData->psys_firstcurve.size() ; sys++) {
@@ -157,8 +154,8 @@ void ExportCurveTrianglePlanes(Mesh *mesh, ParticleCurveData *CData,
                                xbasis = normalize(cross(RotCam - ickey_loc, v1));
                        float3 ickey_loc_shfl = ickey_loc - radius * xbasis;
                        float3 ickey_loc_shfr = ickey_loc + radius * xbasis;
-                       mesh->verts.push_back(ickey_loc_shfl);
-                       mesh->verts.push_back(ickey_loc_shfr);
+                       mesh->add_vertex(ickey_loc_shfl);
+                       mesh->add_vertex(ickey_loc_shfr);
                        vertexindex += 2;
 
                        for(int curvekey = CData->curve_firstkey[curve] + 1; curvekey < CData->curve_firstkey[curve] + CData->curve_keynum[curve]; curvekey++) {
@@ -184,8 +181,8 @@ void ExportCurveTrianglePlanes(Mesh *mesh, ParticleCurveData *CData,
                                        xbasis = normalize(cross(RotCam - ickey_loc, v1));
                                float3 ickey_loc_shfl = ickey_loc - radius * xbasis;
                                float3 ickey_loc_shfr = ickey_loc + radius * xbasis;
-                               mesh->verts.push_back(ickey_loc_shfl);
-                               mesh->verts.push_back(ickey_loc_shfr);
+                               mesh->add_vertex(ickey_loc_shfl);
+                               mesh->add_vertex(ickey_loc_shfr);
                                mesh->add_triangle(vertexindex-2, vertexindex, vertexindex-1, CData->psys_shader[sys], true);
                                mesh->add_triangle(vertexindex+1, vertexindex-1, vertexindex, CData->psys_shader[sys], true);
                                vertexindex += 2;
@@ -193,7 +190,6 @@ void ExportCurveTrianglePlanes(Mesh *mesh, ParticleCurveData *CData,
                }
        }
 
-       mesh->reserve(mesh->verts.size(), mesh->triangles.size(), 0, 0);
        mesh->attributes.remove(ATTR_STD_VERTEX_NORMAL);
        mesh->attributes.remove(ATTR_STD_FACE_NORMAL);
        mesh->add_face_normals();
@@ -220,10 +216,7 @@ void ExportCurveTriangleGeometry(Mesh *mesh, ParticleCurveData *CData, int resol
                }
        }
 
-       mesh->verts.reserve(mesh->verts.size() + numverts);
-       mesh->triangles.reserve(mesh->triangles.size() + numtris);
-       mesh->shader.reserve(mesh->shader.size() + numtris);
-       mesh->smooth.reserve(mesh->smooth.size() + numtris);
+       mesh->reserve_mesh(mesh->verts.size() + numverts, mesh->num_triangles() + numtris);
 
        /* actually export */
        for(int sys = 0; sys < CData->psys_firstcurve.size() ; sys++) {
@@ -312,7 +305,7 @@ void ExportCurveTriangleGeometry(Mesh *mesh, ParticleCurveData *CData, int resol
                                        float angle = M_2PI_F / (float)resolution;
                                        for(int section = 0; section < resolution; section++) {
                                                float3 ickey_loc_shf = ickey_loc + radius * (cosf(angle * section) * xbasis + sinf(angle * section) * ybasis);
-                                               mesh->verts.push_back(ickey_loc_shf);
+                                               mesh->add_vertex(ickey_loc_shf);
                                        }
 
                                        if(subv != 0) {
@@ -329,7 +322,6 @@ void ExportCurveTriangleGeometry(Mesh *mesh, ParticleCurveData *CData, int resol
                }
        }
 
-       mesh->reserve(mesh->verts.size(), mesh->triangles.size(), 0, 0);
        mesh->attributes.remove(ATTR_STD_VERTEX_NORMAL);
        mesh->attributes.remove(ATTR_STD_FACE_NORMAL);
        mesh->add_face_normals();
@@ -344,7 +336,7 @@ void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CData)
        int num_keys = 0;
        int num_curves = 0;
 
-       if(!(mesh->curves.empty() && mesh->curve_keys.empty()))
+       if(mesh->num_curves())
                return;
 
        Attribute *attr_intercept = NULL;
@@ -367,8 +359,7 @@ void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CData)
                VLOG(1) << "Exporting curve segments for mesh " << mesh->name;
        }
 
-       mesh->curve_keys.reserve(mesh->curve_keys.size() + num_keys);
-       mesh->curves.reserve(mesh->curves.size() + num_curves);
+       mesh->reserve_curves(mesh->num_curves() + num_curves, mesh->curve_keys.size() + num_keys);
 
        num_keys = 0;
        num_curves = 0;
@@ -396,18 +387,16 @@ void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CData)
                                num_curve_keys++;
                        }
 
-                       mesh->add_curve(num_keys, num_curve_keys, CData->psys_shader[sys]);
+                       mesh->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->curves.size() != num_curves)) {
+       if((mesh->curve_keys.size() != num_keys) || (mesh->num_curves() != num_curves)) {
                VLOG(1) << "Allocation failed, clearing data";
-               mesh->curve_keys.clear();
-               mesh->curves.clear();
-               mesh->curve_attributes.clear();
+               mesh->clear();
        }
 }
 
@@ -450,13 +439,16 @@ static void ExportCurveSegmentsMotion(Mesh *mesh, ParticleCurveData *CData, int
                                        if(CData->psys_closetip[sys] && (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 1))
                                                radius = 0.0f;
 
+                                       /* curve motion keys store both position and radius in float4 */
                                        mP[i] = float3_to_float4(ickey_loc);
                                        mP[i].w = radius;
 
                                        /* unlike mesh coordinates, these tend to be slightly different
                                         * between frames due to particle transforms into/out of object
                                         * space, so we use an epsilon to detect actual changes */
-                                       if(len_squared(mP[i] - mesh->curve_keys[i]) > 1e-5f*1e-5f)
+                                       float4 curve_key = float3_to_float4(mesh->curve_keys[i]);
+                                       curve_key.w = mesh->curve_radius[i];
+                                       if(len_squared(mP[i] - curve_key) > 1e-5f*1e-5f)
                                                have_motion = true;
                                }
 
@@ -480,8 +472,10 @@ static void ExportCurveSegmentsMotion(Mesh *mesh, ParticleCurveData *CData, int
                        for(int step = 0; step < time_index; step++) {
                                float4 *mP = attr_mP->data_float4() + step*numkeys;
 
-                               for(int key = 0; key < numkeys; key++)
-                                       mP[key] = mesh->curve_keys[key];
+                               for(int key = 0; key < numkeys; key++) {
+                                       mP[key] = float3_to_float4(mesh->curve_keys[key]);
+                                       mP[key].w = mesh->curve_radius[key];
+                               }
                        }
                }
        }
@@ -641,7 +635,9 @@ void BlenderSync::sync_curves(Mesh *mesh,
        if(!motion) {
                /* Clear stored curve data */
                mesh->curve_keys.clear();
-               mesh->curves.clear();
+               mesh->curve_radius.clear();
+               mesh->curve_first_key.clear();
+               mesh->curve_shader.clear();
                mesh->curve_attributes.clear();
        }
 
@@ -658,7 +654,7 @@ void BlenderSync::sync_curves(Mesh *mesh,
        int triangle_method = scene->curve_system_manager->triangle_method;
        int resolution = scene->curve_system_manager->resolution;
        size_t vert_num = mesh->verts.size();
-       size_t tri_num = mesh->triangles.size();
+       size_t tri_num = mesh->num_triangles();
        int used_res = 1;
 
        /* extract particle hair data - should be combined with connecting to mesh later*/
@@ -714,11 +710,10 @@ void BlenderSync::sync_curves(Mesh *mesh,
                        else {
                                Attribute *attr_generated = mesh->curve_attributes.add(ATTR_STD_GENERATED);
                                float3 *generated = attr_generated->data_float3();
-                               size_t i = 0;
 
-                               foreach(Mesh::Curve& curve, mesh->curves) {
-                                       float3 co = float4_to_float3(mesh->curve_keys[curve.first_key]);
-                                       generated[i++] = co*size - loc;
+                               for(size_t i = 0; i < mesh->num_curves(); i++) {
+                                       float3 co = mesh->curve_keys[mesh->get_curve(i).first_key];
+                                       generated[i] = co*size - loc;
                                }
                        }
                }