Creating a 3D game can be challenging. That extra Z coordinate makes many of the common techniques that helped to make 2D games simple no longer work. To aid in this transition, it is worth mentioning that Godot uses similar APIs for 2D and 3D. Most nodes are the same and are present in both 2D and 3D versions. In fact, it is worth checking the 3D platformer tutorial, or the 3D kinematic character tutorials, which are almost identical to their 2D counterparts.
3D에서 수학은 2D보다 조금 더 복잡하기 때문에 위키에서의 벡터 항목(특히 수학자나 엔지니어가 아닌 게임 개발자를 위해 만들어진 것)을 확인하는 것도 3D 게임을 효율적으로 개발할 수 있는 길을 닦는 데 도움이 될 것입니다.
Spatial nodes have a local transform, which is relative to the parent node (as long as the parent node is also of or inherits from the type Spatial). This transform can be accessed as a 4×3 Transform, or as 3 Vector3 members representing location, Euler rotation (X, Y and Z angles) and scale.
Unlike 2D, where loading image content and drawing is straightforward, 3D is a little more difficult. The content needs to be created with special 3D tools (usually referred to as Digital Content Creation tools, or DCCs) and exported to an exchange file format to be imported in Godot. This is required since 3D formats are not as standardized as images.
Godot에서 3D 모델을 가져오기 위한 두 가지 파이프라인이 있습니다. 가장 보편적인 첫번째는 3D 씬 가져오기와 같이 애니메이션, 골격 리그(skeletal rigs), 모양 혼합(blend shapes) 등을 포함한 전체 씬을 (DCC에서 보이는 것과 같이) 가져옵니다.
두 번째 파이프라인은 간단한 .OBJ 파일을 메시 리소스로 가져오는 것입니다. 이는 디스플레이를 위해 MeshInstance 노드에 넣을 수도 있습니다.
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.
어쨌든, 이 메서드는 정적 기하(자주 업데이트되지 않는 모델)를 생성하기 위한 것입니다. 정점 배열을 만들고 3D API에 배열을 제출하는 것은 상당한 성능 비용이 있습니다
즉각적인 지오메트리(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.
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.
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.
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:
Godot uses the metric system for everything in 3D, with 1 unit being equal to 1 meter. Physics and other areas are tuned for this scale. Therefore, 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. 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.).
Some useful keybindings:
To snap placement or rotation, press Ctrl while moving, scaling or rotating.
To center the view on the selected object, press F.
When created from the Project Manager, the 3D environment has a default sky.
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.
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:
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.
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.
Godot has a limit of up to 8 lights per mesh. Aside from that, 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, and no more than 8 lights shine on a single mesh.