{"id":21135602,"url":"https://github.com/ray-cast/trianglepacker","last_synced_at":"2025-08-24T01:12:04.696Z","repository":{"id":93685966,"uuid":"117748695","full_name":"ray-cast/trianglepacker","owner":"ray-cast","description":"📄 Triangle packer for light map","archived":false,"fork":false,"pushed_at":"2018-02-07T00:03:59.000Z","size":761,"stargazers_count":76,"open_issues_count":2,"forks_count":8,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-04T16:53:35.371Z","etag":null,"topics":["bake","lightmap","rectangle-packer","tilemap","triangle-packer","uv-mapper"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ray-cast.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-01-16T22:10:09.000Z","updated_at":"2025-03-18T18:18:20.000Z","dependencies_parsed_at":"2023-03-13T17:15:04.349Z","dependency_job_id":null,"html_url":"https://github.com/ray-cast/trianglepacker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ray-cast/trianglepacker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ray-cast%2Ftrianglepacker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ray-cast%2Ftrianglepacker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ray-cast%2Ftrianglepacker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ray-cast%2Ftrianglepacker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ray-cast","download_url":"https://codeload.github.com/ray-cast/trianglepacker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ray-cast%2Ftrianglepacker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271778236,"owners_count":24819265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bake","lightmap","rectangle-packer","tilemap","triangle-packer","uv-mapper"],"created_at":"2024-11-20T06:56:44.852Z","updated_at":"2025-08-24T01:12:04.670Z","avatar_url":"https://github.com/ray-cast.png","language":"C++","readme":"# Triangle Packer\ntrianglepacker.hpp is a C++11/17 single required source file, that help to packs triangles of a 3D mesh into a texture, \nthis method is a fast greedy algorithm, the output is looks like a blender's lightmappack, and the quality is near the blender.\n\nthis library can supports rectangle pack, when part of input indices are converted from a quad to two triangles, \nthat two triangle become combined and can result in a quad, see the below images.\n\n\n![preview1.png](https://github.com/ray-cast/trianglepacker/raw/master/preview1.png)\n![preview2.png](https://github.com/ray-cast/trianglepacker/raw/master/preview2.png)\n\n# Usage\n```c++\n#include \"trianglepacker.hpp\"\n\n// method 1\n// allocate buffer for each output uv\nstd::vector\u003cfloat2\u003e uvs(vertices.size());\n\nif (!ray::uvmapper::lightmappack(\n    // consecutive triangle positions\n    (float*)vertices.data(), vertices.size(), \n    // resolution\n    512, 512, \n    // margin between all triangle\n    1, \n    // output (a normalized uv coordinate for each input vertex):\n    (float*)uvs.data()))\n{\n    std::cerr \u003c\u003c \"Failed to pack all triangles into the map!\" \u003c\u003c std::endl;\n    return false;\n}\n\n// method 2\n\n// allocate for vertex count\nstd::size_t count = 0;\n\nstd::vector\u003cstd::uint16_t\u003e remap(indices.size()); // allocate buffer for each vertex index\nstd::vector\u003cfloat2\u003e uvs(indices.size()); // allocate buffer for each output uv\nstd::vector\u003cstd::uint16_t\u003e outIndices(indices.size()); // allocate buffer for each output uv\n\nif (!ray::uvmapper::lightmappack(\n    // triangle positions\n    (float*)vertices.data(),\n    // indices buffer\n    indices.data(), indices.size(), \n    // resolution\n    512, 512, \n    // margin between all triangle and quad\n    1, \n    // output (a pointer to the array of remapped vertices):\n    remap.data(), \n    // output (a normalized uv coordinate for each output vertex):\n    (float*)uvs.data(),\n    // output (a index buffer for each ouput uv):\n    outIndices.data()\n    // output (a count of vertex that has been written)\n    count))\n{\n    std::cerr \u003c\u003c \"Failed to pack all triangles into the map!\" \u003c\u003c std::endl;\n    return 0;\n}\n\nstd::vector\u003cVertex\u003e newVertices(count);\n\nfor (std::size_t i = 0; i \u003c count; i++)\n{\n    newVertices[i] = vertices[remap[i]];\n    newVertices[i].uv = uvs[i];\n}\n\nvertices = newVertices;\nindices = outIndices;\n```\n\n[License (MIT)](https://raw.githubusercontent.com/ray-cast/trianglepacker/master/LICENSE.txt)\n-------------------------------------------------------------------------------\n    MIT License\n\n    Copyright (c) 2018 Rui\n\n\tPermission is hereby granted, free of charge, to any person obtaining a\n\tcopy of this software and associated documentation files (the \"Software\"),\n\tto deal in the Software without restriction, including without limitation\n\tthe rights to use, copy, modify, merge, publish, distribute, sublicense,\n\tand/or sell copies of the Software, and to permit persons to whom the\n\tSoftware is furnished to do so, subject to the following conditions:\n\n\tThe above copyright notice and this permission notice shall be included\n\tin all copies or substantial portions of the Software.\n\n\tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n\tOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\tFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\n\tBRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\n\tAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n\tCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n# References\n* Packing Lightmaps \\[[link](http://blackpawn.com/texts/lightmaps/default.html)\\]\n","funding_links":[],"categories":["ComputerGraphics \u0026\u0026 Shadingv"],"sub_categories":["Google Analytics"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fray-cast%2Ftrianglepacker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fray-cast%2Ftrianglepacker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fray-cast%2Ftrianglepacker/lists"}