Skip to main content Link Menu Expand (external link) Document Search Copy Copied

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

Assimp for Unity is based on AssimpNet. This project does not offer full support for AssimpNet and we will never offer it. This page is therefore incomplete and serves as a starting point for using AssimpNet. We encourage you to read official AssimpNet Documentation.

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);

You can also pass PostProcessSteps options in the second parameter.

Assimp will try to detect what importer to use from the data which may or may not be successful. You can pass optional format extension as last parameter to serve as a hint to Assimp to choose which importer to use

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;