2019-08-02 08:17:32 +02:00
|
|
|
tool
|
2019-07-31 20:53:00 +02:00
|
|
|
extends Object
|
|
|
|
class_name MMGenLoader
|
|
|
|
|
|
|
|
func load_gen(filename: String) -> MMGenBase:
|
|
|
|
var file = File.new()
|
|
|
|
if file.open(filename, File.READ) == OK:
|
|
|
|
var data = parse_json(file.get_as_text())
|
|
|
|
return create_gen(data)
|
|
|
|
return null
|
|
|
|
|
2019-08-15 11:53:21 +02:00
|
|
|
func add_to_gen_graph(gen_graph, generators, connections):
|
|
|
|
var rv = { generators=[], connections=[] }
|
|
|
|
for n in generators:
|
|
|
|
var g = create_gen(n)
|
|
|
|
if g != null:
|
|
|
|
var name = g.name
|
|
|
|
var index = 1
|
|
|
|
while gen_graph.has_node(name):
|
|
|
|
index += 1
|
|
|
|
name = g.name + "_" + str(index)
|
|
|
|
g.name = name
|
|
|
|
gen_graph.add_child(g)
|
|
|
|
rv.generators.append(g)
|
|
|
|
for c in connections:
|
|
|
|
gen_graph.connections.append(c)
|
|
|
|
rv.connections.append(c)
|
|
|
|
return rv
|
|
|
|
|
2019-07-31 20:53:00 +02:00
|
|
|
func create_gen(data) -> MMGenBase:
|
|
|
|
var generator = null
|
|
|
|
if data.has("connections") and data.has("nodes"):
|
|
|
|
generator = MMGenGraph.new()
|
2019-08-15 11:53:21 +02:00
|
|
|
add_to_gen_graph(generator, data.nodes, data.connections)
|
2019-08-17 17:35:48 +02:00
|
|
|
elif data.has("shader_model"):
|
2019-08-12 15:58:42 +02:00
|
|
|
generator = MMGenShader.new()
|
2019-08-17 17:35:48 +02:00
|
|
|
generator.set_shader_model(data.shader_model)
|
2019-07-31 20:53:00 +02:00
|
|
|
elif data.has("type"):
|
|
|
|
if data.type == "material":
|
|
|
|
generator = MMGenMaterial.new()
|
2019-08-17 17:35:48 +02:00
|
|
|
elif data.type == "buffer":
|
|
|
|
generator = MMGenBuffer.new()
|
2019-08-25 23:27:07 +02:00
|
|
|
elif data.type == "image":
|
|
|
|
generator = MMGenImage.new()
|
2019-07-31 20:53:00 +02:00
|
|
|
else:
|
2019-08-12 15:58:42 +02:00
|
|
|
var file = File.new()
|
|
|
|
if file.open("res://addons/material_maker/library/"+data.type+".mml", File.READ) == OK:
|
|
|
|
print("loaded description "+data.type+".mml")
|
2019-08-17 17:35:48 +02:00
|
|
|
generator = create_gen(parse_json(file.get_as_text()))
|
2019-08-12 15:58:42 +02:00
|
|
|
file.close()
|
|
|
|
elif file.open("res://addons/material_maker/nodes/"+data.type+".mmn", File.READ) == OK:
|
|
|
|
generator = MMGenShader.new()
|
|
|
|
print("loaded description "+data.type+".mmn")
|
2019-08-17 17:35:48 +02:00
|
|
|
generator.set_shader_model(parse_json(file.get_as_text()))
|
2019-08-12 15:58:42 +02:00
|
|
|
file.close()
|
2019-07-31 20:53:00 +02:00
|
|
|
else:
|
2019-08-12 15:58:42 +02:00
|
|
|
print("Cannot find description for "+data.type)
|
2019-08-17 17:35:48 +02:00
|
|
|
if generator != null:
|
|
|
|
generator.name = data.type
|
2019-08-09 08:16:24 +02:00
|
|
|
else:
|
|
|
|
print(data)
|
2019-08-12 15:58:42 +02:00
|
|
|
if generator != null:
|
2019-08-15 11:53:21 +02:00
|
|
|
if data.has("name"):
|
|
|
|
generator.name = data.name
|
2019-08-12 15:58:42 +02:00
|
|
|
if data.has("node_position"):
|
|
|
|
generator.position.x = data.node_position.x
|
|
|
|
generator.position.y = data.node_position.y
|
|
|
|
if data.has("parameters"):
|
2019-08-17 17:35:48 +02:00
|
|
|
for p in data.parameters.keys():
|
|
|
|
generator.parameters[p] = data.parameters[p]
|
2019-07-31 20:53:00 +02:00
|
|
|
return generator
|