forked from orfeasel/UE4-Cpp-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code for runtime vertex painting
- Loading branch information
Showing
6 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Procedural mesh tut | ||
|
||
Read the full tutorial here: https://wp.me/p6hvtS-rh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
using UnrealBuildTool; | ||
|
||
public class VertexPainting : ModuleRules | ||
{ | ||
public VertexPainting(ReadOnlyTargetRules Target) : base(Target) | ||
{ | ||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; | ||
|
||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RenderCore" }); | ||
|
||
PrivateDependencyModuleNames.AddRange(new string[] { }); | ||
|
||
// Uncomment if you are using Slate UI | ||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); | ||
|
||
// Uncomment if you are using online features | ||
// PrivateDependencyModuleNames.Add("OnlineSubsystem"); | ||
|
||
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
#include "VertexPaintingFunctionLibrary.h" | ||
|
||
void UVertexPaintingFunctionLibrary::PaintSMVertices(UStaticMeshComponent* SMComp) | ||
{ | ||
if (!SMComp) return; | ||
|
||
//Get the static mesh that we're going to paint | ||
UStaticMesh* SM = SMComp->GetStaticMesh(); | ||
if (SM) | ||
{ | ||
//Get the vertex buffer from the 1st lod | ||
//FPositionVertexBuffer* PositionVertexBuffer = &SM->RenderData->LODResources[0].VertexBuffers.PositionVertexBuffer; | ||
|
||
//Make sure that we have at least 1 LOD | ||
SMComp->SetLODDataCount(1, SMComp->LODData.Num()); | ||
FStaticMeshComponentLODInfo* LODInfo = &SMComp->LODData[0]; //We're going to modify the 1st LOD only | ||
|
||
//Empty the painted vertices and assign a new color vertex buffer which will contain the new colors for each vertex | ||
LODInfo->PaintedVertices.Empty(); | ||
LODInfo->OverrideVertexColors = new FColorVertexBuffer(); | ||
|
||
//We're going to use the LODResources to get the total number of vertices that the provided mesh has | ||
FStaticMeshLODResources& LodResources = SM->RenderData->LODResources[0]; | ||
|
||
//Creating a color array | ||
TArray<FColor> RandomColorArray; | ||
//Since we know beforehand the number of elements we might as well reserve the memory now | ||
RandomColorArray.Reserve(LodResources.GetNumVertices() - 1); | ||
|
||
for (int32 i = 0; i < LodResources.GetNumVertices(); i++) | ||
{ | ||
//Generate a random color for the current vertex | ||
RandomColorArray.Add(FColor::MakeRandomColor()); | ||
} | ||
|
||
//Initialize the new vertex colros with the array we created above | ||
LODInfo->OverrideVertexColors->InitFromColorArray(RandomColorArray); | ||
|
||
//Initialize resource and mark render state of object as dirty in order for the engine to re-render it | ||
BeginInitResource(LODInfo->OverrideVertexColors); | ||
SMComp->MarkRenderStateDirty(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Kismet/BlueprintFunctionLibrary.h" | ||
#include "VertexPaintingFunctionLibrary.generated.h" | ||
|
||
/** | ||
* | ||
*/ | ||
UCLASS() | ||
class VERTEXPAINTING_API UVertexPaintingFunctionLibrary : public UBlueprintFunctionLibrary | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
|
||
UFUNCTION(BlueprintCallable, Category = VertexPainting) | ||
static void PaintSMVertices(UStaticMeshComponent* SMComp); | ||
|
||
|
||
}; |