Meshellator - Open source 3D asset import library for .NET / Silverlight

Meshellator is an open source 3D asset import library, available for both .NET 4.0 and Silverlight 4.0. Meshellator is the underlying library for the 3DS, OBJ and NFF content importers for XNA which I have mentioned previously.

What?

Supported file formats are quite limited at the moment. If anybody wants to contribute more, please feel free!

As well as importing meshes from a file, Meshellator also allows you to create meshes from primitive shapes:

Meshellator's only dependency is on Nexus, a lightweight vector and matrix library I blogged about recently.

How?

Meshellator is quite easy to use. After you've added a reference to Meshellator.dll (or Meshellator.Silverlight.dll), the following line is enough to load from a file into a Scene object. The Scene object contains collections for meshes and materials, and should be quite intuitive to navigate.

Scene scene = MeshellatorLoader.ImportFromFile("85-nissan-fairlady.3ds");

Loading one of the built-in primitive shapes is just as easy. Each of the primitive shape methods have some parameters for size and tessellation level.

Scene scene = MeshellatorLoader.CreateFromTeapot(10, 20);

Why?

Given that there's several open source asset import libraries already - in particular Open Asset Import Library (or Assimp) - why make another one? Good question - if you're working purely on Windows, and don't mind a bit of interop into native code, then Assimp is indeed the solution I'd recommend. It's mature, well supported, and supports a whole host of formats.

Meshellator, on the other hand, is new and only supports 2 or 3 file formats at the moment. However, I believe it has a useful place in the .NET ecosystem, as the first (as far as I know) fully managed open source asset import library. Because it's fully managed, it also works on Silverlight.

Where?

You can browse the Meshellator source code here, and you can download the binaries from two places:

Viewer

The source code (but not the binary downloads) includes a viewer application.

image

The viewer application is not developed enough to be that useful, but it may be of technical interest - it combines AvalonDock, FluentRibbon and SlimDX in a WPF MVVM application based on Caliburn. As a historical aside, this viewer application is what eventually became XBuilder, after I realised that the world didn't need another general-purpose model viewer, and the "model viewer as a Visual Studio extension" niche was more interesting.

8 comments

Gravatar Florian Maetschke
Feb 22, 2011
16:38

Great Work man!

Gravatar Michael Shapiro
Mar 2, 2011
06:19

Fantastic job!

Gravatar Michael Shapiro (ms44)
Mar 5, 2011
21:57

Hi Tim,

I tested your recent changes and found that one fix is omitted from the committed version (line 72 in FaseParser.cs).

Current line:

if (rawFaces.Length == 1) continue;

should be replaced with

if (wordParts.Length == 1) continue;

because rawFaces array has now a fixed length and wordParts array actually knows how many word parts there were :)

(See also my proposed fix on git).

Sorry if this is not a right place to leave meshellator related proposals. Do you think it would be better to use githum issues?

Thanks again for Meshellator and DotWarp - I'm moving forward in my learning of these wonderful things.

Gravatar Michael Shapiro (ms440)
Mar 5, 2011
22:13

Also, the last part of the same method // save normal if (!string.IsNullOrEmpty(rawFaces[2])) { currentValue = int.Parse(rawFaces[2]); nindices[i - 1] = currentValue - 1; normals[i - 1] = _object.Normals[currentValue - 1]; } does not need if anymore - it is always true. (See proposed fix for Issue#1 at github.)

Gravatar Tim Jones
Mar 6, 2011
11:40

Thanks!

Michael, I have fixed that (if (wordParts.Length == 1) continue;) in the repo.

Actually I added that if for the normal - if it's not there, rawFaces[2] can be null, and that causes int.Parse(...) to fail.

Yes, for future issues, I think GitHub is best :) But for general discussion here is fine.

Tim

Gravatar Michael Shapiro
Mar 6, 2011
19:24

Thanks Tim! I'm inching along with DotWarp/Meshellator study...

Wonderful job, thanks a mil.

Gravatar Andrew Olney
Mar 9, 2011
01:32

Could you expand on the translation from a Meshellator scene to an XNA model?

I looked at Osiris, but translating NodeContent to a model is equally opaque to me

Gravatar Tim Jones
Mar 16, 2011
08:32

Andrew, as you hinted, all the code for converting a Meshellator scene object to an XNA NodeContent is here. NodeContent is an XNA Content Pipeline class, which ends up being loaded at runtime as an XNA Model. There's a one-to-one mapping between:

  • Meshellator.Scene => XNA NodeContent
  • Meshellator.Mesh => XNA MeshContent, XNA GeometryContent (XNA supports multiple GeometryContent objects per MeshContent, but Meshellator doesn't use / need that)
  • Meshellator.Material => XNA MaterialContent

Does that answer your question? If not, perhaps you could let me know which specific area is not clear, and I'll do my best to explain.

Make a comment

Sorry, commenting has been temporary disabled because of spam. If you have any questions, you can email me, and you can also find me on Twitter.