From 86e903fc869d8408fea7912d1a60c5062c7076a8 Mon Sep 17 00:00:00 2001 From: xiangsilian Date: Mon, 22 Sep 2025 00:32:03 +0800 Subject: [PATCH] asdf --- .../api/texture_loading/texture_loading.cpp | 119 ++++++++++++++---- samples/api/texture_loading/texture_loading.h | 4 +- 2 files changed, 99 insertions(+), 24 deletions(-) diff --git a/samples/api/texture_loading/texture_loading.cpp b/samples/api/texture_loading/texture_loading.cpp index 5d12b68..94f9809 100644 --- a/samples/api/texture_loading/texture_loading.cpp +++ b/samples/api/texture_loading/texture_loading.cpp @@ -599,6 +599,7 @@ void TextureLoading::draw() { std::unique_lock lock(mtx); std::unique_lock lock_point(mtx_point); + std::lock_guard lock_line(mtx_point_line); std::unique_lock lock_mvp(mtx_mvp); ApiVulkanSample::prepare_frame(); @@ -1452,8 +1453,8 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options) 1 + 0.1,1,z, }; - update_point_vertex_buffer(testPoint, sizeof(testPoint) / (3 * 4)); - update_point_vertex_buffer_line(testPoint_line, sizeof(testPoint_line) / (3 * 4)); + //update_point_vertex_buffer(testPoint, sizeof(testPoint) / (3 * 4)); + update_point_vertex_buffer_line(testPoint_line, sizeof(testPoint_line) / (3 * 4), 1, 0, 0); prepared = true; @@ -1535,6 +1536,7 @@ void TextureLoadProcessWithVulkan(uint8_t* data, int width, int height, int rowS TextureLoading::Get()->processWithVulkan(data, width, height, rowStride, dataSize, cam_tex); } +void update_face_round_line_point(float* pos); void ReceiveFacePoint(float* pos, int pointCount, int width, int height) { //for (int i = 0; i < pointCount; i++) { @@ -1542,7 +1544,14 @@ void ReceiveFacePoint(float* pos, int pointCount, int width, int height) // float y = pos[i * 3 + 1]; // float z = pos[i * 3 + 2]; //} - TextureLoading::Get()->update_point_vertex_buffer(pos, pointCount); + TextureLoading* self = TextureLoading::Get(); + if(self != nullptr) + { + //TextureLoading::Get()->update_point_vertex_buffer(pos, pointCount); + //update_face_round_line_point(pos); + self->demo1(pos); + } + } void TextureLoading::processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& out_texture) @@ -1943,8 +1952,69 @@ void TextureLoading::update_point_vertex_buffer(float* pos, int pointCount) } } +int point_index = 0; +void add_point(float* src, float* dest, int index) +{ + dest[point_index * 3] = src[index * 3]; + dest[point_index * 3 + 1] = src[index * 3 + 1]; + dest[point_index * 3 + 2] = src[index * 3 + 2]; + point_index++; +} +void TextureLoading::demo1(float* pos) +{ + point_index = 0; + std::vector pointIndex= { 233,232,231,230,229,118,36,49,209,217,188,233}; + float points[100 * 3]; + for (int i = 0; i < pointIndex.size(); ++i) + { + add_point(pos, points, pointIndex[i]); + } + update_point_vertex_buffer_line(points, point_index, 0.9f, 0.9f, 0.9f); +} -void TextureLoading::update_point_vertex_buffer_line(float* pos, int count) +void update_face_round_line_point(float* pos) +{ + point_index = 0; + float points[100 * 3]; + add_point(pos, points, 152); + add_point(pos, points, 176); + add_point(pos, points, 150); + add_point(pos, points, 172); + add_point(pos, points, 58); + add_point(pos, points, 132); + add_point(pos, points, 234); + add_point(pos, points, 162); + add_point(pos, points, 21); + add_point(pos, points, 54); + add_point(pos, points, 103); + add_point(pos, points, 67); + add_point(pos, points, 109); + add_point(pos, points, 338); + add_point(pos, points, 297); + add_point(pos, points, 332); + add_point(pos, points, 284); + add_point(pos, points, 251); + add_point(pos, points, 389); + add_point(pos, points, 454); + add_point(pos, points, 323); + add_point(pos, points, 361); + add_point(pos, points, 435); + add_point(pos, points, 288); + add_point(pos, points, 397); + add_point(pos, points, 365); + add_point(pos, points, 379); + add_point(pos, points, 378); + add_point(pos, points, 400); + add_point(pos, points, 377); + add_point(pos, points, 152); + TextureLoading* self = TextureLoading::Get(); + if (self != nullptr) + { + self->update_point_vertex_buffer_line(points, point_index, 0.9f, 0.9f, 0.9f); + } +} + +void TextureLoading::update_point_vertex_buffer_line(float* pos, int count, float r, float g, float b) { std::lock_guard lock(mtx_point_line); if (count <= 0) { @@ -1958,33 +2028,36 @@ void TextureLoading::update_point_vertex_buffer_line(float* pos, int count) std::vector vertices(point_count_line); // 假设 pos 数组是 [x0,y0,z0,x1,y1,z1,...] // 为了可视化,这里简单地将坐标映射为颜色 (0-1范围) - float min_x = std::numeric_limits::max(), max_x = std::numeric_limits::lowest(); - float min_y = std::numeric_limits::max(), max_y = std::numeric_limits::lowest(); - float min_z = std::numeric_limits::max(), max_z = std::numeric_limits::lowest(); + //float min_x = std::numeric_limits::max(), max_x = std::numeric_limits::lowest(); + //float min_y = std::numeric_limits::max(), max_y = std::numeric_limits::lowest(); + //float min_z = std::numeric_limits::max(), max_z = std::numeric_limits::lowest(); - for (int i = 0; i < point_count_line; ++i) { - float x = pos[i * 3 + 0]; - float y = pos[i * 3 + 1]; - float z = pos[i * 3 + 2]; - min_x = std::min(min_x, x); max_x = std::max(max_x, x); - min_y = std::min(min_y, y); max_y = std::max(max_y, y); - min_z = std::min(min_z, z); max_z = std::max(max_z, z); - } - float range_x = max_x - min_x; - float range_y = max_y - min_y; - float range_z = max_z - min_z; - if (range_x == 0) range_x = 1.0f; // 防止除零 - if (range_y == 0) range_y = 1.0f; - if (range_z == 0) range_z = 1.0f; + //for (int i = 0; i < point_count_line; ++i) { + // float x = pos[i * 3 + 0]; + // float y = pos[i * 3 + 1]; + // float z = pos[i * 3 + 2]; + // min_x = std::min(min_x, x); max_x = std::max(max_x, x); + // min_y = std::min(min_y, y); max_y = std::max(max_y, y); + // min_z = std::min(min_z, z); max_z = std::max(max_z, z); + //} + //float range_x = max_x - min_x; + //float range_y = max_y - min_y; + //float range_z = max_z - min_z; + //if (range_x == 0) range_x = 1.0f; // 防止除零 + //if (range_y == 0) range_y = 1.0f; + //if (range_z == 0) range_z = 1.0f; for (int i = 0; i < point_count_line; ++i) { vertices[i].x = pos[i * 3 + 0]; vertices[i].y = pos[i * 3 + 1]; vertices[i].z = pos[i * 3 + 2]; // 简单颜色映射 - vertices[i].r = (vertices[i].x - min_x) / range_x; + /*vertices[i].r = (vertices[i].x - min_x) / range_x; vertices[i].g = (vertices[i].y - min_y) / range_y; - vertices[i].b = (vertices[i].z - min_z) / range_z; + vertices[i].b = (vertices[i].z - min_z) / range_z;*/ + vertices[i].r = r; + vertices[i].g = g; + vertices[i].b = b; } // 2. 更新或创建顶点缓冲区 diff --git a/samples/api/texture_loading/texture_loading.h b/samples/api/texture_loading/texture_loading.h index d83d2fd..31db1c6 100644 --- a/samples/api/texture_loading/texture_loading.h +++ b/samples/api/texture_loading/texture_loading.h @@ -176,7 +176,7 @@ public: public: void update_point_vertex_buffer(float* pos, int pointCount); - void update_point_vertex_buffer_line(float* pos, int pointCount_line); + void update_point_vertex_buffer_line(float* pos, int pointCount_line, float r, float g, float b); private: std::thread workerThread; bool running = false; @@ -190,6 +190,8 @@ public: std::mutex mtx_mvp; //void stop(); //void updateTexture(); + + void demo1(float* pos); }; std::unique_ptr create_texture_loading();