@@ -176,6 +176,66 @@ MeshResult Atlas::getMesh(std::uint32_t index) const
176176 return std::make_tuple (mapping, indices, uvs);
177177}
178178
179+ VertexAssignment Atlas::getMeshVertexAssignment (std::uint32_t meshIndex) const
180+ {
181+ if (meshIndex >= m_atlas->meshCount )
182+ {
183+ throw std::out_of_range (" Mesh index " + std::to_string (meshIndex) + " out of bounds for atlas with " + std::to_string (m_atlas->meshCount ) + " meshes." );
184+ }
185+
186+ auto const & mesh = m_atlas->meshes [meshIndex];
187+
188+ py::array_t <std::uint32_t > atlasIndex (py::array::ShapeContainer{mesh.vertexCount });
189+ py::array_t <std::uint32_t > chartIndex (py::array::ShapeContainer{mesh.vertexCount });
190+ auto atlasIndex_ = atlasIndex.mutable_unchecked <1 >();
191+ auto chartIndex_ = chartIndex.mutable_unchecked <1 >();
192+ for (size_t v = 0 ; v < static_cast <size_t >(mesh.vertexCount ); ++v)
193+ {
194+ auto const & vertex = mesh.vertexArray [v];
195+ atlasIndex_ (v) = vertex.atlasIndex ;
196+ chartIndex_ (v) = vertex.chartIndex ;
197+ }
198+
199+ return std::make_tuple (atlasIndex, chartIndex);
200+ }
201+
202+ uint32_t Atlas::getMeshChartCount (std::uint32_t meshIndex) const
203+ {
204+ if (meshIndex >= m_atlas->meshCount )
205+ throw std::out_of_range (" Mesh index " + std::to_string (meshIndex) + " out of bounds for atlas with " + std::to_string (m_atlas->meshCount ) + " meshes." );
206+
207+ auto const & mesh = m_atlas->meshes [meshIndex];
208+
209+ return mesh.chartCount ;
210+ }
211+
212+ Chart Atlas::getMeshChart (std::uint32_t meshIndex, std::uint32_t chartIndex) const
213+ {
214+ if (meshIndex >= m_atlas->meshCount )
215+ throw std::out_of_range (" Mesh index " + std::to_string (meshIndex) + " out of bounds for atlas with " + std::to_string (m_atlas->meshCount ) + " meshes." );
216+
217+ auto const & mesh = m_atlas->meshes [meshIndex];
218+
219+ if (chartIndex >= mesh.chartCount )
220+ throw std::out_of_range (" Chart index " + std::to_string (chartIndex) + " out of bounds for mesh with " + std::to_string (mesh.chartCount ) + " charts." );
221+
222+ xatlas::Chart& chart = mesh.chartArray [chartIndex];
223+ py::array_t <std::uint32_t > faces (py::array::ShapeContainer{chart.faceCount });
224+ auto faces_ = faces.mutable_unchecked <1 >();
225+ for (size_t i = 0 ; i < static_cast <size_t >(chart.faceCount ); ++i)
226+ {
227+ faces_ (i) = chart.faceArray [i];
228+ }
229+
230+ Chart chart_;
231+ chart_.faces = faces;
232+ chart_.atlasIndex = chart.atlasIndex ;
233+ chart_.type = chart.type ;
234+ chart_.material = chart.material ;
235+
236+ return chart_;
237+ }
238+
179239float Atlas::getUtilization (std::uint32_t index) const
180240{
181241 if (index >= m_atlas->atlasCount )
@@ -259,12 +319,21 @@ py::array_t<std::uint8_t> Atlas::getChartImage(std::uint32_t index) const
259319
260320void Atlas::bind (py::module & m)
261321{
322+ py::class_<Chart>(m, " Chart" )
323+ .def_property_readonly (" faces" , [](Chart const & self) { return self.faces ; })
324+ .def_property_readonly (" atlas_index" , [](Chart const & self) { return self.atlasIndex ; })
325+ .def_property_readonly (" type" , [](Chart const & self) { return self.type ; })
326+ .def_property_readonly (" material" , [](Chart const & self) { return self.material ; });
327+
262328 py::class_<Atlas>(m, " Atlas" )
263329 .def (py::init<>())
264330 .def (" add_mesh" , &Atlas::addMesh, py::arg (" positions" ), py::arg (" indices" ), py::arg (" normals" ) = std::nullopt , py::arg (" uvs" ) = std::nullopt )
265331 .def (" add_uv_mesh" , &Atlas::addUvMesh, py::arg (" uvs" ), py::arg (" indices" ), py::arg (" face_materials" ) = std::nullopt )
266332 .def (" generate" , &Atlas::generate, py::arg (" chart_options" ) = xatlas::ChartOptions (), py::arg (" pack_options" ) = xatlas::PackOptions (), py::arg (" verbose" ) = false )
267333 .def (" get_mesh" , &Atlas::getMesh, py::arg (" mesh_index" ))
334+ .def (" get_mesh_vertex_assignment" , &Atlas::getMeshVertexAssignment, py::arg (" mesh_index" ))
335+ .def (" get_mesh_chart_count" , &Atlas::getMeshChartCount, py::arg (" mesh_index" ))
336+ .def (" get_mesh_chart" , &Atlas::getMeshChart, py::arg (" mesh_index" ), py::arg (" chart_index" ))
268337 .def (" get_utilization" , &Atlas::getUtilization, py::arg (" atlas_index" ))
269338 .def (" get_chart_image" , &Atlas::getChartImage, py::arg (" atlas_index" ))
270339 .def_property_readonly (" atlas_count" , [](Atlas const & self) { return self.m_atlas ->atlasCount ; })
0 commit comments