Skip to content

Commit

Permalink
Fixed brush thumbnail generation
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Oct 12, 2024
1 parent 728371c commit 9cebbd1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ func add_brush_to_library(index) -> void:
# Create thumbnail
var result = await get_current_project().get_brush_preview()
var image : Image = Image.new()
image.copy_from(result.get_data())
image.copy_from(result.get_image())
image.resize(32, 32)
brush_library_manager.add_item_to_library(index, status.text, image, data)

Expand Down
20 changes: 11 additions & 9 deletions material_maker/panels/paint/paint.gd
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ func _ready():
image.fill(Color(1, 1, 1))
mask_texture.set_image(image)
mask.set_texture(mask_texture)

_on_Brush_value_changed(%BrushSize.value, "brush_size")
_on_Brush_value_changed(%BrushHardness.value, "brush_hardness")

func update_tab_title() -> void:
if !get_parent().has_method("set_tab_title"):
Expand Down Expand Up @@ -198,18 +199,13 @@ func init_project(mesh : Mesh, mesh_file_path : String, resolution : int, projec
mi.mesh = mesh
layers.add_layer()
model_path = mesh_file_path
set_object(mi)
set_object(mi, true)
set_project_path(project_file_path)
initialize_layers_history()

func set_object(o):
func set_object(o, init_material : bool = false):
object_name = o.name
set_project_path(null)
var mat = o.get_surface_override_material(0)
if mat == null:
mat = o.mesh.surface_get_material(0)
if mat == null:
mat = StandardMaterial3D.new()
preview_material = StandardMaterial3D.new()
preview_material.albedo_texture = layers.get_albedo_texture()
#preview_material.albedo_texture.flags = Texture2D.FLAGS_DEFAULT
Expand Down Expand Up @@ -245,7 +241,13 @@ func set_object(o):
# Set the painter target mesh
painter.set_mesh(o.mesh)
update_view()
painter.init_textures(mat)
if init_material:
var mat = o.get_surface_override_material(0)
if mat == null:
mat = o.mesh.surface_get_material(0)
if mat == null:
mat = StandardMaterial3D.new()
painter.init_textures(mat)

func get_settings() -> Dictionary:
return settings
Expand Down
4 changes: 1 addition & 3 deletions material_maker/tools/painter/brush_preview.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ func set_brush(brush) -> Texture2D:
painter.set_brush_node(brush, false)
await get_tree().process_frame
await get_tree().process_frame
painter.init_textures(background_material)
await get_tree().process_frame
await get_tree().process_frame
await painter.init_textures(background_material)
await get_tree().process_frame
await get_tree().process_frame
var paint_parameters : Dictionary = {
Expand Down
4 changes: 3 additions & 1 deletion material_maker/tools/painter/brush_preview.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ background_material = SubResource("1")
[node name="Painter" parent="." instance=ExtResource("1")]

[node name="SubViewport" type="SubViewport" parent="."]
own_world_3d = true
transparent_bg = true
handle_input_locally = false
render_target_update_mode = 0
Expand All @@ -69,8 +70,9 @@ render_target_update_mode = 0
mesh = SubResource("5")

[node name="Camera3D" type="Camera3D" parent="SubViewport"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 1.8, 0, 0)
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 2, 0, 0)
environment = SubResource("8")
fov = 30.0

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="SubViewport"]
transform = Transform3D(0.5, -0.224144, 0.836516, 0, 0.965926, 0.258819, -0.866025, -0.12941, 0.482963, 0, 0, 0)
Expand Down
16 changes: 8 additions & 8 deletions material_maker/tools/painter/painter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -268,22 +268,22 @@ func init_do_texture_channels(depth : float = 1.0, depth_texture : Texture2D = n
# do_viewport.init_channels(depth_texture, calculate_mask(depth, StandardMaterial3D.TEXTURE_CHANNEL_RED), occlusion_texture, calculate_mask(occlusion, occlusion_channel), null, Color(1.0, 0.0, 0.0, 0.0), null, Color(1.0, 0.0, 0.0, 0.0))

func init_textures(m : StandardMaterial3D):
init_rgba_texture(CHANNEL_ALBEDO, m.albedo_color, m.albedo_texture)
init_mr_texture_channels(m.metallic, m.metallic_texture, m.metallic_texture_channel, m.roughness, m.roughness_texture, m.roughness_texture_channel)
await init_rgba_texture(CHANNEL_ALBEDO, m.albedo_color, m.albedo_texture)
await init_mr_texture_channels(m.metallic, m.metallic_texture, m.metallic_texture_channel, m.roughness, m.roughness_texture, m.roughness_texture_channel)
if m.emission_enabled:
var emission_color = m.emission
emission_color.a = 1.0
init_rgba_texture(CHANNEL_EMISSION, emission_color, m.emission_texture)
await init_rgba_texture(CHANNEL_EMISSION, emission_color, m.emission_texture)
else:
init_rgba_texture(CHANNEL_EMISSION, Color(0.0, 0.0, 0.0), null)
await init_rgba_texture(CHANNEL_EMISSION, Color(0.0, 0.0, 0.0), null)
if m.normal_enabled:
init_rgba_texture(CHANNEL_NORMAL, Color(1.0, 1.0, 1.0), m.n_texture)
await init_rgba_texture(CHANNEL_NORMAL, Color(1.0, 1.0, 1.0), m.n_texture)
else:
init_rgba_texture(CHANNEL_NORMAL, Color(0.5, 0.5, 0.0), null)
await init_rgba_texture(CHANNEL_NORMAL, Color(0.5, 0.5, 0.0), null)
if m.heightmap_enabled or m.ao_enabled:
init_do_texture_channels(m.depth_scale if m.heightmap_enabled else 0.0, m.depth_texture, m.ao_light_affect if m.ao_enabled else 1.0, m.ao_texture, m.ao_texture_channel)
await init_do_texture_channels(m.depth_scale if m.heightmap_enabled else 0.0, m.depth_texture, m.ao_light_affect if m.ao_enabled else 1.0, m.ao_texture, m.ao_texture_channel)
else:
init_rgba_texture(CHANNEL_DO, Color(0.0, 1.0, 0.0, 0.0), null)
await init_rgba_texture(CHANNEL_DO, Color(0.0, 1.0, 0.0, 0.0), null)

func set_texture_size(s : float):
if texture_size != s:
Expand Down

0 comments on commit 9cebbd1

Please sign in to comment.