{"id":16947553,"url":"https://github.com/mrdimas/lightmap","last_synced_at":"2025-04-11T15:31:43.445Z","repository":{"id":226245380,"uuid":"768161862","full_name":"mrDIMAS/lightmap","owner":"mrDIMAS","description":"Light maps generator","archived":false,"fork":false,"pushed_at":"2024-10-21T18:16:54.000Z","size":22,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T15:33:13.381Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrDIMAS.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-06T15:26:38.000Z","updated_at":"2024-12-17T13:38:54.000Z","dependencies_parsed_at":"2024-03-06T17:20:39.642Z","dependency_job_id":"531d8e21-bfce-4c23-a6b0-2043ae1304a2","html_url":"https://github.com/mrDIMAS/lightmap","commit_stats":null,"previous_names":["mrdimas/lightmap"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrDIMAS%2Flightmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrDIMAS%2Flightmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrDIMAS%2Flightmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrDIMAS%2Flightmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrDIMAS","download_url":"https://codeload.github.com/mrDIMAS/lightmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248431527,"owners_count":21102215,"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","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":[],"created_at":"2024-10-13T21:47:30.528Z","updated_at":"2025-04-11T15:31:43.153Z","avatar_url":"https://github.com/mrDIMAS.png","language":"Rust","readme":"# lightmap\n\nLight maps generator.\n\n## Example\n\n```rust\nuse lightmap::{\n    input::{Mesh, WorldVertex},\n    light::{LightDefinition, PointLightDefinition},\n    LightMap,\n};\nuse nalgebra::{Vector2, Vector3};\n\n#[derive(Copy, Clone, Debug, Default, PartialEq)]\npub struct Vertex {\n    pub position: Vector3\u003cf32\u003e,\n    pub tex_coord: Vector2\u003cf32\u003e,\n}\n\nimpl Vertex {\n    fn new(x: f32, y: f32, z: f32) -\u003e Self {\n        Self {\n            position: Vector3::new(x, y, z),\n            tex_coord: Default::default(),\n        }\n    }\n}\n\n// Create cube geometry.\nlet mut vertices = vec![\n    Vertex::new(-0.5, -0.5, 0.5),\n    Vertex::new(-0.5, 0.5, 0.5),\n    Vertex::new(0.5, 0.5, 0.5),\n    Vertex::new(0.5, -0.5, 0.5),\n    Vertex::new(-0.5, -0.5, -0.5),\n    Vertex::new(-0.5, 0.5, -0.5),\n    Vertex::new(0.5, 0.5, -0.5),\n    Vertex::new(0.5, -0.5, -0.5),\n];\nlet mut triangles = vec![\n    // Front\n    [2, 1, 0],\n    [3, 2, 0],\n    // Back\n    [4, 5, 6],\n    [4, 6, 7],\n    // Right\n    [7, 6, 2],\n    [2, 3, 7],\n    // Left\n    [0, 1, 5],\n    [0, 5, 4],\n    // Top\n    [5, 1, 2],\n    [5, 2, 6],\n    // Bottom\n    [3, 0, 4],\n    [7, 3, 4],\n];\n\n// Step 1. Generate second texture coordinates first.\nlet patch = uvgen::generate_uvs(\n    vertices.iter().map(|v| v.position),\n    triangles.iter().cloned(),\n    0.005,\n)\n.unwrap();\n\n// Step 2. Clone vertices on seams.\nfor \u0026vertex_index in \u0026patch.additional_vertices {\n    let vertex = vertices[vertex_index as usize];\n    vertices.push(vertex);\n}\n\n// Step 3. Assign generated second texture coordinates.\nfor (vertex, tex_coord) in vertices.iter_mut().zip(\u0026patch.second_tex_coords) {\n    vertex.tex_coord = *tex_coord;\n}\n\n// Step 4. Replace topology of the mesh using new one, that was produced when generating UVs.\ntriangles = patch.triangles;\n\n// Step 5. Generate light map.\nlet lights = [LightDefinition::Point(PointLightDefinition {\n    intensity: 1.0,\n    color: Vector3::new(1.0, 1.0, 1.0),\n    radius: 2.0,\n    position: Vector3::new(0.0, 2.0, 0.0),\n    sqr_radius: 4.0,\n})];\n\nlet mut mesh = Mesh::new(\n    vertices\n        .iter()\n        .map(|v| WorldVertex {\n            world_normal: Default::default(),\n            world_position: v.position,\n            second_tex_coord: v.tex_coord,\n        })\n        .collect(),\n    triangles,\n)\n.unwrap();\n\n// Calculate normals.\nfor triangle in mesh.triangles.iter() {\n    let pos_a = mesh.vertices[triangle[0] as usize].world_position;\n    let pos_b = mesh.vertices[triangle[1] as usize].world_position;\n    let pos_c = mesh.vertices[triangle[2] as usize].world_position;\n\n    let normal = (pos_c - pos_a)\n        .cross(\u0026(pos_c - pos_b))\n        .try_normalize(f32::EPSILON)\n        .unwrap_or_default();\n\n    mesh.vertices[triangle[0] as usize].world_normal = normal;\n    mesh.vertices[triangle[1] as usize].world_normal = normal;\n    mesh.vertices[triangle[2] as usize].world_normal = normal;\n}\n\nlet meshes = vec![mesh];\n\nlet light_map = LightMap::new(\u0026meshes[0], \u0026meshes, \u0026lights, 64);\n\ndbg!(light_map);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdimas%2Flightmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrdimas%2Flightmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdimas%2Flightmap/lists"}