diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-05-08 01:09:08 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2016-06-08 22:45:40 +0300 |
commit | 2419d4c4ebf63c04c9c33efc8acc379d06661d9a (patch) | |
tree | 53901e787d0eff2d51b0a7b2a7b8e3dd7dec6bb7 /intern/cycles | |
parent | 13a7893495d7dacd5b12c9ac6a6fb5035ba1016d (diff) |
Code refactor: modify mesh storage to use arrays rather than vectors, separate some arrays.
Differential Revision: https://developer.blender.org/D2016
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/blender/blender_curves.cpp | 81 | ||||
-rw-r--r-- | intern/cycles/blender/blender_mesh.cpp | 41 | ||||
-rw-r--r-- | intern/cycles/blender/blender_particles.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh.cpp | 28 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh_build.cpp | 24 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh_split.cpp | 19 | ||||
-rw-r--r-- | intern/cycles/render/attribute.cpp | 20 | ||||
-rw-r--r-- | intern/cycles/render/attribute.h | 6 | ||||
-rw-r--r-- | intern/cycles/render/curves.h | 34 | ||||
-rw-r--r-- | intern/cycles/render/light.cpp | 8 | ||||
-rw-r--r-- | intern/cycles/render/mesh.cpp | 190 | ||||
-rw-r--r-- | intern/cycles/render/mesh.h | 51 | ||||
-rw-r--r-- | intern/cycles/render/mesh_displace.cpp | 9 | ||||
-rw-r--r-- | intern/cycles/render/object.cpp | 18 | ||||
-rw-r--r-- | intern/cycles/render/particles.cpp | 11 | ||||
-rw-r--r-- | intern/cycles/render/particles.h | 2 | ||||
-rw-r--r-- | intern/cycles/render/session.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/subd/subd_dice.cpp | 6 |
18 files changed, 299 insertions, 253 deletions
diff --git a/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp index 64f1b66405e..8fbb2414741 100644 --- a/intern/cycles/blender/blender_curves.cpp +++ b/intern/cycles/blender/blender_curves.cpp @@ -156,16 +156,16 @@ bool ObtainCacheParticleData(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, Par PointerRNA cpsys = RNA_pointer_get(&b_part.ptr, "cycles"); - CData->psys_firstcurve.push_back(curvenum); - CData->psys_curvenum.push_back(totcurves); - CData->psys_shader.push_back(shader); + CData->psys_firstcurve.push_back_slow(curvenum); + CData->psys_curvenum.push_back_slow(totcurves); + CData->psys_shader.push_back_slow(shader); float radius = get_float(cpsys, "radius_scale") * 0.5f; - CData->psys_rootradius.push_back(radius * get_float(cpsys, "root_width")); - CData->psys_tipradius.push_back(radius * get_float(cpsys, "tip_width")); - CData->psys_shape.push_back(get_float(cpsys, "shape")); - CData->psys_closetip.push_back(get_boolean(cpsys, "use_closetip")); + CData->psys_rootradius.push_back_slow(radius * get_float(cpsys, "root_width")); + CData->psys_tipradius.push_back_slow(radius * get_float(cpsys, "tip_width")); + CData->psys_shape.push_back_slow(get_float(cpsys, "shape")); + CData->psys_closetip.push_back_slow(get_boolean(cpsys, "use_closetip")); int pa_no = 0; if(!(b_part.child_type() == 0) && totchild != 0) @@ -180,7 +180,7 @@ bool ObtainCacheParticleData(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, Par for(; pa_no < totparts+totchild; pa_no++) { int keynum = 0; - CData->curve_firstkey.push_back(keyno); + CData->curve_firstkey.push_back_slow(keyno); float curve_length = 0.0f; float3 pcKey; @@ -195,15 +195,15 @@ bool ObtainCacheParticleData(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, Par continue; curve_length += step_length; } - CData->curvekey_co.push_back(cKey); - CData->curvekey_time.push_back(curve_length); + CData->curvekey_co.push_back_slow(cKey); + CData->curvekey_time.push_back_slow(curve_length); pcKey = cKey; keynum++; } keyno += keynum; - CData->curve_keynum.push_back(keynum); - CData->curve_length.push_back(curve_length); + CData->curve_keynum.push_back_slow(keynum); + CData->curve_length.push_back_slow(curve_length); curvenum++; } } @@ -255,7 +255,7 @@ bool ObtainCacheParticleUV(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, Parti float3 uv = make_float3(0.0f, 0.0f, 0.0f); if(b_mesh->tessface_uv_textures.length()) b_psys.uv_on_emitter(psmd, *b_pa, pa_no, uv_num, &uv.x); - CData->curve_uv.push_back(uv); + CData->curve_uv.push_back_slow(uv); if(pa_no < totparts && b_pa != b_psys.particles.end()) ++b_pa; @@ -309,7 +309,7 @@ bool ObtainCacheParticleVcol(Mesh *mesh, BL::Mesh *b_mesh, BL::Object *b_ob, Par float3 vcol = make_float3(0.0f, 0.0f, 0.0f); if(b_mesh->tessface_vertex_colors.length()) b_psys.mcol_on_emitter(psmd, *b_pa, pa_no, vcol_num, &vcol.x); - CData->curve_vcol.push_back(vcol); + CData->curve_vcol.push_back_slow(vcol); if(pa_no < totparts && b_pa != b_psys.particles.end()) ++b_pa; @@ -351,10 +351,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++) { @@ -374,8 +371,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++) { @@ -401,8 +398,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; @@ -410,7 +407,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(); @@ -437,10 +433,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++) { @@ -529,7 +522,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) { @@ -546,7 +539,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(); @@ -561,7 +553,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; @@ -584,8 +576,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; @@ -620,11 +611,9 @@ void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CData) } /* 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(); } } @@ -646,7 +635,7 @@ static void ExportCurveSegmentsMotion(Mesh *mesh, ParticleCurveData *CData, int /* export motion vectors for curve keys */ size_t numkeys = mesh->curve_keys.size(); - float4 *mP = attr_mP->data_float4() + time_index*numkeys; + float3 *mP = attr_mP->data_float3() + time_index*numkeys; bool have_motion = false; int i = 0; @@ -667,8 +656,7 @@ 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; - mP[i] = float3_to_float4(ickey_loc); - mP[i].w = radius; + mP[i] = ickey_loc; /* unlike mesh coordinates, these tend to be slightly different * between frames due to particle transforms into/out of object @@ -695,7 +683,7 @@ static void ExportCurveSegmentsMotion(Mesh *mesh, ParticleCurveData *CData, int /* 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 < time_index; step++) { - float4 *mP = attr_mP->data_float4() + step*numkeys; + float3 *mP = attr_mP->data_float3() + step*numkeys; for(int key = 0; key < numkeys; key++) mP[key] = mesh->curve_keys[key]; @@ -872,7 +860,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(); } @@ -889,7 +879,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*/ @@ -950,11 +940,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; } } } diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index 4a0ad79f3ae..80db51148e6 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -548,13 +548,12 @@ static void create_mesh(Scene *scene, numtris += (vi[3] == 0)? 1: 2; } - /* reserve memory */ - mesh->reserve(numverts, numtris, 0, 0); + /* allocate memory */ + mesh->reserve_mesh(numverts, numtris); /* create vertex coordinates and normals */ - int i = 0; - for(b_mesh.vertices.begin(v); v != b_mesh.vertices.end(); ++v, ++i) - mesh->verts[i] = get_float3(v->co()); + for(b_mesh.vertices.begin(v); v != b_mesh.vertices.end(); ++v) + mesh->add_vertex(get_float3(v->co())); Attribute *attr_N = mesh->attributes.add(ATTR_STD_VERTEX_NORMAL); float3 *N = attr_N->data_float3(); @@ -583,7 +582,7 @@ static void create_mesh(Scene *scene, /* create faces */ vector<int> nverts(numfaces); vector<int> face_flags(numfaces, FACE_FLAG_NONE); - int fi = 0, ti = 0; + int fi = 0; for(b_mesh.tessfaces.begin(f); f != b_mesh.tessfaces.end(); ++f, ++fi) { int4 vi = get_int4(f->vertices_raw()); @@ -618,18 +617,18 @@ static void create_mesh(Scene *scene, is_zero(cross(mesh->verts[vi[2]] - mesh->verts[vi[0]], mesh->verts[vi[3]] - mesh->verts[vi[0]]))) { // TODO(mai): order here is probably wrong - mesh->set_triangle(ti++, vi[0], vi[1], vi[3], shader, smooth, true); - mesh->set_triangle(ti++, vi[2], vi[3], vi[1], shader, smooth, true); + mesh->add_triangle(vi[0], vi[1], vi[3], shader, smooth, true); + mesh->add_triangle(vi[2], vi[3], vi[1], shader, smooth, true); face_flags[fi] |= FACE_FLAG_DIVIDE_24; } else { - mesh->set_triangle(ti++, vi[0], vi[1], vi[2], shader, smooth, true); - mesh->set_triangle(ti++, vi[0], vi[2], vi[3], shader, smooth, true); + mesh->add_triangle(vi[0], vi[1], vi[2], shader, smooth, true); + mesh->add_triangle(vi[0], vi[2], vi[3], shader, smooth, true); face_flags[fi] |= FACE_FLAG_DIVIDE_13; } } else - mesh->set_triangle(ti++, vi[0], vi[1], vi[2], shader, smooth, false); + mesh->add_triangle(vi[0], vi[1], vi[2], shader, smooth, false); nverts[fi] = n; } @@ -759,11 +758,12 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob, /* create derived mesh */ PointerRNA cmesh = RNA_pointer_get(&b_ob_data.ptr, "cycles"); - vector<Mesh::Triangle> oldtriangle = mesh->triangles; + array<int> oldtriangle = mesh->triangles; /* compares curve_keys rather than strands in order to handle quick hair * adjustments in dynamic BVH - other methods could probably do this better*/ - vector<float4> oldcurve_keys = mesh->curve_keys; + array<float3> oldcurve_keys = mesh->curve_keys; + array<float> oldcurve_radius = mesh->curve_radius; mesh->clear(); mesh->used_shaders = used_shaders; @@ -827,14 +827,21 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob, if(oldtriangle.size() != mesh->triangles.size()) rebuild = true; else if(oldtriangle.size()) { - if(memcmp(&oldtriangle[0], &mesh->triangles[0], sizeof(Mesh::Triangle)*oldtriangle.size()) != 0) + 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(float4)*oldcurve_keys.size()) != 0) + 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; } @@ -931,8 +938,8 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob, Attribute *attr_mP = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); if(attr_mP) { - float4 *keys = &mesh->curve_keys[0]; - memcpy(attr_mP->data_float4() + time_index*numkeys, keys, sizeof(float4)*numkeys); + float3 *keys = &mesh->curve_keys[0]; + memcpy(attr_mP->data_float3() + time_index*numkeys, keys, sizeof(float3)*numkeys); } } diff --git a/intern/cycles/blender/blender_particles.cpp b/intern/cycles/blender/blender_particles.cpp index d1e702cfdc2..b9876cd604f 100644 --- a/intern/cycles/blender/blender_particles.cpp +++ b/intern/cycles/blender/blender_particles.cpp @@ -76,7 +76,7 @@ bool BlenderSync::sync_dupli_particle(BL::Object& b_ob, pa.velocity = get_float3(b_pa.velocity()); pa.angular_velocity = get_float3(b_pa.angular_velocity()); - psys->particles.push_back(pa); + psys->particles.push_back_slow(pa); if(object->particle_index != psys->particles.size() - 1) scene->object_manager->tag_update(scene); diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp index 5c474c8c3e9..fa2b9ae7279 100644 --- a/intern/cycles/bvh/bvh.cpp +++ b/intern/cycles/bvh/bvh.cpp @@ -128,11 +128,11 @@ void BVH::pack_triangle(int idx, float4 storage[3]) const Mesh *mesh = objects[tob]->mesh; int tidx = pack.prim_index[idx]; - const int *vidx = mesh->triangles[tidx].v; + Mesh::Triangle t = mesh->get_triangle(tidx); const float3* vpos = &mesh->verts[0]; - float3 v0 = vpos[vidx[0]]; - float3 v1 = vpos[vidx[1]]; - float3 v2 = vpos[vidx[2]]; + float3 v0 = vpos[t.v[0]]; + float3 v1 = vpos[t.v[1]]; + float3 v2 = vpos[t.v[2]]; storage[0] = float3_to_float4(v0); storage[1] = float3_to_float4(v1); @@ -506,10 +506,10 @@ void RegularBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility if(pack.prim_type[prim] & PRIMITIVE_ALL_CURVE) { /* curves */ int str_offset = (params.top_level)? mesh->curve_offset: 0; - const Mesh::Curve& curve = mesh->curves[pidx - str_offset]; + Mesh::Curve curve = mesh->get_curve(pidx - str_offset); int k = PRIMITIVE_UNPACK_SEGMENT(pack.prim_type[prim]); - curve.bounds_grow(k, &mesh->curve_keys[0], bbox); + curve.bounds_grow(k, &mesh->curve_keys[0], &mesh->curve_radius[0], bbox); visibility |= PATH_RAY_CURVE; @@ -520,17 +520,17 @@ void RegularBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility if(attr) { size_t mesh_size = mesh->curve_keys.size(); size_t steps = mesh->motion_steps - 1; - float4 *key_steps = attr->data_float4(); + float3 *key_steps = attr->data_float3(); for(size_t i = 0; i < steps; i++) - curve.bounds_grow(k, key_steps + i*mesh_size, bbox); + curve.bounds_grow(k, key_steps + i*mesh_size, &mesh->curve_radius[0], bbox); } } } else { /* triangles */ int tri_offset = (params.top_level)? mesh->tri_offset: 0; - const Mesh::Triangle& triangle = mesh->triangles[pidx - tri_offset]; + Mesh::Triangle triangle = mesh->get_triangle(pidx - tri_offset); const float3 *vpos = &mesh->verts[0]; triangle.bounds_grow(vpos, bbox); @@ -770,10 +770,10 @@ void QBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility) if(pack.prim_type[prim] & PRIMITIVE_ALL_CURVE) { /* Curves. */ int str_offset = (params.top_level)? mesh->curve_offset: 0; - const Mesh::Curve& curve = mesh->curves[pidx - str_offset]; + Mesh::Curve curve = mesh->get_curve(pidx - str_offset); int k = PRIMITIVE_UNPACK_SEGMENT(pack.prim_type[prim]); - curve.bounds_grow(k, &mesh->curve_keys[0], bbox); + curve.bounds_grow(k, &mesh->curve_keys[0], &mesh->curve_radius[0], bbox); visibility |= PATH_RAY_CURVE; @@ -784,17 +784,17 @@ void QBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility) if(attr) { size_t mesh_size = mesh->curve_keys.size(); size_t steps = mesh->motion_steps - 1; - float4 *key_steps = attr->data_float4(); + float3 *key_steps = attr->data_float3(); for(size_t i = 0; i < steps; i++) - curve.bounds_grow(k, key_steps + i*mesh_size, bbox); + curve.bounds_grow(k, key_steps + i*mesh_size, &mesh->curve_radius[0], bbox); } } } else { /* Triangles. */ int tri_offset = (params.top_level)? mesh->tri_offset: 0; - const Mesh::Triangle& triangle = mesh->triangles[pidx - tri_offset]; + Mesh::Triangle triangle = mesh->get_triangle(pidx - tri_offset); const float3 *vpos = &mesh->verts[0]; triangle.bounds_grow(vpos, bbox); diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp index 76a1bfa2bfe..8dbd5abc183 100644 --- a/intern/cycles/bvh/bvh_build.cpp +++ b/intern/cycles/bvh/bvh_build.cpp @@ -117,8 +117,9 @@ void BVHBuild::add_reference_mesh(BoundBox& root, BoundBox& center, Mesh *mesh, if(mesh->has_motion_blur()) attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); - for(uint j = 0; j < mesh->triangles.size(); j++) { - Mesh::Triangle t = mesh->triangles[j]; + size_t num_triangles = mesh->num_triangles(); + for(uint j = 0; j < num_triangles; j++) { + Mesh::Triangle t = mesh->get_triangle(j); BoundBox bounds = BoundBox::empty; PrimitiveType type = PRIMITIVE_TRIANGLE; @@ -148,22 +149,23 @@ void BVHBuild::add_reference_mesh(BoundBox& root, BoundBox& center, Mesh *mesh, if(mesh->has_motion_blur()) curve_attr_mP = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); - for(uint j = 0; j < mesh->curves.size(); j++) { - Mesh::Curve curve = mesh->curves[j]; + size_t num_curves = mesh->num_curves(); + for(uint j = 0; j < num_curves; j++) { + Mesh::Curve curve = mesh->get_curve(j); PrimitiveType type = PRIMITIVE_CURVE; for(int k = 0; k < curve.num_keys - 1; k++) { BoundBox bounds = BoundBox::empty; - curve.bounds_grow(k, &mesh->curve_keys[0], bounds); + curve.bounds_grow(k, &mesh->curve_keys[0], &mesh->curve_radius[0], bounds); /* motion curve */ if(curve_attr_mP) { size_t mesh_size = mesh->curve_keys.size(); size_t steps = mesh->motion_steps - 1; - float4 *key_steps = curve_attr_mP->data_float4(); + float3 *key_steps = curve_attr_mP->data_float3(); for(size_t i = 0; i < steps; i++) - curve.bounds_grow(k, key_steps + i*mesh_size, bounds); + curve.bounds_grow(k, key_steps + i*mesh_size, &mesh->curve_radius[0], bounds); type = PRIMITIVE_MOTION_CURVE; } @@ -188,10 +190,10 @@ void BVHBuild::add_reference_object(BoundBox& root, BoundBox& center, Object *ob static size_t count_curve_segments(Mesh *mesh) { - size_t num = 0, num_curves = mesh->curves.size(); + size_t num = 0, num_curves = mesh->num_curves(); for(size_t i = 0; i < num_curves; i++) - num += mesh->curves[i].num_keys - 1; + num += mesh->get_curve(i).num_keys - 1; return num; } @@ -204,14 +206,14 @@ void BVHBuild::add_references(BVHRange& root) foreach(Object *ob, objects) { if(params.top_level) { if(!ob->mesh->is_instanced()) { - num_alloc_references += ob->mesh->triangles.size(); + num_alloc_references += ob->mesh->num_triangles(); num_alloc_references += count_curve_segments(ob->mesh); } else num_alloc_references++; } else { - num_alloc_references += ob->mesh->triangles.size(); + num_alloc_references += ob->mesh->num_triangles(); num_alloc_references += count_curve_segments(ob->mesh); } } diff --git a/intern/cycles/bvh/bvh_split.cpp b/intern/cycles/bvh/bvh_split.cpp index 8084975565e..3665fb42bc2 100644 --- a/intern/cycles/bvh/bvh_split.cpp +++ b/intern/cycles/bvh/bvh_split.cpp @@ -292,13 +292,13 @@ void BVHSpatialSplit::split_triangle_primitive(const Mesh *mesh, BoundBox& left_bounds, BoundBox& right_bounds) { - const int *inds = mesh->triangles[prim_index].v; + Mesh::Triangle t = mesh->get_triangle(prim_index); const float3 *verts = &mesh->verts[0]; - float3 v1 = tfm ? transform_point(tfm, verts[inds[2]]) : verts[inds[2]]; + float3 v1 = tfm ? transform_point(tfm, verts[t.v[2]]) : verts[t.v[2]]; for(int i = 0; i < 3; i++) { float3 v0 = v1; - int vindex = inds[i]; + int vindex = t.v[i]; v1 = tfm ? transform_point(tfm, verts[vindex]) : verts[vindex]; float v0p = v0[dim]; float v1p = v1[dim]; @@ -329,12 +329,11 @@ void BVHSpatialSplit::split_curve_primitive(const Mesh *mesh, BoundBox& right_bounds) { /* curve split: NOTE - Currently ignores curve width and needs to be fixed.*/ - const int k0 = mesh->curves[prim_index].first_key + segment_index; + Mesh::Curve curve = mesh->get_curve(prim_index); + const int k0 = curve.first_key + segment_index; const int k1 = k0 + 1; - const float4& key0 = mesh->curve_keys[k0]; - const float4& key1 = mesh->curve_keys[k1]; - float3 v0 = float4_to_float3(key0); - float3 v1 = float4_to_float3(key1); + float3 v0 = mesh->curve_keys[k0]; + float3 v1 = mesh->curve_keys[k1]; if(tfm != NULL) { v0 = transform_point(tfm, v0); @@ -414,8 +413,8 @@ void BVHSpatialSplit::split_object_reference(const Object *object, left_bounds, right_bounds); } - for(int curve_idx = 0; curve_idx < mesh->curves.size(); ++curve_idx) { - Mesh::Curve &curve = mesh->curves[curve_idx]; + for(int curve_idx = 0; curve_idx < mesh->num_curves(); ++curve_idx) { + Mesh::Curve curve = mesh->get_curve(curve_idx); for(int segment_idx = 0; segment_idx < curve.num_keys - 1; ++segment_idx) diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp index b7de83d89c1..71a3cba6811 100644 --- a/intern/cycles/render/attribute.cpp +++ b/intern/cycles/render/attribute.cpp @@ -51,13 +51,13 @@ void Attribute::set(ustring name_, TypeDesc type_, AttributeElement element_) type == TypeDesc::TypeNormal || type == TypeDesc::TypeMatrix); } -void Attribute::reserve(int numverts, int numtris, int numsteps, int numcurves, int numkeys, bool resize) +void Attribute::resize(int numverts, int numtris, int numsteps, int numcurves, int numkeys, bool reserve_only) { - if(resize) { - buffer.resize(buffer_size(numverts, numtris, numsteps, numcurves, numkeys), 0); + if(reserve_only) { + buffer.reserve(buffer_size(numverts, numtris, numsteps, numcurves, numkeys)); } else { - buffer.reserve(buffer_size(numverts, numtris, numsteps, numcurves, numkeys)); + buffer.resize(buffer_size(numverts, numtris, numsteps, numcurves, numkeys), 0); } } @@ -263,7 +263,7 @@ AttributeSet::~AttributeSet() { } -Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement element, bool resize) +Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement element) { Attribute *attr = find(name); @@ -291,9 +291,9 @@ Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement eleme /* this is weak .. */ if(triangle_mesh) - attr->reserve(triangle_mesh->verts.size(), triangle_mesh->triangles.size(), triangle_mesh->motion_steps, 0, 0, resize); + attr->resize(triangle_mesh->verts.size(), triangle_mesh->num_triangles(), triangle_mesh->motion_steps, 0, 0, false); if(curve_mesh) - attr->reserve(0, 0, curve_mesh->motion_steps, curve_mesh->curves.size(), curve_mesh->curve_keys.size(), resize); + attr->resize(0, 0, curve_mesh->motion_steps, curve_mesh->num_curves(), curve_mesh->curve_keys.size(), false); return attr; } @@ -448,13 +448,13 @@ Attribute *AttributeSet::find(AttributeRequest& req) return find(req.std); } -void AttributeSet::reserve() +void AttributeSet::resize(bool reserve_only) { foreach(Attribute& attr, attributes) { if(triangle_mesh) - attr.reserve(triangle_mesh->verts.size(), triangle_mesh->triangles.size(), triangle_mesh->motion_steps, 0, 0, true); + attr.resize(triangle_mesh->verts.size(), triangle_mesh->num_triangles(), triangle_mesh->motion_steps, 0, 0, reserve_only); if(curve_mesh) - attr.reserve(0, 0, 0, curve_mesh->curves.size(), curve_mesh->curve_keys.size(), true); + attr.resize(0, 0, 0, curve_mesh->num_curves(), curve_mesh->curve_keys.size(), reserve_only); } } diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h index 01102d22aaa..41b3626afd3 100644 --- a/intern/cycles/render/attribute.h +++ b/intern/cycles/render/attribute.h @@ -58,7 +58,7 @@ public: Attribute() {} ~Attribute(); void set(ustring name, TypeDesc type, AttributeElement element); - void reserve(int numverts, int numfaces, int numsteps, int numcurves, int numkeys, bool resize); + void resize(int numverts, int numfaces, int numsteps, int numcurves, int numkeys, bool reserve_only); size_t data_sizeof() const; size_t element_size(int numverts, int numfaces, int numsteps, int numcurves, int numkeys) const; @@ -104,7 +104,7 @@ public: AttributeSet(); ~AttributeSet(); - Attribute *add(ustring name, TypeDesc type, AttributeElement element, bool resize = true); + Attribute *add(ustring name, TypeDesc type, AttributeElement element); Attribute *find(ustring name) const; void remove(ustring name); @@ -114,7 +114,7 @@ public: Attribute *find(AttributeRequest& req); - void reserve(); + void resize(bool reserve_only = false); void clear(); }; diff --git a/intern/cycles/render/curves.h b/intern/cycles/render/curves.h index 3d9b4e1f347..e41967eebf5 100644 --- a/intern/cycles/render/curves.h +++ b/intern/cycles/render/curves.h @@ -63,23 +63,23 @@ public: ParticleCurveData(); ~ParticleCurveData(); - vector<int> psys_firstcurve; - vector<int> psys_curvenum; - vector<int> psys_shader; - - vector<float> psys_rootradius; - vector<float> psys_tipradius; - vector<float> psys_shape; - vector<bool> psys_closetip; - - vector<int> curve_firstkey; - vector<int> curve_keynum; - vector<float> curve_length; - vector<float3> curve_uv; - vector<float3> curve_vcol; - - vector<float3> curvekey_co; - vector<float> curvekey_time; + array<int> psys_firstcurve; + array<int> psys_curvenum; + array<int> psys_shader; + + array<float> psys_rootradius; + array<float> psys_tipradius; + array<float> psys_shape; + array<bool> psys_closetip; + + array<int> curve_firstkey; + array<int> curve_keynum; + array<float> curve_length; + array<float3> curve_uv; + array<float3> curve_vcol; + + array<float3> curvekey_co; + array<float> curvekey_time; }; /* HairSystem Manager */ diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index c20bf6b5e9e..9ef35820254 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -247,7 +247,8 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen /* count triangles */ if(have_emission) { - for(size_t i = 0; i < mesh->triangles.size(); i++) { + size_t mesh_num_triangles = mesh->num_triangles(); + for(size_t i = 0; i < mesh_num_triangles; i++) { int shader_index = mesh->shader[i]; Shader *shader = (shader_index < mesh->used_shaders.size()) ? mesh->used_shaders[shader_index] : scene->default_surface; @@ -319,7 +320,8 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen use_light_visibility = true; } - for(size_t i = 0; i < mesh->triangles.size(); i++) { + size_t mesh_num_triangles = mesh->num_triangles(); + for(size_t i = 0; i < mesh_num_triangles; i++) { int shader_index = mesh->shader[i]; Shader *shader = (shader_index < mesh->used_shaders.size()) ? mesh->used_shaders[shader_index] : scene->default_surface; @@ -331,7 +333,7 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen distribution[offset].w = __int_as_float(object_id); offset++; - Mesh::Triangle t = mesh->triangles[i]; + Mesh::Triangle t = mesh->get_triangle(i); float3 p1 = mesh->verts[t.v[0]]; float3 p2 = mesh->verts[t.v[1]]; float3 p3 = mesh->verts[t.v[2]]; diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp index d26404035eb..722632b9934 100644 --- a/intern/cycles/render/mesh.cpp +++ b/intern/cycles/render/mesh.cpp @@ -51,14 +51,14 @@ void Mesh::Triangle::bounds_grow(const float3 *verts, BoundBox& bounds) const /* Curve */ -void Mesh::Curve::bounds_grow(const int k, const float4 *curve_keys, BoundBox& bounds) const +void Mesh::Curve::bounds_grow(const int k, const float3 *curve_keys, const float *curve_radius, BoundBox& bounds) const { float3 P[4]; - P[0] = float4_to_float3(curve_keys[max(first_key + k - 1,first_key)]); - P[1] = float4_to_float3(curve_keys[first_key + k]); - P[2] = float4_to_float3(curve_keys[first_key + k + 1]); - P[3] = float4_to_float3(curve_keys[min(first_key + k + 2, first_key + num_keys - 1)]); + P[0] = curve_keys[max(first_key + k - 1,first_key)]; + P[1] = curve_keys[first_key + k]; + P[2] = curve_keys[first_key + k + 1]; + P[3] = curve_keys[min(first_key + k + 2, first_key + num_keys - 1)]; float3 lower; float3 upper; @@ -67,7 +67,7 @@ void Mesh::Curve::bounds_grow(const int k, const float4 *curve_keys, BoundBox& b curvebounds(&lower.y, &upper.y, P, 1); curvebounds(&lower.z, &upper.z, P, 2); - float mr = max(curve_keys[first_key + k].w, curve_keys[first_key + k + 1].w); + float mr = max(curve_radius[first_key + k], curve_radius[first_key + k + 1]); bounds.grow(lower, mr); bounds.grow(upper, mr); @@ -99,6 +99,8 @@ Mesh::Mesh() attributes.triangle_mesh = this; curve_attributes.curve_mesh = this; + geometry_flags = GEOMETRY_NONE; + has_volume = false; has_surface_bssrdf = false; } @@ -108,21 +110,49 @@ Mesh::~Mesh() delete bvh; } -void Mesh::reserve(int numverts, int numtris, int numcurves, int numcurvekeys) +void Mesh::resize_mesh(int numverts, int numtris) { - /* reserve space to add verts and triangles later */ verts.resize(numverts); - triangles.resize(numtris); + triangles.resize(numtris * 3); shader.resize(numtris); smooth.resize(numtris); forms_quad.resize(numtris); - curve_keys.resize(numcurvekeys); - curves.resize(numcurves); + attributes.resize(); +} - attributes.reserve(); - curve_attributes.reserve(); +void Mesh::reserve_mesh(int numverts, int numtris) +{ + /* reserve space to add verts and triangles later */ + verts.reserve(numverts); + triangles.reserve(numtris * 3); + shader.reserve(numtris); + smooth.reserve(numtris); + + forms_quad.reserve(numtris); + + attributes.resize(true); +} + +void Mesh::resize_curves(int numcurves, int numkeys) +{ + curve_keys.resize(numkeys); + curve_radius.resize(numkeys); + curve_first_key.resize(numcurves); + curve_shader.resize(numcurves); + + curve_attributes.resize(); +} + +void Mesh::reserve_curves(int numcurves, int numkeys) +{ + curve_keys.reserve(numkeys); + curve_radius.reserve(numkeys); + curve_first_key.reserve(numcurves); + curve_shader.reserve(numcurves); + + curve_attributes.resize(true); } void Mesh::clear() @@ -136,7 +166,9 @@ void Mesh::clear() forms_quad.clear(); curve_keys.clear(); - curves.clear(); + curve_radius.clear(); + curve_first_key.clear(); + curve_shader.clear(); attributes.clear(); curve_attributes.clear(); @@ -151,7 +183,7 @@ void Mesh::clear() int Mesh::split_vertex(int vertex) { /* copy vertex location and vertex attributes */ - verts.push_back(verts[vertex]); + add_vertex(verts[vertex]); foreach(Attribute& attr, attributes.attributes) { if(attr.element == ATTR_ELEMENT_VERTEX) { @@ -164,48 +196,31 @@ int Mesh::split_vertex(int vertex) return verts.size() - 1; } -void Mesh::set_triangle(int i, int v0, int v1, int v2, int shader_, bool smooth_, bool forms_quad_) +void Mesh::add_vertex(float3 P) { - Triangle tri; - tri.v[0] = v0; - tri.v[1] = v1; - tri.v[2] = v2; - - triangles[i] = tri; - shader[i] = shader_; - smooth[i] = smooth_; - forms_quad[i] = forms_quad_; + verts.push_back_reserved(P); } void Mesh::add_triangle(int v0, int v1, int v2, int shader_, bool smooth_, bool forms_quad_) { - Triangle tri; - tri.v[0] = v0; - tri.v[1] = v1; - tri.v[2] = v2; - - triangles.push_back(tri); - shader.push_back(shader_); - smooth.push_back(smooth_); - forms_quad.push_back(forms_quad_); + triangles.push_back_reserved(v0); + triangles.push_back_reserved(v1); + triangles.push_back_reserved(v2); + shader.push_back_reserved(shader_); + smooth.push_back_reserved(smooth_); + forms_quad.push_back_reserved(forms_quad_); } void Mesh::add_curve_key(float3 co, float radius) { - float4 key = float3_to_float4(co); - key.w = radius; - - curve_keys.push_back(key); + curve_keys.push_back_reserved(co); + curve_radius.push_back_reserved(radius); } void Mesh::add_curve(int first_key, int num_keys, int shader) { - Curve curve; - curve.first_key = first_key; - curve.num_keys = num_keys; - curve.shader = shader; - - curves.push_back(curve); + curve_first_key.push_back_reserved(first_key); + curve_shader.push_back_reserved(shader); } void Mesh::compute_bounds() @@ -219,7 +234,7 @@ void Mesh::compute_bounds() bnds.grow(verts[i]); for(size_t i = 0; i < curve_keys_size; i++) - bnds.grow(float4_to_float3(curve_keys[i]), curve_keys[i].w); + bnds.grow(curve_keys[i], curve_radius[i]); Attribute *attr = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); if(use_motion_blur && attr) { @@ -247,7 +262,7 @@ void Mesh::compute_bounds() bnds.grow_safe(verts[i]); for(size_t i = 0; i < curve_keys_size; i++) - bnds.grow_safe(float4_to_float3(curve_keys[i]), curve_keys[i].w); + bnds.grow_safe(curve_keys[i], curve_radius[i]); if(use_motion_blur && attr) { size_t steps_size = verts.size() * (motion_steps - 1); @@ -301,15 +316,14 @@ void Mesh::add_face_normals() float3 *fN = attr_fN->data_float3(); /* compute face normals */ - size_t triangles_size = triangles.size(); + size_t triangles_size = num_triangles(); bool flip = transform_negative_scaled; if(triangles_size) { float3 *verts_ptr = &verts[0]; - Triangle *triangles_ptr = &triangles[0]; for(size_t i = 0; i < triangles_size; i++) { - fN[i] = compute_face_normal(triangles_ptr[i], verts_ptr); + fN[i] = compute_face_normal(get_triangle(i), verts_ptr); if(flip) fN[i] = -fN[i]; @@ -329,7 +343,7 @@ void Mesh::add_vertex_normals() { bool flip = transform_negative_scaled; size_t verts_size = verts.size(); - size_t triangles_size = triangles.size(); + size_t triangles_size = num_triangles(); /* static vertex normals */ if(!attributes.find(ATTR_STD_VERTEX_NORMAL)) { @@ -344,11 +358,10 @@ void Mesh::add_vertex_normals() memset(vN, 0, verts.size()*sizeof(float3)); if(triangles_size) { - Triangle *triangles_ptr = &triangles[0]; for(size_t i = 0; i < triangles_size; i++) for(size_t j = 0; j < 3; j++) - vN[triangles_ptr[i].v[j]] += fN[i]; + vN[get_triangle(i).v[j]] += fN[i]; } for(size_t i = 0; i < verts_size; i++) { @@ -374,12 +387,10 @@ void Mesh::add_vertex_normals() memset(mN, 0, verts.size()*sizeof(float3)); if(triangles_size) { - Triangle *triangles_ptr = &triangles[0]; - for(size_t i = 0; i < triangles_size; i++) { for(size_t j = 0; j < 3; j++) { - float3 fN = compute_face_normal(triangles_ptr[i], mP); - mN[triangles_ptr[i].v[j]] += fN; + float3 fN = compute_face_normal(get_triangle(i), mP); + mN[get_triangle(i).v[j]] += fN; } } } @@ -402,8 +413,8 @@ void Mesh::pack_normals(Scene *scene, uint *tri_shader, float4 *vnormal) uint last_shader = -1; bool last_smooth = false; - size_t triangles_size = triangles.size(); - uint *shader_ptr = (shader.size())? &shader[0]: NULL; + size_t triangles_size = num_triangles(); + int *shader_ptr = (shader.size())? &shader[0]: NULL; bool do_transform = transform_applied; Transform ntfm = transform_normal; @@ -446,13 +457,11 @@ void Mesh::pack_verts(float4 *tri_verts, float4 *tri_vindex, size_t vert_offset) } } - size_t triangles_size = triangles.size(); + size_t triangles_size = num_triangles(); if(triangles_size) { - Triangle *triangles_ptr = &triangles[0]; - for(size_t i = 0; i < triangles_size; i++) { - Triangle t = triangles_ptr[i]; + Triangle t = get_triangle(i); tri_vindex[i] = make_float4( __int_as_float(t.v[0] + vert_offset), @@ -466,27 +475,25 @@ void Mesh::pack_verts(float4 *tri_verts, float4 *tri_vindex, size_t vert_offset) void Mesh::pack_curves(Scene *scene, float4 *curve_key_co, float4 *curve_data, size_t curvekey_offset) { size_t curve_keys_size = curve_keys.size(); - float4 *keys_ptr = NULL; /* pack curve keys */ if(curve_keys_size) { - keys_ptr = &curve_keys[0]; + float3 *keys_ptr = &curve_keys[0]; + float *radius_ptr = &curve_radius[0]; for(size_t i = 0; i < curve_keys_size; i++) - curve_key_co[i] = keys_ptr[i]; + curve_key_co[i] = make_float4(keys_ptr[i].x, keys_ptr[i].y, keys_ptr[i].z, radius_ptr[i]); } /* pack curve segments */ - size_t curve_num = curves.size(); + size_t curve_num = num_curves(); if(curve_num) { - Curve *curve_ptr = &curves[0]; - int shader_id = 0; - for(size_t i = 0; i < curve_num; i++) { - Curve curve = curve_ptr[i]; - Shader *shader = (curve.shader < used_shaders.size()) ? - used_shaders[curve.shader] : scene->default_surface; + Curve curve = get_curve(i); + int shader_id = curve_shader[i]; + Shader *shader = (shader_id < used_shaders.size()) ? + used_shaders[shader_id] : scene->default_surface; shader_id = scene->shader_manager->get_shader_id(shader, this, false); curve_data[i] = make_float4( @@ -732,7 +739,7 @@ void MeshManager::update_svm_attributes(Device *device, DeviceScene *dscene, Sce else id = scene->shader_manager->get_attribute_id(req.std); - if(mesh->triangles.size()) { + if(mesh->num_triangles()) { attr_map[index].x = id; attr_map[index].y = req.triangle_element; attr_map[index].z = as_uint(req.triangle_offset); @@ -747,7 +754,7 @@ void MeshManager::update_svm_attributes(Device *device, DeviceScene *dscene, Sce index++; - if(mesh->curves.size()) { + if(mesh->num_curves()) { attr_map[index].x = id; attr_map[index].y = req.curve_element; attr_map[index].z = as_uint(req.curve_offset); @@ -793,9 +800,9 @@ static void update_attribute_element_size(Mesh *mesh, if(mattr) { size_t size = mattr->element_size( mesh->verts.size(), - mesh->triangles.size(), + mesh->num_triangles(), mesh->motion_steps, - mesh->curves.size(), + mesh->num_curves(), mesh->curve_keys.size()); if(mattr->element == ATTR_ELEMENT_VOXEL) { @@ -836,9 +843,9 @@ static void update_attribute_element_offset(Mesh *mesh, /* store attribute data in arrays */ size_t size = mattr->element_size( mesh->verts.size(), - mesh->triangles.size(), + mesh->num_triangles(), mesh->motion_steps, - mesh->curves.size(), + mesh->num_curves(), mesh->curve_keys.size()); if(mattr->element == ATTR_ELEMENT_VOXEL) { @@ -1052,10 +1059,10 @@ void MeshManager::device_update_mesh(Device *device, DeviceScene *dscene, Scene mesh->curve_offset = curve_size; vert_size += mesh->verts.size(); - tri_size += mesh->triangles.size(); + tri_size += mesh->num_triangles(); curve_key_size += mesh->curve_keys.size(); - curve_size += mesh->curves.size(); + curve_size += mesh->num_curves(); } if(tri_size != 0) { @@ -1465,16 +1472,17 @@ void Mesh::tessellate(DiagSplit *split) if(!forms_quad[f]) { /* triangle */ LinearTrianglePatch patch; + Triangle triangle = get_triangle(f); float3 *hull = patch.hull; float3 *normals = patch.normals; for(int i = 0; i < 3; i++) { - hull[i] = verts[triangles[f].v[i]]; + hull[i] = verts[triangle.v[i]]; } if(smooth[f]) { for(int i = 0; i < 3; i++) { - normals[i] = vN[triangles[f].v[i]]; + normals[i] = vN[triangle.v[i]]; } } else { @@ -1488,19 +1496,21 @@ void Mesh::tessellate(DiagSplit *split) else { /* quad */ LinearQuadPatch patch; + Triangle triangle0 = get_triangle(f); + Triangle triangle1 = get_triangle(f+1); float3 *hull = patch.hull; float3 *normals = patch.normals; - hull[0] = verts[triangles[f ].v[0]]; - hull[1] = verts[triangles[f ].v[1]]; - hull[3] = verts[triangles[f ].v[2]]; - hull[2] = verts[triangles[f+1].v[2]]; + hull[0] = verts[triangle0.v[0]]; + hull[1] = verts[triangle0.v[1]]; + hull[3] = verts[triangle0.v[2]]; + hull[2] = verts[triangle1.v[2]]; if(smooth[f]) { - normals[0] = vN[triangles[f ].v[0]]; - normals[1] = vN[triangles[f ].v[1]]; - normals[3] = vN[triangles[f ].v[2]]; - normals[2] = vN[triangles[f+1].v[2]]; + normals[0] = vN[triangle0.v[0]]; + normals[1] = vN[triangle0.v[1]]; + normals[3] = vN[triangle0.v[2]]; + normals[2] = vN[triangle1.v[2]]; } else { for(int i = 0; i < 4; i++) { diff --git a/intern/cycles/render/mesh.h b/intern/cycles/render/mesh.h index 557b664bff3..2d1f3e3a83e 100644 --- a/intern/cycles/render/mesh.h +++ b/intern/cycles/render/mesh.h @@ -51,17 +51,41 @@ public: void bounds_grow(const float3 *verts, BoundBox& bounds) const; }; + Triangle get_triangle(size_t i) const + { + Triangle tri = {{triangles[i*3 + 0], triangles[i*3 + 1], triangles[i*3 + 2]}}; + return tri; + } + + size_t num_triangles() const + { + return triangles.size() / 3; + } + /* Mesh Curve */ struct Curve { int first_key; int num_keys; - uint shader; int num_segments() { return num_keys - 1; } - void bounds_grow(const int k, const float4 *curve_keys, BoundBox& bounds) const; + void bounds_grow(const int k, const float3 *curve_keys, const float *curve_radius, BoundBox& bounds) const; }; + Curve get_curve(size_t i) const + { + int first = curve_first_key[i]; + int next_first = (i+1 < curve_first_key.size()) ? curve_first_key[i+1] : curve_keys.size(); + + Curve curve = {first, next_first - first}; + return curve; + } + + size_t num_curves() const + { + return curve_first_key.size(); + } + /* Displacement */ enum DisplacementMethod { DISPLACE_BUMP = 0, @@ -82,17 +106,19 @@ public: int geometry_flags; /* used to distinguish meshes with no verts and meshed for which geometry is not created */ - vector<float3> verts; - vector<Triangle> triangles; - vector<uint> shader; - vector<bool> smooth; - vector<bool> forms_quad; /* used to tell if triangle is part of a quad patch */ + array<int> triangles; + array<float3> verts; + array<int> shader; + array<bool> smooth; + array<bool> forms_quad; /* used to tell if triangle is part of a quad patch */ bool has_volume; /* Set in the device_update_flags(). */ bool has_surface_bssrdf; /* Set in the device_update_flags(). */ - vector<float4> curve_keys; /* co + radius */ - vector<Curve> curves; + array<float3> curve_keys; + array<float> curve_radius; + array<int> curve_first_key; + array<int> curve_shader; vector<Shader*> used_shaders; AttributeSet attributes; @@ -123,9 +149,12 @@ public: Mesh(); ~Mesh(); - void reserve(int numverts, int numfaces, int numcurves, int numcurvekeys); + void resize_mesh(int numverts, int numfaces); + void reserve_mesh(int numverts, int numfaces); + void resize_curves(int numcurves, int numkeys); + void reserve_curves(int numcurves, int numkeys); void clear(); - void set_triangle(int i, int v0, int v1, int v2, int shader, bool smooth, bool forms_quad = false); + void add_vertex(float3 P); void add_triangle(int v0, int v1, int v2, int shader, bool smooth, bool forms_quad = false); void add_curve_key(float3 loc, float radius); void add_curve(int first_key, int num_keys, int shader); diff --git a/intern/cycles/render/mesh_displace.cpp b/intern/cycles/render/mesh_displace.cpp index d19bf2084d7..95f46ff02a2 100644 --- a/intern/cycles/render/mesh_displace.cpp +++ b/intern/cycles/render/mesh_displace.cpp @@ -60,8 +60,9 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me uint4 *d_input_data = d_input.resize(num_verts); size_t d_input_size = 0; - for(size_t i = 0; i < mesh->triangles.size(); i++) { - Mesh::Triangle t = mesh->triangles[i]; + size_t num_triangles = mesh->num_triangles(); + for(size_t i = 0; i < num_triangles; i++) { + Mesh::Triangle t = mesh->get_triangle(i); int shader_index = mesh->shader[i]; Shader *shader = (shader_index < mesh->used_shaders.size()) ? mesh->used_shaders[shader_index] : scene->default_surface; @@ -146,8 +147,8 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me float4 *offset = (float4*)d_output.data_pointer; Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); - for(size_t i = 0; i < mesh->triangles.size(); i++) { - Mesh::Triangle t = mesh->triangles[i]; + for(size_t i = 0; i < num_triangles; i++) { + Mesh::Triangle t = mesh->get_triangle(i); int shader_index = mesh->shader[i]; Shader *shader = (shader_index < mesh->used_shaders.size()) ? mesh->used_shaders[shader_index] : scene->default_surface; diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index e2fe0bd72a1..4e74940aff1 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -137,12 +137,12 @@ void Object::apply_transform(bool apply_to_motion) /* apply transform to curve keys */ for(size_t i = 0; i < mesh->curve_keys.size(); i++) { - float3 co = transform_point(&tfm, float4_to_float3(mesh->curve_keys[i])); - float radius = mesh->curve_keys[i].w * scalar; + float3 co = transform_point(&tfm, mesh->curve_keys[i]); + float radius = mesh->curve_radius[i] * scalar; /* scale for curve radius is only correct for uniform scale */ - mesh->curve_keys[i] = float3_to_float4(co); - mesh->curve_keys[i].w = radius; + mesh->curve_keys[i] = co; + mesh->curve_radius[i] = radius; } if(apply_to_motion) { @@ -269,7 +269,9 @@ void ObjectManager::device_update_object_transform(UpdateObejctTransformState *s state->surface_area_lock.unlock(); if(it == state->surface_area_map.end()) { - foreach(Mesh::Triangle& t, mesh->triangles) { + size_t num_triangles = mesh->num_triangles(); + for(size_t j = 0; j < num_triangles; j++) { + Mesh::Triangle t = mesh->get_triangle(j); float3 p1 = mesh->verts[t.v[0]]; float3 p2 = mesh->verts[t.v[1]]; float3 p3 = mesh->verts[t.v[2]]; @@ -288,7 +290,9 @@ void ObjectManager::device_update_object_transform(UpdateObejctTransformState *s surface_area *= uniform_scale; } else { - foreach(Mesh::Triangle& t, mesh->triangles) { + size_t num_triangles = mesh->num_triangles(); + for(size_t j = 0; j < num_triangles; j++) { + Mesh::Triangle t = mesh->get_triangle(j); float3 p1 = transform_point(&tfm, mesh->verts[t.v[0]]); float3 p2 = transform_point(&tfm, mesh->verts[t.v[1]]); float3 p3 = transform_point(&tfm, mesh->verts[t.v[2]]); @@ -360,7 +364,7 @@ void ObjectManager::device_update_object_transform(UpdateObejctTransformState *s state->object_flag[object_index] = flag; /* Have curves. */ - if(mesh->curves.size()) { + if(mesh->num_curves()) { state->have_curves = true; } } diff --git a/intern/cycles/render/particles.cpp b/intern/cycles/render/particles.cpp index 50726bb4574..1a35d60fb4b 100644 --- a/intern/cycles/render/particles.cpp +++ b/intern/cycles/render/particles.cpp @@ -58,8 +58,8 @@ void ParticleSystemManager::device_update_particles(Device *device, DeviceScene * adds one dummy particle at the beginning to avoid invalid lookups, * in case a shader uses particle info without actual particle data. */ int num_particles = 1; - foreach(ParticleSystem *psys, scene->particle_systems) - num_particles += psys->particles.size(); + for(size_t j = 0; j < scene->particle_systems.size(); j++) + num_particles += scene->particle_systems[j]->particles.size(); float4 *particles = dscene->particles.resize(PARTICLE_SIZE*num_particles); @@ -71,9 +71,12 @@ void ParticleSystemManager::device_update_particles(Device *device, DeviceScene particles[4] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); int i = 1; - foreach(ParticleSystem *psys, scene->particle_systems) { - foreach(Particle &pa, psys->particles) { + for(size_t j = 0; j < scene->particle_systems.size(); j++) { + ParticleSystem *psys = scene->particle_systems[j]; + + for(size_t k = 0; k < psys->particles.size(); k++) { /* pack in texture */ + Particle& pa = psys->particles[k]; int offset = i*PARTICLE_SIZE; particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, pa.size); diff --git a/intern/cycles/render/particles.h b/intern/cycles/render/particles.h index bf2b6b77015..2509e27b44b 100644 --- a/intern/cycles/render/particles.h +++ b/intern/cycles/render/particles.h @@ -47,7 +47,7 @@ public: void tag_update(Scene *scene); - vector<Particle> particles; + array<Particle> particles; }; /* ParticleSystem Manager */ diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp index 76979e9ba3e..1cd76ff2b39 100644 --- a/intern/cycles/render/session.cpp +++ b/intern/cycles/render/session.cpp @@ -630,7 +630,7 @@ DeviceRequestedFeatures Session::get_requested_device_features() requested_features.use_camera_motion = scene->camera->use_motion; foreach(Object *object, scene->objects) { Mesh *mesh = object->mesh; - if(mesh->curves.size() > 0) { + if(mesh->num_curves()) { requested_features.use_hair = true; } requested_features.use_object_motion |= object->use_motion | mesh->use_motion_blur; diff --git a/intern/cycles/subd/subd_dice.cpp b/intern/cycles/subd/subd_dice.cpp index a5dfcd21ceb..daf0f63d695 100644 --- a/intern/cycles/subd/subd_dice.cpp +++ b/intern/cycles/subd/subd_dice.cpp @@ -48,7 +48,7 @@ void EdgeDice::reserve(int num_verts, int num_tris) vert_offset = mesh->verts.size(); tri_offset = mesh->triangles.size(); - mesh->reserve(vert_offset + num_verts, tri_offset + num_tris, 0, 0); + mesh->resize_mesh(vert_offset + num_verts, tri_offset + num_tris); Attribute *attr_vN = mesh->attributes.add(ATTR_STD_VERTEX_NORMAL); @@ -69,7 +69,7 @@ int EdgeDice::add_vert(Patch *patch, float2 uv) if(params.ptex) { Attribute *attr_ptex_uv = params.mesh->attributes.add(ATTR_STD_PTEX_UV); - params.mesh->attributes.reserve(); + params.mesh->attributes.resize(); float3 *ptex_uv = attr_ptex_uv->data_float3(); ptex_uv[vert_offset] = make_float3(uv.x, uv.y, 0.0f); @@ -84,7 +84,7 @@ void EdgeDice::add_triangle(Patch *patch, int v0, int v1, int v2) if(params.ptex) { Attribute *attr_ptex_face_id = params.mesh->attributes.add(ATTR_STD_PTEX_FACE_ID); - params.mesh->attributes.reserve(); + params.mesh->attributes.resize(); float *ptex_face_id = attr_ptex_face_id->data_float(); ptex_face_id[tri_offset] = (float)patch->ptex_face_id(); |