Assimp: Starting to support point-clouds


In Asset-Importer-Lib we got a lot of feature-requests to provide point-clouds somehow. Doing this will be a big step for our library because the intention when designing Assimp was to give the user an optimized scene with meshes ready for rendering. And we need triangles to get a valid scene definition. And all free vertices, which are not referenced by a triangle / face will be removed during the post-processing. So a point-cloud, free vertices which are not referenced by any triangle, will be not possible with our initial design.

My first step ( and the easiest way to go I guest ) is to be able to export point-cloud data as an ASCII-STL-file. So you can find this feature on our current master branch on github. to export this you have to follow these steps:

  1. Define a scene containing some vertices without any face declarations.
  2. Create your exporter class, use the new introduced boolean property property AI_CONFIG_EXPORT_POINT_CLOUDS and set it to true
  3. Use the ASCII-STL-exporter:
struct XYZ {
    float x, y, z;
};

std::vector<XYZ> points;

for (size_t i = 0; i < 10; ++i) {
    XYZ current;
    current.x = static_cast<float>(i);
    current.y = static_cast<float>(i);
    current.z = static_cast<float>(i);
    points.push_back(current);
}
aiScene scene;
scene.mRootNode = new aiNode();

scene.mMeshes = new aiMesh*[1];
scene.mMeshes[0] = nullptr;
scene.mNumMeshes = 1;

scene.mMaterials = new aiMaterial*[1];
scene.mMaterials[0] = nullptr;
scene.mNumMaterials = 1;

scene.mMaterials[0] = new aiMaterial();

scene.mMeshes[0] = new aiMesh();
scene.mMeshes[0]->mMaterialIndex = 0;

scene.mRootNode->mMeshes = new unsigned int[1];
scene.mRootNode->mMeshes[0] = 0;
scene.mRootNode->mNumMeshes = 1;

auto pMesh = scene.mMeshes[0];

long numValidPoints = points.size();

pMesh->mVertices = new aiVector3D[numValidPoints];
pMesh->mNumVertices = numValidPoints;

int i = 0;
for (XYZ &p : points) {
   pMesh->mVertices[i] = aiVector3D(p.x, p.y, p.z);
   ++i;
}

Assimp::Exporter mAiExporter;
ExportProperties *properties = new ExportProperties;
properties->SetPropertyBool(AI_CONFIG_EXPORT_POINT_CLOUDS, true);
mAiExporter.Export(&scene, "stl", "testExport.stl", 0, properties );

delete properties;

The exported file will have the following syntax:

 solid Assimp_Pointcloud
 facet normal 0 0 0
  vertex 0 0 0
  vertex 0 0 0
  vertex 0 0 0
  vertex 1 1 1
  vertex 1 1 1
  vertex 1 1 1
  vertex 2 2 2
  vertex 2 2 2
  vertex 2 2 2
  vertex 3 3 3
  vertex 3 3 3
  vertex 3 3 3
  vertex 4 4 4
  vertex 4 4 4
  vertex 4 4 4
  vertex 5 5 5
  vertex 5 5 5
  vertex 5 5 5
  vertex 6 6 6
  vertex 6 6 6
  vertex 6 6 6
  vertex 7 7 7
  vertex 7 7 7
  vertex 7 7 7
  vertex 8 8 8
  vertex 8 8 8
  vertex 8 8 8
  vertex 9 9 9
  vertex 9 9 9
  vertex 9 9 9
endsolid Assimp_Pointcloud

If you need any other way how to define point-clouds please use this post to give me feedback!

The next step will be to be able to import a point-could. So stay tuned…