Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve 3D Preview Panel & Graph MenuBar #734

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f7e0832
Initial Commit on 3D preview menu
Jowan-Spooner Sep 29, 2024
b17bd1c
More 3D preview changes
Jowan-Spooner Oct 17, 2024
51ae47d
Improve 3D Panel Menus
Jowan-Spooner Jan 10, 2025
308245b
More improvements to 3D Panel Menus
Jowan-Spooner Jan 10, 2025
aa592c7
Finish 3D preview panel menus
Jowan-Spooner Jan 10, 2025
60c16a4
Small fix
Jowan-Spooner Jan 11, 2025
d5abc48
Merge remote-tracking branch 'RodZill4/master' into better-3D-preview
Jowan-Spooner Jan 11, 2025
c83a73f
Small fixes
Jowan-Spooner Jan 13, 2025
6aac8b1
Fixed problem with saving environments
RodZill4 Jan 23, 2025
6a93596
Moved camera controller (from environment editor) to a separate scene…
RodZill4 Jan 23, 2025
a930780
Updated painting too to use common camera control
RodZill4 Jan 26, 2025
433775c
Checked and tweaked camera control with gestures
RodZill4 Jan 26, 2025
ac1f0f2
Added optional mouse capture to the camera controller scene
RodZill4 Jan 29, 2025
56b32c3
Added chamfered cylinder, fixed chamfered cube in 3D preview
RodZill4 Feb 1, 2025
c7f6a30
Added preview selection (sphere, cylinder, cube and 3D preview) when …
RodZill4 Feb 1, 2025
11b0801
First commit of making the graph 3D preview work again
Jowan-Spooner Feb 12, 2025
2a21dd6
Small fixes
Jowan-Spooner Feb 12, 2025
ed59a09
Final fixes
Jowan-Spooner Feb 12, 2025
88cad5b
Merge remote-tracking branch 'RodZill4/master' into better-3D-preview
Jowan-Spooner Feb 12, 2025
a8d54db
Small fixes after merge
Jowan-Spooner Feb 12, 2025
f1c6df0
Fix theme merge
Jowan-Spooner Feb 12, 2025
7f6c9eb
Fix Export menu & cleanup scripts
Jowan-Spooner Feb 12, 2025
e2e0cba
More cleanup
Jowan-Spooner Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions addons/material_maker/loaders/obj_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@ static func load_obj_file(path : String) -> ArrayMesh:
if !ext.matchn("obj"):
print("given file isn't an OBJ mesh")
return null

var st := SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)

var mdlFile : FileAccess = FileAccess.open(path, FileAccess.READ)
if mdlFile == null:
print("cannot open file at path[", path,"]")
mdlFile.close()
#mdlFile.close()
return null
var newTriMsh : TriMesh = _import_obj(mdlFile)
mdlFile.close()

var hasTex := newTriMsh.uvs.size() > 0
var hasNrm := newTriMsh.normals.size() > 0

for i in newTriMsh.indices.size():
var triangle : Triangle = newTriMsh.indices[i]
if hasTex:
st.set_uv(newTriMsh.uvs[triangle.uv_id_0])
if hasNrm:
st.set_normal(newTriMsh.normals[triangle.nrm_id_0])
st.add_vertex(newTriMsh.vertices[triangle.id_0])

if hasTex:
st.set_uv(newTriMsh.uvs[triangle.uv_id_1])
if hasNrm:
st.set_normal(newTriMsh.normals[triangle.nrm_id_1])
st.add_vertex(newTriMsh.vertices[triangle.id_1])

if hasTex:
st.set_uv(newTriMsh.uvs[triangle.uv_id_2])
if hasNrm:
st.set_normal(newTriMsh.normals[triangle.nrm_id_2])
st.add_vertex(newTriMsh.vertices[triangle.id_2])

if !hasNrm:
st.generate_normals()
if hasTex:
st.generate_tangents()
var mdl : ArrayMesh = st.commit()

return mdl

static func _obj_rel_indice(indice : Vector3, cur_vArr_size : int) -> Vector3:
Expand All @@ -56,20 +56,20 @@ static func _obj_rel_indice(indice : Vector3, cur_vArr_size : int) -> Vector3:
output.x = indice.x - 1 if (indSign.x >= 0) else cur_vArr_size + indice.x
output.y = indice.y - 1 if (indSign.y >= 0) else cur_vArr_size + indice.y
output.z = indice.z - 1 if (indSign.z >= 0) else cur_vArr_size + indice.z

return output

static func _import_obj(mdlFile : FileAccess) -> TriMesh:
var newMsh := TriMesh.new()

while !mdlFile.eof_reached():
var mdlData := mdlFile.get_line()
if mdlData.begins_with("#"):
continue

