Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| int element_index, | int element_index, | ||||
| VectorSet<int> &r_vertex_indices)>; | VectorSet<int> &r_vertex_indices)>; | ||||
| static void scale_vertex_islands_uniformly(Mesh &mesh, | static void scale_vertex_islands_uniformly(Mesh &mesh, | ||||
| const Span<ElementIsland> islands, | const Span<ElementIsland> islands, | ||||
| const UniformScaleParams ¶ms, | const UniformScaleParams ¶ms, | ||||
| const GetVertexIndicesFn get_vertex_indices) | const GetVertexIndicesFn get_vertex_indices) | ||||
| { | { | ||||
| MutableSpan<MVert> verts = mesh.verts_for_write(); | MutableSpan<float3> positions = mesh.vert_positions_for_write(); | ||||
| const Span<MEdge> edges = mesh.edges(); | const Span<MEdge> edges = mesh.edges(); | ||||
| const Span<MPoly> polys = mesh.polys(); | const Span<MPoly> polys = mesh.polys(); | ||||
| const Span<MLoop> loops = mesh.loops(); | const Span<MLoop> loops = mesh.loops(); | ||||
| threading::parallel_for(islands.index_range(), 256, [&](const IndexRange range) { | threading::parallel_for(islands.index_range(), 256, [&](const IndexRange range) { | ||||
| for (const int island_index : range) { | for (const int island_index : range) { | ||||
| const ElementIsland &island = islands[island_index]; | const ElementIsland &island = islands[island_index]; | ||||
| float scale = 0.0f; | float scale = 0.0f; | ||||
| float3 center = {0.0f, 0.0f, 0.0f}; | float3 center = {0.0f, 0.0f, 0.0f}; | ||||
| VectorSet<int> vertex_indices; | VectorSet<int> vertex_indices; | ||||
| for (const int poly_index : island.element_indices) { | for (const int poly_index : island.element_indices) { | ||||
| get_vertex_indices(edges, polys, loops, poly_index, vertex_indices); | get_vertex_indices(edges, polys, loops, poly_index, vertex_indices); | ||||
| center += params.centers[poly_index]; | center += params.centers[poly_index]; | ||||
| scale += params.scales[poly_index]; | scale += params.scales[poly_index]; | ||||
| } | } | ||||
| /* Divide by number of elements to get the average. */ | /* Divide by number of elements to get the average. */ | ||||
| const float f = 1.0f / island.element_indices.size(); | const float f = 1.0f / island.element_indices.size(); | ||||
| scale *= f; | scale *= f; | ||||
| center *= f; | center *= f; | ||||
| for (const int vert_index : vertex_indices) { | for (const int vert_index : vertex_indices) { | ||||
| MVert &vert = verts[vert_index]; | positions[vert_index] = transform_with_uniform_scale(positions[vert_index], center, scale); | ||||
| const float3 old_position = vert.co; | |||||
| const float3 new_position = transform_with_uniform_scale(old_position, center, scale); | |||||
| copy_v3_v3(vert.co, new_position); | |||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||
| BKE_mesh_tag_coords_changed(&mesh); | BKE_mesh_tag_coords_changed(&mesh); | ||||
| } | } | ||||
| static void scale_vertex_islands_on_axis(Mesh &mesh, | static void scale_vertex_islands_on_axis(Mesh &mesh, | ||||
| const Span<ElementIsland> islands, | const Span<ElementIsland> islands, | ||||
| const AxisScaleParams ¶ms, | const AxisScaleParams ¶ms, | ||||
| const GetVertexIndicesFn get_vertex_indices) | const GetVertexIndicesFn get_vertex_indices) | ||||
| { | { | ||||
| MutableSpan<MVert> verts = mesh.verts_for_write(); | MutableSpan<float3> positions = mesh.vert_positions_for_write(); | ||||
| const Span<MEdge> edges = mesh.edges(); | const Span<MEdge> edges = mesh.edges(); | ||||
| const Span<MPoly> polys = mesh.polys(); | const Span<MPoly> polys = mesh.polys(); | ||||
| const Span<MLoop> loops = mesh.loops(); | const Span<MLoop> loops = mesh.loops(); | ||||
| threading::parallel_for(islands.index_range(), 256, [&](const IndexRange range) { | threading::parallel_for(islands.index_range(), 256, [&](const IndexRange range) { | ||||
| for (const int island_index : range) { | for (const int island_index : range) { | ||||
| const ElementIsland &island = islands[island_index]; | const ElementIsland &island = islands[island_index]; | ||||
| Show All 16 Lines | |||||
| axis *= f; | axis *= f; | ||||
| if (math::is_zero(axis)) { | if (math::is_zero(axis)) { | ||||
| axis = float3(1.0f, 0.0f, 0.0f); | axis = float3(1.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| const float4x4 transform = create_single_axis_transform(center, axis, scale); | const float4x4 transform = create_single_axis_transform(center, axis, scale); | ||||
| for (const int vert_index : vertex_indices) { | for (const int vert_index : vertex_indices) { | ||||
| MVert &vert = verts[vert_index]; | positions[vert_index] = transform * positions[vert_index]; | ||||
| const float3 old_position = vert.co; | |||||
| const float3 new_position = transform * old_position; | |||||
| copy_v3_v3(vert.co, new_position); | |||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||
| BKE_mesh_tag_coords_changed(&mesh); | BKE_mesh_tag_coords_changed(&mesh); | ||||
| } | } | ||||
| static Vector<ElementIsland> prepare_face_islands(const Mesh &mesh, const IndexMask face_selection) | static Vector<ElementIsland> prepare_face_islands(const Mesh &mesh, const IndexMask face_selection) | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||