diff options
Diffstat (limited to 'source/blender/nodes')
5 files changed, 11 insertions, 26 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc index b07d809a091..b3b11b2e0e9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc @@ -138,12 +138,6 @@ static Mesh *create_circle_mesh(const float radius, copy_v3_v3(verts.last().co, float3(0)); } - /* Point all vertex normals in the up direction. */ - const short up_normal[3] = {0, 0, SHRT_MAX}; - for (MVert &vert : verts) { - copy_v3_v3_short(vert.no, up_normal); - } - /* Create outer edges. */ const short edge_flag = (fill_type == GEO_NODE_MESH_CIRCLE_FILL_NONE) ? ME_LOOSEEDGE : diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc index 2aa9522cf56..e0923344421 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc @@ -676,8 +676,6 @@ static Mesh *create_vertex_mesh() /* Returns a mesh with a single vertex at the origin. */ Mesh *mesh = BKE_mesh_new_nomain(1, 0, 0, 0, 0); copy_v3_fl3(mesh->mvert[0].co, 0.0f, 0.0f, 0.0f); - const short up[3] = {0, 0, SHRT_MAX}; - copy_v3_v3_short(mesh->mvert[0].no, up); return mesh; } @@ -720,8 +718,6 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top, calculate_cone_uvs(mesh, config); calculate_selection_outputs(mesh, config, attribute_outputs); - BKE_mesh_normals_tag_dirty(mesh); - return mesh; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc index 2c4b5df6030..ecb3c785212 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc @@ -89,14 +89,6 @@ Mesh *create_grid_mesh(const int verts_x, }); } - /* Point all vertex normals in the up direction. */ - { - const short up_normal[3] = {0, 0, SHRT_MAX}; - for (MVert &vert : verts) { - copy_v3_v3_short(vert.no, up_normal); - } - } - const int y_edges_start = 0; const int x_edges_start = verts_x * edges_y; const short edge_flag = (edges_x == 0 || edges_y == 0) ? ME_LOOSEEDGE : diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc index 8a2b054ece0..691267bccb8 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc @@ -203,12 +203,8 @@ Mesh *create_line_mesh(const float3 start, const float3 delta, const int count) MutableSpan<MVert> verts{mesh->mvert, mesh->totvert}; MutableSpan<MEdge> edges{mesh->medge, mesh->totedge}; - short normal[3]; - normal_float_to_short_v3(normal, math::normalize(delta)); - for (const int i : verts.index_range()) { copy_v3_v3(verts[i].co, start + delta * i); - copy_v3_v3_short(verts[i].no, normal); } fill_edge_data(edges); diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc index 41178d5c4e6..751cf917f6f 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc @@ -71,7 +71,12 @@ static int sphere_face_total(const int segments, const int rings) return quads + triangles; } +/** + * Also calculate vertex normals here, since the calculation is trivial, and it allows avoiding the + * calculation later, if it's necessary. The vertex normals are just the normalized positions. + */ static void calculate_sphere_vertex_data(MutableSpan<MVert> verts, + MutableSpan<float3> vert_normals, const float radius, const int segments, const int rings) @@ -80,7 +85,7 @@ static void calculate_sphere_vertex_data(MutableSpan<MVert> verts, const float delta_phi = (2.0f * M_PI) / segments; copy_v3_v3(verts[0].co, float3(0.0f, 0.0f, radius)); - normal_float_to_short_v3(verts[0].no, float3(0.0f, 0.0f, 1.0f)); + vert_normals.first() = float3(0.0f, 0.0f, 1.0f); int vert_index = 1; for (const int ring : IndexRange(1, rings - 1)) { @@ -92,13 +97,13 @@ static void calculate_sphere_vertex_data(MutableSpan<MVert> verts, const float x = sin_theta * std::cos(phi); const float y = sin_theta * std::sin(phi); copy_v3_v3(verts[vert_index].co, float3(x, y, z) * radius); - normal_float_to_short_v3(verts[vert_index].no, float3(x, y, z)); + vert_normals[vert_index] = float3(x, y, z); vert_index++; } } copy_v3_v3(verts.last().co, float3(0.0f, 0.0f, -radius)); - normal_float_to_short_v3(verts.last().no, float3(0.0f, 0.0f, -1.0f)); + vert_normals.last() = float3(0.0f, 0.0f, -1.0f); } static void calculate_sphere_edge_indices(MutableSpan<MEdge> edges, @@ -279,7 +284,9 @@ static Mesh *create_uv_sphere_mesh(const float radius, const int segments, const MutableSpan<MEdge> edges{mesh->medge, mesh->totedge}; MutableSpan<MPoly> polys{mesh->mpoly, mesh->totpoly}; - calculate_sphere_vertex_data(verts, radius, segments, rings); + MutableSpan vert_normals{(float3 *)BKE_mesh_vertex_normals_for_write(mesh), mesh->totvert}; + calculate_sphere_vertex_data(verts, vert_normals, radius, segments, rings); + BKE_mesh_vertex_normals_clear_dirty(mesh); calculate_sphere_edge_indices(edges, segments, rings); |