x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to get skeletal mesh vertex positions after a morph is applied

I'm trying to get vertex positions after all morphs are applied. I'm able to get vertex positions transformed by bones, but not transformed by the morphs. I took a loo into SkinVertices in SkeletalRenderCPUSkin.cpp as suggested in https://answers.unrealengine.com/questions/222373/morph-targets-dont-update-bounds.html, but I'm not able to determine what exactly gets teh morphed vertex position. I tried just copying the method wholesale but I can't make out how to use VertexType as I can't include ProxyLODMeshTypes.h as it's part of a plugin and I just can't seem to include it correctly.

This is my current code below. It crashes when run. Without the big for loop in the middle it works to get vertex positions after bone deformation but adding it in I get an error.

Code:

 bool UCustomFunctionLibrary::AnimatedVertex__GetAnimatedVertexLocations(USkeletalMeshComponent* Mesh, TArray<FVector>& Locations, TArray<FMatrix>& CacheToLocals, int32 LOD_Index, bool PerformPawnVelocityCorrection)
 {
     if (!Mesh) { return false; }
 
     //~~~~~~~~~~~~~ Locations.Empty(); //~~~~~~~~~~~~~
     FSkeletalMeshLODRenderData& LOD = Mesh->GetSkeletalMeshRenderData()->LODRenderData[LOD_Index];
     FSkinWeightVertexBuffer& Buffer = LOD.SkinWeightVertexBuffer;
 
     //Output current locals to variable
     Mesh->GetCurrentRefToLocalMatrices(CacheToLocals, LOD_Index);
 
     Mesh->ComputeSkinnedPositions(Mesh, Locations, CacheToLocals, LOD, Buffer);
 
     for (int i = 0; i < Locations.Num(); i++)
     {
         int32 SectionIndex;
         int32 VertexBufferBaseIndex;
         LOD.GetSectionFromVertexIndex(i, SectionIndex, VertexBufferBaseIndex);
         FSkelMeshRenderSection Section = LOD.RenderSections[SectionIndex];
 
         // Prefetch all bone indices
         const FBoneIndexType* BoneMap = Section.BoneMap.GetData();
         FPlatformMisc::Prefetch(BoneMap);
         FPlatformMisc::Prefetch(BoneMap, PLATFORM_CACHE_LINE_SIZE);
     
         const int32 NumSoftVertices = Section.GetNumVertices();
         if (NumSoftVertices > 0)
         {
             for (int32 VertexIndex = VertexBufferBaseIndex; VertexIndex < NumSoftVertices; VertexIndex++)
             {
                 const int32 VertexBufferIndex = Section.GetVertexBufferIndex() + VertexIndex;
     
                 const FVector& VertexPosition = LOD.StaticVertexBuffers.PositionVertexBuffer.VertexPosition(VertexBufferIndex);
                 FPlatformMisc::Prefetch(&VertexPosition, PLATFORM_CACHE_LINE_SIZE);    // Prefetch next vertices
     
                 Locations[i] = Locations[i] + VertexPosition;
             }
         }
     }
 
     FTransform ToWorld = Mesh->GetComponentTransform(); FVector WorldLocation = ToWorld.GetLocation();
 
     //Pawn Velocity Correction UPawnMovementComponent* MovementComp = nullptr; if(PerformPawnVelocityCorrection) { APawn* Pawn = Cast<APawn>(Mesh->GetOwner()); MovementComp = (Pawn) ? Pawn->GetMovementComponent() : NULL; } bool DoVelocityCorrection = PerformPawnVelocityCorrection && MovementComp; //Pawn Velocity Correction
 
     for (FVector& EachVertex : Locations) 
     { 
         EachVertex = WorldLocation + ToWorld.TransformVector(EachVertex); 
         //if (PerformPawnVelocityCorrection) 
         //{ 
         //    EachVertex += MovementComp->Velocity * FApp::GetDeltaTime(); 
         //} 
     }
 
     return true;
 }

Error:

 Fatal error: [File:D:\Build\++UE4\Sync\Engine\Source\Runtime\RenderCore\Private\RenderResource.cpp] [Line: 128] A FRenderResource was deleted without being released first!
 
 UE4Editor_Core!FDebug::AssertFailed() [d:\build\++ue4\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:425]
 UE4Editor_RenderCore!FRenderResource::~FRenderResource() [d:\build\++ue4\sync\engine\source\runtime\rendercore\private\renderresource.cpp:128]

Does anyone have any suggestions? I've been digging into this for hours and I just can't make it work. Mostly because I don't understand the underlying code in the rendering pipeline. Rendering is not my forte.

Product Version: UE 4.20
Tags:
more ▼

asked Aug 10 '18 at 04:21 AM in C++ Programming

avatar image

Jared Therriault
399 26 22 52

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question