-
-
Notifications
You must be signed in to change notification settings - Fork 87
dtl::shape::PerlinIsland in Unreal Engine (形状クラス)
Kasugaccho edited this page Aug 3, 2019
·
9 revisions
>> dtl::shape::PerlinIsland (形状クラス)
上記のURLに飛び、DTLのダウンロードから(プロジェクト名)Build.csの追加記述を行う。
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;
}4つの変数を定義する。
| 変数名 | 型 | デフォルト値 |
|---|---|---|
| frequency | Float | 2.0 |
| octaves | Integer | 10 |
| max value | Integer | 20000 |
| min value | Integer | 0 |
EventPerlinIslandは エディタで呼び出す(Call in Editor) にチェックを入れる。
今回定義する変数は インスタンス編集可能(Instance Editable) と スポーン時に公開(Expose on Spawn) にチェックを入れる。
作成したActorをテキトーにレベルに配置する。
その後に Landscape を作成する。
Copyright (c) 2018-2021 As Project.
Distributed under the Boost Software License, Version 1.0.(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)




