Moved MMLoader to autoload. Updated demo so it can be exported.

This commit is contained in:
RodZill4 2020-01-28 11:47:29 +01:00
parent 72acb5cd13
commit f1ff09dcc4
21 changed files with 265 additions and 150 deletions

View File

@ -40,11 +40,11 @@ var seed_value : int = 0
const PORT_TYPE_NAMES : Array = [ "f", "rgb", "rgba", "sdf2d", "sdf3d" ] const PORT_TYPE_NAMES : Array = [ "f", "rgb", "rgba", "sdf2d", "sdf3d" ]
const PORT_TYPES : Dictionary = { const PORT_TYPES : Dictionary = {
f = { type="float", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.5, 0.5, 0.5) }, f = { label="Greyscale", type="float", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.5, 0.5, 0.5) },
rgb = { type="vec3", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.5, 0.5, 1.0) }, rgb = { label="Color", type="vec3", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.5, 0.5, 1.0) },
rgba = { type="vec4", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.0, 0.5, 0.0, 0.5) }, rgba = { label="RGBA", type="vec4", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.0, 0.5, 0.0, 0.5) },
sdf2d = { type="float", paramdefs="vec2 uv", params="uv", slot_type=1, color=Color(1.0, 0.5, 0.0) }, sdf2d = { label="SDF2D", type="float", paramdefs="vec2 uv", params="uv", slot_type=1, color=Color(1.0, 0.5, 0.0) },
sdf3d = { type="float", paramdefs="vec3 p", params="p", slot_type=2, color=Color(1.0, 0.0, 0.0) }, sdf3d = { label="SDF3D", type="float", paramdefs="vec3 p", params="p", slot_type=2, color=Color(1.0, 0.0, 0.0) },
any = { slot_type=42, color=Color(1.0, 1.0, 1.0) } any = { slot_type=42, color=Color(1.0, 1.0, 1.0) }
} }
@ -165,6 +165,75 @@ func get_input_shader(input_index : int) -> Dictionary:
func get_shader(output_index : int, context) -> Dictionary: func get_shader(output_index : int, context) -> Dictionary:
return get_shader_code("UV", output_index, context) return get_shader_code("UV", output_index, context)
func generate_preview_shader(src_code) -> String:
var code
code = "shader_type canvas_item;\n"
code += "render_mode blend_disabled;\n"
code += "uniform float preview_size = 64;\n"
var file = File.new()
file.open("res://addons/material_maker/common.shader", File.READ)
code += file.get_as_text()
code += "\n"
if src_code.has("textures"):
for t in src_code.textures.keys():
code += "uniform sampler2D "+t+";\n"
if src_code.has("globals"):
for g in src_code.globals:
code += g
var shader_code = src_code.defs
if src_code.has("rgba"):
shader_code += "\nvoid fragment() {\n"
shader_code += "vec2 uv = UV;\n"
shader_code += src_code.code
shader_code += "COLOR = "+src_code.rgba+";\n"
shader_code += "}\n"
elif src_code.has("sdf2d"):
shader_code += "\nvoid fragment() {\n"
shader_code += "vec2 uv = UV;\n"
shader_code += src_code.code
shader_code += "float d = "+src_code.sdf2d+";\n"
shader_code += "vec3 col = vec3(cos(d*min(256, preview_size)));\n"
shader_code += "col *= clamp(1.0-d*d, 0.0, 1.0);\n"
shader_code += "col *= vec3(1.0, vec2(step(-0.015, d)));\n"
shader_code += "col *= vec3(vec2(step(d, 0.015)), 1.0);\n"
shader_code += "COLOR = vec4(col, 1.0);\n"
shader_code += "}\n"
elif src_code.has("sdf3d"):
shader_code += "\nfloat calcdist(vec3 uv) {\n"
shader_code += src_code.code
shader_code += "return min("+src_code.sdf3d+", uv.z);\n"
shader_code += "}\n"
shader_code += "float raymarch(vec3 ro, vec3 rd) {\n"
shader_code += "float d=0.0;\n"
shader_code += "for (int i = 0; i < 50; i++) {\n"
shader_code += "vec3 p = ro + rd*d;\n"
shader_code += "float dstep = calcdist(p);\n"
shader_code += "d += dstep;\n"
shader_code += "if (dstep < 0.0001) break;\n"
shader_code += "}\n"
shader_code += "return d;\n"
shader_code += "}\n"
shader_code += "vec3 normal(vec3 p) {\n"
shader_code += " float d = calcdist(p);\n"
shader_code += " float e = .0001;\n"
shader_code += " vec3 n = d - vec3(calcdist(p-vec3(e, 0.0, 0.0)), calcdist(p-vec3(0.0, e, 0.0)), calcdist(p-vec3(0.0, 0.0, e)));\n"
shader_code += " return normalize(n);\n"
shader_code += "}\n"
shader_code += "\nvoid fragment() {\n"
shader_code += "vec2 uv = UV-vec2(0.5);\n"
shader_code += "vec3 p = vec3(uv, 2.0-raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0)));\n"
shader_code += "vec3 n = normal(p);\n"
shader_code += "vec3 l = vec3(5.0, 5.0, 10.0);\n"
shader_code += "vec3 ld = normalize(l-p);\n"
shader_code += "float o = step(p.z, 0.001);\n"
shader_code += "float shadow = 1.0-0.75*step(raymarch(l, -ld), length(l-p)-0.01);\n"
shader_code += "float light = 0.3+0.7*dot(n, ld)*shadow;\n"
shader_code += "COLOR = vec4(vec3(0.8+0.2*o, 0.8+0.2*o, 1.0)*light, 1.0);\n"
shader_code += "}\n"
#print("GENERATED SHADER:\n"+shader_code)
code += shader_code
return code
func render(output_index : int, size : int, preview : bool = false) -> Object: func render(output_index : int, size : int, preview : bool = false) -> Object:
var context : MMGenContext = MMGenContext.new() var context : MMGenContext = MMGenContext.new()
var source = get_shader_code("uv", output_index, context) var source = get_shader_code("uv", output_index, context)
@ -174,7 +243,11 @@ func render(output_index : int, size : int, preview : bool = false) -> Object:
source = { defs="", code="", textures={}, rgba="vec4(0.0)" } source = { defs="", code="", textures={}, rgba="vec4(0.0)" }
var shader : String var shader : String
if preview: if preview:
shader = mm_renderer.generate_preview_shader(source) var outputs = get_output_defs()
if outputs.size() > output_index:
var output = outputs[output_index]
print(output)
shader = generate_preview_shader(source)
else: else:
shader = mm_renderer.generate_shader(source) shader = mm_renderer.generate_shader(source)
var result = mm_renderer.render_shader(shader, source.textures, size) var result = mm_renderer.render_shader(shader, source.textures, size)

