From 3e33975e2a876d2ebd009e6a55fa0c0f681a5dd7 Mon Sep 17 00:00:00 2001 From: Xiang Silian Date: Sun, 28 Sep 2025 18:20:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B6=E7=82=B9=E5=BB=B6?= =?UTF-8?q?=E9=95=BF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/texture_loading/texture_loading.cpp | 63 +++++++++++++------ samples/api/texture_loading/texture_loading.h | 3 +- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/samples/api/texture_loading/texture_loading.cpp b/samples/api/texture_loading/texture_loading.cpp index be65e4d..3dc2d2c 100644 --- a/samples/api/texture_loading/texture_loading.cpp +++ b/samples/api/texture_loading/texture_loading.cpp @@ -1753,6 +1753,7 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options) #ifdef _WIN32 LoadOBJ("assets/DemoHead.obj", obj_vertices, obj_indices); + std::vector positions_test; LoadOBJ_test("assets/face.obj", positions_test); #else LoadOBJ("/sdcard/Android/data/com.khronos.vulkan_samples/files/assets/face_with_uv.obj", obj_vertices, obj_indices); @@ -1762,25 +1763,28 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options) generate_quad(); prepared = true; - for (int i = 0; i < obj_vertices.size(); ++i) - { - int face_index = obj_vertices_map[i]; - float x = positions_test[face_index * 3 + 0]; - float y = positions_test[face_index * 3 + 1]; - float z = positions_test[face_index * 3 + 2]; +#ifdef _WIN32 + //for (int i = 0; i < obj_vertices.size(); ++i) + //{ + // int face_index = obj_vertices_map[i]; + // float x = positions_test[face_index * 3 + 0]; + // float y = positions_test[face_index * 3 + 1]; + // float z = positions_test[face_index * 3 + 2]; - float obj_x = obj_vertices[i].pos[0]; - float obj_y = obj_vertices[i].pos[1]; - float obj_z = obj_vertices[i].pos[2]; + // float obj_x = obj_vertices[i].pos[0]; + // float obj_y = obj_vertices[i].pos[1]; + // float obj_z = obj_vertices[i].pos[2]; - //cout << "index: " << i << " face_index:" << face_index << " diff_x:" << (x - obj_x) << " diff_y:" << (y - obj_y) << " diff_z:" << (z - obj_z) << endl; - obj_vertices[i].pos[0] = x; - obj_vertices[i].pos[1] = y; - obj_vertices[i].pos[2] = z; - } + // //cout << "index: " << i << " face_index:" << face_index << " diff_x:" << (x - obj_x) << " diff_y:" << (y - obj_y) << " diff_z:" << (z - obj_z) << endl; + // obj_vertices[i].pos[0] = x; + // obj_vertices[i].pos[1] = y; + // obj_vertices[i].pos[2] = z; + //} - auto vertex_buffer_size = vkb::to_u32(obj_vertices.size() * sizeof(TextureLoadingVertexStructure)); - vertex_buffer->update(obj_vertices.data(), vertex_buffer_size); + //auto vertex_buffer_size = vkb::to_u32(obj_vertices.size() * sizeof(TextureLoadingVertexStructure)); + //vertex_buffer->update(obj_vertices.data(), vertex_buffer_size); + update_face_vertex_buffer(positions_test.data(), obj_vertices.size()); +#endif update_uniform_buffers_point(47, -0.5, -0.51, 0, 1, 1, 1, 0, 0, 0, 0, 0, -1); //start(); @@ -1878,14 +1882,35 @@ void ReceiveFacePoint(float* pos, int pointCount, int width, int height) } +void TextureLoading::extendPoint(float* pos, int start_id, int end_id, float rate) +{ + glm::vec3 start = glm::vec3(pos[start_id * 3], pos[start_id * 3 + 1], pos[start_id * 3 + 2]); + glm::vec3 end = glm::vec3(pos[end_id * 3], pos[end_id * 3 + 1], pos[end_id * 3 + 2]); + glm::vec3 dir = end - start; + glm::vec3 ex_end = end + dir * rate; + pos[end_id * 3 + 0] = ex_end.x; + pos[end_id * 3 + 1] = ex_end.y; + pos[end_id * 3 + 2] = ex_end.z; +} + void TextureLoading::update_face_vertex_buffer(float* pos, int pointCount) { + extendPoint(pos, 68, 54); + extendPoint(pos, 104, 103); + extendPoint(pos, 69, 67); + extendPoint(pos, 108, 109); + extendPoint(pos, 151, 10); + extendPoint(pos, 337, 338); + extendPoint(pos, 299, 297); + extendPoint(pos, 333, 332); + extendPoint(pos, 298, 284); + for (int i = 0; i < obj_vertices.size(); ++i) { int face_index = obj_vertices_map[i]; - float x = positions_test[face_index * 3 + 0]; - float y = positions_test[face_index * 3 + 1]; - float z = positions_test[face_index * 3 + 2]; + float x = pos[face_index * 3 + 0]; + float y = pos[face_index * 3 + 1]; + float z = pos[face_index * 3 + 2]; obj_vertices[i].pos[0] = x; obj_vertices[i].pos[1] = y; diff --git a/samples/api/texture_loading/texture_loading.h b/samples/api/texture_loading/texture_loading.h index dbe457f..9e0bef6 100644 --- a/samples/api/texture_loading/texture_loading.h +++ b/samples/api/texture_loading/texture_loading.h @@ -205,6 +205,7 @@ public: public: void update_point_vertex_buffer(float* pos, int pointCount); + void extendPoint(float* pos, int start_id, int end_id, float rate = 1); void update_face_vertex_buffer(float* pos, int pointCount); void update_point_vertex_buffer_line(float* pos, int pointCount_line, float r, float g, float b, std::vector& vertices); void update_point_vertex_buffer_line_save(std::vector& vertices); @@ -212,7 +213,7 @@ public: bool LoadOBJ(const std::string& filename,std::vector& vertices,std::vector& indices); bool LoadOBJ_test(const std::string& filename, std::vector& positions); private: - std::vector positions_test; + std::vector obj_vertices; std::vector obj_indices; std::map obj_vertices_map;