2019-08-02 08:17:32 +02:00
|
|
|
tool
|
2020-02-17 08:54:46 +01:00
|
|
|
extends MMGenShader
|
2019-07-31 20:53:00 +02:00
|
|
|
class_name MMGenMaterial
|
|
|
|
|
2020-02-19 23:24:34 +01:00
|
|
|
var export_paths = {}
|
|
|
|
|
2019-08-09 08:16:24 +02:00
|
|
|
var material : SpatialMaterial
|
2020-03-18 21:40:02 +01:00
|
|
|
var shader_materials = {}
|
|
|
|
var need_update = {}
|
2020-03-20 07:44:22 +01:00
|
|
|
var need_render = {}
|
2019-08-02 08:17:32 +02:00
|
|
|
var generated_textures = {}
|
2020-03-18 21:40:02 +01:00
|
|
|
var updating : bool = false
|
|
|
|
var update_again : bool = false
|
2019-08-02 08:17:32 +02:00
|
|
|
|
|
|
|
const TEXTURE_LIST = [
|
2020-02-18 08:47:44 +01:00
|
|
|
{ port=0, texture="albedo", sources=[0] },
|
|
|
|
{ port=1, texture="orm", sources=[1, 2, 5] },
|
|
|
|
{ port=2, texture="emission", sources=[3] },
|
|
|
|
{ port=3, texture="normal", sources=[4] },
|
|
|
|
{ port=4, texture="depth", sources=[6] },
|
|
|
|
{ port=5, texture="sss", sources=[7] }
|
2019-08-02 08:17:32 +02:00
|
|
|
]
|
|
|
|
|
2020-02-17 08:54:46 +01:00
|
|
|
const INPUT_ALBEDO : int = 0
|
|
|
|
const INPUT_METALLIC : int = 1
|
|
|
|
const INPUT_ROUGHNESS : int = 2
|
|
|
|
const INPUT_EMISSION : int = 3
|
|
|
|
const INPUT_NORMAL : int = 4
|
|
|
|
const INPUT_OCCLUSION : int = 5
|
|
|
|
const INPUT_DEPTH : int = 6
|
|
|
|
const INPUT_SSS : int = 7
|
|
|
|
|
2019-10-20 20:16:48 +02:00
|
|
|
# The minimum allowed texture size as a power-of-two exponent
|
|
|
|
const TEXTURE_SIZE_MIN = 4 # 16x16
|
|
|
|
|
|
|
|
# The maximum allowed texture size as a power-of-two exponent
|
|
|
|
const TEXTURE_SIZE_MAX = 12 # 4096x4096
|
|
|
|
|
|
|
|
# The default texture size as a power-of-two exponent
|
|
|
|
const TEXTURE_SIZE_DEFAULT = 10 # 1024x1024
|
|
|
|
|
2020-02-17 08:54:46 +01:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _ready() -> void:
|
2019-11-02 22:58:29 +01:00
|
|
|
for t in TEXTURE_LIST:
|
2019-10-01 08:34:08 +02:00
|
|
|
generated_textures[t.texture] = null
|
2020-03-18 21:40:02 +01:00
|
|
|
need_update[t.texture] = true
|
2020-03-20 07:44:22 +01:00
|
|
|
need_render[t.texture] = true
|
2020-03-18 21:40:02 +01:00
|
|
|
shader_materials[t.texture] = ShaderMaterial.new()
|
|
|
|
shader_materials[t.texture].shader = Shader.new()
|
2019-10-01 08:34:08 +02:00
|
|
|
material = SpatialMaterial.new()
|
2020-03-18 21:40:02 +01:00
|
|
|
add_to_group("preview")
|
2019-10-01 08:34:08 +02:00
|
|
|
|
2019-10-19 01:30:25 +02:00
|
|
|
func can_be_deleted() -> bool:
|
|
|
|
return false
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_type() -> String:
|
2019-08-12 15:58:42 +02:00
|
|
|
return "material"
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_type_name() -> String:
|
2019-09-16 20:45:47 +02:00
|
|
|
return "Material"
|
|
|
|
|
2020-02-18 08:47:44 +01:00
|
|
|
func get_output_defs() -> Array:
|
2020-02-17 08:54:46 +01:00
|
|
|
return []
|
2019-09-14 09:14:27 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_image_size() -> int:
|
2019-10-14 20:42:11 +02:00
|
|
|
var rv : int
|
|
|
|
if parameters.has("size"):
|
2019-10-21 23:58:14 +02:00
|
|
|
rv = int(pow(2, parameters.size))
|
2019-10-14 20:42:11 +02:00
|
|
|
else:
|
2019-10-20 20:16:48 +02:00
|
|
|
rv = int(pow(2, TEXTURE_SIZE_DEFAULT))
|
2019-10-14 20:42:11 +02:00
|
|
|
return rv
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func update_preview() -> void:
|
2019-10-02 23:06:20 +02:00
|
|
|
var graph_edit = self
|
|
|
|
while graph_edit is MMGenBase:
|
|
|
|
graph_edit = graph_edit.get_parent()
|
2019-10-21 23:58:14 +02:00
|
|
|
if graph_edit != null and graph_edit.has_method("send_changed_signal"):
|
2019-10-02 23:06:20 +02:00
|
|
|
graph_edit.send_changed_signal()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func set_parameter(p, v) -> void:
|
2019-10-02 23:06:20 +02:00
|
|
|
.set_parameter(p, v)
|
|
|
|
update_preview()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func source_changed(input_index : int) -> void:
|
2019-11-02 22:58:29 +01:00
|
|
|
for t in TEXTURE_LIST:
|
2020-02-18 08:47:44 +01:00
|
|
|
if t.has("sources") and t.sources.find(input_index) != -1:
|
2020-03-18 21:40:02 +01:00
|
|
|
need_update[t.texture] = true
|
2019-10-02 23:06:20 +02:00
|
|
|
update_preview()
|
2019-07-31 20:53:00 +02:00
|
|
|
|
2019-11-06 22:33:01 +01:00
|
|
|
func render_textures() -> void:
|
2019-11-02 22:58:29 +01:00
|
|
|
for t in TEXTURE_LIST:
|
2019-11-14 08:47:21 +01:00
|
|
|
var result
|
2019-09-25 08:04:36 +02:00
|
|
|
if t.has("port"):
|
2020-03-18 21:40:02 +01:00
|
|
|
if !need_update[t.texture]:
|
2019-11-02 22:58:29 +01:00
|
|
|
continue
|
2020-03-18 21:40:02 +01:00
|
|
|
var context : MMGenContext = MMGenContext.new()
|
|
|
|
var source = get_shader_code("uv", t.port, context)
|
|
|
|
while source is GDScriptFunctionState:
|
|
|
|
source = yield(source, "completed")
|
|
|
|
if source.empty():
|
|
|
|
source = { defs="", code="", textures={}, rgba="vec4(0.0)" }
|
|
|
|
shader_materials[t.texture].shader.code = mm_renderer.generate_shader(source)
|
|
|
|
if source.has("textures"):
|
|
|
|
for k in source.textures.keys():
|
|
|
|
shader_materials[t.texture].set_shader_param(k, source.textures[k])
|
|
|
|
result = mm_renderer.render_material(shader_materials[t.texture], get_image_size())
|
2019-11-14 08:47:21 +01:00
|
|
|
else:
|
|
|
|
generated_textures[t.texture] = null
|
2020-03-18 21:40:02 +01:00
|
|
|
need_update[t.texture] = false
|
2019-11-14 08:47:21 +01:00
|
|
|
continue
|
|
|
|
while result is GDScriptFunctionState:
|
|
|
|
result = yield(result, "completed")
|
2020-03-18 21:40:02 +01:00
|
|
|
if generated_textures[t.texture] == null:
|
|
|
|
generated_textures[t.texture] = ImageTexture.new()
|
|
|
|
var texture = generated_textures[t.texture]
|
2019-11-14 08:47:21 +01:00
|
|
|
result.copy_to_texture(texture)
|
|
|
|
result.release()
|
|
|
|
# To work, this must be set after calling `copy_to_texture()`
|
|
|
|
texture.flags |= ImageTexture.FLAG_ANISOTROPIC_FILTER
|
|
|
|
# Disable filtering for small textures, as they're considered to be used
|
|
|
|
# for a pixel art style
|
|
|
|
if texture.get_size().x <= 128:
|
|
|
|
texture.flags ^= ImageTexture.FLAG_FILTER
|
2020-03-18 21:40:02 +01:00
|
|
|
need_update[t.texture] = false
|
2019-10-20 21:16:20 +02:00
|
|
|
|
2020-03-18 21:40:02 +01:00
|
|
|
func on_float_parameter_changed(n : String, v : float) -> void:
|
|
|
|
for t in TEXTURE_LIST:
|
|
|
|
if generated_textures[t.texture] != null:
|
2020-03-20 07:44:22 +01:00
|
|
|
for p in VisualServer.shader_get_param_list(shader_materials[t.texture].shader.get_rid()):
|
|
|
|
if p.name == n:
|
|
|
|
shader_materials[t.texture].set_shader_param(n, v)
|
|
|
|
need_render[t.texture] = true
|
|
|
|
update_textures()
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
func on_texture_changed(n : String) -> void:
|
|
|
|
for t in TEXTURE_LIST:
|
|
|
|
if generated_textures[t.texture] != null:
|
|
|
|
for p in VisualServer.shader_get_param_list(shader_materials[t.texture].shader.get_rid()):
|
|
|
|
if p.name == n:
|
|
|
|
need_render[t.texture] = true
|
|
|
|
update_textures()
|
|
|
|
break
|
|
|
|
|
|
|
|
func update_textures() -> void:
|
2020-03-18 21:40:02 +01:00
|
|
|
update_again = true
|
|
|
|
if !updating:
|
2020-03-20 07:44:22 +01:00
|
|
|
var image_size = get_image_size()
|
2020-03-18 21:40:02 +01:00
|
|
|
updating = true
|
|
|
|
while update_again:
|
|
|
|
update_again = false
|
|
|
|
for t in TEXTURE_LIST:
|
2020-03-20 07:44:22 +01:00
|
|
|
if need_render[t.texture]:
|
2020-03-18 21:40:02 +01:00
|
|
|
var result = mm_renderer.render_material(shader_materials[t.texture], image_size)
|
|
|
|
while result is GDScriptFunctionState:
|
|
|
|
result = yield(result, "completed")
|
|
|
|
result.copy_to_texture(generated_textures[t.texture])
|
|
|
|
result.release()
|
|
|
|
updating = false
|
2019-09-13 08:07:46 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func update_materials(material_list) -> void:
|
2020-02-18 08:47:44 +01:00
|
|
|
render_textures()
|
2019-09-13 08:07:46 +02:00
|
|
|
for m in material_list:
|
2020-02-17 08:54:46 +01:00
|
|
|
update_material(m)
|
2019-08-02 08:17:32 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_generated_texture(slot, file_prefix = null) -> ImageTexture:
|
2019-08-02 08:17:32 +02:00
|
|
|
if file_prefix != null:
|
|
|
|
var file_name = "%s_%s.png" % [ file_prefix, slot ]
|
|
|
|
if File.new().file_exists(file_name):
|
2019-11-10 15:02:00 +01:00
|
|
|
var texture = load(file_name)
|
|
|
|
return texture
|
2019-08-02 08:17:32 +02:00
|
|
|
else:
|
|
|
|
return null
|
|
|
|
else:
|
2019-09-13 08:07:46 +02:00
|
|
|
return generated_textures[slot]
|
2019-08-02 08:17:32 +02:00
|
|
|
|
2020-02-17 08:54:46 +01:00
|
|
|
func update_material(m, file_prefix = null) -> void:
|
2019-08-02 08:17:32 +02:00
|
|
|
var texture
|
2019-11-02 22:58:29 +01:00
|
|
|
if m is SpatialMaterial:
|
|
|
|
# Make the material double-sided for better visiblity in the preview
|
|
|
|
m.params_cull_mode = SpatialMaterial.CULL_DISABLED
|
2019-11-17 07:40:50 +01:00
|
|
|
# Albedo
|
2020-02-18 08:47:44 +01:00
|
|
|
m.albedo_color = parameters.albedo_color
|
2019-11-02 22:58:29 +01:00
|
|
|
m.albedo_texture = get_generated_texture("albedo", file_prefix)
|
2020-02-17 08:54:46 +01:00
|
|
|
# Ambient occlusion
|
|
|
|
if get_source(INPUT_OCCLUSION) != null:
|
|
|
|
m.ao_enabled = true
|
|
|
|
m.ao_light_affect = parameters.ao
|
|
|
|
m.ao_texture = get_generated_texture("orm", file_prefix)
|
|
|
|
m.ao_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_RED
|
|
|
|
else:
|
|
|
|
m.ao_enabled = false
|
|
|
|
# Roughness
|
2019-11-02 22:58:29 +01:00
|
|
|
m.roughness = parameters.roughness
|
2020-02-17 08:54:46 +01:00
|
|
|
if get_source(INPUT_ROUGHNESS) != null:
|
|
|
|
m.roughness_texture = get_generated_texture("orm", file_prefix)
|
|
|
|
m.roughness_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_GREEN
|
|
|
|
else:
|
|
|
|
m.roughness_texture = null
|
2019-11-02 22:58:29 +01:00
|
|
|
# Metallic
|
2020-02-17 08:54:46 +01:00
|
|
|
m.metallic = parameters.metallic
|
2020-02-18 08:47:44 +01:00
|
|
|
if get_source(INPUT_METALLIC) != null:
|
2020-02-17 08:54:46 +01:00
|
|
|
m.metallic_texture = get_generated_texture("orm", file_prefix)
|
|
|
|
m.metallic_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_BLUE
|
|
|
|
else:
|
|
|
|
m.metallic_texture = null
|
2019-11-02 22:58:29 +01:00
|
|
|
# Emission
|
2020-02-17 08:54:46 +01:00
|
|
|
if get_source(INPUT_EMISSION) != null:
|
2019-11-02 22:58:29 +01:00
|
|
|
m.emission_enabled = true
|
2020-02-18 08:47:44 +01:00
|
|
|
m.emission_energy = parameters.emission_energy
|
2020-02-17 08:54:46 +01:00
|
|
|
m.emission_texture = get_generated_texture("emission", file_prefix)
|
2019-11-02 22:58:29 +01:00
|
|
|
else:
|
|
|
|
m.emission_enabled = false
|
|
|
|
# Normal map
|
2020-02-17 08:54:46 +01:00
|
|
|
if get_source(INPUT_NORMAL) != null:
|
2019-11-02 22:58:29 +01:00
|
|
|
m.normal_enabled = true
|
2020-02-17 08:54:46 +01:00
|
|
|
m.normal_texture = get_generated_texture("normal", file_prefix)
|
2020-02-18 08:47:44 +01:00
|
|
|
m.normal_scale = parameters.normal
|
2019-11-02 22:58:29 +01:00
|
|
|
else:
|
|
|
|
m.normal_enabled = false
|
|
|
|
# Depth
|
2020-02-19 08:33:52 +01:00
|
|
|
if get_source(INPUT_DEPTH) != null and parameters.depth_scale > 0:
|
2019-11-02 22:58:29 +01:00
|
|
|
m.depth_enabled = true
|
|
|
|
m.depth_deep_parallax = true
|
2020-02-18 08:47:44 +01:00
|
|
|
m.depth_scale = parameters.depth_scale * 0.2
|
2020-02-17 08:54:46 +01:00
|
|
|
m.depth_texture = get_generated_texture("depth", file_prefix)
|
2019-11-02 22:58:29 +01:00
|
|
|
else:
|
|
|
|
m.depth_enabled = false
|
2019-11-06 22:33:01 +01:00
|
|
|
# Subsurface scattering
|
2020-02-17 08:54:46 +01:00
|
|
|
if get_source(INPUT_SSS) != null:
|
2019-11-06 22:33:01 +01:00
|
|
|
m.subsurf_scatter_enabled = true
|
2020-02-17 08:54:46 +01:00
|
|
|
m.subsurf_scatter_strength = parameters.sss
|
|
|
|
m.subsurf_scatter_texture = get_generated_texture("sss", file_prefix)
|
2019-11-06 22:33:01 +01:00
|
|
|
else:
|
|
|
|
m.subsurf_scatter_enabled = false
|
2019-08-02 08:17:32 +02:00
|
|
|
else:
|
2019-11-02 22:58:29 +01:00
|
|
|
m.set_shader_param("albedo", parameters.albedo_color)
|
|
|
|
m.set_shader_param("texture_albedo", get_generated_texture("albedo", file_prefix))
|
|
|
|
m.set_shader_param("metallic", parameters.metallic)
|
|
|
|
m.set_shader_param("texture_metallic", get_generated_texture("orm", file_prefix))
|
|
|
|
m.set_shader_param("metallic_texture_channel", PoolRealArray([0.0, 0.0, 1.0, 0.0]))
|
2019-11-24 18:47:21 +01:00
|
|
|
m.set_shader_param("roughness", parameters.roughness)
|
2019-11-02 22:58:29 +01:00
|
|
|
m.set_shader_param("texture_roughness", get_generated_texture("orm", file_prefix))
|
|
|
|
m.set_shader_param("roughness_texture_channel", PoolRealArray([0.0, 1.0, 0.0, 0.0]))
|
|
|
|
m.set_shader_param("emission_energy", parameters.emission_energy)
|
|
|
|
m.set_shader_param("texture_emission", get_generated_texture("emission", file_prefix))
|
|
|
|
m.set_shader_param("normal_scale", parameters.normal_scale)
|
2019-11-06 22:33:01 +01:00
|
|
|
m.set_shader_param("texture_normal", get_generated_texture("normal", file_prefix))
|
2019-11-02 22:58:29 +01:00
|
|
|
m.set_shader_param("depth_scale", parameters.depth_scale * 0.2)
|
2019-11-06 22:33:01 +01:00
|
|
|
m.set_shader_param("texture_depth", get_generated_texture("depth", file_prefix))
|
2019-08-02 08:17:32 +02:00
|
|
|
|
2020-02-17 08:54:46 +01:00
|
|
|
# Export
|
|
|
|
|
|
|
|
func get_export_profiles() -> Array:
|
|
|
|
return shader_model.exports.keys()
|
|
|
|
|
|
|
|
func get_export_extension(profile : String) -> String:
|
|
|
|
return shader_model.exports[profile].export_extension
|
|
|
|
|
2020-02-19 23:24:34 +01:00
|
|
|
func get_export_path(profile : String) -> String:
|
|
|
|
if export_paths.has(profile):
|
|
|
|
return export_paths[profile]
|
|
|
|
return ""
|
|
|
|
|
2020-02-18 08:47:44 +01:00
|
|
|
func subst_string(s : String, export_context : Dictionary) -> String:
|
2020-02-19 23:24:34 +01:00
|
|
|
var modified : bool = true
|
|
|
|
while modified:
|
|
|
|
modified = false
|
|
|
|
for k in export_context.keys():
|
|
|
|
var new_s = s.replace(k, export_context[k])
|
|
|
|
if new_s != s:
|
|
|
|
s = new_s
|
|
|
|
modified = true
|
2020-02-19 08:33:52 +01:00
|
|
|
while (true):
|
|
|
|
var search_string = "$(expr:"
|
|
|
|
var position = s.find(search_string)
|
|
|
|
if position == -1:
|
|
|
|
break
|
|
|
|
var parenthesis_level = 0
|
|
|
|
var expr_begin = position+search_string.length()
|
|
|
|
for i in range(expr_begin, s.length()):
|
|
|
|
if s[i] == '(':
|
|
|
|
parenthesis_level += 1
|
|
|
|
elif s[i] == ')':
|
|
|
|
if parenthesis_level == 0:
|
|
|
|
var expression = s.substr(expr_begin, i-expr_begin)
|
|
|
|
var expr = Expression.new()
|
|
|
|
var error = expr.parse(expression, [])
|
|
|
|
if error == OK:
|
|
|
|
s = s.replace(s.substr(position, i+1-position), str(expr.execute()))
|
|
|
|
else:
|
|
|
|
s = s.replace(s.substr(position, i+1-position), "EXPRESSION ERROR ("+expression+")")
|
|
|
|
break
|
|
|
|
parenthesis_level -= 1
|
2020-02-18 08:47:44 +01:00
|
|
|
return s
|
|
|
|
|
|
|
|
func create_file_from_template(template : String, file_name : String, export_context : Dictionary) -> bool:
|
|
|
|
var in_file = File.new()
|
|
|
|
var out_file = File.new()
|
|
|
|
if in_file.open(mm_loader.STD_GENDEF_PATH+"/"+template, File.READ) != OK:
|
2020-03-15 07:08:07 +01:00
|
|
|
if in_file.open(OS.get_executable_path().get_base_dir()+"/nodes/"+template, File.READ) != OK:
|
2020-02-18 08:47:44 +01:00
|
|
|
print("Cannot find template file "+template)
|
|
|
|
return false
|
2020-02-19 23:24:34 +01:00
|
|
|
Directory.new().remove(file_name)
|
|
|
|
if out_file.open(file_name, File.WRITE) != OK:
|
|
|
|
print("Cannot write file '"+file_name+"' ("+str(out_file.get_error())+")")
|
2020-02-18 08:47:44 +01:00
|
|
|
return false
|
|
|
|
var skip_state : Array = [ false ]
|
|
|
|
while ! in_file.eof_reached():
|
|
|
|
var l = in_file.get_line()
|
|
|
|
if l.left(4) == "$if ":
|
|
|
|
var condition = subst_string(l.right(4), export_context)
|
|
|
|
var expr = Expression.new()
|
|
|
|
var error = expr.parse(condition, [])
|
|
|
|
if error != OK:
|
2020-02-19 08:33:52 +01:00
|
|
|
print("Error in expression "+condition+": "+expr.get_error_text())
|
2020-02-18 08:47:44 +01:00
|
|
|
continue
|
|
|
|
skip_state.push_back(!expr.execute())
|
|
|
|
elif l.left(3) == "$fi":
|
|
|
|
skip_state.pop_back()
|
|
|
|
elif l.left(5) == "$else":
|
|
|
|
skip_state.push_back(!skip_state.pop_back())
|
|
|
|
elif ! skip_state.back():
|
|
|
|
out_file.store_line(subst_string(l, export_context))
|
|
|
|
return true
|
|
|
|
|
2020-02-26 08:15:16 +01:00
|
|
|
func export_material(prefix : String, profile : String, size : int = 0) -> void:
|
|
|
|
if size == 0:
|
|
|
|
size = get_image_size()
|
2020-02-19 23:24:34 +01:00
|
|
|
export_paths[profile] = prefix
|
2020-02-18 08:47:44 +01:00
|
|
|
var export_context : Dictionary = {
|
2020-02-19 08:33:52 +01:00
|
|
|
"$(path_prefix)":prefix,
|
|
|
|
"$(file_prefix)":prefix.get_file()
|
2020-02-18 08:47:44 +01:00
|
|
|
}
|
2020-02-19 08:33:52 +01:00
|
|
|
for i in range(shader_model.inputs.size()):
|
|
|
|
var input = shader_model.inputs[i]
|
|
|
|
export_context["$(connected:"+input.name+")"] = "true" if get_source(i) != null else "false"
|
|
|
|
for p in shader_model.parameters:
|
|
|
|
var value = p.default
|
|
|
|
if parameters.has(p.name):
|
|
|
|
value = parameters[p.name]
|
|
|
|
match p.type:
|
|
|
|
"float", "size":
|
|
|
|
export_context["$(param:"+p.name+")"] = str(value)
|
|
|
|
"color":
|
|
|
|
export_context["$(param:"+p.name+".r)"] = str(value.r)
|
|
|
|
export_context["$(param:"+p.name+".g)"] = str(value.g)
|
|
|
|
export_context["$(param:"+p.name+".b)"] = str(value.b)
|
|
|
|
export_context["$(param:"+p.name+".a)"] = str(value.a)
|
|
|
|
_:
|
|
|
|
print(p.type+" not supported in material")
|
2020-02-19 23:24:34 +01:00
|
|
|
if shader_model.exports[profile].has("uids"):
|
|
|
|
for i in range(shader_model.exports[profile].uids):
|
|
|
|
var uid : String
|
|
|
|
var r = []
|
|
|
|
for k in range(16):
|
|
|
|
r.append(randi() & 255)
|
|
|
|
r[6] = (r[6] & 0x0f) | 0x40
|
|
|
|
r[8] = (r[8] & 0x3f) | 0x80
|
|
|
|
for k in range(16):
|
|
|
|
uid += '%02x' % r[k]
|
|
|
|
export_context["$(uid:"+str(i)+")"] = uid
|
2020-02-17 08:54:46 +01:00
|
|
|
for f in shader_model.exports[profile].files:
|
2020-02-19 23:24:34 +01:00
|
|
|
if f.has("conditions"):
|
|
|
|
var condition = subst_string(f.conditions, export_context)
|
|
|
|
var expr = Expression.new()
|
|
|
|
var error = expr.parse(condition, [])
|
|
|
|
if error != OK:
|
|
|
|
print("Error in expression: "+expr.get_error_text())
|
|
|
|
continue
|
|
|
|
if !expr.execute():
|
|
|
|
continue
|
2020-02-17 08:54:46 +01:00
|
|
|
match f.type:
|
|
|
|
"texture":
|
2020-02-18 08:47:44 +01:00
|
|
|
var file_name = subst_string(f.file_name, export_context)
|
2020-02-26 08:15:16 +01:00
|
|
|
var result = render(f.output, size)
|
2020-02-17 08:54:46 +01:00
|
|
|
while result is GDScriptFunctionState:
|
|
|
|
result = yield(result, "completed")
|
|
|
|
result.save_to_file(file_name)
|
|
|
|
result.release()
|
2020-02-18 08:47:44 +01:00
|
|
|
"template":
|
2020-02-19 23:24:34 +01:00
|
|
|
var file_export_context = export_context.duplicate()
|
|
|
|
if f.has("file_params"):
|
|
|
|
for p in f.file_params.keys():
|
|
|
|
file_export_context["$(file_param:"+p+")"] = f.file_params[p]
|
|
|
|
var file_name = subst_string(f.file_name, export_context)
|
|
|
|
create_file_from_template(f.template, file_name, file_export_context)
|
2019-10-20 16:22:06 +02:00
|
|
|
|
2020-02-19 23:24:34 +01:00
|
|
|
func _serialize_data(data: Dictionary) -> Dictionary:
|
|
|
|
data = ._serialize_data(data)
|
|
|
|
data.export_paths = export_paths
|
2019-09-09 22:00:18 +02:00
|
|
|
return data
|
2020-02-19 23:24:34 +01:00
|
|
|
|
|
|
|
func _deserialize(data : Dictionary) -> void:
|
|
|
|
._deserialize(data)
|
|
|
|
if data.has("export_paths"):
|
|
|
|
export_paths = data.export_paths.duplicate()
|