View File

@ -332,4 +332,4 @@ func _deserialize(data : Dictionary) -> void:
label = data.label label = data.label
var nodes = data.nodes if data.has("nodes") else [] var nodes = data.nodes if data.has("nodes") else []
var connections = data.connections if data.has("connections") else [] var connections = data.connections if data.has("connections") else []
load("res://addons/material_maker/engine/loader.gd").add_to_gen_graph(self, nodes, connections) mm_loader.add_to_gen_graph(self, nodes, connections)

View File

@ -1,23 +1,25 @@
tool tool
extends Object extends Node
class_name MMGenLoader
const STD_GENDEF_PATH = "res://addons/material_maker/nodes" const STD_GENDEF_PATH = "res://addons/material_maker/nodes"
static func generator_name_from_path(path : String) -> String: func _ready():
print("loader ready!")
func generator_name_from_path(path : String) -> String:
for p in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]: for p in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]:
print(p) print(p)
print(path.get_base_dir()) print(path.get_base_dir())
return path.get_basename().get_file() return path.get_basename().get_file()
static func load_gen(filename: String) -> MMGenBase: func load_gen(filename: String) -> MMGenBase:
var file = File.new() var file = File.new()
if file.open(filename, File.READ) == OK: if file.open(filename, File.READ) == OK:
var data = parse_json(file.get_as_text()) var data = parse_json(file.get_as_text())
return create_gen(data) return create_gen(data)
return null return null
static func add_to_gen_graph(gen_graph, generators, connections) -> Dictionary: func add_to_gen_graph(gen_graph, generators, connections) -> Dictionary:
var rv = { generators=[], connections=[] } var rv = { generators=[], connections=[] }
var gennames = {} var gennames = {}
for n in generators: for n in generators:
@ -35,7 +37,7 @@ static func add_to_gen_graph(gen_graph, generators, connections) -> Dictionary:
rv.connections.append(c) rv.connections.append(c)
return rv return rv
static func create_gen(data) -> MMGenBase: func create_gen(data) -> MMGenBase:
var guess = [ var guess = [
{ keyword="connections", type=MMGenGraph }, { keyword="connections", type=MMGenGraph },
{ keyword="nodes", type=MMGenGraph }, { keyword="nodes", type=MMGenGraph },
@ -88,7 +90,7 @@ static func create_gen(data) -> MMGenBase:
generator.deserialize(data) generator.deserialize(data)
return generator return generator
static func get_generator_list() -> Array: func get_generator_list() -> Array:
var rv = [] var rv = []
var dir : Directory = Directory.new() var dir : Directory = Directory.new()
for p in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]: for p in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]:

