简体   繁体   English

使用 assimp 将 3d model 转换为 2d

[英]Translating a 3d model to 2d using assimp

I'm using c++ to translate a 3d model entered using command line arguments into a 2d picture in assimp.我正在使用 c++ 将使用命令行 ZDBC11CAA5BDA99F77E6FB4DABD8 输入的 3d model 转换为如imp2D7 所示的命令行 ZDBC11CAA5BDA99F77E6FB4DABD8。 However I'm not sure of the best way to go about it.但是,我不确定 go 的最佳方法。 I have the basic hard coding for to create a set object but I need to redo it using vectors and loops.我有基本的硬编码来创建一组 object 但我需要使用向量和循环重做它。 What's the best way to go about it? go 最好的方法是什么?

void createSimpleQuad(Mesh &m) {
  // Clear out vertices and elements
  m.vertices.clear();
  m.indices.clear();

  // Create four corners
  Vertex upperLeft, upperRight;
  Vertex lowerLeft, lowerRight;
  Vertex upperMiddle;

  // Set positions of vertices
  // Note: glm::vec3(x, y, z)
  upperLeft.position = glm::vec3(-0.5, 0.5, 0.0);
  upperRight.position = glm::vec3(0.5, 0.5, 0.0);
  lowerLeft.position = glm::vec3(-0.5, -0.5, 0.0);
  lowerRight.position = glm::vec3(0.5, -0.5, 0.0);
  upperMiddle.position = glm::vec3(-0.9, 0.5, 0.0);

  // Set vertex colors (red, green, blue, white)
  // Note: glm::vec4(red, green, blue, alpha)
  upperLeft.color = glm::vec4(1.0, 0.0, 0.0, 1.0);
  upperRight.color = glm::vec4(0.0, 1.0, 0.0, 1.0);
  lowerLeft.color = glm::vec4(0.0, 0.0, 1.0, 1.0);
  lowerRight.color = glm::vec4(1.0, 1.0, 1.0, 1.0);
  upperMiddle.color = glm::vec4(0.5, 0.15, 0.979797979, 1.0);

  // Add to mesh's list of vertices
  m.vertices.push_back(upperLeft);
  m.vertices.push_back(upperRight); 
  m.vertices.push_back(lowerLeft);
  m.vertices.push_back(lowerRight);
  m.vertices.push_back(upperMiddle);

  // Add indices for two triangles
  m.indices.push_back(0);
  m.indices.push_back(3);
  m.indices.push_back(1);

  m.indices.push_back(0);
  m.indices.push_back(2);
  m.indices.push_back(3);

  m.indices.push_back(0);
  m.indices.push_back(2);
  m.indices.push_back(4);
}

If you want to generate a 2D-picture out of a 3D-Model you need to:如果您想从 3D 模型中生成 2D 图片,您需要:

  1. Import the model导入 model
  2. Render it via a common render-lib into a texture or manually by using our viewer and take a snapshot通过通用渲染库将其渲染到纹理中,或者使用我们的查看器手动渲染并拍摄快照

At this moment there is no post-process to generate a 2D-View automatically in Assimp.目前没有在 Assimp 中自动生成 2D 视图的后处理。

But when you want to do this with your own render-code this is not so hard to do.但是当你想用你自己的渲染代码来做这件事时,这并不难。 After importing your model you have to:导入 model 后,您必须:

  1. Get the bounding box for your imported asset, just check the opengl-samples in the assimp-repo for some tips获取导入资产的边界框,只需检查 assimp-repo 中的 opengl-samples 以获取一些提示
  2. Calculate the diameter for this bounding box.计算此边界框的直径。
  3. Create a camera, for OpenGL you can use glm for calculating the View-Matrix创建一个摄像头,对于 OpenGL,您可以使用 glm 来计算 View-Matrix
  4. Place the asset at (0|0|0) world coordinate system将资产放置在 (0|0|0) 世界坐标系
  5. Move your camera by the diameter at let it view onto (0|0|0)将您的相机移动直径,让它查看到 (0|0|0)
  6. Render the view into a 2D-Texture or just take a screenshot将视图渲染为 2D 纹理或仅截取屏幕截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM