Contents

Unreal foliage 吸附物体

Contents
1
ULandscapeHeightfieldCollisionComponent::SnapFoliageInstances(const FBox& InInstanceBox)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

void FArashiListMeshAction::SnapFoliage()
{
    UWorld * InWorld=GWorld;
    FScopedTransaction Transaction(NSLOCTEXT("UnrealEd", "FoliageMode_Transaction_SnapToGround", "Snap Foliage To Ground"));
    {       
      bool bMovedInstance = false;
      const int32 NumLevels = InWorld->GetNumLevels();
      for (int32 LevelIdx = 0; LevelIdx < NumLevels; ++LevelIdx)
      {          
         ULevel* Level = InWorld->GetLevel(LevelIdx);
         AInstancedFoliageActor* IFA = AInstancedFoliageActor::GetInstancedFoliageActorForLevel(Level);
         if (IFA)
         {             
            bool bFoundSelection = false;
            for (auto& MeshPair : IFA->FoliageInfos)
            {                
               FFoliageInfo& FoliageInfo = *MeshPair.Value;
               int32 PlacedInstanceCount = FoliageInfo.GetPlacedInstanceCount();
               //构造一个0到PlacedInstanceCount-1的数组
               TArray<int32> SelectedIndices;
               for (int32 i = 0; i < PlacedInstanceCount; ++i)
               {                   
                  SelectedIndices.Add(i);
               }                
               if(PlacedInstanceCount>0)
               {                   // Mark actor once we found selection
                  {
                     IFA->Modify();
                     bFoundSelection = true;
                  }
                  FoliageInfo.PreMoveInstances(IFA, SelectedIndices);

                  for (int32 InstanceIndex : SelectedIndices)
                  {                      
                  bMovedInstance |= SnapInstanceToGround(IFA, MeshPair.Key->AlignMaxAngle, FoliageInfo, InstanceIndex);
                  }
                   FoliageInfo.PostMoveInstances(IFA, SelectedIndices);
               }             
            }          
         }       
      }
      if (bMovedInstance)
      {       

      }    
   }
}