diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-05-08 01:09:08 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-05-28 19:31:00 +0300 |
commit | c96a4c8a2aeab761983b2b9c76104639c5721a2f (patch) | |
tree | 83f45ccbb3a9651df2785abb2ed8eb376a0e7c7e /intern/cycles/bvh | |
parent | b94bfe4cd8362abc4e8d256a081dc364c28a3117 (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/bvh')
-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 |
3 files changed, 36 insertions, 35 deletions
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) |