From 8f71e087e743ad225412cf997310bad57e4c12d8 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 30 May 2020 14:04:37 +0200 Subject: [PATCH] Update mesh utils to get the MeshMerger, and the engine. The CharacterSkeletonGD now uses it. --- HEADS | 2 +- game/player/CharacterSkeletonGD.gd | 88 ++++++++---------------------- 2 files changed, 25 insertions(+), 65 deletions(-) diff --git a/HEADS b/HEADS index 8d2e898b..05704bed 100644 --- a/HEADS +++ b/HEADS @@ -1 +1 @@ -{"engine": {"3.2": "7ccb146a55edc41a9dd14c10efb8dc8f4b87f14e", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "97f10512f8832394389e1109154b8af34a2ef2c6"}, "entity_spell_system": {"master": "d063f8da2816e9e016112a2cc9a22a61c1f43d92"}, "ui_extensions": {"master": "6fe4f69fea8d71043b08d959b8085404c9c4fe47"}, "voxelman": {"master": "7c93cc8f52a60746aa43c0a78631baecbabfe6dc"}, "texture_packer": {"master": "e3047f7dfab861767c5295ea93d2f1404e8de66e"}, "fastnoise": {"master": "d0e3f1c759332cf0d9a5d7e0e71d0b0278310651"}, "mesh_data_resource": {"master": "3cc9f15f05be53380e20763efc0be753b621b8a2"}, "procedural_animations": {"master": "e4f048d67c171c34995763519e6d21bf40df29a7"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "f6d3d65cc6ce4dddfc68054164feec1f612ecd1f"}, "props": {"master": "b2bcb5ea6469b19298cd849c1232ddb5ad26f71c"}, "mesh_utils": {"master": "e4cf48e227ccd4b7a3194f218b32b52fe415ab5a"}, "broken_seals_module": {"master": "14c239fd8716988b837c2fcfe20fe7d9f11dd515"}, "thread_pool": {"master": "5093853b3f2cb430612bc153d0f020206cb6b624"}} \ No newline at end of file +{"engine": {"3.2": "f108037cbfdd010ca61954fcb0a341f754a7a9f0", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "97f10512f8832394389e1109154b8af34a2ef2c6"}, "entity_spell_system": {"master": "d063f8da2816e9e016112a2cc9a22a61c1f43d92"}, "ui_extensions": {"master": "6fe4f69fea8d71043b08d959b8085404c9c4fe47"}, "voxelman": {"master": "7c93cc8f52a60746aa43c0a78631baecbabfe6dc"}, "texture_packer": {"master": "e3047f7dfab861767c5295ea93d2f1404e8de66e"}, "fastnoise": {"master": "d0e3f1c759332cf0d9a5d7e0e71d0b0278310651"}, "mesh_data_resource": {"master": "3cc9f15f05be53380e20763efc0be753b621b8a2"}, "procedural_animations": {"master": "e4f048d67c171c34995763519e6d21bf40df29a7"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "f6d3d65cc6ce4dddfc68054164feec1f612ecd1f"}, "props": {"master": "b2bcb5ea6469b19298cd849c1232ddb5ad26f71c"}, "mesh_utils": {"master": "a841b0ece08ca5d323f9055d2916051ff97dd6f6"}, "broken_seals_module": {"master": "14c239fd8716988b837c2fcfe20fe7d9f11dd515"}, "thread_pool": {"master": "5093853b3f2cb430612bc153d0f020206cb6b624"}} \ No newline at end of file diff --git a/game/player/CharacterSkeletonGD.gd b/game/player/CharacterSkeletonGD.gd index 98b1a5fe..d43d10a4 100644 --- a/game/player/CharacterSkeletonGD.gd +++ b/game/player/CharacterSkeletonGD.gd @@ -187,14 +187,21 @@ func build_mesh(data) -> void: prepare_textures() meshes.clear() - - var vertices : PoolVector3Array = PoolVector3Array() - var normals : PoolVector3Array = PoolVector3Array() - var uvs : PoolVector2Array = PoolVector2Array() - var colors : PoolColorArray = PoolColorArray() - var indices : PoolIntArray = PoolIntArray() - var bone_array : PoolIntArray = PoolIntArray() - var weights_array : PoolRealArray = PoolRealArray() + + var mm : MeshMerger = MeshMerger.new() + mm.format = ArrayMesh.ARRAY_FORMAT_VERTEX | ArrayMesh.ARRAY_FORMAT_COLOR | ArrayMesh.ARRAY_FORMAT_BONES | ArrayMesh.ARRAY_FORMAT_INDEX | ArrayMesh.ARRAY_FORMAT_NORMAL | ArrayMesh.ARRAY_FORMAT_TEX_UV | ArrayMesh.ARRAY_FORMAT_WEIGHTS + var bones : PoolIntArray = PoolIntArray() + bones.resize(4) + bones[0] = 1 + bones[1] = 0 + bones[2] = 0 + bones[3] = 0 + var bonew : PoolRealArray = PoolRealArray() + bonew.resize(4) + bonew[0] = 1 + bonew[1] = 0 + bonew[2] = 0 + bonew[3] = 0 for skele_point in range(EntityEnums.SKELETON_POINTS_MAX): var bone_name : String = get_bone_name(skele_point) @@ -211,71 +218,24 @@ func build_mesh(data) -> void: if entry.entry.get_mesh(model_index) != null: var bt : Transform = skeleton.get_bone_global_pose(bone_idx) - var arrays : Array = entry.entry.get_mesh(model_index).array + var mdr : MeshDataResource = entry.entry.get_mesh(model_index) - var cvertices : PoolVector3Array = arrays[ArrayMesh.ARRAY_VERTEX] as PoolVector3Array - var cnormals : PoolVector3Array = arrays[ArrayMesh.ARRAY_NORMAL] as PoolVector3Array - var cuvs : PoolVector2Array = arrays[ArrayMesh.ARRAY_TEX_UV] as PoolVector2Array - var cindices : PoolIntArray = arrays[ArrayMesh.ARRAY_INDEX] as PoolIntArray - var ta : AtlasTexture = _textures[skele_point] - var tx : float = 0 - var ty : float = 0 - var tw : float = 1 - var th : float = 1 + var rect : Rect2 = Rect2(0, 0, 1, 1) if ta != null and _texture != null: var otw : float = _texture.get_width() var oth : float = _texture.get_height() - tx = ta.region.position.x / otw - ty = ta.region.position.y / oth - tw = ta.region.size.x / otw - th = ta.region.size.y / oth - - var orig_vert_size : int = vertices.size() - - vertices.resize(orig_vert_size + cvertices.size()) - normals.resize(orig_vert_size + cvertices.size()) - uvs.resize(orig_vert_size + cvertices.size()) - colors.resize(orig_vert_size+ cvertices.size()) - bone_array.resize(bone_array.size() + cvertices.size() * 4) - weights_array.resize(weights_array.size() + cvertices.size() * 4) - - for i in range(len(cvertices)): - normals[orig_vert_size + i] = bt.basis.xform(normals[i]) - - var uv : Vector2 = cuvs[i] - - uv.x = tw * uv.x + tx - uv.y = th * uv.y + ty - - uvs[orig_vert_size + i] = uv - - bone_array[(orig_vert_size + i) * 4] = bone_idx - weights_array[(orig_vert_size + i) * 4] = 1 - for j in range(1, 4): - bone_array[(orig_vert_size + i) * 4 + j] = 0 - weights_array[(orig_vert_size + i) * 4 + j] = 0 - - colors[orig_vert_size + i] = Color(0.7, 0.7, 0.7) - vertices[orig_vert_size + i] = bt.xform(cvertices[i]) - - var orig_indices_count = indices.size() - indices.resize(indices.size() + cindices.size()) - for i in range(len(cindices)): - indices[orig_indices_count + i] = orig_vert_size + cindices[i] + rect.position.x = ta.region.position.x / otw + rect.position.y = ta.region.position.y / oth + rect.size.x = ta.region.size.x / otw + rect.size.y = ta.region.size.y / oth + bones[0] = bone_idx + mm.add_mesh_data_resource_bone(mdr, bones, bonew, bt, rect) - var arr : Array = Array() - arr.resize(Mesh.ARRAY_MAX) - arr[Mesh.ARRAY_VERTEX] = vertices - arr[Mesh.ARRAY_NORMAL] = normals - arr[Mesh.ARRAY_TEX_UV] = uvs - arr[Mesh.ARRAY_COLOR] = colors - arr[Mesh.ARRAY_INDEX] = indices - arr[Mesh.ARRAY_BONES] = bone_array - arr[Mesh.ARRAY_WEIGHTS] = weights_array + var arr : Array = mm.build_mesh() var mesh : ArrayMesh = ArrayMesh.new() mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)