Initial commit

This commit is contained in:
Jordon Brooks 2018-04-17 23:43:50 +01:00
commit ba14820cdd
94 changed files with 1123 additions and 0 deletions

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
Content/** filter=lfs diff=lfs merge=lfs -text

14
.gitignore vendored Normal file
View file

@ -0,0 +1,14 @@
Binaries
DerivedDataCache
Intermediate
Saved
.vscode
.vs
*.VC.db
*.opensdf
*.opendb
*.sdf
*.sln
*.suo
*.xcodeproj
*.xcworkspace

2
Config/DefaultEditor.ini Normal file
View file

@ -0,0 +1,2 @@

83
Config/DefaultEngine.ini Normal file
View file

@ -0,0 +1,83 @@
[URL]
[/Script/HardwareTargeting.HardwareTargetingSettings]
TargetedHardwareClass=Desktop
AppliedTargetedHardwareClass=Desktop
DefaultGraphicsPerformance=Maximum
AppliedDefaultGraphicsPerformance=Maximum
[/Script/EngineSettings.GameMapsSettings]
EditorStartupMap=/Game/Maps/Game.Game
GameDefaultMap=/Game/Maps/Game.Game
GlobalDefaultGameMode=/Game/FirstPersonBP/Blueprints/FirstPersonGameMode.FirstPersonGameMode_C
[/Script/Engine.GarbageCollectionSettings]
gc.TimeBetweenPurgingPendingKillObjects=60.000000
gc.ActorClusteringEnabled=True
gc.BlueprintClusteringEnabled=True
gc.MergeGCClusters=True
[/Script/Engine.RendererSettings]
r.ReflectionCaptureResolution=64
r.DefaultFeature.AntiAliasing=3
r.DefaultFeature.LensFlare=True
r.DefaultFeature.AutoExposure=False
[/Script/WindowsTargetPlatform.WindowsTargetSettings]
Compiler=VisualStudio2017
-TargetedRHIs=PCD3D_SM5
-TargetedRHIs=PCD3D_SM4
+TargetedRHIs=SF_VULKAN_SM5
MinimumOSVersion=MSOS_Vista
AudioDevice=
AudioSampleRate=48000
AudioCallbackBufferFrameSize=1024
AudioNumBuffersToEnqueue=1
AudioMaxChannels=0
AudioNumSourceWorkers=4
SpatializationPlugin=
ReverbPlugin=
OcclusionPlugin=
[/Script/Engine.PhysicsSettings]
DefaultGravityZ=-980.000000
DefaultTerminalVelocity=4000.000000
DefaultFluidFriction=0.300000
SimulateScratchMemorySize=262144
RagdollAggregateThreshold=4
TriangleMeshTriangleMinAreaThreshold=5.000000
bEnableAsyncScene=False
bEnableShapeSharing=False
bEnablePCM=True
bEnableStabilization=False
bWarnMissingLocks=True
bEnable2DPhysics=False
LockedAxis=Invalid
DefaultDegreesOfFreedom=Full3D
BounceThresholdVelocity=200.000000
FrictionCombineMode=Average
RestitutionCombineMode=Average
MaxAngularVelocity=3600.000000
MaxDepenetrationVelocity=0.000000
ContactOffsetMultiplier=0.020000
MinContactOffset=2.000000
MaxContactOffset=8.000000
bSimulateSkeletalMeshOnDedicatedServer=True
DefaultShapeComplexity=CTF_UseSimpleAndComplex
bDefaultHasComplexCollision=True
bSuppressFaceRemapTable=False
bSupportUVFromHitResults=False
bDisableActiveActors=False
bDisableCCD=False
bEnableEnhancedDeterminism=False
MaxPhysicsDeltaTime=0.033333
bSubstepping=False
bSubsteppingAsync=False
MaxSubstepDeltaTime=0.016667
MaxSubsteps=6
SyncSceneSmoothingFactor=0.000000
AsyncSceneSmoothingFactor=0.990000
InitialAverageFrameRate=0.016667
PhysXTreeRebuildRate=10

9
Config/DefaultGame.ini Normal file
View file

@ -0,0 +1,9 @@
[/Script/EngineSettings.GeneralProjectSettings]
ProjectID=46080C45406BC8BC3065A492454DFB11
[/Script/UnrealEd.ProjectPackagingSettings]
BlueprintNativizationMethod=Inclusive
BuildConfiguration=PPBC_Development
bGenerateChunks=True
ForDistribution=False

68
Config/DefaultInput.ini Normal file
View file

@ -0,0 +1,68 @@
[/Script/Engine.InputSettings]
-AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f))
-AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f))
-AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f))
-AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f))
-AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f))
-AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f))
+AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MouseWheelAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="Gamepad_LeftTriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="Gamepad_RightTriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MotionController_Left_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MotionController_Left_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MotionController_Left_TriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MotionController_Left_Grip1Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MotionController_Left_Grip2Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MotionController_Right_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MotionController_Right_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MotionController_Right_TriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MotionController_Right_Grip1Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="MotionController_Right_Grip2Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="Gamepad_Special_Left_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
+AxisConfig=(AxisKeyName="Gamepad_Special_Left_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
bAltEnterTogglesFullscreen=True
bF11TogglesFullscreen=True
bUseMouseForTouch=False
bEnableMouseSmoothing=True
bEnableFOVScaling=True
FOVScale=0.011110
DoubleClickTime=0.200000
bCaptureMouseOnLaunch=True
DefaultViewportMouseCaptureMode=CapturePermanently_IncludingInitialMouseDown
bDefaultViewportMouseLock=False
DefaultViewportMouseLockMode=LockOnCapture
+ActionMappings=(ActionName="Fire",Key=Gamepad_RightTrigger,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
+ActionMappings=(ActionName="Fire",Key=LeftMouseButton,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
+ActionMappings=(ActionName="Jump",Key=SpaceBar,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
+ActionMappings=(ActionName="Sprint",Key=LeftControl,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
+AxisMappings=(AxisName="LookUp",Key=MouseY,Scale=-1.000000)
+AxisMappings=(AxisName="LookUpRate",Key=Gamepad_RightY,Scale=1.000000)
+AxisMappings=(AxisName="MoveForward",Key=Down,Scale=-1.000000)
+AxisMappings=(AxisName="MoveForward",Key=Gamepad_LeftY,Scale=1.000000)
+AxisMappings=(AxisName="MoveForward",Key=S,Scale=-1.000000)
+AxisMappings=(AxisName="MoveForward",Key=Up,Scale=1.000000)
+AxisMappings=(AxisName="MoveForward",Key=W,Scale=1.000000)
+AxisMappings=(AxisName="MoveRight",Key=A,Scale=-1.000000)
+AxisMappings=(AxisName="MoveRight",Key=D,Scale=1.000000)
+AxisMappings=(AxisName="MoveRight",Key=Gamepad_LeftX,Scale=1.000000)
+AxisMappings=(AxisName="Turn",Key=MouseX,Scale=1.000000)
+AxisMappings=(AxisName="TurnRate",Key=Gamepad_RightX,Scale=1.000000)
+AxisMappings=(AxisName="TurnRate",Key=Left,Scale=-1.000000)
+AxisMappings=(AxisName="TurnRate",Key=Right,Scale=1.000000)
+AxisMappings=(AxisName="Jump",Key=SpaceBar,Scale=1.000000)
+AxisMappings=(AxisName="Jump",Key=LeftShift,Scale=-1.000000)
bAlwaysShowTouchInterface=False
bShowConsoleOnFourFingerTap=True
DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks
ConsoleKey=None
-ConsoleKeys=Tilde
+ConsoleKeys=Tilde

BIN
Content/Blueprints/Block.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Blueprints/NewPlayerController.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Blueprints/VoxelActor_BP.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/FirstPerson/Animations/FirstPerson_AnimBP.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/Animations/FirstPerson_Fire.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/Animations/FirstPerson_Idle.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/Animations/FirstPerson_JumpEnd.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/Animations/FirstPerson_JumpLoop.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/Animations/FirstPerson_JumpStart.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/Animations/FirstPerson_Run.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/FirstPerson/Character/Materials/M_UE4Man_Body.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/FirstPerson/Character/Mesh/SK_Mannequin_Arms.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/FirstPerson/Character/Textures/UE4_LOGO_CARD.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/FirstPerson/FPWeapon/Materials/M_FPGun.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/FirstPerson/FPWeapon/Mesh/SK_FPGun.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/FirstPerson/FPWeapon/Mesh/SK_FPGun_Skeleton.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/FPWeapon/Textures/T_FPGun_M.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/FPWeapon/Textures/T_FPGun_N.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/Meshes/BaseMaterial.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/Meshes/CubeMaterialOverride.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/FirstPerson/Meshes/FirstPersonProjectileMesh.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPerson/Textures/FirstPersonCrosshair.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPersonBP/Blueprints/FirstPersonCharacter.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPersonBP/Blueprints/FirstPersonGameMode.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPersonBP/Blueprints/FirstPersonHUD.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPersonBP/Blueprints/Hud.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPersonBP/FirstPersonOverview.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/FirstPersonBP/Maps/FirstPersonExampleMap.umap (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Geometry/Meshes/1M_Cube.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Geometry/Meshes/1M_Cube_Chamfer.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Geometry/Meshes/CubeMaterial.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Geometry/Meshes/TemplateFloor.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Geometry/Plane_1M.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Maps/Game.umap (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Maps/Game_BuiltData.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Materials/Blank.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Materials/Block.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Materials/Dirt.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Materials/Grass.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Materials/Leaf.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Materials/Stone.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Materials/Wood.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/textures/Brown_Dirt_Grass_Side.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/textures/Dirt/Brown_Dirt_16.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/textures/Grass/Colour/_Green_Grass_16.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/textures/Leaf/Leaf.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/textures/Stone/Stone_16.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/textures/Textures.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/textures/Wood/Wood_16.uasset (Stored with Git LFS) Normal file

Binary file not shown.

35
Minecraft.uproject Normal file
View file

@ -0,0 +1,35 @@
{
"FileVersion": 3,
"EngineAssociation": "4.19",
"Category": "",
"Description": "",
"Modules": [
{
"Name": "Minecraft",
"Type": "Runtime",
"LoadingPhase": "Default",
"AdditionalDependencies": [
"Engine"
]
}
],
"Plugins": [
{
"Name": "OculusVR",
"Enabled": false
},
{
"Name": "SteamVR",
"Enabled": false
},
{
"Name": "PluginPlayground",
"Enabled": false
}
],
"TargetPlatforms": [
"AllDesktop",
"WindowsNoEditor",
"HTML5"
]
}

View file

@ -0,0 +1,14 @@
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
using System.Collections.Generic;
public class MinecraftTarget : TargetRules
{
public MinecraftTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
ExtraModuleNames.AddRange( new string[] { "Minecraft" } );
}
}

View file

@ -0,0 +1,19 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "CPPController.h"
void ACPPController::BeginPlay()
{
Super::BeginPlay();
ChunkSize = ChunkLineElements * VoxelSize;
ChunkSizeHalf = ChunkSize / 1;
}
void ACPPController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View file

@ -0,0 +1,48 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "CPPController.generated.h"
/**
*
*/
UCLASS()
class MINECRAFT_API ACPPController : public APlayerController
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float RandomSeed = 12345;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FVector2D chunkCoords;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<AActor*> Chunks;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float ChunkX;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float ChunkY;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FVector CharacterPosition;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float ChunkSizeHalf;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float ChunkSize;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float VoxelSize = 100;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float ChunkLineElements = 20;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float RenderRange = 3;
public:
virtual void Tick(float DeltaTime) override;
protected:
virtual void BeginPlay() override;
};

