Project image
ESRIIn Japan,Yamaha Motor Co., Ltd.andOorin Corporationhave jointly conducted research on digital twins of forests, and in this context, ArcGIS Maps SDK for Unity (hereinafter,ArcGIS SDK) was used to develop a Unity application. Recently, that project was published on our GitHub . In this article, we will introduce how the
ArcGIS SDK is used in the Unity application and show its implementation methods. ArcGIS SDK specific features are utilized, and we will also show how to implement them.
For usage of the application, please refer to the GitHub 's README file.
How exactly is the
ArcGIS SDK used?
In this project, the ArcGIS SDK mainly uses three elements. They are: ① displaying base maps, ② reading package files, and ③ managing object coordinates. We will explain them in order.
1. Displaying base maps
Displaying base maps is a fundamental function in GIS. Of course, it is also used in the ArcGIS SDK. In this application, the Map Creator UI feature of the ArcGIS SDK is used to generate base maps. This Map Creator UI allows you to use layers managed on ArcGIS Online
.tpkx.slpk.tpkxtilepackageis specified, and in this project it is assumed to be terrain elevation data displayed. Also,.slpkscenelayerpackageis specified, and in this project it is assumed to be a 3D object scene layer format.
3D オブジェクト シーン レイヤーの形式を前提としています。
StreamingAssets フォルダー
これらのファイルは LoadPackage というスクリプトでゲーム内のマップに読み込んでいます。
例えば地形情報ですが、フォルダー内に見つからなかった場合は、ArcGIS Online が提供する Terrain 3D 標高データを取得し、読み込みます。
if(tpkxFiles.Length > 0)
{
for (int i = 0; i < tpkxFiles.Length; i++)
{
string elevationPath = tpkxFiles[i];
mapComponent.Map.Elevation = new ArcGISMapElevation(new ArcGISImageElevationSource(elevationPath, i.ToString(), ""))
{
ExaggerationFactor = elevEx
};
}
}
else
{
string elevationPath = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer";
mapComponent.Map.Elevation = new ArcGISMapElevation(new ArcGISImageElevationSource(elevationPath, "Terrein 3D", ""))
{
ExaggerationFactor = elevEx
};
}
また、本プロジェクトでは林道を 3D オブジェクト シーン レイヤーとして読み込んでいます。ファイルは tex_elev008_w07.slpk として StreamingAssets フォルダー内に格納されています。下記コードの「ArcGISLayerType」を別の値に書き換えるとその他のレイヤー タイプを読み込むことができるようになります。ぜひ、お手持ちのデータでお試しください。
if (slpkFiles.Length > 0)
{
for (int i = 0; i < slpkFiles.Length; i++)
{
string sceneLayerPath = slpkFiles[i];
ArcGISLayer layer = new ArcGISLayer(sceneLayerPath, ArcGISLayerType.ArcGIS3DObjectSceneLayer, "");
mapComponent.Map.Layers.Add(layer);
}
}
3. オブジェクトの座標管理
本プロジェクトではサンプル データとして、1000 本以上の立木を表示しています。これらの座標は StreamingAssets フォルダー内に格納されている CSV のデータを参照していますが、立木のオブジェクトすべてに ArcGIS Location Component というコンポーネントがアタッチされています。
ArcGIS Location Component
しかし、上の画像をよく見ると緯度と経度(Latitude, Longitude)に関しては値が入力されていますが、高度(Altitude)は値が入力されていません。どのように高度を設定しているのでしょうか。
実は高度はコンポーネントの一番下にある Surface Placement で設定しています。この項目は、オブジェクトの高さを地形に対してどのように配置するかを決定する項目です。今回は没入感重視のため「On the Ground」で強制的に地表面にフィットさせています。この他にも、Altitude の値に準拠する「Absolute Height」と地表面との差分を設定できる「Relative to Ground」があります。
この設定は、TreeGenerator というスクリプトで行っています。この他にもオブジェクトの角度も同様に設定できるため、木によってばらつきを出すためにランダムな回転でバリエーションを出しています。
// LocationComponent 関連
var treeLocation = tree.GetComponent<ArcGISLocationComponent>();
if (treeLocation == null) treeLocation = Undo.AddComponent<ArcGISLocationComponent>(tree);
treeLocation.SurfacePlacementMode = ArcGISSurfacePlacementMode.OnTheGround;
treeLocation.Position = new ArcGISPoint(feature.POINT_X, feature.POINT_Y, 0, ArcGISSpatialReference.WGS84());
float randomizeAngle = UnityEngine.Random.Range(0.0f, 359.9f);
treeLocation.Rotation = new ArcGISRotation(randomizeAngle, 90, 0);
Tips: キャラクターなどの移動体に「On the Ground」を設定すると、地表面に押さえつけられるようになるため、アニメーションなどと干渉し意図しない挙動を起こすことがあります。その場合は、「Absolute Height」の設定がおすすめです。
最後に
本プロジェクトでは森林管理のデジタルツイン化を目指し、ArcGIS SDK を用いて雑木林の再現を行いました。ArcGIS と森林管理や林業をつなぎ、ゲームエンジンの可能性を広げることができたら嬉しく思います。
植林や樹木の範囲指定など、まだまだ実装の余地があると私は思っています。本プロジェクトは GitHub で公開していますので、ご興味のある方はプロジェクトをクローンして、自由にご活用ください。
参考リンク