Skip to content

Commit

Permalink
Improved new_paint_project dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Feb 3, 2024
1 parent f4d1880 commit c809baf
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 8 deletions.
6 changes: 3 additions & 3 deletions export_presets.cfg

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions material_maker/windows/new_painter/new_painter.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extends Window

signal return_status(status : Dictionary)

@export var mesh_material : Material

var mesh_filename = null
var project_filename = null
Expand All @@ -12,6 +13,14 @@ var project_filename = null
@onready var viewport : SubViewport = $VBoxContainer/Main/SubViewportContainer/SubViewport
@onready var error_label : Label = $VBoxContainer/Main/SubViewportContainer/Error


signal return_status(status : Dictionary)


func _ready():
if mesh_material:
mesh_instance.set_surface_override_material(0, mesh_material)

func _on_ViewportContainer_resized():
viewport.size = viewport_container.size

Expand Down Expand Up @@ -40,17 +49,25 @@ func set_mesh(file_name : String) -> void:
button_ok.disabled = false
# Initialise project file name
set_project(mesh_filename.get_basename()+".mmpp")
# Apply the mesh material
if mesh_material:
mesh_instance.set_surface_override_material(0, mesh_material)
# Center the mesh and move the camera to the whole object is visible
var aabb : AABB = mesh_instance.get_aabb()
mesh_instance.transform.origin = -aabb.position-0.5*aabb.size
var d : float = aabb.size.length()
camera.transform.origin.z = 0.8*d
print(d)
camera.transform.origin.z = 0.5*d+0.5
camera.near = 0.01
camera.far = d
# Show errors if any
var errors : PackedStringArray = PackedStringArray()
if mesh.get_surface_count() > 1:
errors.append("Mesh has several surfaces")
if mesh.surface_get_format(0) & ArrayMesh.ARRAY_FORMAT_TEX_UV == 0:
errors.append("Mesh does not have UVs")
error_label.text = "\n".join(errors)

else:
button_ok.disabled = true

Expand Down
61 changes: 58 additions & 3 deletions material_maker/windows/new_painter/new_painter.tscn
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
[gd_scene load_steps=7 format=3 uid="uid://cs6b524f2o614"]
[gd_scene load_steps=12 format=3 uid="uid://cs6b524f2o614"]

[ext_resource type="Script" path="res://material_maker/widgets/size_option_button/size_option_button.gd" id="1"]
[ext_resource type="Script" path="res://material_maker/windows/new_painter/new_painter.gd" id="2"]

[sub_resource type="Shader" id="Shader_g4gcc"]
code = "// NOTE: Shader automatically converted from Godot Engine 4.2.1.stable's StandardMaterial3D.

shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
uniform vec4 albedo1 : source_color;
uniform vec4 albedo2 : source_color;
uniform float roughness : hint_range(0,1);
uniform float specular;
uniform float metallic;
uniform float grid_size;

void vertex() {
}

void fragment() {
ivec2 grid = ivec2(UV*grid_size);
ALBEDO = (((grid.x&1)^(grid.y&1)) == 0) ? albedo1.rgb : albedo2.rgb;
METALLIC = metallic;
ROUGHNESS = roughness;
SPECULAR = specular;
}
"

[sub_resource type="ShaderMaterial" id="ShaderMaterial_5x24r"]
render_priority = 0
shader = SubResource("Shader_g4gcc")
shader_parameter/albedo1 = Color(1, 1, 1, 1)
shader_parameter/albedo2 = Color(0.866667, 0.866667, 0.866667, 1)
shader_parameter/roughness = 0.8
shader_parameter/specular = 0.5
shader_parameter/metallic = 0.0
shader_parameter/grid_size = 32.0

[sub_resource type="World3D" id="World3D_pmwks"]

[sub_resource type="BoxMesh" id="1"]

[sub_resource type="Animation" id="2"]
resource_name = "rotate"
length = 10.0
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
Expand All @@ -28,9 +63,21 @@ _data = {
"rotate": SubResource("2")
}

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_elmmt"]

[sub_resource type="Sky" id="Sky_stx2u"]
sky_material = SubResource("ProceduralSkyMaterial_elmmt")

[sub_resource type="Environment" id="Environment_gdou5"]
background_mode = 2
sky = SubResource("Sky_stx2u")
ambient_light_source = 3
ambient_light_color = Color(1, 1, 1, 1)

[node name="NewPainterWindow" type="Window"]
size = Vector2i(500, 300)
script = ExtResource("2")
mesh_material = SubResource("ShaderMaterial_5x24r")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
custom_minimum_size = Vector2(400, 250)
Expand Down Expand Up @@ -92,6 +139,7 @@ render_target_update_mode = 4
[node name="MeshPivot" type="Node3D" parent="VBoxContainer/Main/SubViewportContainer/SubViewport"]

[node name="MeshInstance3D" type="MeshInstance3D" parent="VBoxContainer/Main/SubViewportContainer/SubViewport/MeshPivot"]
cast_shadow = 0
mesh = SubResource("1")
skeleton = NodePath("../..")

Expand All @@ -105,8 +153,15 @@ autoplay = "rotate"
transform = Transform3D(1, 0, 0, 0, 0.866025, 0.5, 0, -0.5, 0.866025, 0, 0, 0)

[node name="Camera3D" type="Camera3D" parent="VBoxContainer/Main/SubViewportContainer/SubViewport/CameraPivot"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5)
far = 50.0
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2)
far = 50.65

[node name="WorldEnvironment" type="WorldEnvironment" parent="VBoxContainer/Main/SubViewportContainer/SubViewport"]
environment = SubResource("Environment_gdou5")

[node name="Light" type="DirectionalLight3D" parent="VBoxContainer/Main/SubViewportContainer/SubViewport"]
transform = Transform3D(0.707107, -0.5, 0.5, 0, 0.707107, 0.707107, -0.707107, -0.5, 0.5, 0, 1, 1)
light_bake_mode = 0

[node name="Error" type="Label" parent="VBoxContainer/Main/SubViewportContainer"]
layout_mode = 2
Expand Down

0 comments on commit c809baf

Please sign in to comment.