View File

@ -38,75 +38,6 @@ static func generate_shader(src_code) -> String:
code += shader_code code += shader_code
return code return code
static func generate_preview_shader(src_code) -> String:
var code
code = "shader_type canvas_item;\n"
code += "render_mode blend_disabled;\n"
code += "uniform float preview_size = 64;\n"
var file = File.new()
file.open("res://addons/material_maker/common.shader", File.READ)
code += file.get_as_text()
code += "\n"
if src_code.has("textures"):
for t in src_code.textures.keys():
code += "uniform sampler2D "+t+";\n"
if src_code.has("globals"):
for g in src_code.globals:
code += g
var shader_code = src_code.defs
if src_code.has("rgba"):
shader_code += "\nvoid fragment() {\n"
shader_code += "vec2 uv = UV;\n"
shader_code += src_code.code
shader_code += "COLOR = "+src_code.rgba+";\n"
shader_code += "}\n"
elif src_code.has("sdf2d"):
shader_code += "\nvoid fragment() {\n"
shader_code += "vec2 uv = UV;\n"
shader_code += src_code.code
shader_code += "float d = "+src_code.sdf2d+";\n"
shader_code += "vec3 col = vec3(cos(d*min(256, preview_size)));\n"
shader_code += "col *= clamp(1.0-d*d, 0.0, 1.0);\n"
shader_code += "col *= vec3(1.0, vec2(step(-0.015, d)));\n"
shader_code += "col *= vec3(vec2(step(d, 0.015)), 1.0);\n"
shader_code += "COLOR = vec4(col, 1.0);\n"
shader_code += "}\n"
elif src_code.has("sdf3d"):
shader_code += "\nfloat calcdist(vec3 uv) {\n"
shader_code += src_code.code
shader_code += "return min("+src_code.sdf3d+", uv.z);\n"
shader_code += "}\n"
shader_code += "float raymarch(vec3 ro, vec3 rd) {\n"
shader_code += "float d=0.0;\n"
shader_code += "for (int i = 0; i < 50; i++) {\n"
shader_code += "vec3 p = ro + rd*d;\n"
shader_code += "float dstep = calcdist(p);\n"
shader_code += "d += dstep;\n"
shader_code += "if (dstep < 0.0001) break;\n"
shader_code += "}\n"
shader_code += "return d;\n"
shader_code += "}\n"
shader_code += "vec3 normal(vec3 p) {\n"
shader_code += " float d = calcdist(p);\n"
shader_code += " float e = .0001;\n"
shader_code += " vec3 n = d - vec3(calcdist(p-vec3(e, 0.0, 0.0)), calcdist(p-vec3(0.0, e, 0.0)), calcdist(p-vec3(0.0, 0.0, e)));\n"
shader_code += " return normalize(n);\n"
shader_code += "}\n"
shader_code += "\nvoid fragment() {\n"
shader_code += "vec2 uv = UV-vec2(0.5);\n"
shader_code += "vec3 p = vec3(uv, 2.0-raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0)));\n"
shader_code += "vec3 n = normal(p);\n"
shader_code += "vec3 l = vec3(5.0, 5.0, 10.0);\n"
shader_code += "vec3 ld = normalize(l-p);\n"
shader_code += "float o = step(p.z, 0.001);\n"
shader_code += "float shadow = 1.0-0.75*step(raymarch(l, -ld), length(l-p)-0.01);\n"
shader_code += "float light = 0.3+0.7*dot(n, ld)*shadow;\n"
shader_code += "COLOR = vec4(vec3(0.8+0.2*o, 0.8+0.2*o, 1.0)*light, 1.0);\n"
shader_code += "}\n"
#print("GENERATED SHADER:\n"+shader_code)
code += shader_code
return code
static func generate_combined_shader(red_code, green_code, blue_code) -> String: static func generate_combined_shader(red_code, green_code, blue_code) -> String:
var code var code
code = "shader_type canvas_item;\n" code = "shader_type canvas_item;\n"

