手続き型ジオメトリ(幾何)

Godotでジオメトリを手続き的に生成する方法は多数あります。このチュートリアルシリーズでは、それらのいくつかを検討します。それぞれの手法には長所と短所があるため、それぞれを理解し、特定の状況でどのように役立つかを理解することが最善です。

ジオメトリとは何ですか?

ジオメトリは、形を洒落た言い方で表現したものです。コンピュータグラフィックスでは、ジオメトリは通常「頂点」と呼ばれる位置の配列で表されます。 Godotでは、ジオメトリはメッシュで表されます。

メッシュとは何ですか?

Godotの多くの物には名前にメッシュがあります: MeshArrayMeshMeshInstanceMultiMesh、および:ref:` MultiMeshInstance <class_MultiMeshInstance> `。それらはすべて関連がありますが、用途が少し異なります。

MesheとArrayMeshは、MeshInstanceノードを使用して描画されるリソースです。 MesheやArrayMeshなどのリソースをシーンに直接追加することはできません。 MeshInstanceは、シーン内のメッシュの1つのインスタンスを表します。単一のメッシュを複数のMeshInstanceで再利用して、異なるマテリアルまたは変換(スケール、回転、位置など)を使用してシーンの異なる部分に描画することができます。

If you are going to draw the same object many times, it can be helpful to use a MultiMesh with a MultiMeshInstance. MultiMeshInstances draw meshes thousands of times very cheaply by taking advantage of hardware instancing. The drawback with using a MultiMeshInstance is that each of your mesh's surfaces are limited to one material for all instances. It uses an instance array to store different colors and transformations for each instance, but all the instances of each surface use the same material.

メッシュとは

メッシュは、1つ以上のサーフェスで構成されます。サーフェスは、頂点、法線、UVなどを含む複数のサブ配列で構成される配列です。通常、サーフェスとメッシュを構築するプロセスは、VisualServer でユーザーから隠されていますが、ArrayMeshではユーザーは、サーフェス情報を含む配列を渡すことにより、メッシュを手動で構築できます。

サーフェス

Each surface has its own material. Alternatively, you can override the material for all surfaces in the Mesh when you use a MeshInstance using the material_override property.

サーフェス配列

The surface array is an array of length ArrayMesh.ARRAY_MAX. Each position in the array is filled with a sub-array containing per-vertex information. For example, the array located at ArrayMesh.ARRAY_NORMAL is a PoolVector3Array of vertex normals. See Mesh.ArrayType for more information.

The surface array can be indexed or non-indexed. Creating a non-indexed array is as easy as not assigning an array at the index ArrayMesh.ARRAY_INDEX. A non-indexed array stores unique vertex information for every triangle, meaning that when two triangles share a vertex, the vertex is duplicated in the array. An indexed surface array only stores vertex information for each unique vertex and then also stores an array of indices which maps out how to construct the triangles from the vertex array. In general, using an indexed array is faster, but it means you have to share vertex data between triangles, which is not always desired (e.g. when you want per-face normals).

ツール

Godotは、ジオメトリにアクセスして操作するさまざまな方法を提供します。それぞれの詳細については、次のチュートリアルで説明します。

ArrayMesh

The ArrayMesh resource extends Mesh to add a few different quality of life functions and, most importantly, the ability to construct a Mesh surface through scripting.

ArrayMeshの詳細については、ArrayMesh tutoria を参照してください。

MeshDataTool

MeshDataToolは、メッシュデータを、実行時に変更できる頂点、面、およびエッジの配列に変換するリソースです。

MeshDataToolの詳細については、MeshDataTool tutorial を参照してください。

SurfaceTool

SurfaceToolでは、OpenGL 1.xイミディエイトモードスタイルのインターフェイスを使用してメッシュを作成できます。

SurfaceToolの詳細については、SurfaceTool tutorial を参照してください。

ImmediateGeometry

ImmediateGeometry is a node that uses an immediate mode style interface (like SurfaceTool) to draw objects. The difference between ImmediateGeometry and the SurfaceTool is that ImmediateGeometry is a node itself that can be added to the scene tree and is drawn directly from the code, while the SurfaceTool generates a Mesh that needs to be added to a MeshInstance to be seen.

ImmediateGeometry is useful for prototyping because of its straightforward API, but it is slow because the geometry is rebuilt every frame. It is most useful for adding simple geometry for visual debugging (e.g. by drawing lines to visualize physics raycasts etc.).

ImmediateGeometryの詳細については、ImmediateGeometry tutorial を参照してください。

どちらを使うべきですか?

Which approach you use depends on what you are trying to do and what kind of procedure you are comfortable with.

SurfaceToolとArrayMeshはどちらも、時間とともに変化しない静的なジオメトリ(メッシュ)の生成に最適です。

Using an ArrayMesh is slightly faster than using a SurfaceTool, but the API is a little more challenging. Additionally, SurfaceTool has a few quality of life methods such as generate_normals() and index().

ImmediateGeometry regenerates the mesh every frame, so it is much slower than ArrayMesh or SurfaceTool. However, if you need the geometry to change every frame anyway, it provides a much easier interface that may even be a little faster than generating an ArrayMesh every frame.

The MeshDataTool is not fast, but it gives you access to all kinds of properties of the mesh that you don't get with the others (edges, faces, etc.). It is incredibly useful when you need that sort of data to transform the mesh, but it is not a good idea to use it if that extra information is not needed. The MeshDataTool is best used if you are going to be using an algorithm that requires access to the face or edge array.