ObjParser 0.1.0

dotnet add package ObjParser --version 0.1.0
                    
NuGet\Install-Package ObjParser -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ObjParser" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ObjParser" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ObjParser" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ObjParser --version 0.1.0
                    
#r "nuget: ObjParser, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ObjParser@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ObjParser&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ObjParser&version=0.1.0
                    
Install as a Cake Tool

ObjParser

CI Tests

A small, dependency‑free C# library for reading and writing Wavefront OBJ/MTL files.

  • Supports geometry: v, vt, vn, f, l, p
  • Supports grouping/state: g, s, o
  • Supports materials: mtllib, usemtl
  • Target frameworks: netstandard2.0, net8.0

Quick start

Install from source (or add the project as a reference):

git clone https://github.com/stefangordon/ObjParser.git
cd ObjParser
dotnet build
dotnet test

Examples

Read an OBJ and inspect bounds

using ObjParser;

var obj = new ObjModel();
obj.Load("Example/sample.obj");

Console.WriteLine($"Vertices: {obj.Vertices.Count}, Faces: {obj.Faces.Count}");
var b = obj.Bounds;
Console.WriteLine($"Bounds: X[{b.XMin}, {b.XMax}] Y[{b.YMin}, {b.YMax}] Z[{b.ZMin}, {b.ZMax}]");

Build a triangle and write it out

using ObjParser;
using ObjParser.Types;

var obj = new ObjModel();

int v1 = obj.AddVertex(new Vertex { X = 0, Y = 0, Z = 0 });
int v2 = obj.AddVertex(new Vertex { X = 1, Y = 0, Z = 0 });
int v3 = obj.AddVertex(new Vertex { X = 0, Y = 1, Z = 0 });

obj.SetGroups("G1");
obj.SetSmoothingGroup("1");
obj.SetObjectName("Triangle");

obj.AddFace(new Face { VertexIndexList = new[] { v1, v2, v3 } });

obj.Save("triangle.obj", new[] { "Created with ObjParser" });

Add UVs, lines, and points

using ObjParser;
using ObjParser.Types;

var obj = new ObjModel();

int v1 = obj.AddVertex(new Vertex { X = 0, Y = 0, Z = 0 });
int v2 = obj.AddVertex(new Vertex { X = 1, Y = 0, Z = 0 });
int v3 = obj.AddVertex(new Vertex { X = 1, Y = 1, Z = 0 });
int v4 = obj.AddVertex(new Vertex { X = 0, Y = 1, Z = 0 });

int t1 = obj.AddTextureVertex(new TextureVertex { X = 0, Y = 0 });
int t2 = obj.AddTextureVertex(new TextureVertex { X = 1, Y = 0 });
int t3 = obj.AddTextureVertex(new TextureVertex { X = 0, Y = 1 });

obj.SetGroups("Edge", "Wire");
obj.AddLine(new LineElement { VertexIndexList = new[] { v1, v2, v3, v4 }, TextureVertexIndexList = new[] { 0, 0, 0, 0 } });

obj.SetGroups("Points");
obj.AddPoint(new PointElement { VertexIndexList = new[] { v1, v3 } });

obj.SetGroups("Textured");
obj.AddFace(new Face {
    VertexIndexList = new[] { v1, v2, v3 },
    TextureVertexIndexList = new[] { t1, t2, t3 }
});

obj.Save("example.obj", new[] { "Created with ObjParser" });

Work with materials (MTL)

using ObjParser;

// Read/write an MTL file
var mtl = new MaterialLibrary();
mtl.LoadMtl("Example/sample.mtl");
mtl.WriteMtlFile("materials_out.mtl", new[] { "Created with ObjParser" });

// Reference an MTL from an OBJ
var obj = new ObjModel();
obj.MaterialLibraryName = "materials_out.mtl";   // reference in written OBJ
obj.CurrentMaterialName = "Material";            // default material for subsequently added faces

Grouped views

Build an in‑memory view of elements by OBJ group names (g):

var groups = obj.BuildMeshGroups();
foreach (var g in groups)
{
    Console.WriteLine($"Group: {string.Join(" ", g.GroupNames)}  Faces: {g.Faces.Count}  Lines: {g.Lines.Count}  Points: {g.Points.Count}");
}

Target frameworks

  • netstandard2.0 (runs on .NET Framework 4.6.1+, .NET Core 2.0+, Mono, Unity, etc.)
  • net8.0

Build and test locally

dotnet restore ObjParser.sln
dotnet build ObjParser.sln -c Release
dotnet test ObjParser_Tests/ObjParser_Tests.csproj -c Release

License

MIT — see LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 97 9/14/2025