View file

@ -0,0 +1,23 @@
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
public class Minecraft : ModuleRules
{
public Minecraft(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { "ProceduralMeshComponent" });
// 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
}
}

View file

@ -0,0 +1,6 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Minecraft.h"
#include "Modules/ModuleManager.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, Minecraft, "Minecraft" );

View file

@ -0,0 +1,6 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"

View file

@ -0,0 +1,7 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "MinecraftGameModeBase.h"

View file

@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "MinecraftGameModeBase.generated.h"
/**
*
*/
UCLASS()
class MINECRAFT_API AMinecraftGameModeBase : public AGameModeBase
{
GENERATED_BODY()
};

View file

@ -0,0 +1,435 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "VoxelActor.h"
const int32 bTriangles[] = { 2, 1, 0, 0, 3, 2 };
const FVector2D bUVs[] = {FVector2D(0.0, 0.0), FVector2D(0.0, 1.0), FVector2D(1.0, 1.0), FVector2D(1.0, 0.0)};
const FVector bNormals0[] = {FVector(0, 0, 1), FVector(0, 0, 1), FVector(0, 0, 1), FVector(0, 0, 1)};
const FVector bNormals1[] = { FVector(0, 0, -1), FVector(0, 0, -1), FVector(0, 0, -1), FVector(0, 0, -1) };
const FVector bNormals2[] = { FVector(0, 1, 0), FVector(0, 1, 0), FVector(0, 1, 0), FVector(0, 1, 0) };
const FVector bNormals3[] = { FVector(0, -1, 0), FVector(0, -1, 0), FVector(0, -1, 0), FVector(0, -1, 0) };
const FVector bNormals4[] = { FVector(1, 0, 0), FVector(1, 0, 0), FVector(1, 0, 0), FVector(1, 0, 0) };
const FVector bNormals5[] = { FVector(-1, 0, 0), FVector(-1, 0, 0), FVector(-1, 0, 0), FVector(-1, 0, 0) };
const FVector bMask[] = { FVector(0, 0, 1), FVector(0, 0, -1), FVector(0, 1, 0), FVector(0, -1, 0), FVector(1, 0, 0), FVector(-1, 0, 0) };
// Sets default values
AVoxelActor::AVoxelActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
}
// Called when the game starts or when spawned
void AVoxelActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AVoxelActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AVoxelActor::OnConstruction(const FTransform & Transform)
{
FName YourObjectName("Test");
chunkZElements = 80;
chunkTotalElements = chunkLineElements * chunkLineElements * chunkZElements;
chunkLineElementsP2 = chunkLineElements * chunkLineElements;
VoxelSizeHalf = voxelSize / 2;
FString string = "voxel_" + FString::FromInt(chunkXindex) + "+" + FString::FromInt(chunkYindex);
FName name = FName(*string);
proceduralComponent = NewObject<UProceduralMeshComponent>(this, name);
proceduralComponent->RegisterComponent();
RootComponent = proceduralComponent;
RootComponent->SetWorldTransform(Transform);
RootComponent->SetMobility(EComponentMobility::Static);
Super::OnConstruction(Transform);
GenerateChunk();
UpdateMesh();
}
void AVoxelActor::GenerateChunk()
{
FRandomStream RandomStream = FRandomStream(randomSeed);
TArray<FIntVector> TreeCenters;
chunkFields.SetNumUninitialized(chunkTotalElements);
TArray <int32> noise = calculateNoise();
for (int32 x = 0; x < chunkLineElements; x++)
{
for (int32 y = 0; y < chunkLineElements; y++)
{
for (int32 z = 0; z < chunkZElements; z++)
{
int32 index = x + (y * chunkLineElements) + (z * chunkLineElementsP2);
//chunkFields[index] = (z < 30) ? 1 : 0; // Generate no noise
if (z == 31 + noise[x + y * chunkLineElements] && RandomStream.FRand() < 0.02)
TreeCenters.Add(FIntVector(x, y, z)); // WOOD
else if (z == 30 + noise[x + y * chunkLineElements])
chunkFields[index] = 1; // GRASS
else if (z >= 30 - 3 + noise[x + y * chunkLineElements] && z < 30 + noise[x + y * chunkLineElements])
chunkFields[index] = 2; // DIRT
else if (z < 30 - 3 + noise[x + y * chunkLineElements])
chunkFields[index] = 3; // STONE
else chunkFields[index] = 0; // AIR
/*if (z == 30 + noise[x + y * chunkLineElements])
chunkFields[index] = 1;
else if (z >= 27 + noise[x + y * chunkLineElements] && z < 30 + noise[x + y * chunkLineElements])
chunkFields[index] = 2;
else if (z < 27 + noise[x + y * chunkLineElements])
chunkFields[index] = 3;
else chunkFields[index] = 0;*/
//chunkFields[index] = (z == 29 + noise[x + y * chunkLineElements]) ? 2 : 0;
//chunkFields[index] = (z < 29 + noise[x + y * chunkLineElements]) ? 3 : 0;
}
}
}
for (FIntVector TreeCenter : TreeCenters)
{
int32 TreeHeight = RandomStream.RandRange(3, 6);
int32 randomX = RandomStream.RandRange(0, 2);
int32 randomY = RandomStream.RandRange(0, 2);
int32 randomZ = RandomStream.RandRange(0, 2);
for (int32 TreeX = -2; TreeX < 3; TreeX++)
{
for (int32 TreeY = -2; TreeY < 3; TreeY++)
{
for (int32 TreeZ = -2; TreeZ < 3; TreeZ++)
{
if (inRange(TreeX + TreeCenter.X, chunkLineElements) && inRange(TreeY + TreeCenter.Y, chunkLineElements) && inRange(TreeZ + TreeCenter.Z, chunkZElements))
{
float radius = FVector(TreeX * randomX, TreeY * randomY, TreeZ * randomZ).Size();
if (radius <= 2.8)
{
if (RandomStream.FRand() < 0.5 || radius <= 1.2)
{
chunkFields[TreeCenter.X + TreeX + (chunkLineElements * (TreeCenter.Y + TreeY)) + (chunkLineElementsP2 * (TreeCenter.Z + TreeZ + TreeHeight))] = 21;// LEAF
}
}
}
}
}
}
}
}
void AVoxelActor::UpdateMesh()
{
TArray<FMeshSection> meshSections;
meshSections.SetNum(Materials.Num());
int32 el_num = 0;
for (int32 x = 0; x < chunkLineElements; x++)
{
for (int32 y = 0; y < chunkLineElements; y++)
{
for (int32 z = 0; z < chunkZElements; z++)
{
int32 index = x + (chunkLineElements * y) + (chunkLineElementsP2 * z);
int32 meshIndex = chunkFields[index];
if (meshIndex > 0)
{
meshIndex--;
TArray<FVector> &Vertices = meshSections[meshIndex].Vertices;
TArray<int32> &Triangles = meshSections[meshIndex].Triangles;
TArray<FVector> &Normals = meshSections[meshIndex].Normals;
TArray<FVector2D> &UVs = meshSections[meshIndex].UVs;
TArray<FProcMeshTangent> &Tangents = meshSections[meshIndex].Tangents;
TArray<FColor> &VertexColors = meshSections[meshIndex].VertexColors;
int32 ElementID = meshSections[meshIndex].ElementID;
int triangle_num = 0;
for (int i = 0; i < 6; i++)
{
int NewIndex = index + bMask[i].X + (bMask[i].Y * chunkLineElements) + (bMask[i].Z * chunkLineElementsP2);
bool flag = false;
if (meshIndex >= 20) flag = true;
else if ((x + bMask[i].X < chunkLineElements) && (x + bMask[i].X >= 0) && (y + bMask[i].Y < chunkLineElements) && (y + bMask[i].Y >= 0))
{
if (NewIndex < chunkFields.Num() && NewIndex >= 0)
if (chunkFields[NewIndex] < 1) flag = true;
}
else flag = true;
if (flag)
{
Triangles.Add(bTriangles[0] + triangle_num + ElementID);
Triangles.Add(bTriangles[1] + triangle_num + ElementID);
Triangles.Add(bTriangles[2] + triangle_num + ElementID);
Triangles.Add(bTriangles[3] + triangle_num + ElementID);
Triangles.Add(bTriangles[4] + triangle_num + ElementID);
Triangles.Add(bTriangles[5] + triangle_num + ElementID);
triangle_num += 4;
switch (i)
{
case 0: {
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Normals.Append(bNormals0, ARRAY_COUNT(bNormals0));
break;
}
case 1: {
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Normals.Append(bNormals1, ARRAY_COUNT(bNormals1));
break;
}
case 2: {
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Normals.Append(bNormals2, ARRAY_COUNT(bNormals2));
break;
}
case 3: {
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Normals.Append(bNormals3, ARRAY_COUNT(bNormals3));
break;
}
case 4: {
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Normals.Append(bNormals4, ARRAY_COUNT(bNormals4));
break;
}
case 5: {
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
Normals.Append(bNormals5, ARRAY_COUNT(bNormals5));
break;
}
}
UVs.Append(bUVs, ARRAY_COUNT(bUVs));
FColor color = FColor(255, 255, 255, i);
VertexColors.Add(color); VertexColors.Add(color); VertexColors.Add(color); VertexColors.Add(color);
}
}
el_num += triangle_num;
meshSections[meshIndex].ElementID += triangle_num;
}
}
}
}
proceduralComponent->ClearAllMeshSections();
for (int i = 0; i < meshSections.Num(); i++)
{
if (meshSections[i].Vertices.Num() > 0)
proceduralComponent->CreateMeshSection(i, meshSections[i].Vertices, meshSections[i].Triangles, meshSections[i].Normals, meshSections[i].UVs, meshSections[i].VertexColors, meshSections[i].Tangents, collision);
}
int s = 0;
while (s < Materials.Num())
{
proceduralComponent->SetMaterial(s, Materials[s]);
s++;
}
}
TArray<int32> AVoxelActor::calculateNoise_Implementation()
{
TArray <int32> aa;
aa.SetNum(chunkLineElementsP2);
return aa;
}
bool AVoxelActor::inRange(int32 value, int32 range)
{
return (value >= 0 && value < range);
}
//void AVoxelActor::UpdateMesh() // NO NOISE WORKING
//{
// TArray<FVector> Vertices;
// TArray<int32> Triangles;
// TArray<FVector> Normals;
// TArray<FVector2D> UVs;
// TArray<FProcMeshTangent> Tangents;
// TArray<FColor> VertexColors;
//
// int32 ElementID = 0;
//
// for (int32 x = 0; x < chunkLineElements; x++)
// {
// for (int32 y = 0; y < chunkLineElements; y++)
// {
// for (int32 z = 0; z < chunkZElements; z++)
// {
// int32 index = x + (chunkLineElements * y) + (chunkLineElementsP2 * z);
// int32 meshIndex = chunkFields[index];
//
// if (meshIndex > 0)
// {
//
// meshIndex--;
//
// int triangle_num = 0;
// for (int i = 0; i < 6; i++)
// {
// int NewIndex = index + bMask[i].X + (bMask[i].Y * chunkLineElements) + (bMask[i].Z * chunkLineElementsP2);
//
// bool flag = false;
// if (meshIndex >= 20) flag = true;
// else if ((x + bMask[i].X < chunkLineElements) && (x + bMask[i].X >= 0) && (y + bMask[i].Y < chunkLineElements) && (y + bMask[i].Y >= 0))
// {
// if (NewIndex < chunkFields.Num() && NewIndex >= 0)
// if (chunkFields[NewIndex] < 1) flag = true;
// }
// else flag = true;
// if (flag)
// {
// Triangles.Add(bTriangles[0] + triangle_num + ElementID);
// Triangles.Add(bTriangles[1] + triangle_num + ElementID);
// Triangles.Add(bTriangles[2] + triangle_num + ElementID);
// Triangles.Add(bTriangles[3] + triangle_num + ElementID);
// Triangles.Add(bTriangles[4] + triangle_num + ElementID);
// Triangles.Add(bTriangles[5] + triangle_num + ElementID);
// triangle_num += 4;
//
// switch (i)
// {
// case 0: {
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
//
// Normals.Append(bNormals0, ARRAY_COUNT(bNormals0));
// break;
// }
//
// case 1: {
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
//
// Normals.Append(bNormals1, ARRAY_COUNT(bNormals1));
// break;
// }
//
// case 2: {
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
//
// Normals.Append(bNormals2, ARRAY_COUNT(bNormals2));
// break;
// }
//
// case 3: {
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
//
// Normals.Append(bNormals3, ARRAY_COUNT(bNormals3));
// break;
// }
//
// case 4: {
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
//
// Normals.Append(bNormals4, ARRAY_COUNT(bNormals4));
// break;
// }
//
// case 5: {
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), -VoxelSizeHalf + (z * voxelSize)));
// Vertices.Add(FVector(-VoxelSizeHalf + (x * voxelSize), -VoxelSizeHalf + (y * voxelSize), VoxelSizeHalf + (z * voxelSize)));
//
// Normals.Append(bNormals5, ARRAY_COUNT(bNormals5));
// break;
// }
// }
// UVs.Append(bUVs, ARRAY_COUNT(bUVs));
//
// FColor color = FColor(255, 255, 255, i);
// VertexColors.Add(color); VertexColors.Add(color); VertexColors.Add(color); VertexColors.Add(color);
// }
// }
// ElementID += triangle_num;
// }
// }
// }
// }
//
//
// proceduralComponent->ClearAllMeshSections();
// proceduralComponent->CreateMeshSection(0, Vertices, Triangles, Normals, UVs, VertexColors, Tangents, true);
//
//}

