Adding gltf model support for the object mesh#190
Open
kestr31 wants to merge 2 commits intoericstoneking:masterfrom
Open
Adding gltf model support for the object mesh#190kestr31 wants to merge 2 commits intoericstoneking:masterfrom
kestr31 wants to merge 2 commits intoericstoneking:masterfrom
Conversation
- Extract mesh finalization code into standalone FinalizeMesh function (bounding box, normal unitization, edge tables, SurfaceForceProps, EdgeAndPolyDyads, per-poly bounding sphere) - Expose PolyIsDegenerate declaration in meshkit.h - Remove unused variables from LoadWingsObjFile after extraction
- Add cgltf v1.15 header-only C99 parser (MIT license) as vendor header - Add static GLTF helper functions in meshkit.c (TransformPoint, TransformNormal, FindAttribute, UriToPpm, MapGltfMaterial) - Add static LoadGltfFile for parsing glTF/GLB files with support for triangle primitives, world transforms, and PBR-to-Phong material mapping - Add LoadMeshFile dispatcher routing .gltf/.glb to LoadGltfFile and all other extensions to LoadWingsObjFile - Replace LoadWingsObjFile with LoadMeshFile in 42init.c (5 call sites) - Replace LoadWingsObjFile with LoadMeshFile in 42commlink.c (2 call sites) - Add cgltf.h dependency to meshkit.o Makefile rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for developing and maintaining 42 — it has been really helpful for preliminary design of our CubeSat flight software.
While working on a CubeSat project, I ran into difficulty using custom meshes for simulation configuration. I needed to convert a STEP assembly into OBJ via FreeCAD, but the direct STEP-to-OBJ export was unreliable. As a workaround, I exported the STEP file to glTF in FreeCAD — which worked without issues — and then imported the glTF into Blender to convert it to OBJ. While this pipeline got the job done, the extra Blender conversion step felt unnecessary: if 42 could load glTF directly, the entire workaround would be eliminated.
The glTF format ("GL Transmission Format") is an open standard by the Khronos Group and is more modern than OBJ, with broader and more reliable support in current CAD tools — FreeCAD, Blender, SolidWorks, Fusion 360, and others all export it natively. Supporting it in 42 would allow users to bring in models from a wider range of tools without needing a manual conversion step to OBJ.
This pull request adds support for loading glTF 2.0 (.gltf/.glb) 3D models alongside the existing OBJ format. The change is fully backward-compatible: all existing OBJ models continue to load through the same code path without any behavioral change. I would like to ask whether this modification could be considered for merging into the mainline codebase.
How it works
A thin
LoadMeshFile()dispatcher checks the file extension:.gltfor.glbfiles are routed to a newLoadGltfFile()loaderLoadWingsObjFile()To use a glTF model, simply name a
.gltfor.glbfile in the spacecraft configuration (e.g.,MyModel.gltfin the "Geometry Input File Name" field). No other configuration changes are needed.Implementation details
Kit/Include/cgltf.hwith no external dependencies.meshkit.cas static functions, following the existing pattern where all mesh I/O (OBJ loading, KD-tree, octree, etc.) lives in this file.Commit structure
The PR is split into two commits for ease of review:
Files changed
Kit/Include/cgltf.hKit/Include/meshkit.hPolyIsDegenerate,FinalizeMesh,LoadMeshFiledeclarationsKit/Source/meshkit.cFinalizeMesh; add glTF loader andLoadMeshFiledispatcherSource/42init.cLoadMeshFileSource/42commlink.cLoadMeshFileMakefilecgltf.hdependency tomeshkit.obuild ruleTesting
make clean && makeon Linux (gcc,-std=gnu11 -Wall -Wshadow, zero warnings)SC_Simpleconfiguration)Images
The console log for this model's gltf loading was like below:
I would be happy to make any adjustments you think are appropriate. Thank you in advance for considering this contribution.