3Dの概要

3Dゲームの作成は難しい場合があります。 その余分なZ座標により、2Dゲームをシンプルにするのに役立った多くの一般的な手法が機能しなくなります。 この移行を支援するために、Godotは2Dおよび3Dに同様のAPIを使用していることに言及する価値があります。 ほとんどのノードは同じであり、2Dバージョンと3Dバージョンの両方に存在します。 実際、3Dプラットフォーマーチュートリアル、または3Dキネマティックキャラクターチュートリアルを確認する価値があります。

3Dでは、数学は2Dよりもやや複雑です。したがって、wikiの ベクトル演算 エントリ(数学者やエンジニアではなく、ゲーム開発者向けに特別に作成されたもの)をチェックすることで、3Dゲームを効率的に開発する道を開くのに役立ちます。

Spatialノード

Node2D は2Dのベースノードです。Control は、すべてのGUIのベースノードです。 この推論に従って、3Dエンジンはすべての3Dに対して Spatial ノードを使用します。

../../_images/tuto_3d1.png

Spatialノードには、親ノードに相対的なローカルな幾何学変換があります(親ノードもSpatial型であるか、または継承している限り)。この変換は、4x3 Transform として、または位置、オイラー回転(x、y、zの角度)およびスケールを表す3 Vector3 メンバーとしてアクセスできます。

../../_images/tuto_3d2.png

3Dコンテンツ

画像コンテンツの読み込みと描画が簡単な2Dとは異なり、3Dはもう少し難しくなります。コンテンツは、特別な3Dツール(通常DCCと呼ばれます)で作成し、Godotでインポートするために交換用のファイル形式にエクスポートする必要があります(3D形式は画像ほど標準化されていません)。

DCC-created models

There are two pipelines to import 3D models in Godot. The first and most common one is by 3Dシーンのインポート, which allows you to import entire scenes (just as they look in the DCC), including animation, skeletal rigs, blend shapes, etc.

The second pipeline is by importing simple .OBJ files as mesh resources, which can be then put inside a MeshInstance node for display.

Generated geometry

It is possible to create custom geometry by using the ArrayMesh resource directly. Simply create your arrays and use the ArrayMesh.add_surface_from_arrays() function. A helper class is also available, SurfaceTool, which provides a more straightforward API and helpers for indexing, generating normals, tangents, etc.

In any case, this method is meant for generating static geometry (models that will not be updated often), as creating vertex arrays and submitting them to the 3D API has a significant performance cost.

Immediate geometry

If, instead, there is a requirement to generate simple geometry that will be updated often, Godot provides a special node, ImmediateGeometry, which provides an OpenGL 1.x style immediate-mode API to create points, lines, triangles, etc.

2D in 3D

While Godot packs a powerful 2D engine, many types of games use 2D in a 3D environment. By using a fixed camera (either orthogonal or perspective) that does not rotate, nodes such as Sprite3D and AnimatedSprite3D can be used to create 2D games that take advantage of mixing with 3D backgrounds, more realistic parallax, lighting/shadow effects, etc.

The disadvantage is, of course, that added complexity and reduced performance in comparison to plain 2D, as well as the lack of reference of working in pixels.

Environment

Besides editing a scene, it is often common to edit the environment. Godot provides a WorldEnvironment node that allows changing the background color, mode (as in, put a skybox), and applying several types of built-in post-processing effects. Environments can also be overridden in the Camera.

3D viewport

Editing 3D scenes is done in the 3D tab. This tab can be selected manually, but it will be automatically enabled when a Spatial node is selected.

../../_images/tuto_3d3.png

Default 3D scene navigation controls are similar to Blender (aiming to have some sort of consistency in the free software pipeline..), but options are included to customize mouse buttons and behavior to be similar to other tools in the Editor Settings:

../../_images/tuto_3d4.png

Coordinate system

Godot uses the metric system for everything. 3D Physics and other areas are tuned for this, so attempting to use a different scale is usually a bad idea (unless you know what you are doing).

When working with 3D assets, it's always best to work in the correct scale (set your DCC to metric). Godot allows scaling post-import and, while this works in most cases, in rare situations it may introduce floating point precision issues (and thus, glitches or artifacts) in delicate areas, such as rendering or physics, so make sure your artists always work in the right scale!

The Y coordinate is used for "up", though for most objects that need alignment (like lights, cameras, capsule collider, vehicle, etc.), the Z axis is used as a "pointing towards" direction. This convention roughly means that:

  • X is sides
  • Y is up/down
  • Z is front/back

Space and manipulation gizmos

Moving objects in the 3D view is done through the manipulator gizmos. Each axis is represented by a color: Red, Green, Blue represent X,Y,Z respectively. This convention applies to the grid and other gizmos too (and also to the shader language, ordering of components for Vector3,Color,etc.).

../../_images/tuto_3d5.png

Some useful keybindings:

  • To snap placement or rotation, press the "Ctrl" key while moving, scaling or rotating.
  • To center the view on the selected object, press the "f" key.

View menu

The view options are controlled by the "View" menu in the viewport's toolbar.

../../_images/tuto_3d6.png

You can hide the gizmos in the 3D view of the editor through this menu:

../../_images/tuto_3d6_1.png

To hide a specific type of gizmos, you can toggle them off in the "View" menu.

../../_images/tuto_3d6_2.png

Default environment

When created from the Project Manager, the 3D environment has a default sky.

../../_images/tuto_3d8.png

Given how physically based rendering works, it is advised to always try to work with a default environment in order to provide indirect and reflected light to your objects.

Cameras

No matter how many objects are placed in the 3D space, nothing will be displayed unless a Camera is also added to the scene. Cameras can work in either orthogonal or perspective projections:

../../_images/tuto_3d10.png

Cameras are associated with (and only display to) a parent or grandparent viewport. Since the root of the scene tree is a viewport, cameras will display on it by default, but if sub-viewports (either as render target or picture-in-picture) are desired, they need their own children cameras to display.

../../_images/tuto_3d11.png

When dealing with multiple cameras, the following rules are enforced for each viewport:

  • If no cameras are present in the scene tree, the first one that enters it will become the active camera. Further cameras entering the scene will be ignored (unless they are set as current).
  • If a camera has the "current" property set, it will be used regardless of any other camera in the scene. If the property is set, it will become active, replacing the previous camera.
  • If an active camera leaves the scene tree, the first camera in tree-order will take its place.

ライト

There is no limitation on the number of lights, nor of types of lights, in Godot. As many as desired can be added (as long as performance allows).