godot-3d-essentials
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGodot 3D Essentials (4.x)
Godot 3D基础教程(4.x版本)
Assemble a working 3D scene: transforms, camera, lights, environment/post, materials, and
blockouts. Targets Godot 4.3+.
GridMap组装可运行的3D场景:变换、相机、灯光、环境/后期处理、材质以及
关卡原型。适配**Godot 4.3+**版本。
GridMapWhen to use
适用场景
- Use when starting or fixing a 3D scene: positioning a , adding lights, setting up a
Camera3D(sky, ambient, tonemap, glow/SSAO), assigning materials, or building levels withWorldEnvironment.GridMap
When not to use: writing spatial shaders → ; 3D physics bodies and
raycasts → ; character animation blending → ; full FPS
template → the genre skill.
godot-shadersgodot-physicsgodot-animationfps-shooter- 适用于创建或修复3D场景时:定位、添加灯光、设置
Camera3D(天空、环境光、色调映射、光晕/屏幕空间环境光遮蔽)、分配材质,或 使用WorldEnvironment构建关卡。GridMap
不适用场景:编写空间着色器 → 使用;3D物理体与射线检测 → 使用;角色动画混合 → 使用;完整FPS模板 → 使用类型技能。
godot-shadersgodot-physicsgodot-animationfps-shooterCore workflow
核心工作流程
- Everything 3D is a with a
Node3D(position, rotation basis, scale). Move withTransform3D, rotate withglobal_positionorrotate_y(angle).look_at(target) - Add a . Mark it
Camera3D(or callcurrent); setmake_current(),fov,near. Parent it to a rig/pivot for orbit or follow cameras.far - Light the scene. A is the sun;
DirectionalLight3D/OmniLight3Dare local. Enable shadows per light. Without lights and ambient, surfaces render black.SpotLight3D - Add a with an
WorldEnvironmentresource: background (sky/color), ambient light, tonemap, and post (glow, SSAO, fog, adjustments).Environment - Give meshes materials (or a
StandardMaterial3D) onShaderMaterial.MeshInstance3D - Block out levels with , which places
GridMapitems on a 3D grid (the 3D analog of a tilemap).MeshLibrary
- 所有3D对象均为,带有
Node3D组件(位置、旋转基、缩放)。 通过Transform3D移动,使用global_position或rotate_y(angle)旋转。look_at(target) - 添加。标记为
Camera3D(或调用current方法);设置make_current()(视野)、fov(近裁剪面)、near(远裁剪面)。将其挂载到控制节点/枢轴上,实现轨道或跟随相机效果。far - 为场景添加光照。模拟太阳光;
DirectionalLight3D/OmniLight3D用于 局部光照。为每个灯光启用阴影。如果没有灯光和环境光,表面会渲染为黑色。SpotLight3D - **添加**并关联
WorldEnvironment资源:背景(天空/纯色)、 环境光、色调映射,以及后期处理(光晕、SSAO、雾效、参数调整)。Environment - 为网格赋予材质:在上使用
MeshInstance3D或StandardMaterial3D。ShaderMaterial - 使用制作关卡原型,它会将
GridMap中的物品放置在3D网格 上(相当于3D版本的瓦片地图)。MeshLibrary
Patterns
实践模式
1. A follow camera (third-person, smoothed)
1. 跟随相机(第三人称、平滑跟随)
gdscript
extends Camera3D
@export var target: Node3D
@export var offset := Vector3(0, 4, 8)
@export var smooth := 6.0
func _physics_process(delta: float) -> void:
if target == null:
return
var desired := target.global_position + offset
global_position = global_position.lerp(desired, smooth * delta) # smooth follow
look_at(target.global_position, Vector3.UP) # face the targetgdscript
extends Camera3D
@export var target: Node3D
@export var offset := Vector3(0, 4, 8)
@export var smooth := 6.0
func _physics_process(delta: float) -> void:
if target == null:
return
var desired := target.global_position + offset
global_position = global_position.lerp(desired, smooth * delta) # smooth follow
look_at(target.global_position, Vector3.UP) # face the target2. Sun + environment in code
2. 代码实现太阳光与环境
gdscript
func _ready() -> void:
var sun := DirectionalLight3D.new()
sun.rotation_degrees = Vector3(-45, -30, 0)
sun.shadow_enabled = true
add_child(sun)
var we := WorldEnvironment.new()
var env := Environment.new()
env.background_mode = Environment.BG_SKY
env.sky = Sky.new()
env.sky.sky_material = ProceduralSkyMaterial.new()
env.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
env.tonemap_mode = Environment.TONE_MAPPER_FILMIC
env.glow_enabled = true
we.environment = env
add_child(we)gdscript
func _ready() -> void:
var sun := DirectionalLight3D.new()
sun.rotation_degrees = Vector3(-45, -30, 0)
sun.shadow_enabled = true
add_child(sun)
var we := WorldEnvironment.new()
var env := Environment.new()
env.background_mode = Environment.BG_SKY
env.sky = Sky.new()
env.sky.sky_material = ProceduralSkyMaterial.new()
env.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
env.tonemap_mode = Environment.TONE_MAPPER_FILMIC
env.glow_enabled = true
we.environment = env
add_child(we)3. Assign a StandardMaterial3D from code
3. 通过代码分配StandardMaterial3D
gdscript
func tint_mesh(mesh: MeshInstance3D, color: Color) -> void:
var mat := StandardMaterial3D.new()
mat.albedo_color = color
mat.metallic = 0.0
mat.roughness = 0.6
mat.emission_enabled = true
mat.emission = color * 0.3
mesh.material_override = mat # overrides the mesh's surface materialsgdscript
func tint_mesh(mesh: MeshInstance3D, color: Color) -> void:
var mat := StandardMaterial3D.new()
mat.albedo_color = color
mat.metallic = 0.0
mat.roughness = 0.6
mat.emission_enabled = true
mat.emission = color * 0.3
mesh.material_override = mat # overrides the mesh's surface materials4. Place tiles into a GridMap
4. 向GridMap中放置瓦片
gdscript
@onready var grid: GridMap = $GridMap # cell_size + mesh_library set in the editor
func build_floor(width: int, depth: int, item_id: int) -> void:
for x in width:
for z in depth:
# set_cell_item(Vector3i cell, int item, orientation = 0)
grid.set_cell_item(Vector3i(x, 0, z), item_id)gdscript
@onready var grid: GridMap = $GridMap # cell_size + mesh_library set in the editor
func build_floor(width: int, depth: int, item_id: int) -> void:
for x in width:
for z in depth:
# set_cell_item(Vector3i cell, int item, orientation = 0)
grid.set_cell_item(Vector3i(x, 0, z), item_id)Pitfalls
常见陷阱
- Scene renders black → no lights and no ambient. Add a and/or a
DirectionalLight3Dwith ambient/sky. New scenes have neither by default.WorldEnvironment - No camera / wrong camera. If nothing shows, no is
Camera3D. Setcurrentorcurrent = true; only one camera renders per viewport.make_current() - Confusing local vs global transforms. /
positionare relative to the parent;rotation/global_positionare world space. Mixing them under a rotated parent gives surprising results.global_transformuses global coordinates.look_at - Scaling physics/lights. Non-uniform on a
scaledistorts child collisions and lights; prefer scaling the mesh asset or using uniform scale.Node3D - Forgetting /
frominup.look_at— a target equal to the node's position, or anlook_at(target, up)parallel to the look direction, produces NaNs/flips.up - GridMap with no places nothing. Create a
MeshLibrary(from scenes) and assign it;MeshLibraryclears a cell.set_cell_item(cell, -1) - HDR/glow too strong → check and glow thresholds; raw emissive values bloom hard under filmic tonemapping.
tonemap_mode
- 场景渲染为黑色 → 没有灯光和环境光。添加和/或带有环境光/天空的
DirectionalLight3D。新场景默认没有这些元素。WorldEnvironment - 无相机/相机错误。如果没有内容显示,说明没有被设置为
Camera3D。设置current或调用current = true;每个视口仅能有一个相机进行渲染。make_current() - 混淆局部与全局变换。/
position是相对于父节点的;rotation/global_position是世界空间坐标。在旋转的父节点下混用二者会导致意外结果。global_transform使用全局坐标。look_at - 缩放物理体/灯光。对进行非均匀缩放会扭曲子节点的碰撞体和灯光;建议缩放网格资源或使用均匀缩放。
Node3D - 中遗漏
look_at/from参数。up— 如果目标与节点位置相同,或look_at(target, up)方向与注视方向平行,会产生NaN值或翻转问题。up - GridMap未关联→ 无法放置任何物品。创建
MeshLibrary(从场景生成)并分配给它;使用MeshLibrary清除单元格。set_cell_item(cell, -1) - HDR/光晕效果过强 → 检查和光晕阈值;在电影色调映射下,原始自发光值会导致严重的 bloom 效果。
tonemap_mode
References
参考资料
- For Transform3D math, camera projection modes, light/shadow params, the full
Environment/post-processing options, creation, and
MeshLibrary/ReflectionProbelighting, readLightmapGI.references/scene-and-environment.md
- 关于Transform3D数学、相机投影模式、灯光/阴影参数、完整的环境/后期处理选项、创建,以及
MeshLibrary/ReflectionProbe光照的内容,请查阅LightmapGI。references/scene-and-environment.md
Related skills
相关技能
- — 3D bodies, areas, and raycasts.
godot-physics - — spatial shaders for custom 3D surfaces.
godot-shaders - —
godot-animationfor 3D characters.AnimationTree - — third-person orbit / first-person look rigs, framing, and collision.
camera-systems - — keep 3D scenes within frame budget (draw calls, lights, LOD).
performance-optimization - — composes 3D movement, input, and AI into a game.
fps-shooter
- — 3D物理体、区域与射线检测。
godot-physics - — 用于自定义3D表面的空间着色器。
godot-shaders - — 用于3D角色的
godot-animation。AnimationTree - — 第三人称轨道/第一人称视角控制节点、画面构图与碰撞处理。
camera-systems - — 确保3D场景在帧率预算内运行(绘制调用、灯光、LOD)。
performance-optimization - — 整合3D移动、输入与AI的射击游戏模板。
fps-shooter