This commit is contained in:
xsl
2025-09-22 00:32:03 +08:00
parent 628597fe59
commit 86e903fc86
2 changed files with 99 additions and 24 deletions
+96 -23
View File
@@ -599,6 +599,7 @@ void TextureLoading::draw()
{
std::unique_lock<std::mutex> lock(mtx);
std::unique_lock<std::mutex> lock_point(mtx_point);
std::lock_guard<std::mutex> lock_line(mtx_point_line);
std::unique_lock<std::mutex> 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<int> 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<std::mutex> lock(mtx_point_line);
if (count <= 0) {
@@ -1958,33 +2028,36 @@ void TextureLoading::update_point_vertex_buffer_line(float* pos, int count)
std::vector<PointVertex> vertices(point_count_line);
// 假设 pos 数组是 [x0,y0,z0,x1,y1,z1,...]
// 为了可视化,这里简单地将坐标映射为颜色 (0-1范围)
float min_x = std::numeric_limits<float>::max(), max_x = std::numeric_limits<float>::lowest();
float min_y = std::numeric_limits<float>::max(), max_y = std::numeric_limits<float>::lowest();
float min_z = std::numeric_limits<float>::max(), max_z = std::numeric_limits<float>::lowest();
//float min_x = std::numeric_limits<float>::max(), max_x = std::numeric_limits<float>::lowest();
//float min_y = std::numeric_limits<float>::max(), max_y = std::numeric_limits<float>::lowest();
//float min_z = std::numeric_limits<float>::max(), max_z = std::numeric_limits<float>::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. 更新或创建顶点缓冲区