Link

Usage

Table of contents

  1. Importation
    1. Create Assimp Scene from files
    2. Create Assimp Scene from streams
    3. Access Scene components
      1. Meshes
      2. Materials
      3. … and others
  2. Export
    1. Exporting to files
    2. Exporting to blob
  3. Advanced parameters
    1. Scaling the scene
    2. Rotating the scene

WIP

All AssimpNet classes are located on Assimp namespace:

using Assimp;

Importation

You must create

AssimpContext importer = new AssimpContext();

Create Assimp Scene from files

Scene scene = importer.ImportFile("mymodel.fbx");
Scene scene = importer.ImportFile("mymodel.fbx", PostProcessSteps.CalculateTangentSpace | PostProcessSteps.GenerateNormals);

Yon can also use presets:

Scene scene = importer.ImportFile("mymodel.fbx", PostProcessPreset.ConvertToLeftHanded);
Scene scene = importer.ImportFile("mymodel.fbx", PostProcessPreset.TargetRealTimeQuality);
Scene scene = importer.ImportFile("mymodel.fbx", PostProcessPreset.TargetRealTimeMaximumQuality);

Create Assimp Scene from streams

Stream stream = File.Open("mymodel.fbx", FileMode.Open);
Scene scene = importer.ImportFileFromStream(stream);

Access Scene components

Meshes

foreach(Mesh m in scene.Meshes)
{
    List<Vector3D> verts = m.Vertices;
    List<Vector3D> norms = (m.HasNormals) ? m.Normals : null;
    List<Vector3D> uvs = m.HasTextureCoords(0) ? m.TextureCoordinateChannels[0] : null;

    for(int i = 0; i < verts.Count; i++)
    {
        Vector3D pos = verts[i];
        Vector3D norm = (norms != null) ? norms[i] : new Vector3D(0, 0, 0);
        Vector3D uv = (uvs != null) ? uvs[i] : new Vector3D(0, 0, 0);

        ...
    }

    List<Face> faces = m.Faces;

    ...
}

Materials

foreach(Material m in scene.Materials)
{
    Color4D diffuseColor = new Color4D(1, 1, 1, 1);
    if(m.HasColorDiffuse)
    {
        diffuseColor = m.ColorDiffuse;
    }

    String diffuseFilePath = String.Empty;
    if(m.HasTextureDiffuse)
    {
        filePath = Path.Combine(baseDir, m.TextureDiffuse.FilePath);
    }

    ...
}

… and others

AssimpNet API is very similar to the C++ Assimp API. You can check Assimp Docs in order to use this.

Export

Exporting to files

WIP

Exporting to blob

WIP

Advanced parameters

Scaling the scene

importer.Scale = 3;

Rotating the scene

importer.XAxisRotation = 3;
importer.YAxisRotation = 3;
importer.ZAxisRotation = 3;