添加顶点延长。

This commit is contained in:
xsl
2025-09-28 18:20:50 +08:00
parent 86889c334e
commit 3e33975e2a
2 changed files with 46 additions and 20 deletions
+44 -19
View File
@@ -1753,6 +1753,7 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
#ifdef _WIN32 #ifdef _WIN32
LoadOBJ("assets/DemoHead.obj", obj_vertices, obj_indices); LoadOBJ("assets/DemoHead.obj", obj_vertices, obj_indices);
std::vector<float> positions_test;
LoadOBJ_test("assets/face.obj", positions_test); LoadOBJ_test("assets/face.obj", positions_test);
#else #else
LoadOBJ("/sdcard/Android/data/com.khronos.vulkan_samples/files/assets/face_with_uv.obj", obj_vertices, obj_indices); 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(); generate_quad();
prepared = true; prepared = true;
for (int i = 0; i < obj_vertices.size(); ++i) #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]; // int face_index = obj_vertices_map[i];
float y = positions_test[face_index * 3 + 1]; // float x = positions_test[face_index * 3 + 0];
float z = positions_test[face_index * 3 + 2]; // 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_x = obj_vertices[i].pos[0];
float obj_y = obj_vertices[i].pos[1]; // float obj_y = obj_vertices[i].pos[1];
float obj_z = obj_vertices[i].pos[2]; // 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; // //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[0] = x;
obj_vertices[i].pos[1] = y; // obj_vertices[i].pos[1] = y;
obj_vertices[i].pos[2] = z; // obj_vertices[i].pos[2] = z;
} //}
auto vertex_buffer_size = vkb::to_u32(obj_vertices.size() * sizeof(TextureLoadingVertexStructure)); //auto vertex_buffer_size = vkb::to_u32(obj_vertices.size() * sizeof(TextureLoadingVertexStructure));
vertex_buffer->update(obj_vertices.data(), vertex_buffer_size); //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); update_uniform_buffers_point(47, -0.5, -0.51, 0, 1, 1, 1, 0, 0, 0, 0, 0, -1);
//start(); //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) 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) for (int i = 0; i < obj_vertices.size(); ++i)
{ {
int face_index = obj_vertices_map[i]; int face_index = obj_vertices_map[i];
float x = positions_test[face_index * 3 + 0]; float x = pos[face_index * 3 + 0];
float y = positions_test[face_index * 3 + 1]; float y = pos[face_index * 3 + 1];
float z = positions_test[face_index * 3 + 2]; float z = pos[face_index * 3 + 2];
obj_vertices[i].pos[0] = x; obj_vertices[i].pos[0] = x;
obj_vertices[i].pos[1] = y; obj_vertices[i].pos[1] = y;
@@ -205,6 +205,7 @@ public:
public: public:
void update_point_vertex_buffer(float* pos, int pointCount); 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_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<LineVertex>& vertices); void update_point_vertex_buffer_line(float* pos, int pointCount_line, float r, float g, float b, std::vector<LineVertex>& vertices);
void update_point_vertex_buffer_line_save(std::vector<LineVertex>& vertices); void update_point_vertex_buffer_line_save(std::vector<LineVertex>& vertices);
@@ -212,7 +213,7 @@ public:
bool LoadOBJ(const std::string& filename,std::vector<TextureLoadingVertexStructure>& vertices,std::vector<uint32_t>& indices); bool LoadOBJ(const std::string& filename,std::vector<TextureLoadingVertexStructure>& vertices,std::vector<uint32_t>& indices);
bool LoadOBJ_test(const std::string& filename, std::vector<float>& positions); bool LoadOBJ_test(const std::string& filename, std::vector<float>& positions);
private: private:
std::vector<float> positions_test;
std::vector<TextureLoadingVertexStructure> obj_vertices; std::vector<TextureLoadingVertexStructure> obj_vertices;
std::vector<uint32_t> obj_indices; std::vector<uint32_t> obj_indices;
std::map<int, int> obj_vertices_map; std::map<int, int> obj_vertices_map;