var f2c = mdlData.substr(0, 2)
var lineData := mdlData.split(" ", false)

match f2c:
"v ":
var vertex := Vector3(
Expand All @@ -93,7 +93,7 @@ static func _import_obj(mdlFile : FileAccess) -> TriMesh:
newMsh.normals.push_back(normal)
"f ":
var misc = []

for i in lineData.size() - 1:
misc.push_back(lineData[i + 1].split("/"))
for i in misc.size() - 2:
Expand All @@ -102,45 +102,45 @@ static func _import_obj(mdlFile : FileAccess) -> TriMesh:
var vArr_size : int = newMsh.vertices.size()
var tArr_size : int = newMsh.uvs.size()
var nArr_size : int = newMsh.normals.size()

var faceIndices = Vector3(
int(misc[intVar][0]),
int(misc[intVar-1][0]),
int(misc[0][0]))
faceIndices = _obj_rel_indice(faceIndices, vArr_size)

var uvIndices : Vector3
if num >= 2:
uvIndices = Vector3(
int(misc[intVar][1]),
int(misc[intVar-1][1]),
int(misc[0][1]))
uvIndices = _obj_rel_indice(uvIndices, tArr_size)

var normIndices : Vector3
if num == 3:
normIndices = Vector3(
int(misc[intVar][2]),
int(misc[intVar-1][2]),
int(misc[0][2]))
normIndices = _obj_rel_indice(normIndices, nArr_size)

var triangle := Triangle.new()

triangle.id_0 = int(faceIndices.x)
triangle.id_1 = int(faceIndices.y)
triangle.id_2 = int(faceIndices.z)

triangle.uv_id_0 = int(uvIndices.x)
triangle.uv_id_1 = int(uvIndices.y)
triangle.uv_id_2 = int(uvIndices.z)

triangle.nrm_id_0 = int(normIndices.x)
triangle.nrm_id_1 = int(normIndices.y)
triangle.nrm_id_2 = int(normIndices.z)

newMsh.indices.push_back(triangle)

return newMsh

class TriMesh:
Expand Down
14 changes: 8 additions & 6 deletions material_maker/environments/hdris/moonless_golf_1k.hdr.import
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://bqre7xkdgb655"
path="res://.godot/imported/moonless_golf_1k.hdr-9cc5420e458979fa0268bbd265e3a765.ctex"
path.bptc="res://.godot/imported/moonless_golf_1k.hdr-9cc5420e458979fa0268bbd265e3a765.bptc.ctex"
path.astc="res://.godot/imported/moonless_golf_1k.hdr-9cc5420e458979fa0268bbd265e3a765.astc.ctex"
metadata={
"vram_texture": false
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}

[deps]

source_file="res://material_maker/environments/hdris/moonless_golf_1k.hdr"
dest_files=["res://.godot/imported/moonless_golf_1k.hdr-9cc5420e458979fa0268bbd265e3a765.ctex"]
dest_files=["res://.godot/imported/moonless_golf_1k.hdr-9cc5420e458979fa0268bbd265e3a765.bptc.ctex", "res://.godot/imported/moonless_golf_1k.hdr-9cc5420e458979fa0268bbd265e3a765.astc.ctex"]

[params]

compress/mode=0
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
Expand All @@ -31,4 +33,4 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
detect_3d/compress_to=0
2 changes: 2 additions & 0 deletions material_maker/fonts/DroidSansFallback.ttf.import
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ dest_files=["res://.godot/imported/DroidSansFallback.ttf-e30b9821d3711bc136081c8
Rendering=null
antialiasing=1
generate_mipmaps=true
disable_embedded_bitmaps=true
multichannel_signed_distance_field=true
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=true
hinting=1
subpixel_positioning=1
keep_rounding_remainders=true
oversampling=0.0
Fallbacks=null
fallbacks=[]
Expand Down
2 changes: 2 additions & 0 deletions material_maker/fonts/DroidSansJapanese.ttf.import
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ dest_files=["res://.godot/imported/DroidSansJapanese.ttf-22552d3c449e7b4b8df49e5
Rendering=null
antialiasing=1
generate_mipmaps=true
disable_embedded_bitmaps=true
multichannel_signed_distance_field=true
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=true
hinting=1
subpixel_positioning=1
keep_rounding_remainders=true
oversampling=0.0
Fallbacks=null
fallbacks=[]
Expand Down
2 changes: 2 additions & 0 deletions material_maker/fonts/hack.ttf.import
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ dest_files=["res://.godot/imported/hack.ttf-fe4b1180e3e576ff1eae0eea48354ae0.fon
Rendering=null
antialiasing=1
generate_mipmaps=true
disable_embedded_bitmaps=true
multichannel_signed_distance_field=true
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=true
hinting=1
subpixel_positioning=1
keep_rounding_remainders=true
oversampling=0.0
Fallbacks=null
fallbacks=[]
Expand Down
2 changes: 2 additions & 0 deletions material_maker/fonts/vegur_regular.otf.import
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ dest_files=["res://.godot/imported/vegur_regular.otf-b27f03fecf76f08bba1ffc7626d
Rendering=null
antialiasing=1
generate_mipmaps=true
disable_embedded_bitmaps=true
multichannel_signed_distance_field=true
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=true
hinting=1
subpixel_positioning=1
keep_rounding_remainders=true
oversampling=0.0
Fallbacks=null
fallbacks=[]
Expand Down
21 changes: 21 additions & 0 deletions material_maker/globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,24 @@ static func propagate_shortcuts(control : Control, event : InputEvent):
if not control.shortcut_context.get_global_rect().has_point(control.get_global_mouse_position()):
return
do_propagate_shortcuts(control, event)


func interpret_file_name(file_name: String, path:="", file_extension:="",additional_identifiers:={}) -> String:
for i in additional_identifiers:
file_name = file_name.replace(i, additional_identifiers[i])

var current_graph: MMGraphEdit = get_node("/root/MainWindow").get_current_graph_edit()
if current_graph.save_path:
file_name = file_name.replace("$project", current_graph.save_path.get_file().trim_suffix("."+current_graph.save_path.get_extension()))
else:
file_name = file_name.replace("$project", "unnamed_project")

if "$idx" in file_name:
if path:
var idx := 1
while FileAccess.file_exists(path.path_join(file_name).replace("$idx", str(idx).pad_zeros(2))):
idx += 1
file_name = file_name.replace("$idx", str(idx).pad_zeros(2))
else:
file_name = file_name.replace("$idx", str(1).pad_zeros(2))
return file_name
4 changes: 2 additions & 2 deletions material_maker/globals.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://vt76awmi7ix7"]

[ext_resource type="Script" path="res://material_maker/globals.gd" id="1"]
[ext_resource type="Script" path="res://material_maker/globals_menu_manager.gd" id="2"]
[ext_resource type="Script" uid="uid://cllqlhj3x3jj7" path="res://material_maker/globals.gd" id="1"]
[ext_resource type="Script" uid="uid://c8lpv0jfyajsp" path="res://material_maker/globals_menu_manager.gd" id="2"]

[node name="Globals" type="Node"]
script = ExtResource("1")
Expand Down
14 changes: 6 additions & 8 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,10 @@ func _on_PaintEnvironment_id_pressed(id) -> void:
paint.set_environment(id)


func environment_editor() -> void:
add_child(load("res://material_maker/windows/environment_editor/environment_editor.tscn").instantiate())
func environment_editor() -> Node:
var env_editor : Node = load("res://material_maker/windows/environment_editor/environment_editor.tscn").instantiate()
add_child(env_editor)
return env_editor

# -----------------------------------------------------------------------
# Help menu
Expand Down Expand Up @@ -1025,7 +1027,7 @@ func update_preview_2d() -> void:
projects_panel.preview_2d_background.set_generator(generator, output_index)

var current_gen_material = null
func update_preview_3d(previews : Array, _sequential = false) -> void:
func update_preview_3d(previews : Array) -> void:
var graph_edit : MMGraphEdit = get_current_graph_edit()
var gen_material = null
if graph_edit != null and graph_edit.top_generator != null and graph_edit.top_generator.has_node("Material"):
Expand All @@ -1038,7 +1040,7 @@ func update_preview_3d(previews : Array, _sequential = false) -> void:
var materials : Array[ShaderMaterial] = []
for p in previews:
materials.append_array(p.get_materials())
current_gen_material.set_3d_previews(materials)
await current_gen_material.set_3d_previews(materials)

func on_preview_changed(graph) -> void:
if graph == get_current_graph_edit():
Expand All @@ -1053,16 +1055,12 @@ func _on_Projects_tab_changed(_tab) -> void:
var new_graph_edit = null
if new_tab is GraphEdit:
new_graph_edit = new_tab
$VBoxContainer/Layout/FlexibleLayout/Main/BackgroundPreviews.show()
$VBoxContainer/Layout/FlexibleLayout/Main/PreviewUI.show()
set_current_mode("material")
if current_mesh and new_graph_edit.top_generator:
new_graph_edit.top_generator.set_current_mesh(current_mesh)
else:
if new_tab.has_method("get_graph_edit"):
new_graph_edit = new_tab.get_graph_edit()
$VBoxContainer/Layout/FlexibleLayout/Main/BackgroundPreviews.hide()
$VBoxContainer/Layout/FlexibleLayout/Main/PreviewUI.hide()
set_current_mode("paint")
current_tab = new_tab
if new_graph_edit != null:
Expand Down
Loading