Differential D15982 Diff 55977 source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| static void sample_mesh_surface(const Mesh &mesh, | static void sample_mesh_surface(const Mesh &mesh, | ||||
| const float base_density, | const float base_density, | ||||
| const Span<float> density_factors, | const Span<float> density_factors, | ||||
| const int seed, | const int seed, | ||||
| Vector<float3> &r_positions, | Vector<float3> &r_positions, | ||||
| Vector<float3> &r_bary_coords, | Vector<float3> &r_bary_coords, | ||||
| Vector<int> &r_looptri_indices) | Vector<int> &r_looptri_indices) | ||||
| { | { | ||||
| const Span<MVert> verts = mesh.verts(); | const Span<float3> positions = mesh.positions(); | ||||
| const Span<MLoop> loops = mesh.loops(); | const Span<MLoop> loops = mesh.loops(); | ||||
| const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh), | const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh), | ||||
| BKE_mesh_runtime_looptri_len(&mesh)}; | BKE_mesh_runtime_looptri_len(&mesh)}; | ||||
| for (const int looptri_index : looptris.index_range()) { | for (const int looptri_index : looptris.index_range()) { | ||||
| const MLoopTri &looptri = looptris[looptri_index]; | const MLoopTri &looptri = looptris[looptri_index]; | ||||
| const int v0_loop = looptri.tri[0]; | const int v0_loop = looptri.tri[0]; | ||||
| const int v1_loop = looptri.tri[1]; | const int v1_loop = looptri.tri[1]; | ||||
| const int v2_loop = looptri.tri[2]; | const int v2_loop = looptri.tri[2]; | ||||
| const int v0_index = loops[v0_loop].v; | const int v0_index = loops[v0_loop].v; | ||||
| const int v1_index = loops[v1_loop].v; | const int v1_index = loops[v1_loop].v; | ||||
| const int v2_index = loops[v2_loop].v; | const int v2_index = loops[v2_loop].v; | ||||
| const float3 v0_pos = verts[v0_index].co; | const float3 v0_pos = positions[v0_index]; | ||||
| const float3 v1_pos = verts[v1_index].co; | const float3 v1_pos = positions[v1_index]; | ||||
| const float3 v2_pos = verts[v2_index].co; | const float3 v2_pos = positions[v2_index]; | ||||
| float looptri_density_factor = 1.0f; | float looptri_density_factor = 1.0f; | ||||
| if (!density_factors.is_empty()) { | if (!density_factors.is_empty()) { | ||||
| const float v0_density_factor = std::max(0.0f, density_factors[v0_loop]); | const float v0_density_factor = std::max(0.0f, density_factors[v0_loop]); | ||||
| const float v1_density_factor = std::max(0.0f, density_factors[v1_loop]); | const float v1_density_factor = std::max(0.0f, density_factors[v1_loop]); | ||||
| const float v2_density_factor = std::max(0.0f, density_factors[v2_loop]); | const float v2_density_factor = std::max(0.0f, density_factors[v2_loop]); | ||||
| looptri_density_factor = (v0_density_factor + v1_density_factor + v2_density_factor) / 3.0f; | looptri_density_factor = (v0_density_factor + v1_density_factor + v2_density_factor) / 3.0f; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| normals = point_attributes.lookup_or_add_for_write_only_span<float3>( | normals = point_attributes.lookup_or_add_for_write_only_span<float3>( | ||||
| attribute_outputs.normal_id.get(), ATTR_DOMAIN_POINT); | attribute_outputs.normal_id.get(), ATTR_DOMAIN_POINT); | ||||
| } | } | ||||
| if (attribute_outputs.rotation_id) { | if (attribute_outputs.rotation_id) { | ||||
| rotations = point_attributes.lookup_or_add_for_write_only_span<float3>( | rotations = point_attributes.lookup_or_add_for_write_only_span<float3>( | ||||
| attribute_outputs.rotation_id.get(), ATTR_DOMAIN_POINT); | attribute_outputs.rotation_id.get(), ATTR_DOMAIN_POINT); | ||||
| } | } | ||||
| const Span<MVert> verts = mesh.verts(); | const Span<float3> positions = mesh.positions(); | ||||
| const Span<MLoop> loops = mesh.loops(); | const Span<MLoop> loops = mesh.loops(); | ||||
| const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh), | const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh), | ||||
| BKE_mesh_runtime_looptri_len(&mesh)}; | BKE_mesh_runtime_looptri_len(&mesh)}; | ||||
| for (const int i : bary_coords.index_range()) { | for (const int i : bary_coords.index_range()) { | ||||
| const int looptri_index = looptri_indices[i]; | const int looptri_index = looptri_indices[i]; | ||||
| const MLoopTri &looptri = looptris[looptri_index]; | const MLoopTri &looptri = looptris[looptri_index]; | ||||
| const float3 &bary_coord = bary_coords[i]; | const float3 &bary_coord = bary_coords[i]; | ||||
| const int v0_index = loops[looptri.tri[0]].v; | const int v0_index = loops[looptri.tri[0]].v; | ||||
| const int v1_index = loops[looptri.tri[1]].v; | const int v1_index = loops[looptri.tri[1]].v; | ||||
| const int v2_index = loops[looptri.tri[2]].v; | const int v2_index = loops[looptri.tri[2]].v; | ||||
| const float3 v0_pos = verts[v0_index].co; | const float3 v0_pos = positions[v0_index]; | ||||
| const float3 v1_pos = verts[v1_index].co; | const float3 v1_pos = positions[v1_index]; | ||||
| const float3 v2_pos = verts[v2_index].co; | const float3 v2_pos = positions[v2_index]; | ||||
| ids.span[i] = noise::hash(noise::hash_float(bary_coord), looptri_index); | ids.span[i] = noise::hash(noise::hash_float(bary_coord), looptri_index); | ||||
| float3 normal; | float3 normal; | ||||
| if (!normals.span.is_empty() || !rotations.span.is_empty()) { | if (!normals.span.is_empty() || !rotations.span.is_empty()) { | ||||
| normal_tri_v3(normal, v0_pos, v1_pos, v2_pos); | normal_tri_v3(normal, v0_pos, v1_pos, v2_pos); | ||||
| } | } | ||||
| if (!normals.span.is_empty()) { | if (!normals.span.is_empty()) { | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||