Assimp data structure介绍

主要内容从原网站翻译过来:链接 Assimp

数据结构

  • 调用 Assimp::Importer::ReadFile,aiImportFile或aiImportFileEx,返回aiScene。作为data的根。
  • 默认下,所有的3D数据是右手坐标系下的,和openGl一致。在D3D这种左右坐标系下,设置flag aiProcess_MakeLeftHanded。
  • winding-order默认是CCW的,可以设置 aiProcess_FlipWindingOrder to get CW data。
  • UV坐标是左下角为原点,使用flag aiProcess_FlipUVs 可改为左上角为原点。
  • assimp库里矩阵都是行主序。 opengl的api要求的是列主序, unity也里也是列主序。

Node 层次结构

  • scene 由 node的树状结构构成,从scene的root node起,每个node可以有多个child nodes,node相对于parent node有一个transform变换。
  • 每个node refer to 一个或多个meshes,meshes列表存储在aiScene,node通过index to refer,因此多个node能refer to 多个mesh。在node里每个refered mesh的instance是相对于node坐标的,需要级联计算得到global坐标。

recursive filter function such as the following pseudocode

void CopyNodesWithMeshes( aiNode node, SceneObject targetParent, Matrix4x4 accTransform)
{
  SceneObject parent;
  Matrix4x4 transform;
  // if node has meshes, create a new scene object for it
  if( node.mNumMeshes > 0)
  {
    SceneObjekt newObject = new SceneObject;
    targetParent.addChild( newObject);
    // copy the meshes
    CopyMeshes( node, newObject);
    // the new object is the parent for all child nodes
    parent = newObject;
    transform.SetUnity();
  } else
  {
    // if no meshes, skip the node, but keep its transformation
    parent = targetParent;
    transform = node.mTransformation * accTransform;
  }
  // continue for all child nodes
  for( all node.mChildren)
    CopyNodesWithMeshes( node.mChildren[a], parent, transform);
}

Meshes

  • 一个mesh只使用一个material,material数组也是存在scene里,mesh 通过index refer to material。
  • aiMesh 由一系列data channels组成,由导入的文件决定,默认情况下文件里有才会出现在mesh里。aiMesh::mVerteces和aiMesh::mFaces是一定会有的。也能在调用importer::readFile时设置一些flag做post process,计算出你需要的data channels。
  • aiMesh是三角和多边形的集合,一个vertex一定会有一个position,还可能有一个normal,一个tangent或bitangent,zero to AI_MAX_NUMBER_OF_TEXTURECOORDS (4 at the moment) texture coords and zero to AI_MAX_NUMBER_OF_COLOR_SETS (4) vertex colors.
  • 除此以外,一个mesh还可能有一组bones(aiBone)

Material

  • material的数据存放在aiScene里一组aiMaterial。一个material由一组properties组成。

Bones

一个mesh可以有一组bones组成(aiBone对象),每个bone有一个name和一组能够影响到的vertices。以及一个相对mesh的local transform。

创建一个skeleton hierarchy for a mesh:

a) Create a map or a similar container to store which nodes are necessary for the skeleton. Pre-initialise it for all nodes with a "no".
b) For each bone in the mesh:
b1) Find the corresponding node in the scene's hierarchy by comparing their names.
b2) Mark this node as "yes" in the necessityMap.
b3) Mark all of its parents the same way until you 1) find the mesh's node or 2) the parent of the mesh's node.
c) Recursively iterate over the node hierarchy
c1) If the node is marked as necessary, copy it into the skeleton and check its children
c2) If the node is marked as not necessary, skip it and do not iterate over its children.

Animations

一个scene有zero to x aiAnimationentries,一个animation是一组keyframe sequences,每组sequence描述了在一段时间内单个node的transform变化。这种动画通常用于驱动skeleton of a skinned mesh, 当然也有其他的用法。

一个aiAnimation有一个duration,duration和其他的时间戳都是由tick表示,因此为了知道真实的时间,我们需要除以aiAnimation::mTicksPerSecond(0表示这个参数没有被生产软件导出)。

aiAnimation有一组aiNodeAnim。每个aiNodeAnim的name表明了影响那个node,并存有三组key sequence,一起描述mode的transformation matrix。

Textures

通常textures存在单独的文件,然后,也有些文件格式内嵌texutre到model file。这种textures会被加载到aiTexture。

有两种情况:

  1. texure非压缩。颜色直接存在aiTexture::mWidth * aiTexture::mHeight aiTexel structures。每个aiTexel代表一个像素。存储的格式是RGBA8888。
  2. 如果aiTexture::mHeight == 0 ,代表是压缩格式。比如DDS或PNG。 aiTexture::mWidth specifies the size of the texture data in bytes, aiTexture::pcData is a pointer to the raw image data and aiTexture::achFormatHint is either zeroed or contains the most common file extension of the embedded texture’s format.

你可能感兴趣的:(Tools)