1. Introduction: Why Node3D and MeshInstance3D Are Important
When starting 3D game development in Godot Engine, the most important concepts to understand first are Node3D and MeshInstance3D. These define the "location" and "appearance" of all objects existing in 3D space, serving truly as the foundation of 3D scene components.
While Node2D is central in 2D game development, Node3D fulfills that role in 3D.
2. Basic Concepts of Godot's 3D Space
Godot's 3D space is built based on coordinate systems and units, just like the real world.
3D Coordinate System: Right-Hand System and Axis Roles
Godot Engine uses the right-hand coordinate system adopted by many 3D software applications.
| Axis | Role | Direction |
|---|---|---|
| Y-axis | Height (Up/Down) | Positive upward |
| X-axis | Width (Left/Right) | Positive rightward |
| Z-axis | Depth (Forward/Backward) | Positive toward screen back |
Particularly important is that the Y-axis represents "height". Also, in Godot's 3D space, 1 unit corresponds to 1 meter.
Transform: Position, Rotation, Scale
Every object in 3D space has its state defined by data called Transform (transformation).
- Position (Translation/Position): Where in space the object is.
- Rotation: Which direction the object is facing.
- Scale: How large the object is.
3. Node3D: Defining "Location" in 3D Space
Node3D is the most basic node in Godot's 3D node hierarchy and is the base class for all 3D nodes. Its role is very simple yet powerful, specialized in defining an object's "location," "orientation," and "size" in 3D space.
Node3D itself has no visible shape or physical behavior. However, through its transform property, it holds the information for the aforementioned position, rotation, and scale.
Practical Uses of Node3D
Node3D is primarily used for:
- Root Node: Used as the root (top-level) node of 3D scenes.
- Grouping: Used as a parent node to manage multiple 3D nodes together.
- Relative Coordinate Reference: Child nodes are always positioned in relative coordinates based on the parent node's coordinates.
4. MeshInstance3D: Defining "Appearance" in 3D Space
MeshInstance3D is a node that inherits from Node3D and is a node for rendering visual shapes (meshes) in 3D space.
While Node3D determines "where" an object is, MeshInstance3D determines "what" is there—the object's "appearance".
Role Division Between Node3D and MeshInstance3D
| Node | Role | What It Defines |
|---|---|---|
| Node3D | Location | Position, rotation, scale (Transform) |
| MeshInstance3D | Appearance | Shape (Mesh), texture (Material) |
The most important property MeshInstance3D has is mesh. By assigning a Mesh resource like BoxMesh (cube), SphereMesh (sphere), or complex models imported from external sources here, the object finally gets rendered on screen.
5. Practical Example: Generating and Manipulating Simple 3D Objects with Script
Here we'll introduce the procedure for using GDScript to make Node3D the root, dynamically generate MeshInstance3D as its child, and set position and color.
extends Node3D
func _ready():
# 1. Create MeshInstance3D node
var mesh_instance = MeshInstance3D.new()
add_child(mesh_instance)
# 2. Create BoxMesh resource and assign to MeshInstance3D
var box_mesh = BoxMesh.new()
box_mesh.size = Vector3(1.0, 1.0, 1.0)
mesh_instance.mesh = box_mesh
# 3. Create StandardMaterial3D and set color
var material = StandardMaterial3D.new()
material.albedo_color = Color(0.8, 0.2, 0.2)
mesh_instance.set_surface_override_material(0, material)
# 4. Set position
mesh_instance.position = Vector3(2.0, 0.5, 0.0)
# 5. Set rotation (rotate 45 degrees around Y-axis)
mesh_instance.rotation_degrees = Vector3(0, 45, 0)
This code is equivalent to adding nodes in the editor and setting properties in the inspector, all done in script.
6. Summary
In this article, we explained the roles of Node3D and MeshInstance3D and the fundamental concepts of 3D space as foundations for starting 3D game development in Godot Engine.
| Concept | Keywords | Role |
|---|---|---|
| 3D Space | Right-hand system, 1 unit = 1m | Environment where objects exist |
| Node3D | Transform, Position | Defines location |
| MeshInstance3D | Mesh, Material | Defines appearance |
Once you understand the role division of these two nodes, Godot's 3D scene construction is no longer intimidating. Determine placement with Node3D and arrange appearance with MeshInstance3D. This simple principle is the first step in building complex 3D game worlds.