From 7c9b916a618a591b152bca66abf023d746e486a1 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 30 Mar 2020 14:58:57 +0200 Subject: [PATCH] Ported bake_mesh_array_uv and bake_mesh_array_uv into VoxelChunk. --- HEADS | 2 +- game/voxelman/world/TVVoxelChunk.gd | 82 ++--------------------------- 2 files changed, 5 insertions(+), 79 deletions(-) diff --git a/HEADS b/HEADS index 3529083f..0ad7b725 100644 --- a/HEADS +++ b/HEADS @@ -1 +1 @@ -{"engine": {"3.2": "da4eb7101d986af0ba6a15efaaed3dee77370d80", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "533c25e96fe0e5c46f68e6a532da6583cf86f4e2"}, "entity_spell_system": {"master": "0bc136962658731bac3e9e1b23bd9677f4dea9de"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "4a3c9836ffcc687134eb1ea6201bd1bfc0c3442b"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "ea3b34d972fb5f76474daabd7c1e192419811348"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "16d0ff1ed1e986202ed7f743d3c70666e0859b28"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "dc598c59322185032835f964db069964244e58bc"}} \ No newline at end of file +{"engine": {"3.2": "da4eb7101d986af0ba6a15efaaed3dee77370d80", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "533c25e96fe0e5c46f68e6a532da6583cf86f4e2"}, "entity_spell_system": {"master": "0bc136962658731bac3e9e1b23bd9677f4dea9de"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "ee03e42a5a6a27deb500a7d38b33730661cce58e"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "ea3b34d972fb5f76474daabd7c1e192419811348"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "16d0ff1ed1e986202ed7f743d3c70666e0859b28"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "dc598c59322185032835f964db069964244e58bc"}} \ No newline at end of file diff --git a/game/voxelman/world/TVVoxelChunk.gd b/game/voxelman/world/TVVoxelChunk.gd index 14fff553..b3cbcdce 100644 --- a/game/voxelman/world/TVVoxelChunk.gd +++ b/game/voxelman/world/TVVoxelChunk.gd @@ -293,7 +293,10 @@ func _build_phase(phase): VisualServer.mesh_surface_set_material(_lod_meshes[1], 0, library.get_material(2).get_rid()) if LOD_NUM >= 3: - arr = bake_mesh_array_uv(arr) + var mat : ShaderMaterial = library.get_material(0) as ShaderMaterial + var tex : Texture = mat.get_shader_param("texture_albedo") + + arr = bake_mesh_array_uv(arr, tex) arr[VisualServer.ARRAY_TEX_UV] = null VisualServer.mesh_add_surface_from_arrays(_lod_meshes[2], VisualServer.PRIMITIVE_TRIANGLES, arr) @@ -334,83 +337,6 @@ func _build_phase(phase): else: ._build_phase(phase) -func merge_mesh_array(arr : Array) -> Array: - var verts : PoolVector3Array = arr[VisualServer.ARRAY_VERTEX] - var normals : PoolVector3Array = arr[VisualServer.ARRAY_NORMAL] - var uvs : PoolVector2Array = arr[VisualServer.ARRAY_TEX_UV] - var colors : PoolColorArray = arr[VisualServer.ARRAY_COLOR] - var indices : PoolIntArray = arr[VisualServer.ARRAY_INDEX] - - var i : int = 0 - while i < verts.size(): - var v : Vector3 = verts[i] - - var equals : Array - for j in range(i + 1, verts.size()): - var vc : Vector3 = verts[j] - - if is_equal_approx(v.x, vc.x) and is_equal_approx(v.y, vc.y) and is_equal_approx(v.z, vc.z): - equals.push_back(j) - - for k in range(equals.size()): - var rem : int = equals[k] - var remk : int = rem - k - - verts.remove(remk) - normals.remove(remk) - uvs.remove(remk) - colors.remove(remk) - - for j in range(indices.size()): - var indx : int = indices[j] - - if indx == remk: - indices.set(j, i) - elif indx > remk: - indices.set(j, indx - 1) - - i += 1 - - arr[VisualServer.ARRAY_VERTEX] = verts - arr[VisualServer.ARRAY_NORMAL] = normals - arr[VisualServer.ARRAY_TEX_UV] = uvs - arr[VisualServer.ARRAY_COLOR] = colors - arr[VisualServer.ARRAY_INDEX] = indices - - return arr - -func bake_mesh_array_uv(arr : Array) -> Array: - var mat : ShaderMaterial = library.get_material(0) as ShaderMaterial - var tex : Texture = mat.get_shader_param("texture_albedo") - - if tex == null: - return arr - - var img : Image = tex.get_data() - - if img == null: - return arr - - var imgsize : Vector2 = img.get_size() - - var uvs : PoolVector2Array = arr[VisualServer.ARRAY_TEX_UV] - var colors : PoolColorArray = arr[VisualServer.ARRAY_COLOR] - - img.lock() - for i in range(uvs.size()): - var uv : Vector2 = uvs[i] - uv *= imgsize - - var c : Color = img.get_pixelv(uv) - - colors[i] = colors[i] * c * 0.7 - - img.unlock() - - arr[VisualServer.ARRAY_COLOR] = colors - - return arr - func _prop_added(prop): pass