MCPcopy Create free account
hub / github.com/city-super/Octree-GS / generateMeshForText

Function generateMeshForText

SIBR_viewers/src/core/graphics/GUI.cpp:74–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72 }
73
74 Mesh::Ptr generateMeshForText(const std::string & text, unsigned int & separationIndex){
75 // Technically we don't care if we already are in the middle of a ImGui frame.
76 // as long as we clear the draw list. ImGui will detect the empty draw lists and cull them.
77 ImGui::PushID(1234567809);
78 ImGui::SetNextWindowPos(ImVec2(0,0));
79 ImGui::Begin(text.c_str(), nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoInputs);
80 ImGui::SetWindowFontScale(ImGui::GetIO().FontGlobalScale);
81
82 ImGui::Text(text.c_str());
83 // Get back the draw list.
84 ImDrawList * drawlist = ImGui::GetWindowDrawList();
85 const int vertCount = drawlist->VtxBuffer.Size;
86 const int indexCount = drawlist->IdxBuffer.Size;
87 // We generate one mesh from the draw list.
88 std::vector<sibr::Vector3f> vertices(vertCount);
89 std::vector<sibr::Vector2f> uvs(vertCount);
90 std::vector<sibr::Vector3f> colors(vertCount);
91 std::vector<sibr::Vector3u> faces(indexCount / 3);
92
93 sibr::Vector3f centroid(0.0f, 0.0f, 0.0f);
94 for (int k = 0; k < vertCount; ++k) {
95 const auto & vtx = drawlist->VtxBuffer[k];
96 vertices[k][0] = (vtx.pos.x)*2.0f;
97 vertices[k][1] = -vtx.pos.y*2.0f;
98 uvs[k][0] = vtx.uv.x; uvs[k][1] = vtx.uv.y;
99 ImVec4 col = ImGui::ColorConvertU32ToFloat4(vtx.col);
100 colors[k][0] = col.x; colors[k][1] = col.y;
101 colors[k][2] = col.z; vertices[k][2] = col.w;
102 centroid += vertices[k];
103 }
104 for (int k = 0; k < indexCount; k += 3) {
105 faces[k / 3][0] = (unsigned int)drawlist->IdxBuffer[k];
106 faces[k / 3][1] = (unsigned int)drawlist->IdxBuffer[k + 1];
107 faces[k / 3][2] = (unsigned int)drawlist->IdxBuffer[k + 2];
108 }
109 // Center the mesh?
110 centroid /= float(vertices.size());
111 for (int k = 0; k < vertices.size(); ++k) {
112 vertices[k] -= centroid;
113 }
114 Mesh::Ptr mesh = std::make_shared<Mesh>();
115 mesh->vertices(vertices);
116 mesh->colors(colors);
117 mesh->texCoords(uvs);
118 mesh->triangles(faces);
119 // Store the separation idnex between the background and the text foreground.
120 separationIndex = drawlist->CmdBuffer[0].ElemCount;
121
122 // Finish the window, then clear the draw list.
123 ImGui::End();
124 ImGui::PopID();
125 drawlist->Clear();
126 return mesh;
127 }
128
129
130 void fitImageToDisplayRegion(const Vector2f & imgSize, const Vector2i & regionSize, Vector2f& offset, Vector2f& size)

Callers 1

Calls 5

colorsMethod · 0.80
verticesMethod · 0.60
texCoordsMethod · 0.60
trianglesMethod · 0.60
sizeMethod · 0.45

Tested by

no test coverage detected