View file

@ -0,0 +1,91 @@
// 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 "VoxelActor.generated.h"
struct FMeshSection
{
TArray<FVector> Vertices;
TArray<int32> Triangles;
TArray<FVector> Normals;
TArray<FVector2D> UVs;
TArray<FProcMeshTangent> Tangents;
TArray<FColor> VertexColors;
int32 ElementID = 0;
};
UCLASS()
class MINECRAFT_API AVoxelActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AVoxelActor();
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray <UMaterialInterface *> Materials;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (ExposeOnSpawn = true))
int32 randomSeed = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (ExposeOnSpawn = true))
int32 voxelSize = 200;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (ExposeOnSpawn = true))
int32 chunkLineElements = 10;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (ExposeOnSpawn = true))
int32 chunkXindex = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (ExposeOnSpawn = true))
int32 chunkYindex = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool collision = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float xMult = 1;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float yMult = 1;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float Weight = 1;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float freq = 1;
UPROPERTY()
int32 chunkTotalElements;
UPROPERTY()
int32 chunkZElements;
UPROPERTY()
int32 chunkLineElementsP2;
UPROPERTY()
int32 VoxelSizeHalf;
UPROPERTY()
TArray <int32> chunkFields;
UPROPERTY()
UProceduralMeshComponent* proceduralComponent;
UFUNCTION(BlueprintNativeEvent)
TArray <int32> calculateNoise();
virtual TArray <int32> calculateNoise_Implementation();
private:
void GenerateChunk();
void UpdateMesh();
bool inRange(int32 value, int32 range);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
virtual void OnConstruction(const FTransform & Transform) override;
};

View file

@ -0,0 +1,14 @@
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
using System.Collections.Generic;
public class MinecraftEditorTarget : TargetRules
{
public MinecraftEditorTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
ExtraModuleNames.AddRange( new string[] { "Minecraft" } );
}
}