-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mesh map generation updates and adjency map prototype
- Loading branch information
Showing
8 changed files
with
163 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
addons/material_maker/map_generator/adjacency_dilate_compute.tres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[gd_resource type="Resource" script_class="TextResource" load_steps=2 format=3 uid="uid://bbqkm42mc6w1f"] | ||
|
||
[ext_resource type="Script" path="res://addons/material_maker/engine/text_resource.gd" id="1_wb5c8"] | ||
|
||
[resource] | ||
script = ExtResource("1_wb5c8") | ||
text = "#version 450 | ||
layout(local_size_x = @LOCAL_SIZE, local_size_y = 1, local_size_z = 1) in; | ||
@DECLARATIONS | ||
layout(set = 3, binding = 0, std140) restrict buffer MM { | ||
int mm_chunk_y; | ||
}; | ||
void main() { | ||
ivec2 pixel = ivec2(gl_GlobalInvocationID.xy)+ivec2(0, mm_chunk_y); | ||
vec2 image_size = imageSize(OUTPUT_TEXTURE); | ||
vec2 uv = (pixel+vec2(0.5, 0.5))/image_size; | ||
vec2 dilated_uv = texture(seams_map, uv).xy; | ||
vec4 color = mix(texture(tex, dilated_uv), vec4(uv, 0.0, 1.0), step(length(uv-dilated_uv), 0.001)); | ||
imageStore(OUTPUT_TEXTURE, pixel, color); | ||
} | ||
" |
80 changes: 80 additions & 0 deletions
80
addons/material_maker/map_generator/adjacency_generator.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
extends Object | ||
class_name MMAdjacencyGenerator | ||
|
||
|
||
# Code ported from: | ||
# https://github.com/blender/blender/blob/594f47ecd2d5367ca936cf6fc6ec8168c2b360d0/intern/cycles/blender/blender_mesh.cpp#L541 | ||
|
||
|
||
var progress : int = 0 | ||
var progress_total : int = 0 | ||
|
||
|
||
func get_progress() -> float: | ||
if progress_total == 0: | ||
return 0.0 | ||
return float(progress)/float(progress_total) | ||
|
||
func generate(mesh: Mesh) -> Mesh: | ||
var b_mesh : MeshDataTool = MeshDataTool.new() | ||
if not mesh is ArrayMesh: | ||
b_mesh.create_from_surface(mesh.create_outline(0.0), 0) | ||
else: | ||
b_mesh.create_from_surface(mesh, 0) | ||
|
||
progress = 0 | ||
progress_total = b_mesh.get_vertex_count() | ||
|
||
var num_verts = b_mesh.get_vertex_count() | ||
if (num_verts == 0): | ||
return Mesh.new() | ||
|
||
for i in b_mesh.get_vertex_count(): | ||
b_mesh.set_vertex_normal(i, Vector3(0, 0, 0)) | ||
|
||
var found_edges : Array[int] = [] | ||
for i in b_mesh.get_edge_count(): | ||
if b_mesh.get_edge_faces(i).size() > 1: | ||
continue | ||
if i in found_edges: | ||
continue | ||
var i0 : int = b_mesh.get_edge_vertex(i, 0) | ||
var i1 : int = b_mesh.get_edge_vertex(i, 1) | ||
var pi0 : Vector3 = b_mesh.get_vertex(i0) | ||
var pi1 : Vector3 = b_mesh.get_vertex(i1) | ||
print("Edge ", i, " (", pi0, ", ", pi1,")") | ||
for j in range(i+1, b_mesh.get_edge_count()): | ||
var j0 : int = b_mesh.get_edge_vertex(j, 0) | ||
var j1 : int = b_mesh.get_edge_vertex(j, 1) | ||
var pj0 = b_mesh.get_vertex(j0) | ||
var pj1 = b_mesh.get_vertex(j1) | ||
var uvi0 : Vector2 = b_mesh.get_vertex_uv(i0) | ||
var uvi1 : Vector2 = b_mesh.get_vertex_uv(i1) | ||
if pi0 == pj0 and pi1 == pj1: | ||
print(" Edge ", j, " matches") | ||
var uvj0 : Vector2 = b_mesh.get_vertex_uv(j0) | ||
var uvj1 : Vector2 = b_mesh.get_vertex_uv(j1) | ||
b_mesh.set_vertex_normal(i0, Vector3(uvj0.x, uvj0.y, 0)) | ||
b_mesh.set_vertex_normal(i1, Vector3(uvj1.x, uvj1.y, 0)) | ||
b_mesh.set_vertex_normal(j0, Vector3(uvi0.x, uvi0.y, 0)) | ||
b_mesh.set_vertex_normal(j1, Vector3(uvi1.x, uvi1.y, 0)) | ||
elif pi0 == pj1 and pi1 == pj0: | ||
print(" Edge ", j, " matches backwards") | ||
var uvj0 : Vector2 = b_mesh.get_vertex_uv(j0) | ||
var uvj1 : Vector2 = b_mesh.get_vertex_uv(j1) | ||
b_mesh.set_vertex_normal(i1, Vector3(uvj0.x, uvj0.y, 0)) | ||
b_mesh.set_vertex_normal(i0, Vector3(uvj1.x, uvj1.y, 0)) | ||
b_mesh.set_vertex_normal(j1, Vector3(uvi0.x, uvi0.y, 0)) | ||
b_mesh.set_vertex_normal(j0, Vector3(uvi1.x, uvi1.y, 0)) | ||
else: | ||
b_mesh.set_vertex_normal(i0, Vector3(uvi0.x, uvi0.y, 1)) | ||
b_mesh.set_vertex_normal(i1, Vector3(uvi1.x, uvi1.y, 1)) | ||
continue | ||
print(" Edge ", j, " (", pj0, ", ", pj1,")") | ||
found_edges.append(j) | ||
break | ||
|
||
var new_mesh : ArrayMesh = ArrayMesh.new() | ||
var _err := b_mesh.commit_to_surface(new_mesh) | ||
|
||
return new_mesh |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[gd_resource type="Resource" script_class="TextResource" load_steps=2 format=3 uid="uid://btn8qmquhmf05"] | ||
|
||
[ext_resource type="Script" path="res://addons/material_maker/engine/text_resource.gd" id="1_8tcbo"] | ||
|
||
[resource] | ||
script = ExtResource("1_8tcbo") | ||
text = "#version 450 | ||
layout(local_size_x = @LOCAL_SIZE, local_size_y = 1, local_size_z = 1) in; | ||
@DECLARATIONS | ||
layout(set = 3, binding = 0, std140) restrict buffer MM { | ||
int mm_chunk_y; | ||
}; | ||
void main() { | ||
ivec2 pixel = ivec2(gl_GlobalInvocationID.xy)+ivec2(0, mm_chunk_y); | ||
vec2 image_size = imageSize(OUTPUT_TEXTURE); | ||
vec2 uv = (pixel+vec2(0.5, 0.5))/image_size; | ||
vec4 color = texture(tex, texture(seams_map, uv).xy); | ||
imageStore(OUTPUT_TEXTURE, pixel, color); | ||
} | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters