-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
178 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,102 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
#include "MyActor.h" | ||
|
||
|
||
// Sets default values | ||
AMyActor::AMyActor() | ||
{ | ||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. | ||
PrimaryActorTick.bCanEverTick = true; | ||
|
||
CustomMesh = CreateDefaultSubobject<UProceduralMeshComponent>("CustomMesh"); | ||
SetRootComponent(CustomMesh); | ||
CustomMesh->bUseAsyncCooking = true; | ||
|
||
} | ||
|
||
// Called when the game starts or when spawned | ||
void AMyActor::BeginPlay() | ||
{ | ||
Super::BeginPlay(); | ||
GenerateCubeMesh(); | ||
} | ||
|
||
void AMyActor::AddTriangle(int32 V1, int32 V2, int32 V3) | ||
{ | ||
Triangles.Add(V1); | ||
Triangles.Add(V2); | ||
Triangles.Add(V3); | ||
} | ||
|
||
|
||
void AMyActor::GenerateCubeMesh() | ||
{ | ||
//6 sides on cube, 4 verts each (corners) | ||
|
||
//These are relative locations to the placed Actor in the world | ||
Vertices.Add(FVector(0, -100, 0)); //lower left - 0 | ||
Vertices.Add(FVector(0, -100, 100)); //upper left - 1 | ||
Vertices.Add(FVector(0, 100, 0)); //lower right - 2 | ||
Vertices.Add(FVector(0, 100, 100)); //upper right - 3 | ||
|
||
Vertices.Add(FVector(100, -100, 0)); //lower front left - 4 | ||
Vertices.Add(FVector(100, -100, 100)); //upper front left - 5 | ||
|
||
Vertices.Add(FVector(100, 100, 100)); //upper front right - 6 | ||
Vertices.Add(FVector(100, 100, 0)); //lower front right - 7 | ||
|
||
//Back face of cube | ||
AddTriangle(0, 2, 3); //normal face | ||
//AddTriangle(3, 2, 0); // flipped face | ||
AddTriangle(3, 1, 0); | ||
|
||
//Left face of cube | ||
AddTriangle(0, 1, 4); | ||
AddTriangle(4, 1, 5); | ||
|
||
//Front face of cube | ||
AddTriangle(4, 5, 7); | ||
AddTriangle(7, 5, 6); | ||
|
||
//Right face of cube | ||
AddTriangle(7, 6, 3); | ||
AddTriangle(3, 2, 7); | ||
|
||
//Top face | ||
AddTriangle(1, 3, 5); | ||
AddTriangle(6, 5, 3); | ||
|
||
//bottom face | ||
AddTriangle(2, 0, 4); | ||
AddTriangle(4, 7, 2); | ||
|
||
TArray<FLinearColor> VertexColors; | ||
VertexColors.Add(FLinearColor(0.f, 0.f, 1.f)); | ||
VertexColors.Add(FLinearColor(1.f, 0.f, 0.f)); | ||
VertexColors.Add(FLinearColor(1.f, 0.f, 0.f)); | ||
VertexColors.Add(FLinearColor(0.f, 1.f, 0.f)); | ||
VertexColors.Add(FLinearColor(0.5f, 1.f, 0.5f)); | ||
VertexColors.Add(FLinearColor(0.f, 1.f, 0.f)); | ||
VertexColors.Add(FLinearColor(1.f, 1.f, 0.f)); | ||
VertexColors.Add(FLinearColor(0.f, 1.f, 1.f)); | ||
|
||
CustomMesh->CreateMeshSection_LinearColor(0, Vertices, Triangles, TArray<FVector>(), TArray<FVector2D>(), VertexColors, TArray<FProcMeshTangent>(),true); | ||
} | ||
|
||
|
||
|
||
// Called every frame | ||
void AMyActor::Tick(float DeltaTime) | ||
{ | ||
Super::Tick(DeltaTime); | ||
|
||
//Moving the mesh | ||
for (int32 index = 0; index < Vertices.Num(); index++) | ||
{ | ||
//Moving each vertex 1 unit forward | ||
Vertices[index] += FVector(1, 0, 0); | ||
} | ||
CustomMesh->UpdateMeshSection(0, Vertices, TArray<FVector>(), TArray<FVector2D>(), TArray<FColor>(), TArray<FProcMeshTangent>()); | ||
} | ||
|
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,42 @@ | ||
// Fill out your copyright notice in the Description page of Project Settings. | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "GameFramework/Actor.h" | ||
#include "ProceduralMeshComponent.h" | ||
#include "MyActor.generated.h" | ||
|
||
UCLASS() | ||
class PROCEDURALMESH_API AMyActor : public AActor | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
// Sets default values for this actor's properties | ||
AMyActor(); | ||
|
||
protected: | ||
// Called when the game starts or when spawned | ||
virtual void BeginPlay() override; | ||
|
||
UPROPERTY(VisibleAnywhere,BlueprintReadWrite) | ||
UProceduralMeshComponent* CustomMesh; | ||
|
||
/* The vertices of the mesh */ | ||
TArray<FVector> Vertices; | ||
|
||
/* The triangles of the mesh */ | ||
TArray<int32> Triangles; | ||
|
||
/* Creates a triangle that connects the given vertices */ | ||
void AddTriangle(int32 V1, int32 V2, int32 V3); | ||
|
||
void GenerateCubeMesh(); | ||
|
||
public: | ||
|
||
// Called every frame | ||
virtual void Tick(float DeltaTime) override; | ||
|
||
}; |
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,14 @@ | ||
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved. | ||
|
||
using UnrealBuildTool; | ||
|
||
public class ProceduralMesh : ModuleRules | ||
{ | ||
public ProceduralMesh(ReadOnlyTargetRules Target) : base(Target) | ||
{ | ||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; | ||
|
||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "ProceduralMeshComponent" }); | ||
//PrivateDependencyModuleNames.AddRange(new string[] { "ProceduralMeshComponent" }); | ||
} | ||
} |
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,17 @@ | ||
{ | ||
"FileVersion": 3, | ||
"EngineAssociation": "4.18", | ||
"Category": "", | ||
"Description": "", | ||
"Modules": [ | ||
{ | ||
"Name": "ProceduralMesh", | ||
"Type": "Runtime", | ||
"LoadingPhase": "Default", | ||
"AdditionalDependencies": [ | ||
"Engine", | ||
"ProceduralMeshComponent" | ||
] | ||
} | ||
] | ||
} |
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-pE |