[Bf-blender-cvs] [109da73b988] temp-geometry-nodes-instances-api-v2: Merge branch 'master' into temp-geometry-nodes-instances-api-v2

Hans Goudey noreply at git.blender.org
Thu Mar 18 04:30:26 CET 2021


Commit: 109da73b9887f565f2f440975b8861bd553eff21
Author: Hans Goudey
Date:   Fri Feb 26 16:24:56 2021 -0600
Branches: temp-geometry-nodes-instances-api-v2
https://developer.blender.org/rB109da73b9887f565f2f440975b8861bd553eff21

Merge branch 'master' into temp-geometry-nodes-instances-api-v2

===================================================================



===================================================================

diff --cc source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index 0addfaa8bf2,d9878d54353..a15bc784a55
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@@ -99,16 -98,17 +99,18 @@@ static int sample_mesh_surface(const Me
  {
    Span<MLoopTri> looptris = get_mesh_looptris(mesh);
  
 +  int points_len = 0;
    for (const int looptri_index : looptris.index_range()) {
      const MLoopTri &looptri = looptris[looptri_index];
-     const int v0_index = mesh.mloop[looptri.tri[0]].v;
-     const int v1_index = mesh.mloop[looptri.tri[1]].v;
-     const int v2_index = mesh.mloop[looptri.tri[2]].v;
- 
-     const float3 v0_pos = transform * float3(mesh.mvert[v0_index].co);
-     const float3 v1_pos = transform * float3(mesh.mvert[v1_index].co);
-     const float3 v2_pos = transform * float3(mesh.mvert[v2_index].co);
+     const int v0_loop = looptri.tri[0];
+     const int v1_loop = looptri.tri[1];
+     const int v2_loop = looptri.tri[2];
+     const int v0_index = mesh.mloop[v0_loop].v;
+     const int v1_index = mesh.mloop[v1_loop].v;
+     const int v2_index = mesh.mloop[v2_loop].v;
 -    const float3 v0_pos = mesh.mvert[v0_index].co;
 -    const float3 v1_pos = mesh.mvert[v1_index].co;
 -    const float3 v2_pos = mesh.mvert[v2_index].co;
++    const float3 v0_pos = transform * mesh.mvert[v0_index].co;
++    const float3 v1_pos = transform * mesh.mvert[v1_index].co;
++    const float3 v2_pos = transform * mesh.mvert[v2_index].co;
  
      float looptri_density_factor = 1.0f;
      if (density_factors != nullptr) {
@@@ -219,16 -199,16 +221,16 @@@ BLI_NOINLINE static void update_elimina
      const MLoopTri &looptri = looptris[looptri_indices[i]];
      const float3 bary_coord = bary_coords[i];
  
-     const int v0_index = mesh.mloop[looptri.tri[0]].v;
-     const int v1_index = mesh.mloop[looptri.tri[1]].v;
-     const int v2_index = mesh.mloop[looptri.tri[2]].v;
+     const int v0_loop = looptri.tri[0];
+     const int v1_loop = looptri.tri[1];
+     const int v2_loop = looptri.tri[2];
  
-     const float v0_density_factor = std::max(0.0f, density_factors[v0_index]);
-     const float v1_density_factor = std::max(0.0f, density_factors[v1_index]);
-     const float v2_density_factor = std::max(0.0f, density_factors[v2_index]);
+     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 v2_density_factor = std::max(0.0f, density_factors[v2_loop]);
  
 -    const float probablity = v0_density_factor * bary_coord.x + v1_density_factor * bary_coord.y +
 -                             v2_density_factor * bary_coord.z;
 +    const float probablity = attribute_math::mix3<float>(
 +        bary_coord, v0_density_factor, v1_density_factor, v2_density_factor);
  
      const float hash = BLI_hash_int_01(bary_coord.hash());
      if (hash > probablity) {
@@@ -421,49 -362,26 +423,49 @@@ BLI_NOINLINE static void compute_specia
    OutputAttributePtr rotation_attribute = component.attribute_try_get_for_output(
        "rotation", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
  
 -  MutableSpan<int> ids = id_attribute->get_span_for_write_only<int>();
 -  MutableSpan<float3> normals = normal_attribute->get_span_for_write_only<float3>();
 -  MutableSpan<float3> rotations = rotation_attribute->get_span_for_write_only<float3>();
 +  MutableSpan<int> ids_full = id_attribute->get_span_for_write_only<int>();
 +  MutableSpan<float3> normals_full = normal_attribute->get_span_for_write_only<float3>();
 +  MutableSpan<float3> rotations_full = rotation_attribute->get_span_for_write_only<float3>();
  
 -  Span<MLoopTri> looptris = get_mesh_looptris(mesh);
 -  for (const int i : bary_coords.index_range()) {
 -    const int looptri_index = looptri_indices[i];
 -    const MLoopTri &looptri = looptris[looptri_index];
 -    const float3 &bary_coord = bary_coords[i];
 +  int i_point = 0;
 +  int i_instance = 0;
 +  for (const GeometryInstanceGroup &set_group : sets) {
 +    const GeometrySet &set = set_group.geometry_set;
 +    if (!set.has_mesh()) {
 +      continue;
 +    }
  
 -    const int v0_index = mesh.mloop[looptri.tri[0]].v;
 -    const int v1_index = mesh.mloop[looptri.tri[1]].v;
 -    const int v2_index = mesh.mloop[looptri.tri[2]].v;
 -    const float3 v0_pos = mesh.mvert[v0_index].co;
 -    const float3 v1_pos = mesh.mvert[v1_index].co;
 -    const float3 v2_pos = mesh.mvert[v2_index].co;
 +    const MeshComponent &component = *set.get_component_for_read<MeshComponent>();
 +    const Mesh &mesh = *component.get_for_read();
 +    Span<MLoopTri> looptris = get_mesh_looptris(mesh);
 +
 +    for (const int UNUSED(i_set_instance) : set_group.transforms.index_range()) {
 +      Span<float3> bary_coords = bary_coords_array[i_instance].as_span();
 +      Span<int> looptri_indices = looptri_indices_array[i_instance].as_span();
 +      MutableSpan<int> ids = ids_full.slice(i_point, bary_coords.size());
 +      MutableSpan<float3> normals = normals_full.slice(i_point, bary_coords.size());
 +      MutableSpan<float3> rotations = rotations_full.slice(i_point, bary_coords.size());
 +
 +      for (const int i : bary_coords.index_range()) {
 +        const int looptri_index = looptri_indices[i];
 +        const MLoopTri &looptri = looptris[looptri_index];
 +        const float3 &bary_coord = bary_coords[i];
 +
 +        const int v0_index = mesh.mloop[looptri.tri[0]].v;
 +        const int v1_index = mesh.mloop[looptri.tri[1]].v;
 +        const int v2_index = mesh.mloop[looptri.tri[2]].v;
 +        const float3 v0_pos = mesh.mvert[v0_index].co;
 +        const float3 v1_pos = mesh.mvert[v1_index].co;
 +        const float3 v2_pos = mesh.mvert[v2_index].co;
 +
-         ids[i] = (int)(bary_coord.hash()) + looptri_index;
++        ids[i] = (int)(bary_coord.hash()) + (uint64_t)looptri_index;
 +        normal_tri_v3(normals[i], v0_pos, v1_pos, v2_pos);
 +        rotations[i] = normal_to_euler_rotation(normals[i]);
 +      }
  
 -    ids[i] = (int)(bary_coord.hash() + (uint64_t)looptri_index);
 -    normal_tri_v3(normals[i], v0_pos, v1_pos, v2_pos);
 -    rotations[i] = normal_to_euler_rotation(normals[i]);
 +      i_instance++;
 +      i_point += bary_coords.size();
 +    }
    }
  
    id_attribute.apply_span_and_save();
@@@ -489,10 -422,14 +491,11 @@@ static void geo_node_point_distribute_e
    GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
    GeometrySet geometry_set_out;
  
-   const GeometryNodePointDistributeMethod distribute_method =
-       static_cast<GeometryNodePointDistributeMethod>(params.node().custom1);
 -  /* TODO: This node only needs read-only access to input instances. */
 -  geometry_set = geometry_set_realize_instances(geometry_set);
++  const GeometryNodePointDistributeMode distribute_method =
++      static_cast<GeometryNodePointDistributeMode>(params.node().custom1);
  
 -  GeometryNodePointDistributeMode distribute_method = static_cast<GeometryNodePointDistributeMode>(
 -      params.node().custom1);
 -
 -  if (!geometry_set.has_mesh()) {
 +  if (!geometry_set.has_mesh() && !geometry_set.has_instances()) {
+     params.error_message_add(NodeWarningType::Error, "Geometry must contain a mesh.");
      params.set_output("Geometry", std::move(geometry_set_out));
      return;
    }



More information about the Bf-blender-cvs mailing list