【UE4】지형으로 놀자!

소개



안녕하세요. UE4 초초보자(UE4 경력, 수십일)의 최선입니다.

이번에는 신졸의 취업 작품을 위해 만들었습니다.
C++ 지형 생성 라이브러리 을 사용하여 UE4에 고도를 생성합니다.

BP

완성된 작품



>> 언리얼 엔진 4 뷰어 다운로드 [Windows/.exe/(x86/x64)] 📥

고도를 달려갑니다.

고도 산책. #위 4 피 c. 라고 r. 이 m / Fb와 함께 vX — 굿쵸( ¨̮ ) (@wanotaitei) December 8, 2019





수업 개요



>> dtl::shape::PerlinIsland (형상 클래스)






도입 방법



0. 이전 준비



>> 클래스 in Unreal Engine



위의 링크로 이동하여 DTL 다운로드에서 (프로젝트 이름) Build.cs에 대한 추가 설명을 수행합니다.






1. BlueprintFunctionLibrary를 상속한 C++ 클래스 만들기



PerlinIsland.h



#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "PerlinIsland.generated.h"

UCLASS()
class (プロジェクト名マクロ)_API UPerlinIsland : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

        UFUNCTION(BlueprintCallable, Category = DTL, meta = (HidePin = "worldContextObject_", DefaultToSelf = "worldContextObject_"))
        static bool perlinIsland(const UObject* worldContextObject_, float frequency, int32 octaves, int32 max_value, int32 min_value);
};


※ (プロジェクト名マクロ)_API 의 부분은 적절히 변경한다.



PerlinIsland.cpp



#include "PerlinIsland.h"

#include "EngineUtils.h"
#include "Landscape.h"
#include "LandscapeInfo.h"
#include "LandscapeEditor/Public/LandscapeEditorUtils.h"

#include <DTL.hpp>

bool UPerlinIsland::perlinIsland(const UObject* worldContextObject_, float frequency, int32 octaves, int32 max_value, int32 min_value) {

    dtl::shape::PerlinIsland<uint16> generator(
        static_cast<double>(frequency),
        static_cast<size_t>(octaves),
        static_cast<uint16>(max_value),
        static_cast<uint16>(min_value));

    ::UWorld* world{ worldContextObject_->GetWorld() };
    for (TActorIterator<ALandscape> actorItr(world); actorItr; ++actorItr) {
        ::ALandscape* landscape{ *actorItr };
        if (landscape == nullptr) continue;
        ::ULandscapeInfo::RecreateLandscapeInfo(world, false);

        ::FIntRect rect{ landscape->GetBoundingRect() };
        const int32 w{ rect.Width() + 1 };
        const int32 h{ rect.Height() + 1 };

        ::TArray<uint16> Data;
        Data.Init(0, w * h);
        generator.draw(Data, w, h);
        LandscapeEditorUtils::SetHeightmapData(landscape, Data);
        return true;
    }
    return false;
}





2.Actor를 계승한 블루프린트 클래스를 작성



BP



4개의 변수를 정의한다.

































변수 이름유형기본값
frequencyFloat2.0
octavesInteger10
max valueInteger20000
min valueInteger0


BP



EventPerlinIsland는 エディタで呼び出す(Call in Editor)를 체크한다.



BP



이번에 정의하는 변수는 インスタンス編集可能(Instance Editable) 와 スポーン時に公開(Expose on Spawn) 에 체크한다.



BP






3. 완성



작성한 Actor를 텍토에 레벨에 배치한다.

그런 다음 Landscape를 만듭니다.



View






4. 더 자세한 해설 기사



1~3을 봐도 잘 모르는 사람은



dtl::shape::PerlinIsland in Unreal Engine (모양 클래스) 자세한 설명 페이지를 참조하십시오.






사이고에게



<script async=""src="https://platform.twitter.com/widgets.js"/>

이번에는 UE4의 랜드스케이프 기능을 C++ 코드에서 호출하여 지형 생성을 실시했습니다.

좀 더 궁리하면 더 많아, 바리에이션 풍부한 지형이 만들어질 것 같네요.


좋은 웹페이지 즐겨찾기