MeshInstance3D
- Game Development course
- Intermediate
- Lesson 61/83
- 4 min
Learn to show a 3D mesh in Godot with MeshInstance3D.
Godot Node Tree and MeshInstance3D
In the Godot game engine, scenes are hierarchical tree structures composed of Nodes. To visualize a 3D geometry (Mesh) in the scene, the MeshInstance3D node is used. This node positions its assigned geometry data in 3D space and renders it on screen.
MeshInstance3D meshNode = new MeshInstance3D();
GD.Print("Node ready: " + meshNode.Name);Mesh Assignment and Primitive Geometries
A 3D geometry resource is assigned to the Mesh property of the MeshInstance3D node. This resource can be an externally imported 3D model or built-in primitive geometries like BoxMesh or SphereMesh. As soon as the geometry is assigned, it renders in the scene view.
BoxMesh box = new BoxMesh();
meshNode.Mesh = box;Practice Print Node Information
Access the node.Name property and print it with GD.Print("Dugum: " + node.Name);.
Starter code
using System;
public class MeshInstance3D
{
public string Name { get; set; } = "Kup";
public bool Visible { get; set; } = true;
}
public static class GD
{
public static void Print(object message) => Console.WriteLine(message);
}
public class Program
{
public static void Main()
{
MeshInstance3D node = new MeshInstance3D();
// Dugum adini ekrana yazdir
}
}Sample solution
using System;
public class MeshInstance3D
{
public string Name { get; set; } = "Kup";
public bool Visible { get; set; } = true;
}
public static class GD
{
public static void Print(object message) => Console.WriteLine(message);
}
public class Program
{
public static void Main()
{
MeshInstance3D node = new MeshInstance3D();
GD.Print("Dugum: " + node.Name);
}
}Expected output
Dugum: Kup
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which node is used in Godot 3D to display a 3D mesh geometry in the scene?
- Camera3D
- MeshInstance3D Correct answer
- AudioStreamPlayer3D
- Node2D
Explanation: MeshInstance3D is the primary Godot node that visualizes 3D models and geometries in the scene.
2 Instantiate MeshInstance3D Node
MeshInstance3D modelDugumu = new ____();
MeshInstance3D modelDugumu = new MeshInstance3D();
Explanation: To visualize 3D mesh geometry, an object of the MeshInstance3D class is instantiated.
3 Godot 3D Mesh Basics
| Term | Meaning |
|---|---|
MeshInstance3D |
Node rendering 3D mesh in scene |
BoxMesh |
Godot's built-in box geometry |
Mesh |
Resource holding geometry data |
GD.Print() |
Method to print to Godot console |