完成UV对齐
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
TextureLoading::TextureLoading()
|
TextureLoading::TextureLoading()
|
||||||
{
|
{
|
||||||
zoom = -1.f;
|
zoom = -1.f;
|
||||||
@@ -570,7 +572,7 @@ void TextureLoading::build_command_buffers()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
draw_point_cloud(draw_cmd_buffers[i]);
|
//draw_point_cloud(draw_cmd_buffers[i]);
|
||||||
//draw_point_cloud_line(draw_cmd_buffers[i]);
|
//draw_point_cloud_line(draw_cmd_buffers[i]);
|
||||||
|
|
||||||
|
|
||||||
@@ -622,6 +624,35 @@ void TextureLoading::draw()
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
|
||||||
|
bool TextureLoading::LoadOBJ_test(const std::string& filename, std::vector<float>& temp_positions)
|
||||||
|
{
|
||||||
|
std::ifstream file(filename);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
temp_positions.clear();
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(file, line)) {
|
||||||
|
// 跳过空行和注释行
|
||||||
|
if (line.empty() || line[0] == '#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::istringstream iss(line);
|
||||||
|
std::string type;
|
||||||
|
iss >> type;
|
||||||
|
|
||||||
|
if (type == "v") { // 顶点位置
|
||||||
|
float x, y, z;
|
||||||
|
iss >> x >> y >> z;
|
||||||
|
temp_positions.push_back(x);
|
||||||
|
temp_positions.push_back(y);
|
||||||
|
temp_positions.push_back(z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
bool TextureLoading::LoadOBJ(const std::string& filename,
|
bool TextureLoading::LoadOBJ(const std::string& filename,
|
||||||
std::vector<TextureLoadingVertexStructure>& vertices,
|
std::vector<TextureLoadingVertexStructure>& vertices,
|
||||||
std::vector<uint32_t>& indices) {
|
std::vector<uint32_t>& indices) {
|
||||||
@@ -661,7 +692,7 @@ bool TextureLoading::LoadOBJ(const std::string& filename,
|
|||||||
float u, v;
|
float u, v;
|
||||||
iss >> u >> v;
|
iss >> u >> v;
|
||||||
temp_texcoords.push_back(u);
|
temp_texcoords.push_back(u);
|
||||||
temp_texcoords.push_back(v);
|
temp_texcoords.push_back(1-v);
|
||||||
}
|
}
|
||||||
else if (type == "vn") { // 法线
|
else if (type == "vn") { // 法线
|
||||||
float nx, ny, nz;
|
float nx, ny, nz;
|
||||||
@@ -758,6 +789,7 @@ bool TextureLoading::LoadOBJ(const std::string& filename,
|
|||||||
uint32_t newIndex = static_cast<uint32_t>(vertices.size());
|
uint32_t newIndex = static_cast<uint32_t>(vertices.size());
|
||||||
vertices.push_back(vertex);
|
vertices.push_back(vertex);
|
||||||
indices.push_back(newIndex);
|
indices.push_back(newIndex);
|
||||||
|
obj_vertices_map[newIndex] = posIndex;
|
||||||
vertexMap[vertexKey] = newIndex;
|
vertexMap[vertexKey] = newIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1627,7 +1659,7 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
myFloatValue = 1.0f;
|
myFloatValue = 1.5f;
|
||||||
|
|
||||||
// --- 加载前景纹理 (示例) ---
|
// --- 加载前景纹理 (示例) ---
|
||||||
int width = 640;
|
int width = 640;
|
||||||
@@ -1720,23 +1752,36 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
|
|||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (LoadOBJ("assets/face_with_uv.obj", obj_vertices, obj_indices))
|
LoadOBJ("assets/DemoHead.obj", obj_vertices, obj_indices);
|
||||||
|
LoadOBJ_test("assets/face.obj", positions_test);
|
||||||
#else
|
#else
|
||||||
if (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);
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
{
|
|
||||||
|
|
||||||
std::cout << "成功加载OBJ文件" << std::endl;
|
|
||||||
std::cout << "顶点数量: " << obj_vertices.size() << std::endl;
|
|
||||||
std::cout << "索引数量: " << obj_indices.size() << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << "加载OBJ文件失败" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
generate_quad();
|
generate_quad();
|
||||||
prepared = true;
|
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];
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto vertex_buffer_size = vkb::to_u32(obj_vertices.size() * sizeof(TextureLoadingVertexStructure));
|
||||||
|
vertex_buffer->update(obj_vertices.data(), vertex_buffer_size);
|
||||||
|
|
||||||
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();
|
||||||
return true;
|
return true;
|
||||||
@@ -1835,11 +1880,16 @@ void ReceiveFacePoint(float* pos, int pointCount, int width, int height)
|
|||||||
|
|
||||||
void TextureLoading::update_face_vertex_buffer(float* pos, int pointCount)
|
void TextureLoading::update_face_vertex_buffer(float* pos, int pointCount)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < pointCount; ++i)
|
for (int i = 0; i < obj_vertices.size(); ++i)
|
||||||
{
|
{
|
||||||
obj_vertices[i].pos[0] = pos[i * 3 + 0];
|
int face_index = obj_vertices_map[i];
|
||||||
obj_vertices[i].pos[1] = pos[i * 3 + 1];
|
float x = positions_test[face_index * 3 + 0];
|
||||||
obj_vertices[i].pos[2] = pos[i * 3 + 2];
|
float y = positions_test[face_index * 3 + 1];
|
||||||
|
float z = positions_test[face_index * 3 + 2];
|
||||||
|
|
||||||
|
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));
|
auto vertex_buffer_size = vkb::to_u32(obj_vertices.size() * sizeof(TextureLoadingVertexStructure));
|
||||||
|
|||||||
@@ -210,9 +210,12 @@ public:
|
|||||||
void update_point_vertex_buffer_line_save(std::vector<LineVertex>& vertices);
|
void update_point_vertex_buffer_line_save(std::vector<LineVertex>& vertices);
|
||||||
|
|
||||||
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);
|
||||||
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::thread workerThread;
|
std::thread workerThread;
|
||||||
bool running = false;
|
bool running = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user