{"id":21874244,"url":"https://github.com/stefanjohnsen/pyobjparser","last_synced_at":"2025-03-21T23:18:04.244Z","repository":{"id":210396545,"uuid":"726440430","full_name":"StefanJohnsen/pyOBJParser","owner":"StefanJohnsen","description":"Wavefront OBJ + MTL parser python","archived":false,"fork":false,"pushed_at":"2023-12-16T11:23:56.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T17:37:40.314Z","etag":null,"topics":["material","wavefront","wavefront-obj"],"latest_commit_sha":null,"homepage":"","language":"Python","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/StefanJohnsen.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":"2023-12-02T12:06:21.000Z","updated_at":"2025-01-17T15:44:30.000Z","dependencies_parsed_at":"2023-12-16T11:45:38.906Z","dependency_job_id":"847c6d02-ef61-414f-8446-7090641b15e2","html_url":"https://github.com/StefanJohnsen/pyOBJParser","commit_stats":null,"previous_names":["stefanjohnsen/pyobjparser"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefanJohnsen%2FpyOBJParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefanJohnsen%2FpyOBJParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefanJohnsen%2FpyOBJParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefanJohnsen%2FpyOBJParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StefanJohnsen","download_url":"https://codeload.github.com/StefanJohnsen/pyOBJParser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244880660,"owners_count":20525515,"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":["material","wavefront","wavefront-obj"],"created_at":"2024-11-28T07:11:41.946Z","updated_at":"2025-03-21T23:18:04.214Z","avatar_url":"https://github.com/StefanJohnsen.png","language":"Python","readme":"# pyOBJParser\n\nEmpower your project with self-contained OBJ and MTL parser.\n\n### Dependencies\n- os\n- numpy\n\n### Parsed examples\n*pyOBJParser have been integrated into the [pyOBJExplorer](https://github.com/StefanJohnsen/pyOBJExplorer), showcasing the parsing capabilities.*\n\n![OBJExplorer](https://github.com/StefanJohnsen/pyOBJExplorer/blob/main/pictures/explorer.png)\n\n## Usage\n\nCopy `WavefrontOBJ.py` and `WavefrontMTL.py` to your python project directory and import parsers \n\n```\nfrom WavefrontOBJ import *\nfrom WavefrontMTL import *\n```\n\n## Example\nWe've developed a console application for a practical demonstration of its usage. This sample application is found in the [pyOBJExplorer](https://github.com/StefanJohnsen/pyOBJExplorer) repository. It serves as a guide on integrating and utilising `WavefrontOBJ.py` and `WavefrontMTL.py`.\n\n## WavefrontOBJ Parsing Capabilities\n\nThe WavefrontOBJ parser is processing a wide range of data encapsulated within Wavefront OBJ files. It reads vertices, texture coordinates, normals and geometrical elements like points, lines, faces. Notably, it is capable of interpreting all types of faces, including triangles, quads, and more complex polygons (with both positive and negative indices).\n\nAfter parsing the obj file, users gain access to geometry by utilizing the following lists.\n\t\n| Component | Description                                    |\n|-----------|------------------------------------------------|\n| vertex    | Defines points in 3D space, shaping the model. |\n| texture   | Manages texture details for enhanced visuals.  |\n| normal    | Specifies surface orientation for lighting.    |\n| face      | Contains indices for creating flat surfaces.   |\n| line      | Stores indices, useful for wireframe models.   |\n| point     | Manages indices for individual 3D points.      |\n\nHere are some sample formats of faces that OBJ parser can interpret:\n\n```\n# Triangle\nf 1 2 3 \nf 1//1 2//2 3//3 # triangle with vertex and normal\nf 1/1/1 2/2/2 3/3/3 # triangle with vertex, texture and normal\n\n# Quad\nf 1 2 3 4\nf 1//1 2//2 3//3 4//4 # quad with vertex and normal\nf 1/1/1 2/2/2 3/3/3 4/4/4 # quad with vertex, texture and normal\n\n# Polygon\nf 1 2 3 4 5 6 ....\nf 1//1 2//2 3//3 4//4 5//5 6//6 ... # polygon with vertex and normal\nf 1/1/1 2/2/2 3/3/3 4/4/4 5/5/5 6/6/6 ... # polygon with vertex, texture and normal\n\n# Also negative indices is supported\n```\n\n## WavefrontMTL Parsing Capabilities\n\nThe WavefrontMTL parser is designed to handle the most common material data found in Wavefront MTL files, providing essential functionality for 3D model materials. For those who require additional data types, the parser's code is straightforward and user-friendly, making it easy to understand and extend as needed.\n\nAfter parsing the material file, you will be presented with a comprehensive list of all the materials discovered in the file. Each material is encapsulated within a structure and contains the following member variables.\n\n| Member        | Type          | Description                  | Extension                              |\n|---------------|---------------|------------------------------|----------------------------------------|\n| name          | string        | Material name                |                                        |\n| Kd            | Color         | Color                        |                                        |\n| Ka            | Color         | Color Ambient                |                                        |\n| Ks            | Color         | Color Specular               |                                        |\n| Ke            | Color         | Color Emissive               | Physically Rendering/Clara.io          |\n| Ns            | double        | Shininess factor [0..1000]   |                                        |\n| Ns            | double        | Shininess factor [0..1000]   |                                        |\n| Ni            | double        | Optical density              |                                        |\n| d             | Opacity       | Dissolve factor              |                                        |\n| illum         | int           | Illumination [0..10]         |                                        |\n| map_Kd        | Texture       | Texture Diffuse              |                                        |\n| map_Ka        | Texture       | Texture Ambient              |                                        |\n| map_Ks        | Texture       | Texture Specular             |                                        |\n| map_Ns        | Texture       | Texture Glossiness           |                                        |\n| map_d         | Texture       | Opacity Texture (alpha)      |                                        |\n\nExample of typical material data:\n\n```\nnewmtl Material\nKd 0.5 0.5 0.5\nKa 0.0 0.0 0.0\nKs 0.5 0.5 0.5\nKe 0.0 0.0 0.0\nNs 168.89702\nNi 1.0\nd 1.0\nillum 2\nmap_Kd pic1.jpg\nmap_Ka pic2.jpg\nmap_Ks pic3.jpg\nmap_Ns pic4.jpg\nmap_d pic5.jpg\n```\n\n## Example.py\nClone this repository and study the provided example `Example.y`\n\n```\npython Example.py rubikcube.obj\n```\n```\nContent of c:\\temp\\rubikcube.mtl:\nmaterial: mat_1, color: rgb(0.6, 0.6, 0.6)\nmaterial: mat_2, color: rgb(0.1, 0.1, 0.1)\nmaterial: mat_3, color: rgb(1.0, 0.0, 0.0)\nmaterial: mat_4, color: rgb(1.0, 1.0, 1.0)\nmaterial: mat_5, color: rgb(0.9, 0.5, 0.0)\nmaterial: mat_6, color: rgb(0.9, 0.7, 0.1)\nmaterial: mat_7, color: rgb(0.3, 0.6, 0.3)\nmaterial: mat_8, color: rgb(0.2, 0.2, 0.6)\nContent of c:\\temp\\rubikcube.obj:\ngeometry: mat_1, color: rgb(0.6, 0.6, 0.6), faces : 1872\ngeometry: mat_2, color: rgb(0.1, 0.1, 0.1), faces : 13292\ngeometry: mat_3, color: rgb(1.0, 0.0, 0.0), faces : 18\ngeometry: mat_4, color: rgb(1.0, 1.0, 1.0), faces : 18\ngeometry: mat_5, color: rgb(0.9, 0.5, 0.0), faces : 18\ngeometry: mat_6, color: rgb(0.9, 0.7, 0.1), faces : 18\ngeometry: mat_7, color: rgb(0.3, 0.6, 0.3), faces : 18\ngeometry: mat_8, color: rgb(0.2, 0.2, 0.6), faces : 18\n\n```\n*This script serves as a solid foundation. However, I highly recommend exploring [pyOBJExplorer](https://github.com/StefanJohnsen/pyOBJExplorer) for a more detailed examination of all the geometry data.*\n\n## References\nThe following sources have been utilized in the development of this Wavefront MTL parser.\n\n[Paul Bourke: MTL material format (Lightwave, OBJ)](http://paulbourke.net/dataformats/mtl/)\n\n[Wikipedia: Wavefront .obj file](https://en.wikipedia.org/wiki/Wavefront_.obj_file)\n\n[FileFormat.info: WaveFront Material (.mtl) File Format](https://www.fileformat.info/format/material/)\n\n## License\nThis software is released under the MIT License terms.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanjohnsen%2Fpyobjparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefanjohnsen%2Fpyobjparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanjohnsen%2Fpyobjparser/lists"}