-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrender_test.gd
More file actions
74 lines (60 loc) · 2.25 KB
/
Copy pathrender_test.gd
File metadata and controls
74 lines (60 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
## Visual test: builds Starter_01 from its .sk recipe, renders it to user://render_test.png.
## Run with: godot -s res://tests/render_test.gd --path .
extends SceneTree
const OUT_PATH := "user://render_test.png"
func _init() -> void:
call_deferred("_run")
func _run() -> void:
var recipe := SKRecipe.load_from_file("res://synty_assets/characters/Starter_01.sk")
var library := SKPartLibrary.new()
library.scan()
var colors := SKColorEngine.new()
colors.setup()
var database := SKDatabase.new()
if database.open() and not recipe.color_rows.is_empty():
var properties := {}
for prop in database.get_color_properties():
properties[int(prop.id)] = prop
var rows: Array = []
for row in recipe.color_rows:
var prop: Dictionary = properties.get(row.property_id, {})
if not prop.is_empty():
rows.append({ "property": { "u": int(prop.u), "v": int(prop.v) }, "colors": row.colors })
colors.apply_rows(rows)
database.close()
var builder := SKCharacterBuilder.new(library, colors)
var character := builder.build(recipe)
if character == null:
printerr("RENDER TEST: build failed")
quit(1)
return
root.add_child(character)
var light := DirectionalLight3D.new()
light.rotation_degrees = Vector3(-45, 30, 0)
light.light_energy = 1.2
root.add_child(light)
var fill := DirectionalLight3D.new()
fill.rotation_degrees = Vector3(-20, -120, 0)
fill.light_energy = 0.5
root.add_child(fill)
var environment := WorldEnvironment.new()
var env := Environment.new()
env.background_mode = Environment.BG_COLOR
env.background_color = Color(0.2, 0.22, 0.25)
env.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR
env.ambient_light_color = Color(0.7, 0.7, 0.75)
env.ambient_light_energy = 0.6
environment.environment = env
root.add_child(environment)
var camera := Camera3D.new()
camera.position = Vector3(0, 1.0, 2.6)
camera.look_at_from_position(camera.position, Vector3(0, 0.9, 0))
root.add_child(camera)
camera.make_current()
# Let import-frame settle and render a few frames before capturing.
for i in 10:
await process_frame
var image := root.get_viewport().get_texture().get_image()
image.save_png(OUT_PATH)
print("RENDER TEST: saved %s (%dx%d)" % [ProjectSettings.globalize_path(OUT_PATH), image.get_width(), image.get_height()])
quit(0)