AB4D Forum

Full Version: merge stl files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
does anybody know if there is a function to merge 2 stl files into one?
You can use assimp importer to open one or more stl files - just don't clear the scene before adding additional 3D models.

Then you can use the assimp exporter to save the 3D scene (created from models from stl files) to a stl file. 

See the AssimpWpfImporterSample and AssimpWpfExporterSample in AssimpSamples folder for more info.
I tried but if i ceate a viewport with only a sphere3d (for example) and i try to export everything is ok.
When i read stl, put them in the content of a ModelVisual3D and in a 3dvieport, when i export AssimpWpfExporter returns me false!
see the code below.
I noticed that the samples wpf doesn't export my stl file too. So i tried to export a dae: nothing
Help me!
Code:
Dim AssimpWpfImporter As New AssimpWpfImporter

Dim readmodel3d As Model3D = AssimpWpfImporter.ReadModel3D(mfilestl)
Dim modelarray As New ModelVisual3D
modelarray.Content = readmodel3d
myview.Children.Add(modelarray)

Dim AssimpWpfExporter = New AssimpWpfExporter()

AssimpWpfExporter.AddViewport3D(myview)
isExported = AssimpWpfExporter.Export(fileName, "stl")
no ideas?
This was an interesting problem.

It seems that it was possible to export to other file formats, but not to stl.

After using a debug version of assimp importer, I found out that when exporting to stl the assimp exporter does not "want" that the SceneFlags has the NonVerboseFormat flag set. If this flag is set, then the following code throws an exception:

    if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) {
        throw DeadlyImportError("Post-processing order mismatch: expecting pseudo-indexed (\"verbose\") vertices here");
    }

This is done before calculating the normals. I do not know why this is needed to calculate the normals. I also do not know why models created from code (SphereVisual3D, BoxVisual3D, ...) work well, but files imported from stl files throw that exception.


The description of the NonVerboseFormat flag is:
This flag is currently only set by the aiProcess_JoinIdenticalVertices step.

It indicates that the vertices of the output meshes aren't in the internal verbose format anymore. In the verbose format all vertices are unique, no vertex is ever referenced by more than one face.


But it seems that it is used in some other places. This flag is also set by the AssimpWpfExporter. This was done based on the comment from Exporter.cpp file in assimp importer. 

But if the flag is not set, then it seems that exporting works fine for stl file and for other files also.

Therefore I have removed setting this flag. This will be available in the next version.

Until then you can use a workaround and manually set the SceneFlags to None. In the AssimpWpfExporterSample this can be done by adding the following line after "assimpWpfExporter.AddViewport3D(viewport3D);":

assimpWpfExporter.AssimpScene.SceneFlags = SceneFlags.None;
(11-16-2020, 12:58 PM)abenedik Wrote: [ -> ]This was an interesting problem.

It seems that it was possible to export to other file formats, but not to stl.

After using a debug version of assimp importer, I found out that when exporting to stl the assimp exporter does not "want" that the SceneFlags has the NonVerboseFormat flag set. If this flag is set, then the following code throws an exception:

    if (pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) {
        throw DeadlyImportError("Post-processing order mismatch: expecting pseudo-indexed (\"verbose\") vertices here");
    }

This is done before calculating the normals. I do not know why this is needed to calculate the normals. I also do not know why models created from code (SphereVisual3D, BoxVisual3D, ...) work well, but files imported from stl files throw that exception.


The description of the NonVerboseFormat flag is:
This flag is currently only set by the aiProcess_JoinIdenticalVertices step.

It indicates that the vertices of the output meshes aren't in the internal verbose format anymore. In the verbose format all vertices are unique, no vertex is ever referenced by more than one face.


But it seems that it is used in some other places. This flag is also set by the AssimpWpfExporter. This was done based on the comment from Exporter.cpp file in assimp importer. 

But if the flag is not set, then it seems that exporting works fine for stl file and for other files also.

Therefore I have removed setting this flag. This will be available in the next version.

Until then you can use a workaround and manually set the SceneFlags to None. In the AssimpWpfExporterSample this can be done by adding the following line after "assimpWpfExporter.AddViewport3D(viewport3D);":

assimpWpfExporter.AssimpScene.SceneFlags = SceneFlags.None;

thanks a lot!!!!! It works!!