DebugDrawerUtils.cpp
Go to the documentation of this file.
1#include "DebugDrawerUtils.h"
2
3#include <VirtualRobot/Visualization/TriMeshModel.h>
4
5armarx::DebugDrawerTriMesh
6armarx::DebugDrawerUtils::convertTriMesh(const VirtualRobot::TriMeshModel& trimesh)
7{
8 DebugDrawerTriMesh ddMesh;
9
10 auto addVertex = [&](const Eigen::Vector3f& v)
11 {
12 ddMesh.vertices.push_back({v(0), v(1), v(2)});
13 return (int)ddMesh.vertices.size() - 1;
14 };
15
16 auto addColor = [&](const VirtualRobot::VisualizationFactory::Color& c)
17 {
18 ddMesh.colors.push_back(DrawColor{c.r, c.g, c.b, c.transparency});
19 return (int)ddMesh.colors.size() - 1;
20 };
21 ddMesh.faces.reserve(trimesh.faces.size());
22 ddMesh.vertices.reserve(trimesh.vertices.size());
23 ddMesh.colors.reserve(trimesh.colors.size());
24
25 for (auto& f : trimesh.faces)
26 {
27 DebugDrawerFace f2;
28 f2.vertex1.vertexID = addVertex(trimesh.vertices.at(f.id1));
29 f2.vertex2.vertexID = addVertex(trimesh.vertices.at(f.id2));
30 f2.vertex3.vertexID = addVertex(trimesh.vertices.at(f.id3));
31 if (f.idNormal1 != UINT_MAX)
32 {
33 f2.vertex1.normalID = addVertex(trimesh.normals.at(f.idNormal1));
34 f2.vertex2.normalID = addVertex(trimesh.normals.at(f.idNormal2));
35 f2.vertex3.normalID = addVertex(trimesh.normals.at(f.idNormal3));
36 }
37 else
38 {
39 // f2.vertex1.normalID = f2.vertex2.normalID = f2.vertex3.normalID = addVertex(f.normal);
40 f2.normal = {f.normal.x(), f.normal.y(), f.normal.z()};
41 }
42 f2.vertex1.colorID = addColor(trimesh.colors.at(f.idColor1));
43 f2.vertex2.colorID = addColor(trimesh.colors.at(f.idColor2));
44 f2.vertex3.colorID = addColor(trimesh.colors.at(f.idColor3));
45
46 ddMesh.faces.push_back(f2);
47 }
48 return ddMesh;
49}
constexpr T c
static DebugDrawerTriMesh convertTriMesh(const VirtualRobot::TriMeshModel &trimesh)