View File

@ -13,8 +13,7 @@ func set_ptex(s : String) -> void :
call_deferred("update_texture") call_deferred("update_texture")
func update_texture() -> void: func update_texture() -> void:
var loader = MMGenLoader.new() var mm_graph = mm_loader.create_gen(parse_json(ptex))
var mm_graph = loader.create_gen(parse_json(ptex))
if mm_graph == null: if mm_graph == null:
return return
var mm_material : MMGenMaterial = mm_graph.get_node("Material") var mm_material : MMGenMaterial = mm_graph.get_node("Material")

View File

@ -13,7 +13,7 @@ func _exit_tree() -> void:
importer = null importer = null
func generate_material(ptex_filename: String) -> Material: func generate_material(ptex_filename: String) -> Material:
var generator = MMGenLoader.load_gen(ptex_filename) var generator = mm_loader.load_gen(ptex_filename)
add_child(generator) add_child(generator)
if generator.has_node("Material"): if generator.has_node("Material"):
var gen_material = generator.get_node("Material") var gen_material = generator.get_node("Material")

View File

@ -1,13 +1,16 @@
[gd_scene load_steps=8 format=2] [gd_scene load_steps=10 format=2]
[ext_resource path="res://material_maker/examples/skulls.ptex" type="Material" id=1] [ext_resource path="res://material_maker/examples/bricks.ptex" type="Material" id=1]
[ext_resource path="res://material_maker/preview/panoramas/studio_sky.tres" type="Environment" id=2] [ext_resource path="res://material_maker/preview/panoramas/studio_sky.tres" type="Environment" id=2]
[ext_resource path="res://demo/object.tscn" type="PackedScene" id=3]
[ext_resource path="res://material_maker/examples/marble.ptex" type="Material" id=4]
[ext_resource path="res://material_maker/examples/medieval_wall.ptex" type="Material" id=5]
[ext_resource path="res://material_maker/examples/floor1.ptex" type="Material" id=6]
[ext_resource path="res://material_maker/examples/beehive.ptex" type="Material" id=7]
[sub_resource type="SphereMesh" id=1] [sub_resource type="Animation" id=1]
[sub_resource type="Animation" id=2]
resource_name = "rotate" resource_name = "rotate"
length = 10.0 length = 5.0
loop = true loop = true
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/path = NodePath("CamPivot:rotation_degrees") tracks/0/path = NodePath("CamPivot:rotation_degrees")
@ -16,68 +19,66 @@ tracks/0/loop_wrap = true
tracks/0/imported = false tracks/0/imported = false
tracks/0/enabled = true tracks/0/enabled = true
tracks/0/keys = { tracks/0/keys = {
"times": PoolRealArray( 0, 10 ), "times": PoolRealArray( 0, 5 ),
"transitions": PoolRealArray( 1, 1 ), "transitions": PoolRealArray( 1, 1 ),
"update": 0, "update": 0,
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ] "values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ]
} }
[sub_resource type="SpatialMaterial" id=4] [sub_resource type="Animation" id=2]
flags_unshaded = true resource_name = "move"
flags_do_not_receive_shadows = true length = 50.0
[sub_resource type="SphereMesh" id=5]
material = SubResource( 4 )
radius = 0.1
height = 0.2
[sub_resource type="Animation" id=3]
resource_name = "rotate"
length = 5.0
loop = true loop = true
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/path = NodePath("LightPivot:rotation_degrees") tracks/0/path = NodePath("CamPivot:translation")
tracks/0/interp = 1 tracks/0/interp = 1
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/imported = false tracks/0/imported = false
tracks/0/enabled = true tracks/0/enabled = true
tracks/0/keys = { tracks/0/keys = {
"times": PoolRealArray( 0, 5 ), "times": PoolRealArray( 0, 4, 5, 9, 10, 14, 15, 19, 20, 24, 25, 29, 30, 34, 35, 39, 40, 44, 45, 49 ),
"transitions": PoolRealArray( 1, 1 ), "transitions": PoolRealArray( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ),
"update": 0, "update": 0,
"values": [ Vector3( 0, 0, 0 ), Vector3( 360, 0, 0 ) ] "values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, -5 ), Vector3( 0, 0, -5 ), Vector3( 0, 0, -10 ), Vector3( 0, 0, -10 ), Vector3( 0, 0, -15 ), Vector3( 0, 0, -15 ), Vector3( 0, 0, -20 ), Vector3( 0, 0, -20 ), Vector3( 0, 0, -25 ), Vector3( 0, 0, -25 ), Vector3( 0, 0, -20 ), Vector3( 0, 0, -20 ), Vector3( 0, 0, -15 ), Vector3( 0, 0, -15 ), Vector3( 0, 0, -10 ), Vector3( 0, 0, -10 ), Vector3( 0, 0, -5 ), Vector3( 0, 0, -5 ) ]
} }
[node name="Spatial" type="Spatial"] [node name="Spatial" type="Spatial"]
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = SubResource( 1 )
material/0 = ExtResource( 1 )
[node name="CamPivot" type="Spatial" parent="."] [node name="CamPivot" type="Spatial" parent="."]
transform = Transform( 0.982287, 0, 0.187381, 0, 1, 0, -0.187381, 0, 0.982287, 0, 0, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5 )
[node name="Camera" type="Camera" parent="CamPivot"] [node name="Camera" type="Camera" parent="CamPivot"]
transform = Transform( 0.999487, 0.0319038, 0.00268748, -0.0319038, 0.985399, 0.167245, 0.00268751, -0.167245, 0.985912, 0.28563, 0.826821, 2.79088 ) transform = Transform( 0.999487, 0.0319038, 0.00268748, -0.0319038, 0.985399, 0.167245, 0.00268751, -0.167245, 0.985912, 0.28563, 0.826821, 2.79088 )
[node name="CamRotate" type="AnimationPlayer" parent="."] [node name="CamRotate" type="AnimationPlayer" parent="."]
autoplay = "rotate" autoplay = "rotate"
anims/rotate = SubResource( 2 ) anims/rotate = SubResource( 1 )
[node name="LightPivot" type="Spatial" parent="."] [node name="CamMove" type="AnimationPlayer" parent="."]
transform = Transform( 1, 0, 0, 0, 0.929776, -0.368125, 0, 0.368125, 0.929776, 0, 0, 0 ) autoplay = "move"
anims/move = SubResource( 2 )
[node name="OmniLight" type="OmniLight" parent="LightPivot"] [node name="Skulls" parent="." instance=ExtResource( 3 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0746527, 1.74306, 0 )
[node name="MeshInstance" type="MeshInstance" parent="LightPivot/OmniLight"] [node name="Bricks" parent="." instance=ExtResource( 3 )]
cast_shadow = 0 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5 )
mesh = SubResource( 5 ) material/0 = ExtResource( 1 )
material/0 = null
[node name="LightRotate" type="AnimationPlayer" parent="."] [node name="Floor" parent="." instance=ExtResource( 3 )]
autoplay = "rotate" transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -10 )
anims/rotate = SubResource( 3 ) material/0 = ExtResource( 6 )
[node name="Marble" parent="." instance=ExtResource( 3 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -15 )
material/0 = ExtResource( 4 )
[node name="MedievalWall" parent="." instance=ExtResource( 3 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -20 )
material/0 = ExtResource( 5 )
[node name="BeeHive" parent="." instance=ExtResource( 3 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -25 )
material/0 = ExtResource( 7 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="."] [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = ExtResource( 2 ) environment = ExtResource( 2 )

49
demo/object.tscn Normal file
View File

@ -0,0 +1,49 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://material_maker/examples/skulls.ptex" type="Material" id=1]
[sub_resource type="SphereMesh" id=1]
[sub_resource type="SpatialMaterial" id=2]
flags_unshaded = true
flags_do_not_receive_shadows = true
[sub_resource type="SphereMesh" id=3]
material = SubResource( 2 )
radius = 0.1
height = 0.2
[sub_resource type="Animation" id=4]
length = 5.0
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("LightPivot:rotation_degrees")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 5 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Vector3( 0, 0, 0 ), Vector3( 360, 0, 0 ) ]
}
[node name="MeshInstance" type="MeshInstance"]
mesh = SubResource( 1 )
material/0 = ExtResource( 1 )
[node name="LightPivot" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 0.929776, -0.368125, 0, 0.368125, 0.929776, 0, 0, 0 )
[node name="OmniLight" type="OmniLight" parent="LightPivot"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0746527, 1.74306, 0 )
[node name="MeshInstance" type="MeshInstance" parent="LightPivot/OmniLight"]
cast_shadow = 0
mesh = SubResource( 3 )
material/0 = null
[node name="LightRotate" type="AnimationPlayer" parent="."]
autoplay = "rotate"
anims/rotate = SubResource( 4 )

File diff suppressed because one or more lines are too long

View File

@ -12,4 +12,4 @@ dest_files=[ "res://.import/beehive.ptex-51715262d81c1a144e9a7e141a45db7f.tres"
[params] [params]
render=false render=false
scale=1.0 scale=3.0

View File

@ -12,4 +12,4 @@ dest_files=[ "res://.import/bricks.ptex-8a4a409b5b41c018677a6156ef3f93e5.tres" ]
[params] [params]
render=false render=false
scale=1.0 scale=3.0

View File

@ -12,4 +12,4 @@ dest_files=[ "res://.import/floor1.ptex-fb54baf7242d73ad5e0d97d70fc2ffe8.tres" ]
[params] [params]
render=false render=false
scale=1.0 scale=3.0

View File

@ -12,4 +12,4 @@ dest_files=[ "res://.import/marble.ptex-0b7e8ced36657d462bfe938e53d1f73b.tres" ]
[params] [params]
render=false render=false
scale=1.0 scale=3.0

View File

@ -12,4 +12,4 @@ dest_files=[ "res://.import/medieval_wall.ptex-28369316aeb5d9dfca15a3cfe9753817.
[params] [params]
render=false render=false
scale=1.0 scale=3.0

View File

@ -169,8 +169,7 @@ func update_graph(generators, connections) -> Array:
func new_material() -> void: func new_material() -> void:
clear_material() clear_material()
var loader = MMGenLoader.new() top_generator = mm_loader.create_gen({nodes=[{name="Material", type="material","parameters":{"size":11}}], connections=[]})
top_generator = loader.create_gen({nodes=[{name="Material", type="material","parameters":{"size":11}}], connections=[]})
if top_generator != null: if top_generator != null:
add_child(top_generator) add_child(top_generator)
move_child(top_generator, 0) move_child(top_generator, 0)
@ -194,7 +193,7 @@ func create_nodes(data, position : Vector2 = Vector2(0, 0)) -> Array:
if data.has("type"): if data.has("type"):
data = { nodes=[data], connections=[] } data = { nodes=[data], connections=[] }
if typeof(data.nodes) == TYPE_ARRAY and typeof(data.connections) == TYPE_ARRAY: if typeof(data.nodes) == TYPE_ARRAY and typeof(data.connections) == TYPE_ARRAY:
var new_stuff = MMGenLoader.add_to_gen_graph(generator, data.nodes, data.connections) var new_stuff = mm_loader.add_to_gen_graph(generator, data.nodes, data.connections)
for g in new_stuff.generators: for g in new_stuff.generators:
g.position += position g.position += position
return update_graph(new_stuff.generators, new_stuff.connections) return update_graph(new_stuff.generators, new_stuff.connections)
@ -205,7 +204,7 @@ func create_gen_from_type(gen_name) -> void:
func load_file(filename) -> void: func load_file(filename) -> void:
clear_material() clear_material()
top_generator = MMGenLoader.load_gen(filename) top_generator = mm_loader.load_gen(filename)
if top_generator != null: if top_generator != null:
add_child(top_generator) add_child(top_generator)
move_child(top_generator, 0) move_child(top_generator, 0)

View File

@ -195,7 +195,7 @@ func add_recent(path) -> void:
f.close() f.close()
func create_menu_create(menu) -> void: func create_menu_create(menu) -> void:
var gens = MMGenLoader.get_generator_list() var gens = mm_loader.get_generator_list()
menu.clear() menu.clear()
for i in gens.size(): for i in gens.size():
menu.add_item(gens[i], i) menu.add_item(gens[i], i)
@ -205,7 +205,7 @@ func create_menu_create(menu) -> void:
func _on_Create_id_pressed(id) -> void: func _on_Create_id_pressed(id) -> void:
var graph_edit : MMGraphEdit = get_current_graph_edit() var graph_edit : MMGraphEdit = get_current_graph_edit()
if graph_edit != null: if graph_edit != null:
var gens = MMGenLoader.get_generator_list() var gens = mm_loader.get_generator_list()
graph_edit.create_gen_from_type(gens[id]) graph_edit.create_gen_from_type(gens[id])
func menu_about_to_show(name, menu) -> void: func menu_about_to_show(name, menu) -> void:

View File

@ -1,6 +1,6 @@
extends MMGraphNodeBase extends MMGraphNodeBase
static func generate_shader(src_code) -> String: static func generate_debug_shader(src_code) -> String:
var code var code
code = "" code = ""
var file = File.new() var file = File.new()
@ -32,4 +32,4 @@ func _on_Button_pressed() -> void:
var source = src.generator.get_shader_code("UV", src.output_index, context) var source = src.generator.get_shader_code("UV", src.output_index, context)
var popup = preload("res://material_maker/nodes/debug/debug_popup.tscn").instance() var popup = preload("res://material_maker/nodes/debug/debug_popup.tscn").instance()
get_parent().add_child(popup) get_parent().add_child(popup)
popup.show_code(generate_shader(source)) popup.show_code(generate_debug_shader(source))

View File

@ -320,9 +320,9 @@ func do_load_generator(file_name : String) -> void:
new_generator.set_shader_model(parse_json(file.get_as_text())) new_generator.set_shader_model(parse_json(file.get_as_text()))
file.close() file.close()
else: else:
new_generator = MMGenLoader.load_gen(file_name) new_generator = mm_loader.load_gen(file_name)
if new_generator != null: if new_generator != null:
var gen_name = MMGenLoader.generator_name_from_path(file_name) var gen_name = mm_loader.generator_name_from_path(file_name)
if gen_name != "": if gen_name != "":
new_generator.model = gen_name new_generator.model = gen_name
var parent_generator = generator.get_parent() var parent_generator = generator.get_parent()

View File

@ -64,11 +64,6 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://addons/material_maker/engine/gen_image.gd" "path": "res://addons/material_maker/engine/gen_image.gd"
}, { }, {
"base": "Object",
"class": "MMGenLoader",
"language": "GDScript",
"path": "res://addons/material_maker/engine/loader.gd"
}, {
"base": "MMGenBase", "base": "MMGenBase",
"class": "MMGenMaterial", "class": "MMGenMaterial",
"language": "GDScript", "language": "GDScript",
@ -156,7 +151,6 @@ _global_script_class_icons={
"MMGenGraph": "", "MMGenGraph": "",
"MMGenIOs": "", "MMGenIOs": "",
"MMGenImage": "", "MMGenImage": "",
"MMGenLoader": "",
"MMGenMaterial": "", "MMGenMaterial": "",
"MMGenRemote": "", "MMGenRemote": "",
"MMGenRenderer": "", "MMGenRenderer": "",
@ -178,7 +172,7 @@ _global_script_class_icons={
config/name="Material Maker" config/name="Material Maker"
config/description="An open source, extensible procedural material generation tool" config/description="An open source, extensible procedural material generation tool"
run/main_scene="res://material_maker/main_window.tscn" run/main_scene="res://start.tscn"
config/use_custom_user_dir=true config/use_custom_user_dir=true
config/custom_user_dir_name="material_maker" config/custom_user_dir_name="material_maker"
boot_splash/image="res://rodz_labs_logo.png" boot_splash/image="res://rodz_labs_logo.png"
@ -189,6 +183,7 @@ config/release="0.8"
[autoload] [autoload]
mm_loader="*res://addons/material_maker/engine/loader.gd"
mm_renderer="*res://addons/material_maker/engine/renderer.tscn" mm_renderer="*res://addons/material_maker/engine/renderer.tscn"
[debug] [debug]

11
start.gd Normal file
View File

@ -0,0 +1,11 @@
extends Control
func _ready():
print("Loading...")
call_deferred("change_scene")
func change_scene():
if Directory.new().file_exists("res://material_maker/main_window.tscn"):
get_tree().change_scene("res://material_maker/main_window.tscn")
else:
get_tree().change_scene("res://demo/demo.tscn")

11
start.tscn Normal file
View File

@ -0,0 +1,11 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://start.gd" type="Script" id=1]
[node name="Start" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}