mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Updated import, preview and slider widgets
This commit is contained in:
parent
b861cf446d
commit
8c06cd3aa8
@ -7,6 +7,7 @@ Base class for texture generators, that defines their API
|
||||
"""
|
||||
|
||||
signal parameter_changed
|
||||
signal update_textures
|
||||
|
||||
class InputPort:
|
||||
var generator : MMGenBase = null
|
||||
|
@ -25,6 +25,12 @@ const ADDON_TEXTURE_LIST = [
|
||||
{ port=6, texture="depth_texture" }
|
||||
]
|
||||
|
||||
func _ready():
|
||||
texture_list = TEXTURE_LIST
|
||||
for t in texture_list:
|
||||
generated_textures[t.texture] = null
|
||||
material = SpatialMaterial.new()
|
||||
|
||||
func get_type():
|
||||
return "material"
|
||||
|
||||
@ -53,23 +59,8 @@ func get_input_defs():
|
||||
{ name="depth_texture", label="", type="f" }
|
||||
]
|
||||
|
||||
func _ready():
|
||||
texture_list = TEXTURE_LIST
|
||||
if Engine.editor_hint:
|
||||
texture_list = ADDON_TEXTURE_LIST
|
||||
for t in texture_list:
|
||||
generated_textures[t.texture] = null
|
||||
material = SpatialMaterial.new()
|
||||
|
||||
func generate_material(renderer : MMGenRenderer):
|
||||
var source = get_source(0)
|
||||
if source != null:
|
||||
var status = source.generator.render(source.output_index, renderer, 512)
|
||||
while status is GDScriptFunctionState:
|
||||
status = yield(status, "completed")
|
||||
renderer.get_texture().get_data().save_png("res://test.png")
|
||||
material.albedo_texture = load("res://test.png")
|
||||
return material
|
||||
func source_changed(input_index : int):
|
||||
emit_signal("update_textures")
|
||||
|
||||
func render_textures(renderer : MMGenRenderer):
|
||||
for t in texture_list:
|
||||
@ -77,7 +68,7 @@ func render_textures(renderer : MMGenRenderer):
|
||||
var source = get_source(t.port)
|
||||
var texture = null
|
||||
if source != null:
|
||||
var status = source.generator.render(source.output_index, renderer, 512)
|
||||
var status = source.generator.render(source.output_index, renderer, 1024)
|
||||
while status is GDScriptFunctionState:
|
||||
status = yield(status, "completed")
|
||||
texture = ImageTexture.new()
|
||||
@ -104,7 +95,7 @@ func update_spatial_material(m, file_prefix = null):
|
||||
m.albedo_texture = get_generated_texture("albedo", file_prefix)
|
||||
m.metallic = parameters.metallic
|
||||
m.roughness = parameters.roughness
|
||||
if Engine.editor_hint:
|
||||
if false:
|
||||
texture = get_generated_texture("mrao", file_prefix)
|
||||
m.metallic_texture = texture
|
||||
m.metallic_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_RED
|
||||
@ -126,7 +117,7 @@ func update_spatial_material(m, file_prefix = null):
|
||||
m.normal_texture = texture
|
||||
else:
|
||||
m.normal_enabled = false
|
||||
if Engine.editor_hint:
|
||||
if false:
|
||||
if (generated_textures.mrao.mask & (1 << 2)) != 0:
|
||||
m.ao_enabled = true
|
||||
m.ao_light_affect = parameters.ao_light_affect
|
||||
@ -151,22 +142,21 @@ func update_spatial_material(m, file_prefix = null):
|
||||
else:
|
||||
m.depth_enabled = false
|
||||
|
||||
func export_textures(prefix, size = null):
|
||||
if size == null:
|
||||
size = int(pow(2, 8+parameters.resolution))
|
||||
func export_textures(prefix, editor_interface = null):
|
||||
for t in texture_list:
|
||||
var texture = generated_textures[t.texture]
|
||||
if texture != null:
|
||||
var image = texture.get_data()
|
||||
image.save_png("%s_%s.png" % [ prefix, t.texture ])
|
||||
if Engine.editor_hint:
|
||||
var resource_filesystem = get_parent().editor_interface.get_resource_filesystem()
|
||||
var resource_filesystem = editor_interface.get_resource_filesystem()
|
||||
resource_filesystem.scan()
|
||||
yield(resource_filesystem, "filesystem_changed")
|
||||
var new_material = SpatialMaterial.new()
|
||||
update_spatial_material(new_material, prefix)
|
||||
ResourceSaver.save("%s.tres" % [ prefix ], new_material)
|
||||
resource_filesystem.scan()
|
||||
return new_material
|
||||
|
||||
func _serialize(data):
|
||||
return data
|
||||
|
@ -363,3 +363,9 @@ func _on_Projects_tab_changed(tab):
|
||||
new_tab.connect("node_selected", self, "update_preview_2d")
|
||||
current_tab = new_tab
|
||||
update_preview()
|
||||
|
||||
func _on_Preview_show_background_preview(v):
|
||||
var pv = $VBoxContainer/HBoxContainer/VBoxContainer/Preview/MaterialPreview
|
||||
var bgpv = $VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview/Viewport
|
||||
bgpv.world = pv.find_world()
|
||||
$VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview.visible = v
|
||||
|
@ -100,7 +100,7 @@ handle_input_locally = false
|
||||
render_target_update_mode = 0
|
||||
|
||||
[node name="Camera" type="Camera" parent="VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview/Viewport"]
|
||||
transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 2.24976, 2.68116 )
|
||||
transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 2.24976, 2.68115 )
|
||||
current = true
|
||||
|
||||
[node name="Projects" type="Panel" parent="VBoxContainer/HBoxContainer/ProjectsPane"]
|
||||
@ -123,7 +123,7 @@ debug_path = null
|
||||
[node name="NodeFactory" type="Node" parent="."]
|
||||
script = ExtResource( 6 )
|
||||
[connection signal="need_update" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="." method="update_preview_3d"]
|
||||
[connection signal="show_background_preview" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview" method="set_visible"]
|
||||
[connection signal="show_background_preview" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="." method="_on_Preview_show_background_preview"]
|
||||
[connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="." method="new_material"]
|
||||
[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects" method="_on_Projects_resized"]
|
||||
[connection signal="tab_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="." method="_on_Projects_tab_changed"]
|
||||
|
@ -102,7 +102,7 @@ func create_parameter_control(p : Dictionary):
|
||||
if p.has("widget") and p.widget == "spinbox":
|
||||
control = SpinBox.new()
|
||||
else:
|
||||
control = HSlider.new()
|
||||
control = preload("res://addons/material_maker/widgets/hslider.tscn").instance()
|
||||
control.min_value = p.min
|
||||
control.max_value = p.max
|
||||
control.step = 0.005 if !p.has("step") else p.step
|
||||
|
@ -49,8 +49,12 @@ func close_material_maker():
|
||||
func generate_material(ptex_filename: String) -> Material:
|
||||
var generator = MMGenLoader.load_gen(ptex_filename)
|
||||
add_child(generator)
|
||||
var material = generator.get_node("Material")
|
||||
var return_value = material.generate_material(renderer)
|
||||
while return_value is GDScriptFunctionState:
|
||||
return_value = yield(return_value, "completed")
|
||||
return return_value
|
||||
if generator.has_node("Material"):
|
||||
var gen_material = generator.get_node("Material")
|
||||
print(renderer)
|
||||
var return_value = gen_material.render_textures(renderer)
|
||||
while return_value is GDScriptFunctionState:
|
||||
return_value = yield(return_value, "completed")
|
||||
var prefix = ptex_filename.left(ptex_filename.rfind("."))
|
||||
return gen_material.export_textures(prefix, get_editor_interface())
|
||||
return null
|
||||
|
@ -7,7 +7,7 @@ const ENVIRONMENTS = [
|
||||
"experiment", "lobby", "night", "park", "schelde"
|
||||
]
|
||||
|
||||
onready var objects = $MaterialPreview/Objects
|
||||
onready var objects = $MaterialPreview/Preview3d/Objects
|
||||
onready var current_object = objects.get_child(0)
|
||||
|
||||
signal need_update
|
||||
@ -20,14 +20,14 @@ func _ready():
|
||||
var m = o.get_surface_material(0)
|
||||
o.set_surface_material(0, m.duplicate())
|
||||
$Config/Model.add_item(o.name)
|
||||
$ObjectRotate.play("rotate")
|
||||
$MaterialPreview/Preview3d/ObjectRotate.play("rotate")
|
||||
$Preview2D.material = $Preview2D.material.duplicate(true)
|
||||
_on_Environment_item_selected($Config/Environment.selected)
|
||||
_on_Preview_resized()
|
||||
$MaterialPreview/CameraPivot/Camera/RemoteTransform.set_remote_node("../../../../../../ProjectsPane/BackgroundPreview/Viewport/Camera")
|
||||
$MaterialPreview/Preview3d/CameraPivot/Camera/RemoteTransform.set_remote_node("../../../../../../../ProjectsPane/BackgroundPreview/Viewport/Camera")
|
||||
|
||||
func _on_Environment_item_selected(id):
|
||||
$MaterialPreview/WorldEnvironment.environment.background_sky.panorama = load("res://addons/material_maker/panoramas/"+ENVIRONMENTS[id]+".hdr")
|
||||
$MaterialPreview/Preview3d/WorldEnvironment.environment.background_sky.panorama = load("res://addons/material_maker/panoramas/"+ENVIRONMENTS[id]+".hdr")
|
||||
|
||||
func _on_Model_item_selected(id):
|
||||
current_object.visible = false
|
||||
@ -60,8 +60,8 @@ func _on_Button_toggled(button_pressed):
|
||||
|
||||
func on_gui_input(event):
|
||||
if event is InputEventMouseButton:
|
||||
$ObjectRotate.stop()
|
||||
$MaterialPreview/Preview3d/ObjectRotate.stop()
|
||||
elif event is InputEventMouseMotion:
|
||||
if event.button_mask != 0:
|
||||
$MaterialPreview/Objects.rotation.y += 0.01*event.relative.x
|
||||
$MaterialPreview/CameraPivot.rotation.x -= 0.01*event.relative.y
|
||||
$MaterialPreview/Preview3d/Objects.rotation.y += 0.01*event.relative.x
|
||||
$MaterialPreview/Preview3d/CameraPivot.rotation.x -= 0.01*event.relative.y
|
||||
|
@ -1,33 +1,11 @@
|
||||
[gd_scene load_steps=9 format=2]
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://addons/material_maker/preview.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/material_maker/preview_objects.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://addons/material_maker/panoramas/park.hdr" type="Texture" id=3]
|
||||
[ext_resource path="res://addons/material_maker/preview_3d.tscn" type="PackedScene" id=2]
|
||||
|
||||
[sub_resource type="Animation" id=1]
|
||||
loop = true
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("MaterialPreview/Objects: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, 1 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ]
|
||||
}
|
||||
[sub_resource type="World" id=4]
|
||||
|
||||
[sub_resource type="PanoramaSky" id=2]
|
||||
radiance_size = 2
|
||||
panorama = ExtResource( 3 )
|
||||
|
||||
[sub_resource type="Environment" id=3]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 2 )
|
||||
|
||||
[sub_resource type="Shader" id=4]
|
||||
[sub_resource type="Shader" id=2]
|
||||
code = "shader_type canvas_item;
|
||||
|
||||
uniform sampler2D tex;
|
||||
@ -36,8 +14,8 @@ void fragment() {
|
||||
COLOR = texture(tex, UV);
|
||||
}"
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=5]
|
||||
shader = SubResource( 4 )
|
||||
[sub_resource type="ShaderMaterial" id=3]
|
||||
shader = SubResource( 2 )
|
||||
|
||||
[node name="Preview" type="ViewportContainer"]
|
||||
anchor_left = 1.0
|
||||
@ -52,36 +30,15 @@ size_flags_vertical = 3
|
||||
stretch = true
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="ObjectRotate" type="AnimationPlayer" parent="."]
|
||||
autoplay = "rotate"
|
||||
playback_speed = 0.1
|
||||
anims/rotate = SubResource( 1 )
|
||||
|
||||
[node name="MaterialPreview" type="Viewport" parent="."]
|
||||
size = Vector2( 395, 370 )
|
||||
own_world = true
|
||||
world = SubResource( 4 )
|
||||
handle_input_locally = false
|
||||
render_target_clear_mode = 1
|
||||
render_target_update_mode = 3
|
||||
|
||||
[node name="Objects" parent="MaterialPreview" instance=ExtResource( 2 )]
|
||||
transform = Transform( 0.768253, 0, -0.640147, 0, 1, 0, 0.640147, 0, 0.768253, 0, 0, 0 )
|
||||
|
||||
[node name="OmniLight" type="OmniLight" parent="MaterialPreview"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.04729, 1.80471, -2.51024 )
|
||||
omni_range = 6.46518
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="MaterialPreview"]
|
||||
environment = SubResource( 3 )
|
||||
|
||||
[node name="CameraPivot" type="Spatial" parent="MaterialPreview"]
|
||||
transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 0, 0 )
|
||||
|
||||
[node name="Camera" type="Camera" parent="MaterialPreview/CameraPivot"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.5 )
|
||||
environment = SubResource( 3 )
|
||||
current = true
|
||||
|
||||
[node name="RemoteTransform" type="RemoteTransform" parent="MaterialPreview/CameraPivot/Camera"]
|
||||
[node name="Preview3d" parent="MaterialPreview" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="Config" type="HBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
@ -115,7 +72,7 @@ toggle_mode = true
|
||||
text = "O"
|
||||
|
||||
[node name="Preview2D" type="ColorRect" parent="."]
|
||||
material = SubResource( 5 )
|
||||
material = SubResource( 3 )
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_top = -64.0
|
||||
|
55
addons/material_maker/preview_3d.tscn
Normal file
55
addons/material_maker/preview_3d.tscn
Normal file
@ -0,0 +1,55 @@
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://addons/material_maker/preview_objects.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/material_maker/panoramas/park.hdr" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="PanoramaSky" id=1]
|
||||
radiance_size = 2
|
||||
panorama = ExtResource( 2 )
|
||||
|
||||
[sub_resource type="Environment" id=2]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
|
||||
[sub_resource type="Animation" id=3]
|
||||
loop = true
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("MaterialPreview/Spatial/Objects: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, 1 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ]
|
||||
}
|
||||
|
||||
[node name="Preview3d" type="Spatial"]
|
||||
|
||||
[node name="Objects" type="Spatial" parent="." instance=ExtResource( 1 )]
|
||||
transform = Transform( -0.799512, 0, 0.60065, 0, 1, 0, -0.60065, 0, -0.799512, 0, 0, 0 )
|
||||
|
||||
[node name="OmniLight" type="OmniLight" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.345557, 2.74973, -3.97441 )
|
||||
omni_range = 6.46518
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource( 2 )
|
||||
|
||||
[node name="CameraPivot" type="Spatial" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 0, 0 )
|
||||
|
||||
[node name="Camera" type="Camera" parent="CameraPivot"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.5 )
|
||||
environment = SubResource( 2 )
|
||||
current = true
|
||||
|
||||
[node name="RemoteTransform" type="RemoteTransform" parent="CameraPivot/Camera"]
|
||||
remote_path = NodePath("../../../../../../ProjectsPane/BackgroundPreview/Viewport/Camera")
|
||||
|
||||
[node name="ObjectRotate" type="AnimationPlayer" parent="."]
|
||||
autoplay = "rotate"
|
||||
playback_speed = 0.1
|
||||
anims/rotate = SubResource( 3 )
|
3
addons/material_maker/preview_world.tres
Normal file
3
addons/material_maker/preview_world.tres
Normal file
@ -0,0 +1,3 @@
|
||||
[gd_resource type="World" format=2]
|
||||
|
||||
[resource]
|
12
addons/material_maker/widgets/hslider.gd
Normal file
12
addons/material_maker/widgets/hslider.gd
Normal file
@ -0,0 +1,12 @@
|
||||
tool
|
||||
extends HSlider
|
||||
|
||||
func _ready():
|
||||
update_label(value)
|
||||
|
||||
func set_value(v):
|
||||
.set_value(v)
|
||||
update_label(v)
|
||||
|
||||
func update_label(v):
|
||||
$Label.text = "%f" % v
|
23
addons/material_maker/widgets/hslider.tscn
Normal file
23
addons/material_maker/widgets/hslider.tscn
Normal file
@ -0,0 +1,23 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/material_maker/widgets/hslider.gd" type="Script" id=1]
|
||||
|
||||
[node name="MMHSlider" type="HSlider"]
|
||||
margin_left = 1.0
|
||||
margin_top = 1.0
|
||||
margin_right = 134.0
|
||||
margin_bottom = 17.0
|
||||
ticks_on_borders = true
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
self_modulate = Color( 1, 1, 1, 0.501961 )
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
text = "100"
|
||||
align = 1
|
||||
valign = 1
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
[connection signal="value_changed" from="." to="." method="update_label"]
|
Loading…
Reference in New Issue
Block a user